Skip to content

Commit 9d132b5

Browse files
authored
Merge pull request #5941 from awb95/dev-5459-Move_Closer_to_Usage
Extend MoveCloserToUsage Refractoring to solve Issue #5459
2 parents 512f685 + be40f30 commit 9d132b5

14 files changed

+700
-229
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Rubberduck.Parsing.Symbols;
2+
using Rubberduck.Refactorings;
3+
using Rubberduck.Refactorings.MoveCloserToUsage;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Rubberduck.UI.Refactorings.MoveCloserToUsage
11+
{
12+
class MoveCloserToUsagePresenter : RefactoringPresenterBase<MoveCloserToUsageModel>, IMoveCloserToUsagePresenter
13+
{
14+
15+
private static readonly DialogData DialogData = DialogData.Create("RefactoringsUI.MoveCloserToUsageDialog_Caption", 164, 684);
16+
17+
public MoveCloserToUsagePresenter(MoveCloserToUsageModel model, IRefactoringDialogFactory dialogFactory) :
18+
base(DialogData, model, dialogFactory)
19+
{
20+
}
21+
22+
public MoveCloserToUsageModel Show(VariableDeclaration target)
23+
{
24+
if (null == target)
25+
{
26+
return null;
27+
}
28+
29+
Model.Target = target;
30+
31+
return Show();
32+
}
33+
}
34+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<UserControl x:Class="Rubberduck.UI.Refactorings.MoveCloserToUsage.MoveCloserToUsageView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Rubberduck.UI.Refactorings.MoveCloserToUsage"
7+
mc:Ignorable="d"
8+
d:DesignHeight="200" d:DesignWidth="300">
9+
<UserControl.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<ResourceDictionary Source="../../Controls/ToolBar.xaml"/>
13+
</ResourceDictionary.MergedDictionaries>
14+
</ResourceDictionary>
15+
</UserControl.Resources>
16+
<Grid>
17+
<Grid.RowDefinitions>
18+
<RowDefinition Height="50"/>
19+
<RowDefinition Height="*"/>
20+
<RowDefinition Height="40"/>
21+
</Grid.RowDefinitions>
22+
<StackPanel Background="{StaticResource BackgroundLightBrush}">
23+
<Label Content="{Resx ResxName=Rubberduck.Refactorings.RefactoringsUI, Key=MoveCloserToUsageDialog_TitleText}" FontWeight="Bold" />
24+
<TextBlock Text="{Binding Instructions}" Margin="5,0" />
25+
</StackPanel>
26+
27+
<StackPanel Grid.Row="1" Margin="5,10,10,5">
28+
<RadioButton x:Name="StaticRadioButton"
29+
Content="Static"
30+
IsChecked="True"
31+
Height="20"
32+
GroupName="DeclarationStatments"
33+
Command="{Binding SetNewDeclarationStatementCommand}"
34+
CommandParameter="{Binding ElementName=StaticRadioButton, Path=Content}"/>
35+
<RadioButton x:Name="DimRadioButton"
36+
Content="Dim"
37+
Height="20"
38+
GroupName="DeclarationStatments"
39+
Command="{Binding SetNewDeclarationStatementCommand}"
40+
CommandParameter="{Binding ElementName=DimRadioButton, Path=Content}"/>
41+
</StackPanel>
42+
43+
<Grid Grid.Row="2" Background="{x:Static SystemColors.ControlDarkBrush}" Grid.IsSharedSizeScope="True">
44+
<Grid HorizontalAlignment="Right"
45+
Margin="5,0">
46+
<Grid.ColumnDefinitions>
47+
<ColumnDefinition SharedSizeGroup="SettingsButtons" />
48+
<ColumnDefinition SharedSizeGroup="SettingsButtons" />
49+
</Grid.ColumnDefinitions>
50+
<Button Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=OK}"
51+
Grid.Column="0"
52+
Height="20"
53+
Margin="5,0"
54+
Padding="10,0"
55+
IsDefault="True"
56+
Command="{Binding OkButtonCommand}" />
57+
<Button Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=CancelButtonText}"
58+
Grid.Column="1"
59+
Height="20"
60+
Margin="5,0"
61+
Padding="10,0"
62+
IsCancel="True"
63+
Command="{Binding CancelButtonCommand}">
64+
</Button>
65+
</Grid>
66+
</Grid>
67+
68+
</Grid>
69+
</UserControl>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Rubberduck.Refactorings;
2+
using Rubberduck.Refactorings.MoveCloserToUsage;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace Rubberduck.UI.Refactorings.MoveCloserToUsage
19+
{
20+
/// <summary>
21+
/// Interaktionslogik für MoveCloserToUsageView.xaml
22+
/// </summary>
23+
public partial class MoveCloserToUsageView : IRefactoringView<MoveCloserToUsageModel>
24+
{
25+
public MoveCloserToUsageView()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
}
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using NLog;
2+
using Rubberduck.Parsing.Symbols;
3+
using Rubberduck.Refactorings;
4+
using Rubberduck.Refactorings.MoveCloserToUsage;
5+
using Rubberduck.UI.Command;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace Rubberduck.UI.Refactorings.MoveCloserToUsage
13+
{
14+
class MoveCloserToUsageViewModel : RefactoringViewModelBase<MoveCloserToUsageModel>
15+
{
16+
public MoveCloserToUsageViewModel(MoveCloserToUsageModel model) : base(model)
17+
{
18+
SetNewDeclarationStatementCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), (o) => SetNewDeclarationStatementExecute(o));
19+
}
20+
21+
public Declaration Target => Model.Target;
22+
23+
public string Instructions
24+
{
25+
get
26+
{
27+
if (Target == null)
28+
{
29+
return RefactoringsUI.MoveCloserToUsageDialog_InstructionsLabelText;
30+
}
31+
32+
return string.Format(RefactoringsUI.MoveCloserToUsageDialog_InstructionsLabelText, Target.IdentifierName);
33+
}
34+
}
35+
36+
public DelegateCommand SetNewDeclarationStatementCommand { get; }
37+
38+
void SetNewDeclarationStatementExecute(object param)
39+
{
40+
if (param is string newDeclarationStatement)
41+
{
42+
Model.DeclarationStatement = newDeclarationStatement;
43+
}
44+
45+
}
46+
47+
}
48+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Rubberduck.Parsing.Symbols;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Rubberduck.Refactorings.MoveCloserToUsage
9+
{
10+
public interface IMoveCloserToUsagePresenter : IRefactoringPresenter<MoveCloserToUsageModel>
11+
{
12+
MoveCloserToUsageModel Show(VariableDeclaration target);
13+
MoveCloserToUsageModel Model { get; }
14+
}
15+
}
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
using Rubberduck.Parsing.Symbols;
1+
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.Parsing.Symbols;
23

34
namespace Rubberduck.Refactorings.MoveCloserToUsage
45
{
56
public class MoveCloserToUsageModel : IRefactoringModel
67
{
7-
public Declaration Target { get; }
8+
private VariableDeclaration _target;
9+
public VariableDeclaration Target
10+
{
11+
get => _target;
12+
set
13+
{
14+
_target = value;
15+
}
16+
}
817

9-
public MoveCloserToUsageModel(Declaration target)
18+
public string DeclarationStatement { get; set; }
19+
20+
public MoveCloserToUsageModel(VariableDeclaration target, string declarationStatement = null )
1021
{
11-
Target = target;
22+
_target = target;
23+
DeclarationStatement = declarationStatement ?? string.Empty;
1224
}
25+
1326
}
1427
}

0 commit comments

Comments
 (0)