Commit ade141aa authored by Moritz Lipp's avatar Moritz Lipp

Update buffer in the statusbar

parent 9348a128
......@@ -2,14 +2,30 @@
#include <callbacks.h>
#include <girara.h>
#include <stdlib.h>
#include "zathura.h"
gboolean
cb_destroy(GtkWidget* widget, gpointer data)
{
if(Zathura.UI.session)
if(Zathura.UI.session) {
girara_session_destroy(Zathura.UI.session);
}
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);
}
}
......@@ -4,7 +4,9 @@
#define CALLBACKS_H
#include <gtk/gtk.h>
#include <girara.h>
gboolean cb_destroy(GtkWidget* widget, gpointer data);
void buffer_changed(girara_session_t* session);
#endif // CALLBACKS_H
......@@ -9,12 +9,15 @@ config_load_default()
if(!Zathura.UI.session)
return;
/* general settings */
girara_mode_set(Zathura.UI.session, NORMAL);
/* 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, 0, GDK_Escape, 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, 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_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_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);
......
......@@ -5,10 +5,15 @@
#include "callbacks.h"
#include "shortcuts.h"
#include "zathura.h"
bool
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;
}
......@@ -27,12 +32,28 @@ sc_change_buffer(girara_session_t* session, girara_argument_t* argument)
bool
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;
}
bool
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;
}
......
......@@ -15,9 +15,19 @@ init_zathura()
if(!girara_session_init(Zathura.UI.session))
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 */
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 */
config_load_default();
......
......@@ -26,6 +26,7 @@ struct
struct
{
girara_session_t* session; /**> girara interface session */
girara_statusbar_item_t* buffer; /**> buffer statusbar entry */
} UI;
} Zathura;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment