Changeset 13762
- Timestamp:
- 04/14/16 14:13:57 (9 years ago)
- Location:
- branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs
r13716 r13762 34 34 protected bool RenderingRequired; 35 35 protected Dictionary<Type, ChartMode> Modes = new Dictionary<Type, ChartMode>(); 36 protected Stack<ChartMode> ModeStack = new Stack<ChartMode>(); 37 protected List<ChartMode.Shortcut> Shortcuts = new List<ChartMode.Shortcut>(); 38 protected ChartMode.Shortcut ActiveShortcut; 36 39 37 40 protected bool SuppressEvents { get; set; } … … 88 91 89 92 public void AddChartModes(params ChartMode[] chartModes) { 90 foreach (var chartMode in chartModes) 93 foreach (var chartMode in chartModes) { 91 94 Modes.Add(chartMode.GetType(), chartMode); 95 foreach (var shortcut in chartMode.Shortcuts) 96 Shortcuts.Add(shortcut); 97 } 92 98 93 99 ReloadModeToolBar(); 94 100 ReloadModeContextMenu(); 101 } 102 103 public void SetTempChartMode(ChartMode chartMode) { 104 if (Mode == chartMode) return; 105 106 ModeStack.Push(mode); 107 Mode = chartMode; 108 } 109 110 public void ResetTempChartMode() { 111 if (ModeStack.Any()) 112 Mode = ModeStack.Pop(); 95 113 } 96 114 … … 203 221 204 222 protected virtual void OnKeyDown(object sender, KeyEventArgs e) { 205 if (mode != null) 223 if (mode != null) { 206 224 mode.HandleOnKeyDown(sender, e); 225 226 if (e.Handled || ActiveShortcut != null) return; 227 228 foreach (var shortcut in Shortcuts) { 229 if (e.KeyCode == shortcut.Key && e.Modifiers == shortcut.Modifiers) { 230 ActiveShortcut = shortcut; 231 shortcut.DownAction(); 232 break; 233 } 234 } 235 } 207 236 } 208 237 209 238 protected virtual void OnKeyUp(object sender, KeyEventArgs e) { 210 if (mode != null) 239 if (mode != null) { 211 240 mode.HandleOnKeyUp(sender, e); 241 242 if (e.Handled || ActiveShortcut == null) return; 243 244 var modifiers = new List<Keys>(from key in Enum.GetValues(typeof(Keys)).Cast<Keys>() 245 where e.Modifiers.HasFlag(key) 246 select key); 247 248 if (ActiveShortcut.Key == e.KeyCode || ActiveShortcut.GetModifiers().Except(modifiers).Any()) { 249 ActiveShortcut.UpAction(); 250 ActiveShortcut = null; 251 } 252 } 212 253 } 213 254 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartMode.cs
r13717 r13762 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Drawing; 25 using System.Linq; 24 26 using System.Windows.Forms; 25 27 … … 27 29 public abstract class ChartMode { 28 30 protected readonly ChartControl chartControl; 31 protected readonly IList<Shortcut> globalShortcuts = new List<Shortcut>(); 32 protected readonly IList<Shortcut> localShortcuts; 33 protected Shortcut activeShortcut = null; 29 34 protected Cursor cursor; 30 35 protected Point buttonDownPoint; … … 59 64 } 60 65 66 public IEnumerable<Shortcut> Shortcuts { get { return globalShortcuts; } } 67 61 68 protected ChartMode(ChartControl control) { 62 69 chartControl = control; 63 70 chartControl.ModeChanged += (sender, args) => Selected = chartControl.Mode == this; 71 localShortcuts = new List<Shortcut> { 72 new Shortcut(Keys.Escape) { DownAction = Deselect } 73 }; 64 74 } 65 75 … … 71 81 72 82 public virtual void HandleOnKeyDown(object sender, KeyEventArgs e) { 73 switch (e.KeyCode) { 74 case Keys.Escape: 75 Deselect(); 83 if (activeShortcut != null) return; 84 85 foreach (var shortcut in localShortcuts) { 86 if (e.KeyCode == shortcut.Key && e.Modifiers == shortcut.Modifiers) { 87 activeShortcut = shortcut; 88 shortcut.DownAction(); 76 89 break; 90 } 77 91 } 78 92 } 79 93 80 public virtual void HandleOnKeyUp(object sender, KeyEventArgs e) { } 94 public virtual void HandleOnKeyUp(object sender, KeyEventArgs e) { 95 if (activeShortcut == null) return; 96 97 var modifiers = new List<Keys>(from key in Enum.GetValues(typeof(Keys)).Cast<Keys>() 98 where e.Modifiers.HasFlag(key) 99 select key); 100 101 if (activeShortcut.Key == e.KeyCode || activeShortcut.GetModifiers().Except(modifiers).Any()) { 102 activeShortcut.UpAction(); 103 activeShortcut = null; 104 } 105 } 106 81 107 public virtual void HandleOnMouseClick(object sender, MouseEventArgs e) { } 82 108 public virtual void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) { } … … 103 129 if (handler != null) handler(this, EventArgs.Empty); 104 130 } 131 132 public class Shortcut { 133 public Keys Key { get; private set; } 134 public Keys Modifiers { get; private set; } 135 public Action DownAction { get; set; } 136 public Action UpAction { get; set; } 137 138 public Shortcut(Keys key, Keys modifiers = Keys.None) { 139 Key = key; 140 Modifiers = modifiers; 141 } 142 143 public IEnumerable<Keys> GetModifiers() { 144 var keys = new List<Keys>(from key in Enum.GetValues(typeof(Keys)).Cast<Keys>() 145 where Modifiers.HasFlag(key) 146 select key); 147 return keys; 148 } 149 } 105 150 } 106 151 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/PanChartMode.cs
r13717 r13762 33 33 } 34 34 35 public PanChartMode(ChartControl control) : base(control) { } 35 public PanChartMode(ChartControl control) : base(control) { 36 globalShortcuts.Add(new Shortcut(Keys.Space) { 37 DownAction = () => chartControl.SetTempChartMode(this), 38 UpAction = () => chartControl.ResetTempChartMode() 39 }); 40 } 36 41 37 42 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs
r13717 r13762 31 31 public override string ToolTipText { get { return "Select"; } } 32 32 33 public SelectChartMode(ChartControl control) : base(control) { } 33 public SelectChartMode(ChartControl control) : base(control) { 34 localShortcuts.Add(new Shortcut(Keys.Delete) { DownAction = DeleteSelectedPrimitives }); 35 } 34 36 35 37 protected override void OnDeselected() { … … 41 43 chartControl.ResumeRendering(); 42 44 base.OnDeselected(); 43 }44 }45 46 public override void HandleOnKeyDown(object sender, KeyEventArgs e) {47 try {48 switch (e.KeyCode) {49 case Keys.Delete:50 try {51 chartControl.SuspendRendering();52 foreach (var p in chartControl.Chart.Group.SelectedPrimitives)53 chartControl.Chart.Group.Remove(p);54 } finally { chartControl.ResumeRendering(); }55 break;56 }57 } finally {58 base.HandleOnKeyDown(sender, e);59 45 } 60 46 } … … 100 86 } 101 87 } 88 89 protected virtual void DeleteSelectedPrimitives() { 90 try { 91 chartControl.SuspendRendering(); 92 foreach (var p in chartControl.Chart.Group.SelectedPrimitives) 93 chartControl.Chart.Group.Remove(p); 94 } finally { chartControl.ResumeRendering(); } 95 } 102 96 } 103 97 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomInChartMode.cs
r13717 r13762 35 35 } 36 36 37 public ZoomInChartMode(ChartControl control) : base(control) { } 37 public ZoomInChartMode(ChartControl control) : base(control) { 38 globalShortcuts.Add(new Shortcut(Keys.Z, Keys.Control) { 39 DownAction = () => chartControl.SetTempChartMode(this), 40 UpAction = () => chartControl.ResetTempChartMode() 41 }); 42 } 38 43 39 44 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomOutChartMode.cs
r13717 r13762 33 33 } 34 34 35 public ZoomOutChartMode(ChartControl control) : base(control) { } 35 public ZoomOutChartMode(ChartControl control) : base(control) { 36 globalShortcuts.Add(new Shortcut(Keys.Z, Keys.Control | Keys.Shift) { 37 DownAction = () => chartControl.SetTempChartMode(this), 38 UpAction = () => chartControl.ResetTempChartMode() 39 }); 40 } 36 41 37 42 public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.