mirror of https://github.com/buggins/dlangui.git
It works
This commit is contained in:
parent
d584a75ae6
commit
dc730a99ea
|
@ -8,13 +8,15 @@ import dlangui.widgets.metadata;
|
|||
import std.array : replaceFirst;
|
||||
import std.algorithm;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import std.array;
|
||||
import std.file;
|
||||
|
||||
mixin APP_ENTRY_POINT;
|
||||
|
||||
// action codes
|
||||
enum IDEActions : int {
|
||||
enum IDEActions : int
|
||||
{
|
||||
//ProjectOpen = 1010000,
|
||||
FileNew = 1010000,
|
||||
FileOpen,
|
||||
|
@ -29,27 +31,47 @@ enum IDEActions : int {
|
|||
}
|
||||
|
||||
// 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_SAVE = (new Action(IDEActions.FileSave, "MENU_FILE_SAVE"c, "document-save", KeyCode.KEY_S, KeyFlag.Control)).disableByDefault();
|
||||
const Action ACTION_FILE_SAVE_AS = (new Action(IDEActions.FileSaveAs, "MENU_FILE_SAVE_AS"c)).disableByDefault();
|
||||
const Action ACTION_FILE_OPEN = new Action(IDEActions.FileOpen, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control);
|
||||
const Action ACTION_FILE_EXIT = new Action(IDEActions.FileExit, "MENU_FILE_EXIT"c, "document-close"c, KeyCode.KEY_X, KeyFlag.Alt);
|
||||
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();
|
||||
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_EDIT_CUT = (new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut"c, KeyCode.KEY_X, KeyFlag.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_FILE_NEW = new Action(IDEActions.FileNew, "MENU_FILE_NEW"c, "document-new", KeyCode.KEY_N, KeyFlag
|
||||
.Control);
|
||||
const Action ACTION_FILE_SAVE = (new Action(IDEActions.FileSave, "MENU_FILE_SAVE"c, "document-save", KeyCode.KEY_S, KeyFlag
|
||||
.Control)).disableByDefault();
|
||||
const Action ACTION_FILE_SAVE_AS = (new Action(IDEActions.FileSaveAs, "MENU_FILE_SAVE_AS"c))
|
||||
.disableByDefault();
|
||||
const Action ACTION_FILE_OPEN = new Action(IDEActions.FileOpen, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag
|
||||
.Control);
|
||||
const Action ACTION_FILE_EXIT = new Action(IDEActions.FileExit, "MENU_FILE_EXIT"c, "document-close"c, KeyCode.KEY_X, KeyFlag
|
||||
.Alt);
|
||||
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();
|
||||
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_EDIT_CUT = (new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut"c, KeyCode.KEY_X, KeyFlag
|
||||
.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);
|
||||
|
||||
/// DIDE source file editor
|
||||
class DMLSourceEdit : SourceEdit {
|
||||
this(string ID) {
|
||||
class DMLSourceEdit : SourceEdit
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
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);
|
||||
|
@ -57,21 +79,23 @@ class DMLSourceEdit : SourceEdit {
|
|||
content.syntaxSupport = new DMLSyntaxSupport("");
|
||||
setTokenHightlightColor(TokenCategory.Comment, 0x008000); // green
|
||||
setTokenHightlightColor(TokenCategory.Keyword, 0x0000FF); // blue
|
||||
setTokenHightlightColor(TokenCategory.String, 0xa31515); // brown
|
||||
setTokenHightlightColor(TokenCategory.Integer, 0xa315C0); //
|
||||
setTokenHightlightColor(TokenCategory.Float, 0xa315C0); //
|
||||
setTokenHightlightColor(TokenCategory.Error, 0xFF0000); // red
|
||||
setTokenHightlightColor(TokenCategory.String, 0xa31515); // brown
|
||||
setTokenHightlightColor(TokenCategory.Integer, 0xa315C0); //
|
||||
setTokenHightlightColor(TokenCategory.Float, 0xa315C0); //
|
||||
setTokenHightlightColor(TokenCategory.Error, 0xFF0000); // red
|
||||
setTokenHightlightColor(TokenCategory.Op, 0x503000);
|
||||
setTokenHightlightColor(TokenCategory.Identifier_Class, 0x000080); // blue
|
||||
setTokenHightlightColor(TokenCategory.Identifier_Class, 0x000080); // blue
|
||||
|
||||
}
|
||||
this() {
|
||||
|
||||
this()
|
||||
{
|
||||
this("DMLEDIT");
|
||||
}
|
||||
}
|
||||
|
||||
immutable dstring SAMPLE_SOURCE_CODE =
|
||||
q{VerticalLayout {
|
||||
q{VerticalLayout {
|
||||
id: vlayout
|
||||
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 }
|
||||
|
@ -99,27 +123,30 @@ q{VerticalLayout {
|
|||
// used to generate property lists once, then simply swap
|
||||
StringListAdapter[string] propListsAdapters;
|
||||
|
||||
class EditFrame : AppFrame {
|
||||
class EditFrame : AppFrame
|
||||
{
|
||||
|
||||
MenuItem mainMenuItems;
|
||||
|
||||
override protected void initialize() {
|
||||
override protected void initialize()
|
||||
{
|
||||
_appName = "DMLEdit";
|
||||
super.initialize();
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
/// create main menu
|
||||
override protected MainMenu createMainMenu() {
|
||||
override protected MainMenu createMainMenu()
|
||||
{
|
||||
mainMenuItems = new MenuItem();
|
||||
MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE"));
|
||||
fileItem.add(ACTION_FILE_NEW, ACTION_FILE_OPEN,
|
||||
ACTION_FILE_EXIT);
|
||||
ACTION_FILE_EXIT);
|
||||
mainMenuItems.add(fileItem);
|
||||
MenuItem editItem = new MenuItem(new Action(2, "MENU_EDIT"));
|
||||
editItem.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_EDIT_TOGGLE_BLOCK_COMMENT, ACTION_DEBUG_START);
|
||||
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);
|
||||
|
||||
editItem.add(ACTION_EDIT_PREFERENCES);
|
||||
mainMenuItems.add(editItem);
|
||||
|
@ -127,9 +154,9 @@ class EditFrame : AppFrame {
|
|||
return mainMenu;
|
||||
}
|
||||
|
||||
|
||||
/// create app toolbars
|
||||
override protected ToolBarHost createToolbars() {
|
||||
override protected ToolBarHost createToolbars()
|
||||
{
|
||||
ToolBarHost res = new ToolBarHost();
|
||||
ToolBar tb;
|
||||
tb = res.getOrAddToolbar("Standard");
|
||||
|
@ -137,15 +164,18 @@ class EditFrame : AppFrame {
|
|||
|
||||
tb = res.getOrAddToolbar("Edit");
|
||||
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;
|
||||
}
|
||||
|
||||
string _filename;
|
||||
void openSourceFile(string filename) {
|
||||
void openSourceFile(string filename)
|
||||
{
|
||||
import std.file;
|
||||
|
||||
// TODO
|
||||
if (exists(filename)) {
|
||||
if (exists(filename))
|
||||
{
|
||||
_filename = filename;
|
||||
window.windowCaption = toUTF32(filename);
|
||||
_editor.load(filename);
|
||||
|
@ -153,21 +183,25 @@ class EditFrame : AppFrame {
|
|||
}
|
||||
}
|
||||
|
||||
void saveSourceFile(string filename) {
|
||||
void saveSourceFile(string filename)
|
||||
{
|
||||
if (filename.length == 0)
|
||||
filename = _filename;
|
||||
import std.file;
|
||||
|
||||
_filename = filename;
|
||||
window.windowCaption = toUTF32(filename);
|
||||
_editor.save(filename);
|
||||
}
|
||||
|
||||
bool onCanClose() {
|
||||
bool onCanClose()
|
||||
{
|
||||
// todo
|
||||
return true;
|
||||
}
|
||||
|
||||
FileDialog createFileDialog(UIString caption, bool fileMustExist = true) {
|
||||
FileDialog createFileDialog(UIString caption, bool fileMustExist = true)
|
||||
{
|
||||
uint flags = DialogFlag.Modal | DialogFlag.Resizable;
|
||||
if (fileMustExist)
|
||||
flags |= FileDialogFlag.FileMustExist;
|
||||
|
@ -176,107 +210,120 @@ class EditFrame : AppFrame {
|
|||
return dlg;
|
||||
}
|
||||
|
||||
void saveAs() {
|
||||
void saveAs()
|
||||
{
|
||||
}
|
||||
|
||||
/// override to handle specific actions
|
||||
override bool handleAction(const Action a) {
|
||||
if (a) {
|
||||
switch (a.id) {
|
||||
case IDEActions.FileExit:
|
||||
if (onCanClose())
|
||||
window.close();
|
||||
return true;
|
||||
case IDEActions.HelpAbout:
|
||||
window.showMessageBox(UIString.fromRaw("About DlangUI ML Editor"d),
|
||||
UIString.fromRaw("DLangIDE\n(C) Vadim Lopatin, 2015\nhttp://github.com/buggins/dlangui\nSimple editor for DML code"d));
|
||||
return true;
|
||||
case IDEActions.FileNew:
|
||||
UIString caption;
|
||||
caption = "Create new DML file"d;
|
||||
FileDialog dlg = createFileDialog(caption, false);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
dlg.dialogResult = delegate(Dialog dlg, const Action result) {
|
||||
if (result.id == ACTION_OPEN.id) {
|
||||
string filename = result.stringParam;
|
||||
_editor.text=""d;
|
||||
saveSourceFile(filename);
|
||||
}
|
||||
};
|
||||
dlg.show();
|
||||
return true;
|
||||
case IDEActions.FileSave:
|
||||
if (_filename.length) {
|
||||
saveSourceFile(_filename);
|
||||
return true;
|
||||
override bool handleAction(const Action a)
|
||||
{
|
||||
if (a)
|
||||
{
|
||||
switch (a.id)
|
||||
{
|
||||
case IDEActions.FileExit:
|
||||
if (onCanClose())
|
||||
window.close();
|
||||
return true;
|
||||
case IDEActions.HelpAbout:
|
||||
window.showMessageBox(UIString.fromRaw("About DlangUI ML Editor"d),
|
||||
UIString.fromRaw(
|
||||
"DLangIDE\n(C) Vadim Lopatin, 2015\nhttp://github.com/buggins/dlangui\nSimple editor for DML code"d));
|
||||
return true;
|
||||
case IDEActions.FileNew:
|
||||
UIString caption;
|
||||
caption = "Create new DML file"d;
|
||||
FileDialog dlg = createFileDialog(caption, false);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
dlg.dialogResult = delegate(Dialog dlg, const Action result) {
|
||||
if (result.id == ACTION_OPEN.id)
|
||||
{
|
||||
string filename = result.stringParam;
|
||||
_editor.text = ""d;
|
||||
saveSourceFile(filename);
|
||||
}
|
||||
UIString caption;
|
||||
caption = "Save DML File as"d;
|
||||
FileDialog dlg = createFileDialog(caption, false);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
dlg.dialogResult = delegate(Dialog dlg, const Action result) {
|
||||
if (result.id == ACTION_OPEN.id) {
|
||||
string filename = result.stringParam;
|
||||
saveSourceFile(filename);
|
||||
}
|
||||
};
|
||||
dlg.show();
|
||||
};
|
||||
dlg.show();
|
||||
return true;
|
||||
case IDEActions.FileSave:
|
||||
if (_filename.length)
|
||||
{
|
||||
saveSourceFile(_filename);
|
||||
return true;
|
||||
case IDEActions.FileOpen:
|
||||
UIString caption;
|
||||
caption = "Open DML File"d;
|
||||
FileDialog dlg = createFileDialog(caption);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
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);
|
||||
}
|
||||
UIString caption;
|
||||
caption = "Save DML File as"d;
|
||||
FileDialog dlg = createFileDialog(caption, false);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
dlg.dialogResult = delegate(Dialog dlg, const Action result) {
|
||||
if (result.id == ACTION_OPEN.id)
|
||||
{
|
||||
string filename = result.stringParam;
|
||||
saveSourceFile(filename);
|
||||
}
|
||||
};
|
||||
dlg.show();
|
||||
return true;
|
||||
case IDEActions.FileOpen:
|
||||
UIString caption;
|
||||
caption = "Open DML File"d;
|
||||
FileDialog dlg = createFileDialog(caption);
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("DML files"d), "*.dml"));
|
||||
dlg.addFilter(FileFilterEntry(UIString.fromRaw("All files"d), "*.*"));
|
||||
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;
|
||||
}
|
||||
|
||||
/// override to handle specific actions state (e.g. change enabled state for supported actions)
|
||||
override bool handleActionStateRequest(const Action a) {
|
||||
switch (a.id) {
|
||||
case IDEActions.HelpAbout:
|
||||
case IDEActions.FileNew:
|
||||
case IDEActions.FileOpen:
|
||||
case IDEActions.DebugStart:
|
||||
case IDEActions.EditPreferences:
|
||||
case IDEActions.FileSaveAs:
|
||||
override bool handleActionStateRequest(const Action a)
|
||||
{
|
||||
switch (a.id)
|
||||
{
|
||||
case IDEActions.HelpAbout:
|
||||
case IDEActions.FileNew:
|
||||
case IDEActions.FileOpen:
|
||||
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;
|
||||
return true;
|
||||
case IDEActions.FileSave:
|
||||
if (_editor.content.modified)
|
||||
a.state = ACTION_STATE_ENABLED;
|
||||
else
|
||||
a.state = ACTION_STATE_DISABLE;
|
||||
return true;
|
||||
default:
|
||||
return super.handleActionStateRequest(a);
|
||||
else
|
||||
a.state = ACTION_STATE_DISABLE;
|
||||
return true;
|
||||
default:
|
||||
return super.handleActionStateRequest(a);
|
||||
}
|
||||
}
|
||||
|
||||
void updatePreview() {
|
||||
void updatePreview()
|
||||
{
|
||||
dstring dsource = _editor.text;
|
||||
string source = toUTF8(dsource);
|
||||
try {
|
||||
try
|
||||
{
|
||||
Widget w = parseML(source);
|
||||
if (statusLine)
|
||||
statusLine.setStatusText("No errors"d);
|
||||
|
@ -287,7 +334,9 @@ class EditFrame : AppFrame {
|
|||
if (_highlightBackground)
|
||||
w.backgroundColor = 0xC0C0C0C0;
|
||||
_preview.contentWidget = w;
|
||||
} catch (ParserException e) {
|
||||
}
|
||||
catch (ParserException e)
|
||||
{
|
||||
if (statusLine)
|
||||
statusLine.setStatusText(toUTF32("ERROR: " ~ e.msg));
|
||||
_editor.setCaretPos(e.line, e.pos);
|
||||
|
@ -307,6 +356,7 @@ class EditFrame : AppFrame {
|
|||
protected bool _highlightBackground;
|
||||
protected DMLSourceEdit _editor;
|
||||
protected ScrollWidget _preview;
|
||||
|
||||
/// create app body widget
|
||||
override protected Widget createBody()
|
||||
{
|
||||
|
@ -324,17 +374,18 @@ class EditFrame : AppFrame {
|
|||
auto registeredWidgetList = getRegisteredWidgetsList();
|
||||
registeredWidgetList.sort!("a < b");
|
||||
|
||||
foreach(const ref widget; registeredWidgetList)
|
||||
{
|
||||
foreach (const ref widget; registeredWidgetList)
|
||||
{
|
||||
auto propertyListAdapter = new StringListAdapter();
|
||||
if ( auto meta = findWidgetMetadata(widget) )
|
||||
if (auto meta = findWidgetMetadata(widget))
|
||||
{
|
||||
auto mp = meta.properties;
|
||||
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) ~ "]" ));
|
||||
propListsAdapters[widget] = propertyListAdapter;
|
||||
propertyListAdapter.add(UIString.fromRaw(
|
||||
prop.name ~ " [" ~ to!string(prop.type) ~ "]"));
|
||||
propListsAdapters[widget] = propertyListAdapter;
|
||||
}
|
||||
}
|
||||
sla.add(UIString.fromRaw(widget));
|
||||
|
@ -342,15 +393,42 @@ class EditFrame : AppFrame {
|
|||
|
||||
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();
|
||||
leftPanel.layoutHeight = FILL_PARENT;
|
||||
|
||||
widgetsList.minHeight=800;
|
||||
propList.minHeight=600;
|
||||
widgetsList.minHeight = 800;
|
||||
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(new TextWidget().text("Widget properties").backgroundColor(0xdddddd).minHeight(50));
|
||||
leftPanel.addChild(new TextWidget().text("Widget properties")
|
||||
.backgroundColor(0xdddddd).minHeight(50));
|
||||
leftPanel.addChild(propList);
|
||||
|
||||
auto leftDockWin = new DockWindow("left dock");
|
||||
|
@ -393,11 +471,11 @@ class EditFrame : AppFrame {
|
|||
updatePreview();
|
||||
return true;
|
||||
};
|
||||
widgetsList.itemClick = delegate (Widget source, int itemIndex){
|
||||
widgetsList.itemClick = delegate(Widget source, int itemIndex) {
|
||||
propList.adapter = propListsAdapters[to!string(widgetsList.selectedItem)];
|
||||
return true;
|
||||
};
|
||||
widgetsList.onItemDoubleClick = delegate (Widget source, int itemIndex) {
|
||||
widgetsList.onItemDoubleClick = delegate(Widget source, int itemIndex) {
|
||||
auto caret = _editor.caretPos;
|
||||
auto widgetClassName = widgetsList.selectedItem;
|
||||
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
|
||||
{
|
||||
onItemDoubleClickHandler onItemDoubleClick;
|
||||
|
||||
override bool onMouseEvent(MouseEvent event) {
|
||||
override bool onMouseEvent(MouseEvent event)
|
||||
{
|
||||
bool result = super.onMouseEvent(event);
|
||||
if (event.doubleClick) {
|
||||
if (event.doubleClick)
|
||||
{
|
||||
if (onItemDoubleClick !is null)
|
||||
onItemDoubleClick(this, selectedItemIndex);
|
||||
}
|
||||
|
@ -445,7 +525,8 @@ class WidgetsList : StringListWidget
|
|||
}
|
||||
|
||||
/// 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
|
||||
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||
|
|
|
@ -441,7 +441,7 @@ class UIStringTranslator {
|
|||
return s;
|
||||
if (fallbackValue.length > 0)
|
||||
return fallbackValue;
|
||||
return "UNTRANSLATED: "d ~ toUTF32(id);
|
||||
return toUTF32(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue