Skip to content

Commit b9e14ea

Browse files
committed
Make CE selection stick
1 parent 52fb48d commit b9e14ea

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ protected set
164164
}
165165

166166
public bool IsExpanded { get; set; }
167+
public bool IsSelected { get; set; }
167168

168169
public abstract string Name { get; }
169170
public abstract string NameWithSignature { get; }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ private void FillFolders(IEnumerable<Declaration> declarations)
5353
.GroupBy(item => item.CustomFolder)
5454
.OrderBy(item => item.Key);
5555

56+
// set parent so we can walk up to the project node
57+
// we haven't added the nodes yet, so this cast is valid
58+
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
59+
foreach (CodeExplorerCustomFolderViewModel item in _folderTree.Items)
60+
{
61+
item.SetParent(this);
62+
}
63+
5664
foreach (var grouping in groupedItems)
5765
{
5866
AddNodesToTree(_folderTree, items, grouping);
@@ -68,11 +76,6 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
6876
continue;
6977
}
7078

71-
if (folder.Parent.Name == string.Empty)
72-
{
73-
folder.SetParent(this);
74-
}
75-
7679
var parents = grouping.Where(
7780
item => ComponentTypes.Contains(item.DeclarationType) &&
7881
item.CustomFolder.Replace("\"", string.Empty) == folder.FullPath)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,23 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
244244
}
245245
}
246246

247+
private Declaration FindNewProjectDeclaration(string id)
248+
{
249+
return _state.AllUserDeclarations.SingleOrDefault(item =>
250+
item.ProjectId == id &&
251+
item.DeclarationType == DeclarationType.Project);
252+
}
253+
254+
private Declaration FindNewDeclaration(Declaration declaration)
255+
{
256+
return _state.AllUserDeclarations.SingleOrDefault(item =>
257+
item.ProjectId == declaration.ProjectId &&
258+
item.ComponentName == declaration.ComponentName &&
259+
item.ParentScope == declaration.ParentScope &&
260+
item.IdentifierName == declaration.IdentifierName &&
261+
item.DeclarationType == declaration.DeclarationType);
262+
}
263+
247264
private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
248265
{
249266
if (Projects == null)
@@ -274,7 +291,7 @@ private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
274291
grouping)).ToList();
275292

276293
UpdateNodes(Projects, newProjects);
277-
294+
278295
Projects = new ObservableCollection<CodeExplorerItemViewModel>(newProjects);
279296
}
280297

@@ -303,6 +320,7 @@ private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList,
303320
if (oldItem != null)
304321
{
305322
item.IsExpanded = oldItem.IsExpanded;
323+
item.IsSelected = oldItem.IsSelected;
306324

307325
if (oldItem.Items.Any() && item.Items.Any())
308326
{

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
TargetType="{x:Type TreeViewItem}">
272272
<Setter Property="BorderThickness" Value="1.5"/>
273273
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
274+
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
274275
<Setter Property="HorizontalAlignment" Value="Left" />
275276
<EventSetter Event="PreviewMouseRightButtonDown" Handler="OnPreviewMouseRightButtonDown" />
276277
<Style.Triggers>

0 commit comments

Comments
 (0)