n.init_from_model(model);
n.load_content(d);
}
-
+ // make sure we receive an event, when this note is attached or detached
d.ctx.on_attachment_status_change_action("attachment_status_changed");
})
}
+ /// Handles any attachment status change, which includes if this note is
+ /// directly attached or detached, but also if any parent attachment status changes
#[action]
pub fn attachment_status_changed(&mut self, _event: &ActionEvent) -> Option<()>{
let doc = self.doc.get_doc()?;
if doc.ctx.is_attached_to_obj() {
+
+
if let NoteId::Id(note_id) = self.id {
self.lock = self.backend.backend.lockmgr.lock_note(note_id);
if self.lock.is_none() {
where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
// if this is a document context, use the document pointer as target
// otherwise it is a UiObject context, in that case we use the window_data as target
- let doc_ptr = ui_context_document(self.ptr) as *mut T;
- let target_ptr = if !doc_ptr.is_null() {
- let doc_storage: *mut *mut T = doc_ptr.cast();
- *doc_storage
- } else {
- let obj_ptr = ui_context_obj(self.ptr);
- assert!(!obj_ptr.is_null());
- let obj_wdata_ptr = ui_object_get_windowdata(obj_ptr);
- assert!(!obj_wdata_ptr.is_null());
- obj_wdata_ptr as *mut T
- };
- self.add_action_for_target(target_ptr, name, f);
+ unsafe {
+ let doc_ptr = ui_context_document(self.ptr) as *mut T;
+ let target_ptr = if !doc_ptr.is_null() {
+ let doc_storage: *mut *mut T = doc_ptr.cast();
+ *doc_storage
+ } else {
+ let obj_ptr = ui_context_obj(self.ptr);
+ assert!(!obj_ptr.is_null());
+ let obj_wdata_ptr = ui_object_get_windowdata(obj_ptr);
+ assert!(!obj_wdata_ptr.is_null());
+ obj_wdata_ptr as *mut T
+ };
+ self.add_action_for_target(target_ptr, name, f);
+ }
}
pub unsafe fn add_action_for_target<T, F>(&self, target_ptr: *mut T, name: &str, f: F)
let wrapper = Box::new(ActionEventWrapper { callback: Box::new(f), target: target_ptr });
let ptr = self.reg_box(wrapper);
let cstr = CString::new(name).unwrap();
- ui_add_action(self.ptr, cstr.as_ptr(), Some(action_event_wrapper::<T>), ptr as *mut c_void);
+ unsafe {
+ ui_add_action(self.ptr, cstr.as_ptr(), Some(action_event_wrapper::<T>), ptr as *mut c_void);
+ }
}
pub fn add_action_untyped<F>(&self, name: &str, f: F)
}
pub unsafe fn get_data_ptr(&self) -> *mut T {
- let ptr: *mut *mut T = self.ptr.cast();
- *ptr
+ unsafe {
+ let ptr: *mut *mut T = self.ptr.cast();
+ *ptr
+ }
}
pub fn add_action<F>(&mut self, name: &str, f: F)
}
pub unsafe fn ui_list_get<'a, T>(list: *const ffi::UiList, index: usize) -> Option<&'a T> {
- let data = ui_list_get_data(list);
- let ls = &*(data as *mut Vec<T>);
- ls.get(index)
+ unsafe {
+ let data = ui_list_get_data(list);
+ let ls = &*(data as *mut Vec<T>);
+ ls.get(index)
+ }
}
/* -------------------------------- C functions -------------------------------- */
-extern "C" {
+unsafe extern "C" {
fn ui_init(appname: *const c_char, argc: c_int, argv: *const *const c_char);
pub fn ui_global_context() -> *mut ffi::UiContext;
fn ui_getappdir() -> *mut c_char;
type UiListGetFunc = extern "C" fn(*const ffi::UiList, c_int) -> *mut c_void;
type UiListCountFunc = extern "C" fn(*const ffi::UiList) -> c_int;
-extern "C" {
+unsafe extern "C" {
pub fn ui_app_ref();
pub fn ui_app_unref();