Update sc_follow

This commit is contained in:
Moritz Lipp 2012-02-08 00:19:35 +01:00
parent eb26be7e75
commit 9d87451389
2 changed files with 33 additions and 32 deletions

View file

@ -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 (eval == true) {
index = atoi(input);
if (index == 0 && g_strcmp0(input, "0") != 0) { if (index == 0 && g_strcmp0(input, "0") != 0) {
girara_notify(session, GIRARA_WARNING, "Invalid input '%s' given.", input); girara_notify(session, GIRARA_WARNING, "Invalid input '%s' given.", input);
goto error_free; 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,6 +181,7 @@ 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);
if (eval == true) {
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), index); zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), index);
if (link != NULL) { if (link != NULL) {
switch (link->type) { switch (link->type) {
@ -191,25 +194,17 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
} }
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

View file

@ -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 */
if (show_links == true) {
girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow); girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow);
}
return false; return false;
} }