コード例 #1
0
        public IntPtr GetWindowByCaption(string caption, bool startsWith)
        {
            foreach (Process process in AllProcesses)
            {
                IEnumerable <IntPtr> handles;
                try
                {
                    handles = Win32Tools.EnumerateProcessWindowHandles(process.Id);
                }
                catch (ArgumentException)
                {
                    continue;
                }
                catch (InvalidOperationException)
                {
                    continue;
                }

                StringBuilder strbTitle = new StringBuilder(255);
                foreach (IntPtr window in handles)
                {
                    NativeMethods.GetWindowText(window, strbTitle, strbTitle.Capacity + 1);
                    string strTitle = strbTitle.ToString();
                    if ((startsWith && strTitle.StartsWith(caption)) || (!startsWith && strTitle == caption))
                    {
                        return(window);
                    }
                }
            }

            return(IntPtr.Zero);
        }
コード例 #2
0
        private void setGroupCollapsing(ProjectKey projectKey, bool collapse)
        {
            bool isCollapsed = _collapsedProjects.Contains(projectKey);

            if (isCollapsed == collapse)
            {
                return;
            }

            if (collapse)
            {
                _collapsedProjects.Add(projectKey);
            }
            else
            {
                _collapsedProjects.Remove(projectKey);
            }

            NativeMethods.LockWindowUpdate(Handle);
            int vScrollPosition = Win32Tools.GetVerticalScrollPosition(Handle);

            ContentChanged?.Invoke(this);
            Win32Tools.SetVerticalScrollPosition(Handle, vScrollPosition);
            NativeMethods.LockWindowUpdate(IntPtr.Zero);
        }
コード例 #3
0
        // Other

        protected override void WndProc(ref Message rMessage)
        {
            if (rMessage.Msg == NativeMethods.WM_COPYDATA)
            {
                string argumentString = Win32Tools.ConvertMessageToText(rMessage.LParam);
                if (String.IsNullOrEmpty(argumentString))
                {
                    Debug.Assert(false);
                    Trace.TraceError(String.Format("Invalid WM_COPYDATA message content: {0}", argumentString));
                    return;
                }

                string[] arguments = argumentString.Split('|');
                if (arguments[0] == "show")
                {
                    onRestoreFromTray();
                }
                else if (arguments[0] == "diff")
                {
                    onDiffCommand(argumentString);
                }
                else if (App.Helpers.UrlHelper.Parse(arguments[0]) != null)
                {
                    onOpenCommand(arguments[0]);
                }
            }

            base.WndProc(ref rMessage);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: BartWeyder/mrHelper
        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"));
                }
            }
        }
コード例 #5
0
        private static void onLaunchAnotherInstance(LaunchContext context)
        {
            IntPtr mainWindow = context.GetWindowByCaption(Constants.MainWindowCaption, true);

            if (mainWindow != IntPtr.Zero)
            {
                if (context.Arguments.Length > 1)
                {
                    string message = String.Join("|", context.Arguments.Skip(1)); // skip executable path
                    Win32Tools.SendMessageToWindow(mainWindow, message);
                }
                Win32Tools.SendMessageToWindow(mainWindow, "show");
            }
            else
            {
                // This may happen if a custom protocol link is quickly clicked more than once in a row.
                // In the scope of #453 decided that it is simpler to not handle this case at all.
            }
        }
コード例 #6
0
 private void newDiscussionForm_Shown(object sender, EventArgs e)
 {
     Win32Tools.ForceWindowIntoForeground(this.Handle);
     textBoxDiscussionBody.Focus();
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        // General

        /// <summary>
        /// All exceptions thrown within this method are fatal errors, just pass them to upper level handler
        /// </summary>
        private void mainForm_Load(object sender, EventArgs e)
        {
            Win32Tools.EnableCopyDataMessageHandling(this.Handle);
            initializeWork();
        }