Open multiple files in one instance

This commit is contained in:
Christopher Lübbemeier 2018-03-20 18:43:31 +01:00
parent 15a285b032
commit bb9adcc1d5
3 changed files with 33 additions and 27 deletions

View File

@ -63,7 +63,6 @@ use gio::prelude::*;
use ui::Ui;
use misc::escape_filename;
use shell::ShellOptions;
const BIN_PATH_ARG: &str = "--nvim-bin-path";
@ -104,23 +103,23 @@ fn main() {
}
fn open(app: &gtk::Application, files: &[gio::File], _: &str) {
for f in files {
let mut ui = Ui::new(ShellOptions::new(
nvim_bin_path(std::env::args()),
f.get_path().and_then(|p| {
p.to_str().map(|path| escape_filename(path).to_string())
}),
nvim_timeout(std::env::args()),
));
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(
nvim_bin_path(std::env::args()),
files_list,
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: &gtk::Application) {
let mut ui = Ui::new(ShellOptions::new(
nvim_bin_path(std::env::args()),
None,
Vec::new(),
nvim_timeout(std::env::args()),
));

View File

@ -20,8 +20,9 @@ use std::result;
use std::sync::Arc;
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 shell;
use nvim_config::NvimConfig;
@ -138,7 +139,7 @@ pub fn start(
pub fn post_start_init(
nvim: NeovimClientAsync,
open_path: Option<&String>,
open_paths: Vec<String>,
cols: u64,
rows: u64,
) -> result::Result<(), NvimInitError> {
@ -154,11 +155,18 @@ pub fn post_start_init(
.command("runtime! ginit.vim")
.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()
.unwrap()
.command(&format!("e {}", path))
.map_err(NvimInitError::new_post_init)?;
.command_async(&command)
.cb(|r| r.report_err())
.call();
}
Ok(())

View File

@ -382,19 +382,19 @@ impl UiState {
#[derive(Clone)]
pub struct ShellOptions {
nvim_bin_path: Option<String>,
open_path: Option<String>,
open_paths: Vec<String>,
timeout: Option<Duration>,
}
impl ShellOptions {
pub fn new(
nvim_bin_path: Option<String>,
open_path: Option<String>,
open_paths: Vec<String>,
timeout: Option<Duration>,
) -> Self {
ShellOptions {
nvim_bin_path,
open_path,
open_paths,
timeout,
}
}
@ -580,12 +580,13 @@ impl Shell {
.drawing_area
.connect_drag_data_received(move |_, _, _, _, s, _, _| {
let uris = s.get_uris();
let command = uris.iter()
.filter_map(|uri| decode_uri(uri))
.fold(":ar".to_owned(), |command, filename| {
let command = uris.iter().filter_map(|uri| decode_uri(uri)).fold(
":ar".to_owned(),
|command, filename| {
let filename = escape_filename(&filename);
command + " " + &filename
});
},
);
let state = ref_state.borrow_mut();
let mut nvim = state.nvim().unwrap();
nvim.command_async(&command).cb(|r| r.report_err()).call()
@ -884,9 +885,7 @@ fn init_nvim_async(
});
// attach ui
if let Err(err) =
nvim::post_start_init(nvim, options.open_path.as_ref(), cols as u64, rows as u64)
{
if let Err(err) = nvim::post_start_init(nvim, options.open_paths, cols as u64, rows as u64) {
show_nvim_init_error(&err, state_arc.clone());
} else {
set_nvim_initialized(state_arc);