From 8a46c4bbe190974ce834e8458872b827e88745b3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 9 Jan 2024 15:42:42 -0700 Subject: [PATCH] Reduce nav_bar width and misc improvements --- src/main.rs | 27 ++++++++++++++++++++------- src/menu.rs | 2 +- src/tab.rs | 12 ++++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index ee522c0..459894b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,13 +10,7 @@ use cosmic::{ widget::{self, segmented_button}, Application, ApplicationExt, Element, }; -use std::{ - any::TypeId, - env, fs, - path::{Path, PathBuf}, - process, - time::Instant, -}; +use std::{any::TypeId, env, fs, path::PathBuf, process, time::Instant}; use config::{AppTheme, Config, CONFIG_VERSION}; mod config; @@ -370,6 +364,25 @@ impl Application for App { (app, Command::batch(commands)) } + // The default nav_bar widget needs to have its width reduced for cosmic-files + fn nav_bar(&self) -> Option>> { + if !self.core().nav_bar_active() { + return None; + } + + let nav_model = self.nav_model()?; + + let mut nav = crate::widget::nav_bar(nav_model, |entity| { + message::cosmic(cosmic::app::cosmic::Message::NavBar(entity)) + }); + + if !self.core().is_condensed() { + nav = nav.max_width(200); + } + + Some(Element::from(nav)) + } + fn nav_model(&self) -> Option<&segmented_button::SingleSelectModel> { Some(&self.nav_model) } diff --git a/src/menu.rs b/src/menu.rs index fb516a8..fa356ef 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -11,7 +11,7 @@ use cosmic::{ Element, }; -use crate::{fl, Action, Config, Message}; +use crate::{fl, Action, Message}; macro_rules! menu_button { ($($x:expr),+ $(,)?) => ( diff --git a/src/tab.rs b/src/tab.rs index 426f234..a9fe608 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -331,7 +331,7 @@ pub fn scan_trash() -> Vec { items } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum Location { Path(PathBuf), Trash, @@ -548,9 +548,13 @@ impl Tab { } } if let Some(location) = cd { - self.location = location; - self.items_opt = None; - true + if location != self.location { + self.location = location; + self.items_opt = None; + true + } else { + false + } } else { false }