Fix clippy issues
This commit is contained in:
parent
2106b69c15
commit
80d89157e9
@ -182,12 +182,10 @@ fn cursor_rect(mode: &mode::Mode,
|
|||||||
} else {
|
} else {
|
||||||
let cursor_width = if mode.is(&mode::NvimMode::Insert) {
|
let cursor_width = if mode.is(&mode::NvimMode::Insert) {
|
||||||
char_width / 5.0
|
char_width / 5.0
|
||||||
} else {
|
} else if double_width {
|
||||||
if double_width {
|
|
||||||
char_width * 2.0
|
char_width * 2.0
|
||||||
} else {
|
} else {
|
||||||
char_width
|
char_width
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(line_y, cursor_width, line_height)
|
(line_y, cursor_width, line_height)
|
||||||
|
@ -92,7 +92,7 @@ fn open_arg_impl<I>(args: I) -> Option<String>
|
|||||||
{
|
{
|
||||||
args.skip(1)
|
args.skip(1)
|
||||||
.last()
|
.last()
|
||||||
.map(|a| if !a.starts_with("-") {
|
.map(|a| if !a.starts_with('-') {
|
||||||
Some(a.to_owned())
|
Some(a.to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
40
src/nvim.rs
40
src/nvim.rs
@ -27,7 +27,7 @@ pub trait RedrawEvents {
|
|||||||
|
|
||||||
fn on_redraw(&self, mode: &RepaintMode);
|
fn on_redraw(&self, mode: &RepaintMode);
|
||||||
|
|
||||||
fn on_highlight_set(&mut self, attrs: &Vec<(Value, Value)>) -> RepaintMode;
|
fn on_highlight_set(&mut self, attrs: &[(Value, Value)]) -> RepaintMode;
|
||||||
|
|
||||||
fn on_eol_clear(&mut self) -> RepaintMode;
|
fn on_eol_clear(&mut self) -> RepaintMode;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ pub trait RedrawEvents {
|
|||||||
fn on_busy(&mut self, busy: bool) -> RepaintMode;
|
fn on_busy(&mut self, busy: bool) -> RepaintMode;
|
||||||
|
|
||||||
fn popupmenu_show(&mut self,
|
fn popupmenu_show(&mut self,
|
||||||
menu: &Vec<Vec<&str>>,
|
menu: &[Vec<&str>],
|
||||||
selected: i64,
|
selected: i64,
|
||||||
row: u64,
|
row: u64,
|
||||||
col: u64)
|
col: u64)
|
||||||
@ -74,32 +74,32 @@ pub trait GuiApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! try_str {
|
macro_rules! try_str {
|
||||||
($exp:expr) => ($exp.as_str().ok_or("Can't convert argument to string".to_owned())?)
|
($exp:expr) => ($exp.as_str().ok_or_else(|| "Can't convert argument to string".to_owned())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! try_int {
|
macro_rules! try_int {
|
||||||
($expr:expr) => ($expr.as_i64().ok_or("Can't convert argument to int".to_owned())?)
|
($expr:expr) => ($expr.as_i64().ok_or_else(|| "Can't convert argument to int".to_owned())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! try_uint {
|
macro_rules! try_uint {
|
||||||
($exp:expr) => ($exp.as_u64().ok_or("Can't convert argument to u64".to_owned())?)
|
($exp:expr) => ($exp.as_u64().ok_or_else(|| "Can't convert argument to u64".to_owned())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! try_bool {
|
macro_rules! try_bool {
|
||||||
($exp:expr) => ($exp.as_bool().ok_or("Can't convert argument to bool".to_owned())?)
|
($exp:expr) => ($exp.as_bool().ok_or_else(|| "Can't convert argument to bool".to_owned())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! map_array {
|
macro_rules! map_array {
|
||||||
($arg:expr, $err:expr, |$item:ident| $exp:expr) => (
|
($arg:expr, $err:expr, |$item:ident| $exp:expr) => (
|
||||||
$arg.as_array()
|
$arg.as_array()
|
||||||
.ok_or($err)
|
.ok_or_else(|| $err)
|
||||||
.and_then(|items| items.iter().map(|$item| {
|
.and_then(|items| items.iter().map(|$item| {
|
||||||
$exp
|
$exp
|
||||||
}).collect::<Result<Vec<_>, _>>())
|
}).collect::<Result<Vec<_>, _>>())
|
||||||
);
|
);
|
||||||
($arg:expr, $err:expr, |$item:ident| {$exp:expr}) => (
|
($arg:expr, $err:expr, |$item:ident| {$exp:expr}) => (
|
||||||
$arg.as_array()
|
$arg.as_array()
|
||||||
.ok_or($err)
|
.ok_or_else(|| $err)
|
||||||
.and_then(|items| items.iter().map(|$item| {
|
.and_then(|items| items.iter().map(|$item| {
|
||||||
$exp
|
$exp
|
||||||
}).collect::<Result<Vec<_>, _>>())
|
}).collect::<Result<Vec<_>, _>>())
|
||||||
@ -118,7 +118,7 @@ impl CursorShape {
|
|||||||
fn new(shape_code: &Value) -> Result<CursorShape, String> {
|
fn new(shape_code: &Value) -> Result<CursorShape, String> {
|
||||||
let str_code = shape_code
|
let str_code = shape_code
|
||||||
.as_str()
|
.as_str()
|
||||||
.ok_or("Can't convert cursor shape to string".to_owned())?;
|
.ok_or_else(|| "Can't convert cursor shape to string".to_owned())?;
|
||||||
|
|
||||||
Ok(match str_code {
|
Ok(match str_code {
|
||||||
"block" => CursorShape::Block,
|
"block" => CursorShape::Block,
|
||||||
@ -270,13 +270,13 @@ pub fn post_start_init(nvim: &mut Neovim,
|
|||||||
opts.set_popupmenu_external(false);
|
opts.set_popupmenu_external(false);
|
||||||
opts.set_tabline_external(true);
|
opts.set_tabline_external(true);
|
||||||
nvim.ui_attach(cols, rows, opts)
|
nvim.ui_attach(cols, rows, opts)
|
||||||
.map_err(|e| NvimInitError::new_post_init(e))?;
|
.map_err(NvimInitError::new_post_init)?;
|
||||||
nvim.command("runtime! ginit.vim")
|
nvim.command("runtime! ginit.vim")
|
||||||
.map_err(|e| NvimInitError::new_post_init(e))?;
|
.map_err(NvimInitError::new_post_init)?;
|
||||||
|
|
||||||
if let Some(path) = open_path {
|
if let Some(path) = open_path {
|
||||||
nvim.command(&format!("e {}", path))
|
nvim.command(&format!("e {}", path))
|
||||||
.map_err(|e| NvimInitError::new_post_init(e))?;
|
.map_err(NvimInitError::new_post_init)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -300,9 +300,9 @@ impl NvimHandler {
|
|||||||
for ev in ¶ms {
|
for ev in ¶ms {
|
||||||
if let Some(ev_args) = ev.as_array() {
|
if let Some(ev_args) = ev.as_array() {
|
||||||
if let Some(ev_name) = ev_args[0].as_str() {
|
if let Some(ev_name) = ev_args[0].as_str() {
|
||||||
for ref local_args in ev_args.iter().skip(1) {
|
for local_args in ev_args.iter().skip(1) {
|
||||||
let args = match *local_args {
|
let args = match *local_args {
|
||||||
&Value::Array(ref ar) => ar.clone(),
|
Value::Array(ref ar) => ar.clone(),
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
};
|
};
|
||||||
let call_reapint_mode = call(ui, ev_name, &args)?;
|
let call_reapint_mode = call(ui, ev_name, &args)?;
|
||||||
@ -321,7 +321,7 @@ impl NvimHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
"Gui" => {
|
"Gui" => {
|
||||||
if params.len() > 0 {
|
if !params.is_empty() {
|
||||||
if let Some(ev_name) = params[0].as_str().map(String::from) {
|
if let Some(ev_name) = params[0].as_str().map(String::from) {
|
||||||
let args = params.iter().skip(1).cloned().collect();
|
let args = params.iter().skip(1).cloned().collect();
|
||||||
self.safe_call(move |ui| {
|
self.safe_call(move |ui| {
|
||||||
@ -390,7 +390,7 @@ fn call_gui_event(ui: &mut shell::State,
|
|||||||
|
|
||||||
fn call(ui: &mut shell::State,
|
fn call(ui: &mut shell::State,
|
||||||
method: &str,
|
method: &str,
|
||||||
args: &Vec<Value>)
|
args: &[Value])
|
||||||
-> result::Result<RepaintMode, String> {
|
-> result::Result<RepaintMode, String> {
|
||||||
let repaint_mode = match method {
|
let repaint_mode = match method {
|
||||||
"cursor_goto" => ui.on_cursor_goto(try_uint!(args[0]), try_uint!(args[1])),
|
"cursor_goto" => ui.on_cursor_goto(try_uint!(args[0]), try_uint!(args[1])),
|
||||||
@ -439,7 +439,7 @@ fn call(ui: &mut shell::State,
|
|||||||
"tabline_update" => {
|
"tabline_update" => {
|
||||||
let tabs_out = map_array!(args[1], "Error get tabline list".to_owned(), |tab| {
|
let tabs_out = map_array!(args[1], "Error get tabline list".to_owned(), |tab| {
|
||||||
tab.as_map()
|
tab.as_map()
|
||||||
.ok_or("Error get map for tab".to_owned())
|
.ok_or_else(|| "Error get map for tab".to_owned())
|
||||||
.and_then(|tab_map| tab_map.to_attrs_map())
|
.and_then(|tab_map| tab_map.to_attrs_map())
|
||||||
.map(|tab_attrs| {
|
.map(|tab_attrs| {
|
||||||
let name_attr = tab_attrs
|
let name_attr = tab_attrs
|
||||||
@ -460,7 +460,7 @@ fn call(ui: &mut shell::State,
|
|||||||
"Error get array key value for mode_info".to_owned(),
|
"Error get array key value for mode_info".to_owned(),
|
||||||
|mi| {
|
|mi| {
|
||||||
mi.as_map()
|
mi.as_map()
|
||||||
.ok_or("Erro get map for mode_info".to_owned())
|
.ok_or_else(|| "Erro get map for mode_info".to_owned())
|
||||||
.and_then(|mi_map| ModeInfo::new(mi_map))
|
.and_then(|mi_map| ModeInfo::new(mi_map))
|
||||||
})?;
|
})?;
|
||||||
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
||||||
@ -480,7 +480,7 @@ pub trait ErrorReport {
|
|||||||
|
|
||||||
impl<T> ErrorReport for result::Result<T, CallError> {
|
impl<T> ErrorReport for result::Result<T, CallError> {
|
||||||
fn report_err(&self, _: &mut NeovimApi) {
|
fn report_err(&self, _: &mut NeovimApi) {
|
||||||
if let &Err(ref err) = self {
|
if let Err(ref err) = *self {
|
||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
//nvim.report_error(&err_msg).expect("Error report error :)");
|
//nvim.report_error(&err_msg).expect("Error report error :)");
|
||||||
}
|
}
|
||||||
@ -509,7 +509,7 @@ impl RepaintMode {
|
|||||||
}
|
}
|
||||||
(RepaintMode::AreaList(mut target), RepaintMode::AreaList(source)) => {
|
(RepaintMode::AreaList(mut target), RepaintMode::AreaList(source)) => {
|
||||||
for s in &source.list {
|
for s in &source.list {
|
||||||
target.join(&s);
|
target.join(s);
|
||||||
}
|
}
|
||||||
RepaintMode::AreaList(target)
|
RepaintMode::AreaList(target)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl State {
|
|||||||
|
|
||||||
fn before_show(&mut self,
|
fn before_show(&mut self,
|
||||||
shell: &shell::State,
|
shell: &shell::State,
|
||||||
menu_items: &Vec<Vec<&str>>,
|
menu_items: &[Vec<&str>],
|
||||||
selected: i64) {
|
selected: i64) {
|
||||||
if self.nvim.is_none() {
|
if self.nvim.is_none() {
|
||||||
self.nvim = Some(shell.nvim_clone());
|
self.nvim = Some(shell.nvim_clone());
|
||||||
@ -45,7 +45,7 @@ impl State {
|
|||||||
self.select(selected);
|
self.select(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_tree(&self, menu: &Vec<Vec<&str>>, shell: &shell::State) {
|
fn update_tree(&self, menu: &[Vec<&str>], shell: &shell::State) {
|
||||||
if menu.is_empty() {
|
if menu.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ impl State {
|
|||||||
self.renderer.set_property_foreground_rgba(Some(&shell.get_foreground().into()));
|
self.renderer.set_property_foreground_rgba(Some(&shell.get_foreground().into()));
|
||||||
self.renderer.set_property_background_rgba(Some(&shell.get_background().into()));
|
self.renderer.set_property_background_rgba(Some(&shell.get_background().into()));
|
||||||
|
|
||||||
let col_count = menu.get(0).unwrap().len();
|
let col_count = menu[0].len();
|
||||||
let columns = self.tree.get_columns();
|
let columns = self.tree.get_columns();
|
||||||
|
|
||||||
if columns.len() != col_count {
|
if columns.len() != col_count {
|
||||||
@ -166,7 +166,7 @@ impl PopupMenu {
|
|||||||
|
|
||||||
pub fn show(&mut self,
|
pub fn show(&mut self,
|
||||||
shell: &shell::State,
|
shell: &shell::State,
|
||||||
menu_items: &Vec<Vec<&str>>,
|
menu_items: &[Vec<&str>],
|
||||||
selected: i64,
|
selected: i64,
|
||||||
x: i32,
|
x: i32,
|
||||||
y: i32,
|
y: i32,
|
||||||
|
@ -21,12 +21,12 @@ const CURRENT_DIR_PIXBUF: &str = "folder";
|
|||||||
const PLAIN_FILE_PIXBUF: &str = "text-x-generic";
|
const PLAIN_FILE_PIXBUF: &str = "text-x-generic";
|
||||||
|
|
||||||
enum ProjectViewColumns {
|
enum ProjectViewColumns {
|
||||||
NameColumn,
|
Name,
|
||||||
PathColumn,
|
Path,
|
||||||
UriColumn,
|
Uri,
|
||||||
PixbufColumn,
|
Pixbuf,
|
||||||
ProjectColumn,
|
Project,
|
||||||
ProjectStoredColumn,
|
ProjectStored,
|
||||||
}
|
}
|
||||||
|
|
||||||
const COLUMN_COUNT: usize = 6;
|
const COLUMN_COUNT: usize = 6;
|
||||||
@ -36,12 +36,12 @@ const COLUMN_TYPES: [Type; COLUMN_COUNT] = [Type::String,
|
|||||||
Type::String,
|
Type::String,
|
||||||
Type::Bool,
|
Type::Bool,
|
||||||
Type::Bool];
|
Type::Bool];
|
||||||
const COLUMN_IDS: [u32; COLUMN_COUNT] = [ProjectViewColumns::NameColumn as u32,
|
const COLUMN_IDS: [u32; COLUMN_COUNT] = [ProjectViewColumns::Name as u32,
|
||||||
ProjectViewColumns::PathColumn as u32,
|
ProjectViewColumns::Path as u32,
|
||||||
ProjectViewColumns::UriColumn as u32,
|
ProjectViewColumns::Uri as u32,
|
||||||
ProjectViewColumns::PixbufColumn as u32,
|
ProjectViewColumns::Pixbuf as u32,
|
||||||
ProjectViewColumns::ProjectColumn as u32,
|
ProjectViewColumns::Project as u32,
|
||||||
ProjectViewColumns::ProjectStoredColumn as u32];
|
ProjectViewColumns::ProjectStored as u32];
|
||||||
|
|
||||||
pub struct Projects {
|
pub struct Projects {
|
||||||
shell: Rc<RefCell<Shell>>,
|
shell: Rc<RefCell<Shell>>,
|
||||||
@ -161,12 +161,12 @@ impl Projects {
|
|||||||
let list_store = self.get_list_store();
|
let list_store = self.get_list_store();
|
||||||
if let Some(iter) = list_store.get_iter(path) {
|
if let Some(iter) = list_store.get_iter(path) {
|
||||||
let value: bool = list_store
|
let value: bool = list_store
|
||||||
.get_value(&iter, ProjectViewColumns::ProjectStoredColumn as i32)
|
.get_value(&iter, ProjectViewColumns::ProjectStored as i32)
|
||||||
.get()
|
.get()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
list_store.set_value(&iter,
|
list_store.set_value(&iter,
|
||||||
ProjectViewColumns::ProjectStoredColumn as u32,
|
ProjectViewColumns::ProjectStored as u32,
|
||||||
&ToValue::to_value(&!value));
|
&ToValue::to_value(&!value));
|
||||||
|
|
||||||
let pixbuf = if value {
|
let pixbuf = if value {
|
||||||
@ -176,10 +176,10 @@ impl Projects {
|
|||||||
};
|
};
|
||||||
|
|
||||||
list_store.set_value(&iter,
|
list_store.set_value(&iter,
|
||||||
ProjectViewColumns::PixbufColumn as u32,
|
ProjectViewColumns::Pixbuf as u32,
|
||||||
&ToValue::to_value(pixbuf));
|
&ToValue::to_value(pixbuf));
|
||||||
|
|
||||||
let uri_value = list_store.get_value(&iter, ProjectViewColumns::UriColumn as i32);
|
let uri_value = list_store.get_value(&iter, ProjectViewColumns::Uri as i32);
|
||||||
let uri: String = uri_value.get().unwrap();
|
let uri: String = uri_value.get().unwrap();
|
||||||
|
|
||||||
let mut store = self.store.as_mut().unwrap();
|
let mut store = self.store.as_mut().unwrap();
|
||||||
@ -194,8 +194,8 @@ impl Projects {
|
|||||||
|
|
||||||
|
|
||||||
fn open_uri(&self, model: &TreeModel, iter: &TreeIter) {
|
fn open_uri(&self, model: &TreeModel, iter: &TreeIter) {
|
||||||
let uri: String = model.get_value(&iter, ProjectViewColumns::UriColumn as i32).get().unwrap();
|
let uri: String = model.get_value(iter, ProjectViewColumns::Uri as i32).get().unwrap();
|
||||||
let project: bool = model.get_value(&iter, ProjectViewColumns::ProjectColumn as i32).get().unwrap();
|
let project: bool = model.get_value(iter, ProjectViewColumns::Project as i32).get().unwrap();
|
||||||
|
|
||||||
let shell = self.shell.borrow();
|
let shell = self.shell.borrow();
|
||||||
if project {
|
if project {
|
||||||
@ -226,16 +226,13 @@ impl Projects {
|
|||||||
const CANCEL_ID: i32 = 1;
|
const CANCEL_ID: i32 = 1;
|
||||||
|
|
||||||
dlg.add_buttons(&[("_Open", OPEN_ID), ("_Cancel", CANCEL_ID)]);
|
dlg.add_buttons(&[("_Open", OPEN_ID), ("_Cancel", CANCEL_ID)]);
|
||||||
match dlg.run() {
|
if dlg.run() == OPEN_ID {
|
||||||
OPEN_ID => {
|
|
||||||
if let Some(filename) = dlg.get_filename() {
|
if let Some(filename) = dlg.get_filename() {
|
||||||
if let Some(filename) = filename.to_str() {
|
if let Some(filename) = filename.to_str() {
|
||||||
self.shell.borrow().open_file(filename);
|
self.shell.borrow().open_file(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
dlg.destroy();
|
dlg.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +268,7 @@ impl Projects {
|
|||||||
|
|
||||||
image_column.add_attribute(&icon_renderer,
|
image_column.add_attribute(&icon_renderer,
|
||||||
"icon-name",
|
"icon-name",
|
||||||
ProjectViewColumns::PixbufColumn as i32);
|
ProjectViewColumns::Pixbuf as i32);
|
||||||
|
|
||||||
self.tree.append_column(&image_column);
|
self.tree.append_column(&image_column);
|
||||||
|
|
||||||
@ -287,10 +284,10 @@ impl Projects {
|
|||||||
|
|
||||||
text_column.add_attribute(&self.name_renderer,
|
text_column.add_attribute(&self.name_renderer,
|
||||||
"markup",
|
"markup",
|
||||||
ProjectViewColumns::NameColumn as i32);
|
ProjectViewColumns::Name as i32);
|
||||||
text_column.add_attribute(&self.path_renderer,
|
text_column.add_attribute(&self.path_renderer,
|
||||||
"markup",
|
"markup",
|
||||||
ProjectViewColumns::PathColumn as i32);
|
ProjectViewColumns::Path as i32);
|
||||||
|
|
||||||
let area = text_column
|
let area = text_column
|
||||||
.get_area()
|
.get_area()
|
||||||
@ -309,10 +306,10 @@ impl Projects {
|
|||||||
toggle_column.pack_start(&self.toggle_renderer, true);
|
toggle_column.pack_start(&self.toggle_renderer, true);
|
||||||
toggle_column.add_attribute(&self.toggle_renderer,
|
toggle_column.add_attribute(&self.toggle_renderer,
|
||||||
"visible",
|
"visible",
|
||||||
ProjectViewColumns::ProjectColumn as i32);
|
ProjectViewColumns::Project as i32);
|
||||||
toggle_column.add_attribute(&self.toggle_renderer,
|
toggle_column.add_attribute(&self.toggle_renderer,
|
||||||
"active",
|
"active",
|
||||||
ProjectViewColumns::ProjectStoredColumn as i32);
|
ProjectViewColumns::ProjectStored as i32);
|
||||||
|
|
||||||
self.tree.append_column(&toggle_column);
|
self.tree.append_column(&toggle_column);
|
||||||
}
|
}
|
||||||
@ -384,7 +381,7 @@ impl EntryStore {
|
|||||||
pub fn find_mut(&mut self, uri: &str) -> Option<&mut Entry> {
|
pub fn find_mut(&mut self, uri: &str) -> Option<&mut Entry> {
|
||||||
self.entries
|
self.entries
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|e| e.project == true && e.uri == uri)
|
.find(|e| e.project && e.uri == uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(nvim: &mut Neovim) -> EntryStore {
|
pub fn load(nvim: &mut Neovim) -> EntryStore {
|
||||||
@ -399,7 +396,7 @@ impl EntryStore {
|
|||||||
if let Some(pwd) = pwd.as_str() {
|
if let Some(pwd) = pwd.as_str() {
|
||||||
if entries
|
if entries
|
||||||
.iter()
|
.iter()
|
||||||
.find(|e| e.project == true && e.uri == pwd)
|
.find(|e| e.project && e.uri == pwd)
|
||||||
.is_none() {
|
.is_none() {
|
||||||
entries.insert(0, Entry::new_current_project(pwd));
|
entries.insert(0, Entry::new_current_project(pwd));
|
||||||
}
|
}
|
||||||
@ -467,7 +464,7 @@ impl Entry {
|
|||||||
uri: uri.to_owned(),
|
uri: uri.to_owned(),
|
||||||
path: path.parent()
|
path: path.parent()
|
||||||
.map(|s| format!("<small>{}</small>", encode_minimal(&s.to_string_lossy())))
|
.map(|s| format!("<small>{}</small>", encode_minimal(&s.to_string_lossy())))
|
||||||
.unwrap_or("".to_owned()),
|
.unwrap_or_else(|| "".to_owned()),
|
||||||
file_name: format!("<big>{}</big>", encode_minimal(name)),
|
file_name: format!("<big>{}</big>", encode_minimal(name)),
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
pixbuf: BOOKMARKED_PIXBUF,
|
pixbuf: BOOKMARKED_PIXBUF,
|
||||||
@ -480,13 +477,13 @@ impl Entry {
|
|||||||
let path = Path::new(uri);
|
let path = Path::new(uri);
|
||||||
let name = path.file_name()
|
let name = path.file_name()
|
||||||
.map(|f| f.to_string_lossy().as_ref().to_owned())
|
.map(|f| f.to_string_lossy().as_ref().to_owned())
|
||||||
.unwrap_or(path.to_string_lossy().as_ref().to_owned());
|
.unwrap_or_else(|| path.to_string_lossy().as_ref().to_owned());
|
||||||
|
|
||||||
Entry {
|
Entry {
|
||||||
uri: uri.to_owned(),
|
uri: uri.to_owned(),
|
||||||
path: path.parent()
|
path: path.parent()
|
||||||
.map(|s| format!("<small>{}</small>", encode_minimal(&s.to_string_lossy())))
|
.map(|s| format!("<small>{}</small>", encode_minimal(&s.to_string_lossy())))
|
||||||
.unwrap_or("".to_owned()),
|
.unwrap_or_else(|| "".to_owned()),
|
||||||
file_name: format!("<big>{}</big>", encode_minimal(&name)),
|
file_name: format!("<big>{}</big>", encode_minimal(&name)),
|
||||||
name,
|
name,
|
||||||
pixbuf: CURRENT_DIR_PIXBUF,
|
pixbuf: CURRENT_DIR_PIXBUF,
|
||||||
@ -499,7 +496,7 @@ impl Entry {
|
|||||||
let path = Path::new(uri);
|
let path = Path::new(uri);
|
||||||
let name = path.file_name()
|
let name = path.file_name()
|
||||||
.map(|f| f.to_string_lossy().as_ref().to_owned())
|
.map(|f| f.to_string_lossy().as_ref().to_owned())
|
||||||
.unwrap_or("<empty>".to_owned());
|
.unwrap_or_else(|| "<empty>".to_owned());
|
||||||
|
|
||||||
Entry {
|
Entry {
|
||||||
uri: uri.to_owned(),
|
uri: uri.to_owned(),
|
||||||
@ -508,7 +505,7 @@ impl Entry {
|
|||||||
format!("<small>{}</small>",
|
format!("<small>{}</small>",
|
||||||
encode_minimal(&s.to_string_lossy()))
|
encode_minimal(&s.to_string_lossy()))
|
||||||
})
|
})
|
||||||
.unwrap_or("".to_owned()),
|
.unwrap_or_else(|| "".to_owned()),
|
||||||
file_name: format!("<big>{}</big>", encode_minimal(&name)),
|
file_name: format!("<big>{}</big>", encode_minimal(&name)),
|
||||||
name,
|
name,
|
||||||
pixbuf: PLAIN_FILE_PIXBUF,
|
pixbuf: PLAIN_FILE_PIXBUF,
|
||||||
|
23
src/shell.rs
23
src/shell.rs
@ -198,7 +198,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_draw_area<M: AsRef<ModelRect>>(&self, rect_list: &Vec<M>) {
|
fn queue_draw_area<M: AsRef<ModelRect>>(&self, rect_list: &[M]) {
|
||||||
match (&self.line_height, &self.char_width) {
|
match (&self.line_height, &self.char_width) {
|
||||||
(&Some(line_height), &Some(char_width)) => {
|
(&Some(line_height), &Some(char_width)) => {
|
||||||
for rect in rect_list {
|
for rect in rect_list {
|
||||||
@ -964,11 +964,11 @@ impl RedrawEvents for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_redraw(&self, mode: &RepaintMode) {
|
fn on_redraw(&self, mode: &RepaintMode) {
|
||||||
match mode {
|
match *mode {
|
||||||
&RepaintMode::All => self.drawing_area.queue_draw(),
|
RepaintMode::All => self.drawing_area.queue_draw(),
|
||||||
&RepaintMode::Area(ref rect) => self.queue_draw_area(&vec![rect]),
|
RepaintMode::Area(ref rect) => self.queue_draw_area(&[rect]),
|
||||||
&RepaintMode::AreaList(ref list) => self.queue_draw_area(&list.list),
|
RepaintMode::AreaList(ref list) => self.queue_draw_area(&list.list),
|
||||||
&RepaintMode::Nothing => (),
|
RepaintMode::Nothing => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,7 +981,7 @@ impl RedrawEvents for State {
|
|||||||
RepaintMode::Area(self.model.scroll(count))
|
RepaintMode::Area(self.model.scroll(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_highlight_set(&mut self, attrs: &Vec<(Value, Value)>) -> RepaintMode {
|
fn on_highlight_set(&mut self, attrs: &[(Value, Value)]) -> RepaintMode {
|
||||||
let mut model_attrs = Attrs::new();
|
let mut model_attrs = Attrs::new();
|
||||||
|
|
||||||
for &(ref key_val, ref val) in attrs {
|
for &(ref key_val, ref val) in attrs {
|
||||||
@ -1065,22 +1065,19 @@ impl RedrawEvents for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn popupmenu_show(&mut self,
|
fn popupmenu_show(&mut self,
|
||||||
menu: &Vec<Vec<&str>>,
|
menu: &[Vec<&str>],
|
||||||
selected: i64,
|
selected: i64,
|
||||||
row: u64,
|
row: u64,
|
||||||
col: u64)
|
col: u64)
|
||||||
-> RepaintMode {
|
-> RepaintMode {
|
||||||
match (&self.line_height, &self.char_width) {
|
if let (&Some(line_height), &Some(char_width)) = (&self.line_height, &self.char_width) {
|
||||||
(&Some(line_height), &Some(char_width)) => {
|
|
||||||
let point = ModelRect::point(col as usize, row as usize);
|
let point = ModelRect::point(col as usize, row as usize);
|
||||||
let (x, y, width, height) = point.to_area(line_height, char_width);
|
let (x, y, width, height) = point.to_area(line_height, char_width);
|
||||||
|
|
||||||
self.popup_menu
|
self.popup_menu
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.show(&self, menu, selected, x, y, width, height);
|
.show(self, menu, selected, x, y, width, height);
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
|
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ pub fn can_close_window(comps: &UiMutex<Components>, shell: &RefCell<Shell>) ->
|
|||||||
|
|
||||||
fn show_not_saved_dlg(comps: &UiMutex<Components>,
|
fn show_not_saved_dlg(comps: &UiMutex<Components>,
|
||||||
shell: &Shell,
|
shell: &Shell,
|
||||||
changed_bufs: &Vec<String>)
|
changed_bufs: &[String])
|
||||||
-> bool {
|
-> bool {
|
||||||
let mut changed_files = changed_bufs
|
let mut changed_files = changed_bufs
|
||||||
.iter()
|
.iter()
|
||||||
@ -62,8 +62,7 @@ fn show_not_saved_dlg(comps: &UiMutex<Components>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CLOSE_WITHOUT_SAVE => true,
|
CLOSE_WITHOUT_SAVE => true,
|
||||||
CANCEL_ID => false,
|
CANCEL_ID | _ => false,
|
||||||
_ => false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dlg.destroy();
|
dlg.destroy();
|
||||||
|
@ -32,7 +32,7 @@ impl State {
|
|||||||
let target = &self.data[idx as usize];
|
let target = &self.data[idx as usize];
|
||||||
if Some(target) != self.selected.as_ref() {
|
if Some(target) != self.selected.as_ref() {
|
||||||
let mut nvim = self.nvim.as_ref().unwrap().borrow_mut();
|
let mut nvim = self.nvim.as_ref().unwrap().borrow_mut();
|
||||||
nvim.set_current_tabpage(&target).report_err(&mut **nvim);
|
nvim.set_current_tabpage(target).report_err(&mut **nvim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ impl Tabline {
|
|||||||
fn update_state(&self,
|
fn update_state(&self,
|
||||||
nvim: &Rc<RefCell<nvim::NeovimClient>>,
|
nvim: &Rc<RefCell<nvim::NeovimClient>>,
|
||||||
selected: &Tabpage,
|
selected: &Tabpage,
|
||||||
tabs: &Vec<(Tabpage, Option<String>)>) {
|
tabs: &[(Tabpage, Option<String>)]) {
|
||||||
let mut state = self.state.borrow_mut();
|
let mut state = self.state.borrow_mut();
|
||||||
|
|
||||||
if state.nvim.is_none() {
|
if state.nvim.is_none() {
|
||||||
@ -84,7 +84,7 @@ impl Tabline {
|
|||||||
pub fn update_tabs(&self,
|
pub fn update_tabs(&self,
|
||||||
nvim: &Rc<RefCell<nvim::NeovimClient>>,
|
nvim: &Rc<RefCell<nvim::NeovimClient>>,
|
||||||
selected: &Tabpage,
|
selected: &Tabpage,
|
||||||
tabs: &Vec<(Tabpage, Option<String>)>) {
|
tabs: &[(Tabpage, Option<String>)]) {
|
||||||
if tabs.len() <= 1 {
|
if tabs.len() <= 1 {
|
||||||
self.tabs.hide();
|
self.tabs.hide();
|
||||||
return;
|
return;
|
||||||
@ -113,7 +113,7 @@ impl Tabline {
|
|||||||
for (idx, tab) in tabs.iter().enumerate() {
|
for (idx, tab) in tabs.iter().enumerate() {
|
||||||
let tab_child = self.tabs.get_nth_page(Some(idx as u32));
|
let tab_child = self.tabs.get_nth_page(Some(idx as u32));
|
||||||
self.tabs
|
self.tabs
|
||||||
.set_tab_label_text(&tab_child.unwrap(), &tab.1.as_ref().unwrap_or(&"??".to_owned()));
|
.set_tab_label_text(&tab_child.unwrap(), tab.1.as_ref().unwrap_or(&"??".to_owned()));
|
||||||
|
|
||||||
if *selected == tab.0 {
|
if *selected == tab.0 {
|
||||||
self.tabs.set_current_page(Some(idx as u32));
|
self.tabs.set_current_page(Some(idx as u32));
|
||||||
|
@ -172,8 +172,8 @@ impl UiModel {
|
|||||||
let mut cell = &mut self.model[self.cur_row][self.cur_col];
|
let mut cell = &mut self.model[self.cur_row][self.cur_col];
|
||||||
|
|
||||||
cell.ch = text.chars().last().unwrap_or(' ');
|
cell.ch = text.chars().last().unwrap_or(' ');
|
||||||
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(|| Attrs::new());
|
cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(Attrs::new);
|
||||||
cell.attrs.double_width = text.len() == 0;
|
cell.attrs.double_width = text.is_empty();
|
||||||
self.cur_col += 1;
|
self.cur_col += 1;
|
||||||
if self.cur_col >= self.columns {
|
if self.cur_col >= self.columns {
|
||||||
self.cur_col -= 1;
|
self.cur_col -= 1;
|
||||||
@ -274,7 +274,7 @@ impl ModelRectVec {
|
|||||||
|
|
||||||
pub fn join(&mut self, other: &ModelRect) {
|
pub fn join(&mut self, other: &ModelRect) {
|
||||||
match self.find_neighbor(other) {
|
match self.find_neighbor(other) {
|
||||||
Some(i) => self.list.get_mut(i).unwrap().join(other),
|
Some(i) => self.list[i].join(other),
|
||||||
None => self.list.push(other.clone()),
|
None => self.list.push(other.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,17 +379,7 @@ impl ModelRect {
|
|||||||
x2: f64,
|
x2: f64,
|
||||||
y2: f64)
|
y2: f64)
|
||||||
-> ModelRect {
|
-> ModelRect {
|
||||||
let x1 = if x1 > 0.0 {
|
|
||||||
x1 // - 1.0
|
|
||||||
} else {
|
|
||||||
x1
|
|
||||||
};
|
|
||||||
let x2 = if x2 > 0.0 { x2 - 1.0 } else { x2 };
|
let x2 = if x2 > 0.0 { x2 - 1.0 } else { x2 };
|
||||||
let y1 = if y1 > 0.0 {
|
|
||||||
y1 // - 1.0
|
|
||||||
} else {
|
|
||||||
y1
|
|
||||||
};
|
|
||||||
let y2 = if y2 > 0.0 { y2 - 1.0 } else { y2 };
|
let y2 = if y2 > 0.0 { y2 - 1.0 } else { y2 };
|
||||||
let left = (x1 / char_width) as usize;
|
let left = (x1 / char_width) as usize;
|
||||||
let right = (x2 / char_width) as usize;
|
let right = (x2 / char_width) as usize;
|
||||||
@ -435,11 +425,11 @@ impl<'a> Iterator for ClipRowIterator<'a> {
|
|||||||
|
|
||||||
pub struct ClipLine<'a> {
|
pub struct ClipLine<'a> {
|
||||||
rect: &'a ModelRect,
|
rect: &'a ModelRect,
|
||||||
line: &'a Vec<Cell>,
|
line: &'a [Cell],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClipLine<'a> {
|
impl<'a> ClipLine<'a> {
|
||||||
pub fn new(model: &'a Vec<Cell>, rect: &'a ModelRect) -> ClipLine<'a> {
|
pub fn new(model: &'a [Cell], rect: &'a ModelRect) -> ClipLine<'a> {
|
||||||
ClipLine {
|
ClipLine {
|
||||||
line: model,
|
line: model,
|
||||||
rect: rect,
|
rect: rect,
|
||||||
@ -469,7 +459,7 @@ pub struct ClipColIterator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClipColIterator<'a> {
|
impl<'a> ClipColIterator<'a> {
|
||||||
pub fn new(model: &'a Vec<Cell>, rect: &'a ModelRect) -> ClipColIterator<'a> {
|
pub fn new(model: &'a [Cell], rect: &'a ModelRect) -> ClipColIterator<'a> {
|
||||||
ClipColIterator {
|
ClipColIterator {
|
||||||
rect: rect,
|
rect: rect,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
|
@ -11,7 +11,7 @@ impl ValueMapExt for Vec<(Value, Value)> {
|
|||||||
.map(|p| {
|
.map(|p| {
|
||||||
p.0
|
p.0
|
||||||
.as_str()
|
.as_str()
|
||||||
.ok_or("Can't convert map key to string".to_owned())
|
.ok_or_else(|| "Can't convert map key to string".to_owned())
|
||||||
.map(|key| (key, p.1.clone()))
|
.map(|key| (key, p.1.clone()))
|
||||||
})
|
})
|
||||||
.collect::<Result<HashMap<&str, Value>, String>>()
|
.collect::<Result<HashMap<&str, Value>, String>>()
|
||||||
|
Loading…
Reference in New Issue
Block a user