diff --git a/src/App.xaml.cs b/src/App.xaml.cs index 3243a7c9..15b8992c 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -35,69 +35,6 @@ namespace SourceGit { }); } - /// - /// Startup event. - /// - /// - /// - private void OnAppStartup(object sender, StartupEventArgs e) { - // Use this app as a sequence editor? - var args = e.Args; - if (args.Length > 1) { - if (args[0] == "--interactive-rebase") { - if (args.Length < 3) { - Environment.Exit(1); - return; - } - - File.WriteAllText(args[2], File.ReadAllText(args[1])); - } - - Environment.Exit(0); - 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( - RegistryHive.LocalMachine, - Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32); - - var git = root.OpenSubKey("SOFTWARE\\GitForWindows"); - if (git != null) { - Setting.Tools.GitExecutable = Path.Combine( - git.GetValue("InstallPath") as string, - "bin", - "git.exe"); - } - } - - // Apply themes - 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); - break; - } - } - } - - // Show main window - Current.MainWindow = new UI.Launcher(); - Current.MainWindow.Show(); - } - /// /// Open repository. /// @@ -122,6 +59,56 @@ namespace SourceGit { File.WriteAllText(settingFile, data); } + /// + /// Startup event. + /// + /// + /// + private void OnAppStartup(object sender, StartupEventArgs e) { + // Use this app as a sequence editor? + if (OpenAsEditor(e)) 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( + RegistryHive.LocalMachine, + Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32); + + var git = root.OpenSubKey("SOFTWARE\\GitForWindows"); + if (git != null) { + Setting.Tools.GitExecutable = Path.Combine( + git.GetValue("InstallPath") as string, + "bin", + "git.exe"); + } + } + + // Apply themes + 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); + break; + } + } + } + + // Show main window + Current.MainWindow = new UI.Launcher(); + Current.MainWindow.Show(); + } + /// /// Deactivated event. /// @@ -131,5 +118,29 @@ namespace SourceGit { GC.Collect(); SaveSetting(); } + + /// + /// Try to open app as git editor + /// + /// + /// + private bool OpenAsEditor(StartupEventArgs e) { + if (e.Args.Length < 3) return false; + + switch (e.Args[0]) { + case "--sequence": + var output = File.CreateText(e.Args[2]); + output.Write(File.ReadAllText(e.Args[1])); + output.Flush(); + output.Close(); + + Environment.Exit(0); + break; + default: + return false; + } + + return true; + } } } diff --git a/src/UI/InteractiveRebase.xaml b/src/UI/InteractiveRebase.xaml index 0d82a7cd..a516e489 100644 --- a/src/UI/InteractiveRebase.xaml +++ b/src/UI/InteractiveRebase.xaml @@ -139,40 +139,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -