Skip to content

Commit

Permalink
feat: v1.3.12 meesageDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
minkostaev committed Jan 8, 2025
1 parent d751680 commit c081763
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 50 deletions.
1 change: 1 addition & 0 deletions ShortcutsGrid.Tests/Services/TestErrorDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NUnit.Framework;
using ShortcutsGrid.Models;
using ShortcutsGrid.Services;
using ShortcutsGrid.Windows;
using System.Windows;

[TestFixture]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
namespace ShortcutsGrid.Services;
namespace ShortcutsGrid.Extensions;

using System;
using System.Text.RegularExpressions;
using System.Windows.Media;
using System.Windows.Media.Imaging;

internal static class StringExtensions
public static class StringExtensions
{
private static readonly Regex _base64RegexPattern = new(BASE64_REGEX_STRING, RegexOptions.Compiled);

private const string BASE64_REGEX_STRING = @"^[a-zA-Z0-9\+/]*={0,3}$";

public static bool IsBase64(this string base64String)
{
var rs = (!string.IsNullOrEmpty(base64String)
var rs = !string.IsNullOrEmpty(base64String)
&& !string.IsNullOrWhiteSpace(base64String)
&& base64String.Length != 0
&& base64String.Length % 4 == 0
&& !base64String.Contains(' ')
&& !base64String.Contains('\t')
&& !base64String.Contains('\r')
&& !base64String.Contains('\n'))
&& (base64String.Length % 4 == 0
&& _base64RegexPattern.Match(base64String, 0).Success);
&& !base64String.Contains('\n')
&& base64String.Length % 4 == 0
&& _base64RegexPattern.Match(base64String, 0).Success;
return rs;
}

Expand Down
16 changes: 0 additions & 16 deletions ShortcutsGrid/Models/IMessageBoxWrapper.cs

This file was deleted.

1 change: 1 addition & 0 deletions ShortcutsGrid/Services/Image/ImageUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ShortcutsGrid.Services.Image;

using Models;
using ShortcutsGrid.Extensions;
using System;
using System.Drawing;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion ShortcutsGrid/Services/ImageButtonCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class ImageButtonCreator

public static ImageButton GetButton(Shortcut shortcutItem, MainWindow window)
{
MessageDialogs messageDialogs = new MessageDialogs(new MessageBoxWrapper());
var messageDialogs = new MessageDialogs();
bool closeDragButton = shortcutItem.Tag is string && shortcutItem.Tag.ToString() == AppValues.CloseDragId;
var imageButton = new ImageButton(shortcutItem)
{
Expand Down
24 changes: 0 additions & 24 deletions ShortcutsGrid/Services/MessageDialogs.cs

This file was deleted.

6 changes: 3 additions & 3 deletions ShortcutsGrid/ShortcutsGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<ApplicationIcon>Resources\web-browser-128.ico</ApplicationIcon>
<AssemblyVersion>1.3.11.0</AssemblyVersion>
<FileVersion>1.3.11.0</FileVersion>
<VersionPrefix>1.3.11</VersionPrefix>
<AssemblyVersion>1.3.12.0</AssemblyVersion>
<FileVersion>1.3.12.0</FileVersion>
<VersionPrefix>1.3.12</VersionPrefix>
<VersionSuffix>$([System.DateTime]::UtcNow.ToString(yyyy-MM-dd))</VersionSuffix>
</PropertyGroup>

Expand Down
28 changes: 28 additions & 0 deletions ShortcutsGrid/Windows/MessageDialogs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ShortcutsGrid.Windows;

using System.Windows;

public interface IMessageBoxWrapper
{
MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon);
}
public class MessageBoxWrapper : IMessageBoxWrapper
{
public MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon)
{
return MessageBox.Show(messageBoxText, caption, button, icon);
}
}
public class MessageDialogs(IMessageBoxWrapper? messageBox = null)
{
private readonly IMessageBoxWrapper _messageBox = messageBox ?? new MessageBoxWrapper();
public bool IsErrorDisplayed(string error)
{
if (!string.IsNullOrWhiteSpace(error))
{
_messageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return true;
}
return false;
}
}

0 comments on commit c081763

Please sign in to comment.