Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/14/16 14:13:57 (8 years ago)
Author:
jkarder
Message:

#1265: worked on visualization

  • added shortcut handling prototype
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs

    r13716 r13762  
    3434    protected bool RenderingRequired;
    3535    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;
    3639
    3740    protected bool SuppressEvents { get; set; }
     
    8891
    8992    public void AddChartModes(params ChartMode[] chartModes) {
    90       foreach (var chartMode in chartModes)
     93      foreach (var chartMode in chartModes) {
    9194        Modes.Add(chartMode.GetType(), chartMode);
     95        foreach (var shortcut in chartMode.Shortcuts)
     96          Shortcuts.Add(shortcut);
     97      }
    9298
    9399      ReloadModeToolBar();
    94100      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();
    95113    }
    96114
     
    203221
    204222    protected virtual void OnKeyDown(object sender, KeyEventArgs e) {
    205       if (mode != null)
     223      if (mode != null) {
    206224        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      }
    207236    }
    208237
    209238    protected virtual void OnKeyUp(object sender, KeyEventArgs e) {
    210       if (mode != null)
     239      if (mode != null) {
    211240        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      }
    212253    }
    213254
Note: See TracChangeset for help on using the changeset viewer.