commit bc906dc772de296971d59ffe1644cfb92dc2d7b5
parent 0b04881cbd46617dbfe902d9d0e92ade940e07be
Author: lash <dev@holbrook.no>
Date: Wed, 29 May 2024 23:02:56 +0100
Use int menu value in menu header switch
Diffstat:
5 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/src/aux/beamenu/gen.c b/src/aux/beamenu/gen.c
@@ -124,6 +124,7 @@ int set(int c) {
ENTRY o;
ENTRY *p;
int v;
+ int *entry_index;
o.key = (char*)tmpk;
if (*o.key == 0) {
@@ -137,7 +138,9 @@ int set(int c) {
if (!p) {
return 1;
}
- v = *((int*)p->data);
+ entry_index = (int*)(p->data);
+ entry_index += c;
+ v = *entry_index;
beamenu_set(c, tmpc, v);
if (debug) {
fprintf(stderr, "set %d %d %d\n", c, tmpc, v);
diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c
@@ -189,25 +189,30 @@ KeeMenu* kee_menu_new(GtkApplication *gapp, struct kee_context *ctx) {
}
-/// \todo less strcmp
-static void kee_menu_header_update(KeeMenu *o, const char *label) {
+//static void kee_menu_header_update(KeeMenu *o, const char *label) {
+static void kee_menu_header_update(KeeMenu *o, int menu_id) {
GAction *act;
- if (!(strcmp(label, "unlock"))) {
- } else if (!(strcmp(label, "view"))) {
- act = g_action_map_lookup_action(G_ACTION_MAP(o), "import");
- g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
- act = g_action_map_lookup_action(G_ACTION_MAP(o), "back");
- g_simple_action_set_enabled(G_SIMPLE_ACTION(act), false);
- act = g_action_map_lookup_action(G_ACTION_MAP(o), "new_entry");
- g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
- } else if (!(strcmp(label, "entry"))) {
- act = g_action_map_lookup_action(G_ACTION_MAP(o), "back");
- g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
- } else if (!(strcmp(label, "import"))) {
- } else if (!(strcmp(label, "transport"))) {
- } else {
- g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unknown nav label: %s", label);
+ switch (menu_id) {
+ case BEAMENU_DST_KEY:
+ break;
+ case BEAMENU_DST_LIST:
+ act = g_action_map_lookup_action(G_ACTION_MAP(o), "import");
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
+ act = g_action_map_lookup_action(G_ACTION_MAP(o), "back");
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(act), false);
+ act = g_action_map_lookup_action(G_ACTION_MAP(o), "new_entry");
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
+ break;
+ case BEAMENU_DST_NEW:
+ act = g_action_map_lookup_action(G_ACTION_MAP(o), "back");
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
+ case BEAMENU_DST_IMPORT:
+ break;
+ case BEAMENU_DST_TRANSPORT:
+ break;
+ default:
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unknown nav label: %s", beamenu_dst_r[menu_id]);
}
}
@@ -226,7 +231,8 @@ GtkWidget* kee_menu_next(KeeMenu *o, int menu_id) {
//kee_nav_push(&o->nav, widget);
kee_nav_set(widget, menu_id);
gtk_stack_set_visible_child(o->stack, widget);
- kee_menu_header_update(o, label);
+ //kee_menu_header_update(o, label);
+ kee_menu_header_update(o, menu_id);
return widget;
}
@@ -251,7 +257,7 @@ int kee_menu_prev(KeeMenu *o) {
widget = kee_nav_back();
gtk_stack_set_visible_child(o->stack, widget);
- kee_menu_header_update(o, KEE_NAV_LABEL);
+ kee_menu_header_update(o, KEE_NAV_IDX);
return ERR_OK;
}
diff --git a/src/gtk/nav.c b/src/gtk/nav.c
@@ -69,3 +69,10 @@ char *kee_nav_get_label() {
o = beamenu_get(-1);
return beamenu_dst_r[o->i];
}
+
+int kee_nav_get_idx() {
+ struct beamenu_node *o;
+
+ o = beamenu_get(-1);
+ return o->i;
+}
diff --git a/src/gtk/nav.h b/src/gtk/nav.h
@@ -7,6 +7,7 @@
#define KEE_NAV_NOW kee_nav_get()
#define KEE_NAV_LABEL kee_nav_get_label()
+#define KEE_NAV_IDX kee_nav_get_idx()
#ifndef KEE_NAV_N_DST
#define KEE_NAV_N_DST BEAMENU_N_DST + 1
@@ -19,6 +20,7 @@ int kee_nav_init(const char *path);
int kee_nav_set(GtkWidget *, int idx);
int kee_nav_unset(int idx);
GtkWidget* kee_nav_get();
+int kee_nav_get_idx();
char* kee_nav_get_label();
GtkWidget* kee_nav_back(); // returns new current widget
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -82,25 +82,30 @@ void ui_build(GtkApplication *gapp, struct kee_context *ctx) {
win = kee_menu_new(gapp, ctx);
widget = GTK_WIDGET(kee_key_new(&ctx->gpg));
- kee_menu_add(win, "unlock", widget);
+ //kee_menu_add(win, "unlock", widget);
+ kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_KEY], widget);
g_signal_connect (widget, "unlock", G_CALLBACK(ui_handle_unlock), win);
widget = kee_entry_list_new(G_LIST_MODEL(ctx->entry_store), win);
- kee_menu_add(win, "view", widget);
+ //kee_menu_add(win, "view", widget);
+ kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_LIST], widget);
//kee_menu_next(win, "view");
kee_menu_next(win, BEAMENU_DST_LIST);
kee_menu_next(win, BEAMENU_DST_KEY);
import = kee_import_new(win);
- kee_menu_add(win, "import", GTK_WIDGET(import));
+ //kee_menu_add(win, "import", GTK_WIDGET(import));
+ kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_IMPORT], GTK_WIDGET(import));
//g_signal_connect(import, "data_available", G_CALLBACK(ui_handle_import), win);
widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- kee_menu_add(win, "entry", widget);
+ //kee_menu_add(win, "entry", widget);
+ kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_NEW], widget);
trans = g_object_new(KEE_TYPE_TRANSPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
- kee_menu_add(win, "transport", GTK_WIDGET(trans));
+ //kee_menu_add(win, "transport", GTK_WIDGET(trans));
+ kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_TRANSPORT], GTK_WIDGET(trans));
/// \todo make kee-entry action map/group?
act = g_simple_action_new("qr", G_VARIANT_TYPE_STRING);
@@ -111,7 +116,6 @@ void ui_build(GtkApplication *gapp, struct kee_context *ctx) {
g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act));
g_signal_connect(act, "activate", G_CALLBACK(kee_transport_handle_qr), trans);
-
gtk_window_present(GTK_WINDOW (win));
}