Skip to content

Commit 9f4d2c2

Browse files
committed
reinstated ResetButton
2 parents e4bfc14 + 86a918c commit 9f4d2c2

Some content is hidden

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

50 files changed

+1314
-2835
lines changed

RetailCoder.VBE/App.cs

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class App : IDisposable
3030
private RubberduckMenu _menu;
3131
private FormContextMenu _formContextMenu;
3232
private CodeInspectionsToolbar _codeInspectionsToolbar;
33+
private bool displayToolbar = false;
34+
private Point toolbarCoords = new Point(-1, -1);
3335

3436
public App(VBE vbe, AddIn addIn)
3537
{
@@ -42,11 +44,19 @@ public App(VBE vbe, AddIn addIn)
4244
_editor = new ActiveCodePaneEditor(vbe);
4345

4446
LoadConfig();
47+
48+
CleanUp();
49+
50+
Setup();
4551
}
4652

4753
private void _configService_SettingsChanged(object sender, EventArgs e)
4854
{
4955
LoadConfig();
56+
57+
CleanUp();
58+
59+
Setup();
5060
}
5161

5262
private void LoadConfig()
@@ -64,48 +74,15 @@ private void LoadConfig()
6474
_config.UserSettings.LanguageSetting.Code = currentCulture.Name;
6575
_configService.SaveConfiguration(_config);
6676
}
77+
}
6778

68-
if (_menu != null)
69-
{
70-
_menu.Dispose();
71-
}
72-
73-
if (_formContextMenu != null)
74-
{
75-
_formContextMenu.Dispose();
76-
}
77-
78-
var displayToolbar = false;
79-
var toolbarCoords = new Point(-1, -1);
80-
if (_codeInspectionsToolbar != null)
81-
{
82-
displayToolbar = _codeInspectionsToolbar.ToolbarVisible;
83-
toolbarCoords = _codeInspectionsToolbar.ToolbarCoords;
84-
_codeInspectionsToolbar.Dispose();
85-
}
86-
87-
if (_inspector != null)
88-
{
89-
_inspector.Dispose();
90-
}
91-
92-
if (_parserErrorsPresenter != null)
93-
{
94-
_parserErrorsPresenter.Dispose();
95-
}
96-
97-
if (_parser != null)
98-
{
99-
_parser.ParseStarted -= _parser_ParseStarted;
100-
_parser.ParserError -= _parser_ParserError;
101-
}
79+
private void Setup()
80+
{
10281
_parser = new RubberduckParser();
10382
_parser.ParseStarted += _parser_ParseStarted;
10483
_parser.ParserError += _parser_ParserError;
10584

106-
_inspections = _configService.GetImplementedCodeInspections();
107-
_inspector = new Inspector(_parser, _inspections);
108-
EnableCodeInspections(_config);
85+
_inspector = new Inspector(_parser, _configService);
10986

11087
_parserErrorsPresenter = new ParserErrorsPresenter(_vbe, _addIn);
11188

@@ -136,20 +113,6 @@ private void _parser_ParserError(object sender, ParseErrorEventArgs e)
136113
_parserErrorsPresenter.Show();
137114
}
138115

139-
private void EnableCodeInspections(Configuration config)
140-
{
141-
foreach (var inspection in _inspections)
142-
{
143-
foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
144-
{
145-
if (inspection.Description == setting.Description)
146-
{
147-
inspection.Severity = setting.Severity;
148-
}
149-
}
150-
}
151-
}
152-
153116
public void Dispose()
154117
{
155118
Dispose(true);
@@ -159,6 +122,11 @@ protected virtual void Dispose(bool disposing)
159122
{
160123
if (!disposing) { return; }
161124

125+
CleanUp();
126+
}
127+
128+
private void CleanUp()
129+
{
162130
if (_menu != null)
163131
{
164132
_menu.Dispose();
@@ -171,6 +139,8 @@ protected virtual void Dispose(bool disposing)
171139

172140
if (_codeInspectionsToolbar != null)
173141
{
142+
displayToolbar = _codeInspectionsToolbar.ToolbarVisible;
143+
toolbarCoords = _codeInspectionsToolbar.ToolbarCoords;
174144
_codeInspectionsToolbar.Dispose();
175145
}
176146

@@ -183,6 +153,12 @@ protected virtual void Dispose(bool disposing)
183153
{
184154
_parserErrorsPresenter.Dispose();
185155
}
156+
157+
if (_parser != null)
158+
{
159+
_parser.ParseStarted -= _parser_ParseStarted;
160+
_parser.ParserError -= _parser_ParserError;
161+
}
186162
}
187163
}
188164
}

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,47 @@
66
using System.Threading.Tasks;
77
using Microsoft.Vbe.Interop;
88
using Rubberduck.Parsing;
9+
using Rubberduck.Settings;
910

1011
namespace Rubberduck.Inspections
1112
{
1213
public class Inspector : IInspector, IDisposable
1314
{
1415
private readonly IRubberduckParser _parser;
16+
private readonly IGeneralConfigService _configService;
1517
private readonly IList<IInspection> _inspections;
1618

17-
public Inspector(IRubberduckParser parser, IEnumerable<IInspection> inspections)
19+
public Inspector(IRubberduckParser parser, IGeneralConfigService configService)
1820
{
1921
_parser = parser;
2022
_parser.ParseStarted += _parser_ParseStarted;
2123
_parser.ParseCompleted += _parser_ParseCompleted;
2224

23-
_inspections = inspections.ToList();
25+
_configService = configService;
26+
_inspections = configService.GetImplementedCodeInspections();
27+
configService.SettingsChanged += ConfigServiceSettingsChanged;
28+
UpdateInspectionSeverity();
29+
}
30+
31+
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
32+
{
33+
UpdateInspectionSeverity();
34+
}
35+
36+
private void UpdateInspectionSeverity()
37+
{
38+
var config = _configService.LoadConfiguration();
39+
40+
foreach (var inspection in _inspections)
41+
{
42+
foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
43+
{
44+
if (inspection.Description == setting.Description)
45+
{
46+
inspection.Severity = setting.Severity;
47+
}
48+
}
49+
}
2450
}
2551

2652
private void _parser_ParseCompleted(object sender, ParseCompletedEventArgs e)
@@ -139,6 +165,11 @@ protected virtual void Dispose(bool disposing)
139165
if (!disposing) { return; }
140166
_parser.ParseStarted -= _parser_ParseStarted;
141167
_parser.ParseCompleted -= _parser_ParseCompleted;
168+
169+
if (_configService != null)
170+
{
171+
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
172+
}
142173
}
143174
}
144175
}

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ public override IDictionary<string, Action> GetQuickFixes()
2626
private void DeclareAsExplicitVariant()
2727
{
2828
var codeModule = QualifiedSelection.QualifiedName.Component.CodeModule;
29-
var codeLine = codeModule.get_Lines(QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.LineCount);
29+
var codeLine = codeModule.Lines[QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.LineCount];
3030

3131
// methods return empty string if soft-cast context is null - just concat results:
3232
string originalInstruction;
33-
var fix = DeclareExplicitVariant(Context as VBAParser.VariableSubStmtContext, out originalInstruction);
33+
var fix = DeclareExplicitVariant(Context.Parent as VBAParser.VariableSubStmtContext, out originalInstruction);
3434

3535
if (string.IsNullOrEmpty(originalInstruction))
3636
{
37-
fix = DeclareExplicitVariant(Context as VBAParser.ConstSubStmtContext, out originalInstruction);
37+
fix = DeclareExplicitVariant(Context.Parent as VBAParser.ConstSubStmtContext, out originalInstruction);
3838
}
3939

4040
if (string.IsNullOrEmpty(originalInstruction))
4141
{
42-
fix = DeclareExplicitVariant(Context as VBAParser.ArgContext, out originalInstruction);
42+
fix = DeclareExplicitVariant(Context.Parent as VBAParser.ArgContext, out originalInstruction);
4343
}
4444

4545
var fixedCodeLine = codeLine.Replace(originalInstruction, fix);

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@
283283
<Compile Include="Inspections\VariableNotAssignedInspection.cs" />
284284
<Compile Include="Inspections\IdentifierNotAssignedInspectionResult.cs" />
285285
<Compile Include="UI\FolderBrowser.cs" />
286+
<Compile Include="UI\Settings\AddMarkerForm.cs">
287+
<SubType>Form</SubType>
288+
</Compile>
289+
<Compile Include="UI\Settings\AddMarkerForm.Designer.cs">
290+
<DependentUpon>AddMarkerForm.cs</DependentUpon>
291+
</Compile>
292+
<Compile Include="UI\Settings\IAddTodoSettingsView.cs" />
286293
<Compile Include="UI\SourceControl\App.cs" />
287294
<Compile Include="Properties\Annotations.cs" />
288295
<Compile Include="Properties\Resources.Designer.cs">
@@ -466,7 +473,7 @@
466473
<Compile Include="Inspections\OptionExplicitInspectionResult.cs" />
467474
<Compile Include="Inspections\VariableTypeNotDeclaredInspection.cs" />
468475
<Compile Include="Inspections\VariableTypeNotDeclaredInspectionResult.cs" />
469-
<Compile Include="ToDoItems\TaskPriority.cs" />
476+
<Compile Include="ToDoItems\TodoPriority.cs" />
470477
<Compile Include="UI\AboutWindow.cs">
471478
<SubType>Form</SubType>
472479
</Compile>
@@ -591,6 +598,9 @@
591598
<DependentUpon>FindSymbolDialog.cs</DependentUpon>
592599
</EmbeddedResource>
593600
<EmbeddedResource Include="UI\RubberduckUI.sv.resx" />
601+
<EmbeddedResource Include="UI\Settings\AddMarkerForm.resx">
602+
<DependentUpon>AddMarkerForm.cs</DependentUpon>
603+
</EmbeddedResource>
594604
<EmbeddedResource Include="UI\SimpleListControl.resx">
595605
<DependentUpon>SimpleListControl.cs</DependentUpon>
596606
</EmbeddedResource>

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using System.Windows.Forms;
77
using Rubberduck.Inspections;
8+
using Rubberduck.ToDoItems;
89
using Rubberduck.UI;
910

1011
namespace Rubberduck.Settings
@@ -69,7 +70,7 @@ protected override Configuration HandleIOException(IOException ex)
6970
protected override Configuration HandleInvalidOperationException(InvalidOperationException ex)
7071
{
7172
var message = string.Format(RubberduckUI.PromptLoadDefaultConfig, ex.Message, ex.InnerException.Message, ConfigFile);
72-
var result = MessageBox.Show(message, RubberduckUI.LoadConfigError, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
73+
var result = MessageBox.Show(message, RubberduckUI.LoadConfigError, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
7374

7475
if (result == DialogResult.Yes)
7576
{
@@ -113,7 +114,7 @@ public Configuration GetDefaultConfiguration()
113114
public ToDoMarker[] GetDefaultTodoMarkers()
114115
{
115116
var note = new ToDoMarker(RubberduckUI.ToDoMarkerNote, TodoPriority.Low);
116-
var todo = new ToDoMarker(RubberduckUI.ToDoMarkerToDo, TodoPriority.Normal);
117+
var todo = new ToDoMarker(RubberduckUI.ToDoMarkerToDo, TodoPriority.Medium);
117118
var bug = new ToDoMarker(RubberduckUI.ToDoMarkerBug, TodoPriority.High);
118119

119120
return new[] { note, todo, bug };

RetailCoder.VBE/Settings/ToDoMarkers.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System.Xml.Serialization;
1+
using System;
2+
using System.Xml.Serialization;
3+
using Rubberduck.ToDoItems;
4+
using Rubberduck.UI;
25

36
namespace Rubberduck.Settings
47
{
5-
public enum TodoPriority
6-
{
7-
Low,
8-
Normal,
9-
High
10-
}
11-
128
public interface IToDoMarker
139
{
1410
TodoPriority Priority { get; set; }
@@ -25,6 +21,23 @@ public class ToDoMarker : IToDoMarker
2521
[XmlAttribute]
2622
public TodoPriority Priority { get; set; }
2723

24+
[XmlIgnore]
25+
public string PriorityLabel
26+
{
27+
get { return RubberduckUI.ResourceManager.GetString("ToDoPriority_" + Priority, RubberduckUI.Culture); }
28+
set
29+
{
30+
foreach (var priority in Enum.GetValues(typeof(TodoPriority)))
31+
{
32+
if (value == RubberduckUI.ResourceManager.GetString("ToDoPriority_" + priority, RubberduckUI.Culture))
33+
{
34+
Priority = (TodoPriority)priority;
35+
return;
36+
}
37+
}
38+
}
39+
}
40+
2841
/// <summary> Default constructor is required for serialization. DO NOT USE. </summary>
2942
public ToDoMarker()
3043
{
@@ -43,5 +56,19 @@ public override string ToString()
4356
{
4457
return this.Text;
4558
}
59+
60+
public override bool Equals(object obj)
61+
{
62+
var other = (ToDoMarker)obj;
63+
64+
// no need to check PriorityLabel as it soley relies on Priority - if one is wrong, the other has to be too
65+
return Text == other.Text &&
66+
Priority == other.Priority;
67+
}
68+
69+
public override int GetHashCode()
70+
{
71+
return Text.GetHashCode();
72+
}
4673
}
4774
}

RetailCoder.VBE/ToDoItems/ToDoItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace Rubberduck.ToDoItems
1010
/// </summary>
1111
public class ToDoItem
1212
{
13-
private readonly TaskPriority _priority;
14-
public TaskPriority Priority{ get { return _priority; } }
13+
private readonly TodoPriority _priority;
14+
public TodoPriority Priority { get { return _priority; } }
1515

1616
public string PriorityLabel { get { return RubberduckUI.ResourceManager.GetString("ToDoPriority_" + Priority, RubberduckUI.Culture); } }
1717

@@ -30,12 +30,12 @@ public class ToDoItem
3030
private readonly QualifiedSelection _selection;
3131
public QualifiedSelection GetSelection() { return _selection; }
3232

33-
public ToDoItem(TaskPriority priority, CommentNode comment)
33+
public ToDoItem(TodoPriority priority, CommentNode comment)
3434
: this(priority, comment.CommentText, comment.QualifiedSelection)
3535
{
3636
}
3737

38-
public ToDoItem(TaskPriority priority, string description, QualifiedSelection qualifiedSelection)
38+
public ToDoItem(TodoPriority priority, string description, QualifiedSelection qualifiedSelection)
3939
{
4040
_priority = priority;
4141
_description = description;

RetailCoder.VBE/ToDoItems/TaskPriority.cs renamed to RetailCoder.VBE/ToDoItems/TodoPriority.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Rubberduck.ToDoItems
22
{
3-
public enum TaskPriority
3+
public enum TodoPriority
44
{
55
Low,
66
Medium,

RetailCoder.VBE/UI/CodeInspections/CodeInspectionsWindow.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public void SetIssuesStatus(int issueCount, bool completed = false)
8989
{
9090
_issueCount = issueCount;
9191

92-
RefreshButton.Image = completed
92+
RefreshButton.Enabled = completed; // remove this when uncommenting below lines
93+
94+
/*RefreshButton.Image = completed
9395
? Resources.arrow_circle_double
9496
: Resources.cross_circle;
9597
@@ -102,7 +104,7 @@ public void SetIssuesStatus(int issueCount, bool completed = false)
102104
{
103105
RefreshButton.Click -= CancelButton_Click;
104106
RefreshButton.Click += RefreshButtonClicked;
105-
}
107+
}*/
106108

107109

108110
if (issueCount == 0)

0 commit comments

Comments
 (0)