diff --git a/GitCommands/Settings/AppSettings.cs b/GitCommands/Settings/AppSettings.cs index c911784bd68..86758464f52 100644 --- a/GitCommands/Settings/AppSettings.cs +++ b/GitCommands/Settings/AppSettings.cs @@ -276,6 +276,67 @@ public static bool AlwaysShowAllCommands set => WriteBoolRegKey("AlwaysShowAllCommands", value); } + public static bool EnableExplorerIntegration + { + // TODO write getter - check if dll is registered + // get => ReadBoolRegKey("AlwaysShowAllCommands", false); + set => HandleShellIntegration(null, null, value); + } + + private static void HandleShellIntegration(object sender = null, EventArgs e = null, bool register = false) + { + const string GitExtensionsShellEx32Name = "GitExtensionsShellEx32.dll"; + const string GitExtensionsShellEx64Name = "GitExtensionsShellEx64.dll"; + string path = Path.Combine(AppSettings.GetInstallDir(), GitExtensionsShellEx32Name); + + if (!File.Exists(path)) + { + path = Assembly.GetExecutingAssembly().Location; + path = Path.GetDirectoryName(path); + path = Path.Combine(path, GitExtensionsShellEx32Name); + } + + if (File.Exists(path)) + { + try + { + var pi = new ProcessStartInfo + { + FileName = "regsvr32", + Arguments = $"{(!register ? "/u " : "")}" + path.Quote(), + Verb = "RunAs", + UseShellExecute = false, + + // TODO confirmation window is not suppressed + CreateNoWindow = true + }; + + // TODO is IntPtr really the correct way to check architecture here? + if (IntPtr.Size == 8) + { + path = path.Replace(GitExtensionsShellEx32Name, GitExtensionsShellEx64Name); + if (File.Exists(path)) + { + pi.Arguments = $"{(!register ? "/u" : "")}" + path.Quote(); + } + } + + var process = Process.Start(pi); + process.WaitForExit(); + } + catch (System.ComponentModel.Win32Exception) + { + // User cancel operation, continue; + } + } + else + { + // MessageBox.Show(this, string.Format(_cantRegisterShellExtension.Text, CommonLogic.GitExtensionsShellEx32Name), Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + // CheckSettings(); + } + public static bool ShowCurrentBranchInVisualStudio { // This setting MUST be set to false by default, otherwise it will not work in Visual Studio without diff --git a/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.Designer.cs b/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.Designer.cs index 787aff6839d..76073fe48de 100644 --- a/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.Designer.cs +++ b/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.Designer.cs @@ -37,6 +37,7 @@ private void InitializeComponent() this.tlpnlMain = new System.Windows.Forms.TableLayoutPanel(); this.gbShellExtensions = new System.Windows.Forms.GroupBox(); this.tlpnlCascadingMenu = new System.Windows.Forms.TableLayoutPanel(); + this.cbShellIntegration = new System.Windows.Forms.CheckBox(); panel1 = new System.Windows.Forms.Panel(); panel1.SuspendLayout(); this.tlpnlMain.SuspendLayout(); @@ -50,20 +51,20 @@ private void InitializeComponent() panel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; panel1.Controls.Add(this.labelPreview); panel1.Controls.Add(this.label1); - panel1.Location = new System.Drawing.Point(323, 77); panel1.Dock = System.Windows.Forms.DockStyle.Fill; - panel1.Margin = new System.Windows.Forms.Padding(2); + panel1.Location = new System.Drawing.Point(1025, 125); panel1.Name = "panel1"; - panel1.Padding = new System.Windows.Forms.Padding(3); - panel1.Size = new System.Drawing.Size(317, 291); + panel1.Padding = new System.Windows.Forms.Padding(4); + panel1.Size = new System.Drawing.Size(1016, 1054); panel1.TabIndex = 0; // // labelPreview // this.labelPreview.Dock = System.Windows.Forms.DockStyle.Fill; - this.labelPreview.Location = new System.Drawing.Point(0, 15); + this.labelPreview.Location = new System.Drawing.Point(4, 24); + this.labelPreview.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelPreview.Name = "labelPreview"; - this.labelPreview.Size = new System.Drawing.Size(317, 196); + this.labelPreview.Size = new System.Drawing.Size(1008, 1026); this.labelPreview.TabIndex = 1; this.labelPreview.Text = "..."; // @@ -71,9 +72,10 @@ private void InitializeComponent() // this.label1.AutoSize = true; this.label1.Dock = System.Windows.Forms.DockStyle.Top; - this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Location = new System.Drawing.Point(4, 4); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(129, 15); + this.label1.Size = new System.Drawing.Size(169, 20); this.label1.TabIndex = 0; this.label1.Text = "Context menu preview:"; // @@ -82,9 +84,10 @@ private void InitializeComponent() this.lblMenuEntries.AutoSize = true; this.tlpnlCascadingMenu.SetColumnSpan(this.lblMenuEntries, 2); this.lblMenuEntries.Dock = System.Windows.Forms.DockStyle.Fill; - this.lblMenuEntries.Location = new System.Drawing.Point(3, 45); + this.lblMenuEntries.Location = new System.Drawing.Point(4, 82); + this.lblMenuEntries.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblMenuEntries.Name = "lblMenuEntries"; - this.lblMenuEntries.Size = new System.Drawing.Size(636, 30); + this.lblMenuEntries.Size = new System.Drawing.Size(2036, 40); this.lblMenuEntries.TabIndex = 2; this.lblMenuEntries.Text = "Select items to be shown in the cascaded context menu.\r\n(Unchecked items will be " + "shown top level for direct access.)"; @@ -112,9 +115,10 @@ private void InitializeComponent() "Settings", "View stash", "View changes"}); - this.chlMenuEntries.Location = new System.Drawing.Point(3, 78); + this.chlMenuEntries.Location = new System.Drawing.Point(4, 126); + this.chlMenuEntries.Margin = new System.Windows.Forms.Padding(4); this.chlMenuEntries.Name = "chlMenuEntries"; - this.chlMenuEntries.Size = new System.Drawing.Size(315, 110); + this.chlMenuEntries.Size = new System.Drawing.Size(470, 142); this.chlMenuEntries.TabIndex = 3; this.chlMenuEntries.SelectedValueChanged += new System.EventHandler(this.chlMenuEntries_SelectedValueChanged); // @@ -123,9 +127,10 @@ private void InitializeComponent() this.cbAlwaysShowAllCommands.AutoSize = true; this.tlpnlCascadingMenu.SetColumnSpan(this.cbAlwaysShowAllCommands, 2); this.cbAlwaysShowAllCommands.Dock = System.Windows.Forms.DockStyle.Fill; - this.cbAlwaysShowAllCommands.Location = new System.Drawing.Point(3, 3); + this.cbAlwaysShowAllCommands.Location = new System.Drawing.Point(4, 43); + this.cbAlwaysShowAllCommands.Margin = new System.Windows.Forms.Padding(4); this.cbAlwaysShowAllCommands.Name = "cbAlwaysShowAllCommands"; - this.cbAlwaysShowAllCommands.Size = new System.Drawing.Size(636, 19); + this.cbAlwaysShowAllCommands.Size = new System.Drawing.Size(2036, 24); this.cbAlwaysShowAllCommands.TabIndex = 1; this.cbAlwaysShowAllCommands.Text = "Always show all commands"; this.cbAlwaysShowAllCommands.UseVisualStyleBackColor = true; @@ -138,12 +143,13 @@ private void InitializeComponent() this.tlpnlMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tlpnlMain.Controls.Add(this.gbShellExtensions, 0, 0); this.tlpnlMain.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpnlMain.Location = new System.Drawing.Point(8, 8); + this.tlpnlMain.Location = new System.Drawing.Point(12, 12); + this.tlpnlMain.Margin = new System.Windows.Forms.Padding(4); this.tlpnlMain.Name = "tlpnlMain"; this.tlpnlMain.RowCount = 1; this.tlpnlMain.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpnlMain.Size = new System.Drawing.Size(664, 508); - this.tlpnlMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 508F)); + this.tlpnlMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 1233F)); + this.tlpnlMain.Size = new System.Drawing.Size(2076, 1233); this.tlpnlMain.TabIndex = 0; // // gbShellExtensions @@ -152,10 +158,11 @@ private void InitializeComponent() this.gbShellExtensions.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.gbShellExtensions.Controls.Add(this.tlpnlCascadingMenu); this.gbShellExtensions.Dock = System.Windows.Forms.DockStyle.Fill; - this.gbShellExtensions.Location = new System.Drawing.Point(3, 3); + this.gbShellExtensions.Location = new System.Drawing.Point(4, 4); + this.gbShellExtensions.Margin = new System.Windows.Forms.Padding(4); this.gbShellExtensions.Name = "gbShellExtensions"; - this.gbShellExtensions.Padding = new System.Windows.Forms.Padding(8); - this.gbShellExtensions.Size = new System.Drawing.Size(658, 502); + this.gbShellExtensions.Padding = new System.Windows.Forms.Padding(12); + this.gbShellExtensions.Size = new System.Drawing.Size(2068, 1225); this.gbShellExtensions.TabIndex = 0; this.gbShellExtensions.TabStop = false; this.gbShellExtensions.Text = "Cascaded Context Menu"; @@ -167,29 +174,46 @@ private void InitializeComponent() this.tlpnlCascadingMenu.ColumnCount = 2; this.tlpnlCascadingMenu.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tlpnlCascadingMenu.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tlpnlCascadingMenu.Controls.Add(this.cbAlwaysShowAllCommands, 0, 0); - this.tlpnlCascadingMenu.Controls.Add(this.lblMenuEntries, 0, 2); - this.tlpnlCascadingMenu.Controls.Add(this.chlMenuEntries, 0, 3); - this.tlpnlCascadingMenu.Controls.Add(panel1, 1, 3); + this.tlpnlCascadingMenu.Controls.Add(this.cbShellIntegration, 0, 0); + this.tlpnlCascadingMenu.Controls.Add(this.cbAlwaysShowAllCommands, 0, 1); + this.tlpnlCascadingMenu.Controls.Add(this.lblMenuEntries, 0, 3); + this.tlpnlCascadingMenu.Controls.Add(this.chlMenuEntries, 0, 4); + this.tlpnlCascadingMenu.Controls.Add(panel1, 1, 4); this.tlpnlCascadingMenu.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpnlCascadingMenu.Location = new System.Drawing.Point(8, 24); + this.tlpnlCascadingMenu.Location = new System.Drawing.Point(12, 31); + this.tlpnlCascadingMenu.Margin = new System.Windows.Forms.Padding(4); this.tlpnlCascadingMenu.Name = "tlpnlCascadingMenu"; - this.tlpnlCascadingMenu.RowCount = 4; + this.tlpnlCascadingMenu.RowCount = 5; + this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 39F)); this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 11F)); this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tlpnlCascadingMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpnlCascadingMenu.Size = new System.Drawing.Size(642, 470); + this.tlpnlCascadingMenu.Size = new System.Drawing.Size(2044, 1182); this.tlpnlCascadingMenu.TabIndex = 0; // + // cbShellIntegration + // + this.cbShellIntegration.AutoSize = true; + this.tlpnlCascadingMenu.SetColumnSpan(this.cbShellIntegration, 2); + this.cbShellIntegration.Dock = System.Windows.Forms.DockStyle.Fill; + this.cbShellIntegration.Location = new System.Drawing.Point(4, 4); + this.cbShellIntegration.Margin = new System.Windows.Forms.Padding(4); + this.cbShellIntegration.Name = "cbShellIntegration"; + this.cbShellIntegration.Size = new System.Drawing.Size(2036, 31); + this.cbShellIntegration.TabIndex = 4; + this.cbShellIntegration.Text = "Enable Windows Explorer Integration"; + this.cbShellIntegration.UseVisualStyleBackColor = true; + // // ShellExtensionSettingsPage // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.Controls.Add(this.tlpnlMain); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "ShellExtensionSettingsPage"; - this.Padding = new System.Windows.Forms.Padding(8); - this.Size = new System.Drawing.Size(680, 524); + this.Padding = new System.Windows.Forms.Padding(12); + this.Size = new System.Drawing.Size(2100, 1257); panel1.ResumeLayout(false); panel1.PerformLayout(); this.tlpnlMain.ResumeLayout(false); @@ -213,5 +237,6 @@ private void InitializeComponent() private System.Windows.Forms.TableLayoutPanel tlpnlCascadingMenu; private System.Windows.Forms.TableLayoutPanel tlpnlMain; private System.Windows.Forms.GroupBox gbShellExtensions; + private System.Windows.Forms.CheckBox cbShellIntegration; } } diff --git a/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.cs b/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.cs index 401ba3c652e..31e6c409361 100644 --- a/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.cs +++ b/GitUI/CommandsDialogs/SettingsDialog/Pages/ShellExtensionSettingsPage.cs @@ -46,6 +46,7 @@ protected override void PageToSettings() AppSettings.CascadeShellMenuItems = l_CascadeShellMenuItems; AppSettings.AlwaysShowAllCommands = cbAlwaysShowAllCommands.Checked; + AppSettings.EnableExplorerIntegration = cbShellIntegration.Checked; } private void chlMenuEntries_SelectedValueChanged(object sender, EventArgs e)