From 3e6c837916263a023a7cdc98a045f5c9f27381d5 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Dec 2020 11:55:06 +0800 Subject: [PATCH] refactor<*>: move SourceGit.Git.Preference to SourceGit.Preference --- src/{Git/Preference.cs => App.preference.cs} | 204 +++++++----------- src/App.xaml.cs | 46 +++- src/Converters/FileStatusToColor.cs | 2 +- src/Converters/FilesDisplayModeToIcon.cs | 6 +- .../FilesDisplayModeToVisibility.cs | 10 +- src/Git/Commit.cs | 18 -- src/Git/Repository.cs | 20 +- src/UI/Clone.xaml.cs | 14 +- src/UI/CommitViewer.xaml | 2 +- src/UI/Configure.xaml.cs | 2 +- src/UI/Dashboard.xaml | 3 +- src/UI/Dashboard.xaml.cs | 13 +- src/UI/DiffViewer.xaml | 2 +- src/UI/DiffViewer.xaml.cs | 4 +- src/UI/FilesDisplayModeSwitch.xaml.cs | 14 +- src/UI/Histories.xaml | 2 +- src/UI/Histories.xaml.cs | 2 +- src/UI/Init.xaml.cs | 4 +- src/UI/InteractiveRebase.xaml.cs | 4 +- src/UI/Launcher.xaml | 6 +- src/UI/Launcher.xaml.cs | 4 +- src/UI/Manager.xaml.cs | 36 ++-- .../{Preference.xaml => SettingDialog.xaml} | 14 +- ...eference.xaml.cs => SettingDialog.xaml.cs} | 24 +-- src/UI/TwoCommitsDiff.xaml | 2 +- src/UI/WorkingCopy.xaml | 24 +-- src/UI/WorkingCopy.xaml.cs | 14 +- 27 files changed, 236 insertions(+), 260 deletions(-) rename src/{Git/Preference.cs => App.preference.cs} (60%) rename src/UI/{Preference.xaml => SettingDialog.xaml} (96%) rename src/UI/{Preference.xaml.cs => SettingDialog.xaml.cs} (89%) diff --git a/src/Git/Preference.cs b/src/App.preference.cs similarity index 60% rename from src/Git/Preference.cs rename to src/App.preference.cs index cd284055..da6b6467 100644 --- a/src/Git/Preference.cs +++ b/src/App.preference.cs @@ -1,15 +1,83 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text.Json; -namespace SourceGit.Git { +namespace SourceGit { /// /// User's preference settings. Serialized to /// public class Preference { + /// + /// Tools setting. + /// + public class ToolSetting { + /// + /// Git executable file path. + /// + public string GitExecutable { get; set; } + /// + /// Default clone directory. + /// + public string GitDefaultCloneDir { get; set; } + /// + /// Selected merge tool. + /// + public int MergeTool { get; set; } = 0; + /// + /// Executable file path for merge tool. + /// + public string MergeExecutable { get; set; } = "--"; + } + + /// + /// File's display mode. + /// + public enum FilesDisplayMode { + Tree, + List, + Grid, + } + + /// + /// Settings for UI. + /// + public class UISetting { + /// + /// Use light theme? + /// + public bool UseLightTheme { get; set; } + /// + /// Main window width + /// + public double WindowWidth { get; set; } + /// + /// Main window height + /// + public double WindowHeight { get; set; } + /// + /// Move commit viewer from bottom to right + /// + public bool MoveCommitViewerRight { get; set; } + /// + /// File's display mode in unstaged view. + /// + public FilesDisplayMode UnstageFileDisplayMode { get; set; } + /// + /// File's display mode in staged view. + /// + public FilesDisplayMode StagedFileDisplayMode { get; set; } + /// + /// Use DataGrid instead of TreeView in changes view. + /// + public bool UseListInChanges { get; set; } + /// + /// Use combined instead of side-by-side mode in diff viewer. + /// + public bool UseCombinedDiff { get; set; } + } + /// /// Group(Virtual folder) for watched repositories. /// @@ -32,104 +100,19 @@ namespace SourceGit.Git { public bool IsExpended { get; set; } } - /// - /// File's display mode. - /// - public enum FilesDisplayMode { - Tree, - List, - Grid, - } - - #region STATICS - /// - /// Storage path for Preference. - /// - private static readonly string SAVE_PATH = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "SourceGit", - "preference.json"); - /// - /// Runtime singleton instance. - /// - private static Preference instance = null; - public static Preference Instance { - get { - if (instance == null) Load(); - return instance; - } - set { - instance = value; - } - } - #endregion - - #region SETTING_GENERAL - /// - /// Use light color theme. - /// - public bool UseLightTheme { get; set; } + #region SAVED_DATAS /// /// Check for updates. /// - public bool CheckUpdate { get; set; } - #endregion - - #region SETTING_GIT + public bool CheckUpdate { get; set; } = true; /// - /// Git executable file path. + /// Settings for executables. /// - public string GitExecutable { get; set; } + public ToolSetting Tools { get; set; } = new ToolSetting(); /// - /// Default clone directory. + /// Use light color theme. /// - public string GitDefaultCloneDir { get; set; } - #endregion - - #region SETTING_MERGE_TOOL - /// - /// Selected merge tool. - /// - public int MergeTool { get; set; } = 0; - /// - /// Executable file path for merge tool. - /// - public string MergeExecutable { get; set; } = "--"; - #endregion - - #region SETTING_UI - /// - /// Main window's width - /// - public double UIMainWindowWidth { get; set; } - /// - /// Main window's height - /// - public double UIMainWindowHeight { get; set; } - /// - /// Show/Hide tags' list view. - /// - public bool UIShowTags { get; set; } = true; - /// - /// Use horizontal layout for histories. - /// - public bool UIUseHorizontalLayout { get; set; } - /// - /// Files' display mode in unstage view. - /// - public FilesDisplayMode UIUnstageDisplayMode { get; set; } = FilesDisplayMode.Grid; - /// - /// Files' display mode in staged view. - /// - public FilesDisplayMode UIStagedDisplayMode { get; set; } = FilesDisplayMode.Grid; - /// - /// Using datagrid instead of tree in changes. - /// - public bool UIUseListInChanges { get; set; } - /// - /// Use one side diff instead of two sides. - /// - public bool UIUseOneSideDiff { get; set; } + public UISetting UI { get; set; } = new UISetting(); #endregion #region SETTING_REPOS @@ -140,34 +123,7 @@ namespace SourceGit.Git { /// /// Watched repositories. /// - public List Repositories { get; set; } = new List(); - #endregion - - #region METHODS_LOAD_SAVE - /// - /// Load preference from disk. - /// - /// Loaded preference instance. - public static void Load() { - if (!File.Exists(SAVE_PATH)) { - instance = new Preference(); - } else { - instance = JsonSerializer.Deserialize(File.ReadAllText(SAVE_PATH)); - } - } - - /// - /// Save current preference into disk. - /// - public static void Save() { - if (instance == null) return; - - var dir = Path.GetDirectoryName(SAVE_PATH); - if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); - - var data = JsonSerializer.Serialize(instance, new JsonSerializerOptions() { WriteIndented = true }); - File.WriteAllText(SAVE_PATH, data); - } + public List Repositories { get; set; } = new List(); #endregion #region METHODS_ON_GROUP @@ -244,12 +200,12 @@ namespace SourceGit.Git { /// Local storage path. /// Group's ID /// Added repository instance. - public Repository AddRepository(string path, string groupId) { + public Git.Repository AddRepository(string path, string groupId) { var repo = FindRepository(path); if (repo != null) return repo; var dir = new DirectoryInfo(path); - repo = new Repository() { + repo = new Git.Repository() { Path = dir.FullName, Name = dir.Name, GroupId = groupId, @@ -266,7 +222,7 @@ namespace SourceGit.Git { /// /// Local storage path. /// Founded repository instance. - public Repository FindRepository(string path) { + public Git.Repository FindRepository(string path) { var dir = new DirectoryInfo(path); foreach (var repo in Repositories) { if (repo.Path == dir.FullName) return repo; diff --git a/src/App.xaml.cs b/src/App.xaml.cs index 7ae2f60a..3243a7c9 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -1,6 +1,7 @@ using Microsoft.Win32; using System; using System.IO; +using System.Text.Json; using System.Windows; namespace SourceGit { @@ -9,22 +10,18 @@ namespace SourceGit { /// Application. /// public partial class App : Application { - /// - /// Getter/Setter for Git preference. + /// Getter/Setter for application user setting. /// - public static Git.Preference Preference { - get { return Git.Preference.Instance; } - set { Git.Preference.Instance = value; } - } + public static Preference Setting { get; set; } /// /// Check if GIT has been configured. /// public static bool IsGitConfigured { get { - return !string.IsNullOrEmpty(Preference.GitExecutable) - && File.Exists(Preference.GitExecutable); + return !string.IsNullOrEmpty(Setting.Tools.GitExecutable) + && File.Exists(Setting.Tools.GitExecutable); } } @@ -60,6 +57,17 @@ namespace SourceGit { return; } + // Load settings. + var settingFile = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "SourceGit", + "preference.json"); + if (!File.Exists(settingFile)) { + Setting = new Preference(); + } else { + Setting = JsonSerializer.Deserialize(File.ReadAllText(settingFile)); + } + // Try auto configure git via registry. if (!IsGitConfigured) { var root = RegistryKey.OpenBaseKey( @@ -68,7 +76,7 @@ namespace SourceGit { var git = root.OpenSubKey("SOFTWARE\\GitForWindows"); if (git != null) { - Preference.GitExecutable = Path.Combine( + Setting.Tools.GitExecutable = Path.Combine( git.GetValue("InstallPath") as string, "bin", "git.exe"); @@ -76,7 +84,7 @@ namespace SourceGit { } // Apply themes - if (Preference.UseLightTheme) { + if (Setting.UI.UseLightTheme) { foreach (var rs in Current.Resources.MergedDictionaries) { if (rs.Source != null && rs.Source.OriginalString.StartsWith("pack://application:,,,/Resources/Themes/")) { rs.Source = new Uri("pack://application:,,,/Resources/Themes/Light.xaml", UriKind.Absolute); @@ -98,14 +106,30 @@ namespace SourceGit { (Current.MainWindow as UI.Launcher).Open(repo); } + /// + /// Save settings. + /// + public static void SaveSetting() { + var settingFile = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "SourceGit", + "preference.json"); + + var dir = Path.GetDirectoryName(settingFile); + if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); + + var data = JsonSerializer.Serialize(Setting, new JsonSerializerOptions() { WriteIndented = true }); + File.WriteAllText(settingFile, data); + } + /// /// Deactivated event. /// /// /// private void OnAppDeactivated(object sender, EventArgs e) { - Git.Preference.Save(); GC.Collect(); + SaveSetting(); } } } diff --git a/src/Converters/FileStatusToColor.cs b/src/Converters/FileStatusToColor.cs index 86720b97..e57940e2 100644 --- a/src/Converters/FileStatusToColor.cs +++ b/src/Converters/FileStatusToColor.cs @@ -27,7 +27,7 @@ namespace SourceGit.Converters { status = change.Index; } - if (App.Preference.UseLightTheme) { + if (App.Setting.UI.UseLightTheme) { switch (status) { case Git.Change.Status.Modified: return Brushes.Goldenrod; case Git.Change.Status.Added: return Brushes.Green; diff --git a/src/Converters/FilesDisplayModeToIcon.cs b/src/Converters/FilesDisplayModeToIcon.cs index da5e8b7d..441c54c7 100644 --- a/src/Converters/FilesDisplayModeToIcon.cs +++ b/src/Converters/FilesDisplayModeToIcon.cs @@ -8,11 +8,11 @@ namespace SourceGit.Converters { public class FilesDisplayModeToIcon : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var mode = (Git.Preference.FilesDisplayMode)value; + var mode = (Preference.FilesDisplayMode)value; switch (mode) { - case Git.Preference.FilesDisplayMode.Grid: + case Preference.FilesDisplayMode.Grid: return App.Current.FindResource("Icon.Grid") as Geometry; - case Git.Preference.FilesDisplayMode.List: + case Preference.FilesDisplayMode.List: return App.Current.FindResource("Icon.List") as Geometry; default: return App.Current.FindResource("Icon.Tree") as Geometry; diff --git a/src/Converters/FilesDisplayModeToVisibility.cs b/src/Converters/FilesDisplayModeToVisibility.cs index 3fa7285f..2bea761f 100644 --- a/src/Converters/FilesDisplayModeToVisibility.cs +++ b/src/Converters/FilesDisplayModeToVisibility.cs @@ -10,9 +10,9 @@ namespace SourceGit.Converters { public bool TreatGridAsList { get; set; } = true; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var mode = (Git.Preference.FilesDisplayMode)value; - if (mode == Git.Preference.FilesDisplayMode.Tree) return Visibility.Collapsed; - if (mode == Git.Preference.FilesDisplayMode.List) return Visibility.Visible; + var mode = (Preference.FilesDisplayMode)value; + if (mode == Preference.FilesDisplayMode.Tree) return Visibility.Collapsed; + if (mode == Preference.FilesDisplayMode.List) return Visibility.Visible; if (TreatGridAsList) return Visibility.Visible; return Visibility.Collapsed; } @@ -25,7 +25,7 @@ namespace SourceGit.Converters { public class FilesDisplayModeToGrid : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return (Git.Preference.FilesDisplayMode)value == Git.Preference.FilesDisplayMode.Grid ? Visibility.Visible : Visibility.Collapsed; + return (Preference.FilesDisplayMode)value == Preference.FilesDisplayMode.Grid ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { @@ -36,7 +36,7 @@ namespace SourceGit.Converters { public class FilesDisplayModeToTree : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return (Git.Preference.FilesDisplayMode)value == Git.Preference.FilesDisplayMode.Tree ? Visibility.Visible : Visibility.Collapsed; + return (Preference.FilesDisplayMode)value == Preference.FilesDisplayMode.Tree ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/src/Git/Commit.cs b/src/Git/Commit.cs index e432bf4b..6646791b 100644 --- a/src/Git/Commit.cs +++ b/src/Git/Commit.cs @@ -153,24 +153,6 @@ namespace SourceGit.Git { commits.Add(current); } - if (!findHead && commits.Count > 0) { - var startInfo = new ProcessStartInfo(); - startInfo.FileName = Preference.Instance.GitExecutable; - startInfo.Arguments = $"merge-base --is-ancestor {commits[0].SHA} HEAD"; - startInfo.WorkingDirectory = repo.Path; - startInfo.UseShellExecute = false; - startInfo.CreateNoWindow = true; - startInfo.RedirectStandardOutput = false; - startInfo.RedirectStandardError = false; - - var proc = new Process() { StartInfo = startInfo }; - proc.Start(); - proc.WaitForExit(); - - commits[0].IsMerged = proc.ExitCode == 0; - proc.Close(); - } - return commits; } diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs index b2ca87d2..a1ca900d 100644 --- a/src/Git/Repository.cs +++ b/src/Git/Repository.cs @@ -47,6 +47,10 @@ namespace SourceGit.Git { /// public long LastOpenTime { get; set; } /// + /// Expand tags. + /// + public bool ExpandTags { get; set; } + /// /// Filters for logs. /// public List LogFilters { get; set; } = new List(); @@ -89,7 +93,7 @@ namespace SourceGit.Git { /// public string GetConfig(string key) { var startInfo = new ProcessStartInfo(); - startInfo.FileName = Preference.Instance.GitExecutable; + startInfo.FileName = App.Setting.Tools.GitExecutable; startInfo.Arguments = $"config {key}"; startInfo.WorkingDirectory = Path; startInfo.UseShellExecute = false; @@ -113,7 +117,7 @@ namespace SourceGit.Git { /// public void SetConfig(string key, string value) { var startInfo = new ProcessStartInfo(); - startInfo.FileName = Preference.Instance.GitExecutable; + startInfo.FileName = App.Setting.Tools.GitExecutable; startInfo.Arguments = $"config {key} \"{value}\""; startInfo.WorkingDirectory = Path; startInfo.UseShellExecute = false; @@ -135,7 +139,7 @@ namespace SourceGit.Git { /// Errors if exists. public static string RunCommand(string cwd, string args, Action outputHandler, bool includeError = false) { var startInfo = new ProcessStartInfo(); - startInfo.FileName = Preference.Instance.GitExecutable; + startInfo.FileName = App.Setting.Tools.GitExecutable; startInfo.Arguments = "--no-pager -c core.quotepath=off " + args; startInfo.WorkingDirectory = cwd; startInfo.UseShellExecute = false; @@ -213,7 +217,7 @@ namespace SourceGit.Git { /// public static bool IsValid(string path) { var startInfo = new ProcessStartInfo(); - startInfo.FileName = Preference.Instance.GitExecutable; + startInfo.FileName = App.Setting.Tools.GitExecutable; startInfo.Arguments = "rev-parse --git-dir"; startInfo.WorkingDirectory = path; startInfo.UseShellExecute = false; @@ -416,7 +420,7 @@ namespace SourceGit.Git { /// Local name /// /// - public static Repository Clone(string url, string folder, string rName, string lName, Action onProgress) { + public static bool Clone(string url, string folder, string rName, string lName, Action onProgress) { string RemoteName; if (rName != null) { RemoteName = $" --origin {rName}"; @@ -430,12 +434,10 @@ namespace SourceGit.Git { if (errs != null) { App.RaiseError(errs); - return null; + return false; } - var path = new DirectoryInfo(folder + "/" + lName).FullName; - var repo = Preference.Instance.AddRepository(path, ""); - return repo; + return true; } /// diff --git a/src/UI/Clone.xaml.cs b/src/UI/Clone.xaml.cs index 6e30504a..36b712aa 100644 --- a/src/UI/Clone.xaml.cs +++ b/src/UI/Clone.xaml.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -34,7 +35,7 @@ namespace SourceGit.UI { /// Constructor. /// public Clone(PopupManager mgr) { - ParentFolder = App.Preference.GitDefaultCloneDir; + ParentFolder = App.Setting.Tools.GitDefaultCloneDir; popup = mgr; InitializeComponent(); } @@ -82,15 +83,16 @@ namespace SourceGit.UI { popup.Lock(); - var repo = await Task.Run(() => { + var succ = await Task.Run(() => { return Git.Repository.Clone(RemoteUri, ParentFolder, rName, repoName, popup.UpdateStatus); }); - if (repo == null) { - popup.Unlock(); - } else { - popup.Close(true); + if (succ) { + var path = new DirectoryInfo(ParentFolder + "/" + repoName).FullName; + var repo = App.Setting.AddRepository(path, ""); repo.Open(); + } else { + popup.Unlock(); } } diff --git a/src/UI/CommitViewer.xaml b/src/UI/CommitViewer.xaml index 17a40048..b872934b 100644 --- a/src/UI/CommitViewer.xaml +++ b/src/UI/CommitViewer.xaml @@ -305,7 +305,7 @@ Margin="4,0,0,0" ToolTip="SWITCH TO LIST/TREE VIEW" Style="{StaticResource Style.ToggleButton.ListOrTree}" - IsChecked="{Binding Source={x:Static source:App.Preference}, Path=UIUseListInChanges, Mode=TwoWay}"/> + IsChecked="{Binding Source={x:Static source:App.Setting}, Path=UI.UseListInChanges, Mode=TwoWay}"/> + IsChecked="{Binding Path=ExpandTags, ElementName=me, Mode=TwoWay}"> diff --git a/src/UI/Dashboard.xaml.cs b/src/UI/Dashboard.xaml.cs index 3d75dd8e..fac9ce9b 100644 --- a/src/UI/Dashboard.xaml.cs +++ b/src/UI/Dashboard.xaml.cs @@ -46,6 +46,14 @@ namespace SourceGit.UI { private List cachedRemotes = new List(); private string abortCommand = null; + /// + /// Expand/Collapsed tags + /// + public bool ExpandTags { + get { return repo.ExpandTags; } + set { repo.ExpandTags = value; } + } + /// /// Constructor. /// @@ -65,9 +73,10 @@ namespace SourceGit.UI { }); }; + repo = opened; + InitializeComponent(); - repo = opened; histories.Repo = opened; commits.Repo = opened; @@ -347,7 +356,7 @@ namespace SourceGit.UI { } private void OpenTerminal(object sender, RoutedEventArgs e) { - var bash = Path.Combine(App.Preference.GitExecutable, "..", "bash.exe"); + var bash = Path.Combine(App.Setting.Tools.GitExecutable, "..", "bash.exe"); if (!File.Exists(bash)) { App.RaiseError("Can NOT locate bash.exe. Make sure bash.exe exists under the same folder with git.exe"); return; diff --git a/src/UI/DiffViewer.xaml b/src/UI/DiffViewer.xaml index a566e80c..8da0fb53 100644 --- a/src/UI/DiffViewer.xaml +++ b/src/UI/DiffViewer.xaml @@ -61,7 +61,7 @@ Margin="8,0,0,0" Style="{StaticResource Style.ToggleButton.SplitDirection}" ToolTip="Toggle One-Side/Two-Sides" - IsChecked="{Binding Source={x:Static sourcegit:App.Preference}, Path=UIUseOneSideDiff, Mode=TwoWay}" + IsChecked="{Binding Source={x:Static sourcegit:App.Setting}, Path=UI.UseCombinedDiff, Mode=TwoWay}" Checked="ChangeDiffMode" Unchecked="ChangeDiffMode"/> diff --git a/src/UI/DiffViewer.xaml.cs b/src/UI/DiffViewer.xaml.cs index 2267f9b7..c1474bc4 100644 --- a/src/UI/DiffViewer.xaml.cs +++ b/src/UI/DiffViewer.xaml.cs @@ -160,7 +160,7 @@ namespace SourceGit.UI { var lastOldLine = ""; var lastNewLine = ""; - if (App.Preference.UIUseOneSideDiff) { + if (App.Setting.UI.UseCombinedDiff) { var blocks = new List(); foreach (var line in lineChanges) { @@ -510,7 +510,7 @@ namespace SourceGit.UI { if (editors.Count == 0) return; var total = editorContainer.ActualWidth; - if (App.Preference.UIUseOneSideDiff) { + if (App.Setting.UI.UseCombinedDiff) { var editor = editors[0]; var minWidth = total - editor.NonFrozenColumnsViewportHorizontalOffset; var scroller = GetVisualChild(editor); diff --git a/src/UI/FilesDisplayModeSwitch.xaml.cs b/src/UI/FilesDisplayModeSwitch.xaml.cs index 44f74597..f06dfd75 100644 --- a/src/UI/FilesDisplayModeSwitch.xaml.cs +++ b/src/UI/FilesDisplayModeSwitch.xaml.cs @@ -12,12 +12,12 @@ namespace SourceGit.UI { public static readonly DependencyProperty ModeProperty = DependencyProperty.Register( "Mode", - typeof(Git.Preference.FilesDisplayMode), + typeof(Preference.FilesDisplayMode), typeof(FilesDisplayModeSwitch), - new PropertyMetadata(Git.Preference.FilesDisplayMode.Grid)); + new PropertyMetadata(Preference.FilesDisplayMode.Grid)); - public Git.Preference.FilesDisplayMode Mode { - get { return (Git.Preference.FilesDisplayMode)GetValue(ModeProperty); } + public Preference.FilesDisplayMode Mode { + get { return (Preference.FilesDisplayMode)GetValue(ModeProperty); } set { SetValue(ModeProperty, value); } } @@ -32,15 +32,15 @@ namespace SourceGit.UI { } private void UseGrid(object sender, RoutedEventArgs e) { - Mode = Git.Preference.FilesDisplayMode.Grid; + Mode = Preference.FilesDisplayMode.Grid; } private void UseList(object sender, RoutedEventArgs e) { - Mode = Git.Preference.FilesDisplayMode.List; + Mode = Preference.FilesDisplayMode.List; } private void UseTree(object sender, RoutedEventArgs e) { - Mode = Git.Preference.FilesDisplayMode.Tree; + Mode = Preference.FilesDisplayMode.Tree; } } } diff --git a/src/UI/Histories.xaml b/src/UI/Histories.xaml index 7360e910..dcdb0e7e 100644 --- a/src/UI/Histories.xaml +++ b/src/UI/Histories.xaml @@ -189,7 +189,7 @@ diff --git a/src/UI/Histories.xaml.cs b/src/UI/Histories.xaml.cs index deaece8b..633e92e0 100644 --- a/src/UI/Histories.xaml.cs +++ b/src/UI/Histories.xaml.cs @@ -630,7 +630,7 @@ namespace SourceGit.UI { layout.RowDefinitions.Clear(); layout.ColumnDefinitions.Clear(); - if (App.Preference.UIUseHorizontalLayout) { + if (App.Setting.UI.MoveCommitViewerRight) { layout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star), MinWidth = 200 }); layout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2) }); layout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star), MinWidth = 200 }); diff --git a/src/UI/Init.xaml.cs b/src/UI/Init.xaml.cs index 13fe1ce5..f0acae3f 100644 --- a/src/UI/Init.xaml.cs +++ b/src/UI/Init.xaml.cs @@ -36,13 +36,13 @@ namespace SourceGit.UI { if (errs != null) { App.RaiseError(errs); } else { - App.Preference.AddRepository(workingDir, ""); + App.Setting.AddRepository(workingDir, ""); } }); popup.Close(true); - var repo = App.Preference.FindRepository(workingDir); + var repo = App.Setting.FindRepository(workingDir); if (repo != null) repo.Open(); } diff --git a/src/UI/InteractiveRebase.xaml.cs b/src/UI/InteractiveRebase.xaml.cs index a31f4194..3df2c37f 100644 --- a/src/UI/InteractiveRebase.xaml.cs +++ b/src/UI/InteractiveRebase.xaml.cs @@ -42,8 +42,8 @@ namespace SourceGit.UI { public static List Supported = new List() { new InteractiveRebaseModeInfo(InteractiveRebaseMode.Pick, "Pick", "Use this commit", Brushes.Green), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Reword, "Reword", "Edit the commit message", Brushes.Yellow), - new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White), - new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Preference.UseLightTheme ? Brushes.Gray : Brushes.White), + new InteractiveRebaseModeInfo(InteractiveRebaseMode.Squash, "Squash", "Meld into previous commit", App.Setting.UI.UseLightTheme ? Brushes.Gray : Brushes.White), + new InteractiveRebaseModeInfo(InteractiveRebaseMode.Fixup, "Fixup", "Like 'Squash' but discard log message", App.Setting.UI.UseLightTheme? Brushes.Gray : Brushes.White), new InteractiveRebaseModeInfo(InteractiveRebaseMode.Drop, "Drop", "Remove commit", Brushes.Red), }; } diff --git a/src/UI/Launcher.xaml b/src/UI/Launcher.xaml index fd2d9dab..5b67b967 100644 --- a/src/UI/Launcher.xaml +++ b/src/UI/Launcher.xaml @@ -10,9 +10,9 @@ mc:Ignorable="d" MinWidth="800" MinHeight="600" Title="Source Git" - Width="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowWidth, Mode=TwoWay}" - Height="{Binding Source={x:Static source:App.Preference}, Path=UIMainWindowHeight, Mode=TwoWay}" - WindowStartupLocation="CenterOwner"> + Width="{Binding Source={x:Static source:App.Setting}, Path=UI.WindowWidth, Mode=TwoWay}" + Height="{Binding Source={x:Static source:App.Setting}, Path=UI.WindowHeight, Mode=TwoWay}" + WindowStartupLocation="CenterScreen"> diff --git a/src/UI/Launcher.xaml.cs b/src/UI/Launcher.xaml.cs index c13c1d12..6ca9fb8a 100644 --- a/src/UI/Launcher.xaml.cs +++ b/src/UI/Launcher.xaml.cs @@ -95,7 +95,7 @@ namespace SourceGit.UI { Tabs.Add(new ManagerTab()); InitializeComponent(); openedTabs.SelectedItem = Tabs[0]; - if (App.Preference.CheckUpdate) Task.Run(CheckUpdate); + if (App.Setting.CheckUpdate) Task.Run(CheckUpdate); } /// @@ -233,7 +233,7 @@ namespace SourceGit.UI { /// /// private void ShowPreference(object sender, RoutedEventArgs e) { - var dialog = new Preference(); + var dialog = new SettingDialog(); dialog.Owner = this; dialog.ShowDialog(); } diff --git a/src/UI/Manager.xaml.cs b/src/UI/Manager.xaml.cs index 6609410b..b9ce3513 100644 --- a/src/UI/Manager.xaml.cs +++ b/src/UI/Manager.xaml.cs @@ -130,7 +130,7 @@ namespace SourceGit.UI { var delete = new MenuItem(); delete.Header = "Delete"; delete.Click += (o, ev) => { - App.Preference.RemoveRepository(repo.Path); + App.Setting.RemoveRepository(repo.Path); UpdateRecentOpened(); UpdateTree(); HideBrief(); @@ -157,7 +157,7 @@ namespace SourceGit.UI { var addFolder = new MenuItem(); addFolder.Header = "Add Folder"; addFolder.Click += (o, ev) => { - var group = App.Preference.AddGroup("New Group", ""); + var group = App.Setting.AddGroup("New Group", ""); UpdateTree(group.Id); ev.Handled = true; }; @@ -195,7 +195,7 @@ namespace SourceGit.UI { foreach (var path in paths) { FileInfo info = new FileInfo(path); if (info.Attributes == FileAttributes.Directory && Git.Repository.IsValid(path)) { - App.Preference.AddRepository(path, group); + App.Setting.AddRepository(path, group); needRebuild = true; } } @@ -207,7 +207,7 @@ namespace SourceGit.UI { var group = ""; var to = (sender as TreeViewItem)?.DataContext as Node; if (to != null) group = to.IsRepo ? to.ParentId : to.Id; - App.Preference.FindRepository(node.Id).GroupId = group; + App.Setting.FindRepository(node.Id).GroupId = group; needRebuild = true; } @@ -222,7 +222,7 @@ namespace SourceGit.UI { var node = selectedTreeViewItem.DataContext as Node; if (node.IsRepo) { - ShowBrief(App.Preference.FindRepository(node.Id)); + ShowBrief(App.Setting.FindRepository(node.Id)); } else { HideBrief(); } @@ -254,7 +254,7 @@ namespace SourceGit.UI { var node = item.DataContext as Node; if (node != null && !node.IsRepo) { - var group = App.Preference.FindGroup(node.Id); + var group = App.Setting.FindGroup(node.Id); group.IsExpended = item.IsExpanded; e.Handled = true; } @@ -298,9 +298,9 @@ namespace SourceGit.UI { var node = text.DataContext as Node; if (node != null) { if (node.IsRepo) { - App.Preference.RenameRepository(node.Id, text.Text); + App.Setting.RenameRepository(node.Id, text.Text); } else { - App.Preference.RenameGroup(node.Id, text.Text); + App.Setting.RenameGroup(node.Id, text.Text); } UpdateRecentOpened(); @@ -345,7 +345,7 @@ namespace SourceGit.UI { var refIdx = i; mark.Click += (o, e) => { - var repo = App.Preference.FindRepository(node.Id); + var repo = App.Setting.FindRepository(node.Id); if (repo != null) { repo.Color = refIdx; UpdateRecentOpened(); @@ -364,10 +364,10 @@ namespace SourceGit.UI { var addSubFolder = new MenuItem(); addSubFolder.Header = "Add Sub-Folder"; addSubFolder.Click += (o, ev) => { - var parent = App.Preference.FindGroup(node.Id); + var parent = App.Setting.FindGroup(node.Id); if (parent != null) parent.IsExpended = true; - var group = App.Preference.AddGroup("New Group", node.Id); + var group = App.Setting.AddGroup("New Group", node.Id); UpdateTree(group.Id); ev.Handled = true; }; @@ -404,7 +404,7 @@ namespace SourceGit.UI { popupManager.Show(new Init(popupManager, repo.Path)); } else { App.RaiseError("Path is NOT valid git repository or has been removed."); - App.Preference.RemoveRepository(repo.Path); + App.Setting.RemoveRepository(repo.Path); UpdateRecentOpened(); UpdateTree(); } @@ -485,7 +485,7 @@ namespace SourceGit.UI { return; } - var repo = App.Preference.AddRepository(path, ""); + var repo = App.Setting.AddRepository(path, ""); App.Open(repo); } @@ -493,7 +493,7 @@ namespace SourceGit.UI { /// Update recent opened repositories. /// private void UpdateRecentOpened() { - var sorted = App.Preference.Repositories.OrderByDescending(a => a.LastOpenTime).ToList(); + var sorted = App.Setting.Repositories.OrderByDescending(a => a.LastOpenTime).ToList(); var top5 = new List(); for (int i = 0; i < sorted.Count && i < 5; i++) { @@ -512,7 +512,7 @@ namespace SourceGit.UI { var groupNodes = new Dictionary(); var nodes = new List(); - foreach (var group in App.Preference.Groups) { + foreach (var group in App.Setting.Groups) { Node node = new Node() { Id = group.Id, ParentId = group.ParentId, @@ -536,7 +536,7 @@ namespace SourceGit.UI { } } - foreach (var repo in App.Preference.Repositories) { + foreach (var repo in App.Setting.Repositories) { Node node = new Node() { Id = repo.Path, ParentId = repo.GroupId, @@ -563,10 +563,10 @@ namespace SourceGit.UI { /// private void DeleteNode(Node node) { if (node.IsRepo) { - App.Preference.RemoveRepository(node.Id); + App.Setting.RemoveRepository(node.Id); UpdateRecentOpened(); } else { - App.Preference.RemoveGroup(node.Id); + App.Setting.RemoveGroup(node.Id); } UpdateTree(); diff --git a/src/UI/Preference.xaml b/src/UI/SettingDialog.xaml similarity index 96% rename from src/UI/Preference.xaml rename to src/UI/SettingDialog.xaml index b8e65cca..e019b6df 100644 --- a/src/UI/Preference.xaml +++ b/src/UI/SettingDialog.xaml @@ -1,4 +1,4 @@ -