Toolbar: drag commands from drop-downs onto the toolbar; pin icon; Customize Toolbar… (#295)
* Toolbar drop-downs highlight the row under the pointer and the keyboard focus (#288) A panel drop-down's command rows are full-width rows that take the theme's hover background (icon, label and shortcut on it) when hovered or focused. Up/Down move the focus through the enabled rows, Enter starts the command, Escape closes the drop-down. Rows publish `dropdown:<id>` and the highlighted one `dropdown_hot:<id>`; scenario s46 checks pointer and keyboard highlight. Fixes #288 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT * Toolbar: drag commands from drop-downs onto the toolbar; pin icon; Customize Toolbar… (#289) - A panel drop-down row drags onto the toolbar (a button or a panel's free space, with the drop line) and is pinned there; the dragged command's icon follows the pointer. - A toolbar button dragged off the toolbar, or back into the open drop-down, leaves it (its icon shows a cross while releasing would remove it). - A hovered drop-down row shows a pin at its end: click to pin or unpin. - Right-click on the toolbar's empty space: Customize Toolbar… (a window listing the tab's commands with check boxes, and Reset Toolbar) and Reset Toolbar; command menus have Customize Toolbar… too. - Still per workspace and tab, kept with the preferences. Toolbar buttons also publish `button:<id>`; scenario s47 drags a row to the toolbar, unpins by dragging off and into the drop-down, uses the pin icon and Customize Toolbar…, and checks it survives a restart. Fixes #289 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT * Toolbar drop-down pin: a push pin drawn in code (upright and filled when pinned); control protocol lists the toolbar handles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d99ab4bb1
commit
2cac9cad6a
7 files changed
+490
-27
No files matched your search
@@ -1,7 +1,11 @@
|
||||
//! Toolbar customisation: which commands each panel shows as buttons, per workspace and tab.
|
||||
//! A command's menu (right-click on a toolbar button, a panel drop-down row or an S box row)
|
||||
//! pins it to the toolbar, removes it, or pins it to the S box's favourites; buttons are dragged
|
||||
//! to reorder them within and between panels; Reset Toolbar restores the tab. Kept with the
|
||||
//! to reorder them within and between panels; a drop-down row dragged onto the toolbar pins it
|
||||
//! there, a button dragged off the toolbar (or back into the drop-down) leaves it; the pin icon
|
||||
//! on a hovered drop-down row pins or unpins; the toolbar's own menu (right-click its empty
|
||||
//! space) has Customize Toolbar… (a window listing every command of the tab with a check box)
|
||||
//! and Reset Toolbar; Reset Toolbar restores the tab. Kept with the
|
||||
//! preferences and exported or imported with the keyboard shortcuts.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
@@ -20,6 +24,8 @@ pub struct ToolbarCustom {
|
||||
/// `"<workspace>/<tab>/<panel>"` → the panel's buttons, in order (only panels the user
|
||||
/// changed).
|
||||
pub panels: BTreeMap<String, Vec<String>>,
|
||||
/// The Customize Toolbar window is open (not kept).
|
||||
pub customizing: bool,
|
||||
}
|
||||
|
||||
impl ToolbarCustom {
|
||||
@@ -130,6 +136,15 @@ pub fn reorder(app: &mut SolveApp, tab: &str, id: &str, panel: &str, before: Opt
|
||||
app.toolbar_custom.panels.insert(key(tab, panel), ids);
|
||||
}
|
||||
|
||||
/// The pin icon of a drop-down row: pin the command, or remove it when it is pinned.
|
||||
pub fn toggle(app: &mut SolveApp, tab: &str, id: &str) {
|
||||
if pinned_on(app, tab, id).is_some() {
|
||||
remove(app, tab, id);
|
||||
} else if let Err(e) = pin(app, tab, id) {
|
||||
app.set_status(e, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset Toolbar: a tab's panels back to their defaults.
|
||||
pub fn reset(app: &mut SolveApp, tab: &str) {
|
||||
let prefix = format!("{WORKSPACE}/{tab}/");
|
||||
@@ -149,10 +164,19 @@ pub fn command_items(app: &SolveApp, id: &str) -> Vec<Item> {
|
||||
});
|
||||
v.push(Item::action("ui.shortcutPin", if fav { "Unpin from Shortcuts" } else { "Pin to Shortcuts" }, "").with(json!({ "command": id })));
|
||||
v.push(Item::sep());
|
||||
v.push(Item::action("ui.toolbarCustomize", "Customize Toolbar…", ""));
|
||||
v.push(Item::action("ui.toolbarReset", "Reset Toolbar", "").with(json!({ "tab": tab })));
|
||||
v
|
||||
}
|
||||
|
||||
/// The toolbar's own menu (right-click on its empty space).
|
||||
pub fn toolbar_items(app: &SolveApp) -> Vec<Item> {
|
||||
vec![
|
||||
Item::action("ui.toolbarCustomize", "Customize Toolbar…", ""),
|
||||
Item::action("ui.toolbarReset", "Reset Toolbar", "").with(json!({ "tab": app.ui.tab })),
|
||||
]
|
||||
}
|
||||
|
||||
/// Run a toolbar item from a menu.
|
||||
pub fn run(app: &mut SolveApp, action: &str, p: &Value) {
|
||||
let tab = p.get("tab").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| app.ui.tab.clone());
|
||||
@@ -165,6 +189,7 @@ pub fn run(app: &mut SolveApp, action: &str, p: &Value) {
|
||||
}
|
||||
"ui.toolbarRemove" => remove(app, &tab, id),
|
||||
"ui.toolbarReset" => reset(app, &tab),
|
||||
"ui.toolbarCustomize" => app.toolbar_custom.customizing = true,
|
||||
"ui.shortcutPin" => app.sbox.toggle_pin(id),
|
||||
_ => {}
|
||||
}
|
||||
@@ -190,3 +215,67 @@ pub fn import(app: &mut SolveApp, v: &Value) -> Result<(), String> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Customize Toolbar: every command of the tab's panels with a check box (on the toolbar or
|
||||
/// not), how to drag them, and Reset Toolbar.
|
||||
pub fn window(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
if !app.toolbar_custom.customizing {
|
||||
return;
|
||||
}
|
||||
let t = crate::theme::Tokens::get();
|
||||
let tab = app.ui.tab.clone();
|
||||
let mut open = true;
|
||||
let mut changes: Vec<(&'static str, bool)> = Vec::new();
|
||||
let mut reset_tab = false;
|
||||
crate::frame::window(ctx, "Customize Toolbar", crate::frame::Width::Normal)
|
||||
.id(egui::Id::new("sc_toolbar_customize"))
|
||||
.open(&mut open)
|
||||
.default_height(520.0)
|
||||
.show(ctx, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} tab. Tick a command to give it a toolbar button. You can also drag a row of a panel's drop-down onto the toolbar, drag a button off the toolbar to remove it, or use the pin on a drop-down row.",
|
||||
app.tr_label(&tab)
|
||||
))
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical().max_height(400.0).show(ui, |ui| {
|
||||
for (panel, cmds, n) in panel_lists(&tab) {
|
||||
if cmds.is_empty() {
|
||||
continue;
|
||||
}
|
||||
ui.label(egui::RichText::new(app.tr_label(panel)).strong().size(11.0));
|
||||
let shown = buttons(app, &tab, panel, &cmds, n);
|
||||
for c in &cmds {
|
||||
let mut on = shown.iter().any(|b| b.id == c.id) || pinned_on(app, &tab, c.id).is_some();
|
||||
let r = ui.checkbox(&mut on, app.tr_label(c.label));
|
||||
crate::scenario::publish_handle(&format!("customize:{}", c.id), r.rect.left_center() + egui::vec2(8.0, 0.0));
|
||||
if r.changed() {
|
||||
changes.push((c.id, on));
|
||||
}
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Reset Toolbar").clicked() {
|
||||
reset_tab = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
for (id, on) in changes {
|
||||
if on {
|
||||
if let Err(e) = pin(app, &tab, id) {
|
||||
app.set_status(e, true);
|
||||
}
|
||||
} else {
|
||||
remove(app, &tab, id);
|
||||
}
|
||||
}
|
||||
if reset_tab {
|
||||
reset(app, &tab);
|
||||
}
|
||||
app.toolbar_custom.customizing = open;
|
||||
}
|
||||
Reference in new issue
Block a user