Skip to content

Commit a322558

Browse files
committed
Merge pull request #115 from rubberduck-vba/next
sync with main repo
2 parents aba3402 + 8242ad4 commit a322558

File tree

7 files changed

+2741
-2694
lines changed

7 files changed

+2741
-2694
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4-
using System.Globalization;
5-
using System.IO;
64
using System.Linq;
7-
using System.Windows;
85
using System.Windows.Input;
96
using Microsoft.Vbe.Interop;
10-
using Rubberduck.Common;
117
using Rubberduck.Navigation.Folders;
128
using Rubberduck.Parsing.Annotations;
139
using Rubberduck.Parsing.Symbols;
@@ -26,17 +22,13 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2622
{
2723
private readonly FolderHelper _folderHelper;
2824
private readonly RubberduckParserState _state;
29-
private readonly IClipboardWriter _clipboard;
3025

3126
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<ICommand> commands)
3227
{
3328
_folderHelper = folderHelper;
3429
_state = state;
3530
_state.StateChanged += ParserState_StateChanged;
36-
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
37-
38-
_clipboard = new ClipboardWriter();
39-
31+
4032
_refreshCommand = new DelegateCommand(param => _state.OnParseRequested(this),
4133
param => !IsBusy && _state.IsDirty());
4234

@@ -68,37 +60,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
6860
_commitCommand = commands.OfType<CodeExplorer_CommitCommand>().FirstOrDefault();
6961
_undoCommand = commands.OfType<CodeExplorer_UndoCommand>().FirstOrDefault();
7062

71-
//_copyResultsCommand = commands.OfType<CodeExplorer_CopyResultsCommand>().FirstOrDefault();
72-
73-
_copyResultsCommand = new DelegateCommand(param =>
74-
{
75-
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet";
76-
77-
ColumnInfo[] ColumnInfos = { new ColumnInfo("Project"), new ColumnInfo("Folder"), new ColumnInfo("Component"), new ColumnInfo("Declaration Type"), new ColumnInfo("Scope"),
78-
new ColumnInfo("Name"), new ColumnInfo("Return Type") };
79-
80-
// this.ProjectName, this.CustomFolder, this.ComponentName, this.DeclarationType.ToString(), this.Scope
81-
var aDeclarations = _state.AllUserDeclarations.Select(declaration => declaration.ToArray()).ToArray();
82-
83-
var resource = "Rubberduck User Declarations - {0}";
84-
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture));
85-
86-
//var textResults = title + Environment.NewLine + string.Join("", _results.Select(result => result.ToString() + Environment.NewLine).ToArray());
87-
var csvResults = ExportFormatter.Csv(aDeclarations, title, ColumnInfos);
88-
var htmlResults = ExportFormatter.HtmlClipboardFragment(aDeclarations, title, ColumnInfos);
89-
var rtfResults = ExportFormatter.RTF(aDeclarations, title);
90-
91-
MemoryStream strm1 = ExportFormatter.XmlSpreadsheetNew(aDeclarations, title, ColumnInfos);
92-
//Add the formats from richest formatting to least formatting
93-
_clipboard.AppendStream(DataFormats.GetDataFormat(XML_SPREADSHEET_DATA_FORMAT).Name, strm1);
94-
_clipboard.AppendString(DataFormats.Rtf, rtfResults);
95-
_clipboard.AppendString(DataFormats.Html, htmlResults);
96-
_clipboard.AppendString(DataFormats.CommaSeparatedValue, csvResults);
97-
//_clipboard.AppendString(DataFormats.UnicodeText, textResults);
98-
99-
_clipboard.Flush();
100-
101-
});
63+
_copyResultsCommand = commands.OfType<CodeExplorer_CopyResultsCommand>().FirstOrDefault();
10264

10365
_setNameSortCommand = new DelegateCommand(param =>
10466
{

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@
404404
</Compile>
405405
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_CommitCommand.cs" />
406406
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_AddUserFormCommand.cs" />
407+
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_CopyResultsCommand.cs" />
407408
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RefreshComponentCommand.cs" />
408409
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RenameCommand.cs" />
409410
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllReferencesCommand.cs" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Linq;
4+
using System.Windows;
5+
using Rubberduck.Common;
6+
using Rubberduck.Parsing.VBA;
7+
using Rubberduck.UI.Command;
8+
9+
namespace Rubberduck.UI.CodeExplorer.Commands
10+
{
11+
public class CodeExplorer_CopyResultsCommand : CommandBase
12+
{
13+
private readonly RubberduckParserState _state;
14+
private readonly IClipboardWriter _clipboard;
15+
16+
public CodeExplorer_CopyResultsCommand(RubberduckParserState state)
17+
{
18+
_state = state;
19+
_clipboard = new ClipboardWriter();
20+
}
21+
22+
public override void Execute(object parameter)
23+
{
24+
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet";
25+
26+
ColumnInfo[] ColumnInfos = { new ColumnInfo("Project"), new ColumnInfo("Folder"), new ColumnInfo("Component"), new ColumnInfo("Declaration Type"), new ColumnInfo("Scope"),
27+
new ColumnInfo("Name"), new ColumnInfo("Return Type") };
28+
29+
// this.ProjectName, this.CustomFolder, this.ComponentName, this.DeclarationType.ToString(), this.Scope
30+
var aDeclarations = _state.AllUserDeclarations.Select(declaration => declaration.ToArray()).ToArray();
31+
32+
const string resource = "Rubberduck User Declarations - {0}";
33+
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture));
34+
35+
var csvResults = ExportFormatter.Csv(aDeclarations, title, ColumnInfos);
36+
var htmlResults = ExportFormatter.HtmlClipboardFragment(aDeclarations, title, ColumnInfos);
37+
var rtfResults = ExportFormatter.RTF(aDeclarations, title);
38+
39+
var strm1 = ExportFormatter.XmlSpreadsheetNew(aDeclarations, title, ColumnInfos);
40+
//Add the formats from richest formatting to least formatting
41+
_clipboard.AppendStream(DataFormats.GetDataFormat(XML_SPREADSHEET_DATA_FORMAT).Name, strm1);
42+
_clipboard.AppendString(DataFormats.Rtf, rtfResults);
43+
_clipboard.AppendString(DataFormats.Html, htmlResults);
44+
_clipboard.AppendString(DataFormats.CommaSeparatedValue, csvResults);
45+
46+
_clipboard.Flush();
47+
}
48+
}
49+
}

RetailCoder.VBE/UI/Command/ShowParserErrorsCommand.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,70 @@
66
using Microsoft.Vbe.Interop;
77
using Rubberduck.Parsing.Symbols;
88
using Rubberduck.Parsing.VBA;
9+
using Rubberduck.UI.Command.MenuItems;
910
using Rubberduck.UI.Controls;
1011
using Rubberduck.VBEditor;
1112

1213
namespace Rubberduck.UI.Command
1314
{
14-
public interface IShowParserErrorsCommand : ICommand { }
15+
public interface IShowParserErrorsCommand : ICommand, IDisposable { }
1516

1617
[ComVisible(false)]
1718
public class ShowParserErrorsCommand : CommandBase, IShowParserErrorsCommand
1819
{
20+
private readonly VBE _vbe;
1921
private readonly INavigateCommand _navigateCommand;
2022
private readonly RubberduckParserState _state;
2123
private readonly ISearchResultsWindowViewModel _viewModel;
2224
private readonly SearchResultPresenterInstanceManager _presenterService;
2325

24-
public ShowParserErrorsCommand(INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
26+
public ShowParserErrorsCommand(VBE vbe, INavigateCommand navigateCommand, RubberduckParserState state, ISearchResultsWindowViewModel viewModel, SearchResultPresenterInstanceManager presenterService)
2527
{
28+
_vbe = vbe;
2629
_navigateCommand = navigateCommand;
2730
_state = state;
2831
_viewModel = viewModel;
2932
_presenterService = presenterService;
33+
34+
_state.StateChanged += _state_StateChanged;
3035
}
3136

32-
public override void Execute(object parameter)
37+
private void _state_StateChanged(object sender, ParserStateEventArgs e)
3338
{
34-
if (_state.Status != ParserState.Error)
35-
{
36-
return;
37-
}
39+
if (_viewModel == null) { return; }
3840

39-
var viewModel = CreateViewModel();
41+
if (_state.Status != ParserState.Error && _state.Status != ParserState.Parsed) { return; }
42+
43+
UiDispatcher.InvokeAsync(UpdateTab);
44+
}
45+
46+
private void UpdateTab()
47+
{
4048
if (_viewModel == null)
4149
{
4250
return;
4351
}
4452

4553
var oldTab = _viewModel.Tabs.FirstOrDefault(tab => tab.Header == RubberduckUI.Parser_ParserError);
46-
47-
_viewModel.AddTab(viewModel);
48-
_viewModel.SelectedTab = viewModel;
54+
if (_state.Status == ParserState.Error)
55+
{
56+
var viewModel = CreateViewModel();
57+
_viewModel.AddTab(viewModel);
58+
_viewModel.SelectedTab = viewModel;
59+
}
4960

5061
if (oldTab != null)
5162
{
5263
oldTab.CloseCommand.Execute(null);
5364
}
65+
}
66+
67+
public override void Execute(object parameter)
68+
{
69+
if (_viewModel == null)
70+
{
71+
return;
72+
}
5473

5574
try
5675
{
@@ -90,5 +109,13 @@ private Declaration FindModuleDeclaration(VBComponent component)
90109
var declaration = new Declaration(new QualifiedMemberName(new QualifiedModuleName(component), component.Name), project, project == null ? null : project.Scope, component.Name, null, false, false, Accessibility.Global, DeclarationType.ProceduralModule, false, null, false);
91110
return result ?? declaration; // module isn't in parser state - give it a dummy declaration, just so the ViewModel has something to chew on
92111
}
112+
113+
public void Dispose()
114+
{
115+
if (_state != null)
116+
{
117+
_state.StateChanged += _state_StateChanged;
118+
}
119+
}
93120
}
94121
}

0 commit comments

Comments
 (0)