From: Olaf Wintermann Date: Mon, 15 Jun 2026 19:34:07 +0000 (+0200) Subject: add note info label, that shows a message when a locked note is opened X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add note info label, that shows a message when a locked note is opened --- diff --git a/application/src/main.rs b/application/src/main.rs index 636fb01..a4fff48 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -171,6 +171,7 @@ fn create_toolbar(app: &AppContext) { pub enum AppStates { Null = 0, NoteEnableNew, + NoteShowInfo, NoteMaximized } diff --git a/application/src/note.rs b/application/src/note.rs index 78c7c64..28352f0 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -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 diff --git a/application/src/window.rs b/application/src/window.rs index c41d010..8d89892 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -247,6 +247,12 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObjectonattach(&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, ...) { diff --git a/ui/gtk/text.c b/ui/gtk/text.c index 65e507f..4ce3a40 100644 --- a/ui/gtk/text.c +++ b/ui/gtk/text.c @@ -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; diff --git a/ui/motif/text.c b/ui/motif/text.c index dcb784f..68c4bab 100644 --- a/ui/motif/text.c +++ b/ui/motif/text.c @@ -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; diff --git a/ui/ui/toolkit.h b/ui/ui/toolkit.h index e86de0c..848f4fe 100644 --- a/ui/ui/toolkit.h +++ b/ui/ui/toolkit.h @@ -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);