mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 23:43:46 +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
fb0b700c9e
commit
4bf5718349
50
zathura.c
50
zathura.c
@ -371,6 +371,7 @@ gboolean open_stdin(gchar*);
|
||||
void open_uri(char*);
|
||||
void out_of_memory(void) NORETURN;
|
||||
void update_status(void);
|
||||
void read_bookmarks_file(void);
|
||||
void read_configuration_file(const char*);
|
||||
void read_configuration(void);
|
||||
void recalcRectangle(int, PopplerRectangle*);
|
||||
@ -613,26 +614,8 @@ init_bookmarks(void)
|
||||
Zathura.Bookmarks.number_of_bookmarks = 0;
|
||||
Zathura.Bookmarks.bookmarks = NULL;
|
||||
|
||||
/* create or open existing bookmark file */
|
||||
Zathura.Bookmarks.data = g_key_file_new();
|
||||
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;
|
||||
Zathura.Bookmarks.file = g_build_filename(Zathura.Config.data_dir, BOOKMARK_FILE, NULL);
|
||||
read_bookmarks_file();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1058,6 +1041,8 @@ close_file(gboolean keep_monitor)
|
||||
/* save bookmarks */
|
||||
if(Zathura.Bookmarks.data)
|
||||
{
|
||||
read_bookmarks_file();
|
||||
|
||||
/* set current page */
|
||||
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
||||
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
||||
@ -1529,6 +1514,31 @@ update_status(void)
|
||||
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
|
||||
read_configuration_file(const char* rcfile)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user