perspective_viewer/components/main_panel/msg.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use std::rc::Rc;
14
15use crate::components::panel_menu::PanelCommand;
16use crate::queries::ResolvedCommands;
17
18/// Which surface a context-menu gesture landed on.
19#[derive(Clone, Copy, Debug, PartialEq, Eq)]
20pub enum MenuOrigin {
21 /// Inside a panel's frame, where its plugin can be hit-tested.
22 Body,
23
24 /// On a panel's tab.
25 Tab,
26
27 /// Anywhere else in the element.
28 Chrome,
29}
30
31/// A context-menu gesture: where it happened and the panel it targets.
32#[derive(Debug)]
33pub struct MenuRequest {
34 pub x: f64,
35 pub y: f64,
36 pub panel: Option<String>,
37}
38
39#[derive(Debug)]
40pub enum MainPanelMsg {
41 PointerEvent(web_sys::PointerEvent),
42
43 /// A panel's `PanelPhase` changed (`staged_changed` PubSub — see
44 /// `Workspace::insert_panel`/`promote`): re-render so cells/tabs/wrappers
45 /// reflect it and `reconcile` inserts a promoted panel. Subscribed on
46 /// MainPanel's OWN scope — the root's `LayoutChanged` delivery proved
47 /// unreliable from element-API task contexts (promoted panels stranded
48 /// in their hidden wrappers), while this component's own messages
49 /// deliver in every observed context.
50 StagedChanged,
51
52 /// A layout tree was staged for the retained panel set
53 /// (`layout_staged` PubSub): re-render so `reconcile` applies it.
54 LayoutStaged,
55
56 /// The `<regular-layout>` tree changed (fired by its
57 /// `regular-layout-update` event). Used to detect panels removed from
58 /// the layout (e.g. a frame's close button) so they can be disposed.
59 LayoutUpdated,
60
61 /// A tab was selected (fired by `regular-layout-select`, `detail.name`);
62 /// the selected panel becomes the active panel. This is
63 /// regular-layout's own selection signal, so it resolves the correct
64 /// panel within a stack.
65 TabSelected(String),
66
67 /// A pointerdown landed inside the named panel's frame.
68 PanelPointerDown(String),
69
70 /// The layout is about to resize its cells (fired by the cancelable
71 /// `regular-layout-before-resize`). Carries the event so its
72 /// `PresizeDetail` can pre-size each panel's plugin to its target box
73 /// before the layout commits — avoiding the post-commit resize
74 /// shear/clip. The handler (`onbeforeresize` closure) has already
75 /// `preventDefault()`-ed it.
76 BeforeResize(web_sys::Event),
77
78 /// A right-click opened the panel context menu (target panel id, client
79 /// x, y). Fired by the imperative `contextmenu` listener on the viewer
80 /// host — see `_contextmenu_listener` — and by each `PanelTab`.
81 /// `Some(id)` activates that panel and opens its
82 /// [`PanelMenu`](crate::components::panel_menu::PanelMenu) at the
83 /// cursor; `None` (no frame on the composed path — status bar,
84 /// sidebars, the empty stage) resolves to the ACTIVE panel, else to a
85 /// target-less menu offering only "New", whose items create the first
86 /// panel.
87 ContextMenu(Option<String>, f64, f64, MenuOrigin),
88
89 /// The custom commands for a pending context-menu gesture resolved.
90 ContextMenuResolved(Rc<MenuRequest>, ResolvedCommands),
91
92 /// The open context menu selected a custom command, by key.
93 CustomCommand(String),
94
95 /// Dismiss the panel context menu (the menu session ended).
96 CloseContextMenu,
97
98 /// The open context menu selected a command. Maximize/Restore act on the
99 /// layout here; the rest forward to `on_panel_command`.
100 Command(PanelCommand),
101}