Skip to content

Commit 142de1a

Browse files
Hosch250retailcoder
authored andcommitted
Move copy command (#1677)
* Move copy command * Remove unused using directives
1 parent 6560d81 commit 142de1a

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
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+
}

0 commit comments

Comments
 (0)