Skip to content

Commit

Permalink
Add maximize buffer command to command bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jhff committed Jul 30, 2023
1 parent 5193681 commit d7ddcdd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 19 deletions.
35 changes: 22 additions & 13 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ impl Dashboard {
self.last_changed = Some(Instant::now());
}
}
pane::Message::MaximizePane => {
if self.panes.maximized().is_some() {
self.panes.restore();
} else if let Some(pane) = self.focus {
self.panes.maximize(&pane);
}
}
pane::Message::MaximizePane => self.maximize_pane(),
},
Message::SideMenu(message) => {
let event = self.side_menu.update(message);
Expand Down Expand Up @@ -315,12 +309,19 @@ impl Dashboard {
match command_bar.update(message) {
Some(command_bar::Event::Command(command)) => {
match command {
command_bar::Command::OpenConfig => {
let _ = open::that(Config::config_dir());
}
command_bar::Command::ToggleSidebarVisibility => {
self.side_menu.toggle_visibility();
}
command_bar::Command::Buffer(command) => match command {
command_bar::Buffer::Maximize => self.maximize_pane(),
},
command_bar::Command::Configuration(command) => match command {
command_bar::Configuration::Open => {
let _ = open::that(Config::config_dir());
}
},
command_bar::Command::UI(command) => match command {
command_bar::Ui::ToggleSidebarVisibility => {
self.side_menu.toggle_visibility();
}
},
}

return self.toggle_command_bar();
Expand Down Expand Up @@ -614,6 +615,14 @@ impl Dashboard {
}
}

fn maximize_pane(&mut self) {
if self.panes.maximized().is_some() {
self.panes.restore();
} else if let Some(pane) = self.focus {
self.panes.maximize(&pane);
}
}

fn reset_pane(&mut self, pane: pane_grid::Pane) -> Command<Message> {
self.panes
.iter()
Expand Down
57 changes: 51 additions & 6 deletions src/screen/dashboard/command_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,66 @@ pub enum Event {

#[derive(Debug, Clone)]
pub enum Command {
OpenConfig,
Buffer(Buffer),
Configuration(Configuration),
UI(Ui),
}

#[derive(Debug, Clone)]
pub enum Buffer {
Maximize,
}

#[derive(Debug, Clone)]
pub enum Configuration {
Open,
}

#[derive(Debug, Clone)]
pub enum Ui {
ToggleSidebarVisibility,
}

impl Command {
pub fn list() -> Vec<Self> {
vec![
Command::Buffer(Buffer::Maximize),
Command::Configuration(Configuration::Open),
Command::UI(Ui::ToggleSidebarVisibility),
]
}
}

impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Command::OpenConfig => write!(f, "Configuration: Open Directory"),
Command::ToggleSidebarVisibility => write!(f, "UI: Toggle Sidebar visibility"),
Command::Buffer(buffer) => write!(f, "Buffer: {}", buffer),
Command::Configuration(config) => write!(f, "Configuration: {}", config),
Command::UI(ui) => write!(f, "UI: {}", ui),
}
}
}

impl Command {
pub fn list() -> Vec<Self> {
vec![Command::OpenConfig, Command::ToggleSidebarVisibility]
impl std::fmt::Display for Buffer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Buffer::Maximize => write!(f, "Maximize/Restore"),
}
}
}

impl std::fmt::Display for Configuration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Configuration::Open => write!(f, "Open directory"),
}
}
}

impl std::fmt::Display for Ui {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Ui::ToggleSidebarVisibility => write!(f, "Toggle sidebar visibility"),
}
}
}

0 comments on commit d7ddcdd

Please sign in to comment.