mirror of https://github.com/buggins/dlangide.git
#254-autoCollapse-nodes
This commit is contained in:
parent
97c3955625
commit
07b7110219
src/dlangide/ui
|
@ -1,5 +1,6 @@
|
||||||
module dlangide.ui.wspanel;
|
module dlangide.ui.wspanel;
|
||||||
|
|
||||||
|
import std.string;
|
||||||
import dlangui;
|
import dlangui;
|
||||||
import dlangide.workspace.workspace;
|
import dlangide.workspace.workspace;
|
||||||
import dlangide.workspace.project;
|
import dlangide.workspace.project;
|
||||||
|
@ -176,6 +177,7 @@ class WorkspacePanel : DockWindow {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adding elements to the tree
|
||||||
void addProjectItems(TreeItem root, ProjectItem items) {
|
void addProjectItems(TreeItem root, ProjectItem items) {
|
||||||
for (int i = 0; i < items.childCount; i++) {
|
for (int i = 0; i < items.childCount; i++) {
|
||||||
ProjectItem child = items.child(i);
|
ProjectItem child = items.child(i);
|
||||||
|
@ -225,6 +227,8 @@ class WorkspacePanel : DockWindow {
|
||||||
_itemStates[item] = true;
|
_itemStates[item] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Saving items collapse/expand state
|
||||||
protected void saveItemState(string itemPath, bool expanded) {
|
protected void saveItemState(string itemPath, bool expanded) {
|
||||||
bool changed = restoreItemState(itemPath) != expanded;
|
bool changed = restoreItemState(itemPath) != expanded;
|
||||||
if (!_itemStatesDirty && changed)
|
if (!_itemStatesDirty && changed)
|
||||||
|
@ -244,10 +248,19 @@ class WorkspacePanel : DockWindow {
|
||||||
}
|
}
|
||||||
debug Log.d("stored Expanded state ", expanded, " for ", itemPath);
|
debug Log.d("stored Expanded state ", expanded, " for ", itemPath);
|
||||||
}
|
}
|
||||||
|
/// Is need to expand item?
|
||||||
protected bool restoreItemState(string itemPath) {
|
protected bool restoreItemState(string itemPath) {
|
||||||
if (auto p = itemPath in _itemStates) {
|
if (auto p = itemPath in _itemStates) {
|
||||||
debug Log.d("restored Expanded state for ", itemPath);
|
// Item itself must expand, but upper items may be collapsed
|
||||||
return *p;
|
auto path = itemPath;
|
||||||
|
while (path.length > 0 && !path.endsWith("src") && path in _itemStates) {
|
||||||
|
auto pos = lastIndexOf(path, '/');
|
||||||
|
path = pos > -1 ? path[ 0 .. pos ] : "";
|
||||||
|
}
|
||||||
|
if (path.length == 0 || path.endsWith("src")) {
|
||||||
|
debug Log.d("restored Expanded state for ", itemPath);
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue