mirror of
https://github.com/Stone-Red-Code/ClipCMD.git
synced 2026-09-04 08:56:11 +02:00
Add logo and improve error handling
This commit is contained in:
+28
-15
@@ -1,20 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<AssemblyVersion>0.0.0.2</AssemblyVersion>
|
||||
<FileVersion>0.0.0.2</FileVersion>
|
||||
<Version>0.0.0.2</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<AssemblyVersion>0.0.0.2</AssemblyVersion>
|
||||
<FileVersion>0.0.0.2</FileVersion>
|
||||
<Version>0.0.0.2</Version>
|
||||
<ApplicationIcon>logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="InputSimulator" Version="1.0.4" />
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
|
||||
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="logo.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="InputSimulator" Version="1.0.4" />
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
|
||||
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="logo.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+12
-6
@@ -5,15 +5,16 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ClipCMD"
|
||||
mc:Ignorable="d"
|
||||
Title="ClipCMD" Height="450" Width="800">
|
||||
Title="ClipCMD" Height="450" Width="800"
|
||||
Closing="OnClose" StateChanged="OnStateChanged" Icon="logo.ico">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
|
||||
<Label Content="Prefix:" Width="45" />
|
||||
<TextBox x:Name="prefixTextBox" KeyUp="FixTextBox_TextChanged" Text="01" />
|
||||
<TextBox x:Name="prefixTextBox" KeyUp="FixTextBox_TextChanged" Text="_" />
|
||||
</StackPanel>
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
|
||||
<Label Content="Suffix:" Width="45" />
|
||||
<TextBox x:Name="suffixTextBox" KeyUp="FixTextBox_TextChanged" Text="01" />
|
||||
<TextBox x:Name="suffixTextBox" KeyUp="FixTextBox_TextChanged" Text="_" />
|
||||
</StackPanel>
|
||||
|
||||
<Grid DockPanel.Dock="Top" VerticalAlignment="Stretch">
|
||||
@@ -23,14 +24,19 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<DockPanel Grid.Column="0">
|
||||
<Label DockPanel.Dock="Top" Content="Static Commands:" />
|
||||
<TextBox DockPanel.Dock="Top" x:Name="commandsTextBox" TextChanged="StaticCommandsTextBox_TextChanged" TextWrapping="Wrap" AcceptsReturn="True" VerticalAlignment="Stretch" />
|
||||
<Label DockPanel.Dock="Top" Content="Commands:" />
|
||||
<TextBox DockPanel.Dock="Top" x:Name="commandsTextBox" HorizontalScrollBarVisibility="Visible" TextChanged="StaticCommandsTextBox_TextChanged" AcceptsReturn="True" VerticalAlignment="Stretch" />
|
||||
</DockPanel>
|
||||
|
||||
<DockPanel Grid.Column="1">
|
||||
<DockPanel x:Name="logPanel" Grid.Column="1">
|
||||
<Label DockPanel.Dock="Top" Content="History:" />
|
||||
<ListBox DockPanel.Dock="Top" x:Name="logListBox" VerticalAlignment="Stretch" />
|
||||
</DockPanel>
|
||||
|
||||
<DockPanel Visibility="Collapsed" x:Name="errorPanel" Grid.Column="1">
|
||||
<Label DockPanel.Dock="Top" Content="Errors:" />
|
||||
<ListBox DockPanel.Dock="Top" x:Name="errorListBox" Foreground="Red" VerticalAlignment="Stretch" />
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Window>
|
||||
+69
-10
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Language;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
@@ -20,11 +21,25 @@ public partial class MainWindow : Window
|
||||
{
|
||||
private readonly Dictionary<string, string> commands = new Dictionary<string, string>();
|
||||
|
||||
private readonly System.Windows.Forms.NotifyIcon notifyIcon;
|
||||
private WindowState storedWindowState = WindowState.Normal;
|
||||
|
||||
private readonly string cmdPath;
|
||||
private readonly string fixPath;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
notifyIcon = new System.Windows.Forms.NotifyIcon
|
||||
{
|
||||
BalloonTipText = "ClipCMD has been minimized. Click the tray icon to show.",
|
||||
BalloonTipTitle = "ClipCMD",
|
||||
Text = "ClipCMD",
|
||||
Icon = new System.Drawing.Icon("logo.ico"),
|
||||
Visible = true
|
||||
};
|
||||
|
||||
notifyIcon.Click += NotifyIcon_Click;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
@@ -62,6 +77,30 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClose(object? sender, CancelEventArgs args)
|
||||
{
|
||||
notifyIcon.Dispose();
|
||||
}
|
||||
|
||||
private void OnStateChanged(object? sender, EventArgs args)
|
||||
{
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
Hide();
|
||||
notifyIcon?.ShowBalloonTip(2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
storedWindowState = WindowState;
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyIcon_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Show();
|
||||
WindowState = storedWindowState;
|
||||
}
|
||||
|
||||
private IDataObject? oldData;
|
||||
|
||||
private void ClipboardManager_ClipboardChanged(object? sender, EventArgs e)
|
||||
@@ -120,13 +159,14 @@ public partial class MainWindow : Window
|
||||
|
||||
private void StaticCommandsTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
//TODO parse commands
|
||||
|
||||
string[] lines = commandsTextBox.Text.Split('\n').Append("[#END#]").ToArray();
|
||||
string commandNames = string.Empty;
|
||||
StringBuilder script = new StringBuilder();
|
||||
|
||||
commandsTextBox.Foreground = Brushes.Black;
|
||||
commandsTextBox.Foreground = System.Windows.Media.Brushes.Black;
|
||||
errorPanel.Visibility = Visibility.Collapsed;
|
||||
logPanel.Visibility = Visibility.Visible;
|
||||
errorListBox.Items.Clear();
|
||||
commands.Clear();
|
||||
|
||||
foreach (string l in lines)
|
||||
@@ -137,16 +177,25 @@ public partial class MainWindow : Window
|
||||
{
|
||||
if (!string.IsNullOrEmpty(commandNames))
|
||||
{
|
||||
_ = Parser.ParseInput(script.ToString(), out _, out ParseError[] errors);
|
||||
|
||||
if (errors.Length > 0)
|
||||
{
|
||||
foreach (ParseError error in errors)
|
||||
{
|
||||
AddError($"[{commandNames}]\n{error}");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string commandName in commandNames.Split(','))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(commandName) && commands.TryAdd(commandName.Trim(), script.ToString()))
|
||||
if (string.IsNullOrWhiteSpace(commandName))
|
||||
{
|
||||
commandsTextBox.Foreground = Brushes.Black;
|
||||
AddError($"[{commandNames}]\nCommand \"{commandName}\" is empty!");
|
||||
}
|
||||
else
|
||||
else if (!commands.TryAdd(commandName.Trim(), script.ToString()))
|
||||
{
|
||||
commandsTextBox.Foreground = Brushes.Red;
|
||||
return;
|
||||
AddError($"[{commandNames}]\nCommand \"{commandName}\" already exists!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,14 +212,24 @@ public partial class MainWindow : Window
|
||||
}
|
||||
else
|
||||
{
|
||||
commandsTextBox.Foreground = Brushes.Red;
|
||||
AddError($"[{commandNames}]\nInput has to start with [<Command Name>]!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_ = commands.TryAdd("list", $"\"{string.Join(", ", commands.Keys)}\"");
|
||||
|
||||
File.WriteAllText(cmdPath, commandsTextBox.Text);
|
||||
}
|
||||
|
||||
private void AddError(string error)
|
||||
{
|
||||
errorPanel.Visibility = Visibility.Visible;
|
||||
logPanel.Visibility = Visibility.Collapsed;
|
||||
commandsTextBox.Foreground = System.Windows.Media.Brushes.Red;
|
||||
_ = errorListBox.Items.Add(error);
|
||||
}
|
||||
|
||||
private void FixTextBox_TextChanged(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
if (prefixTextBox is null || suffixTextBox is null)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
Reference in New Issue
Block a user