Use open signal for files
This commit is contained in:
parent
d0f31fb979
commit
c2bdaac4ba
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -55,6 +55,11 @@ name = "bitflags"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.0.0"
|
||||
@ -161,9 +166,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gio"
|
||||
version = "0.1.3"
|
||||
source = "git+https://github.com/gtk-rs/gio#7f54acd011ae831a7827c02170d9b90208128a26"
|
||||
source = "git+https://github.com/gtk-rs/gio#52757aced2f5e7a24a66fadae1a261cf8a3dd209"
|
||||
dependencies = [
|
||||
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gio-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
|
||||
"glib 0.1.3 (git+https://github.com/gtk-rs/glib)",
|
||||
"glib-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
|
||||
@ -563,6 +568,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum atk-sys 0.3.4 (git+https://github.com/gtk-rs/sys)" = "<none>"
|
||||
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
|
||||
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
|
||||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
|
||||
"checksum c_vec 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6237ac5a4b1e81c213c24c6437964c61e646df910a914b4ab1487b46df20bd13"
|
||||
"checksum cairo-rs 0.1.3 (git+https://github.com/gtk-rs/cairo)" = "<none>"
|
||||
|
64
src/main.rs
64
src/main.rs
@ -32,10 +32,10 @@ mod popup_menu;
|
||||
mod project;
|
||||
mod tabline;
|
||||
|
||||
use gtk::prelude::*;
|
||||
|
||||
use std::env;
|
||||
use gio::ApplicationExt;
|
||||
use gtk::prelude::*;
|
||||
use gio::{ApplicationExt, FileExt};
|
||||
|
||||
use ui::Ui;
|
||||
|
||||
@ -44,33 +44,46 @@ const BIN_PATH_ARG: &'static str = "--nvim-bin-path";
|
||||
fn main() {
|
||||
env_logger::init().expect("Can't initialize env_logger");
|
||||
|
||||
let app_flags = gio::APPLICATION_HANDLES_OPEN;
|
||||
|
||||
let app = if cfg!(debug_assertions) {
|
||||
gtk::Application::new(Some("org.daa.NeovimGtkDebug"),
|
||||
gio::ApplicationFlags::empty())
|
||||
app_flags)
|
||||
} else {
|
||||
gtk::Application::new(Some("org.daa.NeovimGtk"), gio::ApplicationFlags::empty())
|
||||
gtk::Application::new(Some("org.daa.NeovimGtk"), app_flags)
|
||||
}
|
||||
.expect("Failed to initialize GTK application");
|
||||
|
||||
app.connect_activate(activate);
|
||||
{
|
||||
use gio::ApplicationExtManual;
|
||||
app.connect_open(open);
|
||||
}
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut argv: Vec<&str> = args.iter()
|
||||
let argv: Vec<&str> = args.iter()
|
||||
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
||||
.map(String::as_str)
|
||||
.collect();
|
||||
if open_arg().is_some() {
|
||||
argv.pop();
|
||||
}
|
||||
app.run(argv.len() as i32, &argv);
|
||||
}
|
||||
|
||||
fn open(app: >k::Application, files: &[gio::File], _: &str) {
|
||||
for f in files {
|
||||
let mut ui = Ui::new();
|
||||
|
||||
ui.init(app,
|
||||
nvim_bin_path(std::env::args()).as_ref(),
|
||||
f.get_path().as_ref().map(|p| p.to_str()).unwrap_or(None));
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(app: >k::Application) {
|
||||
let mut ui = Ui::new();
|
||||
|
||||
ui.init(app,
|
||||
nvim_bin_path(std::env::args()).as_ref(),
|
||||
open_arg().as_ref());
|
||||
None);
|
||||
}
|
||||
|
||||
fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
@ -82,23 +95,6 @@ fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
.unwrap_or(None)
|
||||
}
|
||||
|
||||
fn open_arg() -> Option<String> {
|
||||
open_arg_impl(std::env::args())
|
||||
}
|
||||
|
||||
fn open_arg_impl<I>(args: I) -> Option<String>
|
||||
where I: Iterator<Item = String>
|
||||
{
|
||||
args.skip(1)
|
||||
.last()
|
||||
.map(|a| if !a.starts_with("-") {
|
||||
Some(a.to_owned())
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.unwrap_or(None)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -110,20 +106,4 @@ mod tests {
|
||||
.iter()
|
||||
.map(|s| s.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_open_arg() {
|
||||
assert_eq!(Some("some_file.txt".to_string()),
|
||||
open_arg_impl(vec!["neovim-gtk",
|
||||
"--nvim-bin-path=/test_path",
|
||||
"some_file.txt"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_open_arg() {
|
||||
assert_eq!(None,
|
||||
open_arg_impl(vec!["neovim-gtk"].iter().map(|s| s.to_string())));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user