Update buffer in the statusbar

This commit is contained in:
Moritz Lipp 2010-11-13 12:40:48 +01:00
parent 9348a128ff
commit ade141aadc
6 changed files with 57 additions and 4 deletions

View file

@ -2,14 +2,30 @@
#include <callbacks.h> #include <callbacks.h>
#include <girara.h> #include <girara.h>
#include <stdlib.h>
#include "zathura.h" #include "zathura.h"
gboolean gboolean
cb_destroy(GtkWidget* widget, gpointer data) cb_destroy(GtkWidget* widget, gpointer data)
{ {
if(Zathura.UI.session) if(Zathura.UI.session) {
girara_session_destroy(Zathura.UI.session); girara_session_destroy(Zathura.UI.session);
}
return TRUE; return TRUE;
} }
void
buffer_changed(girara_session_t* session)
{
g_return_if_fail(session != NULL);
g_return_if_fail(Zathura.UI.buffer != NULL);
char* buffer = girara_buffer_get(session);
if(buffer) {
girara_statusbar_item_set_text(session, Zathura.UI.buffer, buffer);
free(buffer);
}
}

View file

@ -4,7 +4,9 @@
#define CALLBACKS_H #define CALLBACKS_H
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <girara.h>
gboolean cb_destroy(GtkWidget* widget, gpointer data); gboolean cb_destroy(GtkWidget* widget, gpointer data);
void buffer_changed(girara_session_t* session);
#endif // CALLBACKS_H #endif // CALLBACKS_H

View file

@ -9,12 +9,15 @@ config_load_default()
if(!Zathura.UI.session) if(!Zathura.UI.session)
return; return;
/* general settings */
girara_mode_set(Zathura.UI.session, NORMAL);
/* define default shortcuts */ /* define default shortcuts */
girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, ALL, 0, NULL); girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, ALL, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, ALL, DELETE_LAST, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL);

View file

@ -5,10 +5,15 @@
#include "callbacks.h" #include "callbacks.h"
#include "shortcuts.h" #include "shortcuts.h"
#include "zathura.h"
bool bool
sc_abort(girara_session_t* session, girara_argument_t* argument) sc_abort(girara_session_t* session, girara_argument_t* argument)
{ {
g_return_val_if_fail(session != NULL, false);
girara_mode_set(session, NORMAL);
return false; return false;
} }
@ -27,12 +32,28 @@ sc_change_buffer(girara_session_t* session, girara_argument_t* argument)
bool bool
sc_change_mode(girara_session_t* session, girara_argument_t* argument) sc_change_mode(girara_session_t* session, girara_argument_t* argument)
{ {
g_return_val_if_fail(session != NULL, false);
girara_mode_set(session, argument->n);
return false; return false;
} }
bool bool
sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument)
{ {
g_return_val_if_fail(session != NULL, false);
if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))))
gtk_widget_show(GTK_WIDGET(session->gtk.inputbar));
if(argument->data)
{
gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data);
gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar));
gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1);
}
return false; return false;
} }

View file

@ -15,9 +15,19 @@ init_zathura()
if(!girara_session_init(Zathura.UI.session)) if(!girara_session_init(Zathura.UI.session))
return false; return false;
/* UI */
Zathura.UI.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL);
if(!Zathura.UI.buffer) {
girara_session_destroy(Zathura.UI.session);
return false;
}
/* signals */ /* signals */
g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL);
/* girara events */
Zathura.UI.session->events.buffer_changed = buffer_changed;
/* configuration */ /* configuration */
config_load_default(); config_load_default();

View file

@ -26,6 +26,7 @@ struct
struct struct
{ {
girara_session_t* session; /**> girara interface session */ girara_session_t* session; /**> girara interface session */
girara_statusbar_item_t* buffer; /**> buffer statusbar entry */
} UI; } UI;
} Zathura; } Zathura;