Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PluginManager setting #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions src/GitExtensions.PluginManager/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
using ResourceManager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GitExtensions.PluginManager
{
Expand Down Expand Up @@ -57,6 +52,7 @@ public override bool Execute(GitUIEventArgs gitUiCommands)
args.Monikers = FrameworkMonikers;
args.SelfPackageId = PackageId;
args.ProcessNamesToKillBeforeChange = new[] { Process.GetCurrentProcess().ProcessName };
args.CloseInstancesWithConfirmation = !Configuration.CloseInstances;

ProcessStartInfo info = new ProcessStartInfo()
{
Expand All @@ -66,30 +62,7 @@ public override bool Execute(GitUIEventArgs gitUiCommands)
};
Process.Start(info);

if (Configuration.CloseInstances)
{
CloseAllOtherInstances();
Application.Exit();
}

return false;
}

private void CloseAllOtherInstances()
{
Process current = Process.GetCurrentProcess();
foreach (Process other in Process.GetProcesses())
{
try
{
if (other.MainModule.FileName == current.MainModule.FileName && other.Id != current.Id)
other.Kill();
}
catch (Win32Exception)
{
continue;
}
}
}
}
}
5 changes: 1 addition & 4 deletions src/GitExtensions.PluginManager/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GitExtensions.PluginManager
{
Expand All @@ -13,7 +10,7 @@ internal class PluginSettings : IEnumerable<ISetting>
/// <summary>
/// Gets a property holding if asking to close git extensions is required.
/// </summary>
public static BoolSetting CloseInstancesProperty { get; } = new BoolSetting("CloseInstances", "Close all instances of Git Extensions before starting Plugin Manager", false);
public static BoolSetting CloseInstancesProperty { get; } = new BoolSetting("CloseInstances", "Automatically close Git Extensions when installing plugins", false);

private readonly ISettingsSource source;

Expand Down
2 changes: 1 addition & 1 deletion src/PackageManager.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override void OnStartup(StartupEventArgs e)
NuGetPackageVersionComparer.Instance
);

var wnd = new MainWindow(viewModel, ProcessService, Navigator);
var wnd = new MainWindow(viewModel, ProcessService, Navigator, Args.CloseInstancesWithConfirmation);

wnd.Show();

Expand Down
21 changes: 19 additions & 2 deletions src/PackageManager.UI/Args.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PackageManager
{
public partial class Args : ICloneable<Args>
{
private const string CloseConfirmationArgument = "--close-confirmation";

public string Path { get; set; }
public IReadOnlyCollection<string> Monikers { get; set; }
public IReadOnlyCollection<Dependency> Dependencies { get; set; }
Expand All @@ -20,6 +21,7 @@ public partial class Args : ICloneable<Args>
public string Tags { get; set; }

public IReadOnlyCollection<string> ProcessNamesToKillBeforeChange { get; set; }
public bool CloseInstancesWithConfirmation { get; set; }

public Args()
{
Expand Down Expand Up @@ -48,6 +50,12 @@ private void ParseParameters(string[] args)
IsSelfUpdate = true;
items.Remove(arg);
}

if (arg == CloseConfirmationArgument)
{
CloseInstancesWithConfirmation = true;
items.Remove(arg);
}
}

args = items.ToArray();
Expand Down Expand Up @@ -90,6 +98,9 @@ private bool ParseParameter(string name, string value)
case "--processnamestokillbeforechange":
ProcessNamesToKillBeforeChange = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return true;
case CloseConfirmationArgument:
CloseInstancesWithConfirmation = true;
return true;
default:
return false;
}
Expand Down Expand Up @@ -153,6 +164,11 @@ public override string ToString()
if (ProcessNamesToKillBeforeChange != null && ProcessNamesToKillBeforeChange.Count > 0)
result.Append($" --processnamestokillbeforechange \"{string.Join(",", ProcessNamesToKillBeforeChange)}\"");

if (CloseInstancesWithConfirmation)
{
result.Append($" {CloseConfirmationArgument}");
}

return result.ToString();
}

Expand All @@ -167,7 +183,8 @@ public Args Clone()
IsSelfUpdate = IsSelfUpdate,
SelfOriginalPath = SelfOriginalPath,
SelfUpdateVersion = SelfUpdateVersion,
ProcessNamesToKillBeforeChange = ProcessNamesToKillBeforeChange
ProcessNamesToKillBeforeChange = ProcessNamesToKillBeforeChange,
CloseInstancesWithConfirmation = CloseInstancesWithConfirmation
};
}

Expand Down
40 changes: 22 additions & 18 deletions src/PackageManager.UI/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,29 @@
using PackageManager.Services;
using PackageManager.ViewModels;
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.Navigation;
using System.Windows.Shapes;

namespace PackageManager.Views
{
public partial class MainWindow : Window
{
private readonly ProcessService processes;
private readonly Navigator navigator;
private readonly bool closeWithConfirmation;

public MainViewModel ViewModel
=> (MainViewModel)DataContext;

internal MainWindow(MainViewModel viewModel, ProcessService processes, Navigator navigator)
internal MainWindow(MainViewModel viewModel, ProcessService processes, Navigator navigator, bool closeWithConfirmation)
{
Ensure.NotNull(viewModel, "viewModel");
Ensure.NotNull(processes, "processes");
Ensure.NotNull(navigator, "navigator");
DataContext = viewModel;
this.processes = processes;
this.navigator = navigator;
this.closeWithConfirmation = closeWithConfirmation;
InitializeViewModel();

InitializeComponent();
Expand All @@ -51,14 +42,27 @@ private Task<bool> OnBeforeChange()
var context = processes.PrepareContextForProcessesKillBeforeChange();
if (context.IsExecutable)
{
bool result = navigator.Confirm(
"Plugin Manager",
"Plugin Manager is going to write to files that are holded by other executables. " + Environment.NewLine +
"Do you want to kill all instances of these applications?"
);
if (this.closeWithConfirmation)
{
bool result = navigator.Confirm(
"Plugin Manager",
"Plugin Manager is going to write to files that are holded by other executables. " + Environment.NewLine +
"Do you want to kill all instances of these applications?"
);

if (result)
if (result)
{
context.Execute();
}
else
{
return Task.FromResult(false);
}
}
else
{
context.Execute();
}
}

return Task.FromResult(true);
Expand Down