Skip to main content

gpui_graph/
actions.rs

1use gpui::{App, KeyBinding, actions};
2
3/// Key context set on a focused [`NetworkGraph`](crate::NetworkGraph).
4pub const KEY_CONTEXT: &str = "NetworkGraph";
5
6actions!(
7    network_graph,
8    [
9        /// Zoom in around the viewport center.
10        ZoomIn,
11        /// Zoom out around the viewport center.
12        ZoomOut,
13        /// Fit the whole graph into view.
14        FitView,
15        /// Clear the selection.
16        ClearSelection,
17        /// Move the selection to the nearest item on the left.
18        SelectLeft,
19        SelectRight,
20        SelectUp,
21        SelectDown,
22        /// Same as double-click: activate a node, or expand / collapse a group.
23        Activate,
24        /// Emit a context-menu event for the selection, as a right-click would.
25        OpenContextMenu,
26    ]
27);
28
29/// Register the default key bindings. Call once at startup, after `gpui_base::init`.
30pub fn init(cx: &mut App) {
31    let ctx = Some(KEY_CONTEXT);
32    cx.bind_keys([
33        KeyBinding::new("=", ZoomIn, ctx),
34        KeyBinding::new("+", ZoomIn, ctx),
35        KeyBinding::new("-", ZoomOut, ctx),
36        KeyBinding::new("0", FitView, ctx),
37        KeyBinding::new("escape", ClearSelection, ctx),
38        KeyBinding::new("left", SelectLeft, ctx),
39        KeyBinding::new("right", SelectRight, ctx),
40        KeyBinding::new("up", SelectUp, ctx),
41        KeyBinding::new("down", SelectDown, ctx),
42        KeyBinding::new("enter", Activate, ctx),
43        KeyBinding::new("shift-f10", OpenContextMenu, ctx),
44    ]);
45}