Add config for showing header bar
This commit is contained in:
parent
7013067582
commit
37acfe186e
4 changed files with 43 additions and 3 deletions
|
|
@ -19,3 +19,4 @@ copy = Copy
|
||||||
paste = Paste
|
paste = Paste
|
||||||
select-all = Select all
|
select-all = Select all
|
||||||
new-tab = New tab
|
new-tab = New tab
|
||||||
|
show-headerbar = Show header bar
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ pub struct Config {
|
||||||
pub app_theme: AppTheme,
|
pub app_theme: AppTheme,
|
||||||
pub font_name: String,
|
pub font_name: String,
|
||||||
pub font_size: u16,
|
pub font_size: u16,
|
||||||
|
pub show_headerbar: bool,
|
||||||
pub syntax_theme_dark: String,
|
pub syntax_theme_dark: String,
|
||||||
pub syntax_theme_light: String,
|
pub syntax_theme_light: String,
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +42,7 @@ impl Default for Config {
|
||||||
app_theme: AppTheme::System,
|
app_theme: AppTheme::System,
|
||||||
font_name: "Fira Mono".to_string(),
|
font_name: "Fira Mono".to_string(),
|
||||||
font_size: 14,
|
font_size: 14,
|
||||||
|
show_headerbar: true,
|
||||||
syntax_theme_dark: "COSMIC Dark".to_string(),
|
syntax_theme_dark: "COSMIC Dark".to_string(),
|
||||||
syntax_theme_light: "COSMIC Light".to_string(),
|
syntax_theme_light: "COSMIC Light".to_string(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -115,6 +115,7 @@ pub enum Action {
|
||||||
Paste,
|
Paste,
|
||||||
SelectAll,
|
SelectAll,
|
||||||
Settings,
|
Settings,
|
||||||
|
ShowHeaderBar(bool),
|
||||||
TabNew,
|
TabNew,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,6 +126,7 @@ impl Action {
|
||||||
Action::Paste => Message::Paste(Some(entity)),
|
Action::Paste => Message::Paste(Some(entity)),
|
||||||
Action::SelectAll => Message::SelectAll(Some(entity)),
|
Action::SelectAll => Message::SelectAll(Some(entity)),
|
||||||
Action::Settings => Message::ToggleContextPage(ContextPage::Settings),
|
Action::Settings => Message::ToggleContextPage(ContextPage::Settings),
|
||||||
|
Action::ShowHeaderBar(show_headerbar) => Message::ShowHeaderBar(show_headerbar),
|
||||||
Action::TabNew => Message::TabNew,
|
Action::TabNew => Message::TabNew,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +143,7 @@ pub enum Message {
|
||||||
Paste(Option<segmented_button::Entity>),
|
Paste(Option<segmented_button::Entity>),
|
||||||
PasteValue(Option<segmented_button::Entity>, String),
|
PasteValue(Option<segmented_button::Entity>, String),
|
||||||
SelectAll(Option<segmented_button::Entity>),
|
SelectAll(Option<segmented_button::Entity>),
|
||||||
|
ShowHeaderBar(bool),
|
||||||
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
||||||
SyntaxTheme(usize, bool),
|
SyntaxTheme(usize, bool),
|
||||||
TabActivate(segmented_button::Entity),
|
TabActivate(segmented_button::Entity),
|
||||||
|
|
@ -193,6 +196,8 @@ impl App {
|
||||||
terminal.set_config(&self.config, &self.themes);
|
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())
|
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()])
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
@ -318,6 +327,7 @@ impl Application for App {
|
||||||
/// Creates the application, and optionally emits command on initialize.
|
/// Creates the application, and optionally emits command on initialize.
|
||||||
fn init(mut core: Core, flags: Self::Flags) -> (Self, Command<Self::Message>) {
|
fn init(mut core: Core, flags: Self::Flags) -> (Self, Command<Self::Message>) {
|
||||||
core.window.content_container = false;
|
core.window.content_container = false;
|
||||||
|
core.window.show_headerbar = flags.config.show_headerbar;
|
||||||
|
|
||||||
// Update font name from config
|
// Update font name from config
|
||||||
{
|
{
|
||||||
|
|
@ -464,6 +474,12 @@ impl Application for App {
|
||||||
terminal.select_all();
|
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) => {
|
Message::SystemThemeModeChange(_theme_mode) => {
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
}
|
}
|
||||||
|
|
@ -695,7 +711,7 @@ impl Application for App {
|
||||||
let tab_element: Element<'_, Message> = match context_menu {
|
let tab_element: Element<'_, Message> = match context_menu {
|
||||||
Some(position) => widget::popover(
|
Some(position) => widget::popover(
|
||||||
terminal_box.context_menu(position),
|
terminal_box.context_menu(position),
|
||||||
menu::context_menu(entity),
|
menu::context_menu(&self.config, entity),
|
||||||
)
|
)
|
||||||
.position(position)
|
.position(position)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
|
||||||
25
src/menu.rs
25
src/menu.rs
|
|
@ -11,7 +11,7 @@ use cosmic::{
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{fl, Action, ContextPage, Message};
|
use crate::{fl, Action, Config, Message};
|
||||||
|
|
||||||
macro_rules! menu_button {
|
macro_rules! menu_button {
|
||||||
($($x:expr),+ $(,)?) => (
|
($($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| {
|
let menu_action = |label, action| {
|
||||||
menu_button!(widget::text(label)).on_press(Message::TabContextAction(entity, 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!(
|
widget::container(column!(
|
||||||
menu_action(fl!("copy"), Action::Copy),
|
menu_action(fl!("copy"), Action::Copy),
|
||||||
menu_action(fl!("paste"), Action::Paste),
|
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),
|
horizontal_rule(1),
|
||||||
menu_action(fl!("new-tab"), Action::TabNew),
|
menu_action(fl!("new-tab"), Action::TabNew),
|
||||||
menu_action(fl!("settings"), Action::Settings),
|
menu_action(fl!("settings"), Action::Settings),
|
||||||
|
menu_checkbox(
|
||||||
|
fl!("show-headerbar"),
|
||||||
|
config.show_headerbar,
|
||||||
|
Action::ShowHeaderBar(!config.show_headerbar)
|
||||||
|
),
|
||||||
))
|
))
|
||||||
.padding(1)
|
.padding(1)
|
||||||
//TODO: move style to libcosmic
|
//TODO: move style to libcosmic
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue