Browse Source

Added chckbox style, settings window "tabs" and settings wip

flabbet 4 years ago
parent
commit
3e73e5f80c

+ 2 - 0
PixiEditor/App.xaml

@@ -14,6 +14,8 @@
                 <ResourceDictionary Source="Styles/DockingManagerStyle.xaml" />
                 <ResourceDictionary Source="Styles/DarkScrollBarStyle.xaml" />
                 <ResourceDictionary Source="Styles/ImageCheckBoxStyle.xaml" />
+                <ResourceDictionary Source="Styles/DarkCheckboxStyle.xaml" />
+                <ResourceDictionary Source="Styles/LabelStyles.xaml" />
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Application.Resources>

+ 20 - 0
PixiEditor/Helpers/Converters/EqualityBoolToVisibilityConverter.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class EqualityBoolToVisibilityConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return value.Equals(parameter) ? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 41 - 0
PixiEditor/Models/UserPreferences/PreferencesSettings.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PixiEditor.Models.UserPreferences
+{
+    public static class PreferencesSettings
+    {
+        public static void UpdatePreference(string name, object value)
+        {
+            Properties.Settings.Default.Reload();
+            if (Properties.Settings.Default.Properties[name] != null)
+            {
+                Properties.Settings.Default.Properties[name].DefaultValue = value;
+            }
+            else
+            {
+                Properties.Settings.Default.Properties.Add(new SettingsProperty(name) { DefaultValue = value });
+            }
+
+            Properties.Settings.Default.Save();
+        }
+
+#nullable enable
+
+        public static T? GetPreference<T>(string name)
+        {
+            return GetPreference(name, default(T));
+        }
+
+        public static T? GetPreference<T>(string name, T? fallbackValue)
+        {
+            return Properties.Settings.Default.Properties[name] != null
+                ? (T)Convert.ChangeType(Properties.Settings.Default.Properties[name].DefaultValue, typeof(T))
+                : fallbackValue;
+        }
+    }
+}

+ 13 - 1
PixiEditor/Properties/Settings.Designer.cs

@@ -12,7 +12,7 @@ namespace PixiEditor.Properties {
     
     
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.7.0.0")]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
     internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
         
         private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -22,5 +22,17 @@ namespace PixiEditor.Properties {
                 return defaultInstance;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("True")]
+        public bool ShowNewFilePopupOnStartup {
+            get {
+                return ((bool)(this["ShowNewFilePopupOnStartup"]));
+            }
+            set {
+                this["ShowNewFilePopupOnStartup"] = value;
+            }
+        }
     }
 }

+ 7 - 6
PixiEditor/Properties/Settings.settings

@@ -1,8 +1,9 @@
 <?xml version='1.0' encoding='utf-8'?>
-
-<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
-  <Profiles>
-    <Profile Name="(Default)" />
-  </Profiles>
-  <Settings />
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="PixiEditor.Properties" GeneratedClassName="Settings">
+  <Profiles />
+  <Settings>
+    <Setting Name="ShowNewFilePopupOnStartup" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">True</Value>
+    </Setting>
+  </Settings>
 </SettingsFile>

+ 39 - 0
PixiEditor/Styles/DarkCheckboxStyle.xaml

@@ -0,0 +1,39 @@
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                    xmlns:local="clr-namespace:PixiEditor.Styles">
+    <Style TargetType="CheckBox">
+        <Setter Property="SnapsToDevicePixels" Value="true"/>
+        <Setter Property="OverridesDefaultStyle" Value="true"/>
+        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
+        <Setter Property="Foreground" Value="White"/>
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="CheckBox">
+                    <BulletDecorator Background="Transparent">
+                        <BulletDecorator.Bullet>
+                            <Border x:Name="Border" Width="15" Height="15" CornerRadius="2" Background="#FF1B1B1B" BorderThickness="0">
+                                <Path Width="9" Height="9" x:Name="CheckMark" SnapsToDevicePixels="False" Stroke="#FF0077C9" StrokeThickness="2" Data="M 0 4 L 3 8 8 0" />
+                            </Border>
+                        </BulletDecorator.Bullet>
+                        <ContentPresenter Margin="4,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RecognizesAccessKey="True"/>
+                    </BulletDecorator>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsChecked" Value="false">
+                            <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
+                        </Trigger>
+                        <Trigger Property="IsChecked" Value="{x:Null}">
+                            <Setter TargetName="CheckMark" Property="Data" Value="M 0 8 L 8 0" />
+                        </Trigger>
+                        <Trigger Property="IsMouseOver" Value="true">
+                            <Setter TargetName="Border" Property="Background" Value="#FF131313" />
+                        </Trigger>
+                        <Trigger Property="IsEnabled" Value="false">
+                            <Setter TargetName="CheckMark" Property="Stroke" Value="#FF6C6C6C"/>
+                            <Setter Property="Foreground" Value="Gray"/>
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
+</ResourceDictionary>

+ 13 - 0
PixiEditor/Styles/LabelStyles.xaml

@@ -0,0 +1,13 @@
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                    xmlns:local="clr-namespace:PixiEditor.Styles">
+
+    <Style TargetType="Label" x:Key="BaseLabel">
+        <Setter Property="Foreground" Value="White"/>
+    </Style>
+    
+    <Style x:Key="Header1" TargetType="Label" BasedOn="{StaticResource BaseLabel}">
+        <Setter Property="FontSize" Value="36"/>
+        <Setter Property="Margin" Value="20"/>
+    </Style>
+</ResourceDictionary>

+ 0 - 64
PixiEditor/ViewModels/FeedbackDialogViewModel.cs

@@ -1,64 +0,0 @@
-using System.Windows;
-using PixiEditor.Helpers;
-
-namespace PixiEditor.ViewModels
-{
-    internal class FeedbackDialogViewModel : ViewModelBase
-    {
-        private string _emailBody;
-
-
-        private string _mailFrom;
-
-        public FeedbackDialogViewModel()
-        {
-            CloseButtonCommand = new RelayCommand(CloseWindow);
-            SendButtonCommand = new RelayCommand(Send, CanSend);
-        }
-
-        public RelayCommand CloseButtonCommand { get; set; }
-        public RelayCommand SendButtonCommand { get; set; }
-
-        public string MailFrom
-        {
-            get => _mailFrom;
-            set
-            {
-                if (_mailFrom != value)
-                {
-                    _mailFrom = value;
-                    RaisePropertyChanged("MailFrom");
-                }
-            }
-        }
-
-        public string EmailBody
-        {
-            get => _emailBody;
-            set
-            {
-                if (_emailBody != value)
-                {
-                    _emailBody = value;
-                    RaisePropertyChanged("EmailBody");
-                }
-            }
-        }
-
-        private void CloseWindow(object parameter)
-        {
-            ((Window) parameter).DialogResult = false;
-            CloseButton(parameter);
-        }
-
-        private void Send(object parameter)
-        {
-            CloseButton(parameter);
-        }
-
-        private bool CanSend(object property)
-        {
-            return !string.IsNullOrWhiteSpace(MailFrom);
-        }
-    }
-}

+ 43 - 0
PixiEditor/ViewModels/SettingsWindowViewModel.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PixiEditor.Helpers;
+using PixiEditor.ViewModels.SubViewModels.UserPreferences;
+
+namespace PixiEditor.ViewModels
+{
+    public class SettingsWindowViewModel : ViewModelBase
+    {
+        public RelayCommand SelectCategoryCommand { get; set; }
+
+        private string selectedCategory = "General";
+
+        public string SelectedCategory
+        {
+            get => selectedCategory;
+            set
+            {
+                selectedCategory = value;
+                RaisePropertyChanged(nameof(SelectedCategory));
+            }
+        }
+
+        public SettingsViewModel SettingsSubViewModel { get; set; }
+
+        public SettingsWindowViewModel()
+        {
+            SettingsSubViewModel = new SettingsViewModel(this);
+            SelectCategoryCommand = new RelayCommand(SelectCategory);
+        }
+
+        private void SelectCategory(object parameter)
+        {
+            if (parameter is not null && parameter is string value)
+            {
+                SelectedCategory = value;
+            }
+        }
+    }
+}

+ 47 - 0
PixiEditor/ViewModels/SubViewModels/Main/MiscViewModel.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PixiEditor.Helpers;
+using PixiEditor.Views.Dialogs;
+
+namespace PixiEditor.ViewModels.SubViewModels.Main
+{
+    public class MiscViewModel : SubViewModel<ViewModelMain>
+    {
+        public RelayCommand OpenHyperlinkCommand { get; set; }
+
+        public RelayCommand OpenSettingsWindowCommand { get; set; }
+
+        public MiscViewModel(ViewModelMain owner)
+            : base(owner)
+        {
+            OpenHyperlinkCommand = new RelayCommand(OpenHyperlink);
+            OpenSettingsWindowCommand = new RelayCommand(OpenSettingsWindow);
+        }
+
+        private void OpenSettingsWindow(object parameter)
+        {
+            SettingsWindow settings = new SettingsWindow();
+            settings.Show();
+        }
+
+        private void OpenHyperlink(object parameter)
+        {
+            if (parameter == null)
+            {
+                return;
+            }
+
+            var url = (string)parameter;
+            var processInfo = new ProcessStartInfo()
+            {
+                FileName = url,
+                UseShellExecute = true
+            };
+            Process.Start(processInfo);
+        }
+    }
+}

+ 28 - 0
PixiEditor/ViewModels/SubViewModels/UserPreferences/SettingsViewModel.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Configuration;
+using PixiEditor.Models.UserPreferences;
+
+namespace PixiEditor.ViewModels.SubViewModels.UserPreferences
+{
+    public class SettingsViewModel : SubViewModel<SettingsWindowViewModel>
+    {
+        private bool showNewFilePopupOnStartup = PreferencesSettings.GetPreference("ShowNewFilePopupOnStartup", true);
+
+        public bool ShowNewFilePopupOnStartup
+        {
+            get => showNewFilePopupOnStartup;
+            set
+            {
+                showNewFilePopupOnStartup = value;
+                string name = nameof(ShowNewFilePopupOnStartup);
+                RaisePropertyChanged(name);
+                PreferencesSettings.UpdatePreference(name, value);
+            }
+        }
+
+        public SettingsViewModel(SettingsWindowViewModel owner)
+            : base(owner)
+        {
+        }
+    }
+}

+ 3 - 20
PixiEditor/ViewModels/ViewModelMain.cs

@@ -30,8 +30,6 @@ namespace PixiEditor.ViewModels
 
         public RelayCommand CloseWindowCommand { get; set; }
 
-        public RelayCommand OpenHyperlinkCommand { get; set; }
-
         public FileViewModel FileSubViewModel { get; set; }
 
         public UpdateViewModel UpdateSubViewModel { get; set; }
@@ -53,6 +51,7 @@ namespace PixiEditor.ViewModels
         public ColorsViewModel ColorsSubViewModel { get; set; }
 
         public DocumentViewModel DocumentSubViewModel { get; set; }
+        public MiscViewModel MiscSubViewModel { get; set; }
 
         public BitmapManager BitmapManager { get; set; }
 
@@ -72,7 +71,6 @@ namespace PixiEditor.ViewModels
             ChangesController = new PixelChangesController();
             OnStartupCommand = new RelayCommand(OnStartup);
             CloseWindowCommand = new RelayCommand(CloseWindow);
-            OpenHyperlinkCommand = new RelayCommand(OpenHyperlink);
 
             FileSubViewModel = new FileViewModel(this);
             UpdateSubViewModel = new UpdateViewModel(this);
@@ -84,6 +82,7 @@ namespace PixiEditor.ViewModels
             ViewportSubViewModel = new ViewportViewModel(this);
             ColorsSubViewModel = new ColorsViewModel(this);
             DocumentSubViewModel = new DocumentViewModel(this);
+            MiscSubViewModel = new MiscViewModel(this);
 
             ShortcutController = new ShortcutController
             {
@@ -152,23 +151,7 @@ namespace PixiEditor.ViewModels
         public bool DocumentIsNotNull(object property)
         {
             return BitmapManager.ActiveDocument != null;
-        }
-
-        private void OpenHyperlink(object parameter)
-        {
-            if (parameter == null)
-            {
-                return;
-            }
-
-            var url = (string)parameter;
-            var processInfo = new ProcessStartInfo()
-            {
-                FileName = url,
-                UseShellExecute = true
-            };
-            Process.Start(processInfo);
-        }
+        }        
 
         private void CloseWindow(object property)
         {

+ 62 - 0
PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -0,0 +1,62 @@
+<Window x:Class="PixiEditor.Views.Dialogs.SettingsWindow"
+        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:local="clr-namespace:PixiEditor.Views.Dialogs" xmlns:viewmodels="clr-namespace:PixiEditor.ViewModels" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+        mc:Ignorable="d"
+        Title="SettingsWindow" Name="window" 
+        Height="450" Width="800" WindowStyle="None" DataContext="{DynamicResource SettingsWindowViewModel}"
+        BorderBrush="Black" BorderThickness="1">
+    <Window.Resources>
+        <viewmodels:SettingsWindowViewModel x:Key="SettingsWindowViewModel"/>
+        <converters:EqualityBoolToVisibilityConverter x:Key="EqualityBoolToVisibilityConverter"/>
+    </Window.Resources>
+    <WindowChrome.WindowChrome>
+        <WindowChrome CaptionHeight="32"
+                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
+    </WindowChrome.WindowChrome>
+
+    <Window.CommandBindings>
+        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
+                        Executed="CommandBinding_Executed_Close" />
+    </Window.CommandBindings>
+
+    <Grid Background="{StaticResource AccentColor}">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="200"/>
+            <ColumnDefinition Width="147*"/>
+        </Grid.ColumnDefinitions>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="35" />
+            <RowDefinition />
+        </Grid.RowDefinitions>
+
+        <DockPanel Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Background="{StaticResource MainColor}">
+            <Label Foreground="White" FontSize="16">User preferences</Label>
+            <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}"
+                    WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
+                    Command="{x:Static SystemCommands.CloseWindowCommand}" />
+        </DockPanel>
+        <StackPanel Grid.Row="1" Grid.Column="0">
+            <Button Style="{StaticResource DarkRoundButton}" Margin="10 5 10 5"
+                    Command="{Binding SelectCategoryCommand}" CommandParameter="General">General</Button>
+            <Button Style="{StaticResource DarkRoundButton}" Margin="10 5 10 5" 
+                    Command="{Binding SelectCategoryCommand}" CommandParameter="Updates">Updates</Button>
+        </StackPanel>
+        <Grid Grid.Row="1" Grid.Column="1" Background="{StaticResource MainColor}">
+            <Grid Visibility="{Binding SelectedCategory, Converter={StaticResource EqualityBoolToVisibilityConverter},
+            ConverterParameter='General'}">
+                <StackPanel Orientation="Vertical">
+                    <Label Content="File" Style="{StaticResource Header1}"/>
+                    <StackPanel Orientation="Vertical" Margin="50 0 50 0">
+                        <CheckBox Content="Show New File dialog on startup" IsChecked="{Binding SettingsSubViewModel.ShowNewFilePopupOnStartup}"/>
+                    </StackPanel>
+                </StackPanel>
+            </Grid>
+            <Grid Visibility="{Binding SelectedCategory, Converter={StaticResource EqualityBoolToVisibilityConverter},
+            ConverterParameter='Updates'}">
+            </Grid>
+        </Grid>
+    </Grid>
+</Window>

+ 38 - 0
PixiEditor/Views/Dialogs/SettingsWindow.xaml.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace PixiEditor.Views.Dialogs
+{
+    /// <summary>
+    /// Interaction logic for SettingsWindow.xaml
+    /// </summary>
+    public partial class SettingsWindow : Window
+    {
+        public SettingsWindow()
+        {
+            InitializeComponent();
+        }
+
+        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            e.CanExecute = true;
+        }
+
+        private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
+        {
+            SystemCommands.CloseWindow(this);
+        }
+
+    }
+}

+ 7 - 5
PixiEditor/Views/MainWindow.xaml

@@ -83,6 +83,8 @@
                               Command="{Binding FileSubViewModel.SaveDocumentCommand}" CommandParameter="AsNew" />
                     <MenuItem Header="_Export" InputGestureText="Ctrl+Shift+Alt+S" Command="{Binding FileSubViewModel.ExportFileCommand}" />
                     <Separator />
+                    <MenuItem Header="_Settings" Command="{Binding MiscSubViewModel.OpenSettingsWindowCommand}" />
+                    <Separator />
                     <MenuItem Header="_Exit" Command="{x:Static SystemCommands.CloseWindowCommand}" />
                 </MenuItem>
                 <MenuItem Header="_Edit">
@@ -111,16 +113,16 @@
                     <MenuItem Header="Center Content" Command="{Binding DocumentSubViewModel.CenterContentCommand}" />
                 </MenuItem>
                 <MenuItem Header="_Help">
-                    <MenuItem Header="Documentation" Command="{Binding OpenHyperlinkCommand}"
+                    <MenuItem Header="Documentation" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki"/>
-                    <MenuItem Header="Repository" Command="{Binding OpenHyperlinkCommand}"
+                    <MenuItem Header="Repository" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor"/>
-                    <MenuItem Header="Shortcuts" Command="{Binding OpenHyperlinkCommand}"
+                    <MenuItem Header="Shortcuts" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Shortcuts"/>
                     <Separator/>
-                    <MenuItem Header="License" Command="{Binding OpenHyperlinkCommand}"
+                    <MenuItem Header="License" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/blob/master/LICENSE"/>
-                    <MenuItem Header="Third Party Licenses" Command="{Binding OpenHyperlinkCommand}"
+                    <MenuItem Header="Third Party Licenses" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Third-party-licenses"/>
                 </MenuItem>
             </Menu>