Skip to content

Commit d90f4f3

Browse files
committed
Adds Copy button to Code Explorer, allows copy of *all* User Declarations
WIP...
1 parent 6c35c89 commit d90f4f3

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Globalization;
5+
using System.IO;
46
using System.Linq;
7+
using System.Windows;
58
using System.Windows.Input;
69
using Microsoft.Vbe.Interop;
10+
using Rubberduck.Common;
711
using Rubberduck.Navigation.Folders;
812
using Rubberduck.Parsing.Annotations;
913
using Rubberduck.Parsing.Symbols;
@@ -22,6 +26,7 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2226
{
2327
private readonly FolderHelper _folderHelper;
2428
private readonly RubberduckParserState _state;
29+
private readonly IClipboardWriter _clipboard;
2530

2631
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<ICommand> commands)
2732
{
@@ -30,6 +35,8 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
3035
_state.StateChanged += ParserState_StateChanged;
3136
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
3237

38+
_clipboard = new ClipboardWriter();
39+
3340
_refreshCommand = commands.OfType<CodeExplorer_RefreshCommand>().FirstOrDefault();
3441
_refreshComponentCommand = commands.OfType<CodeExplorer_RefreshComponentCommand>().FirstOrDefault();
3542
_navigateCommand = commands.OfType<CodeExplorer_NavigateCommand>().FirstOrDefault();
@@ -59,6 +66,38 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
5966
_commitCommand = commands.OfType<CodeExplorer_CommitCommand>().FirstOrDefault();
6067
_undoCommand = commands.OfType<CodeExplorer_UndoCommand>().FirstOrDefault();
6168

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+
62101
_setNameSortCommand = new DelegateCommand(param =>
63102
{
64103
SortByName = (bool)param;
@@ -126,6 +165,9 @@ public bool SortBySelection
126165
}
127166
}
128167

168+
private readonly ICommand _copyResultsCommand;
169+
public ICommand CopyResultsCommand { get { return _copyResultsCommand; } }
170+
129171
private readonly ICommand _setNameSortCommand;
130172
public ICommand SetNameSortCommand { get { return _setNameSortCommand; } }
131173

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,24 @@
701701
<TextBlock Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ShowDesignerToolTip}" />
702702
</Button.ToolTip>
703703
</Button>
704+
705+
<Separator />
706+
707+
<Button Command="{Binding CopyResultsCommand}">
708+
<Image Height="16" Source="../../Resources/document-copy.png" />
709+
<Button.ToolTip>
710+
<TextBlock Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_CopyToolTip}" />
711+
</Button.ToolTip>
712+
</Button>
713+
704714
</ToolBar>
705715
</ToolBarTray>
706716

707717
<TreeView Grid.Row="1"
708718
ItemContainerStyle="{StaticResource ShinyTreeView}"
709719
HorizontalContentAlignment="Stretch"
710720
MouseDoubleClick="TreeView_OnMouseDoubleClick"
721+
Style="{StaticResource CodeExplorerTreeViewStyle}" BorderThickness="0,1">
711722
<i:Interaction.Behaviors>
712723
<controls:BindableSelectedItemBehavior SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
713724
</i:Interaction.Behaviors>

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ Warning: All customized settings will be lost. Your old file will be saved in '
562562
<data name="CodeExplorer_ShowFoldersToolTip" xml:space="preserve">
563563
<value>Toggle folders</value>
564564
</data>
565+
<data name="CodeExplorer_CopyToolTip" xml:space="preserve">
566+
<value>Copy to clipboard</value>
567+
</data>
565568
<data name="CodeInspections_CopyToolTip" xml:space="preserve">
566569
<value>Copy inspection results to clipboard</value>
567570
</data>

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ public string ProjectName
405405
}
406406
}
407407

408+
public object[] ToArray()
409+
{
410+
return new object[] { this.ProjectName, this.CustomFolder, this.ComponentName, this.DeclarationType.ToString(), this.Scope, this.IdentifierName, this.AsTypeName };
411+
}
412+
413+
408414
/// <summary>
409415
/// Gets the name of the VBComponent the declaration is made in.
410416
/// </summary>

0 commit comments

Comments
 (0)