Commit 7991618d authored by Sidharth Kapur's avatar Sidharth Kapur
Browse files

Implement tilde feature for statusbar as well

parent 1be84c6c
...@@ -863,6 +863,13 @@ Use basename of the file in the window title. ...@@ -863,6 +863,13 @@ Use basename of the file in the window title.
* Value type: Boolean * Value type: Boolean
* Default value: false * 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 window-title-page
^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
Display the page number in the window title. Display the page number in the window title.
...@@ -877,6 +884,13 @@ Use basename of the file in the statusbar. ...@@ -877,6 +884,13 @@ Use basename of the file in the statusbar.
* Value type: Boolean * Value type: Boolean
* Default value: false * 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 zoom-center
^^^^^^^^^^^ ^^^^^^^^^^^
En/Disables horizontally centered zooming. En/Disables horizontally centered zooming.
...@@ -965,13 +979,6 @@ Define the background color of the selected element in index mode. ...@@ -965,13 +979,6 @@ Define the background color of the selected element in index mode.
* Value type: String * Value type: String
* Default value: #9FBC00 * Default value: #9FBC00
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
SEE ALSO SEE ALSO
......
...@@ -229,6 +229,8 @@ config_load_default(zathura_t* zathura) ...@@ -229,6 +229,8 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL); girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
bool_value = false; bool_value = false;
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL); 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; bool_value = true;
girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL); girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
string_value = ""; string_value = "";
......
...@@ -547,13 +547,24 @@ document_info_open(gpointer data) ...@@ -547,13 +547,24 @@ document_info_open(gpointer data)
} }
const char* const char*
get_window_title_filename(zathura_t* zathura, const char* file_path) get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar)
{ {
bool basename_only = false; bool basename_only = false;
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only); 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) { if (basename_only == false) {
bool home_tilde = false; bool home_tilde = false;
girara_setting_get(zathura->ui.session, "window-title-home-tilde", &home_tilde); 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);
}
if (home_tilde) { if (home_tilde) {
char *home = getenv("HOME"); char *home = getenv("HOME");
size_t home_len = home ? strlen(home) : 0; size_t home_len = home ? strlen(home) : 0;
...@@ -697,13 +708,8 @@ document_open(zathura_t* zathura, const char* path, const char* password, ...@@ -697,13 +708,8 @@ document_open(zathura_t* zathura, const char* path, const char* password,
zathura->bisect.end = number_of_pages - 1; zathura->bisect.end = number_of_pages - 1;
/* update statusbar */ /* update statusbar */
bool basename_only = false; girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file,
girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only); get_formatted_filename(zathura, file_path, true));
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));
}
/* install file monitor */ /* install file monitor */
file_uri = g_filename_to_uri(file_path, NULL, NULL); file_uri = g_filename_to_uri(file_path, NULL, NULL);
...@@ -870,7 +876,7 @@ document_open(zathura_t* zathura, const char* path, const char* password, ...@@ -870,7 +876,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
} }
/* update title */ /* update title */
girara_set_window_title(zathura->ui.session, get_window_title_filename(zathura, file_path)); girara_set_window_title(zathura->ui.session, get_formatted_filename(zathura, file_path, false));
g_free(file_uri); g_free(file_uri);
...@@ -1123,7 +1129,7 @@ statusbar_page_number_update(zathura_t* zathura) ...@@ -1123,7 +1129,7 @@ statusbar_page_number_update(zathura_t* zathura)
if (page_number_in_window_title == true) { if (page_number_in_window_title == true) {
char* title = g_strdup_printf("%s %s", char* title = g_strdup_printf("%s %s",
get_window_title_filename(zathura, zathura_document_get_path(zathura->document)), get_formatted_filename(zathura, zathura_document_get_path(zathura->document), false),
page_number_text); page_number_text);
girara_set_window_title(zathura->ui.session, title); girara_set_window_title(zathura->ui.session, title);
g_free(title); g_free(title);
......
...@@ -278,7 +278,15 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir); ...@@ -278,7 +278,15 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir);
*/ */
void zathura_set_argv(zathura_t* zathura, char** argv); void zathura_set_argv(zathura_t* zathura, char** argv);
const char* get_window_title_filename(zathura_t* zathura, const char* file_path); /**
* 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
*/
const char* get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar);
/** /**
* Opens a file * Opens a file
......
Supports Markdown
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