Open multiple files in one instance
This commit is contained in:
		
							parent
							
								
									15a285b032
								
							
						
					
					
						commit
						bb9adcc1d5
					
				
							
								
								
									
										13
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -63,7 +63,6 @@ use gio::prelude::*; | |||||||
| 
 | 
 | ||||||
| use ui::Ui; | use ui::Ui; | ||||||
| 
 | 
 | ||||||
| use misc::escape_filename; |  | ||||||
| use shell::ShellOptions; | use shell::ShellOptions; | ||||||
| 
 | 
 | ||||||
| const BIN_PATH_ARG: &str = "--nvim-bin-path"; | const BIN_PATH_ARG: &str = "--nvim-bin-path"; | ||||||
| @ -104,23 +103,23 @@ fn main() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn open(app: >k::Application, files: &[gio::File], _: &str) { | fn open(app: >k::Application, files: &[gio::File], _: &str) { | ||||||
|     for f in files { |     let files_list: Vec<String> = files | ||||||
|  |         .into_iter() | ||||||
|  |         .filter_map(|f| f.get_path()?.to_str().map(str::to_owned)) | ||||||
|  |         .collect(); | ||||||
|     let mut ui = Ui::new(ShellOptions::new( |     let mut ui = Ui::new(ShellOptions::new( | ||||||
|         nvim_bin_path(std::env::args()), |         nvim_bin_path(std::env::args()), | ||||||
|             f.get_path().and_then(|p| { |         files_list, | ||||||
|                 p.to_str().map(|path| escape_filename(path).to_string()) |  | ||||||
|             }), |  | ||||||
|         nvim_timeout(std::env::args()), |         nvim_timeout(std::env::args()), | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|     ui.init(app, !nvim_disable_win_state(std::env::args())); |     ui.init(app, !nvim_disable_win_state(std::env::args())); | ||||||
| } | } | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| fn activate(app: >k::Application) { | fn activate(app: >k::Application) { | ||||||
|     let mut ui = Ui::new(ShellOptions::new( |     let mut ui = Ui::new(ShellOptions::new( | ||||||
|         nvim_bin_path(std::env::args()), |         nvim_bin_path(std::env::args()), | ||||||
|         None, |         Vec::new(), | ||||||
|         nvim_timeout(std::env::args()), |         nvim_timeout(std::env::args()), | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -20,8 +20,9 @@ use std::result; | |||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
| use std::time::Duration; | use std::time::Duration; | ||||||
| 
 | 
 | ||||||
| use neovim_lib::{Neovim, NeovimApi, Session, UiAttachOptions}; | use neovim_lib::{Neovim, NeovimApi, NeovimApiAsync, Session, UiAttachOptions}; | ||||||
| 
 | 
 | ||||||
|  | use misc::escape_filename; | ||||||
| use ui::UiMutex; | use ui::UiMutex; | ||||||
| use shell; | use shell; | ||||||
| use nvim_config::NvimConfig; | use nvim_config::NvimConfig; | ||||||
| @ -138,7 +139,7 @@ pub fn start( | |||||||
| 
 | 
 | ||||||
| pub fn post_start_init( | pub fn post_start_init( | ||||||
|     nvim: NeovimClientAsync, |     nvim: NeovimClientAsync, | ||||||
|     open_path: Option<&String>, |     open_paths: Vec<String>, | ||||||
|     cols: u64, |     cols: u64, | ||||||
|     rows: u64, |     rows: u64, | ||||||
| ) -> result::Result<(), NvimInitError> { | ) -> result::Result<(), NvimInitError> { | ||||||
| @ -154,11 +155,18 @@ pub fn post_start_init( | |||||||
|         .command("runtime! ginit.vim") |         .command("runtime! ginit.vim") | ||||||
|         .map_err(NvimInitError::new_post_init)?; |         .map_err(NvimInitError::new_post_init)?; | ||||||
| 
 | 
 | ||||||
|     if let Some(path) = open_path { |     if !open_paths.is_empty() { | ||||||
|  |         let command = open_paths | ||||||
|  |             .iter() | ||||||
|  |             .fold(":ar".to_owned(), |command, filename| { | ||||||
|  |                 let filename = escape_filename(filename); | ||||||
|  |                 command + " " + &filename | ||||||
|  |             }); | ||||||
|         nvim.borrow() |         nvim.borrow() | ||||||
|             .unwrap() |             .unwrap() | ||||||
|             .command(&format!("e {}", path)) |             .command_async(&command) | ||||||
|             .map_err(NvimInitError::new_post_init)?; |             .cb(|r| r.report_err()) | ||||||
|  |             .call(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								src/shell.rs
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/shell.rs
									
									
									
									
									
								
							| @ -382,19 +382,19 @@ impl UiState { | |||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
| pub struct ShellOptions { | pub struct ShellOptions { | ||||||
|     nvim_bin_path: Option<String>, |     nvim_bin_path: Option<String>, | ||||||
|     open_path: Option<String>, |     open_paths: Vec<String>, | ||||||
|     timeout: Option<Duration>, |     timeout: Option<Duration>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ShellOptions { | impl ShellOptions { | ||||||
|     pub fn new( |     pub fn new( | ||||||
|         nvim_bin_path: Option<String>, |         nvim_bin_path: Option<String>, | ||||||
|         open_path: Option<String>, |         open_paths: Vec<String>, | ||||||
|         timeout: Option<Duration>, |         timeout: Option<Duration>, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         ShellOptions { |         ShellOptions { | ||||||
|             nvim_bin_path, |             nvim_bin_path, | ||||||
|             open_path, |             open_paths, | ||||||
|             timeout, |             timeout, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -580,12 +580,13 @@ impl Shell { | |||||||
|             .drawing_area |             .drawing_area | ||||||
|             .connect_drag_data_received(move |_, _, _, _, s, _, _| { |             .connect_drag_data_received(move |_, _, _, _, s, _, _| { | ||||||
|                 let uris = s.get_uris(); |                 let uris = s.get_uris(); | ||||||
|                 let command = uris.iter() |                 let command = uris.iter().filter_map(|uri| decode_uri(uri)).fold( | ||||||
|                     .filter_map(|uri| decode_uri(uri)) |                     ":ar".to_owned(), | ||||||
|                     .fold(":ar".to_owned(), |command, filename| { |                     |command, filename| { | ||||||
|                         let filename = escape_filename(&filename); |                         let filename = escape_filename(&filename); | ||||||
|                         command + " " + &filename |                         command + " " + &filename | ||||||
|                     }); |                     }, | ||||||
|  |                 ); | ||||||
|                 let state = ref_state.borrow_mut(); |                 let state = ref_state.borrow_mut(); | ||||||
|                 let mut nvim = state.nvim().unwrap(); |                 let mut nvim = state.nvim().unwrap(); | ||||||
|                 nvim.command_async(&command).cb(|r| r.report_err()).call() |                 nvim.command_async(&command).cb(|r| r.report_err()).call() | ||||||
| @ -884,9 +885,7 @@ fn init_nvim_async( | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     // attach ui
 |     // attach ui
 | ||||||
|     if let Err(err) = |     if let Err(err) = nvim::post_start_init(nvim, options.open_paths, cols as u64, rows as u64) { | ||||||
|         nvim::post_start_init(nvim, options.open_path.as_ref(), cols as u64, rows as u64) |  | ||||||
|     { |  | ||||||
|         show_nvim_init_error(&err, state_arc.clone()); |         show_nvim_init_error(&err, state_arc.clone()); | ||||||
|     } else { |     } else { | ||||||
|         set_nvim_initialized(state_arc); |         set_nvim_initialized(state_arc); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Christopher Lübbemeier
						Christopher Lübbemeier