private static void onLaunchAnotherInstance(LaunchOptions options, LaunchContext context) { IntPtr mainWindow = context.GetWindowByCaption(Constants.MainWindowCaption, true); if (mainWindow != IntPtr.Zero) { if (context.Arguments.Length > 1) { string message = String.Join("|", context.Arguments); Win32Tools.SendMessageToWindow(mainWindow, message); } Win32Tools.ForceWindowIntoForeground(mainWindow); } else { // This may happen if a custom protocol link is quickly clicked more than once in a row Trace.TraceInformation(String.Format("Cannot find Main Window")); // bring to front any window IntPtr window = context.GetWindowByCaption(String.Empty, true); if (window != IntPtr.Zero) { Win32Tools.ForceWindowIntoForeground(window); } else { Trace.TraceInformation(String.Format("Cannot find application windows")); } } }
private void newDiscussionForm_Shown(object sender, EventArgs e) { Win32Tools.ForceWindowIntoForeground(this.Handle); textBoxDiscussionBody.Focus(); }
private static void onLaunchFromDiffTool(LaunchOptions launchOptions) { LaunchContext context = (launchOptions.SpecialOptions as LaunchOptions.DiffToolModeOptions).LaunchContext; if (context.IsRunningSingleInstance) { Trace.TraceWarning("Merge Request Helper is not running"); MessageBox.Show("Merge Request Helper is not running. Discussion cannot be created", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } IntPtr concurrentDiscussionWindow = context.GetWindowByCaption(Constants.StartNewThreadCaption, false); if (concurrentDiscussionWindow != IntPtr.Zero) { Trace.TraceWarning(String.Format("Found a concurrent {0} window", Constants.StartNewThreadCaption)); Win32Tools.ForceWindowIntoForeground(concurrentDiscussionWindow); return; } int parentToolPID = -1; try { string diffToolName = Path.GetFileNameWithoutExtension(createDiffTool().GetToolCommand()); StorageSupport.LocalCommitStorageType type = ConfigurationHelper.GetPreferredStorageType(Settings); string toolProcessName = type == StorageSupport.LocalCommitStorageType.FileStorage ? diffToolName : "git"; parentToolPID = getParentProcessId(context.CurrentProcess, toolProcessName); } catch (ArgumentException ex) { ExceptionHandlers.Handle("Cannot obtain diff tool file name", ex); } catch (Win32Exception ex) { ExceptionHandlers.Handle("Cannot find parent diff tool process", ex); } if (parentToolPID == -1) { Trace.TraceError("Cannot find parent diff tool process"); MessageBox.Show( "Cannot find parent diff tool process. Discussion cannot be created. Is Merge Request Helper running?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string[] argumentsEx = new string[context.Arguments.Length + 1]; Array.Copy(context.Arguments, 0, argumentsEx, 0, context.Arguments.Length); argumentsEx[argumentsEx.Length - 1] = parentToolPID.ToString(); string message = String.Join("|", argumentsEx.Skip(1)); // skip executable path IntPtr mainWindow = context.GetWindowByCaption(Constants.MainWindowCaption, true); if (mainWindow == IntPtr.Zero) { Debug.Assert(false); Trace.TraceWarning("Cannot find Main Window"); return; } Win32Tools.SendMessageToWindow(mainWindow, message); }