|
| 1 | +using RdcMan; |
| 2 | +using System.Windows.Forms; |
| 3 | +using System.Xml; |
| 4 | +using System.ComponentModel.Composition; |
| 5 | +using System.Reflection; |
| 6 | +using System; |
| 7 | +using System.Text.RegularExpressions; |
| 8 | + |
| 9 | +namespace Plugin.TypeClipboard |
| 10 | +{ |
| 11 | + [Export(typeof(IPlugin))] |
| 12 | + public class TypeClipboard : IPlugin |
| 13 | + { |
| 14 | + Server TargetServer = null; |
| 15 | + |
| 16 | + public void OnContextMenu(System.Windows.Forms.ContextMenuStrip contextMenuStrip, RdcTreeNode node) |
| 17 | + { |
| 18 | + if ((node as GroupBase) == null) |
| 19 | + { |
| 20 | + if ((node as ServerBase) != null) |
| 21 | + { |
| 22 | + this.TargetServer = node as Server; |
| 23 | + ToolStripMenuItem NewMenuItem = new DelegateMenuItem("Type clipboard text", MenuNames.None, () => this.TypeClipboardText()); |
| 24 | + //NewMenuItem.Image = Properties.Resources.PowerShell5_32; |
| 25 | + |
| 26 | + contextMenuStrip.Items.Insert(contextMenuStrip.Items.Count - 1, NewMenuItem); |
| 27 | + contextMenuStrip.Items.Insert(contextMenuStrip.Items.Count - 1, new ToolStripSeparator()); |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public void OnDockServer(ServerBase server) |
| 33 | + { |
| 34 | + //MessageBox.Show("OnDockServer", "Plugin.TypeClipboard event", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 35 | + } |
| 36 | + |
| 37 | + public void OnUndockServer(IUndockedServerForm form) |
| 38 | + { |
| 39 | + //MessageBox.Show("OnUndockServer", "Plugin.TypeClipboard event", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 40 | + } |
| 41 | + |
| 42 | + public void PostLoad(IPluginContext context) |
| 43 | + { |
| 44 | + //MessageBox.Show("PostLoad", "Plugin.TypeClipboard event", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 45 | + } |
| 46 | + |
| 47 | + public void PreLoad(IPluginContext context, XmlNode xmlNode) |
| 48 | + { |
| 49 | + //MessageBox.Show("PreLoad", "Plugin.TypeClipboard event", MessageBoxButtons.OK ,MessageBoxIcon.Information); |
| 50 | + } |
| 51 | + |
| 52 | + public XmlNode SaveSettings() |
| 53 | + { |
| 54 | + //MessageBox.Show("SaveSettings", "Plugin.TypeClipboard event", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 55 | + return null; |
| 56 | + } |
| 57 | + |
| 58 | + public void Shutdown() |
| 59 | + { |
| 60 | + //MessageBox.Show("Shutdown", "Plugin.TypeClipboard event", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 61 | + } |
| 62 | + |
| 63 | + public void TypeClipboardText() |
| 64 | + { |
| 65 | + if(!this.TargetServer.IsConnected) { |
| 66 | + //MessageBox.Show("Not connected...", "Not connected...", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 67 | + return; |
| 68 | + } |
| 69 | + MethodInfo FocusMethod = this.TargetServer.GetType().GetMethod("Focus", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); |
| 70 | + FocusMethod.Invoke(this.TargetServer, null); |
| 71 | + |
| 72 | + string StuffToType = Clipboard.GetText(); |
| 73 | + //MessageBox.Show(StuffToType, "StuffToType", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 74 | + |
| 75 | + // Escape special chars which SendKeys is looking for: |
| 76 | + // https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys(v=vs.110).aspx |
| 77 | + string StuffToTypeEscaped = Regex.Replace(StuffToType, "[+^%~(){}]", "{$0}"); |
| 78 | + |
| 79 | + // Replace newlines with enter |
| 80 | + StuffToTypeEscaped = Regex.Replace(StuffToTypeEscaped, "\r\n?", "~"); |
| 81 | + |
| 82 | + //MessageBox.Show(StuffToTypeEscaped, "StuffToTypeEscaped", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 83 | + SendKeys.SendWait(StuffToTypeEscaped); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments