Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
laomuon committed Aug 6, 2024
1 parent f6cd157 commit 38c9cb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 0 additions & 3 deletions zathura/shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,6 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
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_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura);

gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview);
Expand All @@ -1224,11 +1223,9 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE);
}

// g_idle_add(G_SOURCE_FUNC(index_scroll_to_current_page), zathura);
girara_set_view(session, zathura->ui.index);
index_scroll_to_current_page(zathura);
girara_mode_set(zathura->ui.session, zathura->modes.index);
refresh_view(zathura);
}

return false;
Expand Down
15 changes: 12 additions & 3 deletions zathura/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <girara/settings.h>
#include <girara/utils.h>

#include "glib.h"
#include "links.h"
#include "utils.h"
#include "zathura.h"
Expand All @@ -20,6 +21,7 @@
#include "page.h"
#include "plugin.h"
#include "content-type.h"
#include "zathura/types.h"

double zathura_correct_zoom_value(girara_session_t* session, const double zoom) {
if (session == NULL) {
Expand Down Expand Up @@ -126,20 +128,27 @@ static gboolean search_current_index(GtkTreeModel* model, GtkTreePath* UNUSED(pa
return FALSE;
}

static void tree_view_scroll_to_cell(zathura_t* zathura)
{
GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreePath* current_path = gtk_tree_path_new_from_string(zathura->global.current_index_path);
gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0);
}

void index_scroll_to_current_page(zathura_t* zathura) {
GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreeModel* model = gtk_tree_view_get_model(tree_view);


SearchData search_data;
search_data.current_page = zathura_document_get_current_page_number(zathura->document);
gtk_tree_model_foreach(model, search_current_index, &search_data);

GtkTreePath* current_path = gtk_tree_model_get_path(model, &search_data.current_iter);
zathura->global.current_index_path = gtk_tree_path_to_string(current_path);
gtk_tree_view_expand_to_path(tree_view, current_path);
gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0);

g_idle_add(G_SOURCE_FUNC(tree_view_scroll_to_cell), zathura);
gtk_tree_view_set_cursor(tree_view, current_path, NULL, FALSE);
girara_error("%f\n", gtk_adjustment_get_upper(gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(tree_view))));
gtk_tree_path_free(current_path);
}

Expand Down
1 change: 1 addition & 0 deletions zathura/zathura.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct zathura_s {
GdkModifierType synctex_edit_modmask; /**< Modifier to trigger synctex edit */
GdkModifierType highlighter_modmask; /**< Modifier to draw with a highlighter */
bool double_click_follow; /**< Double/Single click to follow link */
char *current_index_path;
} global;

struct {
Expand Down

0 comments on commit 38c9cb2

Please sign in to comment.