Skip to content

Commit

Permalink
Merge pull request #4 from karolberezicki/1.3
Browse files Browse the repository at this point in the history
1.3 release
  • Loading branch information
karolberezicki authored Oct 12, 2017
2 parents b557712 + cec473e commit 9818ff1
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 29 deletions.
15 changes: 13 additions & 2 deletions EasySnippets/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
StartupUri="Views/MainWindow.xaml"
DispatcherUnhandledException="App_DispatcherUnhandledException">
<Application.Resources>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool"/>
</ResourceDictionary>
</Application.Resources>
</Application>
</Application>
25 changes: 25 additions & 0 deletions EasySnippets/EasySnippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@
<ApplicationIcon>es.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath>
</Reference>
<Reference Include="MahApps.Metro.SimpleChildWindow, Version=1.4.0.0, Culture=neutral, PublicKeyToken=bbbfdff7f500a992, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.SimpleChildWindow.1.4.0\lib\net45\MahApps.Metro.SimpleChildWindow.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Reactive.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -65,12 +83,19 @@
</ApplicationDefinition>
<Compile Include="Utils\StartUpManager.cs" />
<Compile Include="ViewModels\Settings.cs" />
<Compile Include="Views\ClosingDialog.xaml.cs">
<DependentUpon>ClosingDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\EditorWindow.xaml.cs">
<DependentUpon>EditorWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\Annotations.cs" />
<Compile Include="ViewModels\Snippet.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Page Include="Views\ClosingDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\EditorWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
16 changes: 16 additions & 0 deletions EasySnippets/ViewModels/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(ref T storage, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(storage, value))
Expand Down
31 changes: 31 additions & 0 deletions EasySnippets/Views/ClosingDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<simpleChildWindow:ChildWindow x:Class="EasySnippets.Views.ClosingDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
Title="Exit"
Padding="15"
d:DesignHeight="100"
d:DesignWidth="120"
AllowMove="True"
ShowCloseButton="True"
mc:Ignorable="d">

<simpleChildWindow:ChildWindow.OverlayBrush>
<SolidColorBrush Opacity="0.8" Color="{StaticResource Gray2}" />
</simpleChildWindow:ChildWindow.OverlayBrush>


<StackPanel Orientation="Vertical" Margin="10">
<StackPanel Margin="5">
<TextBlock FontSize="16">Are you sure</TextBlock>
<TextBlock FontSize="16">you want to exit?</TextBlock>
</StackPanel>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Margin="5" Content="Yes" Click="ApplicationShutdown"/>
<Button Margin="5" Content="No" Click="DialogDismiss"/>
</StackPanel>
</StackPanel>
</simpleChildWindow:ChildWindow>
26 changes: 26 additions & 0 deletions EasySnippets/Views/ClosingDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Windows;
using MahApps.Metro.SimpleChildWindow;

namespace EasySnippets.Views
{
/// <summary>
/// Interaction logic for ClosingDialog.xaml
/// </summary>
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();
}
}
}
5 changes: 3 additions & 2 deletions EasySnippets/Views/EditorWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Window x:Class="EasySnippets.Views.EditorWindow"
<controls:MetroWindow x:Class="EasySnippets.Views.EditorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:EasySnippets"
xmlns:views="clr-namespace:EasySnippets.Views"
x:Name="EasySnippetsEditorWindow"
Expand Down Expand Up @@ -56,4 +57,4 @@
Visibility="{Binding IsEdit, Converter={StaticResource VisibilityOfBool}, RelativeSource={RelativeSource FindAncestor, AncestorType= views:EditorWindow}}"/>
</Grid>

</Window>
</controls:MetroWindow>
5 changes: 5 additions & 0 deletions EasySnippets/Views/EditorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
29 changes: 20 additions & 9 deletions EasySnippets/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<Window x:Class="EasySnippets.Views.MainWindow"
<controls:MetroWindow x:Class="EasySnippets.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:EasySnippets"
x:Name="EasySnippetsWindow"
mc:Ignorable="d"
Title="Easy Snippets"
Height="300" Width="200"
Height="300" Width="220"
WindowStyle="ToolWindow"
Closing="Window_Closing" Deactivated="MainWindow_OnDeactivated">
BorderBrush="{DynamicResource AccentColorBrush}"
BorderThickness="2"
WindowStartupLocation="CenterScreen"
Closing="Window_Closing" Deactivated="MainWindow_OnDeactivated">

<Window.CommandBindings>
<CommandBinding Command="Open" Executed="MenuOpen_Click"></CommandBinding>
Expand All @@ -23,13 +27,13 @@
<KeyBinding Key="S" Modifiers="Control+Shift" Command="SaveAs"></KeyBinding>
</Window.InputBindings>

<Grid>
<Grid Margin="2">
<Grid.DataContext>
<Binding ElementName="EasySnippetsWindow" Path="." />
</Grid.DataContext>

<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
Expand All @@ -55,16 +59,23 @@
Name="SnippetsDataGrid"
SelectionChanged="SnippetsDataGrid_OnSelectionChanged"
MouseDoubleClick="EditSnippet"
SelectionMode="Single">
SelectionMode="Single"
CanUserSortColumns="False">

<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="BorderThickness" Value="1" />
</Style>
</DataGrid.ColumnHeaderStyle>

<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name, Mode=TwoWay}"
Width="*" IsReadOnly="True" FontSize="20" />
</DataGrid.Columns>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="LightSkyBlue"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightSkyBlue"/>
</DataGrid.Resources>
</DataGrid>
</Grid>

</Window>
</controls:MetroWindow>
52 changes: 36 additions & 16 deletions EasySnippets/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
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;
using EasySnippets.Utils;
using EasySnippets.ViewModels;
using Microsoft.Win32;
using Newtonsoft.Json;
using MahApps.Metro.SimpleChildWindow;

namespace EasySnippets.Views
{
Expand All @@ -25,28 +28,27 @@ public MainWindow()
SnippetsList = new ObservableCollection<Snippet>();
InitializeComponent();

LoadSettings();
}
IObservable<SizeChangedEventArgs> observableSizeChanges = Observable
.FromEventPattern<SizeChangedEventArgs>(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)
Expand Down Expand Up @@ -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}");
}
}

Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -190,6 +197,7 @@ private void LoadSettings()
{
string json = File.ReadAllText(Settings.SettingsPath);
AppSettings = JsonConvert.DeserializeObject<Settings>(json);

}
catch (Exception)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
5 changes: 5 additions & 0 deletions EasySnippets/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MahApps.Metro" version="1.5.0" targetFramework="net461" />
<package id="MahApps.Metro.SimpleChildWindow" version="1.4.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="Rx-Core" version="2.2.5" targetFramework="net461" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net461" />
<package id="Rx-Linq" version="2.2.5" targetFramework="net461" />
</packages>

0 comments on commit 9818ff1

Please sign in to comment.