mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-29 00:34:55 +01:00
Implement ZATHURA_LINK_GOTO_REMOTE
This commit is contained in:
parent
ef99076a48
commit
a86940b3f4
5 changed files with 40 additions and 0 deletions
1
types.c
1
types.c
|
@ -20,6 +20,7 @@ zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position,
|
|||
case ZATHURA_LINK_GOTO_DEST:
|
||||
link->target.page_number = target.page_number;
|
||||
break;
|
||||
case ZATHURA_LINK_GOTO_REMOTE:
|
||||
case ZATHURA_LINK_URI:
|
||||
if (target.value == NULL) {
|
||||
g_free(link);
|
||||
|
|
26
utils.c
26
utils.c
|
@ -338,6 +338,9 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
|
|||
case ZATHURA_LINK_GOTO_DEST:
|
||||
page_set_delayed(zathura, link->target.page_number);
|
||||
break;
|
||||
case ZATHURA_LINK_GOTO_REMOTE:
|
||||
open_remote(zathura, link->target.value);
|
||||
break;
|
||||
case ZATHURA_LINK_URI:
|
||||
if (girara_xdg_open(link->target.value) == false) {
|
||||
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
|
||||
|
@ -347,3 +350,26 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
open_remote(zathura_t* zathura, const char* file)
|
||||
{
|
||||
if (zathura == NULL || file == NULL || zathura->document == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* path = zathura_document_get_path(zathura->document);
|
||||
char* dir = g_path_get_dirname(path);
|
||||
char* uri = g_build_filename(dir, file, NULL);
|
||||
|
||||
char* argv[] = {
|
||||
*(zathura->global.arguments),
|
||||
uri,
|
||||
NULL
|
||||
};
|
||||
|
||||
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||
|
||||
g_free(uri);
|
||||
g_free(dir);
|
||||
}
|
||||
|
|
11
utils.h
11
utils.h
|
@ -130,4 +130,15 @@ void readjust_view_after_zooming(zathura_t* zathura, float old_zoom);
|
|||
*/
|
||||
void zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link);
|
||||
|
||||
/**
|
||||
* Opens a remote file
|
||||
*
|
||||
* Determines the path of the current document and tries to open a given file
|
||||
* in that path
|
||||
*
|
||||
* @param zathura Zathura instance
|
||||
* @param file File name
|
||||
*/
|
||||
void open_remote(zathura_t* zathura, const char* file);
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
|
@ -169,6 +169,7 @@ zathura_init(int argc, char* argv[])
|
|||
/* global settings */
|
||||
zathura->global.recolor = false;
|
||||
zathura->global.update_page_number = true;
|
||||
zathura->global.arguments = argv;
|
||||
|
||||
/* load plugins */
|
||||
zathura_plugin_manager_load(zathura->plugins.manager);
|
||||
|
|
|
@ -77,6 +77,7 @@ struct zathura_s
|
|||
bool recolor; /**< Recoloring mode switch */
|
||||
bool update_page_number; /**< Update current page number */
|
||||
girara_list_t* marks; /**< Marker */
|
||||
char** arguments; /**> Arguments that were passed at startup */
|
||||
} global;
|
||||
|
||||
struct
|
||||
|
|
Loading…
Reference in a new issue