Skip to content

Commit 5fec4ad

Browse files
authored
Merge pull request #5438 from MDoerner/MoveToFolderRefactoring
Introducing Move to Folder refactoring
2 parents 7b1c020 + 6f0a1d7 commit 5fec4ad

File tree

98 files changed

+3229
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3229
-311
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults(Qualifi
5151
{
5252
var setters = RelevantDeclarationsInModule(module, finder)
5353
.Where(declaration => IsResultDeclaration(declaration, finder))
54-
.GroupBy(declaration => declaration.DeclarationType)
54+
.GroupBy(declaration => declaration.QualifiedName)
5555
.Select(grouping => grouping.First()); // don't get both Let and Set accessors
5656

5757
return setters
@@ -62,9 +62,10 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults(Qualifi
6262
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder)
6363
{
6464
return (declaration.Accessibility == Accessibility.Implicit
65-
|| declaration.Accessibility == Accessibility.Public
66-
|| declaration.Accessibility == Accessibility.Global)
65+
|| declaration.Accessibility == Accessibility.Public
66+
|| declaration.Accessibility == Accessibility.Global)
6767
&& finder.MatchName(declaration.IdentifierName)
68+
.Where(otherDeclaration => otherDeclaration.QualifiedModuleName.Equals(declaration.QualifiedModuleName))
6869
.All(accessor => accessor.DeclarationType != DeclarationType.PropertyGet);
6970
}
7071

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Collections.Generic;
22
using System.Diagnostics;
33
using System.Linq;
4+
using Rubberduck.Common;
5+
using Rubberduck.JunkDrawer.Extensions;
46
using Rubberduck.Navigation.Folders;
57
using Rubberduck.Parsing.Symbols;
68
using Rubberduck.VBEditor;
@@ -30,7 +32,7 @@ public CodeExplorerCustomFolderViewModel(
3032
{
3133
_vbe = vbe;
3234
FolderDepth = parent is CodeExplorerCustomFolderViewModel folder ? folder.FolderDepth + 1 : 1;
33-
FullPath = fullPath?.Trim('"') ?? string.Empty;
35+
FullPath = fullPath?.FromVbaStringLiteral() ?? string.Empty;
3436
Name = name.Replace("\"", string.Empty);
3537

3638
AddNewChildren(ref declarations);
@@ -44,7 +46,7 @@ public CodeExplorerCustomFolderViewModel(
4446

4547
public string FullPath { get; }
4648

47-
public string FolderAttribute => $"'@Folder(\"{FullPath.Replace("\"", string.Empty)}\")";
49+
public string FolderAttribute => $"'@Folder({FullPath.ToVbaStringLiteral()})";
4850

4951
/// <summary>
5052
/// One-based depth in the folder hierarchy.

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Windows.Input;
1717
using Rubberduck.Parsing.UIContext;
1818
using Rubberduck.Templates;
19+
using Rubberduck.UI.CodeExplorer.Commands.DragAndDrop;
1920
using Rubberduck.UI.Command.ComCommands;
2021
using Rubberduck.UI.UnitTesting.ComCommands;
2122
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
@@ -379,6 +380,7 @@ private void ExecuteRemoveCommand(object param)
379380
public OpenProjectPropertiesCommand OpenProjectPropertiesCommand { get; set; }
380381
public SetAsStartupProjectCommand SetAsStartupProjectCommand { get; set; }
381382
public RenameCommand RenameCommand { get; set; }
383+
public CodeExplorerMoveToFolderCommand MoveToFolderCommand { get; set; }
382384
public IndentCommand IndenterCommand { get; set; }
383385
public CodeExplorerFindAllReferencesCommand FindAllReferencesCommand { get; set; }
384386
public CodeExplorerFindAllImplementationsCommand FindAllImplementationsCommand { get; set; }
@@ -398,7 +400,9 @@ private void ExecuteRemoveCommand(object param)
398400
public CommandBase SyncCodePaneCommand { get; }
399401
public CodeExplorerExtractInterfaceCommand CodeExplorerExtractInterfaceCommand { get; set; }
400402

401-
public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration)
403+
public CodeExplorerMoveToFolderDragAndDropCommand MoveToFolderDragAndDropCommand { get; set; }
404+
405+
public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration)
402406
{
403407
if (declaration == null)
404408
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using Rubberduck.Parsing.Symbols;
3+
using Rubberduck.JunkDrawer.Extensions;
4+
5+
namespace Rubberduck.Navigation.Folders
6+
{
7+
public static class DeclarationFolderExtensions
8+
{
9+
public static string RootFolder(this Declaration declaration)
10+
{
11+
return declaration?.CustomFolder?.RootFolder()
12+
?? declaration?.ProjectName
13+
?? string.Empty;
14+
}
15+
16+
public static bool IsInFolder(this Declaration declaration, string folder)
17+
{
18+
if (declaration?.CustomFolder is null || folder is null)
19+
{
20+
return false;
21+
}
22+
23+
return declaration.CustomFolder.Equals(folder, StringComparison.Ordinal);
24+
}
25+
26+
public static bool IsInSubFolder(this Declaration declaration, string folder)
27+
{
28+
var declarationFolder = declaration?.CustomFolder;
29+
if (declarationFolder is null || folder is null)
30+
{
31+
return false;
32+
}
33+
34+
return declarationFolder.IsSubFolderOf(folder);
35+
}
36+
37+
public static bool IsInFolderOrSubFolder(this Declaration declaration, string folder)
38+
{
39+
var declarationFolder = declaration?.CustomFolder;
40+
if (declarationFolder is null || folder is null)
41+
{
42+
return false;
43+
}
44+
45+
return declaration.IsInFolder(folder)
46+
|| declarationFolder.IsSubFolderOf(folder);
47+
}
48+
}
49+
}

Rubberduck.Core/Navigation/Folders/FolderExtensions.cs

Lines changed: 0 additions & 78 deletions
This file was deleted.

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
<DesignTime>True</DesignTime>
118118
<AutoGen>True</AutoGen>
119119
</Compile>
120+
<Compile Update="UI\Refactorings\MoveFolder\MoveMultipleFoldersView.xaml.cs">
121+
<DependentUpon>MoveMultipleFoldersView.xaml</DependentUpon>
122+
</Compile>
123+
<Compile Update="UI\Refactorings\MoveToFolder\MoveMultipleToFolderView.xaml.cs">
124+
<DependentUpon>MoveMultipleToFolderView.xaml</DependentUpon>
125+
</Compile>
120126
</ItemGroup>
121127
<ItemGroup>
122128
<EmbeddedResource Update="Properties\Resources.resx">

Rubberduck.Core/UI/CodeExplorer/CodeExplorerAddComponentService.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,7 @@ private string Folder(CodeExplorerItemViewModel node)
101101
return ActiveProjectFolder();
102102
}
103103

104-
var customFolder = declaration.CustomFolder;
105-
if (customFolder != null)
106-
{
107-
return customFolder.Replace("\"", string.Empty);
108-
}
109-
110-
return ProjectFolder(declaration.ProjectName);
104+
return declaration.CustomFolder ?? ProjectFolder(declaration.ProjectName);
111105
}
112106

113107
private string ActiveProjectFolder()

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@
210210
<Setter Property="HorizontalAlignment" Value="Left" />
211211
<EventSetter Event="MouseDoubleClick" Handler="TreeView_OnMouseDoubleClick" />
212212
<EventSetter Event="MouseRightButtonDown" Handler="TreeView_OnMouseRightButtonDown" />
213+
<EventSetter Event="DragOver" Handler="TreeView_OnDragOver" />
214+
<EventSetter Event="Drop" Handler="TreeView_OnDrop" />
215+
<EventSetter Event="PreviewQueryContinueDrag" Handler="TreeView_PreviewContinueDrag" />
216+
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="TreeView_PreviewMouseLeftButtonDown" />
217+
<EventSetter Event="PreviewMouseMove" Handler="TreeView_PreviewMouseMove" />
218+
213219
<Style.Triggers>
214220
<Trigger Property="IsSelected" Value="True">
215221
<Setter Property="BorderBrush" Value="{StaticResource HighlightBorderActiveBrush}"/>
@@ -395,7 +401,8 @@
395401
FontSize="{Binding FontSize, Mode=OneWay}"
396402
BorderThickness="0,1"
397403
VirtualizingPanel.IsVirtualizing="False"
398-
KeyDown="ProjectTree_KeyDown">
404+
KeyDown="ProjectTree_KeyDown"
405+
AllowDrop="True">
399406
<TreeView.ContextMenu>
400407
<ContextMenu>
401408
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Open}"
@@ -417,9 +424,12 @@
417424
<Image Source="{StaticResource RefreshImage}" />
418425
</MenuItem.Icon>
419426
</MenuItem>
420-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=Rename}"
427+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Rename}"
421428
Command="{Binding RenameCommand}"
422429
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
430+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_MoveToFolder}"
431+
Command="{Binding MoveToFolderCommand}"
432+
CommandParameter="{Binding SelectedItem, Mode=OneWay}" />
423433
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_ExtractInterfaceText}"
424434
Command="{Binding CodeExplorerExtractInterfaceCommand}"
425435
CommandParameter="{Binding SelectedItem, Mode=OneWay}">

0 commit comments

Comments
 (0)