Skip to content

Commit 667c358

Browse files
authored
Merge branch 'next' into next
2 parents 9e0d457 + 38c48ed commit 667c358

File tree

285 files changed

+9796
-8134
lines changed

Some content is hidden

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

285 files changed

+9796
-8134
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ This library makes localizing WPF applications at runtime using resx files a bre
9595

9696
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx) with the [author's permission](http://www.codeproject.com/Messages/5272045/Re-License.aspx) to re-release under the GPLv3.
9797
98-
###[Using Raw Input from C# to handle multiple keyboards](http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard)
99-
100-
A library using the Raw Input API for reacting to low level keyboard/mouse events.
101-
102-
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx).
103-
10498
##Icons
10599

106100
We didn't come up with these icons ourselves! Here's who did what:

RetailCoder.VBE/App.cs

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,23 @@
33
using Infralution.Localization.Wpf;
44
using NLog;
55
using Rubberduck.Common;
6-
using Rubberduck.Parsing;
7-
using Rubberduck.Parsing.Symbols;
8-
using Rubberduck.Parsing.VBA;
96
using Rubberduck.Settings;
107
using Rubberduck.UI;
118
using Rubberduck.UI.Command.MenuItems;
129
using System;
1310
using System.Globalization;
14-
using System.Linq;
1511
using System.Windows.Forms;
1612
using Rubberduck.UI.Command;
1713
using Rubberduck.UI.Command.MenuItems.CommandBars;
1814
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1915
using Rubberduck.VersionCheck;
16+
using Application = System.Windows.Forms.Application;
2017

2118
namespace Rubberduck
2219
{
2320
public sealed class App : IDisposable
2421
{
25-
private readonly IVBE _vbe;
2622
private readonly IMessageBox _messageBox;
27-
private readonly IParseCoordinator _parser;
2823
private readonly AutoSave.AutoSave _autoSave;
2924
private readonly IGeneralConfigService _configService;
3025
private readonly IAppMenu _appMenus;
@@ -39,85 +34,27 @@ public sealed class App : IDisposable
3934

4035
public App(IVBE vbe,
4136
IMessageBox messageBox,
42-
IParseCoordinator parser,
4337
IGeneralConfigService configService,
4438
IAppMenu appMenus,
4539
RubberduckCommandBar stateBar,
4640
IRubberduckHooks hooks,
4741
IVersionCheck version,
4842
CommandBase checkVersionCommand)
4943
{
50-
_vbe = vbe;
5144
_messageBox = messageBox;
52-
_parser = parser;
5345
_configService = configService;
54-
_autoSave = new AutoSave.AutoSave(_vbe, _configService);
46+
_autoSave = new AutoSave.AutoSave(vbe, _configService);
5547
_appMenus = appMenus;
5648
_stateBar = stateBar;
5749
_hooks = hooks;
5850
_version = version;
5951
_checkVersionCommand = checkVersionCommand;
6052

61-
_hooks.MessageReceived += _hooks_MessageReceived;
6253
_configService.SettingsChanged += _configService_SettingsChanged;
63-
_parser.State.StateChanged += Parser_StateChanged;
64-
_parser.State.StatusMessageUpdate += State_StatusMessageUpdate;
65-
54+
6655
UiDispatcher.Initialize();
6756
}
6857

69-
private void State_StatusMessageUpdate(object sender, RubberduckStatusMessageEventArgs e)
70-
{
71-
var message = e.Message;
72-
if (message == ParserState.LoadingReference.ToString())
73-
{
74-
// note: ugly hack to enable Rubberduck.Parsing assembly to do this
75-
message = RubberduckUI.ParserState_LoadingReference;
76-
}
77-
78-
_stateBar.SetStatusLabelCaption(message, _parser.State.ModuleExceptions.Count);
79-
}
80-
81-
private void _hooks_MessageReceived(object sender, HookEventArgs e)
82-
{
83-
RefreshSelection();
84-
}
85-
86-
private ParserState _lastStatus;
87-
private Declaration _lastSelectedDeclaration;
88-
89-
private void RefreshSelection()
90-
{
91-
var pane = _vbe.ActiveCodePane;
92-
{
93-
Declaration selectedDeclaration = null;
94-
if (!pane.IsWrappingNullReference)
95-
{
96-
selectedDeclaration = _parser.State.FindSelectedDeclaration(pane);
97-
var refCount = selectedDeclaration == null ? 0 : selectedDeclaration.References.Count();
98-
var caption = _stateBar.GetContextSelectionCaption(_vbe.ActiveCodePane, selectedDeclaration);
99-
_stateBar.SetContextSelectionCaption(caption, refCount);
100-
}
101-
102-
var currentStatus = _parser.State.Status;
103-
if (ShouldEvaluateCanExecute(selectedDeclaration, currentStatus))
104-
{
105-
_appMenus.EvaluateCanExecute(_parser.State);
106-
_stateBar.EvaluateCanExecute(_parser.State);
107-
}
108-
109-
_lastStatus = currentStatus;
110-
_lastSelectedDeclaration = selectedDeclaration;
111-
}
112-
}
113-
114-
private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserState currentStatus)
115-
{
116-
return _lastStatus != currentStatus ||
117-
(selectedDeclaration != null && !selectedDeclaration.Equals(_lastSelectedDeclaration)) ||
118-
(selectedDeclaration == null && _lastSelectedDeclaration != null);
119-
}
120-
12158
private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
12259
{
12360
_config = _configService.LoadConfiguration();
@@ -163,8 +100,7 @@ public void Startup()
163100
_stateBar.Initialize();
164101
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
165102
_appMenus.Localize();
166-
_stateBar.SetStatusLabelCaption(ParserState.Pending);
167-
_stateBar.EvaluateCanExecute(_parser.State);
103+
168104
UpdateLoggingLevel();
169105

170106
if (_config.UserSettings.GeneralSettings.CheckVersion)
@@ -185,14 +121,6 @@ public void Shutdown()
185121
}
186122
}
187123

188-
private void Parser_StateChanged(object sender, EventArgs e)
189-
{
190-
Logger.Debug("App handles StateChanged ({0}), evaluating menu states...", _parser.State.Status);
191-
_appMenus.EvaluateCanExecute(_parser.State);
192-
_stateBar.EvaluateCanExecute(_parser.State);
193-
_stateBar.SetStatusLabelCaption(_parser.State.Status, _parser.State.ModuleExceptions.Count);
194-
}
195-
196124
private void LoadConfig()
197125
{
198126
_config = _configService.LoadConfiguration();
@@ -263,17 +191,6 @@ public void Dispose()
263191
return;
264192
}
265193

266-
if (_parser != null && _parser.State != null)
267-
{
268-
_parser.State.StateChanged -= Parser_StateChanged;
269-
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
270-
}
271-
272-
if (_hooks != null)
273-
{
274-
_hooks.MessageReceived -= _hooks_MessageReceived;
275-
}
276-
277194
if (_configService != null)
278195
{
279196
_configService.SettingsChanged -= _configService_SettingsChanged;

RetailCoder.VBE/AppMenu.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Rubberduck.Parsing;
45
using Rubberduck.Parsing.VBA;
6+
using Rubberduck.UI;
57
using Rubberduck.UI.Command.MenuItems;
68
using Rubberduck.UI.Command.MenuItems.ParentMenus;
79

@@ -10,10 +12,17 @@ namespace Rubberduck
1012
public class AppMenu : IAppMenu, IDisposable
1113
{
1214
private readonly IReadOnlyList<IParentMenuItem> _menus;
15+
private readonly IParseCoordinator _parser;
16+
private readonly ISelectionChangeService _selectionService;
1317

14-
public AppMenu(IEnumerable<IParentMenuItem> menus)
18+
public AppMenu(IEnumerable<IParentMenuItem> menus, IParseCoordinator parser, ISelectionChangeService selectionService)
1519
{
1620
_menus = menus.ToList();
21+
_parser = parser;
22+
_selectionService = selectionService;
23+
24+
_parser.State.StateChanged += OnParserStateChanged;
25+
_selectionService.SelectedDeclarationChanged += OnSelectedDeclarationChange;
1726
}
1827

1928
public void Initialize()
@@ -24,6 +33,16 @@ public void Initialize()
2433
}
2534
}
2635

36+
public void OnSelectedDeclarationChange(object sender, DeclarationChangedEventArgs e)
37+
{
38+
EvaluateCanExecute(_parser.State);
39+
}
40+
41+
private void OnParserStateChanged(object sender, EventArgs e)
42+
{
43+
EvaluateCanExecute(_parser.State);
44+
}
45+
2746
public void EvaluateCanExecute(RubberduckParserState state)
2847
{
2948
foreach (var menu in _menus)
@@ -42,6 +61,9 @@ public void Localize()
4261

4362
public void Dispose()
4463
{
64+
_parser.State.StateChanged -= OnParserStateChanged;
65+
_selectionService.SelectedDeclarationChanged -= OnSelectedDeclarationChange;
66+
4567
// note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
4668
//foreach (var menu in _menus.Where(menu => menu.Item != null))
4769
//{

0 commit comments

Comments
 (0)