Move to enum-based commands
This commit is contained in:
@@ -12,6 +12,8 @@ use cursive::views::EditView;
|
||||
use cursive::{Cursive, Printer};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use command::Command;
|
||||
use command::Command::Focus;
|
||||
use commands::CommandResult;
|
||||
use events;
|
||||
use traits::{IntoBoxedViewExt, ViewExt};
|
||||
@@ -283,29 +285,28 @@ impl View for Layout {
|
||||
}
|
||||
|
||||
impl ViewExt for Layout {
|
||||
fn on_command(
|
||||
&mut self,
|
||||
s: &mut Cursive,
|
||||
cmd: &str,
|
||||
args: &[String],
|
||||
) -> Result<CommandResult, String> {
|
||||
if cmd == "focus" {
|
||||
if let Some(view) = args.get(0) {
|
||||
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
match cmd {
|
||||
Command::Focus(view) => {
|
||||
if self.views.keys().any(|k| k == view) {
|
||||
self.set_view(view.clone());
|
||||
let screen = self.views.get_mut(view).unwrap();
|
||||
screen.view.on_command(s, cmd, args)?;
|
||||
screen.view.on_command(s, cmd)?;
|
||||
}
|
||||
|
||||
Ok(CommandResult::Consumed(None))
|
||||
}
|
||||
Command::Back => {
|
||||
self.pop_view();
|
||||
Ok(CommandResult::Consumed(None))
|
||||
}
|
||||
_ => {
|
||||
if let Some(screen) = self.get_current_screen_mut() {
|
||||
screen.view.on_command(s, cmd)
|
||||
} else {
|
||||
Ok(CommandResult::Ignored)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(CommandResult::Consumed(None))
|
||||
} else if cmd == "back" {
|
||||
self.pop_view();
|
||||
Ok(CommandResult::Consumed(None))
|
||||
} else if let Some(screen) = self.get_current_screen_mut() {
|
||||
screen.view.on_command(s, cmd, args)
|
||||
} else {
|
||||
Ok(CommandResult::Ignored)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user