Clippy fixes

This commit is contained in:
Rasmus Larsen
2019-05-20 22:32:28 +02:00
parent 1671db14c1
commit 0beaa82a1f
5 changed files with 52 additions and 59 deletions

View File

@@ -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))
} */

View File

@@ -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);

View File

@@ -54,14 +54,11 @@ impl ViewWrapper for PlaylistsView {
impl ViewExt for PlaylistsView {
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
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)

View File

@@ -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<CommandResult, String> {
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));
}
_ => {}
},
_ => {}
}
}
}

View File

@@ -104,28 +104,25 @@ impl View for TabView {
impl ViewExt for TabView {
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
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) {