Skip to content

Commit

Permalink
nuget package
Browse files Browse the repository at this point in the history
  • Loading branch information
FolkerKinzel committed Nov 5, 2023
1 parent 7df0091 commit d3b4611
Show file tree
Hide file tree
Showing 10 changed files with 3,605 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Synchronizes access between multiple threads and multiple instances of the same program.
* Implements an interface to support Dependency Inversion and unit tests (mockable).

[Project Reference and Release Notes](https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.0)
[Project Reference and Release Notes](https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.1)

[See code examples on GitHub](https://github.com/FolkerKinzel/RecentFiles.WPF)

Expand Down
Binary file not shown.
3,572 changes: 3,572 additions & 0 deletions src/FolkerKinzel.RecentFiles.WPF.Reference.en/Help/Working/System.Net.Http.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace FolkerKinzel.RecentFiles.WPF.Intls.Tests;

[TestClass]
public class FileNameFormatterTest
public class FileNameFormatterTests
{
[TestMethod]
public void GetMenuItemHeaderFromFilenameTest1()
Expand All @@ -14,5 +14,13 @@ public void GetMenuItemHeaderFromFilenameTest1()

Assert.IsTrue(output.StartsWith("_1: C:\\one"));
Assert.IsTrue(output.EndsWith("fifteen\\sixteen"));
StringAssert.Contains(output, FileNameFormatter.GetReplacement());
}

[TestMethod]
public void GetMenuItemHeaderFromFilenameTest2()
{
string output = FileNameFormatter.GetMenuItemHeaderFromFilename("C:\\test.txt", 9);
Assert.AreEqual(output, "1_0: C:\\test.txt", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public void MenuLoadedTest1()
[WpfTestMethod()]
public void MenuLoadedTest2()
{
File.WriteAllText(_fileName, "C:\\test.txt");
File.WriteAllText(_fileName,
"""
C:\\test1.txt

C:\\test2.txt
""");
using var menu = new RecentFilesMenu(Environment.CurrentDirectory);

var menuItem = new System.Windows.Controls.MenuItem();
Expand Down Expand Up @@ -142,6 +147,7 @@ public void MenuLoadedTest4()
C:\\test6.txt
C:\\test7.txt
C:\\test8.txt
C:\\test9.txt
""");
using var menu = new RecentFilesMenu(Environment.CurrentDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<!-- nuget-Package: -->
<PackageId>FolkerKinzel.RecentFiles.WPF</PackageId>
<Product>FolkerKinzel.RecentFiles.WPF</Product>
<Version>1.5.0</Version>
<FileVersion>1.5.0.11</FileVersion>
<Version>1.5.1</Version>
<FileVersion>1.5.1.4</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<PackageReleaseNotes>https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.1</PackageReleaseNotes>
<PackageTags>recent menu WPF</PackageTags>
<Description>Recent files menu for WPF applications.</Description>
<Authors>Folker Kinzel</Authors>
Expand Down
12 changes: 10 additions & 2 deletions src/FolkerKinzel.RecentFiles.WPF/Intls/FileNameFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace FolkerKinzel.RecentFiles.WPF.Intls;
internal static class FileNameFormatter
{
private const int MAX_DISPLAYED_FILE_PATH_LENGTH = 88;
private const string REPLACEMENT = " \u2026 ";

internal static string GetMenuItemHeaderFromFilename(string fileName, int i)
{
Expand All @@ -16,11 +17,11 @@ internal static string GetMenuItemHeaderFromFilename(string fileName, int i)
fileName =
#if NET462
fileName.Substring(0, QUARTER_DISPLAYED_FILE_PATH_LENGTH - 3) +
"..." +
REPLACEMENT +
fileName.Substring(fileName.Length - THREE_QUARTER_DISPLAYED_FILE_PATH_LENGTH);
#else
string.Concat(fileName.AsSpan(0, QUARTER_DISPLAYED_FILE_PATH_LENGTH - 3),
" \u2026 ",
REPLACEMENT,
fileName.AsSpan(fileName.Length - THREE_QUARTER_DISPLAYED_FILE_PATH_LENGTH));
#endif
}
Expand All @@ -36,4 +37,11 @@ internal static string GetMenuItemHeaderFromFilename(string fileName, int i)

return fileName;
}


/// <summary>
/// Helper method to support unit tests.
/// </summary>
/// <returns>The value of <see cref="REPLACEMENT"/>.</returns>
internal static string GetReplacement() => REPLACEMENT;
}
2 changes: 2 additions & 0 deletions src/FolkerKinzel.RecentFiles.WPF/RecentFilesMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private void HandleLoaded()

if (string.IsNullOrWhiteSpace(currentFile))
{
recentFiles.RemoveAt(i);
--i;
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FolkerKinzel.RecentFiles.WPF/md/NugetReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* Synchronizes access between multiple threads and multiple instances of the same program.
* Implements an interface to support Dependency Inversion and unit tests (mockable).

[Project Reference and Release Notes](https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.0)
[Project Reference and Release Notes](https://github.com/FolkerKinzel/RecentFiles.WPF/releases/tag/v1.5.1)

[See code examples on GitHub](https://github.com/FolkerKinzel/RecentFiles.WPF)
9 changes: 0 additions & 9 deletions src/WpfExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ public sealed partial class MainWindow : Window, INotifyPropertyChanged
private readonly IRecentFilesMenu _recentFilesMenu;
private string? _currentFile;


public MainWindow(IRecentFilesMenu recentFilesMenu)
{
this._recentFilesMenu = recentFilesMenu;
InitializeComponent();
}


public string? CurrentFile
{
get => _currentFile;
Expand All @@ -42,7 +40,6 @@ private set
}
}


private void Window_Loaded(object? sender, RoutedEventArgs e)
{
// Assign the RecentFilesMenu the MenuItem next to which the
Expand All @@ -54,7 +51,6 @@ private void Window_Loaded(object? sender, RoutedEventArgs e)
_recentFilesMenu.RecentFileSelected += RecentFilesMenu_RecentFileSelected;
}


private async void Window_Closed(object? sender, EventArgs e)
{
// Wait all tasks to be finished before disposing the
Expand All @@ -63,15 +59,12 @@ private async void Window_Closed(object? sender, EventArgs e)
_recentFilesMenu.Dispose();
}


private void Quit_Click(object? sender, RoutedEventArgs e) => Close();


private void RecentFilesMenu_RecentFileSelected(
object? sender,
RecentFileSelectedEventArgs e) => OpenFile(e.FileName);


private void OpenDirectory_Executed(object? sender, ExecutedRoutedEventArgs e)
{
using var dialog = new System.Windows.Forms.FolderBrowserDialog();
Expand All @@ -91,7 +84,6 @@ private void OpenFile_Executed(object? sender, ExecutedRoutedEventArgs e)
}
}


private void OpenFile(string fileName)
{
try
Expand All @@ -108,7 +100,6 @@ private void OpenFile(string fileName)
CurrentFile = fileName;
}


private void OnPropertyChanged([CallerMemberName] string propName = "")
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}

0 comments on commit d3b4611

Please sign in to comment.