Commit 075924d1 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Merge remote-tracking branch 'sid-kap/substitute_home_with_tilde' into develop

parents 5ca5264d 2b73bfb6
......@@ -887,6 +887,13 @@ Use basename of the file in the window title.
* Value type: Boolean
* Default value: false
window-title-home-tilde
^^^^^^^^^^^^^^^^^^^^^^^
Display a short version of the file path, which replaces $HOME with ~, in the window title.
* Value type: Boolean
* Default value: false
window-title-page
^^^^^^^^^^^^^^^^^
Display the page number in the window title.
......@@ -901,6 +908,13 @@ Use basename of the file in the statusbar.
* Value type: Boolean
* Default value: false
statusbar-home-tilde
^^^^^^^^^^^^^^^^^^^^
Display a short version of the file path, which replaces $HOME with ~, in the statusbar.
* Value type: Boolean
* Default value: false
zoom-center
^^^^^^^^^^^
En/Disables horizontally centered zooming.
......
......@@ -226,9 +226,13 @@ config_load_default(zathura_t* zathura)
bool_value = false;
girara_setting_add(gsession, "window-title-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the window title"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "window-title-home-tilde", &bool_value, BOOLEAN, false, _("Use ~ instead of $HOME in the filename in the window title"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "statusbar-home-tilde", &bool_value, BOOLEAN, false, _("Use ~ instead of $HOME in the filename in the statusbar"), NULL, NULL);
bool_value = true;
girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
string_value = "";
......
......@@ -546,6 +546,55 @@ document_info_open(gpointer data)
return FALSE;
}
char*
get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar)
{
bool basename_only = false;
if (statusbar) {
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
} else {
girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only);
}
if (basename_only == false) {
bool home_tilde = false;
if (statusbar) {
girara_setting_get(zathura->ui.session, "statusbar-home-tilde", &home_tilde);
} else {
girara_setting_get(zathura->ui.session, "window-title-home-tilde", &home_tilde);
}
size_t file_path_len = file_path ? strlen(file_path) : 0;
if (home_tilde) {
char *home = girara_get_home_directory(NULL);
size_t home_len = home ? strlen(home) : 0;
if (home_len > 1
&& file_path_len >= home_len
&& g_str_has_prefix(file_path, home)
&& (!file_path[home_len] || file_path[home_len] == '/')) {
size_t remaining_len = file_path_len - home_len;
GString* remaining_path = g_string_new_len(&file_path[home_len], remaining_len);
char* tilde_path = g_strdup_printf("~%s", remaining_path->str);
g_string_free(remaining_path, true);
return tilde_path;
} else {
return g_strdup(file_path);
}
} else {
return g_strdup(file_path);
}
} else {
const char* basename = zathura_document_get_basename(zathura->document);
return g_strdup(basename);
}
}
bool
document_open(zathura_t* zathura, const char* path, const char* password,
int page_number)
......@@ -665,13 +714,9 @@ document_open(zathura_t* zathura, const char* path, const char* password,
zathura->bisect.end = number_of_pages - 1;
/* update statusbar */
bool basename_only = false;
girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only);
if (basename_only == false) {
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, file_path);
} else {
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, zathura_document_get_basename(document));
}
char* filename = get_formatted_filename(zathura, file_path, true);
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, filename);
g_free(filename);
/* install file monitor */
file_uri = g_filename_to_uri(file_path, NULL, NULL);
......@@ -838,13 +883,9 @@ document_open(zathura_t* zathura, const char* path, const char* password,
}
/* update title */
basename_only = false;
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
if (basename_only == false) {
girara_set_window_title(zathura->ui.session, file_path);
} else {
girara_set_window_title(zathura->ui.session, zathura_document_get_basename(document));
}
char* formatted_filename = get_formatted_filename(zathura, file_path, false);
girara_set_window_title(zathura->ui.session, formatted_filename);
g_free(formatted_filename);
g_free(file_uri);
......@@ -1096,15 +1137,11 @@ statusbar_page_number_update(zathura_t* zathura)
girara_setting_get(zathura->ui.session, "window-title-page", &page_number_in_window_title);
if (page_number_in_window_title == true) {
bool basename_only = false;
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
char* title = g_strdup_printf("%s %s",
(basename_only == true)
? zathura_document_get_basename(zathura->document)
: zathura_document_get_path(zathura->document),
page_number_text);
char* filename = get_formatted_filename(zathura, zathura_document_get_path(zathura->document), false);
char* title = g_strdup_printf("%s %s", filename, page_number_text);
girara_set_window_title(zathura->ui.session, title);
g_free(title);
g_free(filename);
}
g_free(page_number_text);
......
......@@ -278,6 +278,16 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir);
*/
void zathura_set_argv(zathura_t* zathura, char** argv);
/**
* Returns the filename formatted according to the user config.
* Takes into account the basename setting and the home-tilde setting.
*
* @param zatura The zathura session
* @param file_path The filename to be formatted
* @param statusbar True if for statusbar, false if for window title
*/
char* get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar);
/**
* Opens a file
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment