Skip to content

Commit

Permalink
Unicode is now supported.
Browse files Browse the repository at this point in the history
In the previous code, the '?' There was a problem with texting. (e.g. '—' character)

In addition, even if HexDecimalCharacter exists, it has been changed so that Windows Notifier no longer outputs a 'SUCCESS... BUT' message.

After some testing, we plan to release this improved version as version 1.3.3.
  • Loading branch information
Cyp9715 committed Jul 10, 2023
1 parent 8a6cc43 commit c186c5e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
30 changes: 14 additions & 16 deletions DeleteNewline/ClipboardManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Navigation;

namespace DeleteNewline
{
Expand All @@ -7,35 +8,32 @@ static class ClipboardManager
static RegexManager regexManager = new RegexManager();
static private object lockClipboard = new object();

public static (bool, string) ReplaceText(ref IDataObject idata, string regex, string replace)
public static (bool, string) ReplaceText(string regex, string replace)
{
lock(lockClipboard)
{
string clipboardText = (string)idata.GetData(DataFormats.Text);
string clipboardText = Clipboard.GetText(TextDataFormat.UnicodeText);
(bool success, clipboardText) = regexManager.Replace(clipboardText, regex, replace);
Clipboard.SetDataObject(clipboardText);

return (success, clipboardText);
}
}

public static bool GetText(ref IDataObject idata)
public static string GetText()
{
IDataObject temp_idata;
return Clipboard.GetText(TextDataFormat.UnicodeText);
}

lock (lockClipboard)
public static bool ContainText()
{
if(Clipboard.ContainsText() == true)
{
temp_idata = Clipboard.GetDataObject();

if (temp_idata.GetDataPresent(DataFormats.Text) == false)
{
return false;
}
else
{
idata = temp_idata;
return true;
}
return true;
}
else
{
return false;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DeleteNewline/DeleteNewline.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<Platforms>AnyCPU;x86</Platforms>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>1.3.2</AssemblyVersion>
<AssemblyVersion>1.3.3</AssemblyVersion>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<AssemblyName>Delete Newline</AssemblyName>
</PropertyGroup>
Expand Down
10 changes: 4 additions & 6 deletions DeleteNewline/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace DeleteNewline
{
static class Execute
{
static IDataObject? idataObj;

public static void DeleteNewline_WithNotifier(string regex, string replace)
{
string notifyHeader = String.Empty;
Expand All @@ -19,11 +17,11 @@ public static void DeleteNewline_WithNotifier(string regex, string replace)

VirtualInput.InputImplement.TypeKeyboard_Copy();

if (ClipboardManager.GetText(ref idataObj) == true)
if (ClipboardManager.ContainText() == true)
{
isTextForm = true;

(success, replacedText) = ClipboardManager.ReplaceText(ref idataObj, regex, replace);
(success, replacedText) = ClipboardManager.ReplaceText(regex, replace);

int limitLen = 100;

Expand Down Expand Up @@ -59,9 +57,9 @@ public static void DeleteNewline_WithoutNotifier(string regex, string replace)
{
VirtualInput.InputImplement.TypeKeyboard_Copy();

if (ClipboardManager.GetText(ref idataObj) == true)
if (ClipboardManager.ContainText() == true)
{
ClipboardManager.ReplaceText(ref idataObj, regex, replace);
ClipboardManager.ReplaceText(regex, replace);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DeleteNewline/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace DeleteNewline
static class Global
{
public const string programName = "Delete Newline";
public const string version = "1.3.2";
public const string version = "1.3.3";
}
}
2 changes: 1 addition & 1 deletion DeleteNewline/View/Mutable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
<bcl:String x:Key="waterMark_ouputRegex">The Regex applied string is output.</bcl:String>

<!-- version infomation -->
<bcl:String x:Key="text_versionInfomation">Delete Newline 1.3.2</bcl:String>
<bcl:String x:Key="text_versionInfomation">Delete Newline 1.3.3</bcl:String>
</ResourceDictionary>
12 changes: 5 additions & 7 deletions DeleteNewline/View/Page_InputText.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ public Page_InputText()
DataContext = vm_Input;
}

IDataObject? idataObj;

private void MenuItem_Paste_Click(object sender, RoutedEventArgs e)
{
string originalText = String.Empty;

if (ClipboardManager.GetText(ref idataObj) == true)
if (ClipboardManager.ContainText() == true)
{
originalText = (string)idataObj.GetData(DataFormats.Text);
originalText = ClipboardManager.GetText();
TextBox_Main.AppendText(originalText);

string regexExpression = ViewModel_Page_Setting.vm_settings.text_textBox_regexExpression;
string regexReplace = ViewModel_Page_Setting.vm_settings.text_textBox_regexReplace;

ClipboardManager.ReplaceText(ref idataObj, regexExpression, regexReplace);
ClipboardManager.ReplaceText(regexExpression, regexReplace);
}
else
{
Expand All @@ -45,12 +43,12 @@ private void TextBox_Main_KeyUp(object sender, KeyEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) && e.Key == Key.V || Keyboard.IsKeyDown(Key.V) && e.Key == Key.LeftCtrl)
{
if (ClipboardManager.GetText(ref idataObj) == true)
if (ClipboardManager.ContainText() == true)
{
string regexExpression = ViewModel_Page_Setting.vm_settings.text_textBox_regexExpression;
string regexReplace = ViewModel_Page_Setting.vm_settings.text_textBox_regexReplace;

ClipboardManager.ReplaceText(ref idataObj, regexExpression, regexReplace);
ClipboardManager.ReplaceText(regexExpression, regexReplace);
}
else
{
Expand Down
15 changes: 12 additions & 3 deletions DeleteNewline/Windows/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Notifications;
Expand All @@ -8,16 +10,24 @@ namespace Windows
{
static class Notification
{
private static string ReplaceHexadecimalSymbols(string txt)
{
string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";
return Regex.Replace(txt, r, "", RegexOptions.Compiled);
}

public static void Send(string title, string content, int expirationTime = 5)
{
string removeHexDecimalText = ReplaceHexadecimalSymbols(content);

Task task_notify = new Task(() =>
{
try
{
// Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater
new ToastContentBuilder()
.AddText(title)
.AddText(content)
.AddText(removeHexDecimalText)
.SetBackgroundActivation()
.Show(toast =>
{
Expand All @@ -39,8 +49,7 @@ public static void Send(string title, string content, int expirationTime = 5)
}
});



// 동시 task 방지.
task_notify.Start();
task_notify.Wait();
}
Expand Down

0 comments on commit c186c5e

Please sign in to comment.