Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8b61706
Made the `ParseCoordinator` remove all references upon reparse and no…
MDoerner Feb 24, 2017
93385bf
Fixed issue #2737.
MDoerner Feb 24, 2017
3c6bfd6
Add checks for protected projects in project event handlers.
comintern Feb 25, 2017
812d8bd
Limit VBComponents\VBProjects handlers to a single instance. Check pr…
comintern Feb 25, 2017
96eca0c
Disable logging to the system logs. Closes #2739
comintern Feb 25, 2017
df50fac
Missed a line removing the system logging.
comintern Feb 25, 2017
16f698a
Replace manual filepath parsing with Path statics.
comintern Feb 25, 2017
587217f
R#'d file.
comintern Feb 25, 2017
771bde1
Make branch name rule more complete, convert to regular expression.
comintern Feb 25, 2017
e98a1d1
More manual filepath replacements.
comintern Feb 25, 2017
7dc5c48
Use default repository directory from settings. Closes #2726
comintern Feb 25, 2017
e270a7f
Merge pull request #2738 from MDoerner/ProperlyCleanUpReferencesFromP…
retailcoder Feb 25, 2017
12d625b
Select path delimiter based on local network v. non-local network.
comintern Feb 25, 2017
97cbcd0
Split the correct path string for CloneRemotePath...
comintern Feb 25, 2017
f2c7576
Remove retun from WndProc - WM_DESTROY needs to reach base.
comintern Feb 25, 2017
1e5df7a
Conflict resolution commit.
comintern Feb 25, 2017
3a11174
Add comments for R# suppressions.
comintern Feb 25, 2017
b78e8bf
Fix unicode escapes in regex, remove multi-level requirement.
comintern Feb 25, 2017
03aaf15
Fix bad file path construction for Undo.
comintern Feb 25, 2017
5346f62
Wrap Environment to support testing, add trys.
comintern Feb 25, 2017
cf8001a
Rearrange mocks.
comintern Feb 25, 2017
601665c
Fix broken test that was testing broken behavior.
comintern Feb 25, 2017
a87e067
Merge branch 'next' into next
comintern Feb 25, 2017
1349239
Merge pull request #2740 from comintern/next
retailcoder Feb 25, 2017
9d2c779
Check for null project IDs before raising events with them.
comintern Feb 25, 2017
af3b2f3
Fix name validation for EncapsulateFieldDialog
comintern Feb 25, 2017
23e4f61
Fix code writing logic in EncapsulateFieldDialog. Corrected Get for V…
comintern Feb 25, 2017
485939b
Merge branch 'next' of https://github.com/comintern/Rubberduck.git
comintern Feb 25, 2017
600fac4
Refactor EncapsulateField to share code-writing code. Commented out t…
comintern Feb 26, 2017
6d17b95
Merge branch 'next' into next
comintern Feb 26, 2017
ad6b9c0
Added IsReferencedByModule and HasReferenceToModule to ModuleState
MDoerner Feb 26, 2017
99ff37a
Added access through the RubberduckParserState.
MDoerner Feb 26, 2017
5f86fa8
Added module to module reference handling to the ParseCoordinator.
MDoerner Feb 27, 2017
127ad15
Merge pull request #2743 from comintern/next
retailcoder Feb 27, 2017
1fb243e
Merge branch 'next' into SavingModuleReferences
retailcoder Feb 27, 2017
01e4c0a
Gut App.cs, and move the entrails to classes that should have those r…
comintern Feb 27, 2017
f9a7d78
Handler should be Invoked, not called directly.
comintern Feb 27, 2017
1ede1e8
Merge branch 'next' of https://github.com/comintern/Rubberduck.git
comintern Feb 27, 2017
76cf060
Merge branch 'next' into next
comintern Feb 27, 2017
62e6783
Merge pull request #2746 from comintern/next
retailcoder Feb 27, 2017
352e12e
Merge branch 'next' into SavingModuleReferences
retailcoder Feb 27, 2017
5cdccba
Merge pull request #2745 from MDoerner/SavingModuleReferences
retailcoder Feb 27, 2017
57abcf5
Freshen up Ducky.ico using the same image source as the About dialog.
comintern Feb 27, 2017
d10ff37
Merge branch 'next' of https://github.com/comintern/Rubberduck.git
comintern Feb 27, 2017
ee893d2
Merge branch 'next' into next
comintern Feb 27, 2017
4ad4e25
Merge pull request #2748 from comintern/next
retailcoder Feb 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 3 additions & 175 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,23 @@
using Infralution.Localization.Wpf;
using NLog;
using Rubberduck.Common;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Settings;
using Rubberduck.UI;
using Rubberduck.UI.Command.MenuItems;
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Rubberduck.UI.Command;
using Rubberduck.UI.Command.MenuItems.CommandBars;
using Rubberduck.VBEditor.Events;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using Rubberduck.VBEditor.SafeComWrappers.MSForms;
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
using Rubberduck.VersionCheck;
using Application = System.Windows.Forms.Application;

namespace Rubberduck
{
public sealed class App : IDisposable
{
private readonly IVBE _vbe;
private readonly IMessageBox _messageBox;
private readonly IParseCoordinator _parser;
private readonly AutoSave.AutoSave _autoSave;
private readonly IGeneralConfigService _configService;
private readonly IAppMenu _appMenus;
Expand All @@ -44,171 +34,27 @@ public sealed class App : IDisposable

public App(IVBE vbe,
IMessageBox messageBox,
IParseCoordinator parser,
IGeneralConfigService configService,
IAppMenu appMenus,
RubberduckCommandBar stateBar,
IRubberduckHooks hooks,
IVersionCheck version,
CommandBase checkVersionCommand)
{
_vbe = vbe;
_messageBox = messageBox;
_parser = parser;
_configService = configService;
_autoSave = new AutoSave.AutoSave(_vbe, _configService);
_autoSave = new AutoSave.AutoSave(vbe, _configService);
_appMenus = appMenus;
_stateBar = stateBar;
_hooks = hooks;
_version = version;
_checkVersionCommand = checkVersionCommand;

VBENativeServices.SelectionChanged += _vbe_SelectionChanged;
VBENativeServices.WindowFocusChange += _vbe_FocusChanged;

_configService.SettingsChanged += _configService_SettingsChanged;
_parser.State.StateChanged += Parser_StateChanged;
_parser.State.StatusMessageUpdate += State_StatusMessageUpdate;


UiDispatcher.Initialize();
}

//TODO - This should be able to move to the appropriate handling classes now.
#region Statusbar

private void State_StatusMessageUpdate(object sender, RubberduckStatusMessageEventArgs e)
{
var message = e.Message;
if (message == ParserState.LoadingReference.ToString())
{
// note: ugly hack to enable Rubberduck.Parsing assembly to do this
message = RubberduckUI.ParserState_LoadingReference;
}

_stateBar.SetStatusLabelCaption(message, _parser.State.ModuleExceptions.Count);
}

private void _vbe_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
RefreshSelection(e.CodePane);
}

private void _vbe_FocusChanged(object sender, WindowChangedEventArgs e)
{
if (e.EventType == FocusType.GotFocus)
{
switch (e.Window.Type)
{
case WindowKind.Designer:
//Designer or control on designer form selected.
RefreshSelection(e.Window);
break;
case WindowKind.CodeWindow:
//Caret changed in a code pane.
RefreshSelection(e.CodePane);
break;
}
}
else if (e.EventType == FocusType.ChildFocus)
{
//Treeview selection changed in project window.
RefreshSelection();
}
}

private ParserState _lastStatus;
private Declaration _lastSelectedDeclaration;
private void RefreshSelection(ICodePane pane)
{
if (pane == null || pane.IsWrappingNullReference)
{
return;
}

var selectedDeclaration = _parser.State.FindSelectedDeclaration(pane);
var caption = _stateBar.GetContextSelectionCaption(_vbe.ActiveCodePane, selectedDeclaration);
UpdateStatusbarAndCommandState(caption, selectedDeclaration);
}

private void RefreshSelection(IWindow window)
{
if (window == null || window.IsWrappingNullReference || window.Type != WindowKind.Designer)
{
return;
}

var component = _vbe.SelectedVBComponent;
var caption = GetComponentControlsCaption(component);
//TODO: Need to find the selected declaration for the Form\Control.
UpdateStatusbarAndCommandState(caption, null);
}

private void RefreshSelection()
{
var caption = string.Empty;
var component = _vbe.SelectedVBComponent;
if (component == null || component.IsWrappingNullReference)
{
//The user might have selected the project node in Project Explorer
//If they've chosen a folder, we'll return the project anyway
caption = !_vbe.ActiveVBProject.IsWrappingNullReference
? _vbe.ActiveVBProject.Name
: null;
}
else
{
caption = component.Type == ComponentType.UserForm && component.HasOpenDesigner
? GetComponentControlsCaption(component)
: string.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, component.Type);
}
//TODO: Need to find the selected declaration for the selected treeview item.
UpdateStatusbarAndCommandState(caption, null);
}

private void UpdateStatusbarAndCommandState(string caption, Declaration selectedDeclaration)
{
var refCount = selectedDeclaration == null ? 0 : selectedDeclaration.References.Count();
_stateBar.SetContextSelectionCaption(caption, refCount);

var currentStatus = _parser.State.Status;
if (ShouldEvaluateCanExecute(selectedDeclaration, currentStatus))
{
_appMenus.EvaluateCanExecute(_parser.State);
_stateBar.EvaluateCanExecute(_parser.State);
}

_lastStatus = currentStatus;
_lastSelectedDeclaration = selectedDeclaration;
}

private string GetComponentControlsCaption(IVBComponent component)
{
switch (component.SelectedControls.Count)
{
case 0:
//TODO get the real designer for VB6
return String.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, "MSForms.UserForm");
break;
case 1:
//TODO return the libraryName.className of the control
IControl control = component.SelectedControls.First();
return String.Format("{0}.{1}.{2} ({3})", component.ParentProject.Name, component.Name, control.Name, control.TypeName());
break;
default:
return String.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, RubberduckUI.ContextMultipleControlsSelection);
break;
}
}

private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserState currentStatus)
{
return _lastStatus != currentStatus ||
(selectedDeclaration != null && !selectedDeclaration.Equals(_lastSelectedDeclaration)) ||
(selectedDeclaration == null && _lastSelectedDeclaration != null);
}

#endregion

private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
{
_config = _configService.LoadConfiguration();
Expand Down Expand Up @@ -254,8 +100,7 @@ public void Startup()
_stateBar.Initialize();
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
_appMenus.Localize();
_stateBar.SetStatusLabelCaption(ParserState.Pending);
_stateBar.EvaluateCanExecute(_parser.State);

UpdateLoggingLevel();

if (_config.UserSettings.GeneralSettings.CheckVersion)
Expand All @@ -276,14 +121,6 @@ public void Shutdown()
}
}

private void Parser_StateChanged(object sender, EventArgs e)
{
Logger.Debug("App handles StateChanged ({0}), evaluating menu states...", _parser.State.Status);
_appMenus.EvaluateCanExecute(_parser.State);
_stateBar.EvaluateCanExecute(_parser.State);
_stateBar.SetStatusLabelCaption(_parser.State.Status, _parser.State.ModuleExceptions.Count);
}

private void LoadConfig()
{
_config = _configService.LoadConfiguration();
Expand Down Expand Up @@ -354,15 +191,6 @@ public void Dispose()
return;
}

if (_parser != null && _parser.State != null)
{
_parser.State.StateChanged -= Parser_StateChanged;
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
}

VBENativeServices.SelectionChanged += _vbe_SelectionChanged;
VBENativeServices.WindowFocusChange += _vbe_FocusChanged;

if (_configService != null)
{
_configService.SettingsChanged -= _configService_SettingsChanged;
Expand Down
24 changes: 23 additions & 1 deletion RetailCoder.VBE/AppMenu.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Parsing;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI;
using Rubberduck.UI.Command.MenuItems;
using Rubberduck.UI.Command.MenuItems.ParentMenus;

Expand All @@ -10,10 +12,17 @@ namespace Rubberduck
public class AppMenu : IAppMenu, IDisposable
{
private readonly IReadOnlyList<IParentMenuItem> _menus;
private readonly IParseCoordinator _parser;
private readonly ISelectionChangeService _selectionService;

public AppMenu(IEnumerable<IParentMenuItem> menus)
public AppMenu(IEnumerable<IParentMenuItem> menus, IParseCoordinator parser, ISelectionChangeService selectionService)
{
_menus = menus.ToList();
_parser = parser;
_selectionService = selectionService;

_parser.State.StateChanged += OnParserStateChanged;
_selectionService.SelectedDeclarationChanged += OnSelectedDeclarationChange;
}

public void Initialize()
Expand All @@ -24,6 +33,16 @@ public void Initialize()
}
}

public void OnSelectedDeclarationChange(object sender, DeclarationChangedEventArgs e)
{
EvaluateCanExecute(_parser.State);
}

private void OnParserStateChanged(object sender, EventArgs e)
{
EvaluateCanExecute(_parser.State);
}

public void EvaluateCanExecute(RubberduckParserState state)
{
foreach (var menu in _menus)
Expand All @@ -42,6 +61,9 @@ public void Localize()

public void Dispose()
{
_parser.State.StateChanged -= OnParserStateChanged;
_selectionService.SelectedDeclarationChanged -= OnSelectedDeclarationChange;

// note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
//foreach (var menu in _menus.Where(menu => menu.Item != null))
//{
Expand Down
Binary file modified RetailCoder.VBE/Ducky.ico
Binary file not shown.
7 changes: 0 additions & 7 deletions RetailCoder.VBE/NLog.dll.nlog
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@
deleteOldFileOnStartup="true"
keepFileOpen="false"
encoding="UTF-8"/>
<target
xsi:type="EventLog"
name="eventlog"
source="Rubberduck-VBA"
layout="${message}${newline}Call site: ${callsite:className=true:methodName=true}${newline}Logger: ${logger}${newline}${exception:format=tostring}">
</target>
<target
xsi:type="Debugger"
name="debuglog"
layout="${longdate};${uppercase:${level}};${logger};${message};${exception:format=tostring}"/>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
<logger name="*" minlevel="Error" writeTo="eventlog"/>
<logger name="*" minlevel="Trace" writeTo="debuglog" />
</rules>
</nlog>
Loading