2020-07-03 00:24:31 -07:00
|
|
|
using Microsoft.Win32;
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
namespace SourceGit {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Application.
|
|
|
|
/// </summary>
|
|
|
|
public partial class App : Application {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Getter/Setter for Git preference.
|
|
|
|
/// </summary>
|
|
|
|
public static Git.Preference Preference {
|
|
|
|
get { return Git.Preference.Instance; }
|
|
|
|
set { Git.Preference.Instance = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check if GIT has been configured.
|
|
|
|
/// </summary>
|
|
|
|
public static bool IsGitConfigured {
|
|
|
|
get {
|
|
|
|
return !string.IsNullOrEmpty(Preference.GitExecutable)
|
|
|
|
&& File.Exists(Preference.GitExecutable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Error handler.
|
|
|
|
/// </summary>
|
|
|
|
public static Action<string> OnError {
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Raise error message.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="message"></param>
|
|
|
|
public static void RaiseError(string message) {
|
|
|
|
OnError?.Invoke(message);
|
|
|
|
}
|
|
|
|
|
2020-08-04 18:32:24 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Get popup manager by repository
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="repo"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static UI.PopupManager GetPopupManager(Git.Repository repo) {
|
|
|
|
var main = Current.MainWindow as UI.Launcher;
|
|
|
|
if (main == null) return null;
|
|
|
|
if (repo == null) return (main.Tabs[0].Page as UI.Manager).popupManager;
|
|
|
|
|
|
|
|
for (int i = 1; i < main.openedTabs.Items.Count; i++) {
|
|
|
|
var opened = main.openedTabs.Items[i] as UI.Launcher.Tab;
|
|
|
|
if (opened.Repo.Path == repo.Path) {
|
|
|
|
return (opened.Page as UI.Dashboard).popupManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-03 00:24:31 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Startup event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private void OnAppStartup(object sender, StartupEventArgs e) {
|
2020-07-22 23:04:42 -07:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-07-03 00:24:31 -07:00
|
|
|
// 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) {
|
|
|
|
Preference.GitExecutable = Path.Combine(
|
|
|
|
git.GetValue("InstallPath") as string,
|
|
|
|
"bin",
|
|
|
|
"git.exe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply themes
|
|
|
|
if (Preference.UIUseLightTheme) {
|
|
|
|
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
|
2020-08-04 18:32:24 -07:00
|
|
|
Current.MainWindow = new UI.Launcher();
|
|
|
|
Current.MainWindow.Show();
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deactivated event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private void OnAppDeactivated(object sender, EventArgs e) {
|
|
|
|
Git.Preference.Save();
|
2020-07-15 18:26:21 -07:00
|
|
|
GC.Collect();
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|