Skip to content

Commit 28dcb9d

Browse files
authored
Merge pull request #3452 from ThunderFrame/next
Adds export/clipboard button to ToDo Explorer
2 parents c7dc9b3 + cfe1124 commit 28dcb9d

File tree

5 files changed

+137
-9
lines changed

5 files changed

+137
-9
lines changed

RetailCoder.VBE/ToDoItems/ToDoItem.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Rubberduck.Parsing.Symbols;
1+
using Rubberduck.Common;
2+
using Rubberduck.Parsing.Symbols;
23
using Rubberduck.UI;
34
using Rubberduck.UI.Controls;
45
using Rubberduck.VBEditor;
@@ -9,7 +10,7 @@ namespace Rubberduck.ToDoItems
910
/// Represents a Todo comment and the necessary information to display and navigate to that comment.
1011
/// This is a binding item. Changing it's properties changes how it is displayed.
1112
/// </summary>
12-
public class ToDoItem : INavigateSource
13+
public class ToDoItem : INavigateSource, IExportable
1314
{
1415
private readonly string _description;
1516
public string Description { get { return _description; } }
@@ -31,5 +32,23 @@ public NavigateCodeEventArgs GetNavigationArgs()
3132
{
3233
return new NavigateCodeEventArgs(_selection);
3334
}
35+
36+
public object[] ToArray()
37+
{
38+
var module = _selection.QualifiedName;
39+
return new object[] { _type, Description, module.ProjectName, module.ComponentName, _selection.Selection.StartLine, _selection.Selection.StartColumn };
40+
}
41+
42+
public string ToClipboardString()
43+
{
44+
var module = _selection.QualifiedName;
45+
return string.Format(
46+
RubberduckUI.ToDoExplorerToDoItemFormat,
47+
_type,
48+
_description,
49+
module.ProjectName,
50+
module.ComponentName,
51+
_selection.Selection.StartLine);
52+
}
3453
}
3554
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 41 additions & 4 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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -2106,4 +2106,20 @@ Would you like to import them to Rubberduck?</value>
21062106
<data name="RubberduckMenu_Refresh" xml:space="preserve">
21072107
<value>Refresh</value>
21082108
</data>
2109-
</root>
2109+
<data name="ToDoExplorer_NumberOfIssuesFound_Plural" xml:space="preserve">
2110+
<value>Rubberduck ToDo Items - {0}
2111+
{1} items found.</value>
2112+
<comment>{0}=timestamp; {1}=number</comment>
2113+
</data>
2114+
<data name="ToDoExplorer_NumberOfIssuesFound_Singular" xml:space="preserve">
2115+
<value>Rubberduck ToDo Items - {0}
2116+
{1} items found.</value>
2117+
<comment>{0}=timestamp; {1}=number</comment>
2118+
</data>
2119+
<data name="ToDoExplorerToDoItemFormat" xml:space="preserve">
2120+
<value>{0}: {1} - {2}.{3} line {4}.</value>
2121+
</data>
2122+
<data name="ToDoExplorer_CopyToolTip" xml:space="preserve">
2123+
<value>Copy to clipboard</value>
2124+
</data>
2125+
</root>

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerControl.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,12 @@
510510
controls:MenuItemGroup.GroupName="ToDoExplorer_GroupingStyle" />
511511
</MenuItem>
512512
</Menu>
513+
<Button Command="{Binding CopyResultsCommand}">
514+
<Image Height="16" Source="../../Resources/document-copy.png" />
515+
<Button.ToolTip>
516+
<TextBlock Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=ToDoExplorer_CopyToolTip}" />
517+
</Button.ToolTip>
518+
</Button>
513519
<Button ToolTip="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Settings}" Command="{Binding OpenTodoSettings}" BorderThickness="0" Background="Transparent">
514520
<Image Source="{StaticResource SettingsImage}" />
515521
</Button>

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Globalization;
45
using System.Linq;
6+
using System.Windows;
57
using NLog;
68
using Rubberduck.Parsing.VBA;
79
using Rubberduck.Settings;
@@ -155,6 +157,54 @@ public CommandBase RemoveCommand
155157
}
156158
}
157159

160+
private CommandBase _copyResultsCommand;
161+
public CommandBase CopyResultsCommand
162+
{
163+
get
164+
{
165+
if (_copyResultsCommand != null)
166+
{
167+
return _copyResultsCommand;
168+
}
169+
return _copyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ =>
170+
{
171+
const string xmlSpreadsheetDataFormat = "XML Spreadsheet";
172+
if (_items == null)
173+
{
174+
return;
175+
}
176+
ColumnInfo[] columnInfos = { new ColumnInfo("Type"), new ColumnInfo("Description"), new ColumnInfo("Project"), new ColumnInfo("Component"), new ColumnInfo("Line", hAlignment.Right), new ColumnInfo("Column", hAlignment.Right) };
177+
178+
var resultArray = _items.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
179+
180+
var resource = _items.Count == 1
181+
? RubberduckUI.ToDoExplorer_NumberOfIssuesFound_Singular
182+
: RubberduckUI.ToDoExplorer_NumberOfIssuesFound_Plural;
183+
184+
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture), _items.Count);
185+
186+
var textResults = title + Environment.NewLine + string.Join("", _items.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
187+
var csvResults = ExportFormatter.Csv(resultArray, title, columnInfos);
188+
var htmlResults = ExportFormatter.HtmlClipboardFragment(resultArray, title, columnInfos);
189+
var rtfResults = ExportFormatter.RTF(resultArray, title);
190+
191+
// todo: verify that this disposing this stream breaks the xmlSpreadsheetDataFormat
192+
var stream = ExportFormatter.XmlSpreadsheetNew(resultArray, title, columnInfos);
193+
194+
IClipboardWriter _clipboard = new ClipboardWriter();
195+
//Add the formats from richest formatting to least formatting
196+
_clipboard.AppendStream(DataFormats.GetDataFormat(xmlSpreadsheetDataFormat).Name, stream);
197+
_clipboard.AppendString(DataFormats.Rtf, rtfResults);
198+
_clipboard.AppendString(DataFormats.Html, htmlResults);
199+
_clipboard.AppendString(DataFormats.CommaSeparatedValue, csvResults);
200+
_clipboard.AppendString(DataFormats.UnicodeText, textResults);
201+
202+
_clipboard.Flush();
203+
204+
});
205+
}
206+
}
207+
158208
private CommandBase _openTodoSettings;
159209
public CommandBase OpenTodoSettings
160210
{

0 commit comments

Comments
 (0)