forked from 1b-agent/opencadstudio-upstream
Ribbon key tips: Alt shows codes on tabs, buttons and menu items
A lone Alt shows a code on every ribbon tab and quick-access button. Typing a tab code opens the tab and shows the codes of its buttons, dropdowns, slide-outs and collapsed panels; a button code runs it, a dropdown or slide-out code opens it and shows its item codes, Esc goes back one level. Codes follow the reference ribbon; buttons without a reference counterpart get none and unnamed menu items are numbered. Codes are drawn as accent pills over the widgets that reported their bounds in the current frame, with a hint bar under the ribbon. While the tips are open keys go to them only. The automation gets a keytips action and read operation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
592289f4fd
commit
86429bf439
34 files changed
+1569
-53
No files matched your search
@@ -114,6 +114,7 @@ pub(super) const NAMES: &[&str] = &[
|
||||
"pc_section",
|
||||
"ribbon_tab",
|
||||
"ribbon_dropdown",
|
||||
"keytips",
|
||||
"dialog_ok",
|
||||
"attdef_dialog",
|
||||
"field_dialog",
|
||||
@@ -1884,6 +1885,28 @@ impl OpenCADStudio {
|
||||
})
|
||||
}
|
||||
"ribbon_dropdown" => Message::ToggleRibbonDropdown(string(req, "value")?.into()),
|
||||
// Ribbon key tips: `show`, `alt` (a lone Alt), `type:<codes>`, `enter`,
|
||||
// `esc` or `hide`. Read them back with the `keytips` read operation.
|
||||
"keytips" => {
|
||||
use crate::ui::ribbon::KeyTipInput as K;
|
||||
let value = string(req, "value")?;
|
||||
let inputs: Vec<K> = match value {
|
||||
"show" => vec![K::Open { refocus: false }],
|
||||
"alt" => vec![K::AltTap],
|
||||
"esc" => vec![K::Escape],
|
||||
"hide" => vec![K::Hide],
|
||||
"enter" => vec![K::Enter],
|
||||
_ => match value.strip_prefix("type:") {
|
||||
Some(codes) if !codes.is_empty() => codes
|
||||
.chars()
|
||||
.map(|ch| K::Char(ch.to_uppercase().collect()))
|
||||
.collect(),
|
||||
_ => return Err(failure("invalid_value", "Use show, alt, type:<codes>, enter, esc or hide")),
|
||||
},
|
||||
};
|
||||
let tasks: Vec<_> = inputs.into_iter().map(|input| self.on_keytip(input)).collect();
|
||||
return Ok(Task::batch(tasks));
|
||||
}
|
||||
// The -VIEW Background dialog, one field per call: "type=gradient",
|
||||
// "color|top|middle|bottom=r,g,b", "three=1", "rotation=30",
|
||||
// "image=<path>", "position=center|stretch|tile", "aspect=1", "offset=x,y" (pixels), "scale=x,y",
|
||||
|
||||
@@ -559,6 +559,7 @@ impl OpenCADStudio {
|
||||
| "audit"
|
||||
| "text_search"
|
||||
| "text_audit"
|
||||
| "keytips"
|
||||
);
|
||||
if !query && !self.control.enabled {
|
||||
return (
|
||||
@@ -850,6 +851,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
"grips" => self.control_grips(),
|
||||
"keytips" => self.ribbon.keytips_json(req["detail"].as_str() == Some("full")),
|
||||
"xdata_get" => self.xdata_read(&req),
|
||||
"get_selection" => self.control_get_selection(),
|
||||
"text_search" => self.control_text_search(&req).unwrap_or_else(|e| e),
|
||||
|
||||
@@ -2754,6 +2754,8 @@ pub enum Message {
|
||||
SetProjection(bool),
|
||||
/// Select a ribbon module tab by index.
|
||||
RibbonSelectTab(usize),
|
||||
/// Ribbon key tips: Alt, typed codes and Esc.
|
||||
KeyTip(crate::ui::ribbon::KeyTipInput),
|
||||
/// Change the ribbon tool-panel density (persisted).
|
||||
SetRibbonCollapseMode(crate::ui::ribbon::CollapseMode),
|
||||
/// A ribbon tool button was clicked — highlights the tool and dispatches its event.
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//! Ribbon key tips: a lone Alt opens them, typed codes walk the ribbon and
|
||||
//! Esc goes back one level.
|
||||
|
||||
use iced::Task;
|
||||
|
||||
use crate::app::{Message, OpenCADStudio};
|
||||
use crate::ui::ribbon::{KeyTipInput, KeyTipStep};
|
||||
|
||||
impl OpenCADStudio {
|
||||
pub(in crate::app) fn on_keytip(&mut self, input: KeyTipInput) -> Task<Message> {
|
||||
match input {
|
||||
KeyTipInput::AltTap if self.ribbon.keytips_active() => self.hide_keytips(),
|
||||
KeyTipInput::AltTap => {
|
||||
if self.active_modal.is_some() || self.clean_screen || self.ribbon_closed {
|
||||
return Task::none();
|
||||
}
|
||||
// A focused field other than the command line keeps Alt.
|
||||
iced::advanced::widget::operate(
|
||||
iced::advanced::widget::operation::focusable::count(),
|
||||
)
|
||||
.then(|count| {
|
||||
if count.focused.is_none() {
|
||||
return Task::done(Message::KeyTip(KeyTipInput::Open { refocus: false }));
|
||||
}
|
||||
iced::widget::operation::is_focused(iced::widget::Id::new(
|
||||
crate::ui::command_line::CMD_INPUT_ID,
|
||||
))
|
||||
.map(|command_line| {
|
||||
if command_line {
|
||||
Message::KeyTip(KeyTipInput::Open { refocus: true })
|
||||
} else {
|
||||
Message::Noop
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
KeyTipInput::Open { refocus } => {
|
||||
self.ribbon.show_keytips(refocus);
|
||||
// Typed codes must not reach the command line.
|
||||
if refocus {
|
||||
self.unfocus_widgets()
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
KeyTipInput::Hide => self.hide_keytips(),
|
||||
KeyTipInput::Escape => {
|
||||
if self.ribbon.keytip_escape() {
|
||||
Task::none()
|
||||
} else {
|
||||
self.hide_keytips()
|
||||
}
|
||||
}
|
||||
KeyTipInput::Char(_) | KeyTipInput::Enter => {
|
||||
let ch = match &input {
|
||||
KeyTipInput::Char(ch) => Some(ch.as_str()),
|
||||
_ => None,
|
||||
};
|
||||
match self.ribbon.keytip_type(ch) {
|
||||
KeyTipStep::Ignore | KeyTipStep::Stay => Task::none(),
|
||||
KeyTipStep::Open(message) => self.update(message),
|
||||
KeyTipStep::Run(message) => {
|
||||
let refocus = self.hide_keytips();
|
||||
Task::batch([refocus, self.update(message)])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the key tips, returning the focus to the command line if it had
|
||||
/// it.
|
||||
pub(in crate::app) fn hide_keytips(&mut self) -> Task<Message> {
|
||||
if self.ribbon.hide_keytips() {
|
||||
self.focus_cmd_input()
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,7 @@ mod dialog;
|
||||
mod dynamic;
|
||||
mod file;
|
||||
mod graphic_attributes;
|
||||
mod keytips;
|
||||
pub(in crate::app) use file::background_task;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(in crate::app) use file::native_paths_match;
|
||||
@@ -621,6 +622,10 @@ impl OpenCADStudio {
|
||||
if Some(id) == self.main_window {
|
||||
self.spacemouse_focused = focused;
|
||||
}
|
||||
// Key tips close when the window loses the focus.
|
||||
if !focused && self.ribbon.keytips_active() {
|
||||
return self.hide_keytips();
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::SpaceMouseEnabled(enabled) => {
|
||||
@@ -2277,6 +2282,7 @@ impl OpenCADStudio {
|
||||
Message::PcManager(message) => self.update_pc_manager(message),
|
||||
Message::Count(message) => self.on_count(message),
|
||||
Message::SheetSet(message) => self.on_sheet_set(message),
|
||||
Message::KeyTip(input) => self.on_keytip(input),
|
||||
Message::RibbonSelectTab(idx) => {
|
||||
self.ribbon.select(idx);
|
||||
Task::none()
|
||||
|
||||
+30
-1
@@ -2252,12 +2252,23 @@ bg={bg_ms:.1}ms n={view_count}"
|
||||
iced::widget::Space::new().width(0).height(0).into()
|
||||
};
|
||||
|
||||
// Key tips: the hint bar under the dropdowns, the codes above all.
|
||||
let (keytip_bar, keytip_layer): (Element<'_, Message>, Element<'_, Message>) =
|
||||
self.ribbon.keytip_layers().unwrap_or_else(|| {
|
||||
(
|
||||
iced::widget::Space::new().width(0).height(0).into(),
|
||||
iced::widget::Space::new().width(0).height(0).into(),
|
||||
)
|
||||
});
|
||||
|
||||
let composed = stack![
|
||||
main_ui,
|
||||
keytip_bar,
|
||||
dropdown_layer,
|
||||
qselect_layer,
|
||||
snap_override_layer,
|
||||
open_progress_layer,
|
||||
keytip_layer,
|
||||
];
|
||||
|
||||
// If the Plot Style editor was launched from PLOT, keep the Plot dialog
|
||||
@@ -2547,9 +2558,18 @@ impl OpenCADStudio {
|
||||
event::listen_with(|ev, status, win_id| {
|
||||
use iced::event::Status;
|
||||
match ev {
|
||||
iced::Event::Mouse(iced::mouse::Event::ButtonPressed(_))
|
||||
if crate::ui::ribbon::keytips_active() =>
|
||||
{
|
||||
crate::ui::ribbon::keytip_pointer_pressed();
|
||||
Some(Message::KeyTip(crate::ui::ribbon::KeyTipInput::Hide))
|
||||
}
|
||||
iced::Event::Mouse(iced::mouse::Event::ButtonPressed(
|
||||
iced::mouse::Button::Left,
|
||||
)) => Some(Message::PropPointerPressed),
|
||||
)) => {
|
||||
crate::ui::ribbon::keytip_pointer_pressed();
|
||||
Some(Message::PropPointerPressed)
|
||||
}
|
||||
iced::Event::Window(window::Event::CloseRequested) => {
|
||||
Some(Message::WindowCloseRequested(win_id))
|
||||
}
|
||||
@@ -2562,6 +2582,9 @@ impl OpenCADStudio {
|
||||
iced::Event::Window(window::Event::FileDropped(path)) => {
|
||||
Some(Message::FileDropped(path))
|
||||
}
|
||||
iced::Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
|
||||
crate::ui::ribbon::keytip_key_released(&key)
|
||||
}
|
||||
iced::Event::Keyboard(keyboard::Event::ModifiersChanged(m)) => {
|
||||
// `command()` is Cmd on macOS, Ctrl elsewhere — the
|
||||
// platform multi-select modifier for the layer list.
|
||||
@@ -2575,8 +2598,14 @@ impl OpenCADStudio {
|
||||
physical_key,
|
||||
modifiers,
|
||||
text,
|
||||
repeat,
|
||||
..
|
||||
}) => {
|
||||
if let Some(keytip) =
|
||||
crate::ui::ribbon::keytip_key_pressed(&key, modifiers, repeat)
|
||||
{
|
||||
return keytip;
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let accel = modifiers.command();
|
||||
// AltGr reaches Windows apps as Ctrl+Alt, and a macOS
|
||||
|
||||
Reference in new issue
Block a user