public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { string[] fileNames; string startingDir = Path.GetDirectoryName(documentWorkspace.FilePath); DialogResult result = DocumentWorkspace.ChooseFiles(documentWorkspace, out fileNames, true, startingDir); HistoryMemento retHA = null; if (result == DialogResult.OK) { Type oldToolType = documentWorkspace.GetToolType(); documentWorkspace.SetTool(null); retHA = ImportMultipleFiles(documentWorkspace, fileNames); Type newToolType; if (retHA != null) { CompoundHistoryMemento cha = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { retHA }); retHA = cha; newToolType = typeof(Tools.MoveTool); } else { newToolType = oldToolType; } documentWorkspace.SetToolFromType(newToolType); } return(retHA); }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { string[] strArray; string directoryName = Path.GetDirectoryName(documentWorkspace.FilePath); DialogResult result = DocumentWorkspace.ChooseFiles(documentWorkspace, out strArray, true, directoryName); HistoryMemento memento = null; if (result == DialogResult.OK) { System.Type type2; System.Type toolType = documentWorkspace.GetToolType(); documentWorkspace.ClearTool(); memento = this.ImportMultipleFiles(documentWorkspace, strArray); if (memento != null) { HistoryMemento[] actions = new HistoryMemento[] { memento }; CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, StaticImage, actions); memento = memento2; type2 = typeof(MoveSelectedPixelsTool); } else { type2 = toolType; } documentWorkspace.SetToolFromType(type2); } return(memento); }
public ToolHistoryMemento(DocumentWorkspace documentWorkspace, string name, ImageResource image) : base(name, image) { this.documentWorkspace = documentWorkspace; this.toolType = documentWorkspace.GetToolType(); }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { string[] fileNames; string startingDir = Path.GetDirectoryName(documentWorkspace.FilePath); DialogResult result = DocumentWorkspace.ChooseFiles(documentWorkspace, out fileNames, true, startingDir); HistoryMemento retHA = null; if (result == DialogResult.OK) { Type oldToolType = documentWorkspace.GetToolType(); documentWorkspace.SetTool(null); retHA = ImportMultipleFiles(documentWorkspace, fileNames); Type newToolType; if (retHA != null) { CompoundHistoryMemento cha = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { retHA }); retHA = cha; newToolType = typeof(Tools.MoveTool); } else { newToolType = oldToolType; } documentWorkspace.SetToolFromType(newToolType); } return retHA; }
/// <summary> /// This method is called when the tool is active and a keyboard key is pressed /// and released. If you respond to the keyboard key, set e.Handled to true. /// </summary> protected virtual void OnKeyPress(KeyPressEventArgs e) { if (!e.Handled && DocumentWorkspace.Focused) { int wsIndex = Array.IndexOf <char>(wildShortcuts, e.KeyChar); if (wsIndex != -1) { e.Handled = OnWildShortcutKey(wsIndex); } else if (e.KeyChar == swapColorsShortcut) { AppWorkspace.Widgets.ColorsForm.SwapUserColors(); e.Handled = true; } else if (e.KeyChar == decPenSizeShortcut) { AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-1.0f); e.Handled = true; } else if (e.KeyChar == decPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0) { AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-5.0f); e.Handled = true; } else if (e.KeyChar == incPenSizeShortcut) { AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+1.0f); e.Handled = true; } else if (e.KeyChar == incPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0) { AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+5.0f); e.Handled = true; } else { ToolInfo[] toolInfos = DocumentWorkspace.ToolInfos; Type currentToolType = DocumentWorkspace.GetToolType(); int currentTool = 0; if (0 != (ModifierKeys & Keys.Shift)) { Array.Reverse(toolInfos); } if (char.ToLower(this.HotKey) != char.ToLower(e.KeyChar) || (DateTime.Now - lastToolSwitch) > toolSwitchReset) { // If it's been a short time since they pressed a tool switching hotkey, // we will start from the beginning of this list. This helps to enable two things: // 1) If multiple tools have the same hotkey, the user may press that hotkey // to cycle through them // 2) After a period of time, pressing the hotkey will revert to always // choosing the first tool in that list of tools which have the same hotkey. currentTool = -1; } else { for (int t = 0; t < toolInfos.Length; ++t) { if (toolInfos[t].ToolType == currentToolType) { currentTool = t; break; } } } for (int t = 0; t < toolInfos.Length; ++t) { int newTool = (t + currentTool + 1) % toolInfos.Length; ToolInfo localToolInfo = toolInfos[newTool]; if (localToolInfo.ToolType == DocumentWorkspace.GetToolType() && localToolInfo.SkipIfActiveOnHotKey) { continue; } if (char.ToLower(localToolInfo.HotKey) == char.ToLower(e.KeyChar)) { if (!this.IsMouseDown) { AppWorkspace.Widgets.ToolsControl.SelectTool(localToolInfo.ToolType); } e.Handled = true; lastToolSwitch = DateTime.Now; break; } } // If the keypress is still not handled ... if (!e.Handled) { switch (e.KeyChar) { // By default, Esc/Enter clear the current selection if there is any case (char)13: // Enter case (char)27: // Escape if (this.mouseDown == 0 && !Selection.IsEmpty) { e.Handled = true; DocumentWorkspace.ExecuteFunction(new DeselectFunction()); } break; } } } } }