]> uap-core.de Git - note.git/commitdiff
add note info label, that shows a message when a locked note is opened main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 15 Jun 2026 19:34:07 +0000 (21:34 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 15 Jun 2026 19:34:07 +0000 (21:34 +0200)
application/src/main.rs
application/src/note.rs
application/src/window.rs
ui/common/context.c
ui/gtk/text.c
ui/motif/text.c
ui/ui/toolkit.h

index 636fb01abb50e2ef18117cf228674190a04f69d2..a4fff48ec185197fe347eb2ab83f1ee68376df39 100644 (file)
@@ -171,6 +171,7 @@ fn create_toolbar(app: &AppContext<MainWindow>) {
 pub enum AppStates {
     Null = 0,
     NoteEnableNew,
+    NoteShowInfo,
     NoteMaximized
 }
 
index 78c7c64a2742b46a6185e6b509220e98bb9e0cfa..28352f0404924607c31275cdeb191a99c0ac7bbb 100644 (file)
@@ -33,6 +33,7 @@ use sea_orm::{NotSet, Set};
 use entity::note::NoteType;
 use ui_rs::{action, ui_actions, UiModel};
 use ui_rs::ui::*;
+use crate::AppStates;
 use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate, SaveNoteResult};
 use crate::lockmanager::{NoteLock, OpenNoteHandle};
 use crate::window::NoteTypeTabView;
@@ -64,7 +65,10 @@ pub struct Note {
     pub note_type: UiInteger,
 
     #[bind("note_text")]
-    pub text: UiText
+    pub text: UiText,
+    
+    #[bind("note_info")]
+    pub info: UiString
 }
 
 #[ui_actions]
@@ -88,6 +92,7 @@ impl Note {
 
             note_type: Default::default(),
             text: Default::default(),
+            info: Default::default(),
         }
     }
 
@@ -122,6 +127,10 @@ impl Note {
                 if self.lock.is_none() {
                     // the note is already opened in another window
                     self.text.set_readonly(true);
+                    self.info.set("Note already opened in another window");
+                    doc.ctx.set_state(AppStates::NoteShowInfo as i32);
+                } else {
+                    doc.ctx.unset_state(AppStates::NoteShowInfo as i32);
                 }
 
                 // also try to get an OpenNoteHandle, which checks the current note version
index c41d0107768b05bb526fffe7c31836536ec6eaa7..8d898922dd3fa4c62cb294e8e6f128410f28c054 100644 (file)
@@ -247,6 +247,12 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                     tabview.tab("empty", |_obj| {});
 
                     tabview.tab("textnote", |obj| {
+                        obj.label(|l|{
+                            l.margin(4);
+                            l.varname("note_info");
+                            l.visibility_states(&[AppStates::NoteShowInfo as i32]);
+                        });
+
                         let textarea = obj.textarea(|b|{
                            b.fill(true);
                             b.varname("note_text");
index f1159749f5542364fb9cbf2d327761b0b4cfdfbd..1fd4c1f510fe390f210f8098ec5334d0fda705ac 100644 (file)
@@ -196,6 +196,7 @@ void uic_context_attach_document(UiContext *ctx, void *document) {
         event.document = document;
         doc_ctx->onattach(&event, doc_ctx->onattachdata);
     }
+    uic_check_state_widgets(ui_context_toplevel_parent(ctx));
     uic_send_status_change(doc_ctx);
 }
 
@@ -252,6 +253,7 @@ void uic_context_detach_document(UiContext *ctx, void *document) {
         doc_ctx->ondetach(&event, doc_ctx->ondetachdata);
     }
     
+    uic_check_state_widgets(ui_context_toplevel_parent(ctx));
     uic_send_status_change(doc_ctx);
     ui_document_unref(document);
 }
@@ -651,6 +653,15 @@ UiContext* ui_context_parent(UiContext *ctx) {
     return ctx->parent;
 }
 
+UiContext* ui_context_toplevel_parent(UiContext *ctx) {
+    if(ctx->obj) {
+        return ctx;
+    } else if (ctx->parent) {
+        return ui_context_toplevel_parent(ctx->parent);
+    }
+    return NULL;
+}
+
 
 void ui_set_state(UiContext *ctx, int state) {
     if(!cxListIndexValid(ctx->states, cxListFind(ctx->states, &state))) {
@@ -658,7 +669,7 @@ void ui_set_state(UiContext *ctx, int state) {
     }
     
     // enable/disable group widgets
-    uic_check_state_widgets(ctx);
+    uic_check_state_widgets(ui_context_toplevel_parent(ctx));
 }
 
 void ui_unset_state(UiContext *ctx, int state) {
@@ -668,15 +679,39 @@ void ui_unset_state(UiContext *ctx, int state) {
     }
     
     // enable/disable group widgets
-    uic_check_state_widgets(ctx);
+    uic_check_state_widgets(ui_context_toplevel_parent(ctx));
+}
+
+typedef struct StatesList {
+    CX_ARRAY(int, states);
+} StatesList;
+
+static void add_ctx_states(UiContext *ctx, StatesList *states) {
+    size_t nstates = cxListSize(ctx->states);
+    int *ctx_states = cxListAt(ctx->states, 0);;
+    
+    cx_array_add_array(states->states, ctx_states, nstates);
+    
+    CxIterator i = cxListIterator(ctx->documents);
+    cx_foreach(void *, doc, i) {
+        UiContext *doc_ctx = ui_document_context(doc);
+        add_ctx_states(doc_ctx, states);
+    }
 }
 
 int* ui_active_states(UiContext *ctx, int *nstates) {
-    *nstates = cxListSize(ctx->states);
-    return cxListAt(ctx->states, 0);
+    StatesList states;
+    cx_array_init(states.states, 32);
+    add_ctx_states(ctx, &states);
+    *nstates = (int)states.states.size;
+    return states.states.data;
 }
 
 void uic_check_state_widgets(UiContext *ctx) {
+    if(!ctx) {
+        return;
+    }
+    
     int ngroups = 0;
     int *groups = ui_active_states(ctx, &ngroups);
     
@@ -702,6 +737,8 @@ void uic_check_state_widgets(UiContext *ctx) {
         free(check);
         gw->enable(gw->widget, enable);
     }
+    
+    free(groups);
 }
 
 void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) {
index 65e507f8e12fe66fa271289778701ec6e752a72f..4ce3a40565a91e9802eabfc105885660112696c1 100644 (file)
@@ -54,9 +54,9 @@ static void selection_handler(
         int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end);
         if(sel != textview->last_selection_state) {
             if(sel) {
-                ui_set_state(textview->ctx, UI_GROUP_SELECTION);
+                ui_set_state(textview->ctx, UI_STATE_SELECTION);
             } else {
-                ui_unset_state(textview->ctx, UI_GROUP_SELECTION);
+                ui_unset_state(textview->ctx, UI_STATE_SELECTION);
             }
         }
         textview->last_selection_state = sel;
index dcb784fea1aa9159c7cddbcc375bd86adfcbc34e..68c4bab487eb7671984e121c8e97aaf6eb3f6420 100644 (file)
@@ -218,9 +218,9 @@ void ui_text_selection_callback(
     int sel = left < right ? 1 : 0;
     if(sel != textarea->last_selection_state) {
         if(sel) {
-            ui_set_state(textarea->obj->ctx, UI_GROUP_SELECTION);
+            ui_set_state(textarea->obj->ctx, UI_STATE_SELECTION);
         } else {
-            ui_unset_state(textarea->obj->ctx, UI_GROUP_SELECTION);
+            ui_unset_state(textarea->obj->ctx, UI_STATE_SELECTION);
         }
     }
     textarea->last_selection_state = sel;
index e86de0cb2b14fda2d82219adc4a9fcf8ee04073e..848f4fe278f6ebddf931653f6b3fe356c49c9012 100644 (file)
@@ -180,9 +180,9 @@ typedef struct UiWidget UiWidget;
 extern "C" {
 #endif
 
-#define UI_GROUP_SELECTION  20000
+#define UI_STATE_SELECTION  20000
 
-#define UI_GROUPS(...) (const int[]){ __VA_ARGS__, -1 }
+#define UI_STATES(...) (const int[]){ __VA_ARGS__, -1 }
     
 /* public types */
 #ifndef __cplusplus
@@ -542,6 +542,7 @@ UIEXPORT UiContext* ui_global_context(void);
 UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata);
 
 UIEXPORT UiContext* ui_context_parent(UiContext *ctx);
+UIEXPORT UiContext* ui_context_toplevel_parent(UiContext *ctx);
 
 UIEXPORT void ui_object_ref(UiObject *obj);
 UIEXPORT int ui_object_unref(UiObject *obj);