This commit is contained in:
johan.forsberg 2023-11-04 22:26:03 +01:00
parent d584a75ae6
commit dc730a99ea
3 changed files with 802 additions and 413 deletions

View File

@ -8,13 +8,15 @@ import dlangui.widgets.metadata;
import std.array : replaceFirst; import std.array : replaceFirst;
import std.algorithm; import std.algorithm;
import std.stdio; import std.stdio;
import std.string;
import std.array; import std.array;
import std.file; import std.file;
mixin APP_ENTRY_POINT; mixin APP_ENTRY_POINT;
// action codes // action codes
enum IDEActions : int { enum IDEActions : int
{
//ProjectOpen = 1010000, //ProjectOpen = 1010000,
FileNew = 1010000, FileNew = 1010000,
FileOpen, FileOpen,
@ -29,27 +31,47 @@ enum IDEActions : int {
} }
// actions // actions
const Action ACTION_FILE_NEW = new Action(IDEActions.FileNew, "MENU_FILE_NEW"c, "document-new", KeyCode.KEY_N, KeyFlag.Control); const Action ACTION_FILE_NEW = new Action(IDEActions.FileNew, "MENU_FILE_NEW"c, "document-new", KeyCode.KEY_N, KeyFlag
const Action ACTION_FILE_SAVE = (new Action(IDEActions.FileSave, "MENU_FILE_SAVE"c, "document-save", KeyCode.KEY_S, KeyFlag.Control)).disableByDefault(); .Control);
const Action ACTION_FILE_SAVE_AS = (new Action(IDEActions.FileSaveAs, "MENU_FILE_SAVE_AS"c)).disableByDefault(); const Action ACTION_FILE_SAVE = (new Action(IDEActions.FileSave, "MENU_FILE_SAVE"c, "document-save", KeyCode.KEY_S, KeyFlag
const Action ACTION_FILE_OPEN = new Action(IDEActions.FileOpen, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control); .Control)).disableByDefault();
const Action ACTION_FILE_EXIT = new Action(IDEActions.FileExit, "MENU_FILE_EXIT"c, "document-close"c, KeyCode.KEY_X, KeyFlag.Alt); const Action ACTION_FILE_SAVE_AS = (new Action(IDEActions.FileSaveAs, "MENU_FILE_SAVE_AS"c))
const Action ACTION_EDIT_COPY = (new Action(EditorActions.Copy, "MENU_EDIT_COPY"c, "edit-copy"c, KeyCode.KEY_C, KeyFlag.Control)).addAccelerator(KeyCode.INS, KeyFlag.Control).disableByDefault(); .disableByDefault();
const Action ACTION_EDIT_PASTE = (new Action(EditorActions.Paste, "MENU_EDIT_PASTE"c, "edit-paste"c, KeyCode.KEY_V, KeyFlag.Control)).addAccelerator(KeyCode.INS, KeyFlag.Shift).disableByDefault(); const Action ACTION_FILE_OPEN = new Action(IDEActions.FileOpen, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag
const Action ACTION_EDIT_CUT = (new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut"c, KeyCode.KEY_X, KeyFlag.Control)).addAccelerator(KeyCode.DEL, KeyFlag.Shift).disableByDefault(); .Control);
const Action ACTION_EDIT_UNDO = (new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo"c, KeyCode.KEY_Z, KeyFlag.Control)).disableByDefault(); const Action ACTION_FILE_EXIT = new Action(IDEActions.FileExit, "MENU_FILE_EXIT"c, "document-close"c, KeyCode.KEY_X, KeyFlag
const Action ACTION_EDIT_REDO = (new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo"c, KeyCode.KEY_Y, KeyFlag.Control)).addAccelerator(KeyCode.KEY_Z, KeyFlag.Control|KeyFlag.Shift).disableByDefault(); .Alt);
const Action ACTION_EDIT_INDENT = (new Action(EditorActions.Indent, "MENU_EDIT_INDENT"c, "edit-indent"c, KeyCode.TAB, 0)).addAccelerator(KeyCode.KEY_BRACKETCLOSE, KeyFlag.Control).disableByDefault(); const Action ACTION_EDIT_COPY = (new Action(EditorActions.Copy, "MENU_EDIT_COPY"c, "edit-copy"c, KeyCode.KEY_C, KeyFlag
const Action ACTION_EDIT_UNINDENT = (new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode.TAB, KeyFlag.Shift)).addAccelerator(KeyCode.KEY_BRACKETOPEN, KeyFlag.Control).disableByDefault(); .Control)).addAccelerator(KeyCode.INS, KeyFlag.Control).disableByDefault();
const Action ACTION_EDIT_TOGGLE_LINE_COMMENT = (new Action(EditorActions.ToggleLineComment, "MENU_EDIT_TOGGLE_LINE_COMMENT"c, null, KeyCode.KEY_DIVIDE, KeyFlag.Control)).disableByDefault(); const Action ACTION_EDIT_PASTE = (new Action(EditorActions.Paste, "MENU_EDIT_PASTE"c, "edit-paste"c, KeyCode.KEY_V, KeyFlag
const Action ACTION_EDIT_TOGGLE_BLOCK_COMMENT = (new Action(EditorActions.ToggleBlockComment, "MENU_EDIT_TOGGLE_BLOCK_COMMENT"c, null, KeyCode.KEY_DIVIDE, KeyFlag.Control|KeyFlag.Shift)).disableByDefault(); .Control)).addAccelerator(KeyCode.INS, KeyFlag.Shift).disableByDefault();
const Action ACTION_EDIT_PREFERENCES = (new Action(IDEActions.EditPreferences, "MENU_EDIT_PREFERENCES"c, null)).disableByDefault(); const Action ACTION_EDIT_CUT = (new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut"c, KeyCode.KEY_X, KeyFlag
const Action ACTION_DEBUG_START = new Action(IDEActions.DebugStart, "MENU_DEBUG_UPDATE_PREVIEW"c, "debug-run"c, KeyCode.F5, 0); .Control)).addAccelerator(KeyCode.DEL, KeyFlag.Shift).disableByDefault();
const Action ACTION_EDIT_UNDO = (new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo"c, KeyCode.KEY_Z, KeyFlag
.Control)).disableByDefault();
const Action ACTION_EDIT_REDO = (new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo"c, KeyCode.KEY_Y, KeyFlag
.Control)).addAccelerator(KeyCode.KEY_Z, KeyFlag.Control | KeyFlag.Shift)
.disableByDefault();
const Action ACTION_EDIT_INDENT = (new Action(EditorActions.Indent, "MENU_EDIT_INDENT"c, "edit-indent"c, KeyCode.TAB, 0))
.addAccelerator(KeyCode.KEY_BRACKETCLOSE, KeyFlag.Control).disableByDefault();
const Action ACTION_EDIT_UNINDENT = (new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode
.TAB, KeyFlag.Shift)).addAccelerator(KeyCode.KEY_BRACKETOPEN, KeyFlag.Control)
.disableByDefault();
const Action ACTION_EDIT_TOGGLE_LINE_COMMENT = (new Action(EditorActions.ToggleLineComment, "MENU_EDIT_TOGGLE_LINE_COMMENT"c, null, KeyCode
.KEY_DIVIDE, KeyFlag.Control)).disableByDefault();
const Action ACTION_EDIT_TOGGLE_BLOCK_COMMENT = (new Action(EditorActions.ToggleBlockComment, "MENU_EDIT_TOGGLE_BLOCK_COMMENT"c, null, KeyCode
.KEY_DIVIDE, KeyFlag.Control | KeyFlag.Shift)).disableByDefault();
const Action ACTION_EDIT_PREFERENCES = (new Action(IDEActions.EditPreferences, "MENU_EDIT_PREFERENCES"c, null))
.disableByDefault();
const Action ACTION_DEBUG_START = new Action(IDEActions.DebugStart, "MENU_DEBUG_UPDATE_PREVIEW"c, "debug-run"c, KeyCode
.F5, 0);
const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABOUT"c); const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABOUT"c);
/// DIDE source file editor /// DIDE source file editor
class DMLSourceEdit : SourceEdit { class DMLSourceEdit : SourceEdit
this(string ID) { {
this(string ID)
{
super(ID); super(ID);
MenuItem editPopupItem = new MenuItem(null); MenuItem editPopupItem = new MenuItem(null);
editPopupItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_DEBUG_START); editPopupItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_DEBUG_START);
@ -57,21 +79,23 @@ class DMLSourceEdit : SourceEdit {
content.syntaxSupport = new DMLSyntaxSupport(""); content.syntaxSupport = new DMLSyntaxSupport("");
setTokenHightlightColor(TokenCategory.Comment, 0x008000); // green setTokenHightlightColor(TokenCategory.Comment, 0x008000); // green
setTokenHightlightColor(TokenCategory.Keyword, 0x0000FF); // blue setTokenHightlightColor(TokenCategory.Keyword, 0x0000FF); // blue
setTokenHightlightColor(TokenCategory.String, 0xa31515); // brown setTokenHightlightColor(TokenCategory.String, 0xa31515); // brown
setTokenHightlightColor(TokenCategory.Integer, 0xa315C0); // setTokenHightlightColor(TokenCategory.Integer, 0xa315C0); //
setTokenHightlightColor(TokenCategory.Float, 0xa315C0); // setTokenHightlightColor(TokenCategory.Float, 0xa315C0); //
setTokenHightlightColor(TokenCategory.Error, 0xFF0000); // red setTokenHightlightColor(TokenCategory.Error, 0xFF0000); // red
setTokenHightlightColor(TokenCategory.Op, 0x503000); setTokenHightlightColor(TokenCategory.Op, 0x503000);
setTokenHightlightColor(TokenCategory.Identifier_Class, 0x000080); // blue setTokenHightlightColor(TokenCategory.Identifier_Class, 0x000080); // blue
} }
this() {
this()
{
this("DMLEDIT"); this("DMLEDIT");
} }
} }
immutable dstring SAMPLE_SOURCE_CODE = immutable dstring SAMPLE_SOURCE_CODE =
q{VerticalLayout { q{VerticalLayout {
id: vlayout id: vlayout
margins: Rect { left: 5; right: 3; top: 2; bottom: 4 } margins: Rect { left: 5; right: 3; top: 2; bottom: 4 }
padding: Rect { 5, 4, 3, 2 } // same as Rect { left: 5; top: 4; right: 3; bottom: 2 } padding: Rect { 5, 4, 3, 2 } // same as Rect { left: 5; top: 4; right: 3; bottom: 2 }
@ -99,27 +123,30 @@ q{VerticalLayout {
// used to generate property lists once, then simply swap // used to generate property lists once, then simply swap
StringListAdapter[string] propListsAdapters; StringListAdapter[string] propListsAdapters;
class EditFrame : AppFrame { class EditFrame : AppFrame
{
MenuItem mainMenuItems; MenuItem mainMenuItems;
override protected void initialize() { override protected void initialize()
{
_appName = "DMLEdit"; _appName = "DMLEdit";
super.initialize(); super.initialize();
updatePreview(); updatePreview();
} }
/// create main menu /// create main menu
override protected MainMenu createMainMenu() { override protected MainMenu createMainMenu()
{
mainMenuItems = new MenuItem(); mainMenuItems = new MenuItem();
MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE")); MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE"));
fileItem.add(ACTION_FILE_NEW, ACTION_FILE_OPEN, fileItem.add(ACTION_FILE_NEW, ACTION_FILE_OPEN,
ACTION_FILE_EXIT); ACTION_FILE_EXIT);
mainMenuItems.add(fileItem); mainMenuItems.add(fileItem);
MenuItem editItem = new MenuItem(new Action(2, "MENU_EDIT")); MenuItem editItem = new MenuItem(new Action(2, "MENU_EDIT"));
editItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, editItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE,
ACTION_EDIT_CUT, ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_CUT, ACTION_EDIT_UNDO, ACTION_EDIT_REDO,
ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_EDIT_TOGGLE_BLOCK_COMMENT, ACTION_DEBUG_START); ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_EDIT_TOGGLE_BLOCK_COMMENT, ACTION_DEBUG_START);
editItem.add(ACTION_EDIT_PREFERENCES); editItem.add(ACTION_EDIT_PREFERENCES);
mainMenuItems.add(editItem); mainMenuItems.add(editItem);
@ -127,9 +154,9 @@ class EditFrame : AppFrame {
return mainMenu; return mainMenu;
} }
/// create app toolbars /// create app toolbars
override protected ToolBarHost createToolbars() { override protected ToolBarHost createToolbars()
{
ToolBarHost res = new ToolBarHost(); ToolBarHost res = new ToolBarHost();
ToolBar tb; ToolBar tb;
tb = res.getOrAddToolbar("Standard"); tb = res.getOrAddToolbar("Standard");
@ -137,15 +164,18 @@ class EditFrame : AppFrame {
tb = res.getOrAddToolbar("Edit"); tb = res.getOrAddToolbar("Edit");
tb.addButtons(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_SEPARATOR, tb.addButtons(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_SEPARATOR,
ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT); ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT);
return res; return res;
} }
string _filename; string _filename;
void openSourceFile(string filename) { void openSourceFile(string filename)
{
import std.file; import std.file;
// TODO // TODO
if (exists(filename)) { if (exists(filename))
{
_filename = filename; _filename = filename;
window.windowCaption = toUTF32(filename); window.windowCaption = toUTF32(filename);
_editor.load(filename); _editor.load(filename);
@ -153,21 +183,25 @@ class EditFrame : AppFrame {
} }
} }
void saveSourceFile(string filename) { void saveSourceFile(string filename)
{
if (filename.length == 0) if (filename.length == 0)
filename = _filename; filename = _filename;
import std.file; import std.file;
_filename = filename; _filename = filename;
window.windowCaption = toUTF32(filename); window.windowCaption = toUTF32(filename);
_editor.save(filename); _editor.save(filename);
} }
bool onCanClose() { bool onCanClose()
{
// todo // todo
return true; return true;
} }
FileDialog createFileDialog(UIString caption, bool fileMustExist = true) { FileDialog createFileDialog(UIString caption, bool fileMustExist = true)
{
uint flags = DialogFlag.Modal | DialogFlag.Resizable; uint flags = DialogFlag.Modal | DialogFlag.Resizable;
if (fileMustExist) if (fileMustExist)
flags |= FileDialogFlag.FileMustExist; flags |= FileDialogFlag.FileMustExist;
@ -176,107 +210,120 @@ class EditFrame : AppFrame {
return dlg; return dlg;
} }
void saveAs() { void saveAs()
{
} }
/// override to handle specific actions /// override to handle specific actions
override bool handleAction(const Action a) { override bool handleAction(const Action a)
if (a) { {
switch (a.id) { if (a)
case IDEActions.FileExit: {
if (onCanClose()) switch (a.id)
window.close(); {
return true; case IDEActions.FileExit:
case IDEActions.HelpAbout: if (onCanClose())
window.showMessageBox(UIString.fromRaw("About DlangUI ML Editor"d), window.close();
UIString.fromRaw("DLangIDE\n(C) Vadim Lopatin, 2015\nhttp://github.com/buggins/dlangui\nSimple editor for DML code"d)); return true;
return true; case IDEActions.HelpAbout:
case IDEActions.FileNew: window.showMessageBox(UIString.fromRaw("About DlangUI ML Editor"d),
UIString caption; UIString.fromRaw(
caption = "Create new DML file"d; "DLangIDE\n(C) Vadim Lopatin, 2015\nhttp://github.com/buggins/dlangui\nSimple editor for DML code"d));
FileDialog dlg = createFileDialog(caption, false); return true;
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml")); case IDEActions.FileNew:
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*")); UIString caption;
dlg.dialogResult = delegate(Dialog dlg, const Action result) { caption = "Create new DML file"d;
if (result.id == ACTION_OPEN.id) { FileDialog dlg = createFileDialog(caption, false);
string filename = result.stringParam; dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
_editor.text=""d; dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
saveSourceFile(filename); dlg.dialogResult = delegate(Dialog dlg, const Action result) {
} if (result.id == ACTION_OPEN.id)
}; {
dlg.show(); string filename = result.stringParam;
return true; _editor.text = ""d;
case IDEActions.FileSave: saveSourceFile(filename);
if (_filename.length) {
saveSourceFile(_filename);
return true;
} }
UIString caption; };
caption = "Save DML File as"d; dlg.show();
FileDialog dlg = createFileDialog(caption, false); return true;
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml")); case IDEActions.FileSave:
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*")); if (_filename.length)
dlg.dialogResult = delegate(Dialog dlg, const Action result) { {
if (result.id == ACTION_OPEN.id) { saveSourceFile(_filename);
string filename = result.stringParam;
saveSourceFile(filename);
}
};
dlg.show();
return true; return true;
case IDEActions.FileOpen: }
UIString caption; UIString caption;
caption = "Open DML File"d; caption = "Save DML File as"d;
FileDialog dlg = createFileDialog(caption); FileDialog dlg = createFileDialog(caption, false);
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml")); dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*")); dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
dlg.dialogResult = delegate(Dialog dlg, const Action result) { dlg.dialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_OPEN.id) { if (result.id == ACTION_OPEN.id)
string filename = result.stringParam; {
openSourceFile(filename); string filename = result.stringParam;
} saveSourceFile(filename);
}; }
dlg.show(); };
return true; dlg.show();
case IDEActions.DebugStart: return true;
updatePreview(); case IDEActions.FileOpen:
return true; UIString caption;
case IDEActions.EditPreferences: caption = "Open DML File"d;
//showPreferences(); FileDialog dlg = createFileDialog(caption);
return true; dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
default: dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
return super.handleAction(a); dlg.dialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_OPEN.id)
{
string filename = result.stringParam;
openSourceFile(filename);
}
};
dlg.show();
return true;
case IDEActions.DebugStart:
updatePreview();
return true;
case IDEActions.EditPreferences:
//showPreferences();
return true;
default:
return super.handleAction(a);
} }
} }
return false; return false;
} }
/// override to handle specific actions state (e.g. change enabled state for supported actions) /// override to handle specific actions state (e.g. change enabled state for supported actions)
override bool handleActionStateRequest(const Action a) { override bool handleActionStateRequest(const Action a)
switch (a.id) { {
case IDEActions.HelpAbout: switch (a.id)
case IDEActions.FileNew: {
case IDEActions.FileOpen: case IDEActions.HelpAbout:
case IDEActions.DebugStart: case IDEActions.FileNew:
case IDEActions.EditPreferences: case IDEActions.FileOpen:
case IDEActions.FileSaveAs: case IDEActions.DebugStart:
case IDEActions.EditPreferences:
case IDEActions.FileSaveAs:
a.state = ACTION_STATE_ENABLED;
return true;
case IDEActions.FileSave:
if (_editor.content.modified)
a.state = ACTION_STATE_ENABLED; a.state = ACTION_STATE_ENABLED;
return true; else
case IDEActions.FileSave: a.state = ACTION_STATE_DISABLE;
if (_editor.content.modified) return true;
a.state = ACTION_STATE_ENABLED; default:
else return super.handleActionStateRequest(a);
a.state = ACTION_STATE_DISABLE;
return true;
default:
return super.handleActionStateRequest(a);
} }
} }
void updatePreview() { void updatePreview()
{
dstring dsource = _editor.text; dstring dsource = _editor.text;
string source = toUTF8(dsource); string source = toUTF8(dsource);
try { try
{
Widget w = parseML(source); Widget w = parseML(source);
if (statusLine) if (statusLine)
statusLine.setStatusText("No errors"d); statusLine.setStatusText("No errors"d);
@ -287,7 +334,9 @@ class EditFrame : AppFrame {
if (_highlightBackground) if (_highlightBackground)
w.backgroundColor = 0xC0C0C0C0; w.backgroundColor = 0xC0C0C0C0;
_preview.contentWidget = w; _preview.contentWidget = w;
} catch (ParserException e) { }
catch (ParserException e)
{
if (statusLine) if (statusLine)
statusLine.setStatusText(toUTF32("ERROR: " ~ e.msg)); statusLine.setStatusText(toUTF32("ERROR: " ~ e.msg));
_editor.setCaretPos(e.line, e.pos); _editor.setCaretPos(e.line, e.pos);
@ -307,6 +356,7 @@ class EditFrame : AppFrame {
protected bool _highlightBackground; protected bool _highlightBackground;
protected DMLSourceEdit _editor; protected DMLSourceEdit _editor;
protected ScrollWidget _preview; protected ScrollWidget _preview;
/// create app body widget /// create app body widget
override protected Widget createBody() override protected Widget createBody()
{ {
@ -324,17 +374,18 @@ class EditFrame : AppFrame {
auto registeredWidgetList = getRegisteredWidgetsList(); auto registeredWidgetList = getRegisteredWidgetsList();
registeredWidgetList.sort!("a < b"); registeredWidgetList.sort!("a < b");
foreach(const ref widget; registeredWidgetList) foreach (const ref widget; registeredWidgetList)
{ {
auto propertyListAdapter = new StringListAdapter(); auto propertyListAdapter = new StringListAdapter();
if ( auto meta = findWidgetMetadata(widget) ) if (auto meta = findWidgetMetadata(widget))
{ {
auto mp = meta.properties; auto mp = meta.properties;
mp.sort!("a.name < b.name"); mp.sort!("a.name < b.name");
foreach(const ref prop; mp) foreach (const ref prop; mp)
{ {
propertyListAdapter.add(UIString.fromRaw(prop.name ~ " [" ~ to!string(prop.type) ~ "]" )); propertyListAdapter.add(UIString.fromRaw(
propListsAdapters[widget] = propertyListAdapter; prop.name ~ " [" ~ to!string(prop.type) ~ "]"));
propListsAdapters[widget] = propertyListAdapter;
} }
} }
sla.add(UIString.fromRaw(widget)); sla.add(UIString.fromRaw(widget));
@ -342,15 +393,42 @@ class EditFrame : AppFrame {
widgetsList.adapter = sla; widgetsList.adapter = sla;
StringListAdapter origSla = new StringListAdapter();
for (int i = 0; i < sla.getItems.count; i++)
{
origSla.add(sla.items[i]);
}
auto leftPanel = new VerticalLayout(); auto leftPanel = new VerticalLayout();
leftPanel.layoutHeight = FILL_PARENT; leftPanel.layoutHeight = FILL_PARENT;
widgetsList.minHeight=800; widgetsList.minHeight = 800;
propList.minHeight=600; propList.minHeight = 600;
leftPanel.addChild(new TextWidget().text("Widgets").backgroundColor(0xdddddd).minHeight(50) ); auto searchBox = new EditLine().text("...").backgroundColor(0xffffff).minHeight(25);
searchBox.keyEvent = delegate(Widget w, KeyEvent e) {
string[] arr;
foreach (s; origSla.getItems)
arr ~= s;
arr = arr.filter!(x => x.toLower.canFind(searchBox.text.toLower)).array;
sla.clear();
foreach (string k; arr)
sla.add(k);
widgetsList.adapter = sla;
return false;
};
leftPanel.addChild(searchBox);
leftPanel.addChild(new TextWidget().text("Widgets").backgroundColor(0xdddddd).minHeight(25));
leftPanel.addChild(widgetsList); leftPanel.addChild(widgetsList);
leftPanel.addChild(new TextWidget().text("Widget properties").backgroundColor(0xdddddd).minHeight(50)); leftPanel.addChild(new TextWidget().text("Widget properties")
.backgroundColor(0xdddddd).minHeight(50));
leftPanel.addChild(propList); leftPanel.addChild(propList);
auto leftDockWin = new DockWindow("left dock"); auto leftDockWin = new DockWindow("left dock");
@ -393,11 +471,11 @@ class EditFrame : AppFrame {
updatePreview(); updatePreview();
return true; return true;
}; };
widgetsList.itemClick = delegate (Widget source, int itemIndex){ widgetsList.itemClick = delegate(Widget source, int itemIndex) {
propList.adapter = propListsAdapters[to!string(widgetsList.selectedItem)]; propList.adapter = propListsAdapters[to!string(widgetsList.selectedItem)];
return true; return true;
}; };
widgetsList.onItemDoubleClick = delegate (Widget source, int itemIndex) { widgetsList.onItemDoubleClick = delegate(Widget source, int itemIndex) {
auto caret = _editor.caretPos; auto caret = _editor.caretPos;
auto widgetClassName = widgetsList.selectedItem; auto widgetClassName = widgetsList.selectedItem;
EditOperation op = new EditOperation(EditAction.Replace, caret, widgetClassName); EditOperation op = new EditOperation(EditAction.Replace, caret, widgetClassName);
@ -428,15 +506,17 @@ class EditFrame : AppFrame {
} }
} }
alias onItemDoubleClickHandler = void delegate (Widget source, int itemIndex); alias onItemDoubleClickHandler = void delegate(Widget source, int itemIndex);
class WidgetsList : StringListWidget class WidgetsList : StringListWidget
{ {
onItemDoubleClickHandler onItemDoubleClick; onItemDoubleClickHandler onItemDoubleClick;
override bool onMouseEvent(MouseEvent event) { override bool onMouseEvent(MouseEvent event)
{
bool result = super.onMouseEvent(event); bool result = super.onMouseEvent(event);
if (event.doubleClick) { if (event.doubleClick)
{
if (onItemDoubleClick !is null) if (onItemDoubleClick !is null)
onItemDoubleClick(this, selectedItemIndex); onItemDoubleClick(this, selectedItemIndex);
} }
@ -445,7 +525,8 @@ class WidgetsList : StringListWidget
} }
/// entry point for dlangui based application /// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) { extern (C) int UIAppMain(string[] args)
{
// embed non-standard resources listed in views/resources.list into executable // embed non-standard resources listed in views/resources.list into executable
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")()); embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());

View File

@ -441,7 +441,7 @@ class UIStringTranslator {
return s; return s;
if (fallbackValue.length > 0) if (fallbackValue.length > 0)
return fallbackValue; return fallbackValue;
return "UNTRANSLATED: "d ~ toUTF32(id); return toUTF32(id);
} }
} }

File diff suppressed because it is too large Load Diff