/// <summary> /// Getts shortcut from row as a string /// TODO: Move to that row /// </summary> /// <param name="row"></param> /// <returns></returns> protected string getShortcutAsAString(TemplatesDataSet.TemplatesRow row) { if (row.IsShortcut_KeyNull()) { return(""); } long key = row.Shortcut_Key; string shortcut_s = ""; if (row.Shortcut_Ctrl) { shortcut_s += "Ctrl + "; } if (row.Shortcut_Alt) { shortcut_s += "Alt + "; } if (row.Shortcut_Shift) { shortcut_s += "Shift + "; } if (row.Shortcut_Win) { shortcut_s += "Win + "; } shortcut_s += keyCode2Name((Keys)key); return(shortcut_s); }
protected bool editTemplate_dataRow(TemplatesDataSet.TemplatesRow r) { var w = new TemplateEditor(r); var res = w.ShowDialog(); w.Dispose(); if (res != DialogResult.OK) { return(false); } return(r.RowState != DataRowState.Unchanged); }
private void gridAddNewItem() { /// @link http://msdn.microsoft.com/en-us/library/5ycd1034(v=vs.80).aspx TemplatesDataSet.TemplatesRow r = (TemplatesDataSet.TemplatesRow) this.dataSet.Templates.NewRow(); if (this.editTemplate_dataRow(r)) { try { this.dataSet.Templates.Rows.Add(r); this.databaseSaveChangesOrShowErrorMessage(); } catch (Exception e) { this.showException("Your data aren't valid!", e); } } }
protected void onShortcutFired(object sender, KeyPressedEventArgs args) { if (this.CtrlVLock) { return; } KeyboardHook_item khi = (KeyboardHook_item)sender; TemplatesDataSet.TemplatesRow dr = (TemplatesDataSet.TemplatesRow)khi.CustomData; if (dr == null) { return; } string puvodniClipboard = Clipboard.GetText(); // Zaloha obsahu clipboard // Copy template to clipboard string template = dr.Template.Replace("\r\n", "\n"); // Mac, Unix newlines to Win newlines // Using application direct write // TODO: wait until KEYUP insted of 500ms pause Thread.Sleep(new TimeSpan(0, 0, 0, 0, 500)); String selectedText = ""; // Overring clipboard with current selection, if template wants to do that if (template.Contains("<copy!/>\n")) { try { selectedText = getSelectedTextUsingAutomationElement(); } catch (InvalidOperationException e) { // SMALL C here!!! Otherwise this sends CTRL+SHIFT+C SendKeys.SendWait("^(c)"); // Send CTRL+C SendKeys.Flush(); //Thread.Sleep(new TimeSpan(0, 0, 0, 0, 50)); selectedText = Clipboard.GetText(); } template = template.Replace("<copy!/>\n", ""); } // Macros template = template.Replace("<clipboard/>", selectedText); this.CtrlVLock = true; Clipboard.SetText(template); SendKeys.SendWait("^(v)"); // intentionally small 'v' SendKeys.Flush(); // wait before we restore clipboard this could fix problems with pasting original values Thread.Sleep(new TimeSpan(0, 0, 0, 0, 100)); try { if (puvodniClipboard != null) { Clipboard.SetText(puvodniClipboard); // obnovime puvodni obsah clipboardu } } catch (System.Runtime.InteropServices.ExternalException e) { /*do nothing*/ } this.CtrlVLock = false; // escape string // http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx // template = template.Replace("{", "----{{----") // .Replace("}", "----}}----") // .Replace("----{{----", "{{}") // .Replace("----}}----", "{}}") // .Replace("+", "{+}") // .Replace("^", "{^}") // .Replace("%", "{%}") // .Replace("~", "{~}") // .Replace("(", "{(}") // .Replace(")", "{)}") // .Replace("[", "{[}") // .Replace("]", "{]}") // // .Replace("\n", "{ENTER}") // .Replace("\r", "{ENTER}"); // Send result to application // SendKeys.SendWait(template); // SendKeys.Flush(); // Notify, that all has been done //this.notifyIcon.ShowBalloonTip(1, "ClipboardTemplates", "Template has been sent to application.", ToolTipIcon.Info); // Copy to clipboard //var originalClipboardContent = Clipboard.GetDataObject(); //Clipboard.SetText(dr.Template); // //this.notifyIcon.ShowBalloonTip(1, "ClipboardTemplate", "Your template has been copied to clipboard", ToolTipIcon.Info); // ////Thread.Sleep(new TimeSpan(0,0,0,0,250)); // ////SendKeys.SendWait("^V"); ////SendKeys.SendWait("+{INSERT}"); // //Clipboard.SetDataObject(originalClipboardContent); }