1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Collections . ObjectModel ;
4
+ using System . Globalization ;
5
+ using System . IO ;
4
6
using System . Linq ;
7
+ using System . Windows ;
5
8
using System . Windows . Input ;
6
9
using Microsoft . Vbe . Interop ;
10
+ using Rubberduck . Common ;
7
11
using Rubberduck . Navigation . Folders ;
8
12
using Rubberduck . Parsing . Annotations ;
9
13
using Rubberduck . Parsing . Symbols ;
@@ -22,6 +26,7 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
22
26
{
23
27
private readonly FolderHelper _folderHelper ;
24
28
private readonly RubberduckParserState _state ;
29
+ private readonly IClipboardWriter _clipboard ;
25
30
26
31
public CodeExplorerViewModel ( FolderHelper folderHelper , RubberduckParserState state , List < ICommand > commands )
27
32
{
@@ -30,6 +35,8 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
30
35
_state . StateChanged += ParserState_StateChanged ;
31
36
_state . ModuleStateChanged += ParserState_ModuleStateChanged ;
32
37
38
+ _clipboard = new ClipboardWriter ( ) ;
39
+
33
40
_refreshCommand = commands . OfType < CodeExplorer_RefreshCommand > ( ) . FirstOrDefault ( ) ;
34
41
_refreshComponentCommand = commands . OfType < CodeExplorer_RefreshComponentCommand > ( ) . FirstOrDefault ( ) ;
35
42
_navigateCommand = commands . OfType < CodeExplorer_NavigateCommand > ( ) . FirstOrDefault ( ) ;
@@ -59,6 +66,38 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
59
66
_commitCommand = commands . OfType < CodeExplorer_CommitCommand > ( ) . FirstOrDefault ( ) ;
60
67
_undoCommand = commands . OfType < CodeExplorer_UndoCommand > ( ) . FirstOrDefault ( ) ;
61
68
69
+ //_copyResultsCommand = commands.OfType<CodeExplorer_CopyResultsCommand>().FirstOrDefault();
70
+
71
+ _copyResultsCommand = new DelegateCommand ( param =>
72
+ {
73
+ const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet" ;
74
+
75
+ ColumnInfo [ ] ColumnInfos = { new ColumnInfo ( "Project" ) , new ColumnInfo ( "Folder" ) , new ColumnInfo ( "Component" ) , new ColumnInfo ( "Declaration Type" ) , new ColumnInfo ( "Scope" ) ,
76
+ new ColumnInfo ( "Name" ) , new ColumnInfo ( "Return Type" ) } ;
77
+
78
+ // this.ProjectName, this.CustomFolder, this.ComponentName, this.DeclarationType.ToString(), this.Scope
79
+ var aDeclarations = _state . AllUserDeclarations . Select ( declaration => declaration . ToArray ( ) ) . ToArray ( ) ;
80
+
81
+ var resource = "Rubberduck User Declarations - {0}" ;
82
+ var title = string . Format ( resource , DateTime . Now . ToString ( CultureInfo . InvariantCulture ) ) ;
83
+
84
+ //var textResults = title + Environment.NewLine + string.Join("", _results.Select(result => result.ToString() + Environment.NewLine).ToArray());
85
+ var csvResults = ExportFormatter . Csv ( aDeclarations , title , ColumnInfos ) ;
86
+ var htmlResults = ExportFormatter . HtmlClipboardFragment ( aDeclarations , title , ColumnInfos ) ;
87
+ var rtfResults = ExportFormatter . RTF ( aDeclarations , title ) ;
88
+
89
+ MemoryStream strm1 = ExportFormatter . XmlSpreadsheetNew ( aDeclarations , title , ColumnInfos ) ;
90
+ //Add the formats from richest formatting to least formatting
91
+ _clipboard . AppendStream ( DataFormats . GetDataFormat ( XML_SPREADSHEET_DATA_FORMAT ) . Name , strm1 ) ;
92
+ _clipboard . AppendString ( DataFormats . Rtf , rtfResults ) ;
93
+ _clipboard . AppendString ( DataFormats . Html , htmlResults ) ;
94
+ _clipboard . AppendString ( DataFormats . CommaSeparatedValue , csvResults ) ;
95
+ //_clipboard.AppendString(DataFormats.UnicodeText, textResults);
96
+
97
+ _clipboard . Flush ( ) ;
98
+
99
+ } ) ;
100
+
62
101
_setNameSortCommand = new DelegateCommand ( param =>
63
102
{
64
103
SortByName = ( bool ) param ;
@@ -126,6 +165,9 @@ public bool SortBySelection
126
165
}
127
166
}
128
167
168
+ private readonly ICommand _copyResultsCommand ;
169
+ public ICommand CopyResultsCommand { get { return _copyResultsCommand ; } }
170
+
129
171
private readonly ICommand _setNameSortCommand ;
130
172
public ICommand SetNameSortCommand { get { return _setNameSortCommand ; } }
131
173
0 commit comments