2018-03-26 08:24:36 +00:00
|
|
|
#![windows_subsystem = "windows"]
|
|
|
|
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate cairo;
|
|
|
|
extern crate env_logger;
|
2016-03-31 13:52:22 +00:00
|
|
|
extern crate gdk;
|
2016-05-05 07:23:04 +00:00
|
|
|
extern crate gdk_sys;
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate gio;
|
2017-08-18 15:35:33 +00:00
|
|
|
#[macro_use]
|
2016-03-28 14:14:10 +00:00
|
|
|
extern crate glib;
|
2017-08-18 15:35:33 +00:00
|
|
|
extern crate glib_sys as glib_ffi;
|
2017-08-25 15:32:30 +00:00
|
|
|
extern crate gobject_sys as gobject_ffi;
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate gtk;
|
|
|
|
extern crate gtk_sys;
|
|
|
|
extern crate htmlescape;
|
|
|
|
#[macro_use]
|
2018-03-19 18:00:40 +00:00
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate log;
|
|
|
|
extern crate neovim_lib;
|
2017-03-05 22:28:07 +00:00
|
|
|
extern crate pango;
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate pango_cairo_sys;
|
2017-08-18 15:35:33 +00:00
|
|
|
extern crate pango_sys;
|
2017-03-05 22:28:07 +00:00
|
|
|
extern crate pangocairo;
|
2018-03-19 18:00:40 +00:00
|
|
|
extern crate percent_encoding;
|
2016-04-02 20:00:18 +00:00
|
|
|
extern crate phf;
|
2017-11-17 15:40:09 +00:00
|
|
|
extern crate rmpv;
|
2018-03-19 18:00:40 +00:00
|
|
|
extern crate regex;
|
2018-03-25 13:29:59 +00:00
|
|
|
extern crate unicode_width;
|
2017-05-13 14:31:19 +00:00
|
|
|
|
2017-10-19 14:04:58 +00:00
|
|
|
extern crate serde;
|
2017-05-13 14:31:19 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2017-10-30 15:25:23 +00:00
|
|
|
extern crate serde_json;
|
2018-02-16 09:57:26 +00:00
|
|
|
extern crate toml;
|
2016-03-16 14:39:53 +00:00
|
|
|
|
2017-08-18 15:35:33 +00:00
|
|
|
mod sys;
|
|
|
|
|
2017-10-26 14:56:53 +00:00
|
|
|
mod nvim_config;
|
2017-10-19 14:04:58 +00:00
|
|
|
mod dirs;
|
2017-11-14 15:38:24 +00:00
|
|
|
mod theme;
|
2017-08-23 09:45:56 +00:00
|
|
|
mod color;
|
2017-07-08 11:02:56 +00:00
|
|
|
mod value;
|
2017-07-08 20:45:55 +00:00
|
|
|
mod mode;
|
2016-03-19 08:47:23 +00:00
|
|
|
mod ui_model;
|
2017-03-23 15:04:24 +00:00
|
|
|
#[macro_use]
|
2016-03-16 15:25:25 +00:00
|
|
|
mod ui;
|
2017-10-29 19:16:55 +00:00
|
|
|
mod plug_manager;
|
2017-03-31 10:22:05 +00:00
|
|
|
mod nvim;
|
2017-08-18 15:35:33 +00:00
|
|
|
mod render;
|
2017-03-23 15:04:24 +00:00
|
|
|
mod shell;
|
2016-04-04 10:14:57 +00:00
|
|
|
mod input;
|
2017-03-13 15:03:32 +00:00
|
|
|
mod settings;
|
2017-03-22 15:37:18 +00:00
|
|
|
mod cursor;
|
2017-11-18 12:56:37 +00:00
|
|
|
mod cmd_line;
|
2017-04-01 10:00:14 +00:00
|
|
|
mod shell_dlg;
|
2017-04-19 08:40:53 +00:00
|
|
|
mod popup_menu;
|
2017-05-13 14:31:19 +00:00
|
|
|
mod project;
|
2017-05-27 16:50:25 +00:00
|
|
|
mod tabline;
|
2017-07-06 09:41:35 +00:00
|
|
|
mod error;
|
2018-03-11 12:49:13 +00:00
|
|
|
mod file_browser;
|
2018-02-25 14:54:15 +00:00
|
|
|
mod subscriptions;
|
2018-03-19 18:00:40 +00:00
|
|
|
mod misc;
|
2016-03-16 14:39:53 +00:00
|
|
|
|
2017-03-06 13:58:10 +00:00
|
|
|
use std::env;
|
2017-12-10 09:46:36 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
use std::str::FromStr;
|
2017-12-15 01:36:16 +00:00
|
|
|
use gio::prelude::*;
|
2016-05-05 14:27:45 +00:00
|
|
|
|
2017-04-12 10:12:05 +00:00
|
|
|
use ui::Ui;
|
2017-03-16 10:18:13 +00:00
|
|
|
|
2017-06-04 10:14:09 +00:00
|
|
|
use shell::ShellOptions;
|
|
|
|
|
2017-12-10 09:46:36 +00:00
|
|
|
const BIN_PATH_ARG: &str = "--nvim-bin-path";
|
|
|
|
const TIMEOUT_ARG: &str = "--timeout";
|
2018-02-16 09:57:26 +00:00
|
|
|
const DISABLE_WIN_STATE_RESTORE: &str = "--disable-win-restore";
|
2017-03-07 15:20:48 +00:00
|
|
|
|
2016-03-16 15:25:25 +00:00
|
|
|
fn main() {
|
2018-02-17 10:07:06 +00:00
|
|
|
env_logger::init();
|
2017-04-03 11:17:06 +00:00
|
|
|
|
2017-12-31 09:47:50 +00:00
|
|
|
let app_flags = gio::ApplicationFlags::HANDLES_OPEN | gio::ApplicationFlags::NON_UNIQUE;
|
2017-06-08 14:17:08 +00:00
|
|
|
|
2018-02-10 09:16:28 +00:00
|
|
|
glib::set_program_name(Some("NeovimGtk"));
|
|
|
|
|
2017-05-13 21:30:34 +00:00
|
|
|
let app = if cfg!(debug_assertions) {
|
2017-12-10 09:46:36 +00:00
|
|
|
gtk::Application::new(Some("org.daa.NeovimGtkDebug"), app_flags)
|
|
|
|
} else {
|
|
|
|
gtk::Application::new(Some("org.daa.NeovimGtk"), app_flags)
|
|
|
|
}.expect("Failed to initialize GTK application");
|
2017-03-06 13:58:10 +00:00
|
|
|
|
|
|
|
app.connect_activate(activate);
|
2017-12-15 01:36:16 +00:00
|
|
|
app.connect_open(open);
|
|
|
|
|
|
|
|
let new_window_action = gio::SimpleAction::new("new-window", None);
|
|
|
|
let app_ref = app.clone();
|
|
|
|
new_window_action.connect_activate(move |_, _| activate(&app_ref));
|
|
|
|
app.add_action(&new_window_action);
|
2017-03-06 13:58:10 +00:00
|
|
|
|
2017-10-30 19:56:49 +00:00
|
|
|
gtk::Window::set_default_icon_name("org.daa.NeovimGtk");
|
|
|
|
|
2017-03-06 13:58:10 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2017-12-31 09:47:50 +00:00
|
|
|
let argv: Vec<String> = args.iter()
|
2017-04-12 10:12:05 +00:00
|
|
|
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
2017-12-10 09:46:36 +00:00
|
|
|
.filter(|a| !a.starts_with(TIMEOUT_ARG))
|
2018-02-16 09:57:26 +00:00
|
|
|
.filter(|a| !a.starts_with(DISABLE_WIN_STATE_RESTORE))
|
2017-12-31 09:47:50 +00:00
|
|
|
.cloned()
|
2017-04-12 10:12:05 +00:00
|
|
|
.collect();
|
2017-07-11 09:33:55 +00:00
|
|
|
app.run(&argv);
|
2017-03-06 13:58:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 14:17:08 +00:00
|
|
|
fn open(app: >k::Application, files: &[gio::File], _: &str) {
|
2018-03-20 17:43:31 +00:00
|
|
|
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()));
|
2017-06-08 14:17:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 13:58:10 +00:00
|
|
|
fn activate(app: >k::Application) {
|
2017-12-10 09:46:36 +00:00
|
|
|
let mut ui = Ui::new(ShellOptions::new(
|
|
|
|
nvim_bin_path(std::env::args()),
|
2018-03-20 17:43:31 +00:00
|
|
|
Vec::new(),
|
2017-12-10 09:46:36 +00:00
|
|
|
nvim_timeout(std::env::args()),
|
|
|
|
));
|
2017-04-12 10:12:05 +00:00
|
|
|
|
2018-02-16 09:57:26 +00:00
|
|
|
ui.init(app, !nvim_disable_win_state(std::env::args()));
|
2016-03-16 14:39:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 09:46:36 +00:00
|
|
|
fn nvim_bin_path<I>(mut args: I) -> Option<String>
|
|
|
|
where
|
|
|
|
I: Iterator<Item = String>,
|
2017-03-14 09:37:06 +00:00
|
|
|
{
|
2018-02-16 09:57:26 +00:00
|
|
|
args.find(|a| a.starts_with(BIN_PATH_ARG))
|
|
|
|
.and_then(|p| p.split('=').nth(1).map(str::to_owned))
|
2017-12-10 09:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn nvim_timeout<I>(mut args: I) -> Option<Duration>
|
|
|
|
where
|
|
|
|
I: Iterator<Item = String>,
|
2017-03-14 09:37:06 +00:00
|
|
|
{
|
2017-12-10 09:46:36 +00:00
|
|
|
args.find(|a| a.starts_with(TIMEOUT_ARG))
|
|
|
|
.and_then(|p| p.split('=').nth(1).map(str::to_owned))
|
|
|
|
.and_then(|timeout| match u64::from_str(&timeout) {
|
|
|
|
Ok(timeout) => Some(timeout),
|
|
|
|
Err(err) => {
|
|
|
|
error!("Can't convert timeout argument to integer: {}", err);
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.map(|timeout| Duration::from_secs(timeout))
|
2017-03-07 15:20:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 09:57:26 +00:00
|
|
|
fn nvim_disable_win_state<I>(mut args: I) -> bool
|
|
|
|
where
|
|
|
|
I: Iterator<Item = String>,
|
|
|
|
{
|
|
|
|
args.find(|a| a.starts_with(DISABLE_WIN_STATE_RESTORE))
|
|
|
|
.map(|_| true)
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:37:06 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bin_path_arg() {
|
2017-12-10 09:46:36 +00:00
|
|
|
assert_eq!(
|
|
|
|
Some("/test_path".to_string()),
|
|
|
|
nvim_bin_path(
|
|
|
|
vec!["neovim-gtk", "--nvim-bin-path=/test_path"]
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string()),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_timeout_arg() {
|
|
|
|
assert_eq!(
|
|
|
|
Some(Duration::from_secs(100)),
|
2018-02-16 09:57:26 +00:00
|
|
|
nvim_timeout(
|
|
|
|
vec!["neovim-gtk", "--timeout=100"]
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string(),)
|
|
|
|
)
|
2017-12-10 09:46:36 +00:00
|
|
|
);
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|
|
|
|
}
|