Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Temporary commit to continue working
  • Loading branch information
IvenBach committed Aug 25, 2019
1 parent c0d04c9 commit 0a8bb63
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 37 deletions.
55 changes: 32 additions & 23 deletions Rubberduck.Core/Common/ClipboardWriter.cs
Expand Up @@ -5,6 +5,11 @@
using System.Linq;
using System;
using System.Globalization;
using System.Windows.Data;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Symbols;
using Rubberduck.UI.UnitTesting.ViewModels;
using Rubberduck.Resources;

namespace Rubberduck.Common
{
Expand All @@ -15,29 +20,16 @@ public interface IClipboardWriter
void AppendString(string formatName, string data);
void AppendStream(string formatName, MemoryStream stream);
void Flush();
//void AppendInfo(ClipboardFormat xmlSpreadsheetFormat, ClipboardFormat rtfFormat, ClipboardFormat htmlFormat, ClipboardFormat csvFormat, ClipboardFormat unicodeTextFormat);
void AppendInfo(ColumnInfo[] columnInfos,
IEnumerable<object> results,
object results,
string titleFormat,
bool includeXmlSpreadsheetformat = false,
bool includeXmlSpreadsheetFormat = false,
bool includeRtfFormat = false,
bool includeHtmlFormat = false,
bool includeCsvFormat = false,
bool includeUnicodeFormat = false);
}

public struct ClipboardFormat
{
public string FormatName;
public object Data;

public ClipboardFormat(string formatName, object data)
{
FormatName = formatName;
Data = data;
}
}

public class ClipboardWriter : IClipboardWriter
{
private DataObject _data;
Expand Down Expand Up @@ -88,18 +80,35 @@ public void Flush()
//public void AppendInfo(ClipboardFormat xmlSpreadsheetFormat, ClipboardFormat rtfFormat, ClipboardFormat htmlFormat, ClipboardFormat csvFormat, ClipboardFormat unicodeTextFormat)
//TODO: bitFlag
public void AppendInfo(ColumnInfo[] columnInfos,
IEnumerable<object> results,
object results,
string titleFormat,
bool includeXmlSpreadsheetformat = false,
bool includeXmlSpreadsheetFormat = false,
bool includeRtfFormat = false,
bool includeHtmlFormat = false,
bool includeCsvFormat = false,
bool includeUnicodeFormat = false)
{
var resultsAsArray = results.Select(result => result.ToArray()).ToArray();
var title = string.Format(titleFormat, DateTime.Now.ToString(CultureInfo.InvariantCulture));
//var resultsAsArray = results.Select(result => result.ToArray()).ToArray();
object[][] resultsAsArray;
switch (results)
{
case IEnumerable<Declaration> declarations:
resultsAsArray = declarations.Select(declaration => declaration.ToArray()).ToArray();
break;
case System.Collections.ObjectModel.ObservableCollection<IInspectionResult> inspectionResults:
resultsAsArray = inspectionResults.OfType<IExportable>().Select(result => result.ToArray()).ToArray();
break;
case System.Collections.ObjectModel.ObservableCollection<TestMethodViewModel> testMethodViewModels:
resultsAsArray = testMethodViewModels.Select(test => test.ToArray()).ToArray();
break;
default:
resultsAsArray = null;
break;
}

var title = string.Format(RubberduckUI.TestExplorer_AppendHeader, DateTime.Now.ToString(CultureInfo.InvariantCulture));

if (includeXmlSpreadsheetformat)
if (includeXmlSpreadsheetFormat)
{
const string xmlSpreadsheetDataFormat = "XML Spreadsheet";
using (var stream = ExportFormatter.XmlSpreadsheetNew(resultsAsArray, title, columnInfos))
Expand All @@ -123,10 +132,10 @@ public void Flush()
AppendString(DataFormats.CommaSeparatedValue, ExportFormatter.Csv(resultsAsArray, title, columnInfos));
}

if (includeUnicodeFormat)
if (includeUnicodeFormat && results is ListCollectionView unicodeResults)
{
var unicodeResults = title + Environment.NewLine + string.Join(string.Empty, results.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
var unicodeTextFormat = new ClipboardFormat(DataFormats.UnicodeText, unicodeResults);
var unicodeTextFormat = title + Environment.NewLine + string.Join(string.Empty, unicodeResults.OfType<IExportable>().Select(result => result.ToClipboardString() + Environment.NewLine).ToArray());
AppendString(DataFormats.UnicodeText, unicodeTextFormat);
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions Rubberduck.Core/UI/CodeExplorer/Commands/CopyResultsCommand.cs
Expand Up @@ -5,6 +5,7 @@
using Rubberduck.Common;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI.Command;
using Rubberduck.Resources.CodeExplorer;

namespace Rubberduck.UI.CodeExplorer.Commands
{
Expand All @@ -30,13 +31,14 @@ protected override void OnExecute(object parameter)
{
ColumnInfo[] ColumnInfos = { new ColumnInfo("Project"), new ColumnInfo("Folder"), new ColumnInfo("Component"), new ColumnInfo("Declaration Type"), new ColumnInfo("Scope"),
new ColumnInfo("Name"), new ColumnInfo("Return Type") };

//TODO: _state.AllUserDeclarations --> Results
// this.ProjectName, this.CustomFolder, this.ComponentName, this.DeclarationType.ToString(), this.Scope
var aDeclarations = _state.AllUserDeclarations.Select(declaration => declaration.ToArray()).ToArray();

const string resource = "Rubberduck User Declarations - {0}";
_clipboard.AppendInfo(ColumnInfos, _state.AllUserDeclarations, resource, true, true, true, true);

_clipboard.AppendInfo(ColumnInfos,
_state.AllUserDeclarations,
CodeExplorerUI.CodeExplorer_AppendHeader,
true,
true,
true,
true);

_clipboard.Flush();
}
Expand Down
11 changes: 7 additions & 4 deletions Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs
Expand Up @@ -653,13 +653,16 @@ private void ExecuteCopyResultsCommand(object parameter)
return;
}

var resultArray = Results.OfType<IExportable>().Select(result => result.ToArray()).ToArray();

var resource = resultArray.Count() == 1
var resource = _results.Count == 1
? Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Singular
: Resources.RubberduckUI.CodeInspections_NumberOfIssuesFound_Plural;

_clipboard.AppendInfo(ColumnInformation, Results as IEnumerable<object>, resource, true, true, true, true, true);
_clipboard.AppendInfo(ColumnInformation,
Results, resource, true,
true,
true,
true,
true);

_clipboard.Flush();
}
Expand Down
11 changes: 8 additions & 3 deletions Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs
Expand Up @@ -398,9 +398,14 @@ private void ExecuteCopyResultsCommand(object parameter)
ColumnInfo[] columnInfos = { new ColumnInfo("Project"), new ColumnInfo("Component"), new ColumnInfo("Method"), new ColumnInfo("Outcome"), new ColumnInfo("Output"),
new ColumnInfo("Start Time"), new ColumnInfo("End Time"), new ColumnInfo("Duration (ms)", hAlignment.Right) };

//TODO: Convert to resource string
const string resource = "Rubberduck Test Results - {0}";
_clipboard.AppendInfo(columnInfos, Model.Tests, resource, true, true, true, true, true);
_clipboard.AppendInfo(columnInfos,
Model.Tests,
RubberduckUI.TestExplorer_AppendHeader,
true,
true,
true,
true,
true);

_clipboard.Flush();
}
Expand Down
9 changes: 9 additions & 0 deletions Rubberduck.Resources/CodeExplorer/CodeExplorerUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.Resources/CodeExplorer/CodeExplorerUI.resx
Expand Up @@ -440,4 +440,7 @@ Continue?</value>

{0}</value>
</data>
<data name="CodeExplorer_AppendHeader" xml:space="preserve">
<value>Rubberduck User Declarations - {0}</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Rubberduck.Resources/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.Resources/RubberduckUI.resx
Expand Up @@ -1629,4 +1629,7 @@ NOTE: Restart is required for the setting to take effect.</value>
<data name="TestOutcome_Unknown" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="TestExplorer_AppendHeader" xml:space="preserve">
<value>Rubberduck Test Results - {0}</value>
</data>
</root>

0 comments on commit 0a8bb63

Please sign in to comment.