Skip to content

Commit f7add1a

Browse files
committed
Merge remote-tracking branch 'upstream/next' into Issue2777_CleanedUpCommits
2 parents 69e5d1e + 652b8ff commit f7add1a

File tree

25 files changed

+443
-120
lines changed

25 files changed

+443
-120
lines changed

Rubberduck.CodeAnalysis/Inspections/Abstract/InspectionBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
5-
using Rubberduck.Parsing.Annotations;
65
using Rubberduck.Parsing.Inspections.Abstract;
76
using Rubberduck.Parsing.Symbols;
87
using Rubberduck.Parsing.VBA;

Rubberduck.CodeAnalysis/Inspections/Abstract/InspectionResultBase.cs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Rubberduck.Inspections.Abstract
1313
{
14-
public abstract class InspectionResultBase : IInspectionResult, INavigateSource, IExportable
14+
public abstract class InspectionResultBase : IInspectionResult, INavigateSource
1515
{
1616
protected InspectionResultBase(IInspection inspection,
1717
string description,
@@ -56,39 +56,6 @@ public int CompareTo(IInspectionResult other)
5656
return Inspection.CompareTo(other.Inspection);
5757
}
5858

59-
/// <summary>
60-
/// WARNING: This property can have side effects. It can change the ActiveVBProject if the result has a null Declaration,
61-
/// which causes a flicker in the VBE. This should only be called if it is *absolutely* necessary.
62-
/// </summary>
63-
public string ToClipboardString()
64-
{
65-
var module = QualifiedSelection.QualifiedName;
66-
var documentName = Target != null
67-
? Target.ProjectDisplayName
68-
: string.Empty;
69-
//todo: Find a sane way to reimplement this.
70-
//if (string.IsNullOrEmpty(documentName))
71-
//{
72-
// var component = module.Component;
73-
// documentName = component != null
74-
// ? component.ParentProject.ProjectDisplayName
75-
// : string.Empty;
76-
//}
77-
if (string.IsNullOrEmpty(documentName))
78-
{
79-
documentName = Path.GetFileName(module.ProjectPath);
80-
}
81-
82-
return string.Format(
83-
InspectionsUI.QualifiedSelectionInspection,
84-
Inspection.Severity,
85-
Description,
86-
$"({documentName})",
87-
module.ProjectName,
88-
module.ComponentName,
89-
QualifiedSelection.Selection.StartLine);
90-
}
91-
9259
private NavigateCodeEventArgs _navigationArgs;
9360
public NavigateCodeEventArgs GetNavigationArgs()
9461
{
@@ -105,11 +72,5 @@ public int CompareTo(object obj)
10572
{
10673
return CompareTo(obj as IInspectionResult);
10774
}
108-
109-
public object[] ToArray()
110-
{
111-
var module = QualifiedSelection.QualifiedName;
112-
return new object[] { Inspection.Severity.ToString(), module.ProjectName, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
113-
}
11475
}
11576
}

Rubberduck.CodeAnalysis/Inspections/Results/IdentifierReferenceInspectionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public IdentifierReferenceInspectionResult(IInspection inspection, string descri
3434

3535
public override bool ChangesInvalidateResult(ICollection<QualifiedModuleName> modifiedModules)
3636
{
37-
return modifiedModules.Contains(Target.QualifiedModuleName)
38-
|| base.ChangesInvalidateResult(modifiedModules);
37+
return Target != null && modifiedModules.Contains(Target.QualifiedModuleName)
38+
|| base.ChangesInvalidateResult(modifiedModules);
3939
}
4040
}
4141
}

Rubberduck.Core/Common/ClipboardWriter.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.IO;
22
using System.Windows;
33
using System.Windows.Media.Imaging;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System;
47

58
namespace Rubberduck.Common
69
{
@@ -11,6 +14,22 @@ public interface IClipboardWriter
1114
void AppendString(string formatName, string data);
1215
void AppendStream(string formatName, MemoryStream stream);
1316
void Flush();
17+
void AppendInfo(ColumnInfo[] columnInfos,
18+
IEnumerable<IExportable> exportableResults,
19+
string titleFormat,
20+
ClipboardWriterAppendingInformationFormat appendingInformationFormat);
21+
}
22+
23+
[Flags]
24+
public enum ClipboardWriterAppendingInformationFormat
25+
{
26+
None = 0,
27+
XmlSpreadsheetFormat = 1 << 0,
28+
RtfFormat = 1 << 1,
29+
HtmlFormat = 1 << 2,
30+
CsvFormat = 1 << 3,
31+
UnicodeFormat = 1 << 4,
32+
All = XmlSpreadsheetFormat | RtfFormat | HtmlFormat | CsvFormat | UnicodeFormat
1433
}
1534

1635
public class ClipboardWriter : IClipboardWriter
@@ -32,7 +51,6 @@ public void AppendImage(BitmapSource image)
3251
_data.SetImage(image);
3352
}
3453

35-
3654
public void AppendString(string formatName, string data)
3755
{
3856
if (_data == null)
@@ -59,5 +77,43 @@ public void Flush()
5977
_data = null;
6078
}
6179
}
80+
81+
public void AppendInfo(ColumnInfo[] columnInfos,
82+
IEnumerable<IExportable> results,
83+
string title,
84+
ClipboardWriterAppendingInformationFormat appendingInformationFormat)
85+
{
86+
object[][] resultsAsArray = results.Select(result => result.ToArray()).ToArray();
87+
88+
if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.XmlSpreadsheetFormat))
89+
{
90+
const string xmlSpreadsheetDataFormat = "XML Spreadsheet";
91+
using (var stream = ExportFormatter.XmlSpreadsheetNew(resultsAsArray, title, columnInfos))
92+
{
93+
AppendStream(DataFormats.GetDataFormat(xmlSpreadsheetDataFormat).Name, stream);
94+
}
95+
}
96+
97+
if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.RtfFormat))
98+
{
99+
AppendString(DataFormats.Rtf, ExportFormatter.RTF(resultsAsArray, title));
100+
}
101+
102+
if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.HtmlFormat))
103+
{
104+
AppendString(DataFormats.Html, ExportFormatter.HtmlClipboardFragment(resultsAsArray, title, columnInfos));
105+
}
106+
107+
if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.CsvFormat))
108+
{
109+
AppendString(DataFormats.CommaSeparatedValue, ExportFormatter.Csv(resultsAsArray, title, columnInfos));
110+
}
111+
112+
if (appendingInformationFormat.HasFlag(ClipboardWriterAppendingInformationFormat.UnicodeFormat) && results is IEnumerable<IExportable> unicodeResults)
113+
{
114+
var unicodeTextFormat = title + Environment.NewLine + string.Join(string.Empty, unicodeResults.Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
115+
AppendString(DataFormats.UnicodeText, unicodeTextFormat);
116+
}
117+
}
62118
}
63119
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Rubberduck.Common;
2+
using Rubberduck.Parsing.Symbols;
3+
using Rubberduck.Resources;
4+
5+
namespace Rubberduck.Formatters
6+
{
7+
public class DeclarationFormatter : IExportable
8+
{
9+
private readonly Declaration _declaration;
10+
11+
public DeclarationFormatter(Declaration declaration)
12+
{
13+
_declaration = declaration;
14+
}
15+
16+
public object[] ToArray()
17+
{
18+
return _declaration.ToArray();
19+
}
20+
21+
public string ToClipboardString()
22+
{
23+
return string.Format(RubberduckUI.CodeExplorer_IExportable_DeclarationFormat,
24+
_declaration.Project.Name,
25+
_declaration.CustomFolder,
26+
_declaration.ComponentName,
27+
_declaration.DeclarationType,
28+
_declaration.Scope,
29+
_declaration.IdentifierName);
30+
}
31+
}
32+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Rubberduck.Common;
2+
using Rubberduck.Parsing.Inspections.Abstract;
3+
using Rubberduck.Inspections.Abstract;
4+
using System.IO;
5+
using Rubberduck.Resources.Inspections;
6+
7+
namespace Rubberduck.Formatters
8+
{
9+
public class InspectionResultFormatter : IExportable
10+
{
11+
private readonly IInspectionResult _inspectionResult;
12+
13+
public InspectionResultFormatter(IInspectionResult inspectionResult)
14+
{
15+
_inspectionResult = inspectionResult;
16+
}
17+
18+
public object[] ToArray()
19+
{
20+
var module = _inspectionResult.QualifiedSelection.QualifiedName;
21+
return new object[]
22+
{
23+
_inspectionResult.Inspection.Severity.ToString(),
24+
module.ProjectName,
25+
module.ComponentName,
26+
_inspectionResult.Description,
27+
_inspectionResult.QualifiedSelection.Selection.StartLine,
28+
_inspectionResult.QualifiedSelection.Selection.StartColumn
29+
};
30+
}
31+
32+
/// <summary>
33+
/// WARNING: This property can have side effects. It can change the ActiveVBProject if the result has a null Declaration,
34+
/// which causes a flicker in the VBE. This should only be called if it is *absolutely* necessary.
35+
/// </summary>
36+
public string ToClipboardString()
37+
{
38+
var module = _inspectionResult.QualifiedSelection.QualifiedName;
39+
var documentName = _inspectionResult.Target != null
40+
? _inspectionResult.Target.ProjectDisplayName
41+
: string.Empty;
42+
43+
//todo: Find a sane way to reimplement this.
44+
//if (string.IsNullOrEmpty(documentName))
45+
//{
46+
// var component = module.Component;
47+
// documentName = component != null
48+
// ? component.ParentProject.ProjectDisplayName
49+
// : string.Empty;
50+
//}
51+
52+
if (string.IsNullOrEmpty(documentName))
53+
{
54+
documentName = Path.GetFileName(module.ProjectPath);
55+
}
56+
57+
return string.Format(
58+
InspectionsUI.QualifiedSelectionInspection,
59+
_inspectionResult.Inspection.Severity,
60+
_inspectionResult.Description,
61+
$"({documentName})",
62+
module.ProjectName,
63+
module.ComponentName,
64+
_inspectionResult.QualifiedSelection.Selection.StartLine);
65+
}
66+
}
67+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Rubberduck.UI.UnitTesting.ViewModels;
2+
using Rubberduck.Common;
3+
4+
namespace Rubberduck.Formatters
5+
{
6+
public class TestMethodViewModelFormatter : IExportable
7+
{
8+
private readonly TestMethodViewModel _testMethodViewModel;
9+
10+
public TestMethodViewModelFormatter(TestMethodViewModel testMethodViewModel)
11+
{
12+
_testMethodViewModel = testMethodViewModel;
13+
}
14+
15+
public object[] ToArray()
16+
{
17+
return _testMethodViewModel.ToArray();
18+
}
19+
20+
public string ToClipboardString()
21+
{
22+
return _testMethodViewModel.ToString();
23+
}
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Rubberduck.ToDoItems;
2+
using Rubberduck.Common;
3+
using Rubberduck.Resources;
4+
5+
namespace Rubberduck.Formatters
6+
{
7+
public class ToDoItemFormatter : IExportable
8+
{
9+
private readonly ToDoItem _toDoItem;
10+
11+
public ToDoItemFormatter(ToDoItem toDoItem)
12+
{
13+
_toDoItem = toDoItem;
14+
}
15+
16+
public object[] ToArray()
17+
{
18+
var module = _toDoItem.Selection.QualifiedName;
19+
return new object[] { _toDoItem.Type, _toDoItem.Description, module.ProjectName, module.ComponentName, _toDoItem.Selection.Selection.StartLine, _toDoItem.Selection.Selection.StartColumn };
20+
}
21+
22+
public string ToClipboardString()
23+
{
24+
var module = _toDoItem.Selection.QualifiedName;
25+
return string.Format(RubberduckUI.ToDoExplorerToDoItemFormat,
26+
_toDoItem.Type,
27+
_toDoItem.Description,
28+
module.ProjectName,
29+
module.ComponentName,
30+
_toDoItem.Selection.Selection.StartLine);
31+
}
32+
}
33+
}

Rubberduck.Core/ToDoItems/ToDoItem.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using Rubberduck.Common;
2-
using Rubberduck.Interaction.Navigation;
1+
using Rubberduck.Interaction.Navigation;
32
using Rubberduck.Parsing.Symbols;
4-
using Rubberduck.Resources;
53
using Rubberduck.VBEditor;
64

75
namespace Rubberduck.ToDoItems
@@ -10,7 +8,7 @@ namespace Rubberduck.ToDoItems
108
/// Represents a Todo comment and the necessary information to display and navigate to that comment.
119
/// This is a binding item. Changing it's properties changes how it is displayed.
1210
/// </summary>
13-
public class ToDoItem : INavigateSource, IExportable
11+
public class ToDoItem : INavigateSource
1412
{
1513
public string Description { get; }
1614

@@ -29,23 +27,5 @@ public NavigateCodeEventArgs GetNavigationArgs()
2927
{
3028
return new NavigateCodeEventArgs(Selection);
3129
}
32-
33-
public object[] ToArray()
34-
{
35-
var module = Selection.QualifiedName;
36-
return new object[] { Type, Description, module.ProjectName, module.ComponentName, Selection.Selection.StartLine, Selection.Selection.StartColumn };
37-
}
38-
39-
public string ToClipboardString()
40-
{
41-
var module = Selection.QualifiedName;
42-
return string.Format(
43-
RubberduckUI.ToDoExplorerToDoItemFormat,
44-
Type,
45-
Description,
46-
module.ProjectName,
47-
module.ComponentName,
48-
Selection.Selection.StartLine);
49-
}
5030
}
5131
}

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
6565
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
6666

67-
<CompositeCollection x:Key="AddModuleCommands">
67+
<CompositeCollection x:Key="AddModuleCommands" x:Shared="False">
6868
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddExistingFileText}"
6969
Command="{Binding ImportCommand}"
7070
CommandParameter="{Binding SelectedItem, Mode=OneWay}">

0 commit comments

Comments
 (0)