From 7b2011d5596252424fb8487472066e541ec9d615 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 5 Oct 2016 13:43:55 +0200 Subject: [PATCH 01/10] Add ConsolePanel --- .../ConsolePanel/ConsoleControl.Designer.cs | 47 +++ .../Plugins/ConsolePanel/ConsoleControl.cs | 322 ++++++++++++++++++ .../Plugins/ConsolePanel/ConsolePanel.csproj | 101 ++++++ .../Gui/TabbedConsole.Designer.cs | 87 +++++ .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 79 +++++ .../ConsolePanel/Gui/TabbedConsole.resx | 120 +++++++ .../ConsolePanel/Managers/ConsoleManager.cs | 42 +++ External/Plugins/ConsolePanel/PluginMain.cs | 202 +++++++++++ .../ConsolePanel/Properties/AssemblyInfo.cs | 36 ++ .../Properties/Resources.Designer.cs | 63 ++++ .../ConsolePanel/Properties/Resources.resx | 101 ++++++ External/Plugins/ConsolePanel/Settings.cs | 38 +++ External/Plugins/ConsolePanel/WinApi.cs | 87 +++++ FlashDevelop.sln | 16 +- 14 files changed, 1340 insertions(+), 1 deletion(-) create mode 100644 External/Plugins/ConsolePanel/ConsoleControl.Designer.cs create mode 100644 External/Plugins/ConsolePanel/ConsoleControl.cs create mode 100644 External/Plugins/ConsolePanel/ConsolePanel.csproj create mode 100644 External/Plugins/ConsolePanel/Gui/TabbedConsole.Designer.cs create mode 100644 External/Plugins/ConsolePanel/Gui/TabbedConsole.cs create mode 100644 External/Plugins/ConsolePanel/Gui/TabbedConsole.resx create mode 100644 External/Plugins/ConsolePanel/Managers/ConsoleManager.cs create mode 100644 External/Plugins/ConsolePanel/PluginMain.cs create mode 100644 External/Plugins/ConsolePanel/Properties/AssemblyInfo.cs create mode 100644 External/Plugins/ConsolePanel/Properties/Resources.Designer.cs create mode 100644 External/Plugins/ConsolePanel/Properties/Resources.resx create mode 100644 External/Plugins/ConsolePanel/Settings.cs create mode 100644 External/Plugins/ConsolePanel/WinApi.cs diff --git a/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs b/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs new file mode 100644 index 0000000000..6942d51967 --- /dev/null +++ b/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs @@ -0,0 +1,47 @@ +namespace ConsoleControl +{ + partial class ConsoleControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pnlClipping = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // pnlClipping + // + this.pnlClipping.Location = new System.Drawing.Point(0, 0); + this.pnlClipping.Name = "pnlClipping"; + this.pnlClipping.Size = new System.Drawing.Size(128, 103); + this.pnlClipping.TabIndex = 0; + this.pnlClipping.Enter += new System.EventHandler(this.CmdPanel_Enter); + // + // ConsoleControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.pnlClipping); + this.ForeColor = System.Drawing.Color.White; + this.Name = "ConsoleControl"; + this.Size = new System.Drawing.Size(246, 149); + this.Enter += new System.EventHandler(this.CmdPanel_Enter); + this.Resize += new System.EventHandler(this.CmdPanel_Resize); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel pnlClipping; + } +} diff --git a/External/Plugins/ConsolePanel/ConsoleControl.cs b/External/Plugins/ConsolePanel/ConsoleControl.cs new file mode 100644 index 0000000000..1ae3a5dc28 --- /dev/null +++ b/External/Plugins/ConsolePanel/ConsoleControl.cs @@ -0,0 +1,322 @@ +using System; +using System.Windows.Forms; +using System.Diagnostics; +using System.Drawing; +using System.Collections.Generic; +using System.Windows.Automation; + +namespace ConsoleControl +{ + public partial class ConsoleControl : UserControl + { + Process process; + IntPtr cmdHandle; + AutomationElement window; + Size realSize; + + ConsoleColor backColor = ConsoleColor.Black; + ConsoleColor foreColor = ConsoleColor.White; + List commandsToDo = new List(); + string lastWorkingDir; + string cmd; + + public event EventHandler Exited; + + public string WorkingDirectory + { + set + { + lastWorkingDir = value; + + if (process == null) + { + Create(); + } + else + { + SendString("cd \"" + value + "\""); + SendString("cls"); + } + } + } + + public ConsoleColor ConsoleBackColor + { + get + { + return backColor; + } + set + { + if (backColor == value) + return; + + backColor = value; + + var trimmedFore = foreColor.ToString("X").TrimStart('0'); + var trimmedBack = backColor.ToString("X").TrimStart('0'); + if (trimmedFore == "") + trimmedFore = "0"; + if (trimmedBack == "") + trimmedBack = "0"; + + SendString("color " + trimmedBack + trimmedFore); + SendString("cls"); + } + } + + public ConsoleColor ConsoleForeColor + { + get + { + return foreColor; + } + set + { + if (foreColor == value) + return; + + foreColor = value; + + var trimmedFore = foreColor.ToString("X").TrimStart('0'); + var trimmedBack = backColor.ToString("X").TrimStart('0'); + if (trimmedFore == "") + trimmedFore = "0"; + if (trimmedBack == "") + trimmedBack = "0"; + + SendString("color " + trimmedBack + trimmedFore); + SendString("cls"); + } + } + + /// + /// Returns the actual size of the console window's client area + /// (the width of a console window only changes by specific values) + /// + public Size ActualSize + { + get + { + return realSize; + } + } + + public Process Process + { + get + { + return process; + } + } + + /// + /// Creates a new ConsoleControl + /// + /// + /// + public ConsoleControl(string command, bool init = true, string workingDirectory = null) + { + InitializeComponent(); + SetStyle(ControlStyles.Selectable, true); + + lastWorkingDir = workingDirectory; + cmd = command; + + if (init) + Create(); + } + + /// + /// Cancel the currently running process + /// + public void Cancel() + { + if (process != null) + { + if (!process.HasExited) + { + SendString("^(c)", false); + process.Kill(); + } + + process = null; + } + } + + /// + /// Creates the console window if it was closed / not created yet + /// + public void Create() + { + if (process != null && !process.HasExited) + { + return; + } + + try + { + process = new Process(); + + process.StartInfo.FileName = cmd; + + if (lastWorkingDir != null) + process.StartInfo.WorkingDirectory = lastWorkingDir; + process.StartInfo.UseShellExecute = false; + + process.EnableRaisingEvents = true; + process.Exited += Process_Exited; + + process.Start(); + + //Wait for cmd window + while (process.MainWindowHandle == IntPtr.Zero) + { + process.Refresh(); + } + cmdHandle = process.MainWindowHandle; + window = System.Windows.Automation.AutomationElement.FromHandle(cmdHandle); + WinApi.SetParent(cmdHandle, pnlClipping.Handle); + + SendString("cls"); + ResizeConsole(); + } + catch + { + } + } + + /// + /// Sends a String to the embedded console window + /// + /// The string to send + /// if true, a "\r" is appended to the given string + public void SendString(string str, bool execute = true) + { + if (execute) + str += "\r"; + ProcessCommandCache(); + try + { + RunCommandWithoutCache(str); + } + catch + { + commandsToDo.Add(str); + } + } + + private void ProcessCommandCache() + { + while (commandsToDo.Count > 0) + { + var toDo = commandsToDo[0]; + + try + { + RunCommandWithoutCache(toDo); + commandsToDo.RemoveAt(0); + } + catch + { + break; + } + } + } + + private void RunCommandWithoutCache(string cmd) + { + window.SetFocus(); + //TODO: prevent user from clicking around while doing this + SendKeys.SendWait(cmd); + + Focus(); + } + + private void ResizeConsole() + { + WinApi.ShowWindow(cmdHandle, WinApi.SW_SHOWMAXIMIZED); + + WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(new Point(0, 0), Size)); + + SetRealConsoleSize(); + + var tooWide = realSize.Width > Width; + var tooHigh = realSize.Height > Height; + if (tooWide || tooHigh) + { + int newWidth = realSize.Width; + int newHeight = realSize.Height; + if (tooWide) + { + newWidth -= 8; + } + if (tooHigh) + { + newHeight -= 12; + } + + WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(0, 0, newWidth, newHeight)); + SetRealConsoleSize(); + } + + pnlClipping.Size = realSize; + } + + private void SetRealConsoleSize() + { + WINDOWINFO info; + WinApi.GetWindowInfo(cmdHandle, out info); + + var leftBorder = info.rcClient.Left - info.rcWindow.Left; + var topBorder = info.rcClient.Top - info.rcWindow.Top; + var rightBorder = (int)info.cxWindowBorders; + var bottomBorder = (int)info.cyWindowBorders; + + var width = info.rcWindow.Right - info.rcWindow.Left; + var height = info.rcWindow.Bottom - info.rcWindow.Top; + + realSize.Width = width - leftBorder - rightBorder; + realSize.Height = height - topBorder - bottomBorder; + } + + private void CmdPanel_Resize(object sender, EventArgs e) + { + ResizeConsole(); + } + + private void Process_Exited(object sender, EventArgs e) + { + cmdHandle = IntPtr.Zero; + if (Exited != null) + Exited(sender, e); + } + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + + Cancel(); + + base.Dispose(disposing); + } + + private void CmdPanel_Enter(object sender, EventArgs e) + { + try + { + window.SetFocus(); + } + catch { } + + ProcessCommandCache(); + } + } +} diff --git a/External/Plugins/ConsolePanel/ConsolePanel.csproj b/External/Plugins/ConsolePanel/ConsolePanel.csproj new file mode 100644 index 0000000000..914f68c617 --- /dev/null +++ b/External/Plugins/ConsolePanel/ConsolePanel.csproj @@ -0,0 +1,101 @@ + + + + + Debug + AnyCPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA} + Library + Properties + ConsolePanel + ConsolePanel + v3.5 + 512 + + + + true + full + false + ..\..\..\FlashDevelop\Bin\Debug\Plugins\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\FlashDevelop\Bin\Debug\Plugins\ + TRACE + prompt + 4 + AnyCPU + + + + + + + + + + UserControl + + + ConsoleControl.cs + + + UserControl + + + TabbedConsole.cs + + + + + + True + True + Resources.resx + + + + + + + {61885f70-b4dc-4b44-852d-5d6d03f2a734} + PluginCore + False + + + {78101c01-e186-4954-b1dd-debb7905fad8} + ProjectManager + False + + + + + TabbedConsole.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + + + + + + + \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.Designer.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.Designer.cs new file mode 100644 index 0000000000..c88c91519a --- /dev/null +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.Designer.cs @@ -0,0 +1,87 @@ +namespace ConsolePanel.Gui +{ + partial class TabbedConsole + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tabConsoles = new System.Windows.Forms.TabControl(); + this.btnNew = new System.Windows.Forms.Button(); + this.pnlContainer = new System.Windows.Forms.Panel(); + this.pnlContainer.SuspendLayout(); + this.SuspendLayout(); + // + // tabConsoles + // + this.tabConsoles.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabConsoles.Location = new System.Drawing.Point(0, 0); + this.tabConsoles.Name = "tabConsoles"; + this.tabConsoles.SelectedIndex = 0; + this.tabConsoles.Size = new System.Drawing.Size(398, 199); + this.tabConsoles.TabIndex = 0; + this.tabConsoles.MouseClick += new System.Windows.Forms.MouseEventHandler(this.tabConsoles_MouseClick); + // + // btnNew + // + this.btnNew.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnNew.FlatAppearance.BorderSize = 0; + this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnNew.Location = new System.Drawing.Point(379, 3); + this.btnNew.Name = "btnNew"; + this.btnNew.Size = new System.Drawing.Size(16, 16); + this.btnNew.TabIndex = 0; + this.btnNew.UseVisualStyleBackColor = false; + this.btnNew.Click += new System.EventHandler(this.btnNew_Click); + // + // pnlContainer + // + this.pnlContainer.Controls.Add(this.btnNew); + this.pnlContainer.Controls.Add(this.tabConsoles); + this.pnlContainer.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlContainer.Location = new System.Drawing.Point(0, 0); + this.pnlContainer.Name = "pnlContainer"; + this.pnlContainer.Size = new System.Drawing.Size(398, 199); + this.pnlContainer.TabIndex = 1; + // + // TabbedConsole + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.pnlContainer); + this.Name = "TabbedConsole"; + this.Size = new System.Drawing.Size(398, 199); + this.pnlContainer.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabConsoles; + private System.Windows.Forms.Button btnNew; + private System.Windows.Forms.Panel pnlContainer; + } +} diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs new file mode 100644 index 0000000000..3142e3eb8a --- /dev/null +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace ConsolePanel.Gui +{ + public partial class TabbedConsole : UserControl + { + //private List consoles; + private PluginMain main; + + public ICollection Consoles + { + get + { + return consoleTabMap.Keys; + } + } + + public Dictionary consoleTabMap; + public Dictionary tabConsoleMap; + + public TabbedConsole(PluginMain plugin) + { + InitializeComponent(); + + main = plugin; + consoleTabMap = new Dictionary(); + tabConsoleMap = new Dictionary(); + + btnNew.Image = PluginCore.PluginBase.MainForm.FindImage16("33"); + } + + public void AddConsole(ConsoleControl.ConsoleControl console) + { + var tabPage = new TabPage("Console"); + console.Dock = DockStyle.Fill; + tabPage.Controls.Add(console); + + tabConsoles.TabPages.Add(tabPage); + tabConsoles.SelectTab(tabPage); + consoleTabMap.Add(console, tabConsoles.SelectedTab); + tabConsoleMap.Add(tabConsoles.SelectedTab, console); + } + + public void RemoveConsole(ConsoleControl.ConsoleControl console) + { + if (consoleTabMap.ContainsKey(console)) + { + console.Cancel(); + + var page = consoleTabMap[console]; + tabConsoles.TabPages.Remove(page); + consoleTabMap.Remove(console); + tabConsoleMap.Remove(page); + } + } + + private void tabConsoles_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Middle) + { + for (int i = 0; i < tabConsoles.TabCount; i++) + { + if (tabConsoles.GetTabRect(i).Contains(e.Location)) + { + RemoveConsole(tabConsoleMap[tabConsoles.TabPages[i]]); + } + } + + } + } + + private void btnNew_Click(object sender, EventArgs e) + { + main.CreateConsolePanel(); + } + } +} diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.resx b/External/Plugins/ConsolePanel/Gui/TabbedConsole.resx new file mode 100644 index 0000000000..7080a7d118 --- /dev/null +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs new file mode 100644 index 0000000000..b464373db6 --- /dev/null +++ b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ConsolePanel.Managers +{ + public delegate void OnExited(); + + public class ConsoleManager + { + static PluginMain main; + + static List commandList = new List(); + + /// + /// Runs a command in a new console window. + /// + /// the command to run, uses standard cmd input syntax + public static void RunCommand(string command) + { + if (main != null) + { + while(commandList.Count > 0) + { + main.CreateConsolePanel().SendString(commandList[0]); + commandList.RemoveAt(0); + } + main.CreateConsolePanel().SendString(command); + } + else + { + commandList.Add(command); + } + } + + public static void Init(PluginMain plugin) + { + main = plugin; + } + } +} diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs new file mode 100644 index 0000000000..8428b76c13 --- /dev/null +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -0,0 +1,202 @@ + +using System; +using PluginCore; +using System.ComponentModel; +using PluginCore.Managers; +using PluginCore.Utilities; +using System.IO; +using PluginCore.Helpers; +using System.Windows.Forms; +using WeifenLuo.WinFormsUI.Docking; +using System.Drawing; +using ProjectManager.Projects; + +namespace ConsolePanel +{ + public class PluginMain : IPlugin + { + private string pluginName = "ConsolePanel"; + private string pluginGuid = "AEDE556E-54C3-4EFB-8EF3-54E85DC37D1E"; + private string pluginHelp = "http://hexmachina.org/"; + private string pluginDesc = "Plugin that adds an embedded console window to FlashDevelop."; + private string pluginAuth = "Christoph Otter"; + private string settingFilename; + private Settings settingObject; + private DockContent cmdPanelDockContent; + private Gui.TabbedConsole tabView; + private Image image; + + public int Api + { + get + { + return 1; + } + } + + public string Author + { + get + { + return pluginAuth; + } + } + + public string Description + { + get + { + return pluginDesc; + } + } + + public string Guid + { + get + { + return pluginGuid; + } + } + + public string Help + { + get + { + return pluginHelp; + } + } + + public string Name + { + get + { + return pluginName; + } + } + + [Browsable(false)] + public object Settings + { + get + { + return settingObject; + } + } + + public void Initialize() + { + InitBasics(); + LoadSettings(); + CreatePluginPanel(); + CreateConsolePanel(); + CreateMenuItem(); + + EventManager.AddEventHandler(this, EventType.Command, HandlingPriority.Normal); + } + + public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) + { + switch (e.Type) + { + case EventType.Command: + var data = (DataEvent)e; + if (data.Action == "ProjectManager.Project") + { + var project = (Project) data.Data; + foreach (var panel in tabView.Consoles) + { + panel.WorkingDirectory = PluginBase.CurrentProject.GetAbsolutePath(""); + } + } + break; + } + } + + public void Dispose() + { + SaveSettings(); + } + + private void InitBasics() + { + string dataPath = Path.Combine(PathHelper.DataDir, pluginName); + if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); + this.settingFilename = Path.Combine(dataPath, "Settings.fdb"); + + image = PluginBase.MainForm.FindImage("57"); + + Managers.ConsoleManager.Init(this); + } + + private void LoadSettings() + { + this.settingObject = new Settings(); + if (!File.Exists(this.settingFilename)) this.SaveSettings(); + else + { + Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject); + this.settingObject = (Settings)obj; + } + } + + private void SaveSettings() + { + ObjectSerializer.Serialize(this.settingFilename, this.settingObject); + } + + private void CreatePluginPanel() + { + tabView = new Gui.TabbedConsole(this); + cmdPanelDockContent = PluginBase.MainForm.CreateDockablePanel(tabView, pluginGuid, image, DockState.DockBottom); + cmdPanelDockContent.Text = "Console"; + } + + public ConsoleControl.ConsoleControl CreateConsolePanel() + { + cmdPanelDockContent.Show(); + + var cmdPanel = new ConsoleControl.ConsoleControl("cmd", false); + cmdPanel.Text = "Console"; + cmdPanel.ConsoleBackColor = settingObject.BackgroundColor; + cmdPanel.ConsoleForeColor = settingObject.ForegroundColor; + + cmdPanel.Exited += delegate + { + if (tabView.InvokeRequired) + { + tabView.Invoke((MethodInvoker)delegate + { + if (!PluginBase.MainForm.ClosingEntirely) + tabView.RemoveConsole(cmdPanel); + }); + } + else + { + if (!PluginBase.MainForm.ClosingEntirely) + tabView.RemoveConsole(cmdPanel); + } + }; + + cmdPanel.Create(); + + tabView.AddConsole(cmdPanel); + + return cmdPanel; + } + + private void CreateMenuItem() + { + string label = "Embedded Console"; + ToolStripMenuItem viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); + ToolStripMenuItem cmdItem = new ToolStripMenuItem(label, image, OpenCmdPanel); + + viewMenu.DropDownItems.Add(cmdItem); + } + + private void OpenCmdPanel(object sender, EventArgs e) + { + CreateConsolePanel(); + //cmdPanelDockContent.Show(); + } + } +} diff --git a/External/Plugins/ConsolePanel/Properties/AssemblyInfo.cs b/External/Plugins/ConsolePanel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..5a3fb3d221 --- /dev/null +++ b/External/Plugins/ConsolePanel/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EmbeddedCmd")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EmbeddedCmd")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("AEDE556E-54C3-4EFB-8EF3-54E85DC37D1E")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/External/Plugins/ConsolePanel/Properties/Resources.Designer.cs b/External/Plugins/ConsolePanel/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..e0c93530ef --- /dev/null +++ b/External/Plugins/ConsolePanel/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ConsolePanel.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConsolePanel.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/External/Plugins/ConsolePanel/Properties/Resources.resx b/External/Plugins/ConsolePanel/Properties/Resources.resx new file mode 100644 index 0000000000..4fdb1b6aff --- /dev/null +++ b/External/Plugins/ConsolePanel/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Settings.cs b/External/Plugins/ConsolePanel/Settings.cs new file mode 100644 index 0000000000..14325d71ed --- /dev/null +++ b/External/Plugins/ConsolePanel/Settings.cs @@ -0,0 +1,38 @@ +using System; +using System.ComponentModel; + +namespace ConsolePanel +{ + [Serializable] + class Settings + { + private ConsoleColor background = ConsoleColor.Black; + private ConsoleColor foreground = ConsoleColor.White; + + [DisplayName("Background Color"), DefaultValue(ConsoleColor.Black)] + public ConsoleColor BackgroundColor + { + get + { + return this.background; + } + set + { + this.background = value; + } + } + + [DisplayName("Foreground Color"), DefaultValue(ConsoleColor.White)] + public ConsoleColor ForegroundColor + { + get + { + return this.foreground; + } + set + { + this.foreground = value; + } + } + } +} diff --git a/External/Plugins/ConsolePanel/WinApi.cs b/External/Plugins/ConsolePanel/WinApi.cs new file mode 100644 index 0000000000..48086b2473 --- /dev/null +++ b/External/Plugins/ConsolePanel/WinApi.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; + +namespace ConsoleControl +{ + [StructLayout(LayoutKind.Sequential)] + struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + [StructLayout(LayoutKind.Sequential)] + struct WINDOWINFO + { + public uint cbSize; + public RECT rcWindow; + public RECT rcClient; + public uint dwStyle; + public uint dwExStyle; + public uint dwWindowStatus; + public uint cxWindowBorders; + public uint cyWindowBorders; + public ushort atomWindowType; + public ushort wCreatorVersion; + + public WINDOWINFO(Boolean? filler) : this() // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)". + { + cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO))); + } + } + + class WinApi + { + public const int GWL_STYLE = -16; + public const int SW_SHOWMAXIMIZED = 3; + + [DllImport("user32.dll")] + public static extern int GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll")] + public static extern bool GetWindowInfo(IntPtr hwnd, out WINDOWINFO wi); + + [DllImport("user32.dll")] + public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); + + [DllImport("user32.dll")] + public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + + [DllImport("user32.dll")] + public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + [DllImport("user32.dll")] + public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); + + [DllImport("user32.dll")] + public static extern bool AdjustWindowRect(ref RECT lpRect, int dwStyle, bool bMenu); + + public static Rectangle GetClientRect(IntPtr hWnd) + { + RECT rc; + GetClientRect(hWnd, out rc); + + return new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top); + } + + public static void ResizeClientRectTo(IntPtr hWnd, Rectangle desired) + { + RECT size; + size.Top = desired.Top; + size.Left = desired.Left; + size.Bottom = desired.Bottom; + size.Right = desired.Right; + + var style = GetWindowLong(hWnd, GWL_STYLE); + AdjustWindowRect(ref size, style, false); + MoveWindow(hWnd, size.Left, size.Top, size.Right - size.Left, size.Bottom - size.Top, true); + } + } +} diff --git a/FlashDevelop.sln b/FlashDevelop.sln index fa646274ca..13c98754c6 100644 --- a/FlashDevelop.sln +++ b/FlashDevelop.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlashDevelop", "FlashDevelop\FlashDevelop.csproj", "{EFD07485-9A64-4EEC-94E7-ACBD4DA5CA93}" ProjectSection(ProjectDependencies) = postProject @@ -83,6 +83,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASCompletion.Tests", "Tests EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeRefactor.Tests", "Tests\External\Plugins\CodeRefactor.Tests\CodeRefactor.Tests.csproj", "{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsolePanel", "External\Plugins\ConsolePanel\ConsolePanel.csproj", "{2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -493,6 +495,18 @@ Global {19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|Any CPU.Build.0 = Release|Any CPU {19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.ActiveCfg = Release|x86 {19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.Build.0 = Release|x86 + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|x86.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|x86.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|Any CPU.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|x86.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|x86.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|Any CPU.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|Any CPU.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|x86.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 495d42c052e6218b997ce5be3737b73b0382b5b5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 12 Oct 2016 15:32:58 +0200 Subject: [PATCH 02/10] Fixed a bug in ConsoleControl --- .../ConsolePanel/ConsoleControl.Designer.cs | 1 + .../Plugins/ConsolePanel/ConsoleControl.cs | 12 +- .../Plugins/ConsolePanel/ConsoleControl.resx | 120 ++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 External/Plugins/ConsolePanel/ConsoleControl.resx diff --git a/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs b/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs index 6942d51967..061819bcb2 100644 --- a/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs +++ b/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this.ForeColor = System.Drawing.Color.White; this.Name = "ConsoleControl"; this.Size = new System.Drawing.Size(246, 149); + this.Paint += new System.Windows.Forms.PaintEventHandler(this.ConsoleControl_Paint); this.Enter += new System.EventHandler(this.CmdPanel_Enter); this.Resize += new System.EventHandler(this.CmdPanel_Resize); this.ResumeLayout(false); diff --git a/External/Plugins/ConsolePanel/ConsoleControl.cs b/External/Plugins/ConsolePanel/ConsoleControl.cs index 1ae3a5dc28..9ca2b4db97 100644 --- a/External/Plugins/ConsolePanel/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/ConsoleControl.cs @@ -137,7 +137,12 @@ public void Cancel() if (!process.HasExited) { SendString("^(c)", false); - process.Kill(); + try + { + process.Kill(); + } + catch { } + } process = null; @@ -318,5 +323,10 @@ private void CmdPanel_Enter(object sender, EventArgs e) ProcessCommandCache(); } + + private void ConsoleControl_Paint(object sender, PaintEventArgs e) + { + ResizeConsole(); + } } } diff --git a/External/Plugins/ConsolePanel/ConsoleControl.resx b/External/Plugins/ConsolePanel/ConsoleControl.resx new file mode 100644 index 0000000000..7080a7d118 --- /dev/null +++ b/External/Plugins/ConsolePanel/ConsoleControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From be053fe9b25ac0d122745810aa404ade5d206894 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 17 Nov 2016 18:23:25 +0100 Subject: [PATCH 03/10] Improved overall structure --- .../Plugins/ConsolePanel/ConsolePanel.csproj | 8 ++- .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 18 +++--- External/Plugins/ConsolePanel/IConsole.cs | 40 +++++++++++++ .../Plugins/ConsolePanel/IConsoleProvider.cs | 12 ++++ .../Implementation/CmdProcess/CmdConsole.cs | 58 +++++++++++++++++++ .../CmdProcess/CmdConsoleProvider.cs | 15 +++++ .../CmdProcess}/ConsoleControl.Designer.cs | 2 +- .../CmdProcess}/ConsoleControl.cs | 9 ++- .../CmdProcess}/ConsoleControl.resx | 0 .../ConsolePanel/Managers/ConsoleManager.cs | 44 +++++++++++--- External/Plugins/ConsolePanel/PluginMain.cs | 33 ++++++++--- External/Plugins/ConsolePanel/Settings.cs | 28 --------- 12 files changed, 207 insertions(+), 60 deletions(-) create mode 100644 External/Plugins/ConsolePanel/IConsole.cs create mode 100644 External/Plugins/ConsolePanel/IConsoleProvider.cs create mode 100644 External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs create mode 100644 External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs rename External/Plugins/ConsolePanel/{ => Implementation/CmdProcess}/ConsoleControl.Designer.cs (97%) rename External/Plugins/ConsolePanel/{ => Implementation/CmdProcess}/ConsoleControl.cs (97%) rename External/Plugins/ConsolePanel/{ => Implementation/CmdProcess}/ConsoleControl.resx (100%) diff --git a/External/Plugins/ConsolePanel/ConsolePanel.csproj b/External/Plugins/ConsolePanel/ConsolePanel.csproj index 914f68c617..b6e13cb440 100644 --- a/External/Plugins/ConsolePanel/ConsolePanel.csproj +++ b/External/Plugins/ConsolePanel/ConsolePanel.csproj @@ -38,10 +38,12 @@ - + + + UserControl - + ConsoleControl.cs @@ -50,6 +52,8 @@ TabbedConsole.cs + + diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs index 3142e3eb8a..c4ba683c47 100644 --- a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -9,7 +9,7 @@ public partial class TabbedConsole : UserControl //private List consoles; private PluginMain main; - public ICollection Consoles + public ICollection Consoles { get { @@ -17,25 +17,25 @@ public ICollection Consoles } } - public Dictionary consoleTabMap; - public Dictionary tabConsoleMap; + public Dictionary consoleTabMap; + public Dictionary tabConsoleMap; public TabbedConsole(PluginMain plugin) { InitializeComponent(); main = plugin; - consoleTabMap = new Dictionary(); - tabConsoleMap = new Dictionary(); + consoleTabMap = new Dictionary(); + tabConsoleMap = new Dictionary(); btnNew.Image = PluginCore.PluginBase.MainForm.FindImage16("33"); } - public void AddConsole(ConsoleControl.ConsoleControl console) + public void AddConsole(IConsole console) { var tabPage = new TabPage("Console"); - console.Dock = DockStyle.Fill; - tabPage.Controls.Add(console); + console.ConsoleControl.Dock = DockStyle.Fill; + tabPage.Controls.Add(console.ConsoleControl); tabConsoles.TabPages.Add(tabPage); tabConsoles.SelectTab(tabPage); @@ -43,7 +43,7 @@ public void AddConsole(ConsoleControl.ConsoleControl console) tabConsoleMap.Add(tabConsoles.SelectedTab, console); } - public void RemoveConsole(ConsoleControl.ConsoleControl console) + public void RemoveConsole(IConsole console) { if (consoleTabMap.ContainsKey(console)) { diff --git a/External/Plugins/ConsolePanel/IConsole.cs b/External/Plugins/ConsolePanel/IConsole.cs new file mode 100644 index 0000000000..5b75f98183 --- /dev/null +++ b/External/Plugins/ConsolePanel/IConsole.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ConsolePanel +{ + /// + /// Interface to implement a different way of embedding a console window + /// + public interface IConsole + { + event EventHandler Exited; + + /// + /// The Control that is added to the FlashDevelop form + /// + Control ConsoleControl + { + get; + } + + string WorkingDirectory + { + //get; + set; + } + + void Clear(); + + void Cancel(); + + /// + /// Sends a string to the command line + /// + /// + void SendString(string str); + } +} diff --git a/External/Plugins/ConsolePanel/IConsoleProvider.cs b/External/Plugins/ConsolePanel/IConsoleProvider.cs new file mode 100644 index 0000000000..41d82bec32 --- /dev/null +++ b/External/Plugins/ConsolePanel/IConsoleProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ConsolePanel +{ + public interface IConsoleProvider + { + IConsole GetConsole(); + } +} diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs new file mode 100644 index 0000000000..887a683cb1 --- /dev/null +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ConsolePanel.Implementation.CmdProcess +{ + class CmdConsole : IConsole + { + ConsoleControl cmd; + + public Control ConsoleControl + { + get + { + return cmd; + } + } + + public string WorkingDirectory + { + set + { + cmd.WorkingDirectory = value; + } + } + + public event EventHandler Exited; + + public void Clear() + { + cmd.SendString("cls"); + } + + public void Cancel() + { + cmd.Cancel(); + } + + public void SendString(string str) + { + cmd.SendString(str, false); + } + + public CmdConsole() + { + cmd = new ConsoleControl(); + cmd.Text = "cmd"; + + cmd.Exited += delegate (object sender, EventArgs e) + { + if (Exited != null) + Exited(sender, e); + }; + } + } +} diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs new file mode 100644 index 0000000000..14d85bf76a --- /dev/null +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ConsolePanel.Implementation.CmdProcess +{ + class CmdConsoleProvider : IConsoleProvider + { + public IConsole GetConsole() + { + return new CmdConsole(); + } + } +} diff --git a/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.Designer.cs similarity index 97% rename from External/Plugins/ConsolePanel/ConsoleControl.Designer.cs rename to External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.Designer.cs index 061819bcb2..3b832d795a 100644 --- a/External/Plugins/ConsolePanel/ConsoleControl.Designer.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.Designer.cs @@ -1,4 +1,4 @@ -namespace ConsoleControl +namespace ConsolePanel.Implementation.CmdProcess { partial class ConsoleControl { diff --git a/External/Plugins/ConsolePanel/ConsoleControl.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs similarity index 97% rename from External/Plugins/ConsolePanel/ConsoleControl.cs rename to External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs index 9ca2b4db97..1e3adc40e1 100644 --- a/External/Plugins/ConsolePanel/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs @@ -4,8 +4,9 @@ using System.Drawing; using System.Collections.Generic; using System.Windows.Automation; +using ConsoleControl; -namespace ConsoleControl +namespace ConsolePanel.Implementation.CmdProcess { public partial class ConsoleControl : UserControl { @@ -18,7 +19,6 @@ public partial class ConsoleControl : UserControl ConsoleColor foreColor = ConsoleColor.White; List commandsToDo = new List(); string lastWorkingDir; - string cmd; public event EventHandler Exited; @@ -115,13 +115,12 @@ public Process Process /// /// /// - public ConsoleControl(string command, bool init = true, string workingDirectory = null) + public ConsoleControl(bool init = true, string workingDirectory = null) { InitializeComponent(); SetStyle(ControlStyles.Selectable, true); lastWorkingDir = workingDirectory; - cmd = command; if (init) Create(); @@ -163,7 +162,7 @@ public void Create() { process = new Process(); - process.StartInfo.FileName = cmd; + process.StartInfo.FileName = "cmd"; if (lastWorkingDir != null) process.StartInfo.WorkingDirectory = lastWorkingDir; diff --git a/External/Plugins/ConsolePanel/ConsoleControl.resx b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx similarity index 100% rename from External/Plugins/ConsolePanel/ConsoleControl.resx rename to External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx diff --git a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs index b464373db6..09bc30e187 100644 --- a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs +++ b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs @@ -12,20 +12,17 @@ public class ConsoleManager static PluginMain main; static List commandList = new List(); + static IConsoleProvider cachedProvider; /// - /// Runs a command in a new console window. + /// Creates a new console panel and sends the given string to it. /// - /// the command to run, uses standard cmd input syntax - public static void RunCommand(string command) + /// the command to send + public static void CreateConsole(string command) { if (main != null) { - while(commandList.Count > 0) - { - main.CreateConsolePanel().SendString(commandList[0]); - commandList.RemoveAt(0); - } + processCommandList(); main.CreateConsolePanel().SendString(command); } else @@ -34,9 +31,40 @@ public static void RunCommand(string command) } } + public static void SetConsoleProvider(IConsoleProvider provider) + { + if (main != null) + { + main.ConsoleProvider = provider; + } + else + { + cachedProvider = provider; + } + } + public static void Init(PluginMain plugin) { main = plugin; + processCachedProvider(); + processCommandList(); + } + + static void processCommandList() + { + while (commandList.Count > 0) + { + main.CreateConsolePanel().SendString(commandList[0]); + commandList.RemoveAt(0); + } + } + + static void processCachedProvider() + { + if (cachedProvider != null) + { + main.ConsoleProvider = cachedProvider; + } } } } diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index 8428b76c13..ef6da69ece 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -26,6 +26,8 @@ public class PluginMain : IPlugin private Gui.TabbedConsole tabView; private Image image; + private IConsoleProvider provider; + public int Api { get @@ -83,11 +85,24 @@ public object Settings } } + public IConsoleProvider ConsoleProvider + { + get + { + return provider; + } + set + { + provider = value; + } + } + public void Initialize() { InitBasics(); LoadSettings(); CreatePluginPanel(); + CreateDefaultConsoleProvider(); CreateConsolePanel(); CreateMenuItem(); @@ -151,14 +166,20 @@ private void CreatePluginPanel() cmdPanelDockContent.Text = "Console"; } - public ConsoleControl.ConsoleControl CreateConsolePanel() + private void CreateDefaultConsoleProvider() + { + ConsoleProvider = new Implementation.CmdProcess.CmdConsoleProvider(); + } + + public IConsole CreateConsolePanel() { cmdPanelDockContent.Show(); - var cmdPanel = new ConsoleControl.ConsoleControl("cmd", false); - cmdPanel.Text = "Console"; - cmdPanel.ConsoleBackColor = settingObject.BackgroundColor; - cmdPanel.ConsoleForeColor = settingObject.ForegroundColor; + var cmdPanel = ConsoleProvider.GetConsole(); + //var cmdPanel = new ConsoleControl.ConsoleControl(false); + //cmdPanel.Text = "Console"; + //cmdPanel.ConsoleBackColor = settingObject.BackgroundColor; + //cmdPanel.ConsoleForeColor = settingObject.ForegroundColor; cmdPanel.Exited += delegate { @@ -177,8 +198,6 @@ public ConsoleControl.ConsoleControl CreateConsolePanel() } }; - cmdPanel.Create(); - tabView.AddConsole(cmdPanel); return cmdPanel; diff --git a/External/Plugins/ConsolePanel/Settings.cs b/External/Plugins/ConsolePanel/Settings.cs index 14325d71ed..eb3e7a6d91 100644 --- a/External/Plugins/ConsolePanel/Settings.cs +++ b/External/Plugins/ConsolePanel/Settings.cs @@ -6,33 +6,5 @@ namespace ConsolePanel [Serializable] class Settings { - private ConsoleColor background = ConsoleColor.Black; - private ConsoleColor foreground = ConsoleColor.White; - - [DisplayName("Background Color"), DefaultValue(ConsoleColor.Black)] - public ConsoleColor BackgroundColor - { - get - { - return this.background; - } - set - { - this.background = value; - } - } - - [DisplayName("Foreground Color"), DefaultValue(ConsoleColor.White)] - public ConsoleColor ForegroundColor - { - get - { - return this.foreground; - } - set - { - this.foreground = value; - } - } } } From da5cc539d3da1bebb4e539c1a667778fcfa90feb Mon Sep 17 00:00:00 2001 From: slavara Date: Wed, 25 Nov 2020 19:51:24 +0300 Subject: [PATCH 04/10] WIP --- .../Plugins/ConsolePanel/ConsolePanel.csproj | 15 +- .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 20 +-- .../ConsolePanel/Gui/TabbedConsole.resx | 120 ------------- External/Plugins/ConsolePanel/IConsole.cs | 14 +- .../Plugins/ConsolePanel/IConsoleProvider.cs | 9 +- .../Implementation/CmdProcess/CmdConsole.cs | 43 +---- .../CmdProcess/CmdConsoleProvider.cs | 12 +- .../CmdProcess/ConsoleControl.resx | 120 ------------- .../ConsolePanel/Managers/ConsoleManager.cs | 27 ++- External/Plugins/ConsolePanel/PluginMain.cs | 169 ++++-------------- External/Plugins/ConsolePanel/Settings.cs | 3 +- External/Plugins/ConsolePanel/WinApi.cs | 8 +- .../CssCompletion/Helpers/CssMinify.cs | 21 ++- FlashDevelop.sln | 16 ++ 14 files changed, 96 insertions(+), 501 deletions(-) delete mode 100644 External/Plugins/ConsolePanel/Gui/TabbedConsole.resx delete mode 100644 External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx diff --git a/External/Plugins/ConsolePanel/ConsolePanel.csproj b/External/Plugins/ConsolePanel/ConsolePanel.csproj index b6e13cb440..d511412387 100644 --- a/External/Plugins/ConsolePanel/ConsolePanel.csproj +++ b/External/Plugins/ConsolePanel/ConsolePanel.csproj @@ -9,9 +9,7 @@ Properties ConsolePanel ConsolePanel - v3.5 - 512 - + v4.8 true @@ -78,23 +76,12 @@ - - TabbedConsole.cs - ResXFileCodeGenerator Resources.Designer.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/IConsole.cs b/External/Plugins/ConsolePanel/IConsole.cs index 5b75f98183..cc92356329 100644 --- a/External/Plugins/ConsolePanel/IConsole.cs +++ b/External/Plugins/ConsolePanel/IConsole.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace ConsolePanel @@ -16,16 +13,9 @@ public interface IConsole /// /// The Control that is added to the FlashDevelop form /// - Control ConsoleControl - { - get; - } + Control ConsoleControl { get; } - string WorkingDirectory - { - //get; - set; - } + string WorkingDirectory { set; } void Clear(); diff --git a/External/Plugins/ConsolePanel/IConsoleProvider.cs b/External/Plugins/ConsolePanel/IConsoleProvider.cs index 41d82bec32..7b8e494457 100644 --- a/External/Plugins/ConsolePanel/IConsoleProvider.cs +++ b/External/Plugins/ConsolePanel/IConsoleProvider.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ConsolePanel +namespace ConsolePanel { public interface IConsoleProvider { IConsole GetConsole(); } -} +} \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs index 887a683cb1..2f8ef562ad 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs @@ -1,58 +1,31 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace ConsolePanel.Implementation.CmdProcess { class CmdConsole : IConsole { - ConsoleControl cmd; + readonly ConsoleControl cmd; - public Control ConsoleControl - { - get - { - return cmd; - } - } + public Control ConsoleControl => cmd; public string WorkingDirectory { - set - { - cmd.WorkingDirectory = value; - } + set => cmd.WorkingDirectory = value; } public event EventHandler Exited; - public void Clear() - { - cmd.SendString("cls"); - } + public void Clear() => cmd.SendString("cls"); - public void Cancel() - { - cmd.Cancel(); - } + public void Cancel() => cmd.Cancel(); - public void SendString(string str) - { - cmd.SendString(str, false); - } + public void SendString(string str) => cmd.SendString(str, false); public CmdConsole() { - cmd = new ConsoleControl(); - cmd.Text = "cmd"; - - cmd.Exited += delegate (object sender, EventArgs e) - { - if (Exited != null) - Exited(sender, e); - }; + cmd = new ConsoleControl {Text = "cmd"}; + cmd.Exited += (sender, e) => Exited?.Invoke(sender, e); } } } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs index 14d85bf76a..fc3e1df7f7 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ConsolePanel.Implementation.CmdProcess +namespace ConsolePanel.Implementation.CmdProcess { class CmdConsoleProvider : IConsoleProvider { - public IConsole GetConsole() - { - return new CmdConsole(); - } + public IConsole GetConsole() => new CmdConsole(); } } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx deleted file mode 100644 index 7080a7d118..0000000000 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs index 09bc30e187..e3a8ed14f3 100644 --- a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs +++ b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs @@ -1,17 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace ConsolePanel.Managers { - public delegate void OnExited(); - public class ConsoleManager { static PluginMain main; - static List commandList = new List(); + static readonly List CommandList = new List(); static IConsoleProvider cachedProvider; /// @@ -22,12 +17,12 @@ public static void CreateConsole(string command) { if (main != null) { - processCommandList(); + ProcessCommandList(); main.CreateConsolePanel().SendString(command); } else { - commandList.Add(command); + CommandList.Add(command); } } @@ -46,20 +41,20 @@ public static void SetConsoleProvider(IConsoleProvider provider) public static void Init(PluginMain plugin) { main = plugin; - processCachedProvider(); - processCommandList(); + ProcessCachedProvider(); + ProcessCommandList(); } - static void processCommandList() + static void ProcessCommandList() { - while (commandList.Count > 0) + while (CommandList.Count > 0) { - main.CreateConsolePanel().SendString(commandList[0]); - commandList.RemoveAt(0); + main.CreateConsolePanel().SendString(CommandList[0]); + CommandList.RemoveAt(0); } } - static void processCachedProvider() + static void ProcessCachedProvider() { if (cachedProvider != null) { diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index ef6da69ece..c7f4dfd7ba 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -1,5 +1,4 @@ - -using System; +using System; using PluginCore; using System.ComponentModel; using PluginCore.Managers; @@ -9,93 +8,33 @@ using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; using System.Drawing; -using ProjectManager.Projects; namespace ConsolePanel { public class PluginMain : IPlugin { - private string pluginName = "ConsolePanel"; - private string pluginGuid = "AEDE556E-54C3-4EFB-8EF3-54E85DC37D1E"; - private string pluginHelp = "http://hexmachina.org/"; - private string pluginDesc = "Plugin that adds an embedded console window to FlashDevelop."; - private string pluginAuth = "Christoph Otter"; - private string settingFilename; - private Settings settingObject; - private DockContent cmdPanelDockContent; - private Gui.TabbedConsole tabView; - private Image image; - - private IConsoleProvider provider; - - public int Api - { - get - { - return 1; - } - } + string settingFilename; + Settings settingObject; + DockContent cmdPanelDockContent; + Gui.TabbedConsole tabView; + Image image; - public string Author - { - get - { - return pluginAuth; - } - } + public int Api => 1; - public string Description - { - get - { - return pluginDesc; - } - } + public string Author { get; } = "Christoph Otter"; - public string Guid - { - get - { - return pluginGuid; - } - } + public string Description { get; } = "Plugin that adds an embedded console window to FlashDevelop."; - public string Help - { - get - { - return pluginHelp; - } - } + public string Guid { get; } = "AEDE556E-54C3-4EFB-8EF3-54E85DC37D1E"; - public string Name - { - get - { - return pluginName; - } - } + public string Help { get; } = "www.flashdevelop.org/community/"; + + public string Name { get; } = nameof(ConsolePanel); [Browsable(false)] - public object Settings - { - get - { - return settingObject; - } - } + public object Settings => settingObject; - public IConsoleProvider ConsoleProvider - { - get - { - return provider; - } - set - { - provider = value; - } - } + public IConsoleProvider ConsoleProvider { get; set; } public void Initialize() { @@ -117,7 +56,6 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) var data = (DataEvent)e; if (data.Action == "ProjectManager.Project") { - var project = (Project) data.Data; foreach (var panel in tabView.Consoles) { panel.WorkingDirectory = PluginBase.CurrentProject.GetAbsolutePath(""); @@ -127,95 +65,64 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) } } - public void Dispose() - { - SaveSettings(); - } + public void Dispose() => SaveSettings(); - private void InitBasics() + void InitBasics() { - string dataPath = Path.Combine(PathHelper.DataDir, pluginName); - if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); - this.settingFilename = Path.Combine(dataPath, "Settings.fdb"); - + var path = Path.Combine(PathHelper.DataDir, Name); + if (!Directory.Exists(path)) Directory.CreateDirectory(path); + settingFilename = Path.Combine(path, "Settings.fdb"); image = PluginBase.MainForm.FindImage("57"); - Managers.ConsoleManager.Init(this); } - private void LoadSettings() + void LoadSettings() { - this.settingObject = new Settings(); - if (!File.Exists(this.settingFilename)) this.SaveSettings(); - else - { - Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject); - this.settingObject = (Settings)obj; - } + settingObject = new Settings(); + if (!File.Exists(settingFilename)) SaveSettings(); + else settingObject = ObjectSerializer.Deserialize(settingFilename, settingObject); } - private void SaveSettings() - { - ObjectSerializer.Serialize(this.settingFilename, this.settingObject); - } + void SaveSettings() => ObjectSerializer.Serialize(settingFilename, settingObject); - private void CreatePluginPanel() + void CreatePluginPanel() { tabView = new Gui.TabbedConsole(this); - cmdPanelDockContent = PluginBase.MainForm.CreateDockablePanel(tabView, pluginGuid, image, DockState.DockBottom); + cmdPanelDockContent = PluginBase.MainForm.CreateDockablePanel(tabView, Guid, image, DockState.DockBottom); cmdPanelDockContent.Text = "Console"; } - private void CreateDefaultConsoleProvider() - { - ConsoleProvider = new Implementation.CmdProcess.CmdConsoleProvider(); - } + void CreateDefaultConsoleProvider() => ConsoleProvider = new Implementation.CmdProcess.CmdConsoleProvider(); public IConsole CreateConsolePanel() { cmdPanelDockContent.Show(); - var cmdPanel = ConsoleProvider.GetConsole(); - //var cmdPanel = new ConsoleControl.ConsoleControl(false); - //cmdPanel.Text = "Console"; - //cmdPanel.ConsoleBackColor = settingObject.BackgroundColor; - //cmdPanel.ConsoleForeColor = settingObject.ForegroundColor; - - cmdPanel.Exited += delegate + cmdPanel.Exited += (sender, args) => { if (tabView.InvokeRequired) { - tabView.Invoke((MethodInvoker)delegate + tabView.Invoke((MethodInvoker) (() => { if (!PluginBase.MainForm.ClosingEntirely) tabView.RemoveConsole(cmdPanel); - }); - } - else - { - if (!PluginBase.MainForm.ClosingEntirely) - tabView.RemoveConsole(cmdPanel); + })); } + else if (!PluginBase.MainForm.ClosingEntirely) + tabView.RemoveConsole(cmdPanel); }; - tabView.AddConsole(cmdPanel); - return cmdPanel; } - private void CreateMenuItem() + void CreateMenuItem() { - string label = "Embedded Console"; - ToolStripMenuItem viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); - ToolStripMenuItem cmdItem = new ToolStripMenuItem(label, image, OpenCmdPanel); - + var label = "Console Panel"; + var viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); + var cmdItem = new ToolStripMenuItem(label, image, OpenCmdPanel); viewMenu.DropDownItems.Add(cmdItem); } - private void OpenCmdPanel(object sender, EventArgs e) - { - CreateConsolePanel(); - //cmdPanelDockContent.Show(); - } + void OpenCmdPanel(object sender, EventArgs e) => CreateConsolePanel(); } } diff --git a/External/Plugins/ConsolePanel/Settings.cs b/External/Plugins/ConsolePanel/Settings.cs index eb3e7a6d91..f7fc36e2d2 100644 --- a/External/Plugins/ConsolePanel/Settings.cs +++ b/External/Plugins/ConsolePanel/Settings.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; namespace ConsolePanel { @@ -7,4 +6,4 @@ namespace ConsolePanel class Settings { } -} +} \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/WinApi.cs b/External/Plugins/ConsolePanel/WinApi.cs index 48086b2473..2840f9be57 100644 --- a/External/Plugins/ConsolePanel/WinApi.cs +++ b/External/Plugins/ConsolePanel/WinApi.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; using System.Drawing; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Windows.Forms; namespace ConsoleControl { @@ -65,9 +61,7 @@ class WinApi public static Rectangle GetClientRect(IntPtr hWnd) { - RECT rc; - GetClientRect(hWnd, out rc); - + GetClientRect(hWnd, out var rc); return new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top); } diff --git a/External/Plugins/CssCompletion/Helpers/CssMinify.cs b/External/Plugins/CssCompletion/Helpers/CssMinify.cs index 8c76021264..bc5d055e05 100644 --- a/External/Plugins/CssCompletion/Helpers/CssMinify.cs +++ b/External/Plugins/CssCompletion/Helpers/CssMinify.cs @@ -111,7 +111,7 @@ public static string Minify(string theCss) /// The current CSS parsing state. /// /// The future CSS parsing state. - private static CssState GetState(string theCss, ref int thePos, CssState theCurState) + static CssState GetState(string theCss, ref int thePos, CssState theCurState) { int aLen = theCss.Length; int i = thePos; @@ -181,19 +181,18 @@ private static CssState GetState(string theCss, ref int thePos, CssState theCurS thePos = i; char c = theCss[i]; - if (IsTokenChar(c)) - return CssState.Token; - - if (c == '\"') - return CssState.StringD; - if (c == '\'') - return CssState.StringS; - return CssState.Punctuation; + if (IsTokenChar(c)) return CssState.Token; + return c switch + { + '\"' => CssState.StringD, + '\'' => CssState.StringS, + _ => CssState.Punctuation + }; } - private static bool IsWhitespaceChar(char p) => p == '\t' || p == '\r' || p == '\n' || p == ' '; + static bool IsWhitespaceChar(char p) => p == '\t' || p == '\r' || p == '\n' || p == ' '; - private static bool IsTokenChar(char theChar) + static bool IsTokenChar(char theChar) { if (theChar >= 'a' && theChar <= 'z') return true; if (theChar >= '0' && theChar <= '9') return true; diff --git a/FlashDevelop.sln b/FlashDevelop.sln index e5e4a4f7bf..2b7c577cce 100644 --- a/FlashDevelop.sln +++ b/FlashDevelop.sln @@ -605,6 +605,22 @@ Global {DCA7613E-7BC3-4610-A95E-73C0D64C5B98}.Release+Tests|Any CPU.Build.0 = Release|Any CPU {DCA7613E-7BC3-4610-A95E-73C0D64C5B98}.Release+Tests|x86.ActiveCfg = Release|Any CPU {DCA7613E-7BC3-4610-A95E-73C0D64C5B98}.Release+Tests|x86.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|x86.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug|x86.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug+Tests|Any CPU.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug+Tests|Any CPU.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug+Tests|x86.ActiveCfg = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Debug+Tests|x86.Build.0 = Debug|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|Any CPU.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|x86.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release|x86.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|Any CPU.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|Any CPU.Build.0 = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|x86.ActiveCfg = Release|Any CPU + {2A36ADDC-B30E-472B-BDD6-0E6E35649FAA}.Release+Tests|x86.Build.0 = Release|Any CPU {FF680DE0-9CB7-45F4-BAFA-6EFFAAFD9C09}.Debug|Any CPU.ActiveCfg = Debug|x86 {FF680DE0-9CB7-45F4-BAFA-6EFFAAFD9C09}.Debug|Any CPU.Build.0 = Debug|x86 {FF680DE0-9CB7-45F4-BAFA-6EFFAAFD9C09}.Debug|x86.ActiveCfg = Debug|x86 From 1382998b914101b60c0b1deac79b5317eb30fb58 Mon Sep 17 00:00:00 2001 From: slavara Date: Wed, 25 Nov 2020 20:02:57 +0300 Subject: [PATCH 05/10] WIP --- External/Plugins/ConsolePanel/PluginMain.cs | 40 +++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index c7f4dfd7ba..382d50bd48 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -15,10 +15,12 @@ public class PluginMain : IPlugin { string settingFilename; Settings settingObject; - DockContent cmdPanelDockContent; + DockContent pluginPanel; Gui.TabbedConsole tabView; Image image; + #region Required Properties + public int Api => 1; public string Author { get; } = "Christoph Otter"; @@ -34,18 +36,19 @@ public class PluginMain : IPlugin [Browsable(false)] public object Settings => settingObject; + #endregion + public IConsoleProvider ConsoleProvider { get; set; } public void Initialize() { InitBasics(); LoadSettings(); + AddEventHandlers(); CreatePluginPanel(); + CreateMenuItem(); CreateDefaultConsoleProvider(); CreateConsolePanel(); - CreateMenuItem(); - - EventManager.AddEventHandler(this, EventType.Command, HandlingPriority.Normal); } public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) @@ -83,26 +86,37 @@ void LoadSettings() else settingObject = ObjectSerializer.Deserialize(settingFilename, settingObject); } + void AddEventHandlers() => EventManager.AddEventHandler(this, EventType.Command, HandlingPriority.Normal); + void SaveSettings() => ObjectSerializer.Serialize(settingFilename, settingObject); void CreatePluginPanel() { tabView = new Gui.TabbedConsole(this); - cmdPanelDockContent = PluginBase.MainForm.CreateDockablePanel(tabView, Guid, image, DockState.DockBottom); - cmdPanelDockContent.Text = "Console"; + pluginPanel = PluginBase.MainForm.CreateDockablePanel(tabView, Guid, image, DockState.DockBottom); + pluginPanel.Text = "Console"; + } + + void CreateMenuItem() + { + var label = "Console Panel"; + var viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); + var cmdItem = new ToolStripMenuItem(label, image, OpenPanel); + viewMenu.DropDownItems.Add(cmdItem); } + void OpenPanel(object sender, EventArgs e) => pluginPanel.Show(); + void CreateDefaultConsoleProvider() => ConsoleProvider = new Implementation.CmdProcess.CmdConsoleProvider(); public IConsole CreateConsolePanel() { - cmdPanelDockContent.Show(); var cmdPanel = ConsoleProvider.GetConsole(); cmdPanel.Exited += (sender, args) => { if (tabView.InvokeRequired) { - tabView.Invoke((MethodInvoker) (() => + tabView.Invoke((MethodInvoker)(() => { if (!PluginBase.MainForm.ClosingEntirely) tabView.RemoveConsole(cmdPanel); @@ -114,15 +128,5 @@ public IConsole CreateConsolePanel() tabView.AddConsole(cmdPanel); return cmdPanel; } - - void CreateMenuItem() - { - var label = "Console Panel"; - var viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); - var cmdItem = new ToolStripMenuItem(label, image, OpenCmdPanel); - viewMenu.DropDownItems.Add(cmdItem); - } - - void OpenCmdPanel(object sender, EventArgs e) => CreateConsolePanel(); } } From 006a21d6147967da4d0e7eb414a08588416e5290 Mon Sep 17 00:00:00 2001 From: slavara Date: Wed, 25 Nov 2020 21:32:26 +0300 Subject: [PATCH 06/10] WIP --- .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 26 +-- .../CmdProcess/ConsoleControl.cs | 175 +++++------------- .../ConsolePanel/Managers/ConsoleManager.cs | 6 +- 3 files changed, 59 insertions(+), 148 deletions(-) diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs index 34412cc686..aabb6b4903 100644 --- a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -36,29 +36,23 @@ public void AddConsole(IConsole console) public void RemoveConsole(IConsole console) { - if (consoleTabMap.ContainsKey(console)) - { - console.Cancel(); - - var page = consoleTabMap[console]; - tabConsoles.TabPages.Remove(page); - consoleTabMap.Remove(console); - tabConsoleMap.Remove(page); - } + if (!consoleTabMap.ContainsKey(console)) return; + console.Cancel(); + var page = consoleTabMap[console]; + tabConsoles.TabPages.Remove(page); + consoleTabMap.Remove(console); + tabConsoleMap.Remove(page); } void tabConsoles_MouseClick(object sender, MouseEventArgs e) { - if (e.Button == MouseButtons.Middle) + if (e.Button != MouseButtons.Middle) return; + for (int i = 0; i < tabConsoles.TabCount; i++) { - for (int i = 0; i < tabConsoles.TabCount; i++) + if (tabConsoles.GetTabRect(i).Contains(e.Location)) { - if (tabConsoles.GetTabRect(i).Contains(e.Location)) - { - RemoveConsole(tabConsoleMap[tabConsoles.TabPages[i]]); - } + RemoveConsole(tabConsoleMap[tabConsoles.TabPages[i]]); } - } } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs index 1e3adc40e1..8149d0cc4e 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs @@ -10,14 +10,13 @@ namespace ConsolePanel.Implementation.CmdProcess { public partial class ConsoleControl : UserControl { - Process process; IntPtr cmdHandle; AutomationElement window; Size realSize; ConsoleColor backColor = ConsoleColor.Black; ConsoleColor foreColor = ConsoleColor.White; - List commandsToDo = new List(); + readonly List commandsToDo = new List(); string lastWorkingDir; public event EventHandler Exited; @@ -27,11 +26,7 @@ public string WorkingDirectory set { lastWorkingDir = value; - - if (process == null) - { - Create(); - } + if (Process == null) Create(); else { SendString("cd \"" + value + "\""); @@ -42,24 +37,15 @@ public string WorkingDirectory public ConsoleColor ConsoleBackColor { - get - { - return backColor; - } + get => backColor; set { - if (backColor == value) - return; - + if (value == backColor) return; backColor = value; - var trimmedFore = foreColor.ToString("X").TrimStart('0'); var trimmedBack = backColor.ToString("X").TrimStart('0'); - if (trimmedFore == "") - trimmedFore = "0"; - if (trimmedBack == "") - trimmedBack = "0"; - + if (trimmedFore == "") trimmedFore = "0"; + if (trimmedBack == "") trimmedBack = "0"; SendString("color " + trimmedBack + trimmedFore); SendString("cls"); } @@ -67,24 +53,15 @@ public ConsoleColor ConsoleBackColor public ConsoleColor ConsoleForeColor { - get - { - return foreColor; - } + get => foreColor; set { - if (foreColor == value) - return; - + if (value == foreColor) return; foreColor = value; - var trimmedFore = foreColor.ToString("X").TrimStart('0'); var trimmedBack = backColor.ToString("X").TrimStart('0'); - if (trimmedFore == "") - trimmedFore = "0"; - if (trimmedBack == "") - trimmedBack = "0"; - + if (trimmedFore == "") trimmedFore = "0"; + if (trimmedBack == "") trimmedBack = "0"; SendString("color " + trimmedBack + trimmedFore); SendString("cls"); } @@ -94,21 +71,9 @@ public ConsoleColor ConsoleForeColor /// Returns the actual size of the console window's client area /// (the width of a console window only changes by specific values) /// - public Size ActualSize - { - get - { - return realSize; - } - } + public Size ActualSize => realSize; - public Process Process - { - get - { - return process; - } - } + public Process Process { get; set; } /// /// Creates a new ConsoleControl @@ -119,11 +84,8 @@ public ConsoleControl(bool init = true, string workingDirectory = null) { InitializeComponent(); SetStyle(ControlStyles.Selectable, true); - lastWorkingDir = workingDirectory; - - if (init) - Create(); + if (init) Create(); } /// @@ -131,21 +93,18 @@ public ConsoleControl(bool init = true, string workingDirectory = null) /// public void Cancel() { - if (process != null) + if (Process is null) return; + if (!Process.HasExited) { - if (!process.HasExited) + SendString("^(c)", false); + try { - SendString("^(c)", false); - try - { - process.Kill(); - } - catch { } - + Process.Kill(); } - - process = null; + catch { } + } + Process = null; } /// @@ -153,35 +112,25 @@ public void Cancel() /// public void Create() { - if (process != null && !process.HasExited) - { - return; - } - + if (Process != null && !Process.HasExited) return; try { - process = new Process(); - - process.StartInfo.FileName = "cmd"; - - if (lastWorkingDir != null) - process.StartInfo.WorkingDirectory = lastWorkingDir; - process.StartInfo.UseShellExecute = false; - - process.EnableRaisingEvents = true; - process.Exited += Process_Exited; - - process.Start(); + Process = new Process(); + Process.StartInfo.FileName = "cmd"; + if (lastWorkingDir != null) Process.StartInfo.WorkingDirectory = lastWorkingDir; + Process.StartInfo.UseShellExecute = false; + Process.EnableRaisingEvents = true; + Process.Exited += Process_Exited; + Process.Start(); //Wait for cmd window - while (process.MainWindowHandle == IntPtr.Zero) + while (Process.MainWindowHandle == IntPtr.Zero) { - process.Refresh(); + Process.Refresh(); } - cmdHandle = process.MainWindowHandle; - window = System.Windows.Automation.AutomationElement.FromHandle(cmdHandle); + cmdHandle = Process.MainWindowHandle; + window = AutomationElement.FromHandle(cmdHandle); WinApi.SetParent(cmdHandle, pnlClipping.Handle); - SendString("cls"); ResizeConsole(); } @@ -197,8 +146,7 @@ public void Create() /// if true, a "\r" is appended to the given string public void SendString(string str, bool execute = true) { - if (execute) - str += "\r"; + if (execute) str += "\r"; ProcessCommandCache(); try { @@ -210,12 +158,11 @@ public void SendString(string str, bool execute = true) } } - private void ProcessCommandCache() + void ProcessCommandCache() { while (commandsToDo.Count > 0) { var toDo = commandsToDo[0]; - try { RunCommandWithoutCache(toDo); @@ -228,55 +175,40 @@ private void ProcessCommandCache() } } - private void RunCommandWithoutCache(string cmd) + void RunCommandWithoutCache(string cmd) { window.SetFocus(); //TODO: prevent user from clicking around while doing this SendKeys.SendWait(cmd); - Focus(); } - private void ResizeConsole() + void ResizeConsole() { WinApi.ShowWindow(cmdHandle, WinApi.SW_SHOWMAXIMIZED); - WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(new Point(0, 0), Size)); - SetRealConsoleSize(); - var tooWide = realSize.Width > Width; var tooHigh = realSize.Height > Height; if (tooWide || tooHigh) { int newWidth = realSize.Width; int newHeight = realSize.Height; - if (tooWide) - { - newWidth -= 8; - } - if (tooHigh) - { - newHeight -= 12; - } - + if (tooWide) newWidth -= 8; + if (tooHigh) newHeight -= 12; WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(0, 0, newWidth, newHeight)); SetRealConsoleSize(); } - pnlClipping.Size = realSize; } - private void SetRealConsoleSize() + void SetRealConsoleSize() { - WINDOWINFO info; - WinApi.GetWindowInfo(cmdHandle, out info); - + WinApi.GetWindowInfo(cmdHandle, out var info); var leftBorder = info.rcClient.Left - info.rcWindow.Left; var topBorder = info.rcClient.Top - info.rcWindow.Top; var rightBorder = (int)info.cxWindowBorders; var bottomBorder = (int)info.cyWindowBorders; - var width = info.rcWindow.Right - info.rcWindow.Left; var height = info.rcWindow.Bottom - info.rcWindow.Top; @@ -284,16 +216,12 @@ private void SetRealConsoleSize() realSize.Height = height - topBorder - bottomBorder; } - private void CmdPanel_Resize(object sender, EventArgs e) - { - ResizeConsole(); - } + void CmdPanel_Resize(object sender, EventArgs e) => ResizeConsole(); - private void Process_Exited(object sender, EventArgs e) + void Process_Exited(object sender, EventArgs e) { cmdHandle = IntPtr.Zero; - if (Exited != null) - Exited(sender, e); + Exited?.Invoke(sender, e); } /// @@ -302,30 +230,21 @@ private void Process_Exited(object sender, EventArgs e) /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) - { - components.Dispose(); - } - + if (disposing) components?.Dispose(); Cancel(); - base.Dispose(disposing); } - private void CmdPanel_Enter(object sender, EventArgs e) + void CmdPanel_Enter(object sender, EventArgs e) { try { window.SetFocus(); } catch { } - ProcessCommandCache(); } - private void ConsoleControl_Paint(object sender, PaintEventArgs e) - { - ResizeConsole(); - } + void ConsoleControl_Paint(object sender, PaintEventArgs e) => ResizeConsole(); } } diff --git a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs index e3a8ed14f3..6217736a67 100644 --- a/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs +++ b/External/Plugins/ConsolePanel/Managers/ConsoleManager.cs @@ -56,10 +56,8 @@ static void ProcessCommandList() static void ProcessCachedProvider() { - if (cachedProvider != null) - { - main.ConsoleProvider = cachedProvider; - } + if (cachedProvider is null) return; + main.ConsoleProvider = cachedProvider; } } } From 15ffec95ab97cf0d124ecf89e244a75ccc3d645f Mon Sep 17 00:00:00 2001 From: slavara Date: Wed, 25 Nov 2020 21:54:45 +0300 Subject: [PATCH 07/10] WIP --- .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 4 +-- .../Plugins/ConsolePanel/IConsoleProvider.cs | 1 + .../Implementation/CmdProcess/CmdConsole.cs | 16 +++++++----- .../CmdProcess/CmdConsoleProvider.cs | 3 ++- .../CmdProcess/ConsoleControl.cs | 2 +- External/Plugins/ConsolePanel/PluginMain.cs | 25 ++++++++++++------- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs index aabb6b4903..91249d2523 100644 --- a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -10,8 +10,8 @@ public partial class TabbedConsole : UserControl public ICollection Consoles => consoleTabMap.Keys; - public Dictionary consoleTabMap; - public Dictionary tabConsoleMap; + readonly Dictionary consoleTabMap; + readonly Dictionary tabConsoleMap; public TabbedConsole(PluginMain plugin) { diff --git a/External/Plugins/ConsolePanel/IConsoleProvider.cs b/External/Plugins/ConsolePanel/IConsoleProvider.cs index 7b8e494457..1a8304da01 100644 --- a/External/Plugins/ConsolePanel/IConsoleProvider.cs +++ b/External/Plugins/ConsolePanel/IConsoleProvider.cs @@ -3,5 +3,6 @@ public interface IConsoleProvider { IConsole GetConsole(); + IConsole GetConsole(string workingDirectory); } } \ No newline at end of file diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs index 2f8ef562ad..1f772c3117 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsole.cs @@ -7,6 +7,16 @@ class CmdConsole : IConsole { readonly ConsoleControl cmd; + public CmdConsole() : this(null) + { + } + + public CmdConsole(string workingDirectory) + { + cmd = new ConsoleControl(true, workingDirectory) { Text = "cmd" }; + cmd.Exited += (sender, e) => Exited?.Invoke(sender, e); + } + public Control ConsoleControl => cmd; public string WorkingDirectory @@ -21,11 +31,5 @@ public string WorkingDirectory public void Cancel() => cmd.Cancel(); public void SendString(string str) => cmd.SendString(str, false); - - public CmdConsole() - { - cmd = new ConsoleControl {Text = "cmd"}; - cmd.Exited += (sender, e) => Exited?.Invoke(sender, e); - } } } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs index fc3e1df7f7..5f55d6e35b 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/CmdConsoleProvider.cs @@ -2,6 +2,7 @@ { class CmdConsoleProvider : IConsoleProvider { - public IConsole GetConsole() => new CmdConsole(); + public IConsole GetConsole() => GetConsole(null); + public IConsole GetConsole(string workingDirectory) => new CmdConsole(workingDirectory); } } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs index 8149d0cc4e..717be6515c 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs @@ -131,7 +131,7 @@ public void Create() cmdHandle = Process.MainWindowHandle; window = AutomationElement.FromHandle(cmdHandle); WinApi.SetParent(cmdHandle, pnlClipping.Handle); - SendString("cls"); + SendString(" ",false); ResizeConsole(); } catch diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index 382d50bd48..e1e863b4d5 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -44,11 +44,10 @@ public void Initialize() { InitBasics(); LoadSettings(); - AddEventHandlers(); CreatePluginPanel(); CreateMenuItem(); CreateDefaultConsoleProvider(); - CreateConsolePanel(); + AddEventHandlers(); } public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) @@ -65,6 +64,9 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) } } break; + case EventType.UIStarted: + CreateConsolePanel(); + break; } } @@ -86,7 +88,11 @@ void LoadSettings() else settingObject = ObjectSerializer.Deserialize(settingFilename, settingObject); } - void AddEventHandlers() => EventManager.AddEventHandler(this, EventType.Command, HandlingPriority.Normal); + void AddEventHandlers() + { + EventManager.AddEventHandler(this, EventType.Command); + EventManager.AddEventHandler(this, EventType.UIStarted, HandlingPriority.Low); + } void SaveSettings() => ObjectSerializer.Serialize(settingFilename, settingObject); @@ -111,22 +117,23 @@ void CreateMenuItem() public IConsole CreateConsolePanel() { - var cmdPanel = ConsoleProvider.GetConsole(); - cmdPanel.Exited += (sender, args) => + var workingDirectory = PluginBase.CurrentProject?.GetAbsolutePath(string.Empty); + var panel = ConsoleProvider.GetConsole(workingDirectory); + panel.Exited += (sender, args) => { if (tabView.InvokeRequired) { tabView.Invoke((MethodInvoker)(() => { if (!PluginBase.MainForm.ClosingEntirely) - tabView.RemoveConsole(cmdPanel); + tabView.RemoveConsole(panel); })); } else if (!PluginBase.MainForm.ClosingEntirely) - tabView.RemoveConsole(cmdPanel); + tabView.RemoveConsole(panel); }; - tabView.AddConsole(cmdPanel); - return cmdPanel; + tabView.AddConsole(panel); + return panel; } } } From 98d74bb8148f5a093da99e7af593673526c17146 Mon Sep 17 00:00:00 2001 From: slavara Date: Wed, 25 Nov 2020 23:31:59 +0300 Subject: [PATCH 08/10] WIP --- .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 2 +- .../CmdProcess/ConsoleControl.cs | 21 ++++++++++++------- External/Plugins/ConsolePanel/PluginMain.cs | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs index 91249d2523..bac3651291 100644 --- a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -24,7 +24,7 @@ public TabbedConsole(PluginMain plugin) public void AddConsole(IConsole console) { - var tabPage = new TabPage("Console"); + var tabPage = new TabPage(console.ConsoleControl.Text); console.ConsoleControl.Dock = DockStyle.Fill; tabPage.Controls.Add(console.ConsoleControl); diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs index 717be6515c..85c302c119 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs @@ -43,9 +43,9 @@ public ConsoleColor ConsoleBackColor if (value == backColor) return; backColor = value; var trimmedFore = foreColor.ToString("X").TrimStart('0'); + if (trimmedFore.Length == 0) trimmedFore = "0"; var trimmedBack = backColor.ToString("X").TrimStart('0'); - if (trimmedFore == "") trimmedFore = "0"; - if (trimmedBack == "") trimmedBack = "0"; + if (trimmedBack.Length == 0) trimmedBack = "0"; SendString("color " + trimmedBack + trimmedFore); SendString("cls"); } @@ -59,9 +59,9 @@ public ConsoleColor ConsoleForeColor if (value == foreColor) return; foreColor = value; var trimmedFore = foreColor.ToString("X").TrimStart('0'); + if (trimmedFore.Length == 0) trimmedFore = "0"; var trimmedBack = backColor.ToString("X").TrimStart('0'); - if (trimmedFore == "") trimmedFore = "0"; - if (trimmedBack == "") trimmedBack = "0"; + if (trimmedBack.Length == 0) trimmedBack = "0"; SendString("color " + trimmedBack + trimmedFore); SendString("cls"); } @@ -115,11 +115,16 @@ public void Create() if (Process != null && !Process.HasExited) return; try { - Process = new Process(); - Process.StartInfo.FileName = "cmd"; + Process = new Process + { + StartInfo = + { + FileName = "cmd", + UseShellExecute = false, + }, + EnableRaisingEvents = true + }; if (lastWorkingDir != null) Process.StartInfo.WorkingDirectory = lastWorkingDir; - Process.StartInfo.UseShellExecute = false; - Process.EnableRaisingEvents = true; Process.Exited += Process_Exited; Process.Start(); diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index e1e863b4d5..94cf7c5e95 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -60,7 +60,7 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) { foreach (var panel in tabView.Consoles) { - panel.WorkingDirectory = PluginBase.CurrentProject.GetAbsolutePath(""); + panel.WorkingDirectory = PluginBase.CurrentProject.GetAbsolutePath(string.Empty); } } break; From 39dd46a4767548bcabbba6f5f0e4bc1f5d5f66c3 Mon Sep 17 00:00:00 2001 From: slavara Date: Thu, 26 Nov 2020 00:36:45 +0300 Subject: [PATCH 09/10] WIP --- .../Plugins/ConsolePanel/ConsolePanel.csproj | 2 ++ .../Plugins/ConsolePanel/Gui/TabbedConsole.cs | 8 +++---- .../CmdProcess/ConsoleControl.cs | 12 +++++++--- External/Plugins/ConsolePanel/PluginMain.cs | 24 +++++++++++++------ External/Plugins/ConsolePanel/WinApi.cs | 3 +++ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/External/Plugins/ConsolePanel/ConsolePanel.csproj b/External/Plugins/ConsolePanel/ConsolePanel.csproj index d511412387..8a24ee50d2 100644 --- a/External/Plugins/ConsolePanel/ConsolePanel.csproj +++ b/External/Plugins/ConsolePanel/ConsolePanel.csproj @@ -19,6 +19,7 @@ DEBUG;TRACE prompt 4 + preview pdbonly @@ -28,6 +29,7 @@ prompt 4 AnyCPU + preview diff --git a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs index bac3651291..315db4abab 100644 --- a/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs +++ b/External/Plugins/ConsolePanel/Gui/TabbedConsole.cs @@ -24,12 +24,12 @@ public TabbedConsole(PluginMain plugin) public void AddConsole(IConsole console) { - var tabPage = new TabPage(console.ConsoleControl.Text); + var tab = new TabPage(console.ConsoleControl.Text); console.ConsoleControl.Dock = DockStyle.Fill; - tabPage.Controls.Add(console.ConsoleControl); + tab.Controls.Add(console.ConsoleControl); - tabConsoles.TabPages.Add(tabPage); - tabConsoles.SelectTab(tabPage); + tabConsoles.TabPages.Add(tab); + tabConsoles.SelectTab(tab); consoleTabMap.Add(console, tabConsoles.SelectedTab); tabConsoleMap.Add(tabConsoles.SelectedTab, console); } diff --git a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs index 85c302c119..90d7d2b08f 100644 --- a/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs +++ b/External/Plugins/ConsolePanel/Implementation/CmdProcess/ConsoleControl.cs @@ -112,7 +112,7 @@ public void Cancel() /// public void Create() { - if (Process != null && !Process.HasExited) return; + if (Process is not null && !Process.HasExited) return; try { Process = new Process @@ -121,10 +121,11 @@ public void Create() { FileName = "cmd", UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden, }, EnableRaisingEvents = true }; - if (lastWorkingDir != null) Process.StartInfo.WorkingDirectory = lastWorkingDir; + if (lastWorkingDir is not null) Process.StartInfo.WorkingDirectory = lastWorkingDir; Process.Exited += Process_Exited; Process.Start(); @@ -142,6 +143,11 @@ public void Create() catch { } + + GotFocus += (sender, args) => + { + pnlClipping.Focus(); + }; } /// @@ -191,7 +197,7 @@ void RunCommandWithoutCache(string cmd) void ResizeConsole() { WinApi.ShowWindow(cmdHandle, WinApi.SW_SHOWMAXIMIZED); - WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(new Point(0, 0), Size)); + WinApi.ResizeClientRectTo(cmdHandle, new Rectangle(Point.Empty, Size)); SetRealConsoleSize(); var tooWide = realSize.Width > Width; var tooHigh = realSize.Height > Height; diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index 94cf7c5e95..08d93a375e 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -111,29 +111,39 @@ void CreateMenuItem() viewMenu.DropDownItems.Add(cmdItem); } - void OpenPanel(object sender, EventArgs e) => pluginPanel.Show(); + void OpenPanel(object sender, EventArgs e) + { + if (tabView.Consoles.Count == 0) CreateConsolePanel(); + pluginPanel.Show(); + } void CreateDefaultConsoleProvider() => ConsoleProvider = new Implementation.CmdProcess.CmdConsoleProvider(); public IConsole CreateConsolePanel() { var workingDirectory = PluginBase.CurrentProject?.GetAbsolutePath(string.Empty); - var panel = ConsoleProvider.GetConsole(workingDirectory); - panel.Exited += (sender, args) => + var console = ConsoleProvider.GetConsole(workingDirectory); + console.Exited += (sender, args) => { if (tabView.InvokeRequired) { tabView.Invoke((MethodInvoker)(() => { if (!PluginBase.MainForm.ClosingEntirely) - tabView.RemoveConsole(panel); + { + tabView.RemoveConsole(console); + if (tabView.Consoles.Count == 0) pluginPanel.Hide(); + } })); } else if (!PluginBase.MainForm.ClosingEntirely) - tabView.RemoveConsole(panel); + { + tabView.RemoveConsole(console); + if (tabView.Consoles.Count == 0) pluginPanel.Hide(); + } }; - tabView.AddConsole(panel); - return panel; + tabView.AddConsole(console); + return console; } } } diff --git a/External/Plugins/ConsolePanel/WinApi.cs b/External/Plugins/ConsolePanel/WinApi.cs index 2840f9be57..ed179804c5 100644 --- a/External/Plugins/ConsolePanel/WinApi.cs +++ b/External/Plugins/ConsolePanel/WinApi.cs @@ -77,5 +77,8 @@ public static void ResizeClientRectTo(IntPtr hWnd, Rectangle desired) AdjustWindowRect(ref size, style, false); MoveWindow(hWnd, size.Left, size.Top, size.Right - size.Left, size.Bottom - size.Top, true); } + + [DllImport("user32.dll")] + public static extern IntPtr SetFocus(IntPtr hWnd); } } From 210ee87e4c426f18d5b5b18d774bceaa312ccd12 Mon Sep 17 00:00:00 2001 From: slavara Date: Thu, 26 Nov 2020 00:43:43 +0300 Subject: [PATCH 10/10] WIP --- External/Plugins/ConsolePanel/PluginMain.cs | 25 ++++++++------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/External/Plugins/ConsolePanel/PluginMain.cs b/External/Plugins/ConsolePanel/PluginMain.cs index 08d93a375e..0add6c4a51 100644 --- a/External/Plugins/ConsolePanel/PluginMain.cs +++ b/External/Plugins/ConsolePanel/PluginMain.cs @@ -125,25 +125,18 @@ public IConsole CreateConsolePanel() var console = ConsoleProvider.GetConsole(workingDirectory); console.Exited += (sender, args) => { - if (tabView.InvokeRequired) - { - tabView.Invoke((MethodInvoker)(() => - { - if (!PluginBase.MainForm.ClosingEntirely) - { - tabView.RemoveConsole(console); - if (tabView.Consoles.Count == 0) pluginPanel.Hide(); - } - })); - } - else if (!PluginBase.MainForm.ClosingEntirely) - { - tabView.RemoveConsole(console); - if (tabView.Consoles.Count == 0) pluginPanel.Hide(); - } + if (tabView.InvokeRequired) tabView.Invoke((MethodInvoker) RemoveConsole); + else RemoveConsole(); }; tabView.AddConsole(console); return console; + // Utils + void RemoveConsole() + { + if (PluginBase.MainForm.ClosingEntirely) return; + tabView.RemoveConsole(console); + if (tabView.Consoles.Count == 0) pluginPanel.Hide(); + } } } }