Update code for dlangui 0.10.3

This commit is contained in:
Grim Maple 2023-05-18 22:57:40 +03:00
parent b822795449
commit 1bd86c66cd
5 changed files with 63 additions and 63 deletions

View File

@ -12,7 +12,7 @@
"stringImportPaths": ["views"], "stringImportPaths": ["views"],
"dependencies": { "dependencies": {
"dlangui": "~>0.10.2", "dlangui": "~>0.10.3",
"dcd": "~>0.16.0-beta.1" "dcd": "~>0.16.0-beta.1"
}, },

View File

@ -43,7 +43,7 @@ class DMDProfilerView : WidgetGroupDefaultDrawing {
class TraceFuncionGrid : StringGridWidgetBase { class TraceFuncionGrid : StringGridWidgetBase {
protected FunctionNode[] _list; protected FunctionNode[] _list;
protected dstring[] _colTitles; protected UIString[] _colTitles;
protected ulong _ticksPerSecond; protected ulong _ticksPerSecond;
this(string ID, FunctionNode[] list, ulong ticks_per_second) { this(string ID, FunctionNode[] list, ulong ticks_per_second) {
super(ID); super(ID);
@ -53,10 +53,10 @@ class TraceFuncionGrid : StringGridWidgetBase {
fullColumnOnLeft(false); fullColumnOnLeft(false);
fullRowOnTop(false); fullRowOnTop(false);
resize(4, cast(int)list.length); resize(4, cast(int)list.length);
setColTitle(0, "Function name"d); setColTitle(0, UIString.fromRaw("Function name"));
setColTitle(1, "Called"d); setColTitle(1, UIString.fromRaw("Called"));
setColTitle(2, "F us"d); setColTitle(2, UIString.fromRaw("F us"));
setColTitle(3, "F+D us"d); setColTitle(3, UIString.fromRaw("F+D us"));
showRowHeaders = false; showRowHeaders = false;
rowSelect = true; rowSelect = true;
minVisibleRows = 10; minVisibleRows = 10;
@ -80,54 +80,54 @@ class TraceFuncionGrid : StringGridWidgetBase {
buffer[i] = buf[k - i - 1]; buffer[i] = buf[k - i - 1];
return cast(dstring)buffer[0..k]; return cast(dstring)buffer[0..k];
} }
dstring formatDurationTicks(ulong n) { auto formatDurationTicks(ulong n) {
ulong v = n * 1000000 / _ticksPerSecond; ulong v = n * 1000000 / _ticksPerSecond;
return formatNumber(v, _numberFormatBuf[]); return UIString.fromRaw(formatNumber(v, _numberFormatBuf[]));
} }
/// get cell text /// get cell text
override dstring cellText(int col, int row) { override UIString cellText(int col, int row) {
import std.conv : to; import std.conv : to;
if (row < 0 || row >= _list.length) if (row < 0 || row >= _list.length)
return ""d; return UIString.fromRaw(""d);
FunctionNode entry = _list[row]; FunctionNode entry = _list[row];
switch (col) { switch (col) {
case 0: case 0:
string fn = entry.name; string fn = entry.name;
if (fn.length > 256) if (fn.length > 256)
fn = fn[0..256] ~ "..."; fn = fn[0..256] ~ "...";
return fn.to!dstring; return UIString.fromRaw(fn.to!dstring);
case 1: case 1:
return formatNumber(entry.number_of_calls, _numberFormatBuf); return UIString.fromRaw(formatNumber(entry.number_of_calls, _numberFormatBuf));
case 2: case 2:
return formatDurationTicks(entry.function_time); return formatDurationTicks(entry.function_time);
case 3: case 3:
return formatDurationTicks(entry.function_and_descendant_time); return formatDurationTicks(entry.function_and_descendant_time);
default: default:
return ""d; return UIString.fromRaw(""d);
} }
} }
/// set cell text /// set cell text
override StringGridWidgetBase setCellText(int col, int row, dstring text) { override StringGridWidgetBase setCellText(int col, int row, UIString text) {
// do nothing // do nothing
return this; return this;
} }
/// returns row header title /// returns row header title
override dstring rowTitle(int row) { override UIString rowTitle(int row) {
return ""d; return UIString.fromRaw(""d);
} }
/// set row header title /// set row header title
override StringGridWidgetBase setRowTitle(int row, dstring title) { override StringGridWidgetBase setRowTitle(int row, UIString title) {
return this; return this;
} }
/// returns row header title /// returns row header title
override dstring colTitle(int col) { override UIString colTitle(int col) {
return _colTitles[col]; return _colTitles[col];
} }
/// set col header title /// set col header title
override StringGridWidgetBase setColTitle(int col, dstring title) { override StringGridWidgetBase setColTitle(int col, UIString title) {
_colTitles[col] = title; _colTitles[col] = title;
return this; return this;
} }

View File

@ -38,7 +38,7 @@ class NewProjectDlg : Dialog {
IDEFrame _ide; IDEFrame _ide;
this(IDEFrame parent, bool newWorkspace, Workspace currentWorkspace, string dir) { this(IDEFrame parent, bool newWorkspace, Workspace currentWorkspace, string dir) {
super(newWorkspace ? UIString.fromId("OPTION_NEW_WORKSPACE"c) : UIString.fromId("OPTION_NEW_PROJECT"c), parent.window, super(newWorkspace ? UIString.fromId("OPTION_NEW_WORKSPACE"c) : UIString.fromId("OPTION_NEW_PROJECT"c), parent.window,
DialogFlag.Modal | DialogFlag.Resizable | DialogFlag.Popup, 500, 400); DialogFlag.Modal | DialogFlag.Resizable | DialogFlag.Popup, 500, 400);
_ide = parent; _ide = parent;
_icon = "dlangui-logo1"; _icon = "dlangui-logo1";
@ -64,8 +64,8 @@ class NewProjectDlg : Dialog {
margins: 5 margins: 5
layoutWidth: 25%; layoutHeight: fill layoutWidth: 25%; layoutHeight: fill
TextWidget { text: OPTION_PROJECT_TEMPLATE } TextWidget { text: OPTION_PROJECT_TEMPLATE }
StringListWidget { StringListWidget {
id: projectTemplateList id: projectTemplateList
layoutWidth: wrap; layoutHeight: fill layoutWidth: wrap; layoutHeight: fill
} }
} }
@ -73,8 +73,8 @@ class NewProjectDlg : Dialog {
margins: 5 margins: 5
layoutWidth: 40%; layoutHeight: fill layoutWidth: 40%; layoutHeight: fill
TextWidget { text: OPTION_TEMPLATE_DESCR } TextWidget { text: OPTION_TEMPLATE_DESCR }
EditBox { EditBox {
id: templateDescription; readOnly: true id: templateDescription; readOnly: true
layoutWidth: fill; layoutHeight: fill layoutWidth: fill; layoutHeight: fill
} }
} }
@ -82,7 +82,7 @@ class NewProjectDlg : Dialog {
layoutWidth: 35%; layoutHeight: fill layoutWidth: 35%; layoutHeight: fill
margins: 5 margins: 5
TextWidget { text: OPTION_DIRECTORY_LAYOUT } TextWidget { text: OPTION_DIRECTORY_LAYOUT }
EditBox { EditBox {
id: directoryLayout; readOnly: true id: directoryLayout; readOnly: true
layoutWidth: fill; layoutHeight: fill layoutWidth: fill; layoutHeight: fill
} }
@ -362,13 +362,13 @@ class NewProjectDlg : Dialog {
project.name = toUTF32(_projectName); project.name = toUTF32(_projectName);
if (!project.save()) if (!project.save())
return setError("Cannot save project"); return setError("Cannot save project");
project.content.setString("targetName", _projectName); project.content.setting.setString("targetName", _projectName);
if (_currentTemplate.isLibrary) { if (_currentTemplate.isLibrary) {
project.content.setString("targetType", "staticLibrary"); project.content.setting.setString("targetType", "staticLibrary");
project.content.setString("targetPath", "lib"); project.content.setting.setString("targetPath", "lib");
} else { } else {
project.content.setString("targetType", "executable"); project.content.setting.setString("targetType", "executable");
project.content.setString("targetPath", "bin"); project.content.setting.setString("targetPath", "bin");
} }
if (_currentTemplate.json) if (_currentTemplate.json)
project.content.merge(_currentTemplate.json); project.content.merge(_currentTemplate.json);
@ -500,7 +500,7 @@ extern (C) int UIAppMain(string[] args) {
}; };
// show message box with content of editors // show message box with content of editors
window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) { window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) {
window.showMessageBox(UIString.fromId("MSG_OK_BUTTON"c), window.showMessageBox(UIString.fromId("MSG_OK_BUTTON"c),
UIString.fromId("EDITOR_CONTENT"c) ~ "\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text); UIString.fromId("EDITOR_CONTENT"c) ~ "\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text);
return true; return true;
}; };

View File

@ -312,19 +312,19 @@ struct ProjectConfiguration {
string name; string name;
/// type, for libraries one can run tests, for apps - execute them /// type, for libraries one can run tests, for apps - execute them
Type type; Type type;
/// How to display default configuration in ui /// How to display default configuration in ui
immutable static string DEFAULT_NAME = "default"; immutable static string DEFAULT_NAME = "default";
/// Default project configuration /// Default project configuration
immutable static ProjectConfiguration DEFAULT = ProjectConfiguration(DEFAULT_NAME, Type.Default); immutable static ProjectConfiguration DEFAULT = ProjectConfiguration(DEFAULT_NAME, Type.Default);
/// Type of configuration /// Type of configuration
enum Type { enum Type {
Default, Default,
Executable, Executable,
Library Library
} }
private static Type parseType(string s) private static Type parseType(string s)
{ {
switch(s) switch(s)
@ -336,7 +336,7 @@ struct ProjectConfiguration {
default: return Type.Default; default: return Type.Default;
} }
} }
/// parsing from setting file /// parsing from setting file
static ProjectConfiguration[] load(Setting s) static ProjectConfiguration[] load(Setting s)
{ {
@ -491,7 +491,7 @@ class Project : WorkspaceItem {
/// name /// name
override @property void name(dstring s) { override @property void name(dstring s) {
super.name(s); super.name(s);
_projectFile.setString("name", toUTF8(s)); _projectFile.setting.setString("name", toUTF8(s));
} }
/// name /// name
@ -502,7 +502,7 @@ class Project : WorkspaceItem {
/// name /// name
override @property void description(dstring s) { override @property void description(dstring s) {
super.description(s); super.description(s);
_projectFile.setString("description", toUTF8(s)); _projectFile.setting.setString("description", toUTF8(s));
} }
/// returns project's own source paths /// returns project's own source paths
@ -577,12 +577,12 @@ class Project : WorkspaceItem {
if (!isExecutable) if (!isExecutable)
return null; return null;
string exename = toUTF8(name); string exename = toUTF8(name);
exename = _projectFile.getString("targetName", exename); exename = _projectFile.setting.getString("targetName", exename);
// TODO: use targetName // TODO: use targetName
version (Windows) { version (Windows) {
exename = exename ~ ".exe"; exename = exename ~ ".exe";
} }
string targetPath = _projectFile.getString("targetPath", null); string targetPath = _projectFile.setting.getString("targetPath", null);
string exePath; string exePath;
if (targetPath.length) if (targetPath.length)
exePath = buildNormalizedPath(_filename.dirName, targetPath, exename); // int $targetPath directory exePath = buildNormalizedPath(_filename.dirName, targetPath, exename); // int $targetPath directory
@ -686,10 +686,10 @@ class Project : WorkspaceItem {
protected string[] findSourcePaths() { protected string[] findSourcePaths() {
string[] res; string[] res;
res.assumeSafeAppend; res.assumeSafeAppend;
string[] srcPaths = _projectFile.getStringArray("sourcePaths"); string[] srcPaths = _projectFile.setting.getStringArray("sourcePaths");
foreach(s; srcPaths) foreach(s; srcPaths)
addRelativePathIfExists(res, s); addRelativePathIfExists(res, s);
Setting configs = _projectFile.objectByPath("configurations"); Setting configs = _projectFile.setting.objectByPath("configurations");
if (configs) { if (configs) {
for (int i = 0; i < configs.length; i++) { for (int i = 0; i < configs.length; i++) {
Setting s = configs[i]; Setting s = configs[i];
@ -711,7 +711,7 @@ class Project : WorkspaceItem {
void processSubpackages() { void processSubpackages() {
import dlangui.core.files; import dlangui.core.files;
_subPackages.length = 0; _subPackages.length = 0;
Setting subPackages = _projectFile.settingByPath("subPackages", SettingType.ARRAY, false); Setting subPackages = _projectFile.setting.settingByPath("subPackages", SettingType.ARRAY, false);
if (subPackages) { if (subPackages) {
string p = _projectFile.filename.dirName; string p = _projectFile.filename.dirName;
for(int i = 0; i < subPackages.length; i++) { for(int i = 0; i < subPackages.length; i++) {
@ -762,7 +762,7 @@ class Project : WorkspaceItem {
// //
_mainSourceFile = null; _mainSourceFile = null;
try { try {
_name = toUTF32(_projectFile.getString("name")); _name = toUTF32(_projectFile.setting.getString("name"));
_originalName = _name; _originalName = _name;
if (_baseProjectName) { if (_baseProjectName) {
_name = _baseProjectName ~ ":" ~ _name; _name = _baseProjectName ~ ":" ~ _name;
@ -771,7 +771,7 @@ class Project : WorkspaceItem {
_name ~= "-"d; _name ~= "-"d;
_name ~= toUTF32(_dependencyVersion.startsWith("~") ? _dependencyVersion[1..$] : _dependencyVersion); _name ~= toUTF32(_dependencyVersion.startsWith("~") ? _dependencyVersion[1..$] : _dependencyVersion);
} }
_description = toUTF32(_projectFile.getString("description")); _description = toUTF32(_projectFile.setting.getString("description"));
Log.d(" project name: ", _name); Log.d(" project name: ", _name);
Log.d(" project description: ", _description); Log.d(" project description: ", _description);
@ -787,7 +787,7 @@ class Project : WorkspaceItem {
if (!_isDependency) if (!_isDependency)
loadSelections(); loadSelections();
_configurations = ProjectConfiguration.load(_projectFile); _configurations = ProjectConfiguration.load(_projectFile.setting);
Log.i("Project configurations: ", _configurations); Log.i("Project configurations: ", _configurations);
@ -843,7 +843,7 @@ class Project : WorkspaceItem {
_dependencies = newdeps; _dependencies = newdeps;
return false; return false;
} }
Setting versions = selectionsFile.objectByPath("versions"); Setting versions = selectionsFile.setting.objectByPath("versions");
if (!versions.isObject) { if (!versions.isObject) {
_dependencies = newdeps; _dependencies = newdeps;
return false; return false;

View File

@ -54,9 +54,9 @@ class Workspace : WorkspaceItem {
protected Project[] _projects; protected Project[] _projects;
protected SettingsFile _workspaceFile; protected SettingsFile _workspaceFile;
protected WorkspaceSettings _settings; protected WorkspaceSettings _settings;
protected IDEFrame _frame; protected IDEFrame _frame;
this(IDEFrame frame, string fname = WORKSPACE_EXTENSION) { this(IDEFrame frame, string fname = WORKSPACE_EXTENSION) {
super(fname); super(fname);
_workspaceFile = new SettingsFile(fname); _workspaceFile = new SettingsFile(fname);
@ -74,9 +74,9 @@ class Workspace : WorkspaceItem {
} }
@property Setting includePath(){ @property Setting includePath(){
Setting res = _workspaceFile.objectByPath("includePath", true); Setting res = _workspaceFile.setting.objectByPath("includePath", true);
return res; return res;
} }
@property Project[] projects() { return _projects; } @property Project[] projects() { return _projects; }
@ -91,19 +91,19 @@ class Workspace : WorkspaceItem {
protected Project _startupProject; protected Project _startupProject;
@property Project startupProject() { return _startupProject; } @property Project startupProject() { return _startupProject; }
@property void startupProject(Project project) { @property void startupProject(Project project) {
if (_startupProject is project) if (_startupProject is project)
return; return;
_startupProject = project; _startupProject = project;
_settings.startupProjectName = toUTF8(project.name); _settings.startupProjectName = toUTF8(project.name);
_frame.updateProjectConfigurations(); _frame.updateProjectConfigurations();
} }
/// Last opened files in workspace /// Last opened files in workspace
@property WorkspaceFile[] files() { @property WorkspaceFile[] files() {
return _settings.files(); return _settings.files();
} }
/// Last opened files in workspace /// Last opened files in workspace
@property void files(WorkspaceFile[] fs) { @property void files(WorkspaceFile[] fs) {
_settings.files(fs); _settings.files(fs);
@ -159,7 +159,7 @@ class Workspace : WorkspaceItem {
updateBreakpointFiles(res); updateBreakpointFiles(res);
return res; return res;
} }
void setSourceFileBreakpoints(ProjectSourceFile file, Breakpoint[] breakpoints) { void setSourceFileBreakpoints(ProjectSourceFile file, Breakpoint[] breakpoints) {
_settings.setProjectBreakpoints(toUTF8(file.project.name), file.projectFilePath, breakpoints); _settings.setProjectBreakpoints(toUTF8(file.project.name), file.projectFilePath, breakpoints);
} }
@ -169,7 +169,7 @@ class Workspace : WorkspaceItem {
updateBookmarkFiles(res); updateBookmarkFiles(res);
return res; return res;
} }
void setSourceFileBookmarks(ProjectSourceFile file, EditorBookmark[] bookmarks) { void setSourceFileBookmarks(ProjectSourceFile file, EditorBookmark[] bookmarks) {
_settings.setProjectBookmarks(toUTF8(file.project.name), file.projectFilePath, bookmarks); _settings.setProjectBookmarks(toUTF8(file.project.name), file.projectFilePath, bookmarks);
} }
@ -180,7 +180,7 @@ class Workspace : WorkspaceItem {
updateBreakpointFiles(res); updateBreakpointFiles(res);
return res; return res;
} }
protected void fillStartupProject() { protected void fillStartupProject() {
string s = _settings.startupProjectName; string s = _settings.startupProjectName;
if ((!_startupProject || !_startupProject.name.toUTF8.equal(s)) && _projects.length) { if ((!_startupProject || !_startupProject.name.toUTF8.equal(s)) && _projects.length) {
@ -312,13 +312,13 @@ class Workspace : WorkspaceItem {
if (nf && !_name.empty) // cut off last comma if (nf && !_name.empty) // cut off last comma
_name = _name[ 0 .. $ - 1 ]; _name = _name[ 0 .. $ - 1 ];
if (df && !_description.empty) // cut off last delimiter if (df && !_description.empty) // cut off last delimiter
_description = _description[ 0 .. $ - 3 ]; _description = _description[ 0 .. $ - 3 ];
} }
_workspaceFile.setString("name", toUTF8(_name)); _workspaceFile.setting.setString("name", toUTF8(_name));
_workspaceFile.setString("description", toUTF8(_description)); _workspaceFile.setting.setString("description", toUTF8(_description));
Log.d("workspace name: ", _name); Log.d("workspace name: ", _name);
Log.d("workspace description: ", _description); Log.d("workspace description: ", _description);
Setting projects = _workspaceFile.objectByPath("projects", true); Setting projects = _workspaceFile.setting.objectByPath("projects", true);
projects.clear(SettingType.OBJECT); projects.clear(SettingType.OBJECT);
foreach (Project p; _projects) { foreach (Project p; _projects) {
if (p.isDependency) if (p.isDependency)
@ -346,8 +346,8 @@ class Workspace : WorkspaceItem {
return false; return false;
} }
_settings.load(filename ~ WORKSPACE_SETTINGS_EXTENSION); _settings.load(filename ~ WORKSPACE_SETTINGS_EXTENSION);
_name = toUTF32(_workspaceFile["name"].str); _name = toUTF32(_workspaceFile.setting["name"].str);
_description = toUTF32(_workspaceFile["description"].str); _description = toUTF32(_workspaceFile.setting["description"].str);
Log.d("workspace name: ", _name); Log.d("workspace name: ", _name);
Log.d("workspace description: ", _description); Log.d("workspace description: ", _description);
if (_name.empty()) { if (_name.empty()) {
@ -355,7 +355,7 @@ class Workspace : WorkspaceItem {
return false; return false;
} }
auto originalStartupProjectName = _settings.startupProjectName; auto originalStartupProjectName = _settings.startupProjectName;
Setting projects = _workspaceFile.objectByPath("projects", true); Setting projects = _workspaceFile.setting.objectByPath("projects", true);
foreach(string key, Setting value; projects) { foreach(string key, Setting value; projects) {
string path = value.str; string path = value.str;
Log.d("project: ", key, " path:", path); Log.d("project: ", key, " path:", path);