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
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user