diff --git a/i18n/en/cosmic_term.ftl b/i18n/en/cosmic_term.ftl index bc05043..e92b1cc 100644 --- a/i18n/en/cosmic_term.ftl +++ b/i18n/en/cosmic_term.ftl @@ -19,3 +19,4 @@ copy = Copy paste = Paste select-all = Select all new-tab = New tab +show-headerbar = Show header bar diff --git a/src/config.rs b/src/config.rs index e6977fe..7faa59d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,6 +31,7 @@ pub struct Config { pub app_theme: AppTheme, pub font_name: String, pub font_size: u16, + pub show_headerbar: bool, pub syntax_theme_dark: String, pub syntax_theme_light: String, } @@ -41,6 +42,7 @@ impl Default for Config { app_theme: AppTheme::System, font_name: "Fira Mono".to_string(), font_size: 14, + show_headerbar: true, syntax_theme_dark: "COSMIC Dark".to_string(), syntax_theme_light: "COSMIC Light".to_string(), } diff --git a/src/main.rs b/src/main.rs index ec893f4..780dbe2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,6 +115,7 @@ pub enum Action { Paste, SelectAll, Settings, + ShowHeaderBar(bool), TabNew, } @@ -125,6 +126,7 @@ impl Action { Action::Paste => Message::Paste(Some(entity)), Action::SelectAll => Message::SelectAll(Some(entity)), Action::Settings => Message::ToggleContextPage(ContextPage::Settings), + Action::ShowHeaderBar(show_headerbar) => Message::ShowHeaderBar(show_headerbar), Action::TabNew => Message::TabNew, } } @@ -141,6 +143,7 @@ pub enum Message { Paste(Option), PasteValue(Option, String), SelectAll(Option), + ShowHeaderBar(bool), SystemThemeModeChange(cosmic_theme::ThemeMode), SyntaxTheme(usize, bool), TabActivate(segmented_button::Entity), @@ -193,6 +196,8 @@ impl App { terminal.set_config(&self.config, &self.themes); } } + + self.core.window.show_headerbar = self.config.show_headerbar; cosmic::app::command::set_theme(self.config.app_theme.theme()) } @@ -288,6 +293,10 @@ impl App { }), ), ) + .add( + widget::settings::item::builder(fl!("show-headerbar")) + .toggler(self.config.show_headerbar, Message::ShowHeaderBar), + ) .into()]) .into() } @@ -318,6 +327,7 @@ impl Application for App { /// Creates the application, and optionally emits command on initialize. fn init(mut core: Core, flags: Self::Flags) -> (Self, Command) { core.window.content_container = false; + core.window.show_headerbar = flags.config.show_headerbar; // Update font name from config { @@ -464,6 +474,12 @@ impl Application for App { terminal.select_all(); } } + Message::ShowHeaderBar(show_headerbar) => { + if show_headerbar != self.config.show_headerbar { + self.config.show_headerbar = show_headerbar; + return self.save_config(); + } + } Message::SystemThemeModeChange(_theme_mode) => { return self.update_config(); } @@ -695,7 +711,7 @@ impl Application for App { let tab_element: Element<'_, Message> = match context_menu { Some(position) => widget::popover( terminal_box.context_menu(position), - menu::context_menu(entity), + menu::context_menu(&self.config, entity), ) .position(position) .into(), diff --git a/src/menu.rs b/src/menu.rs index 9131576..fb528d3 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -11,7 +11,7 @@ use cosmic::{ Element, }; -use crate::{fl, Action, ContextPage, Message}; +use crate::{fl, Action, Config, Message}; macro_rules! menu_button { ($($x:expr),+ $(,)?) => ( @@ -28,11 +28,27 @@ macro_rules! menu_button { ); } -pub fn context_menu<'a>(entity: segmented_button::Entity) -> Element<'a, Message> { +pub fn context_menu<'a>(config: &Config, entity: segmented_button::Entity) -> Element<'a, Message> { let menu_action = |label, action| { menu_button!(widget::text(label)).on_press(Message::TabContextAction(entity, action)) }; + let menu_checkbox = |label, value, action| { + let check: Element<_> = if value { + widget::icon::from_name("object-select-symbolic") + .size(16) + .into() + } else { + widget::Space::with_width(Length::Fixed(16.0)).into() + }; + menu_button!( + check, + widget::Space::with_width(Length::Fixed(8.0)), + widget::text(label), + ) + .on_press(Message::TabContextAction(entity, action)) + }; + widget::container(column!( menu_action(fl!("copy"), Action::Copy), menu_action(fl!("paste"), Action::Paste), @@ -40,6 +56,11 @@ pub fn context_menu<'a>(entity: segmented_button::Entity) -> Element<'a, Message horizontal_rule(1), menu_action(fl!("new-tab"), Action::TabNew), menu_action(fl!("settings"), Action::Settings), + menu_checkbox( + fl!("show-headerbar"), + config.show_headerbar, + Action::ShowHeaderBar(!config.show_headerbar) + ), )) .padding(1) //TODO: move style to libcosmic