Skip to content

Commit f5e9c2a

Browse files
authored
Merge pull request #4986 from IvenBach/Issue2947_ToDoHeaderReorder
Allow reordering of ToDoExplorer header columns
2 parents 55788e8 + 30a81ea commit f5e9c2a

17 files changed

+292
-40
lines changed

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Properties/Settings.settings

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,33 @@
185185
<BlockCompletion IsEnabled="false" CompleteOnEnter="false" CompleteOnTab="false" />
186186
&lt;/AutoCompleteSettings&gt;</Value>
187187
</Setting>
188+
<Setting Name="ToDoGridViewColumnInfo_Description" Type="Rubberduck.Settings.ToDoGridViewColumnInfo" Scope="Application">
189+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
190+
&lt;ToDoGridViewColumnInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
191+
&lt;DisplayIndex&gt;0&lt;/DisplayIndex&gt;
192+
&lt;Width /&gt;
193+
&lt;/ToDoGridViewColumnInfo&gt;</Value>
194+
</Setting>
195+
<Setting Name="ToDoGridViewColumnInfo_Project" Type="Rubberduck.Settings.ToDoGridViewColumnInfo" Scope="Application">
196+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
197+
&lt;ToDoGridViewColumnInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
198+
&lt;DisplayIndex&gt;1&lt;/DisplayIndex&gt;
199+
&lt;Width /&gt;
200+
&lt;/ToDoGridViewColumnInfo&gt;</Value>
201+
</Setting>
202+
<Setting Name="ToDoGridViewColumnInfo_Module" Type="Rubberduck.Settings.ToDoGridViewColumnInfo" Scope="Application">
203+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
204+
&lt;ToDoGridViewColumnInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
205+
&lt;DisplayIndex&gt;2&lt;/DisplayIndex&gt;
206+
&lt;Width /&gt;
207+
&lt;/ToDoGridViewColumnInfo&gt;</Value>
208+
</Setting>
209+
<Setting Name="ToDoGridViewColumnInfo_LineNumber" Type="Rubberduck.Settings.ToDoGridViewColumnInfo" Scope="Application">
210+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
211+
&lt;ToDoGridViewColumnInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
212+
&lt;DisplayIndex&gt;3&lt;/DisplayIndex&gt;
213+
&lt;Width /&gt;
214+
&lt;/ToDoGridViewColumnInfo&gt;</Value>
215+
</Setting>
188216
</Settings>
189217
</SettingsFile>

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<Reference Include="Infralution.Localization.Wpf">
2828
<HintPath>..\libs\Infralution.Localization.Wpf.dll</HintPath>
2929
</Reference>
30+
<Reference Include="mscorlib" />
3031
<Reference Include="PresentationCore" />
3132
<Reference Include="PresentationFramework" />
3233
<Reference Include="PresentationFramework.Aero" />
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using Rubberduck.UI;
3+
using System.Windows.Controls;
4+
using System.Xml.Serialization;
5+
6+
namespace Rubberduck.Settings
7+
{
8+
public interface IGridViewColumnInfo
9+
{
10+
int DisplayIndex { get; set; }
11+
DataGridLength Width { get; set; }
12+
}
13+
14+
public class ToDoGridViewColumnInfo : ViewModelBase, IGridViewColumnInfo, IEquatable<ToDoGridViewColumnInfo>
15+
{
16+
private int _displayIndex;
17+
public int DisplayIndex
18+
{
19+
get => _displayIndex;
20+
set
21+
{
22+
if (value != _displayIndex)
23+
{
24+
_displayIndex = value;
25+
OnPropertyChanged();
26+
}
27+
}
28+
}
29+
30+
[XmlElement(Type = typeof(DataGridLength))]
31+
private DataGridLength _width;
32+
33+
public DataGridLength Width
34+
{
35+
get => _width;
36+
set
37+
{
38+
if (value != _width)
39+
{
40+
_width = value;
41+
OnPropertyChanged();
42+
}
43+
}
44+
}
45+
46+
/// <Summary>
47+
/// Default constructor required for XML serialization.
48+
/// </Summary>
49+
public ToDoGridViewColumnInfo()
50+
{
51+
}
52+
53+
public ToDoGridViewColumnInfo(int displayIndex, DataGridLength width)
54+
{
55+
DisplayIndex = displayIndex;
56+
Width = width;
57+
}
58+
59+
public bool Equals(ToDoGridViewColumnInfo other)
60+
{
61+
return DisplayIndex == other.DisplayIndex
62+
&& Width == other.Width;
63+
}
64+
}
65+
}
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using System.Windows.Controls;
24
using Rubberduck.SettingsProvider;
35

46
namespace Rubberduck.Settings
57
{
68
public class ToDoListConfigProvider : ConfigurationServiceBase<ToDoListSettings>
79
{
8-
private readonly IEnumerable<ToDoMarker> defaultMarkers;
10+
private readonly IEnumerable<ToDoMarker> _defaultMarkers;
11+
private readonly ObservableCollection<ToDoGridViewColumnInfo> _toDoExplorerColumns;
912

1013
public ToDoListConfigProvider(IPersistenceService<ToDoListSettings> persister)
1114
: base(persister, new DefaultSettings<ToDoListSettings, Properties.Settings>())
1215
{
13-
// FIXME replace separated ToDoMarkers with ToDoListSettings
14-
defaultMarkers = new DefaultSettings<ToDoMarker, Properties.Settings>().Defaults;
16+
_defaultMarkers = new DefaultSettings<ToDoMarker, Properties.Settings>().Defaults;
17+
18+
var gvciDefaults = new DefaultSettings<ToDoGridViewColumnInfo, Properties.Settings>().Defaults;
19+
_toDoExplorerColumns = new ObservableCollection<ToDoGridViewColumnInfo>(gvciDefaults);
1520
}
1621

1722
public override ToDoListSettings ReadDefaults()
1823
{
19-
return new ToDoListSettings(defaultMarkers);
24+
return new ToDoListSettings(_defaultMarkers, _toDoExplorerColumns);
25+
}
26+
27+
public override ToDoListSettings Read()
28+
{
29+
var toDoListSettings = base.Read();
30+
31+
if (toDoListSettings.ColumnHeadersInformation == null
32+
|| toDoListSettings.ColumnHeadersInformation.Count == 0)
33+
{
34+
toDoListSettings.ColumnHeadersInformation = _toDoExplorerColumns;
35+
}
36+
37+
return toDoListSettings;
2038
}
2139
}
2240
}

Rubberduck.Core/Settings/ToDoListSettings.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Xml.Serialization;
6+
using Rubberduck.UI;
57

68
namespace Rubberduck.Settings
79
{
810
internal interface IToDoListSettings
911
{
1012
ToDoMarker[] ToDoMarkers { get; set; }
13+
ObservableCollection<ToDoGridViewColumnInfo> ColumnHeadersInformation { get; set; }
1114
}
1215

1316
[XmlType(AnonymousType = true)]
14-
public class ToDoListSettings : IToDoListSettings, IEquatable<ToDoListSettings>
17+
public class ToDoListSettings : ViewModelBase, IToDoListSettings, IEquatable<ToDoListSettings>
1518
{
1619
private IEnumerable<ToDoMarker> _markers;
1720

@@ -26,21 +29,38 @@ public ToDoMarker[] ToDoMarkers
2629
}
2730
}
2831

32+
private ObservableCollection<ToDoGridViewColumnInfo> _columnHeadersInfo;
33+
public ObservableCollection<ToDoGridViewColumnInfo> ColumnHeadersInformation
34+
{
35+
get => _columnHeadersInfo;
36+
set
37+
{
38+
if (value != _columnHeadersInfo)
39+
{
40+
_columnHeadersInfo = value;
41+
OnPropertyChanged();
42+
}
43+
}
44+
}
45+
2946
/// <Summary>
3047
/// Default constructor required for XML serialization.
3148
/// </Summary>
3249
public ToDoListSettings()
3350
{
3451
}
3552

36-
public ToDoListSettings(IEnumerable<ToDoMarker> defaultMarkers)
53+
public ToDoListSettings(IEnumerable<ToDoMarker> defaultMarkers, ObservableCollection<ToDoGridViewColumnInfo> columnHeaders)
3754
{
3855
_markers = defaultMarkers;
56+
ColumnHeadersInformation = columnHeaders;
3957
}
4058

4159
public bool Equals(ToDoListSettings other)
4260
{
43-
return other != null && ToDoMarkers.SequenceEqual(other.ToDoMarkers);
61+
return other != null
62+
&& ToDoMarkers.SequenceEqual(other.ToDoMarkers)
63+
&& ColumnHeadersInformation.Equals(other.ColumnHeadersInformation);
4464
}
4565
}
4666
}

Rubberduck.Core/UI/Controls/BindableTextEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public BindableTextEditor()
3636
}
3737

3838
public static readonly DependencyProperty TextProperty =
39-
DependencyProperty.Register("Text", typeof(string), typeof(BindableTextEditor), new PropertyMetadata((obj, args) =>
39+
DependencyProperty.Register(nameof(Text), typeof(string), typeof(BindableTextEditor), new PropertyMetadata((obj, args) =>
4040
{
4141
var target = (BindableTextEditor)obj;
4242
target.Text = (string)args.NewValue;
4343
}));
4444

4545
protected override void OnTextChanged(EventArgs e)
4646
{
47-
RaisePropertyChanged("Text");
47+
RaisePropertyChanged(nameof(Text));
4848
base.OnTextChanged(e);
4949
}
5050

Rubberduck.Core/UI/Controls/GroupingGrid.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Rubberduck.UI.Controls
77
public partial class GroupingGrid
88
{
99
public static readonly DependencyProperty ShowGroupingItemCountProperty =
10-
DependencyProperty.Register("ShowGroupingItemCount", typeof (bool), typeof(GroupingGrid));
10+
DependencyProperty.Register(nameof(ShowGroupingItemCount), typeof (bool), typeof(GroupingGrid));
1111

1212
public static readonly DependencyProperty InitialExpandedStateProperty =
13-
DependencyProperty.Register("InitialExpandedState", typeof(bool), typeof(GroupingGrid));
13+
DependencyProperty.Register(nameof(InitialExpandedState), typeof(bool), typeof(GroupingGrid));
1414

1515
public bool ShowGroupingItemCount
1616
{

Rubberduck.Core/UI/ToDoItems/ToDoExplorerControl.xaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,24 @@
308308
</ToolBar>
309309
</ToolBarTray>
310310

311-
<controls:GroupingGrid Grid.Row="1"
311+
<controls:GroupingGrid x:Name="MainGrid"
312+
Grid.Row="1"
312313
ShowGroupingItemCount="True"
313314
ItemsSource="{Binding Items, NotifyOnSourceUpdated=True}"
314315
SelectedItem="{Binding SelectedItem}"
315316
SelectionUnit="FullRow"
316-
InitialExpandedState="True">
317+
InitialExpandedState="True"
318+
CanUserReorderColumns="True"
319+
ColumnReordered="GroupingGrid_ColumnReordered">
317320
<controls:GroupingGrid.Columns>
318-
319-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.ToDoExplorer.ToDoExplorerUI, Key=TodoExplorer_Description}" Binding="{Binding Description, Mode=OneTime}" Width="*"/>
320-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ProjectName}" Binding="{Binding Selection.QualifiedName.ProjectName, Mode=OneTime}" />
321-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ModuleName}" Binding="{Binding Selection.QualifiedName.ComponentName, Mode=OneTime}" />
322-
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.ToDoExplorer.ToDoExplorerUI, Key=TodoExplorer_LineNumber}" Binding="{Binding Selection.Selection.StartLine, Mode=OneTime}" />
321+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.ToDoExplorer.ToDoExplorerUI, Key=TodoExplorer_Description}" Binding="{Binding Description, Mode=OneTime}" Width="*"
322+
DisplayIndex="{Binding DescriptionColumnIndex, Mode=TwoWay, FallbackValue=0}" />
323+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ProjectName}" Binding="{Binding Selection.QualifiedName.ProjectName, Mode=OneTime}" Width="75"
324+
DisplayIndex="{Binding ProjectColumnIndex, Mode=TwoWay, FallbackValue=1}" />
325+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ModuleName}" Binding="{Binding Selection.QualifiedName.ComponentName, Mode=OneTime}" Width="75"
326+
DisplayIndex="{Binding ComponentColumnIndex, Mode=TwoWay, FallbackValue=2}" />
327+
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.ToDoExplorer.ToDoExplorerUI, Key=TodoExplorer_LineNumber}" Binding="{Binding Selection.Selection.StartLine, Mode=OneTime}" Width="75"
328+
DisplayIndex="{Binding LineNumberColumnIndex, Mode=TwoWay, FallbackValue=3}" />
323329
</controls:GroupingGrid.Columns>
324330
<i:Interaction.Behaviors>
325331
<controls:GroupItemExpandedBehavior ExpandedState="{Binding ExpandedState, Mode=TwoWay}" />

Rubberduck.Core/UI/ToDoItems/ToDoExplorerControl.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-

1+
using System;
2+
23
namespace Rubberduck.UI.ToDoItems
34
{
45
/// <summary>
@@ -21,5 +22,10 @@ private void ToDoExplorerControl_Loaded(object sender, System.Windows.RoutedEven
2122
ViewModel.RefreshCommand.Execute(null);
2223
}
2324
}
25+
26+
private void GroupingGrid_ColumnReordered(object sender, System.Windows.Controls.DataGridColumnEventArgs e)
27+
{
28+
ViewModel.UpdateColumnHeaderInformation(MainGrid.Columns);
29+
}
2430
}
2531
}

0 commit comments

Comments
 (0)