mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 17:43:47 +01:00
index: Display page label alongside page number
Displays target page as "Page <label> (<number>)" in the index, e.g. "Page iv (6)". When no page label is defined, the previous "Page <number>" format is retained. This is consistant with the status bar formatting. The additional "(<number>)" is in a new column to keep it aligned.
This commit is contained in:
parent
b86cb99d22
commit
2fb3992d9d
@ -363,7 +363,7 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
|
|||||||
|
|
||||||
if(gtk_tree_model_get_iter(model, &iter, path)) {
|
if(gtk_tree_model_get_iter(model, &iter, path)) {
|
||||||
zathura_index_element_t* index_element;
|
zathura_index_element_t* index_element;
|
||||||
gtk_tree_model_get(model, &iter, 2, &index_element, -1);
|
gtk_tree_model_get(model, &iter, 3, &index_element, -1);
|
||||||
|
|
||||||
if (index_element == NULL) {
|
if (index_element == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -1175,7 +1175,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
|||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
model = GTK_TREE_MODEL(gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
|
model = GTK_TREE_MODEL(gtk_tree_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
|
||||||
if (model == NULL) {
|
if (model == NULL) {
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
@ -1200,12 +1200,13 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
|||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
document_index_build(model, NULL, document_index);
|
document_index_build(session, model, NULL, document_index);
|
||||||
girara_node_free(document_index);
|
girara_node_free(document_index);
|
||||||
|
|
||||||
/* setup widget */
|
/* 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), 0, "Title", renderer, "markup", 0, NULL);
|
||||||
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 1, "Target", renderer2, "text", 1, NULL);
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 1, "Target", renderer2, "text", 1, 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);
|
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(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
||||||
|
@ -70,7 +70,9 @@ index_element_free(void* data, GObject* UNUSED(object))
|
|||||||
zathura_index_element_free(element);
|
zathura_index_element_free(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree) {
|
void document_index_build(girara_session_t* session, GtkTreeModel* model,
|
||||||
|
GtkTreeIter* parent, girara_tree_node_t* tree)
|
||||||
|
{
|
||||||
girara_list_t* list = girara_node_get_children(tree);
|
girara_list_t* list = girara_node_get_children(tree);
|
||||||
|
|
||||||
for (size_t idx = 0; idx != girara_list_size(list); ++idx) {
|
for (size_t idx = 0; idx != girara_list_size(list); ++idx) {
|
||||||
@ -80,8 +82,20 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_
|
|||||||
zathura_link_target_t target = zathura_link_get_target(index_element->link);
|
zathura_link_target_t target = zathura_link_get_target(index_element->link);
|
||||||
|
|
||||||
gchar* description = NULL;
|
gchar* description = NULL;
|
||||||
|
gchar* description2 = NULL;
|
||||||
|
|
||||||
if (type == ZATHURA_LINK_GOTO_DEST) {
|
if (type == ZATHURA_LINK_GOTO_DEST) {
|
||||||
|
zathura_t *zathura = session->global.data;
|
||||||
|
zathura_page_t *page = zathura_document_get_page(zathura->document, target.page_number);
|
||||||
|
char *label = zathura_page_get_label(page, NULL);
|
||||||
|
|
||||||
|
if (label != NULL) {
|
||||||
|
description = g_strdup_printf("Page %s", label);
|
||||||
|
description2 = g_strdup_printf("(%d)", target.page_number + 1);
|
||||||
|
g_free(label);
|
||||||
|
} else {
|
||||||
description = g_strdup_printf("Page %d", target.page_number + 1);
|
description = g_strdup_printf("Page %d", target.page_number + 1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
description = g_strdup(target.value);
|
description = g_strdup(target.value);
|
||||||
}
|
}
|
||||||
@ -89,13 +103,15 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_
|
|||||||
GtkTreeIter tree_iter;
|
GtkTreeIter tree_iter;
|
||||||
gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent);
|
gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent);
|
||||||
gchar* markup = g_markup_escape_text(index_element->title, -1);
|
gchar* markup = g_markup_escape_text(index_element->title, -1);
|
||||||
gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, markup, 1, description, 2, index_element, -1);
|
gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, markup,
|
||||||
|
1, description, 2, description2, 3, index_element, -1);
|
||||||
g_free(markup);
|
g_free(markup);
|
||||||
g_object_weak_ref(G_OBJECT(model), index_element_free, index_element);
|
|
||||||
g_free(description);
|
g_free(description);
|
||||||
|
g_free(description2);
|
||||||
|
g_object_weak_ref(G_OBJECT(model), index_element_free, index_element);
|
||||||
|
|
||||||
if (girara_node_get_num_children(node) > 0) {
|
if (girara_node_get_num_children(node) > 0) {
|
||||||
document_index_build(model, &tree_iter, node);
|
document_index_build(session, model, &tree_iter, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,12 @@ bool file_valid_extension(zathura_t* zathura, const char* path);
|
|||||||
* Generates the document index based upon the list retrieved from the document
|
* Generates the document index based upon the list retrieved from the document
|
||||||
* object.
|
* object.
|
||||||
*
|
*
|
||||||
|
* @param session The session
|
||||||
* @param model The tree model
|
* @param model The tree model
|
||||||
* @param parent The tree iterator parent
|
* @param parent The tree iterator parent
|
||||||
* @param tree The Tree iterator
|
* @param tree The Tree iterator
|
||||||
*/
|
*/
|
||||||
void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree);
|
void document_index_build(girara_session_t* session, GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate a rectangle by 0, 90, 180 or 270 degree
|
* Rotate a rectangle by 0, 90, 180 or 270 degree
|
||||||
|
Loading…
Reference in New Issue
Block a user