Add pane shortcuts to View menu

This commit is contained in:
Georg Bauer
2026-07-27 20:14:19 +02:00
parent 9d58f79295
commit 56be87d288
2 changed files with 66 additions and 2 deletions

View File

@@ -2020,6 +2020,10 @@ impl App {
Some(crate::native_menu::NativeMenuEvent::NewChat) => Message::NewChat, Some(crate::native_menu::NativeMenuEvent::NewChat) => Message::NewChat,
Some(crate::native_menu::NativeMenuEvent::ExportChat) => Message::ExportChat, Some(crate::native_menu::NativeMenuEvent::ExportChat) => Message::ExportChat,
Some(crate::native_menu::NativeMenuEvent::ToggleSidebar) => Message::ToggleSidebar, Some(crate::native_menu::NativeMenuEvent::ToggleSidebar) => Message::ToggleSidebar,
Some(crate::native_menu::NativeMenuEvent::ShowChat) => Message::ShowChat,
Some(crate::native_menu::NativeMenuEvent::ShowA2ui) => Message::ShowA2ui,
Some(crate::native_menu::NativeMenuEvent::ShowGit) => Message::ShowGit,
Some(crate::native_menu::NativeMenuEvent::ShowStats) => Message::ShowStats,
Some(crate::native_menu::NativeMenuEvent::Help) => Message::OpenHelp, Some(crate::native_menu::NativeMenuEvent::Help) => Message::OpenHelp,
Some(crate::native_menu::NativeMenuEvent::Quit) => Message::RequestQuit, Some(crate::native_menu::NativeMenuEvent::Quit) => Message::RequestQuit,
Some(crate::native_menu::NativeMenuEvent::Edit(command)) => { Some(crate::native_menu::NativeMenuEvent::Edit(command)) => {
@@ -2228,6 +2232,7 @@ impl App {
self.selected_project.is_some(), self.selected_project.is_some(),
self.active_chat_title().is_some(), self.active_chat_title().is_some(),
!self.config.interface.sidebar_collapsed, !self.config.interface.sidebar_collapsed,
self.detail_tab,
edit, edit,
); );
} }

View File

@@ -1,6 +1,7 @@
use muda::accelerator::{Accelerator, CMD_OR_CTRL, Code, Modifiers}; use muda::accelerator::{Accelerator, CMD_OR_CTRL, Code, Modifiers};
use muda::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem, Submenu}; use muda::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem, Submenu};
use crate::app::DetailTab;
use crate::native_edit::EditCommand; use crate::native_edit::EditCommand;
const PREFERENCES: &str = "preferences"; const PREFERENCES: &str = "preferences";
@@ -8,6 +9,10 @@ const MODEL_MANAGER: &str = "model-manager";
const NEW_CHAT: &str = "new-chat"; const NEW_CHAT: &str = "new-chat";
const EXPORT_CHAT: &str = "export-chat"; const EXPORT_CHAT: &str = "export-chat";
const TOGGLE_SIDEBAR: &str = "toggle-sidebar"; const TOGGLE_SIDEBAR: &str = "toggle-sidebar";
const SHOW_CHAT: &str = "show-chat";
const SHOW_A2UI: &str = "show-a2ui";
const SHOW_GIT: &str = "show-git";
const SHOW_STATS: &str = "show-stats";
const HELP: &str = "help"; const HELP: &str = "help";
const QUIT: &str = "quit"; const QUIT: &str = "quit";
const UNDO: &str = "undo"; const UNDO: &str = "undo";
@@ -22,6 +27,10 @@ pub(crate) struct NativeMenu {
new_chat: MenuItem, new_chat: MenuItem,
export_chat: MenuItem, export_chat: MenuItem,
sidebar: CheckMenuItem, sidebar: CheckMenuItem,
chat: CheckMenuItem,
a2ui: CheckMenuItem,
git: CheckMenuItem,
stats: CheckMenuItem,
undo: MenuItem, undo: MenuItem,
redo: MenuItem, redo: MenuItem,
cut: MenuItem, cut: MenuItem,
@@ -37,6 +46,10 @@ pub(crate) enum NativeMenuEvent {
NewChat, NewChat,
ExportChat, ExportChat,
ToggleSidebar, ToggleSidebar,
ShowChat,
ShowA2ui,
ShowGit,
ShowStats,
Help, Help,
Quit, Quit,
Edit(EditCommand), Edit(EditCommand),
@@ -87,6 +100,10 @@ pub(crate) fn install() -> Result<NativeMenu, String> {
true, true,
Some(Accelerator::new(Some(Modifiers::SUPER), Code::KeyB)), Some(Accelerator::new(Some(Modifiers::SUPER), Code::KeyB)),
); );
let chat = view_item(SHOW_CHAT, "Chat", Code::Digit1, true);
let a2ui = view_item(SHOW_A2UI, "A2UI", Code::Digit2, false);
let git = view_item(SHOW_GIT, "Git", Code::Digit3, false);
let stats = view_item(SHOW_STATS, "Stats", Code::Digit4, false);
let open_help = MenuItem::with_id( let open_help = MenuItem::with_id(
HELP, HELP,
"DS4Server Help", "DS4Server Help",
@@ -141,8 +158,17 @@ pub(crate) fn install() -> Result<NativeMenu, String> {
&select_all, &select_all,
]) ])
.map_err(|error| error.to_string())?; .map_err(|error| error.to_string())?;
view.append_items(&[&sidebar, &PredefinedMenuItem::separator(), &model_manager]) view.append_items(&[
.map_err(|error| error.to_string())?; &sidebar,
&PredefinedMenuItem::separator(),
&chat,
&a2ui,
&git,
&stats,
&PredefinedMenuItem::separator(),
&model_manager,
])
.map_err(|error| error.to_string())?;
window window
.append_items(&[ .append_items(&[
&PredefinedMenuItem::minimize(None), &PredefinedMenuItem::minimize(None),
@@ -161,6 +187,10 @@ pub(crate) fn install() -> Result<NativeMenu, String> {
new_chat, new_chat,
export_chat, export_chat,
sidebar, sidebar,
chat,
a2ui,
git,
stats,
undo, undo,
redo, redo,
cut, cut,
@@ -176,11 +206,16 @@ impl NativeMenu {
project_active: bool, project_active: bool,
chat_active: bool, chat_active: bool,
sidebar_visible: bool, sidebar_visible: bool,
detail_tab: DetailTab,
edit: crate::native_edit::EditAvailability, edit: crate::native_edit::EditAvailability,
) { ) {
self.new_chat.set_enabled(project_active); self.new_chat.set_enabled(project_active);
self.export_chat.set_enabled(chat_active); self.export_chat.set_enabled(chat_active);
self.sidebar.set_checked(sidebar_visible); self.sidebar.set_checked(sidebar_visible);
self.chat.set_checked(detail_tab == DetailTab::Chat);
self.a2ui.set_checked(detail_tab == DetailTab::A2ui);
self.git.set_checked(detail_tab == DetailTab::Git);
self.stats.set_checked(detail_tab == DetailTab::Stats);
self.undo.set_enabled(edit.undo); self.undo.set_enabled(edit.undo);
self.redo.set_enabled(edit.redo); self.redo.set_enabled(edit.redo);
self.cut.set_enabled(edit.cut); self.cut.set_enabled(edit.cut);
@@ -198,6 +233,10 @@ pub(crate) fn next_event() -> Option<NativeMenuEvent> {
NEW_CHAT => NativeMenuEvent::NewChat, NEW_CHAT => NativeMenuEvent::NewChat,
EXPORT_CHAT => NativeMenuEvent::ExportChat, EXPORT_CHAT => NativeMenuEvent::ExportChat,
TOGGLE_SIDEBAR => NativeMenuEvent::ToggleSidebar, TOGGLE_SIDEBAR => NativeMenuEvent::ToggleSidebar,
SHOW_CHAT => NativeMenuEvent::ShowChat,
SHOW_A2UI => NativeMenuEvent::ShowA2ui,
SHOW_GIT => NativeMenuEvent::ShowGit,
SHOW_STATS => NativeMenuEvent::ShowStats,
HELP => NativeMenuEvent::Help, HELP => NativeMenuEvent::Help,
QUIT => NativeMenuEvent::Quit, QUIT => NativeMenuEvent::Quit,
UNDO => NativeMenuEvent::Edit(EditCommand::Undo), UNDO => NativeMenuEvent::Edit(EditCommand::Undo),
@@ -213,6 +252,16 @@ pub(crate) fn next_event() -> Option<NativeMenuEvent> {
None None
} }
fn view_item(id: &'static str, label: &'static str, code: Code, checked: bool) -> CheckMenuItem {
CheckMenuItem::with_id(
id,
label,
true,
checked,
Some(Accelerator::new(Some(Modifiers::SUPER), code)),
)
}
fn edit_item( fn edit_item(
id: &'static str, id: &'static str,
label: &'static str, label: &'static str,
@@ -240,4 +289,14 @@ mod tests {
assert_eq!(paste.id().0, PASTE); assert_eq!(paste.id().0, PASTE);
assert!(paste.is_enabled()); assert!(paste.is_enabled());
} }
#[test]
fn view_items_keep_the_selected_pane_checked() {
let chat = view_item(SHOW_CHAT, "Chat", Code::Digit1, true);
let stats = view_item(SHOW_STATS, "Stats", Code::Digit4, false);
assert_eq!(chat.id().0, SHOW_CHAT);
assert!(chat.is_checked());
assert_eq!(stats.id().0, SHOW_STATS);
assert!(!stats.is_checked());
}
} }