1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![deny(bare_trait_objects)]
extern crate gio_sys as gio_ffi;
extern crate glib_sys as glib_ffi;
extern crate gobject_sys as gobject_ffi;
extern crate gtk_sys as gtk_ffi;
#[macro_use]
extern crate lazy_static;
extern crate libc;
extern crate nautilus_extension_sys as nautilus_ffi;
pub use column_provider::{Column, ColumnProvider};
pub use info_provider::{FileInfo, InfoProvider};
pub use lazy_static::lazy_static;
pub use menu_provider::{Menu, MenuItem, MenuProvider};
pub use nautilus_module::NautilusModule;
pub use property_page_provider::{PropertyPage, PropertyPageProvider};
pub mod column_provider;
pub mod info_provider;
pub mod menu_provider;
pub mod property_page_provider;
mod nautilus_module;
mod translate;
#[macro_export]
macro_rules! nautilus_module {
($register_fn:ident) => {
use std::sync::Mutex as NautilusExtensionMutex;
use nautilus_extension::lazy_static as nautilus_extension_lazy_static;
nautilus_extension_lazy_static! {
static ref MODULE_TYPE_LIST: NautilusExtensionMutex<Vec<GType>> = NautilusExtensionMutex::new(Vec::new());
}
#[no_mangle]
pub extern "C" fn nautilus_module_initialize(module: *mut GTypeModule) {
let module_type: GType = $register_fn(module);
MODULE_TYPE_LIST.lock().unwrap().push(module_type);
}
#[no_mangle]
pub unsafe extern "C" fn nautilus_module_list_types(types: *mut *const GType, num_types: *mut c_int) {
let list_ptr = MODULE_TYPE_LIST.lock().unwrap().as_ptr();
let list_len = MODULE_TYPE_LIST.lock().unwrap().len() as c_int;
unsafe {
*types = list_ptr;
*num_types = list_len;
}
}
#[no_mangle]
pub extern "C" fn nautilus_module_shutdown() {
}
}
}
#[macro_export]
macro_rules! nautilus_menu_item_activate_cb {
($extern_fn:ident, $safe_fn:ident) => {
#[no_mangle]
pub unsafe extern "C" fn $extern_fn(_nautilusmenuitem: *mut GObject, user_data: gpointer) {
use $crate::info_provider::FileInfo;
use std::mem;
let files: Box<Vec<FileInfo>> = Box::from_raw(mem::transmute(user_data));
$safe_fn(*files);
}
}
}
#[macro_export]
macro_rules! nautilus_menu_background_activate_cb {
($extern_fn:ident, $safe_fn:ident) => {
#[no_mangle]
pub unsafe extern "C" fn $extern_fn(_nautilusmenuitem: *mut GObject, user_data: gpointer) {
use $crate::info_provider::FileInfo;
use std::mem;
let file: Box<FileInfo> = Box::from_raw(mem::transmute(user_data));
$safe_fn(*file);
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}