internal void GenerateButtons(int processId = -1) { var thread = new Thread(() => { _eventManager = _eventManager ?? new EventManager(); _hoverLayer = _hoverLayer ?? (Bitmap)Resources.ResourceManager.GetObject("Hover_Layer"); var process = processId != -1 ? Process.GetProcessById(processId) : Process.GetProcessesByName("mspaint").FirstOrDefault(); if (process == null) { Console.WriteLine("Cannot find any Paint process" + (processId == -1 ? "." : " With the process ID of " + processId + ".")); return; } window = AutomationElement.FromHandle(process.MainWindowHandle); statusBar = window.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.StatusBar)); statusText = statusBar.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit))[4]; var unmanagedWindow = new NativeUnmanagedWindow(process.MainWindowHandle); var build = AddButton(process, unmanagedWindow, "Build"); build.MouseClick += (sender, args) => JavaInterface.RunCallback(CallbackType.Build); var run = AddButton(process, unmanagedWindow, "Run", tooltip: "Runs the current file"); run.MouseClick += (sender, args) => JavaInterface.RunCallback(CallbackType.Run); var stop = AddButton(process, unmanagedWindow, "Stop", tooltip: "Stops the execution of the current program"); stop.MouseClick += (sender, args) => JavaInterface.RunCallback(CallbackType.Stop); AddButton(process, unmanagedWindow, "Spacer", space: true); var commit = AddButton(process, unmanagedWindow, "Commit", tooltip: "Commits all files in the project"); commit.MouseClick += (sender, args) => JavaInterface.RunCallback(CallbackType.Commit); var push = AddButton(process, unmanagedWindow, "Push", tooltip: "Pushes all files in the project"); push.MouseClick += (sender, args) => JavaInterface.RunCallback(CallbackType.Push); var pull = AddButton(process, unmanagedWindow, "Pull", tooltip: "Updates the project from git"); pull.MouseClick += (sender, args) => { MessageBox.Show("This feature is not currently supported, but stay tuned for updates!", "Unsupported Operation", MessageBoxButtons.OK, MessageBoxIcon.Warning); }; _textHoster = AddText(process); Application.Run(new ApplicationContext()); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
internal void GenerateButtons() { var thread = new Thread(() => { _eventManager = new EventManager(); _hoverLayer = (Bitmap)Resources.ResourceManager.GetObject("Hover_Layer"); var process = Process.GetProcessesByName("mspaint").FirstOrDefault(); if (process == null) { Console.WriteLine("Cannot find any Paint process."); return; } window = AutomationElement.FromHandle(process.MainWindowHandle); statusBar = window.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.StatusBar)); statusText = statusBar.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit))[4]; var build = AddButton(process, "Build"); build.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Build); var run = AddButton(process, "Run", tooltip: "Runs the current file"); run.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Run); var stop = AddButton(process, "Stop", tooltip: "Stops the execution of the current program"); stop.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Stop); AddButton(process, "Spacer", space: true); var commit = AddButton(process, "Commit", tooltip: "Commits all files in the project"); commit.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Commit); var push = AddButton(process, "Push", tooltip: "Pushes all files in the project"); push.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Push); var pull = AddButton(process, "Pull", tooltip: "Updates the project from git"); pull.Click += (sender, args) => JavaInterface.RunCallback(CallbackType.Pull); _textHoster = AddText(process); WaitForEverything(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }