mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Toolbars: Rename Button works on a button whose command is dimmed
A context menu owned by a disabled button takes no clicks with the current craft-libs, so Rename Button... on a dimmed button opened no dialog. The row around the button now owns the menu, and a right click on the button opens it.
This commit is contained in:
1 parent
cfa2bbb878
commit
7d9cd73f5f
1 file changed
+17
-8
@@ -32,6 +32,7 @@ use craft::ui::buttons::{Button, IconButton};
|
||||
use craft::ui::contract::{Bind, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use craft::ui::dialog::DialogResult;
|
||||
use craft::ui::display::{Divider, Shade, Text};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::patterns::form_dialogs::{
|
||||
DialogFields, FieldValue, HostedListManager, HostedParamDialog, ListManagerAction, ListManagerChoice, ListManagerEntry, ListManagerWords, Param,
|
||||
@@ -895,21 +896,29 @@ fn command_button(app: &VectorcraftApp, ui: &mut egui::Ui, bar: &str, look: &Com
|
||||
(Some(t), Some(keys)) => format!("{} {keys}", t.name),
|
||||
(Some(t), None) => t.name.clone(),
|
||||
};
|
||||
let button = match &look.text {
|
||||
Some(t) => Button::command(t.command.clone()).label(look.said()),
|
||||
None => Button::new(look.said()).enabled(false),
|
||||
};
|
||||
// The face paints the label; the accessible name stays `said`.
|
||||
let button = if look.own.is_some() { button.painted(look.label().to_string()) } else { button };
|
||||
let response = button.tooltip(tip).show(ui).response;
|
||||
let mut response = None;
|
||||
// A menu owned by a dimmed button takes no clicks, so the row around the button owns the menu and a right
|
||||
// click on the button opens it: Rename Button… and the rest work while the command is dimmed.
|
||||
let row = Row::new()
|
||||
.show(ui, |ui, _| {
|
||||
let button = match &look.text {
|
||||
Some(t) => Button::command(t.command.clone()).label(look.said()),
|
||||
None => Button::new(look.said()).enabled(false),
|
||||
};
|
||||
// The face paints the label; the accessible name stays `said`.
|
||||
let button = if look.own.is_some() { button.painted(look.label().to_string()) } else { button };
|
||||
response = Some(button.tooltip(tip.clone()).show(ui).response);
|
||||
})
|
||||
.output;
|
||||
if measuring {
|
||||
return;
|
||||
}
|
||||
let Some(response) = response else { return };
|
||||
let (i, n) = place;
|
||||
let moved = |at: usize| CommandRef::with_params("toolbar.addCommand", json!({ "command": look.id, "toolbar": bar, "at": at }));
|
||||
let removed = CommandRef::with_params("toolbar.removeCommand", json!({ "command": look.id, "toolbar": bar }));
|
||||
let renamed = CommandRef::with_params("toolbar.renameCommand", json!({ "command": look.id, "toolbar": bar }));
|
||||
Menu::context(look.name().to_string(), &response).show(ui, |ui, _| {
|
||||
Menu::context(look.name().to_string(), &row).opened_by(&response, Trigger::Context).show(ui, |ui, _| {
|
||||
MenuItem::command(moved(i.saturating_sub(1))).label(tl!("Move Up")).enabled(i > 0).show(ui);
|
||||
MenuItem::command(moved(i + 1)).label(tl!("Move Down")).enabled(i + 1 < n).show(ui);
|
||||
MenuItem::command(renamed.clone()).label(tl!("Rename Button…")).show(ui);
|
||||
|
||||
Reference in new issue
Block a user