Skip to content

Commit 302e1df

Browse files
committed
Fix export (to clipboard) for inspection results and todo items
1 parent c7ac2da commit 302e1df

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Rubberduck.Core/Formatters/InspectionResultFormatter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Rubberduck.Common;
22
using Rubberduck.Parsing.Inspections.Abstract;
3-
using System.IO;
43
using Rubberduck.Resources.Inspections;
54

65
namespace Rubberduck.Formatters

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.ComponentModel;
66
using System.Diagnostics;
77
using System.Globalization;
8+
using System.IO;
89
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
@@ -13,6 +14,7 @@
1314
using System.Windows.Input;
1415
using NLog;
1516
using Rubberduck.Common;
17+
using Rubberduck.Formatters;
1618
using Rubberduck.Inspections.Abstract;
1719
using Rubberduck.Interaction.Navigation;
1820
using Rubberduck.JunkDrawer.Extensions;
@@ -666,15 +668,24 @@ private void ExecuteCopyResultsCommand(object parameter)
666668
return;
667669
}
668670

669-
var resultArray = Results.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
671+
var resultArray = Results
672+
.OfType<IInspectionResult>()
673+
.Select(result => new InspectionResultFormatter(result, DocumentName(result)))
674+
.Select(formattedResult => formattedResult.ToArray())
675+
.ToArray();
670676

671677
var resource = resultArray.Length == 1
672678
? Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Singular
673679
: Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Plural;
674680

675681
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture), resultArray.Count());
676682

677-
var textResults = title + Environment.NewLine + string.Join(string.Empty, Results.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
683+
var resultTexts = Results
684+
.OfType<IInspectionResult>()
685+
.Select(result => new InspectionResultFormatter(result, DocumentName(result)))
686+
.Select(formattedResult => $"{formattedResult.ToClipboardString()}{Environment.NewLine}")
687+
.ToArray();
688+
var textResults = $"{title}{Environment.NewLine}{string.Join(string.Empty, resultTexts)}";
678689
var csvResults = ExportFormatter.Csv(resultArray, title, ColumnInformation);
679690
var htmlResults = ExportFormatter.HtmlClipboardFragment(resultArray, title, ColumnInformation);
680691
var rtfResults = ExportFormatter.RTF(resultArray, title);
@@ -691,6 +702,20 @@ private void ExecuteCopyResultsCommand(object parameter)
691702
_clipboard.Flush();
692703
}
693704

705+
private string DocumentName(IInspectionResult result)
706+
{
707+
var module = result.QualifiedSelection.QualifiedName;
708+
var projectId = module.ProjectId;
709+
var project = _state.ProjectsProvider.Project(projectId);
710+
711+
if (project == null)
712+
{
713+
return Path.GetFileName(module.ProjectPath);
714+
}
715+
716+
return project.ProjectDisplayName;
717+
}
718+
694719
private bool CanExecuteCopyResultsCommand(object parameter)
695720
{
696721
return !IsBusy && _results != null && _results.Any();

Rubberduck.Core/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,21 @@ public void ExecuteCopyResultsCommand(object obj)
249249

250250
ColumnInfo[] columnInfos = { new ColumnInfo("Type"), new ColumnInfo("Description"), new ColumnInfo("Project"), new ColumnInfo("Component"), new ColumnInfo("Line", hAlignment.Right), new ColumnInfo("Column", hAlignment.Right) };
251251

252-
var resultArray = _items.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
252+
var resultArray = _items
253+
.Select(item => new ToDoItemFormatter(item))
254+
.Select(formattedItem => formattedItem.ToArray()).ToArray();
253255

254256
var resource = _items.Count == 1
255257
? ToDoExplorerUI.ToDoExplorer_NumberOfIssuesFound_Singular
256258
: ToDoExplorerUI.ToDoExplorer_NumberOfIssuesFound_Plural;
257259

258260
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture), _items.Count);
259261

260-
var textResults = title + Environment.NewLine + string.Join(string.Empty, _items.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
262+
var itemTexts = _items
263+
.Select(item => new ToDoItemFormatter(item))
264+
.Select(formattedItem => $"{formattedItem.ToClipboardString()}{Environment.NewLine}")
265+
.ToArray();
266+
var textResults = $"{title}{Environment.NewLine}{string.Join(string.Empty, itemTexts)}";
261267
var csvResults = ExportFormatter.Csv(resultArray, title, columnInfos);
262268
var htmlResults = ExportFormatter.HtmlClipboardFragment(resultArray, title, columnInfos);
263269
var rtfResults = ExportFormatter.RTF(resultArray, title);

0 commit comments

Comments
 (0)