mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-07 14:15:59 +01:00
Reread bookmarks file before writing (closes #74)
Applying patch from Minoru with some simple adapations. Therefor read_bookmarks_file doesn't leak (bookmarks is never freed).
This commit is contained in:
parent
2ce5b54c71
commit
af61d097ed
1 changed files with 30 additions and 20 deletions
50
zathura.c
50
zathura.c
|
@ -371,6 +371,7 @@ gboolean open_stdin(gchar*);
|
||||||
void open_uri(char*);
|
void open_uri(char*);
|
||||||
void out_of_memory(void) NORETURN;
|
void out_of_memory(void) NORETURN;
|
||||||
void update_status(void);
|
void update_status(void);
|
||||||
|
void read_bookmarks_file(void);
|
||||||
void read_configuration_file(const char*);
|
void read_configuration_file(const char*);
|
||||||
void read_configuration(void);
|
void read_configuration(void);
|
||||||
void recalcRectangle(int, PopplerRectangle*);
|
void recalcRectangle(int, PopplerRectangle*);
|
||||||
|
@ -613,26 +614,8 @@ init_bookmarks(void)
|
||||||
Zathura.Bookmarks.number_of_bookmarks = 0;
|
Zathura.Bookmarks.number_of_bookmarks = 0;
|
||||||
Zathura.Bookmarks.bookmarks = NULL;
|
Zathura.Bookmarks.bookmarks = NULL;
|
||||||
|
|
||||||
/* create or open existing bookmark file */
|
Zathura.Bookmarks.file = g_build_filename(Zathura.Config.data_dir, BOOKMARK_FILE, NULL);
|
||||||
Zathura.Bookmarks.data = g_key_file_new();
|
read_bookmarks_file();
|
||||||
gchar* bookmarks = g_build_filename(Zathura.Config.data_dir, BOOKMARK_FILE, NULL);
|
|
||||||
|
|
||||||
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
|
|
||||||
{
|
|
||||||
/* file does not exist */
|
|
||||||
g_file_set_contents(bookmarks, "# Zathura bookmarks\n", -1, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
GError* error = NULL;
|
|
||||||
if(!g_key_file_load_from_file(Zathura.Bookmarks.data, bookmarks,
|
|
||||||
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error))
|
|
||||||
{
|
|
||||||
gchar* message = g_strdup_printf("Could not load bookmark file: %s", error->message);
|
|
||||||
notify(ERROR, message);
|
|
||||||
g_free(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Zathura.Bookmarks.file = bookmarks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1058,6 +1041,8 @@ close_file(gboolean keep_monitor)
|
||||||
/* save bookmarks */
|
/* save bookmarks */
|
||||||
if(Zathura.Bookmarks.data)
|
if(Zathura.Bookmarks.data)
|
||||||
{
|
{
|
||||||
|
read_bookmarks_file();
|
||||||
|
|
||||||
/* set current page */
|
/* set current page */
|
||||||
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
||||||
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
||||||
|
@ -1529,6 +1514,31 @@ update_status(void)
|
||||||
g_free(zoom_level);
|
g_free(zoom_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
read_bookmarks_file(void)
|
||||||
|
{
|
||||||
|
/* free it at first */
|
||||||
|
if (Zathura.Bookmarks.data)
|
||||||
|
g_key_file_free(Zathura.Bookmarks.data);
|
||||||
|
|
||||||
|
/* create or open existing bookmark file */
|
||||||
|
Zathura.Bookmarks.data = g_key_file_new();
|
||||||
|
if(!g_file_test(Zathura.Bookmarks.file, G_FILE_TEST_IS_REGULAR))
|
||||||
|
{
|
||||||
|
/* file does not exist */
|
||||||
|
g_file_set_contents(Zathura.Bookmarks.file, "# Zathura bookmarks\n", -1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
GError* error = NULL;
|
||||||
|
if(!g_key_file_load_from_file(Zathura.Bookmarks.data, Zathura.Bookmarks.file,
|
||||||
|
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error))
|
||||||
|
{
|
||||||
|
gchar* message = g_strdup_printf("Could not load bookmark file: %s", error->message);
|
||||||
|
notify(ERROR, message);
|
||||||
|
g_free(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
read_configuration_file(const char* rcfile)
|
read_configuration_file(const char* rcfile)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue