Skip to content

Commit

Permalink
Merge pull request #54 from deadlydog/CopyPathsInSameOrderAsGrid
Browse files Browse the repository at this point in the history
feat: Copy Paths to the clipboard in the same order they appear in th…
  • Loading branch information
deadlydog authored Dec 26, 2020
2 parents 029ec03 + f8a902a commit 96b5945
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.9.0 - December 26, 2020

Features:

- Copy to clipboard functions copy paths in the same order they appear in the UI grid.

## v1.8.9 - December 16, 2020

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variables:
buildConfiguration: 'Release'
appBinariesDirectory: 'src\PathLengthCheckerGUI\bin\$(buildConfiguration)'

version.MajorMinor: '1.8' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.MajorMinor: '1.9' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.Revision: $[counter(variables['version.MajorMinor'], 0)]
versionNumber: '$(version.MajorMinor).$(version.Revision)'

Expand Down
22 changes: 14 additions & 8 deletions src/PathLengthCheckerGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PathLengthChecker;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -66,6 +67,11 @@ public ObservableCollection<PathInfo> Paths
}
private ObservableCollection<PathInfo> _paths = new ObservableCollection<PathInfo>();

/// <summary>
/// This returns the same items as the Paths property, but sorted however the UI happens to be sorted.
/// </summary>
private IEnumerable<PathInfo> PathsFromUiDataGrid => dgPaths.Items.Cast<PathInfo>();

public PathInfo SelectedPath
{
get { return (PathInfo)GetValue(SelectedPathProperty); }
Expand Down Expand Up @@ -228,27 +234,27 @@ private void DisplayResultsMetadata()

private void splitbtnCopyToClipboard_Click(object sender, RoutedEventArgs e)
{
var text = GetPathsAsString(includeLength: true);
var text = GetPathsFromUiDataGridAsString(includeLength: true);
SetClipboardText(text);
}

private void btnCopyToClipboardWithoutLengths_Click(object sender, RoutedEventArgs e)
{
var text = GetPathsAsString(includeLength: false);
var text = GetPathsFromUiDataGridAsString(includeLength: false);
SetClipboardText(text);
CloseCopyToClipboardSplitButtonDropDown();
}

private void btnCopyToClipboardAsCsv_Click(object sender, RoutedEventArgs e)
{
var text = GetPathsAsCsvString(includeLength: true);
var text = GetPathsFromUiDataGridAsCsvString(includeLength: true);
SetClipboardText(text);
CloseCopyToClipboardSplitButtonDropDown();
}

private void btnCopyToClipboardWithoutLengthsAsCsv_Click(object sender, RoutedEventArgs e)
{
var text = GetPathsAsCsvString(includeLength: false);
var text = GetPathsFromUiDataGridAsCsvString(includeLength: false);
SetClipboardText(text);
CloseCopyToClipboardSplitButtonDropDown();
}
Expand All @@ -258,18 +264,18 @@ private void CloseCopyToClipboardSplitButtonDropDown()
splitbtnCopyToClipboard.IsOpen = false;
}

private string GetPathsAsString(bool includeLength)
private string GetPathsFromUiDataGridAsString(bool includeLength)
{
var text = new StringBuilder();
foreach (var path in Paths)
foreach (var path in PathsFromUiDataGrid)
{
var item = includeLength ? $"{path.Length}: {path.Path}" : path.Path;
text.AppendLine(item);
}
return text.ToString().Trim();
}

private string GetPathsAsCsvString(bool includeLength)
private string GetPathsFromUiDataGridAsCsvString(bool includeLength)
{
var text = new StringBuilder();

Expand All @@ -278,7 +284,7 @@ private string GetPathsAsCsvString(bool includeLength)
"\"Path\"";
text.AppendLine(header);

foreach (var path in Paths)
foreach (var path in PathsFromUiDataGrid)
{
var item = includeLength ?
$"{path.Length},\"{path.Path}\"" :
Expand Down

0 comments on commit 96b5945

Please sign in to comment.