pub enum AppStates {
Null = 0,
NoteEnableNew,
+ NoteShowInfo,
NoteMaximized
}
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;
pub note_type: UiInteger,
#[bind("note_text")]
- pub text: UiText
+ pub text: UiText,
+
+ #[bind("note_info")]
+ pub info: UiString
}
#[ui_actions]
note_type: Default::default(),
text: Default::default(),
+ info: Default::default(),
}
}
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
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");
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);
}
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);
}
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))) {
}
// 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) {
}
// 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);
free(check);
gw->enable(gw->widget, enable);
}
+
+ free(groups);
}
void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) {
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;
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;
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
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);