diff --git a/src/commands.rs b/src/commands.rs index 3b92d49..7fa2575 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -252,7 +252,8 @@ impl CommandManager { Ok(None) } - /* handle default commands + /* + TODO: handle default commands else if let Some(callback) = self.callbacks.get(cmd) { callback.as_ref().map(|cb| cb(s, args)).unwrap_or(Ok(None)) } */ diff --git a/src/ui/layout.rs b/src/ui/layout.rs index 5b6be84..8cdefab 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -13,7 +13,6 @@ use cursive::{Cursive, Printer}; use unicode_width::UnicodeWidthStr; use command::Command; -use command::Command::Focus; use commands::CommandResult; use events; use traits::{IntoBoxedViewExt, ViewExt}; @@ -207,6 +206,25 @@ impl View for Layout { } } + fn layout(&mut self, size: Vec2) { + self.last_size = size; + + self.statusbar.layout(Vec2::new(size.x, 2)); + + self.cmdline.layout(Vec2::new(size.x, 1)); + + if let Some(screen) = self.get_current_screen_mut() { + screen.view.layout(Vec2::new(size.x, size.y - 3)); + } + + // the focus view has changed, let the views know so they can redraw + // their items + if self.screenchange { + debug!("layout: new screen selected: {:?}", self.focus); + self.screenchange = false; + } + } + fn required_size(&mut self, constraint: Vec2) -> Vec2 { Vec2::new(constraint.x, constraint.y) } @@ -246,25 +264,6 @@ impl View for Layout { } } - fn layout(&mut self, size: Vec2) { - self.last_size = size; - - self.statusbar.layout(Vec2::new(size.x, 2)); - - self.cmdline.layout(Vec2::new(size.x, 1)); - - if let Some(screen) = self.get_current_screen_mut() { - screen.view.layout(Vec2::new(size.x, size.y - 3)); - } - - // the focus view has changed, let the views know so they can redraw - // their items - if self.screenchange { - debug!("layout: new screen selected: {:?}", self.focus); - self.screenchange = false; - } - } - fn call_on_any<'a>(&mut self, s: &Selector, c: AnyCb<'a>) { if let Some(screen) = self.get_current_screen_mut() { screen.view.call_on_any(s, c); diff --git a/src/ui/playlists.rs b/src/ui/playlists.rs index 57071a2..d8b5c57 100644 --- a/src/ui/playlists.rs +++ b/src/ui/playlists.rs @@ -54,14 +54,11 @@ impl ViewWrapper for PlaylistsView { impl ViewExt for PlaylistsView { fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result { - match cmd { - Command::Delete => { - if let Some(dialog) = self.delete_dialog() { - s.add_layer(dialog); - } - return Ok(CommandResult::Consumed(None)); + if let Command::Delete = cmd { + if let Some(dialog) = self.delete_dialog() { + s.add_layer(dialog); } - _ => {} + return Ok(CommandResult::Consumed(None)); } self.list.on_command(s, cmd) diff --git a/src/ui/search.rs b/src/ui/search.rs index aa184fb..8bd4eb9 100644 --- a/src/ui/search.rs +++ b/src/ui/search.rs @@ -412,6 +412,14 @@ impl View for SearchView { self.tabs.layout(Vec2::new(size.x, size.y - 1)); } + fn on_event(&mut self, event: Event) -> EventResult { + if self.edit_focused { + self.edit.on_event(event) + } else { + self.tabs.on_event(event) + } + } + fn call_on_any<'a>(&mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>) { self.edit.call_on_any(selector, Box::new(|v| callback(v))); self.tabs.call_on_any(selector, Box::new(|v| callback(v))); @@ -425,21 +433,13 @@ impl View for SearchView { Err(()) } } - - fn on_event(&mut self, event: Event) -> EventResult { - if self.edit_focused { - self.edit.on_event(event) - } else { - self.tabs.on_event(event) - } - } } impl ViewExt for SearchView { fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result { match cmd { Command::Search(query) => self.run_search(query.to_string()), - Command::Focus(view) => { + Command::Focus(_) => { self.edit_focused = true; self.clear(); return Ok(CommandResult::Consumed(None)); @@ -454,8 +454,8 @@ impl ViewExt for SearchView { }; if let CommandResult::Ignored = result { - match cmd { - Command::Move(mode, amount) => match mode { + if let Command::Move(mode, _) = cmd { + match mode { MoveMode::Up if !self.edit_focused => { self.edit_focused = true; return Ok(CommandResult::Consumed(None)); @@ -465,8 +465,7 @@ impl ViewExt for SearchView { return Ok(CommandResult::Consumed(None)); } _ => {} - }, - _ => {} + } } } diff --git a/src/ui/tabview.rs b/src/ui/tabview.rs index 23658e3..01f74d8 100644 --- a/src/ui/tabview.rs +++ b/src/ui/tabview.rs @@ -104,28 +104,25 @@ impl View for TabView { impl ViewExt for TabView { fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result { - match cmd { - Command::Move(mode, amount) => { - let amount = match amount { - Some(amount) => *amount, - _ => 1, - }; + if let Command::Move(mode, amount) = cmd { + let amount = match amount { + Some(amount) => *amount, + _ => 1, + }; - let len = self.tabs.len(); + let len = self.tabs.len(); - match mode { - MoveMode::Left if self.selected > 0 => { - self.move_focus(-(amount as i32)); - return Ok(CommandResult::Consumed(None)); - } - MoveMode::Right if self.selected < len - 1 => { - self.move_focus(amount as i32); - return Ok(CommandResult::Consumed(None)); - } - _ => {} + match mode { + MoveMode::Left if self.selected > 0 => { + self.move_focus(-(amount as i32)); + return Ok(CommandResult::Consumed(None)); } + MoveMode::Right if self.selected < len - 1 => { + self.move_focus(amount as i32); + return Ok(CommandResult::Consumed(None)); + } + _ => {} } - _ => {} } if let Some(tab) = self.tabs.get_mut(self.selected) {