mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-22 18:41:44 +01:00
feat(shell): every panel opens and closes from the keyboard, and F4 hides them all (#456) (M8)
This commit is contained in:
1 parent
587d9c7839
commit
ab583b3da7
5 files changed
+173
-14
No files matched your search
+24
-2
@@ -526,6 +526,8 @@ pub struct App {
|
||||
pub dock: crate::dock::Layout,
|
||||
/// The dock's view state: a tab being dragged, where groups were drawn.
|
||||
pub dock_view: crate::dock_ui::DockView,
|
||||
/// Window › Hide Panels (F4): the arrangement to bring back, while every panel is hidden.
|
||||
pub hidden_panels: Option<crate::dock::Layout>,
|
||||
/// Window › Workspace › Manage Workspaces… (ADR 0087).
|
||||
pub manage_workspaces: crate::workspaces_window::Manage,
|
||||
/// The Motion Editor's view state: the property whose curve it shows, the picked key
|
||||
@@ -696,6 +698,18 @@ pub const VIEW_SHORTCUTS: &[(&str, &str)] = &[
|
||||
("F3", "view.find_next"),
|
||||
("Shift+F3", "view.find_prev"),
|
||||
("Alt+F3", "view.movie_explorer"),
|
||||
// Window › each panel, open and closed from the keyboard with Animate's keys (#456), and F4
|
||||
// for all of them at once. (Animate's Align key, Ctrl+K, is the command palette here: Align,
|
||||
// Layer Depth and the Motion Editor take a key in the shortcut editor, `VIEW_UNBOUND`.)
|
||||
("Ctrl+Alt+T", "view.panel.timeline"),
|
||||
("Ctrl+F2", "view.panel.tools"),
|
||||
("Ctrl+F3", "view.panel.properties"),
|
||||
("Ctrl+L", "view.panel.library"),
|
||||
("F2", "view.panel.output"),
|
||||
("Ctrl+Shift+F9", "view.panel.colour"),
|
||||
("Ctrl+F9", "view.panel.swatches"),
|
||||
("Ctrl+F10", "view.panel.history"),
|
||||
("F4", "view.hide_panels"),
|
||||
// The open documents (ADR 0112): Close and Close All as in Animate, and the tab keys of
|
||||
// browsers (Ctrl+Tab and Ctrl+Shift+Tab work too).
|
||||
("Ctrl+W", "view.close_document"),
|
||||
@@ -707,6 +721,9 @@ pub const VIEW_SHORTCUTS: &[(&str, &str)] = &[
|
||||
("]", "view.brush_larger"),
|
||||
];
|
||||
|
||||
/// View actions without a default key: they can be given one in the shortcut editor.
|
||||
pub const VIEW_UNBOUND: &[&str] = &["view.panel.align", "view.panel.layer_depth", "view.panel.motion_editor"];
|
||||
|
||||
impl App {
|
||||
/// Show the last update's result once the native window begins drawing.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -919,6 +936,7 @@ impl App {
|
||||
tl_heard: None,
|
||||
tl_refocus: false,
|
||||
menu_keys: Default::default(),
|
||||
hidden_panels: None,
|
||||
system_look: platform::SystemLook::default(),
|
||||
themes: Default::default(),
|
||||
themes_dir: None,
|
||||
@@ -4271,10 +4289,14 @@ impl App {
|
||||
self.run("timeline.goto", json!({"frame": 0}));
|
||||
}
|
||||
}
|
||||
"view.actions" => self.toggle_panel(crate::dock::Panel::Actions),
|
||||
"view.hide_panels" => self.toggle_hide_panels(),
|
||||
id if crate::dock::Panel::from_action(id).is_some() => {
|
||||
if let Some(p) = crate::dock::Panel::from_action(id) {
|
||||
self.window_menu_panel(p);
|
||||
}
|
||||
}
|
||||
"view.find_next" => crate::find_panel::step(self, true),
|
||||
"view.find_prev" => crate::find_panel::step(self, false),
|
||||
"view.movie_explorer" => crate::movie_explorer::open(self),
|
||||
"view.close_document" => crate::tabs::close_active(self),
|
||||
"view.close_all_documents" => crate::tabs::close_all(self),
|
||||
"view.next_document" => crate::tabs::step(self, true),
|
||||
|
||||
+24
@@ -56,6 +56,30 @@ impl Panel {
|
||||
}
|
||||
}
|
||||
|
||||
/// The action that opens and closes it from the keyboard (#456): bindable in the shortcut
|
||||
/// editor, shown beside its Window menu item.
|
||||
pub fn action(self) -> &'static str {
|
||||
match self {
|
||||
Panel::Properties => "view.panel.properties",
|
||||
Panel::Align => "view.panel.align",
|
||||
Panel::Colour => "view.panel.colour",
|
||||
Panel::Library => "view.panel.library",
|
||||
Panel::MovieExplorer => "view.movie_explorer",
|
||||
Panel::History => "view.panel.history",
|
||||
Panel::LayerDepth => "view.panel.layer_depth",
|
||||
Panel::Timeline => "view.panel.timeline",
|
||||
Panel::MotionEditor => "view.panel.motion_editor",
|
||||
Panel::Actions => "view.actions",
|
||||
Panel::Output => "view.panel.output",
|
||||
Panel::Swatches => "view.panel.swatches",
|
||||
Panel::Tools => "view.panel.tools",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_action(id: &str) -> Option<Panel> {
|
||||
Panel::ALL.into_iter().find(|p| p.action() == id)
|
||||
}
|
||||
|
||||
pub fn from_id(id: &str) -> Option<Panel> {
|
||||
Panel::ALL.into_iter().find(|p| p.id() == id)
|
||||
}
|
||||
|
||||
@@ -201,6 +201,7 @@ impl App {
|
||||
/// Brings a panel forward, reopening it where it was if it was closed; in a dock collapsed
|
||||
/// to icons it opens over the stage.
|
||||
pub fn show_panel(&mut self, p: Panel) {
|
||||
self.unhide_panels();
|
||||
if !self.dock.is_shown(p) {
|
||||
self.dock.show(p);
|
||||
self.dock_changed();
|
||||
@@ -212,6 +213,11 @@ impl App {
|
||||
|
||||
/// The Window menu's items: close a panel on screen, bring any other forward.
|
||||
pub fn toggle_panel(&mut self, p: Panel) {
|
||||
// Asked for while the panels are hidden: they all come back, with this one in front.
|
||||
if self.unhide_panels() {
|
||||
self.show_panel(p);
|
||||
return;
|
||||
}
|
||||
if !self.panel_visible(p) && self.dock.is_open(p) {
|
||||
self.show_panel(p);
|
||||
return;
|
||||
@@ -226,6 +232,52 @@ impl App {
|
||||
self.dock_changed();
|
||||
}
|
||||
|
||||
/// A panel's Window menu item, and its key (#456): closes the panel when it is in front,
|
||||
/// brings it forward otherwise.
|
||||
pub fn window_menu_panel(&mut self, p: Panel) {
|
||||
if p == Panel::MovieExplorer && !self.panel_visible(p) {
|
||||
crate::movie_explorer::open(self);
|
||||
} else {
|
||||
self.toggle_panel(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// Window › Hide Panels (F4, as in Animate; #456): every panel closes and the stage takes
|
||||
/// the window; the same key brings them back exactly as they were. The hidden state is for
|
||||
/// now only: it is never what a workspace remembers, so a restart shows the panels.
|
||||
pub fn toggle_hide_panels(&mut self) {
|
||||
if self.unhide_panels() {
|
||||
return;
|
||||
}
|
||||
let open: Vec<Panel> = Panel::ALL.into_iter().filter(|p| self.dock.is_open(*p)).collect();
|
||||
if open.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.hidden_panels = Some(self.dock.clone());
|
||||
for p in open {
|
||||
self.dock.close(p);
|
||||
}
|
||||
self.dock_view.epoch += 1;
|
||||
self.dock_view.placed.clear();
|
||||
self.dock_view.flyout = None;
|
||||
let key = self.keymap.primary("view.hide_panels").map(crate::platform::shortcut_label);
|
||||
self.status_ok(match key {
|
||||
Some(k) => tr!("Panels hidden: {key} brings them back", key = k),
|
||||
None => tr!("Panels hidden: Window › Show Panels brings them back").to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
/// Brings back the panels Hide Panels hid. True when there were any.
|
||||
pub fn unhide_panels(&mut self) -> bool {
|
||||
match self.hidden_panels.take() {
|
||||
Some(l) => {
|
||||
self.set_layout(l);
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the arrangement as the current workspace's, to be saved.
|
||||
pub fn dock_changed(&mut self) {
|
||||
self.prefs.workspaces.keep(&self.dock);
|
||||
@@ -234,6 +286,7 @@ impl App {
|
||||
|
||||
/// Window › Workspace: switches to a workspace, as it was last arranged.
|
||||
pub fn switch_workspace(&mut self, key: &str) {
|
||||
self.unhide_panels();
|
||||
self.prefs.workspaces.keep(&self.dock);
|
||||
if let Some(l) = self.prefs.workspaces.switch(key) {
|
||||
self.set_layout(l);
|
||||
@@ -242,6 +295,7 @@ impl App {
|
||||
|
||||
/// Window › Workspace › Reset: the current workspace as built or saved.
|
||||
pub fn reset_workspace(&mut self) {
|
||||
self.hidden_panels = None;
|
||||
let l = self.prefs.workspaces.reset();
|
||||
self.set_layout(l);
|
||||
let name = crate::i18n::t_dyn(crate::dock::Workspaces::name(&self.prefs.workspaces.current)).into_owned();
|
||||
@@ -1370,6 +1424,46 @@ mod tests {
|
||||
ctx.run_ui(input(events), |ui| app.frame(ui)).textures_delta.clear();
|
||||
}
|
||||
|
||||
/// #456: every panel opens and closes from the keyboard, and F4 hides them all and brings
|
||||
/// them back as they were, without the hidden state becoming the workspace's.
|
||||
#[test]
|
||||
fn panels_toggle_from_the_keyboard_and_f4_hides_them_all() {
|
||||
use egui::{Key, Modifiers};
|
||||
let (mut app, ctx) = app();
|
||||
settle(&ctx, &mut app);
|
||||
let press = |ctx: &egui::Context, app: &mut App, key: Key, modifiers: Modifiers| {
|
||||
frame(ctx, app, vec![egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }]);
|
||||
settle(ctx, app);
|
||||
};
|
||||
let ctrl = Modifiers::COMMAND;
|
||||
assert!(app.panel_visible(Panel::Library) && app.panel_visible(Panel::Timeline));
|
||||
press(&ctx, &mut app, Key::L, ctrl);
|
||||
assert!(!app.dock.is_open(Panel::Library), "Ctrl+L closes the Library");
|
||||
press(&ctx, &mut app, Key::L, ctrl);
|
||||
assert!(app.panel_visible(Panel::Library), "and opens it again where it was");
|
||||
press(&ctx, &mut app, Key::T, ctrl | Modifiers::ALT);
|
||||
assert!(!app.dock.is_open(Panel::Timeline));
|
||||
press(&ctx, &mut app, Key::T, ctrl | Modifiers::ALT);
|
||||
assert!(app.panel_visible(Panel::Timeline));
|
||||
|
||||
let before = app.dock.clone();
|
||||
let kept = app.prefs.workspaces.layout();
|
||||
press(&ctx, &mut app, Key::F4, Modifiers::NONE);
|
||||
assert!(Panel::ALL.into_iter().all(|p| !app.dock.is_open(p)), "F4 hides every panel");
|
||||
assert_eq!(app.prefs.workspaces.layout(), kept, "the workspace keeps its panels");
|
||||
press(&ctx, &mut app, Key::F4, Modifiers::NONE);
|
||||
assert_eq!(app.dock, before, "F4 again: exactly as they were");
|
||||
// A panel asked for while they are hidden brings them all back, with it in front.
|
||||
press(&ctx, &mut app, Key::F4, Modifiers::NONE);
|
||||
press(&ctx, &mut app, Key::F9, ctrl);
|
||||
assert!(app.panel_visible(Panel::Swatches) && app.panel_visible(Panel::Timeline) && app.panel_visible(Panel::Library));
|
||||
assert!(app.hidden_panels.is_none());
|
||||
// Hidden panels do not outlive a workspace change.
|
||||
app.toggle_hide_panels();
|
||||
app.switch_workspace("animator");
|
||||
assert!(app.hidden_panels.is_none() && app.dock.is_open(Panel::Timeline));
|
||||
}
|
||||
|
||||
pub(crate) fn settle(ctx: &egui::Context, app: &mut App) {
|
||||
for _ in 0..3 {
|
||||
frame(ctx, app, Vec::new());
|
||||
|
||||
+23
-2
@@ -7,7 +7,7 @@
|
||||
//! ones that open this editor, the palette and preferences, quitting, playing and cancelling.
|
||||
//! A chord is written in registry notation, modifiers in a fixed order: `Ctrl+Alt+Shift+K`.
|
||||
|
||||
use crate::app::{Tool, VIEW_SHORTCUTS};
|
||||
use crate::app::{Tool, VIEW_SHORTCUTS, VIEW_UNBOUND};
|
||||
use anicraft_engine::{SHORTCUT_ALIASES, commands};
|
||||
use egui::{Key, Modifiers};
|
||||
use std::cell::RefCell;
|
||||
@@ -89,6 +89,18 @@ fn view_label(id: &str) -> &'static str {
|
||||
"view.find_next" => tr_noop!("Find Next"),
|
||||
"view.find_prev" => tr_noop!("Find Previous"),
|
||||
"view.movie_explorer" => tr_noop!("Movie Explorer"),
|
||||
"view.panel.properties" => tr_noop!("Properties Panel"),
|
||||
"view.panel.align" => tr_noop!("Align Panel"),
|
||||
"view.panel.colour" => tr_noop!("Colour Panel"),
|
||||
"view.panel.library" => tr_noop!("Library Panel"),
|
||||
"view.panel.history" => tr_noop!("History Panel"),
|
||||
"view.panel.layer_depth" => tr_noop!("Layer Depth Panel"),
|
||||
"view.panel.timeline" => tr_noop!("Timeline Panel"),
|
||||
"view.panel.motion_editor" => tr_noop!("Motion Editor Panel"),
|
||||
"view.panel.output" => tr_noop!("Output Panel"),
|
||||
"view.panel.swatches" => tr_noop!("Swatches Panel"),
|
||||
"view.panel.tools" => tr_noop!("Tools Panel"),
|
||||
"view.hide_panels" => tr_noop!("Hide Panels / Show Panels"),
|
||||
"view.close_document" => tr_noop!("Close Document"),
|
||||
"view.close_all_documents" => tr_noop!("Close All Documents"),
|
||||
"view.next_document" => tr_noop!("Next Document"),
|
||||
@@ -162,7 +174,7 @@ pub fn actions() -> Vec<Action> {
|
||||
.collect();
|
||||
v.extend(Tool::ALL.into_iter().map(|t| Action { id: tool_id(t), label: t.label(), group: tr_noop!("Tools"), defaults: t.shortcut().into_iter().collect() }));
|
||||
let mut views: Vec<&str> = Vec::new();
|
||||
for (_, id) in VIEW_SHORTCUTS {
|
||||
for id in VIEW_SHORTCUTS.iter().map(|(_, id)| id).chain(VIEW_UNBOUND) {
|
||||
if !views.contains(id) {
|
||||
views.push(id);
|
||||
}
|
||||
@@ -441,6 +453,15 @@ mod tests {
|
||||
assert_eq!(m.keys("view.brush_smaller"), ["["]);
|
||||
assert_eq!(m.keys("view.brush_larger"), ["]"]);
|
||||
assert_eq!(m.primary("view.onion"), Some("Alt+Shift+O"));
|
||||
// #456: every panel is an action, with Animate's key where it is free.
|
||||
for p in crate::dock::Panel::ALL {
|
||||
assert!(m.actions.iter().any(|a| a.id == p.action() && a.label != "View action"), "{p:?} has no action");
|
||||
assert_eq!(crate::dock::Panel::from_action(p.action()), Some(p));
|
||||
}
|
||||
assert_eq!(m.primary("view.panel.library"), Some("Ctrl+L"));
|
||||
assert_eq!(m.primary("view.panel.timeline"), Some("Ctrl+Alt+T"));
|
||||
assert_eq!(m.primary("view.panel.align"), None, "Ctrl+K is the command palette");
|
||||
assert_eq!(m.primary("view.hide_panels"), Some("F4"));
|
||||
assert_eq!(m.owner("ctrl+z").map(|a| a.id), None, "chords are case-sensitive registry names");
|
||||
assert_eq!(m.owner("Ctrl+Shift+Z").map(|a| a.id), Some("modify.remove_transform"));
|
||||
let mut all: Vec<String> = m.actions.iter().flat_map(|a| m.keys(a.id).to_vec()).collect();
|
||||
|
||||
+8
-10
@@ -730,19 +730,17 @@ pub(crate) fn menu_contents(app: &mut App, ui: &mut egui::Ui, top: &str, cmds: &
|
||||
// Every panel: ticked while it is in front; choosing one brings it forward, or
|
||||
// closes it when it already is.
|
||||
for p in crate::dock::Panel::ALL {
|
||||
let key = match p {
|
||||
crate::dock::Panel::Actions => app.keymap.primary("view.actions").unwrap_or(""),
|
||||
crate::dock::Panel::MovieExplorer => app.keymap.primary("view.movie_explorer").unwrap_or(""),
|
||||
_ => "",
|
||||
};
|
||||
// Its key, as set in the shortcut editor (#456).
|
||||
let key = app.keymap.primary(p.action()).unwrap_or("");
|
||||
if ui_item(ui, crate::i18n::t(p.label()), key, Some(app.panel_visible(p))) {
|
||||
if p == crate::dock::Panel::MovieExplorer && !app.panel_visible(p) {
|
||||
crate::movie_explorer::open(app);
|
||||
} else {
|
||||
app.toggle_panel(p);
|
||||
}
|
||||
app.window_menu_panel(p);
|
||||
}
|
||||
}
|
||||
// Every panel at once (F4, as in Animate): the stage takes the window.
|
||||
let key = app.keymap.primary("view.hide_panels").unwrap_or("");
|
||||
if ui_item(ui, if app.hidden_panels.is_some() { tr!("Show Panels") } else { tr!("Hide Panels") }, key, None) {
|
||||
app.toggle_hide_panels();
|
||||
}
|
||||
// Brush presets with previews, and your own (ADR 0068).
|
||||
if ui_item(ui, tr!("Brush Library"), "", Some(app.brush_lib.open)) {
|
||||
crate::brush_panel::toggle(app);
|
||||
|
||||
Reference in new issue
Block a user