Skip to content

[Feature] settings option to change sidebar size #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions i18n/en/cosmic_files.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ match-desktop = Match desktop
dark = Dark
light = Light

## NavBar Size
navbar-size = Sidebar Size
small = Small
medium = Medium
large = Large

# Context menu
add-to-sidebar = Add to sidebar
compress = Compress
Expand Down
33 changes: 31 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use trash::TrashItem;
#[cfg(feature = "wayland")]
use wayland_client::{protocol::wl_output::WlOutput, Proxy};

use crate::operation::{OperationError, OperationErrorType};
use crate::{
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
config::{AppTheme, Config, DesktopConfig, Favorite, IconSizes, TabConfig},
Expand All @@ -74,6 +73,10 @@ use crate::{
spawn_detached::spawn_detached,
tab::{self, HeadingOptions, ItemMetadata, Location, Tab, HOVER_DURATION},
};
use crate::{
config::NavBarSize,
operation::{OperationError, OperationErrorType},
};

#[derive(Clone, Debug)]
pub enum Mode {
Expand Down Expand Up @@ -274,6 +277,7 @@ impl MenuAction for NavMenuAction {
pub enum Message {
AddToSidebar(Option<Entity>),
AppTheme(AppTheme),
NavBarSize(NavBarSize),
CloseToast(widget::ToastId),
Compress(Option<Entity>),
Config(Config),
Expand Down Expand Up @@ -520,6 +524,7 @@ pub struct App {
config: Config,
mode: Mode,
app_themes: Vec<String>,
bar_sizes: Vec<String>,
context_page: ContextPage,
dialog_pages: VecDeque<DialogPage>,
dialog_text_input: widget::Id,
Expand Down Expand Up @@ -1544,6 +1549,24 @@ impl App {
},
))
})
.add({
let nav_bar_size_selected = match self.config.nav_bar_size {
NavBarSize::Small => 0,
NavBarSize::Medium => 1,
NavBarSize::Large => 2,
};
widget::settings::item::builder(fl!("navbar-size")).control(widget::dropdown(
&self.bar_sizes,
Some(nav_bar_size_selected),
move |index| {
Message::NavBarSize(match index {
0 => NavBarSize::Small,
1 => NavBarSize::Medium,
_ => NavBarSize::Large,
})
},
))
})
.into()])
.into()
}
Expand Down Expand Up @@ -1590,6 +1613,7 @@ impl Application for App {
}

let app_themes = vec![fl!("match-desktop"), fl!("dark"), fl!("light")];
let bar_sizes = vec![fl!("small"), fl!("medium"), fl!("large")];

let key_binds = key_binds(&match flags.mode {
Mode::App => tab::Mode::App,
Expand All @@ -1607,6 +1631,7 @@ impl Application for App {
config: flags.config,
mode: flags.mode,
app_themes,
bar_sizes,
context_page: ContextPage::Preview(None, PreviewKind::Selected),
dialog_pages: VecDeque::new(),
dialog_text_input: widget::Id::unique(),
Expand Down Expand Up @@ -1701,7 +1726,7 @@ impl Application for App {
.into_container();

if !self.core().is_condensed() {
nav = nav.max_width(280);
nav = nav.max_width(self.config.nav_bar_size.size());
}

Some(Element::from(
Expand Down Expand Up @@ -1907,6 +1932,10 @@ impl Application for App {
config_set!(app_theme, app_theme);
return self.update_config();
}
Message::NavBarSize(nav_bar_size) => {
config_set!(nav_bar_size, nav_bar_size);
return self.update_config();
}
Message::Compress(entity_opt) => {
let paths = self.selected_paths(entity_opt);
if let Some(current_path) = paths.first() {
Expand Down
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ impl AppTheme {
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum NavBarSize {
Small,
Medium,
Large,
}

impl NavBarSize {
pub fn size(&self) -> f32 {
match self {
NavBarSize::Small => 64.0,
NavBarSize::Medium => 160.0,
NavBarSize::Large => 280.0,
}
}
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Favorite {
Home,
Expand Down Expand Up @@ -99,6 +116,7 @@ impl Favorite {
#[serde(default)]
pub struct Config {
pub app_theme: AppTheme,
pub nav_bar_size: NavBarSize,
pub desktop: DesktopConfig,
pub favorites: Vec<Favorite>,
pub show_details: bool,
Expand Down Expand Up @@ -139,6 +157,7 @@ impl Default for Config {
fn default() -> Self {
Self {
app_theme: AppTheme::System,
nav_bar_size: NavBarSize::Large,
desktop: DesktopConfig::default(),
favorites: vec![
Favorite::Home,
Expand Down