feat: Keyboard Shortcuts panel + SHORTCUTS command
Opens a reference panel listing all built-in keyboard shortcuts (F3-F12, Ctrl+N/O/S/Z/C/X/V, etc.) and any user-defined overrides. SHORTCUTS LIST — open the panel SHORTCUTS SET <k> <c> — add/update a custom shortcut label SHORTCUTS CLEAR <k> — remove a custom entry Custom shortcuts are stored in app state (runtime only) and shown in the panel alongside the hardcoded bindings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e36fafe6df
commit
67b5f5e3d5
5 changed files with 218 additions and 2 deletions
|
|
@ -278,7 +278,7 @@ Underlay (PDF/DWF/DGN)
|
||||||
| Çoklu seçim (window/crossing) | ✅ |
|
| Çoklu seçim (window/crossing) | ✅ |
|
||||||
| Sağ tık bağlam menüsü | ✅ |
|
| Sağ tık bağlam menüsü | ✅ |
|
||||||
| Araç çubuğu özelleştirme | ⬜ |
|
| Araç çubuğu özelleştirme | ⬜ |
|
||||||
| Tema / Renk şeması seçimi | ⬜ |
|
| Tema / Renk şeması seçimi | ✅ |
|
||||||
| Klavye kısayol düzenleyici | ⬜ |
|
| Klavye kısayol düzenleyici | ⬜ |
|
||||||
| Komut geçmişi gezinme (↑↓) | ✅ |
|
| Komut geçmişi gezinme (↑↓) | ✅ |
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1972,6 +1972,43 @@ impl H7CAD {
|
||||||
self.command_line.push_info("Opening Patreon page...");
|
self.command_line.push_info("Opening Patreon page...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Keyboard Shortcuts panel ──────────────────────────────────
|
||||||
|
cmd if cmd == "SHORTCUTS" || cmd.starts_with("SHORTCUTS ") => {
|
||||||
|
let raw_rest = cmd.trim_start_matches("SHORTCUTS").trim();
|
||||||
|
let parts: Vec<&str> = raw_rest.splitn(3, ' ').collect();
|
||||||
|
let sub = parts.first().map(|s| s.to_uppercase()).unwrap_or_default();
|
||||||
|
match sub.as_str() {
|
||||||
|
"" | "LIST" | "?" => {
|
||||||
|
return Task::done(Message::ShortcutsPanelOpen);
|
||||||
|
}
|
||||||
|
"SET" | "S" => {
|
||||||
|
// SHORTCUTS SET <key> <command>
|
||||||
|
// e.g. SHORTCUTS SET CTRL+D DIST
|
||||||
|
let key = parts.get(1).map(|s| s.to_uppercase()).unwrap_or_default();
|
||||||
|
let cmd_str = parts.get(2).map(|s| s.to_uppercase()).unwrap_or_default();
|
||||||
|
if key.is_empty() || cmd_str.is_empty() {
|
||||||
|
self.command_line.push_error("Usage: SHORTCUTS SET <key> <command> e.g. SHORTCUTS SET CTRL+D DIST");
|
||||||
|
} else {
|
||||||
|
self.shortcut_overrides.insert(key.clone(), cmd_str.clone());
|
||||||
|
self.command_line.push_output(&format!("Shortcut set: {key} → {cmd_str}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CLEAR" | "DELETE" | "REMOVE" => {
|
||||||
|
let key = parts.get(1).map(|s| s.to_uppercase()).unwrap_or_default();
|
||||||
|
if key.is_empty() {
|
||||||
|
self.command_line.push_error("Usage: SHORTCUTS CLEAR <key>");
|
||||||
|
} else if self.shortcut_overrides.remove(&key).is_some() {
|
||||||
|
self.command_line.push_output(&format!("Shortcut '{key}' removed."));
|
||||||
|
} else {
|
||||||
|
self.command_line.push_error(&format!("Shortcut '{key}' not found."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.command_line.push_info("Usage: SHORTCUTS LIST | SET <key> <cmd> | CLEAR <key>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Color Scheme / Theme selector ─────────────────────────────
|
// ── Color Scheme / Theme selector ─────────────────────────────
|
||||||
cmd if cmd == "COLORSCHEME" || cmd.starts_with("COLORSCHEME ") => {
|
cmd if cmd == "COLORSCHEME" || cmd.starts_with("COLORSCHEME ") => {
|
||||||
use iced::Theme;
|
use iced::Theme;
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ pub(super) struct H7CAD {
|
||||||
// ── Color Scheme ──────────────────────────────────────────────────────
|
// ── Color Scheme ──────────────────────────────────────────────────────
|
||||||
active_theme: Theme,
|
active_theme: Theme,
|
||||||
|
|
||||||
|
// ── Keyboard Shortcut Editor ──────────────────────────────────────────
|
||||||
|
shortcuts_panel_open: bool,
|
||||||
|
/// User-defined function-key overrides: "F3" → command string.
|
||||||
|
shortcut_overrides: std::collections::HashMap<String, String>,
|
||||||
|
|
||||||
// ── Layout Manager Panel ──────────────────────────────────────────────
|
// ── Layout Manager Panel ──────────────────────────────────────────────
|
||||||
layout_manager_open: bool,
|
layout_manager_open: bool,
|
||||||
layout_manager_selected: String,
|
layout_manager_selected: String,
|
||||||
|
|
@ -359,6 +364,9 @@ pub enum Message {
|
||||||
LayoutManagerSetCurrent,
|
LayoutManagerSetCurrent,
|
||||||
/// Switch the UI color scheme.
|
/// Switch the UI color scheme.
|
||||||
SetTheme(Theme),
|
SetTheme(Theme),
|
||||||
|
// ── Keyboard Shortcut Editor ────────────────────────────────────────
|
||||||
|
ShortcutsPanelOpen,
|
||||||
|
ShortcutsPanelClose,
|
||||||
/// Close the viewport right-click context menu without performing any action.
|
/// Close the viewport right-click context menu without performing any action.
|
||||||
ViewportContextMenuClose,
|
ViewportContextMenuClose,
|
||||||
/// A window was closed by the OS (e.g. the user clicked the title-bar ✕).
|
/// A window was closed by the OS (e.g. the user clicked the title-bar ✕).
|
||||||
|
|
@ -537,6 +545,9 @@ impl H7CAD {
|
||||||
active_plot_style: None,
|
active_plot_style: None,
|
||||||
// Color scheme (default: dark CAD-style)
|
// Color scheme (default: dark CAD-style)
|
||||||
active_theme: Theme::Dark,
|
active_theme: Theme::Dark,
|
||||||
|
// Keyboard shortcuts
|
||||||
|
shortcuts_panel_open: false,
|
||||||
|
shortcut_overrides: std::collections::HashMap::new(),
|
||||||
// Layout Manager
|
// Layout Manager
|
||||||
layout_manager_open: false,
|
layout_manager_open: false,
|
||||||
layout_manager_selected: "Model".to_string(),
|
layout_manager_selected: "Model".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -2370,6 +2370,16 @@ impl H7CAD {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Keyboard Shortcuts Panel ──────────────────────────────────────
|
||||||
|
Message::ShortcutsPanelOpen => {
|
||||||
|
self.shortcuts_panel_open = true;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
Message::ShortcutsPanelClose => {
|
||||||
|
self.shortcuts_panel_open = false;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
Message::ViewportContextMenuClose => {
|
Message::ViewportContextMenuClose => {
|
||||||
let i = self.active_tab;
|
let i = self.active_tab;
|
||||||
self.tabs[i].scene.selection.borrow_mut().context_menu = None;
|
self.tabs[i].scene.selection.borrow_mut().context_menu = None;
|
||||||
|
|
|
||||||
160
src/app/view.rs
160
src/app/view.rs
|
|
@ -367,7 +367,13 @@ impl H7CAD {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stack![main_ui, self.app_menu.view(), snap_layer, dropdown_layer, layout_ctx_layer, page_setup_layer, textstyle_layer, tablestyle_layer, mlstyle_layer, plotstyle_layer, layout_manager_layer, dimstyle_layer, viewport_ctx_layer].into()
|
let shortcuts_layer: Element<'_, Message> = if self.shortcuts_panel_open {
|
||||||
|
shortcuts_panel_overlay(&self.shortcut_overrides)
|
||||||
|
} else {
|
||||||
|
iced::widget::Space::new().width(0).height(0).into()
|
||||||
|
};
|
||||||
|
|
||||||
|
stack![main_ui, self.app_menu.view(), snap_layer, dropdown_layer, layout_ctx_layer, page_setup_layer, textstyle_layer, tablestyle_layer, mlstyle_layer, plotstyle_layer, layout_manager_layer, shortcuts_layer, dimstyle_layer, viewport_ctx_layer].into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscription(&self) -> Subscription<Message> {
|
pub fn subscription(&self) -> Subscription<Message> {
|
||||||
|
|
@ -2196,3 +2202,155 @@ fn layout_manager_overlay<'a>(
|
||||||
|
|
||||||
stack![catcher, positioned].into()
|
stack![catcher, positioned].into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Keyboard Shortcuts Reference Panel ────────────────────────────────────
|
||||||
|
|
||||||
|
fn shortcuts_panel_overlay<'a>(
|
||||||
|
overrides: &'a std::collections::HashMap<String, String>,
|
||||||
|
) -> Element<'a, Message> {
|
||||||
|
use iced::Length::Fill;
|
||||||
|
use iced::Color;
|
||||||
|
use iced::widget::scrollable;
|
||||||
|
|
||||||
|
const PANEL_BG: Color = Color { r: 0.15, g: 0.15, b: 0.15, a: 1.0 };
|
||||||
|
const BORDER: Color = Color { r: 0.35, g: 0.35, b: 0.35, a: 1.0 };
|
||||||
|
const TEXT_COL: Color = Color { r: 0.88, g: 0.88, b: 0.88, a: 1.0 };
|
||||||
|
const DIM_COL: Color = Color { r: 0.55, g: 0.55, b: 0.55, a: 1.0 };
|
||||||
|
const HEAD_COL: Color = Color { r: 0.40, g: 0.70, b: 1.00, a: 1.0 };
|
||||||
|
|
||||||
|
let shortcut_row = |key: &'static str, action: &'static str| -> Element<'_, Message> {
|
||||||
|
row![
|
||||||
|
text(key).size(11).color(HEAD_COL).font(iced::Font::MONOSPACE).width(120),
|
||||||
|
text(action).size(11).color(TEXT_COL),
|
||||||
|
].spacing(8).align_y(iced::Center).padding([2, 0]).into()
|
||||||
|
};
|
||||||
|
|
||||||
|
let section = |title: &'static str| -> Element<'_, Message> {
|
||||||
|
text(title).size(12).color(DIM_COL).into()
|
||||||
|
};
|
||||||
|
|
||||||
|
let builtins: Vec<Element<'_, Message>> = vec![
|
||||||
|
section("── Function Keys ──────────────────────────────"),
|
||||||
|
shortcut_row("F3", "Toggle Object Snap"),
|
||||||
|
shortcut_row("F7", "Toggle Grid"),
|
||||||
|
shortcut_row("F8", "Toggle Ortho"),
|
||||||
|
shortcut_row("F9", "Toggle Grid Snap"),
|
||||||
|
shortcut_row("F10", "Toggle Polar Tracking"),
|
||||||
|
shortcut_row("F11", "Toggle Object Snap Tracking"),
|
||||||
|
shortcut_row("F12", "Toggle Dynamic Input"),
|
||||||
|
section("── Ctrl Shortcuts ─────────────────────────────"),
|
||||||
|
shortcut_row("Ctrl+N", "New Drawing"),
|
||||||
|
shortcut_row("Ctrl+O", "Open File"),
|
||||||
|
shortcut_row("Ctrl+S", "Save"),
|
||||||
|
shortcut_row("Ctrl+Shift+S","Save As"),
|
||||||
|
shortcut_row("Ctrl+Z", "Undo"),
|
||||||
|
shortcut_row("Ctrl+Shift+Z / Ctrl+Y", "Redo"),
|
||||||
|
shortcut_row("Ctrl+C", "Copy to Clipboard"),
|
||||||
|
shortcut_row("Ctrl+X", "Cut to Clipboard"),
|
||||||
|
shortcut_row("Ctrl+V", "Paste from Clipboard"),
|
||||||
|
section("── Other Keys ──────────────────────────────────"),
|
||||||
|
shortcut_row("Enter / Space", "Finalize command / Repeat last"),
|
||||||
|
shortcut_row("Escape", "Cancel active command"),
|
||||||
|
shortcut_row("Delete", "Delete selected entities"),
|
||||||
|
shortcut_row("↑ / ↓", "Command history navigation"),
|
||||||
|
];
|
||||||
|
|
||||||
|
// User-defined overrides
|
||||||
|
let mut override_rows: Vec<Element<'_, Message>> = vec![
|
||||||
|
section("── Custom Overrides (SHORTCUTS SET) ─────────"),
|
||||||
|
];
|
||||||
|
if overrides.is_empty() {
|
||||||
|
override_rows.push(
|
||||||
|
text(" (none — use: SHORTCUTS SET <key> <command>)")
|
||||||
|
.size(11).color(DIM_COL).into()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let mut sorted: Vec<_> = overrides.iter().collect();
|
||||||
|
sorted.sort_by_key(|(k, _)| k.as_str());
|
||||||
|
for (key, cmd) in sorted {
|
||||||
|
let label: &str = key.as_str();
|
||||||
|
let cmd_str: &str = cmd.as_str();
|
||||||
|
override_rows.push(
|
||||||
|
row![
|
||||||
|
text(label).size(11).color(HEAD_COL).font(iced::Font::MONOSPACE).width(120),
|
||||||
|
text(cmd_str).size(11).color(TEXT_COL),
|
||||||
|
].spacing(8).align_y(iced::Center).padding([2, 0]).into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut all_rows = builtins;
|
||||||
|
all_rows.extend(override_rows);
|
||||||
|
|
||||||
|
let panel = container(
|
||||||
|
column![
|
||||||
|
row![
|
||||||
|
text("Keyboard Shortcuts").size(13).color(TEXT_COL),
|
||||||
|
Space::new().width(Fill),
|
||||||
|
button(text("✕").size(12).color(DIM_COL))
|
||||||
|
.on_press(Message::ShortcutsPanelClose)
|
||||||
|
.style(|_: &Theme, _| button::Style {
|
||||||
|
background: Some(Background::Color(Color::TRANSPARENT)),
|
||||||
|
text_color: DIM_COL,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.padding([2, 6]),
|
||||||
|
].align_y(iced::Center),
|
||||||
|
text("Type SHORTCUTS SET <key> <cmd> to add custom shortcuts.")
|
||||||
|
.size(10).color(DIM_COL),
|
||||||
|
Space::new().height(8),
|
||||||
|
container(
|
||||||
|
scrollable(
|
||||||
|
column(all_rows).spacing(4).padding([0, 8])
|
||||||
|
).height(360)
|
||||||
|
)
|
||||||
|
.style(|_: &Theme| container::Style {
|
||||||
|
background: Some(Background::Color(Color { r: 0.12, g: 0.12, b: 0.12, a: 1.0 })),
|
||||||
|
border: Border { color: BORDER, width: 1.0, radius: 4.0.into() },
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.padding(8),
|
||||||
|
Space::new().height(8),
|
||||||
|
row![
|
||||||
|
Space::new().width(Fill),
|
||||||
|
button(text("Close").size(11))
|
||||||
|
.on_press(Message::ShortcutsPanelClose)
|
||||||
|
.style(|_: &Theme, status| button::Style {
|
||||||
|
background: Some(Background::Color(match status {
|
||||||
|
button::Status::Hovered | button::Status::Pressed =>
|
||||||
|
Color { r: 0.28, g: 0.28, b: 0.28, a: 1.0 },
|
||||||
|
_ => Color { r: 0.22, g: 0.22, b: 0.22, a: 1.0 },
|
||||||
|
})),
|
||||||
|
text_color: TEXT_COL,
|
||||||
|
border: Border { color: BORDER, width: 1.0, radius: 4.0.into() },
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.padding([5, 12]),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
.spacing(6)
|
||||||
|
.padding(16)
|
||||||
|
)
|
||||||
|
.style(|_: &Theme| container::Style {
|
||||||
|
background: Some(Background::Color(PANEL_BG)),
|
||||||
|
border: Border { color: BORDER, width: 1.0, radius: 6.0.into() },
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.width(520)
|
||||||
|
.height(480);
|
||||||
|
|
||||||
|
let catcher = mouse_area(container(Space::new().width(Fill).height(Fill))
|
||||||
|
.width(Fill).height(Fill)
|
||||||
|
.style(|_: &Theme| container::Style {
|
||||||
|
background: Some(Background::Color(Color { r: 0.0, g: 0.0, b: 0.0, a: 0.45 })),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
).on_press(Message::ShortcutsPanelClose);
|
||||||
|
|
||||||
|
let positioned = container(panel)
|
||||||
|
.width(Fill).height(Fill)
|
||||||
|
.align_x(iced::Alignment::Center)
|
||||||
|
.align_y(iced::Alignment::Center);
|
||||||
|
|
||||||
|
stack![catcher, positioned].into()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue