add document-activate handler, this is fired when user switches over to a document

This commit is contained in:
Adrian Malacoda 2019-04-26 23:27:35 -05:00
parent d550196ff7
commit b948f685e4

View File

@ -3,6 +3,7 @@ use shenlong_sys::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::ptr; use std::ptr;
use std::mem::transmute; use std::mem::transmute;
use scouter::Scouter;
extern "C" fn shenlong_init(plugin: *mut GeanyPlugin, pdata: gpointer) -> gboolean { extern "C" fn shenlong_init(plugin: *mut GeanyPlugin, pdata: gpointer) -> gboolean {
println!("shenlong init"); println!("shenlong init");
@ -16,6 +17,14 @@ extern "C" fn shenlong_init(plugin: *mut GeanyPlugin, pdata: gpointer) -> gboole
Some(transmute(shenlong_document_open as usize)), Some(transmute(shenlong_document_open as usize)),
ptr::null_mut() ptr::null_mut()
); );
plugin_signal_connect(
plugin,
ptr::null_mut(),
c_str!("document-activate").to_owned().as_ptr(),
0,
Some(transmute(shenlong_document_activate as usize)),
ptr::null_mut()
);
plugin_signal_connect( plugin_signal_connect(
plugin, plugin,
ptr::null_mut(), ptr::null_mut(),
@ -41,8 +50,20 @@ extern "C" fn shenlong_cleanup(plugin: *mut GeanyPlugin, pdata: gpointer) {
} }
extern "C" fn shenlong_document_open(obj: *mut GObject, doc: *mut GeanyDocument, user_data: gpointer) { extern "C" fn shenlong_document_open(obj: *mut GObject, doc: *mut GeanyDocument, user_data: gpointer) {
unsafe { let document_path = unsafe { CStr::from_ptr((*doc).real_path).to_str().expect("failed to get document path") };
println!("shenlong document open: {:?}", CStr::from_ptr((*doc).real_path).to_str()); println!("shenlong document open: {:?}", document_path);
let mut scouter = Scouter::new(document_path);
if let Some(project) = scouter.next() {
println!("-- shenlong project open: {:?}", project);
}
}
extern "C" fn shenlong_document_activate(obj: *mut GObject, doc: *mut GeanyDocument, user_data: gpointer) {
let document_path = unsafe { CStr::from_ptr((*doc).real_path).to_str().expect("failed to get document path") };
println!("shenlong document activate: {:?}", document_path);
let mut scouter = Scouter::new(document_path);
if let Some(project) = scouter.next() {
println!("-- shenlong project open: {:?}", project);
} }
} }