Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions zathura/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "adjustment.h"
#include "synctex.h"
#include "dbus-interface.h"
#include "zathura/commands.h"
#include "zathura/types.h"

gboolean cb_destroy(GtkWidget* UNUSED(widget), zathura_t* zathura) {
if (zathura_has_document(zathura) == true) {
Expand Down Expand Up @@ -334,19 +336,44 @@ void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, GtkTreeVi
GtkTreeIter iter;

g_object_get(G_OBJECT(tree_view), "model", &model, NULL);

if (gtk_tree_model_get_iter(model, &iter, path)) {
zathura_index_element_t* index_element;
gtk_tree_model_get(model, &iter, 3, &index_element, -1);

if (index_element == NULL) {
return;
}

sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
zathura_link_evaluate(zathura, index_element->link);
}
g_object_unref(model);
}

void cb_explorer_row_activated(girara_session_t* session, GtkTreeView* tree_view, GtkTreePath* path, GtkTreeViewColumn* UNUSED(column), void* data){
zathura_t* zathura = data;
if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL){
return;
}

GtkTreeModel* model;
GtkTreeIter iter;

g_object_get(G_OBJECT(tree_view), "model", &model, NULL);
if (gtk_tree_model_get_iter(model, &iter, path)){
zathura_explorer_element_s* explorer_element;
gtk_tree_model_get(model, &iter, 3, &explorer_element, -1);
if(explorer_element == NULL){
return;
}
if(explorer_element->type == ZATHURA_EXPLORER_TYPE_DIR || explorer_element->type == ZATHURA_EXPLORER_TYPE_FILE_INVALID){
return;
}
zathura_link_target_t target = zathura_link_get_target(explorer_element->link);
document_open_idle(session->global.data, target.value, NULL, 0, NULL, NULL, NULL, NULL);
}


zathura->ui.file_explorer = NULL;
zathura->ui.index = NULL;
g_object_unref(model);
}

Expand Down
10 changes: 10 additions & 0 deletions zathura/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ void cb_page_layout_value_changed(girara_session_t* session, const char* name, g
*/
void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, GtkTreeViewColumn* column, void* zathura);

/**
* Called when an explorer element is activated (e.g.: double click)
*
* @param tree_view Tree view
* @param path Path
* @param column Column
* @param zathura Zathura session
*/
void cb_explorer_row_activated(girara_session_t* session, GtkTreeView* tree_view, GtkTreePath* path, GtkTreeViewColumn* column, void* zathura);

/**
* Called when input has been passed to the sc_follow dialog
*
Expand Down
108 changes: 108 additions & 0 deletions zathura/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "database.h"
#include "dbus-interface.h"
#include "document.h"
#include "girara/log.h"
#include "internal.h"
#include "page-widget.h"
#include "page.h"
Expand All @@ -20,6 +21,7 @@
#include "shortcuts.h"
#include "utils.h"
#include "zathura.h"
#include "callbacks.h"

#include <girara/commands.h>
#include <girara/datastructures.h>
Expand Down Expand Up @@ -682,3 +684,109 @@ bool cmd_source(girara_session_t* session, girara_list_t* argument_list) {

return true;
}

bool cmd_toggle_explorer(girara_session_t* session, girara_list_t* UNUSED(argument_list)){
g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session-> global.data != NULL, false);
zathura_t* zathura = session->global.data;

girara_tree_node_t* explorer = NULL;
GtkWidget* treeview = NULL;
GtkTreeModel* model = NULL;
GtkCellRenderer* renderer = NULL;
GtkCellRenderer* renderer2 = NULL;


if (zathura->ui.file_explorer == NULL){
/* create new file explorer widget */
zathura->ui.file_explorer = gtk_scrolled_window_new(NULL, NULL);

if (zathura->ui.file_explorer == NULL){
return false;
}

gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.file_explorer), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

/* create file explorer */
explorer = zathura_explorer_generate(session, NULL);
if(explorer == NULL){
girara_notify(session, GIRARA_WARNING, _("Unable to retrieve the file explorer"));
goto error_free;
}

model = GTK_TREE_MODEL(gtk_tree_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
if (model == NULL) {
goto error_free;
}

treeview = gtk_tree_view_new_with_model(model);
if(treeview == NULL){
goto error_free;
}

gtk_style_context_add_class(gtk_widget_get_style_context(treeview), "indexmode");

g_object_unref(model);

renderer = gtk_cell_renderer_text_new();
if(renderer == NULL){
goto error_free;
}

renderer2 = gtk_cell_renderer_text_new();
if(renderer2 == NULL){
goto error_free;
}

file_explorer_build(session, model, NULL, explorer);
girara_node_free(explorer);

/* setup widget */
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), 0, "Title", renderer, "markup", 0, NULL);
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), 2, "(alt)", renderer2, "text", 2, NULL);

gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f);
gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_equal_func_index, treeview, NULL);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(treeview), FALSE);
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura);

gtk_container_add(GTK_CONTAINER(zathura->ui.file_explorer), treeview);
}

if (zathura->ui.file_explorer && gtk_widget_get_visible(GTK_WIDGET(zathura->ui.file_explorer))){
/* toggle off */
} else{
/* save document position in jumplist */
zathura_jumplist_add(zathura);

const zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document);

if (adjust_mode == ZATHURA_ADJUST_INPUTBAR) {
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE);
}

/* set the view */
girara_set_view(session, zathura->ui.file_explorer);
GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.file_explorer))->data;
gtk_widget_grab_focus(GTK_WIDGET(tree_view));
girara_mode_set(zathura->ui.session, zathura->modes.index);
}

return true;

error_free:

if(zathura->ui.file_explorer != NULL){
g_object_ref_sink(zathura->ui.file_explorer);
zathura->ui.file_explorer = NULL;
}

if(explorer != NULL){
girara_node_free(explorer);
}

return true;
}
11 changes: 11 additions & 0 deletions zathura/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,15 @@ bool cmd_version(girara_session_t* session, girara_list_t* argument_list);
*/
bool cmd_source(girara_session_t* session, girara_list_t* argument_list);

/**
* Toggles the file explorer
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return true if no error occurred
*/

bool cmd_toggle_explorer(girara_session_t* session, girara_list_t* argument_list);


#endif // COMMANDS_H
1 change: 1 addition & 0 deletions zathura/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ void config_load_default(zathura_t* zathura) {
girara_inputbar_command_add(gsession, "hlsearch", NULL, cmd_hlsearch, NULL, _("Highlight current search results"));
girara_inputbar_command_add(gsession, "version", NULL, cmd_version, NULL, _("Show version information"));
girara_inputbar_command_add(gsession, "source", NULL, cmd_source, NULL, _("Source config file"));
girara_inputbar_command_add(gsession, "explore", "fe", cmd_toggle_explorer, NULL, _("Toggle the file explorer"));

girara_special_command_add(gsession, '/', cmd_search, INCREMENTAL_SEARCH, FORWARD, NULL);
girara_special_command_add(gsession, '?', cmd_search, INCREMENTAL_SEARCH, BACKWARD, NULL);
Expand Down
31 changes: 26 additions & 5 deletions zathura/shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ bool sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), gi
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
zathura_document_t* document = zathura_get_document(zathura);

bool clear_search = true;
girara_setting_get(session, "abort-clear-search", &clear_search);

Expand Down Expand Up @@ -1002,11 +1001,18 @@ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, g
g_return_val_if_fail(argument != NULL, false);
g_return_val_if_fail(zathura->document != NULL, false);

if (zathura->ui.index == NULL) {
if (zathura->ui.index == NULL && zathura->ui.file_explorer == NULL) {
return false;
}

GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreeView* tree_view = NULL;
if (zathura->ui.index && gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))){
tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
}else if (zathura->ui.file_explorer && gtk_widget_get_visible(GTK_WIDGET(zathura->ui.file_explorer))){
tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.file_explorer))->data;
}else{
return false;
}
GtkTreePath* path;
GtkTreePath* start_path;
GtkTreePath* end_path;
Expand Down Expand Up @@ -1131,7 +1137,11 @@ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, g
}
break;
case SELECT:
cb_index_row_activated(tree_view, path, NULL, zathura);
if(gtk_widget_get_visible(zathura->ui.file_explorer)){
cb_explorer_row_activated(session, tree_view, path, NULL, zathura);
}else{
cb_index_row_activated(tree_view, path, NULL, zathura);
}
goto free_and_return;
}

Expand All @@ -1157,6 +1167,17 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
return false;
}

if (zathura->ui.file_explorer && gtk_widget_get_visible(GTK_WIDGET(zathura->ui.file_explorer))){

girara_set_view(session, zathura->ui.document_widget);
gtk_widget_hide(GTK_WIDGET(zathura->ui.file_explorer));
girara_mode_set(zathura->ui.session, zathura->modes.normal);

/* refresh view */
refresh_view(zathura);
return true;
}

girara_tree_node_t* document_index = NULL;
GtkWidget* treeview = NULL;
GtkTreeModel* model = NULL;
Expand Down Expand Up @@ -1223,7 +1244,7 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview);
}

if (gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) {
if (zathura->ui.index && gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) {
girara_set_view(session, zathura->ui.document_widget);
gtk_widget_hide(GTK_WIDGET(zathura->ui.index));
girara_mode_set(zathura->ui.session, zathura->modes.normal);
Expand Down
2 changes: 2 additions & 0 deletions zathura/shortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, g
*/
bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t);

bool sc_toggle_file_explorer(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t);

/**
* Toggle multi page mode
*
Expand Down
10 changes: 10 additions & 0 deletions zathura/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ void zathura_index_element_free(zathura_index_element_t* index) {
g_free(index);
}

void zathura_explorer_element_free(zathura_explorer_element_s* index) {
if (index == NULL) {
return;
}

g_free(index->title);
zathura_link_free(index->link);
g_free(index);
}

zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height) {
g_return_val_if_fail(width != 0, NULL);
g_return_val_if_fail(height != 0, NULL);
Expand Down
23 changes: 23 additions & 0 deletions zathura/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ typedef struct zathura_index_element_s {
zathura_link_t* link;
} zathura_index_element_t;

typedef enum zathura_explorer_type_e{
ZATHURA_EXPLORER_TYPE_FILE_VALID,
ZATHURA_EXPLORER_TYPE_FILE_INVALID,
ZATHURA_EXPLORER_TYPE_DIR,
} zathura_explorer_type_e;

/**
* Index element
*/
typedef struct zathura_explorer_element_s{
char* title; /**< Title of the element */
zathura_explorer_type_e type;
zathura_link_t* link;
} zathura_explorer_element_s;


/**
* Form type
*/
Expand Down Expand Up @@ -238,6 +254,13 @@ ZATHURA_PLUGIN_API zathura_index_element_t* zathura_index_element_new(const char
*/
ZATHURA_PLUGIN_API void zathura_index_element_free(zathura_index_element_t* index);

/**
* Free index element
*
* @param index The index element
*/
ZATHURA_PLUGIN_API void zathura_explorer_element_free(zathura_explorer_element_s* index);

/**
* Creates a list that should be used to store \ref
* zathura_document_information_entry_t entries
Expand Down
Loading