mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-03-03 18:04:40 +01:00
Update sc_follow
This commit is contained in:
parent
eb26be7e75
commit
9d87451389
2 changed files with 33 additions and 32 deletions
57
callbacks.c
57
callbacks.c
|
@ -154,20 +154,22 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
|
||||||
g_return_val_if_fail(session->global.data != NULL, FALSE);
|
g_return_val_if_fail(session->global.data != NULL, FALSE);
|
||||||
|
|
||||||
zathura_t* zathura = session->global.data;
|
zathura_t* zathura = session->global.data;
|
||||||
|
bool eval = true;
|
||||||
|
|
||||||
char* input = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
|
char* input = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
|
||||||
if (input == NULL) {
|
if (input == NULL || strlen(input) == 0) {
|
||||||
goto error_ret;
|
eval = false;
|
||||||
} else if (strlen(input) == 0) {
|
|
||||||
goto error_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = atoi(input);
|
int index = 0;
|
||||||
if (index == 0 && g_strcmp0(input, "0") != 0) {
|
if (eval == true) {
|
||||||
girara_notify(session, GIRARA_WARNING, "Invalid input '%s' given.", input);
|
index = atoi(input);
|
||||||
goto error_free;
|
if (index == 0 && g_strcmp0(input, "0") != 0) {
|
||||||
|
girara_notify(session, GIRARA_WARNING, "Invalid input '%s' given.", input);
|
||||||
|
eval = false;
|
||||||
|
}
|
||||||
|
index = index - 1;
|
||||||
}
|
}
|
||||||
index = index-1;
|
|
||||||
|
|
||||||
/* set pages to draw links */
|
/* set pages to draw links */
|
||||||
bool invalid_index = true;
|
bool invalid_index = true;
|
||||||
|
@ -179,37 +181,30 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
|
||||||
|
|
||||||
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
|
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
|
||||||
|
|
||||||
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), index);
|
if (eval == true) {
|
||||||
if (link != NULL) {
|
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), index);
|
||||||
switch (link->type) {
|
if (link != NULL) {
|
||||||
case ZATHURA_LINK_TO_PAGE:
|
switch (link->type) {
|
||||||
page_set_delayed(zathura, link->target.page_number);
|
case ZATHURA_LINK_TO_PAGE:
|
||||||
break;
|
page_set_delayed(zathura, link->target.page_number);
|
||||||
case ZATHURA_LINK_EXTERNAL:
|
break;
|
||||||
girara_xdg_open(link->target.value);
|
case ZATHURA_LINK_EXTERNAL:
|
||||||
break;
|
girara_xdg_open(link->target.value);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
invalid_index = false;
|
invalid_index = false;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalid_index == true) {
|
if (eval == true && invalid_index == true) {
|
||||||
girara_notify(session, GIRARA_WARNING, "Invalid index '%s' given.", input);
|
girara_notify(session, GIRARA_WARNING, "Invalid index '%s' given.", input);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(input);
|
g_free(input);
|
||||||
|
|
||||||
return TRUE;
|
return (eval == TRUE) ? TRUE : FALSE;
|
||||||
|
|
||||||
error_free:
|
|
||||||
|
|
||||||
g_free(input);
|
|
||||||
|
|
||||||
error_ret:
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -121,6 +121,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set pages to draw links */
|
/* set pages to draw links */
|
||||||
|
bool show_links = false;
|
||||||
unsigned int page_offset = 0;
|
unsigned int page_offset = 0;
|
||||||
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
|
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
|
||||||
zathura_page_t* page = zathura->document->pages[page_id];
|
zathura_page_t* page = zathura->document->pages[page_id];
|
||||||
|
@ -134,6 +135,9 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||||
|
|
||||||
int number_of_links = 0;
|
int number_of_links = 0;
|
||||||
g_object_get(page->drawing_area, "number-of-links", &number_of_links, NULL);
|
g_object_get(page->drawing_area, "number-of-links", &number_of_links, NULL);
|
||||||
|
if (number_of_links != 0) {
|
||||||
|
show_links = true;
|
||||||
|
}
|
||||||
g_object_set(page->drawing_area, "offset-links", page_offset, NULL);
|
g_object_set(page->drawing_area, "offset-links", page_offset, NULL);
|
||||||
page_offset += number_of_links;
|
page_offset += number_of_links;
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,7 +146,9 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ask for input */
|
/* ask for input */
|
||||||
girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow);
|
if (show_links == true) {
|
||||||
|
girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue