Compare commits
3 Commits
f94feb50f9
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
b948f685e4 | ||
|
d550196ff7 | ||
|
7398c1fd56 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1,3 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "0.6.9"
|
version = "0.6.9"
|
||||||
|
2
install_builddeps
Executable file
2
install_builddeps
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
sudo apt-get build-dep clang geany geany-plugins
|
117
src/lib.rs
117
src/lib.rs
@@ -1,8 +1,47 @@
|
|||||||
use c_str_macro::c_str;
|
use c_str_macro::c_str;
|
||||||
use shenlong_sys::*;
|
use shenlong_sys::*;
|
||||||
|
use std::ffi::CStr;
|
||||||
|
use std::ptr;
|
||||||
|
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");
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
plugin_signal_connect(
|
||||||
|
plugin,
|
||||||
|
ptr::null_mut(),
|
||||||
|
c_str!("document-open").to_owned().as_ptr(),
|
||||||
|
0,
|
||||||
|
Some(transmute(shenlong_document_open as usize)),
|
||||||
|
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,
|
||||||
|
ptr::null_mut(),
|
||||||
|
c_str!("document-new").to_owned().as_ptr(),
|
||||||
|
0,
|
||||||
|
Some(transmute(shenlong_document_new as usize)),
|
||||||
|
ptr::null_mut()
|
||||||
|
);
|
||||||
|
plugin_signal_connect(
|
||||||
|
plugin,
|
||||||
|
ptr::null_mut(),
|
||||||
|
c_str!("document-save").to_owned().as_ptr(),
|
||||||
|
0,
|
||||||
|
Some(transmute(shenlong_document_save as usize)),
|
||||||
|
ptr::null_mut()
|
||||||
|
);
|
||||||
|
}
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,6 +49,38 @@ extern "C" fn shenlong_cleanup(plugin: *mut GeanyPlugin, pdata: gpointer) {
|
|||||||
println!("shenlong cleanup");
|
println!("shenlong cleanup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" fn shenlong_document_open(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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn shenlong_document_new(obj: *mut GObject, doc: *mut GeanyDocument, user_data: gpointer) {
|
||||||
|
println!("shenlong document new");
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn shenlong_document_save(obj: *mut GObject, doc: *mut GeanyDocument, user_data: gpointer) {
|
||||||
|
unsafe {
|
||||||
|
println!("shenlong document save: {:?}", CStr::from_ptr((*doc).real_path).to_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn shenlong_empty_callback() {
|
||||||
|
println!("shenlong empty callback");
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn geany_load_module(plugin: *mut GeanyPlugin) {
|
pub extern "C" fn geany_load_module(plugin: *mut GeanyPlugin) {
|
||||||
println!("loading shenlong module");
|
println!("loading shenlong module");
|
||||||
@@ -24,6 +95,52 @@ pub extern "C" fn geany_load_module(plugin: *mut GeanyPlugin) {
|
|||||||
plugin_funcs.init = Some(shenlong_init);
|
plugin_funcs.init = Some(shenlong_init);
|
||||||
plugin_funcs.cleanup = Some(shenlong_cleanup);
|
plugin_funcs.cleanup = Some(shenlong_cleanup);
|
||||||
|
|
||||||
|
/*let mut plugin_callbacks: [PluginCallback; 6] = [
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: c_str!("document-open").to_owned().into_raw(),
|
||||||
|
callback: Some(transmute(shenlong_document_open as usize)),
|
||||||
|
//callback: Some(shenlong_empty_callback),
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
},
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: c_str!("document-new").to_owned().into_raw(),
|
||||||
|
//callback: Some(transmute(shenlong_document_new as usize)),
|
||||||
|
callback: Some(shenlong_empty_callback),
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
},
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: c_str!("document-close").to_owned().into_raw(),
|
||||||
|
//callback: Some(transmute(shenlong_document_new as usize)),
|
||||||
|
callback: Some(shenlong_empty_callback),
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
},
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: c_str!("document-save").to_owned().into_raw(),
|
||||||
|
//callback: Some(transmute(shenlong_document_save as usize)),
|
||||||
|
callback: Some(shenlong_empty_callback),
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
},
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: c_str!("document-reload").to_owned().into_raw(),
|
||||||
|
//callback: Some(transmute(shenlong_document_new as usize)),
|
||||||
|
callback: Some(shenlong_empty_callback),
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
},
|
||||||
|
PluginCallback {
|
||||||
|
signal_name: ptr::null(),
|
||||||
|
callback: None,
|
||||||
|
after: 0,
|
||||||
|
user_data: ptr::null_mut()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
plugin_funcs.callbacks = plugin_callbacks.as_mut_ptr();*/
|
||||||
|
|
||||||
geany_plugin_register(plugin, 235, GEANY_API_VERSION as i32, GEANY_ABI_VERSION as i32);
|
geany_plugin_register(plugin, 235, GEANY_API_VERSION as i32, GEANY_ABI_VERSION as i32);
|
||||||
}
|
}
|
||||||
|
println!("... shenlong module loaded");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user