diff --git a/EasySnippets/App.xaml b/EasySnippets/App.xaml
index 42c55b7..4d059e3 100644
--- a/EasySnippets/App.xaml
+++ b/EasySnippets/App.xaml
@@ -5,6 +5,17 @@
StartupUri="Views/MainWindow.xaml"
DispatcherUnhandledException="App_DispatcherUnhandledException">
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/EasySnippets/EasySnippets.csproj b/EasySnippets/EasySnippets.csproj
index 89071ed..e48a23d 100644
--- a/EasySnippets/EasySnippets.csproj
+++ b/EasySnippets/EasySnippets.csproj
@@ -38,13 +38,31 @@
es.ico
+
+ ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll
+
+
+ ..\packages\MahApps.Metro.SimpleChildWindow.1.4.0\lib\net45\MahApps.Metro.SimpleChildWindow.dll
+
..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll
+
+ ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll
+
+
+ ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll
+
+
+ ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll
+
+
+ ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll
+
@@ -65,12 +83,19 @@
+
+ ClosingDialog.xaml
+
EditorWindow.xaml
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/EasySnippets/ViewModels/Settings.cs b/EasySnippets/ViewModels/Settings.cs
index 2a80619..5ad01bd 100644
--- a/EasySnippets/ViewModels/Settings.cs
+++ b/EasySnippets/ViewModels/Settings.cs
@@ -33,6 +33,22 @@ public string CurrentFilePath
set => SetProperty(ref _currentFilePath, value);
}
+ private int _height;
+
+ public int Height
+ {
+ get => _height;
+ set => SetProperty(ref _height, value);
+ }
+
+ private int _width;
+
+ public int Width
+ {
+ get => _width;
+ set => SetProperty(ref _width, value);
+ }
+
protected new virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer.Default.Equals(storage, value))
diff --git a/EasySnippets/Views/ClosingDialog.xaml b/EasySnippets/Views/ClosingDialog.xaml
new file mode 100644
index 0000000..ccadca3
--- /dev/null
+++ b/EasySnippets/Views/ClosingDialog.xaml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+ Are you sure
+ you want to exit?
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/EasySnippets/Views/ClosingDialog.xaml.cs b/EasySnippets/Views/ClosingDialog.xaml.cs
new file mode 100644
index 0000000..a50e595
--- /dev/null
+++ b/EasySnippets/Views/ClosingDialog.xaml.cs
@@ -0,0 +1,26 @@
+using System.Windows;
+using MahApps.Metro.SimpleChildWindow;
+
+namespace EasySnippets.Views
+{
+ ///
+ /// Interaction logic for ClosingDialog.xaml
+ ///
+ public partial class ClosingDialog : ChildWindow
+ {
+ public ClosingDialog()
+ {
+ InitializeComponent();
+ }
+
+ private void ApplicationShutdown(object sender, RoutedEventArgs e)
+ {
+ Application.Current.Shutdown();
+ }
+
+ private void DialogDismiss(object sender, RoutedEventArgs e)
+ {
+ Close();
+ }
+ }
+}
diff --git a/EasySnippets/Views/EditorWindow.xaml b/EasySnippets/Views/EditorWindow.xaml
index b59d10d..7bb51fe 100644
--- a/EasySnippets/Views/EditorWindow.xaml
+++ b/EasySnippets/Views/EditorWindow.xaml
@@ -1,8 +1,9 @@
-
-
+
diff --git a/EasySnippets/Views/EditorWindow.xaml.cs b/EasySnippets/Views/EditorWindow.xaml.cs
index 99be21e..045a6ee 100644
--- a/EasySnippets/Views/EditorWindow.xaml.cs
+++ b/EasySnippets/Views/EditorWindow.xaml.cs
@@ -24,6 +24,11 @@ public EditorWindow(Snippet snippet, bool isEdit)
private void OkClick(object sender, RoutedEventArgs e)
{
+ if (string.IsNullOrWhiteSpace(SnippetNameTextBox.Text) || string.IsNullOrWhiteSpace(SnippetValueTextBox.Text))
+ {
+ return;
+ }
+
Snippet.Name = SnippetNameTextBox.Text;
Snippet.Value = SnippetValueTextBox.Text;
diff --git a/EasySnippets/Views/MainWindow.xaml b/EasySnippets/Views/MainWindow.xaml
index 6d958e7..6bf9958 100644
--- a/EasySnippets/Views/MainWindow.xaml
+++ b/EasySnippets/Views/MainWindow.xaml
@@ -1,15 +1,19 @@
-
+ BorderBrush="{DynamicResource AccentColorBrush}"
+ BorderThickness="2"
+ WindowStartupLocation="CenterScreen"
+ Closing="Window_Closing" Deactivated="MainWindow_OnDeactivated">
@@ -23,13 +27,13 @@
-
+
-
+
@@ -55,16 +59,23 @@
Name="SnippetsDataGrid"
SelectionChanged="SnippetsDataGrid_OnSelectionChanged"
MouseDoubleClick="EditSnippet"
- SelectionMode="Single">
+ SelectionMode="Single"
+ CanUserSortColumns="False">
+
+
+
+
+
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/EasySnippets/Views/MainWindow.xaml.cs b/EasySnippets/Views/MainWindow.xaml.cs
index 3faa7a1..63b070c 100644
--- a/EasySnippets/Views/MainWindow.xaml.cs
+++ b/EasySnippets/Views/MainWindow.xaml.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
+using System.Reactive.Linq;
+using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -9,6 +11,7 @@
using EasySnippets.ViewModels;
using Microsoft.Win32;
using Newtonsoft.Json;
+using MahApps.Metro.SimpleChildWindow;
namespace EasySnippets.Views
{
@@ -25,28 +28,27 @@ public MainWindow()
SnippetsList = new ObservableCollection();
InitializeComponent();
- LoadSettings();
- }
+ IObservable observableSizeChanges = Observable
+ .FromEventPattern(this, "SizeChanged")
+ .Select(x => x.EventArgs)
+ .Throttle(TimeSpan.FromMilliseconds(300));
- private void Exit_Click(object sender, RoutedEventArgs e)
- {
- if (CancelClose())
- {
- return;
- }
+ IDisposable sizeChangedSubscription = observableSizeChanges
+ .ObserveOn(SynchronizationContext.Current)
+ .Subscribe(x => WindowSizeChanged());
- Application.Current.Shutdown();
+ LoadSettings();
}
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+ private async void Exit_Click(object sender, RoutedEventArgs e)
{
- e.Cancel = CancelClose();
+ await this.ShowChildWindowAsync(new ClosingDialog());
}
- private bool CancelClose()
+ private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
- return MessageBoxCentered.Show(this, "Are you sure?", "Exit",
- MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No;
+ e.Cancel = true;
+ await this.ShowChildWindowAsync(new ClosingDialog());
}
private void MenuOpen_Click(object sender, RoutedEventArgs e)
@@ -119,7 +121,7 @@ private void AlwaysOnTopToggle(object sender, RoutedEventArgs e)
private void SnippetsDataGrid_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SnippetsDataGrid.SelectedItem is Snippet snippet){
- Clipboard.SetText($"{snippet.Value}");
+ Clipboard.SetDataObject($"{snippet.Value}");
}
}
@@ -137,6 +139,11 @@ private void EditSnippet(object sender, MouseButtonEventArgs e)
{
int rowIndex = SnippetsDataGrid.SelectedIndex;
+ if (rowIndex < 0)
+ {
+ return;
+ }
+
Snippet snippet = rowIndex < SnippetsList.Count ? SnippetsList[rowIndex] : new Snippet();
bool isEdit = rowIndex < SnippetsList.Count;
@@ -164,7 +171,7 @@ private void EditSnippet(object sender, MouseButtonEventArgs e)
SnippetsList.Add(editorWindow.Snippet);
}
- Clipboard.SetText($"{editorWindow.Snippet.Value}");
+ Clipboard.SetDataObject($"{editorWindow.Snippet.Value}");
}
private void MainWindow_OnDeactivated(object sender, EventArgs e)
@@ -190,6 +197,7 @@ private void LoadSettings()
{
string json = File.ReadAllText(Settings.SettingsPath);
AppSettings = JsonConvert.DeserializeObject(json);
+
}
catch (Exception)
{
@@ -201,6 +209,12 @@ private void LoadSettings()
};
}
+ AppSettings.Height = AppSettings.Height > 0 ? AppSettings.Height : 300;
+ AppSettings.Width = AppSettings.Width > 0 ? AppSettings.Width : 220;
+
+ Height = AppSettings.Height;
+ Width = AppSettings.Width;
+
Topmost = AppSettings.AlwaysOnTopEnabled;
AlwaysOnTopMenuItem.IsChecked = AppSettings.AlwaysOnTopEnabled;
AutoStartMenuItem.IsChecked = AppSettings.AutoStartEnabled;
@@ -231,5 +245,11 @@ private void AutoStartToggle(object sender, RoutedEventArgs e)
{
ApplyAutoStart(((MenuItem)sender).IsChecked);
}
+
+ private void WindowSizeChanged()
+ {
+ AppSettings.Height = Convert.ToInt32(Height);
+ AppSettings.Width = Convert.ToInt32(Width);
+ }
}
}
diff --git a/EasySnippets/packages.config b/EasySnippets/packages.config
index e4ac9c6..d02c28c 100644
--- a/EasySnippets/packages.config
+++ b/EasySnippets/packages.config
@@ -1,4 +1,9 @@
+
+
+
+
+
\ No newline at end of file