mirror of https://github.com/buggins/dlangui.git
example1: support opening of file in separate tab with open file dialog
This commit is contained in:
parent
4bbab0b7ca
commit
00e4d207d4
|
@ -66,7 +66,7 @@
|
||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids>DebugFocus</debugids>
|
<debugids>DebugFocus</debugids>
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids>USE_OPENGL Unicode</versionids>
|
<versionids>Unicode</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>0</mapverbosity>
|
<mapverbosity>0</mapverbosity>
|
||||||
<createImplib>1</createImplib>
|
<createImplib>1</createImplib>
|
||||||
|
@ -389,6 +389,7 @@
|
||||||
<File path="src\dlangui\widgets\menu.d" />
|
<File path="src\dlangui\widgets\menu.d" />
|
||||||
<File path="src\dlangui\widgets\popup.d" />
|
<File path="src\dlangui\widgets\popup.d" />
|
||||||
<File path="src\dlangui\widgets\scroll.d" />
|
<File path="src\dlangui\widgets\scroll.d" />
|
||||||
|
<File path="src\dlangui\widgets\srcedit.d" />
|
||||||
<File path="src\dlangui\widgets\statusline.d" />
|
<File path="src\dlangui\widgets\statusline.d" />
|
||||||
<File path="src\dlangui\widgets\styles.d" />
|
<File path="src\dlangui\widgets\styles.d" />
|
||||||
<File path="src\dlangui\widgets\tabs.d" />
|
<File path="src\dlangui\widgets\tabs.d" />
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids />
|
<debugids />
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids>USE_OPENGL Unicode</versionids>
|
<versionids>Unicode</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>3</mapverbosity>
|
<mapverbosity>3</mapverbosity>
|
||||||
<createImplib>0</createImplib>
|
<createImplib>0</createImplib>
|
||||||
|
@ -89,7 +89,6 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
<cRuntime>2</cRuntime>
|
|
||||||
<additionalOptions>-profile</additionalOptions>
|
<additionalOptions>-profile</additionalOptions>
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
@ -184,7 +183,6 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
<cRuntime>1</cRuntime>
|
|
||||||
<additionalOptions />
|
<additionalOptions />
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
|
|
@ -22,6 +22,8 @@ import dlangui.dialogs.msgbox;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.utf;
|
import std.utf;
|
||||||
|
import std.algorithm;
|
||||||
|
import std.path;
|
||||||
|
|
||||||
|
|
||||||
mixin APP_ENTRY_POINT;
|
mixin APP_ENTRY_POINT;
|
||||||
|
@ -186,9 +188,10 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
// load theme from file "theme_default.xml"
|
// load theme from file "theme_default.xml"
|
||||||
Platform.instance.uiTheme = "theme_default";
|
Platform.instance.uiTheme = "theme_default";
|
||||||
|
|
||||||
// you can override default hinting mode here
|
// you can override default hinting mode here (Normal, AutoHint, Disabled)
|
||||||
FontManager.instance.hintingMode = HintingMode.Normal;
|
FontManager.instance.hintingMode = HintingMode.Normal;
|
||||||
// you can override antialiasing setting here
|
// you can override antialiasing setting here (0 means antialiasing always on, some big value = always off)
|
||||||
|
// fonts with size less than specified value will not be antialiased
|
||||||
FontManager.instance.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
FontManager.instance.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
||||||
|
|
||||||
// create window
|
// create window
|
||||||
|
@ -197,6 +200,8 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
static if (true) {
|
static if (true) {
|
||||||
VerticalLayout contentLayout = new VerticalLayout();
|
VerticalLayout contentLayout = new VerticalLayout();
|
||||||
|
|
||||||
|
TabWidget tabs = new TabWidget("TABS");
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
// create main menu
|
// create main menu
|
||||||
|
|
||||||
|
@ -303,8 +308,29 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
//dlg.filterIndex = 2;
|
//dlg.filterIndex = 2;
|
||||||
dlg.onDialogResult = delegate(Dialog dlg, const Action result) {
|
dlg.onDialogResult = delegate(Dialog dlg, const Action result) {
|
||||||
if (result.id == ACTION_OPEN.id) {
|
if (result.id == ACTION_OPEN.id) {
|
||||||
|
string filename = result.stringParam;
|
||||||
|
if (filename.endsWith(".d") || filename.endsWith(".txt") || filename.endsWith(".cpp") || filename.endsWith(".h") || filename.endsWith(".c")
|
||||||
|
|| filename.endsWith(".json") || filename.endsWith(".dd") || filename.endsWith(".ddoc") || filename.endsWith(".xml") || filename.endsWith(".html")
|
||||||
|
|| filename.endsWith(".html") || filename.endsWith(".css") || filename.endsWith(".log") || filename.endsWith(".hpp")) {
|
||||||
|
// open source file in tab
|
||||||
|
int index = tabs.tabIndex(filename);
|
||||||
|
if (index >= 0) {
|
||||||
|
// file is already opened in tab
|
||||||
|
tabs.selectTab(index, true);
|
||||||
|
} else {
|
||||||
|
SourceEdit editor = new SourceEdit(filename);
|
||||||
|
if (editor.load(filename)) {
|
||||||
|
tabs.addTab(editor, toUTF32(baseName(filename)));
|
||||||
|
tabs.selectTab(filename);
|
||||||
|
} else {
|
||||||
|
destroy(editor);
|
||||||
|
window.showMessageBox(UIString("File open error"d), UIString("Cannot open file "d ~ toUTF32(filename)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
|
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
|
||||||
window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam)));
|
window.showMessageBox(UIString("FileOpen result"d), UIString("Filename: "d ~ toUTF32(filename)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -321,7 +347,6 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
// ========= create tabs ===================
|
// ========= create tabs ===================
|
||||||
|
|
||||||
TabWidget tabs = new TabWidget("TABS");
|
|
||||||
tabs.onTabChangedListener = delegate(string newTabId, string oldTabId) {
|
tabs.onTabChangedListener = delegate(string newTabId, string oldTabId) {
|
||||||
window.windowCaption = tabs.tab(newTabId).text.value ~ " - dlangui example 1"d;
|
window.windowCaption = tabs.tab(newTabId).text.value ~ " - dlangui example 1"d;
|
||||||
};
|
};
|
||||||
|
|
|
@ -463,22 +463,22 @@ class FontManager {
|
||||||
/// removes entries not used after last call of checkpoint() or cleanup()
|
/// removes entries not used after last call of checkpoint() or cleanup()
|
||||||
abstract void cleanup();
|
abstract void cleanup();
|
||||||
|
|
||||||
/// get min font size for antialiased fonts
|
/// get min font size for antialiased fonts (0 means antialiasing always on, some big value = always off)
|
||||||
@property int minAnitialiasedFontSize() {
|
@property int minAnitialiasedFontSize() {
|
||||||
return _minAnitialiasedFontSize;
|
return _minAnitialiasedFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set new min font size for antialiased fonts
|
/// set new min font size for antialiased fonts - fonts with size >= specified value will be antialiased (0 means antialiasing always on, some big value = always off)
|
||||||
@property void minAnitialiasedFontSize(int size) {
|
@property void minAnitialiasedFontSize(int size) {
|
||||||
_minAnitialiasedFontSize = size;
|
_minAnitialiasedFontSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get current hinting mode
|
/// get current hinting mode (Normal, AutoHint, Disabled)
|
||||||
@property HintingMode hintingMode() {
|
@property HintingMode hintingMode() {
|
||||||
return _hintingMode;
|
return _hintingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set hinting mode
|
/// set hinting mode (Normal, AutoHint, Disabled)
|
||||||
@property void hintingMode(HintingMode mode) {
|
@property void hintingMode(HintingMode mode) {
|
||||||
_hintingMode = mode;
|
_hintingMode = mode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,6 +476,15 @@ class TabHost : FrameLayout, TabHandler {
|
||||||
onTabChangedListener(newActiveTabId, previousTabId);
|
onTabChangedListener(newActiveTabId, previousTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get tab content widget by id
|
||||||
|
Widget tabBody(string id) {
|
||||||
|
for (int i = 0; i < _children.count; i++) {
|
||||||
|
if (_children[i].compareId(id))
|
||||||
|
return _children[i];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// remove tab
|
/// remove tab
|
||||||
TabHost removeTab(string id) {
|
TabHost removeTab(string id) {
|
||||||
assert(_tabControl !is null, "No TabControl set for TabHost");
|
assert(_tabControl !is null, "No TabControl set for TabHost");
|
||||||
|
@ -588,6 +597,11 @@ class TabWidget : VerticalLayout, TabHandler {
|
||||||
_tabControl.selectTab(index, updateAccess);
|
_tabControl.selectTab(index, updateAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get tab content widget by id
|
||||||
|
Widget tabBody(string id) {
|
||||||
|
return _tabHost.tabBody(id);
|
||||||
|
}
|
||||||
|
|
||||||
/// returns tab item by id (null if index out of range)
|
/// returns tab item by id (null if index out of range)
|
||||||
TabItem tab(int index) {
|
TabItem tab(int index) {
|
||||||
return _tabControl.tab(index);
|
return _tabControl.tab(index);
|
||||||
|
|
Loading…
Reference in New Issue