mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 05:56:01 +01:00
Update sc_reload behaviour
This commit is contained in:
parent
959fdb56d3
commit
59a6c7c560
1 changed files with 98 additions and 111 deletions
209
zathura.c
209
zathura.c
|
@ -228,7 +228,6 @@ struct
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
GFileMonitor* monitor;
|
GFileMonitor* monitor;
|
||||||
GFile* file;
|
|
||||||
} FileMonitor;
|
} FileMonitor;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -290,6 +289,7 @@ void add_marker(int);
|
||||||
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
|
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
|
||||||
void change_mode(int);
|
void change_mode(int);
|
||||||
void calculate_offset(GtkWidget*, double*, double*);
|
void calculate_offset(GtkWidget*, double*, double*);
|
||||||
|
void close_file(gboolean);
|
||||||
void enter_password();
|
void enter_password();
|
||||||
void highlight_result(int, PopplerRectangle*);
|
void highlight_result(int, PopplerRectangle*);
|
||||||
void draw(int);
|
void draw(int);
|
||||||
|
@ -471,7 +471,6 @@ init_zathura()
|
||||||
Zathura.Search.draw = FALSE;
|
Zathura.Search.draw = FALSE;
|
||||||
|
|
||||||
Zathura.FileMonitor.monitor = NULL;
|
Zathura.FileMonitor.monitor = NULL;
|
||||||
Zathura.FileMonitor.file = NULL;
|
|
||||||
|
|
||||||
/* UI */
|
/* UI */
|
||||||
Zathura.UI.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
|
Zathura.UI.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
|
||||||
|
@ -822,6 +821,96 @@ calculate_offset(GtkWidget* widget, double* offset_x, double* offset_y)
|
||||||
*offset_y = 0;
|
*offset_y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
close_file(gboolean keep_monitor)
|
||||||
|
{
|
||||||
|
if(!Zathura.PDF.document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* clean up pages */
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < Zathura.PDF.number_of_pages; i++)
|
||||||
|
{
|
||||||
|
Page* current_page = Zathura.PDF.pages[i];
|
||||||
|
g_object_unref(current_page->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* save bookmarks */
|
||||||
|
if(Zathura.Bookmarks.data)
|
||||||
|
{
|
||||||
|
/* set current page */
|
||||||
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
||||||
|
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
||||||
|
|
||||||
|
/* set page offset */
|
||||||
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
||||||
|
BM_PAGE_OFFSET, Zathura.PDF.page_offset);
|
||||||
|
|
||||||
|
/* save bookmarks */
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
||||||
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
||||||
|
Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page);
|
||||||
|
|
||||||
|
/* convert file and save it */
|
||||||
|
gchar* bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL);
|
||||||
|
g_file_set_contents(Zathura.Bookmarks.file, bookmarks, -1, NULL);
|
||||||
|
g_free(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* inotify */
|
||||||
|
if(!keep_monitor)
|
||||||
|
{
|
||||||
|
g_object_unref(Zathura.FileMonitor.monitor);
|
||||||
|
Zathura.FileMonitor.monitor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reset values */
|
||||||
|
free(Zathura.PDF.pages);
|
||||||
|
g_object_unref(Zathura.PDF.document);
|
||||||
|
g_free(Zathura.State.pages);
|
||||||
|
gtk_window_set_title(Zathura.UI.window, "zathura");
|
||||||
|
|
||||||
|
Zathura.State.pages = g_strdup_printf("");
|
||||||
|
Zathura.State.filename = (char*) DEFAULT_TEXT;
|
||||||
|
|
||||||
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
Zathura.PDF.document = NULL;
|
||||||
|
if(!keep_monitor)
|
||||||
|
{
|
||||||
|
Zathura.PDF.file = NULL;
|
||||||
|
Zathura.PDF.password = NULL;
|
||||||
|
Zathura.PDF.page_number = 0;
|
||||||
|
Zathura.PDF.scale = 0;
|
||||||
|
Zathura.PDF.rotate = 0;
|
||||||
|
}
|
||||||
|
Zathura.PDF.number_of_pages = 0;
|
||||||
|
Zathura.PDF.page_offset = 0;
|
||||||
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
|
||||||
|
/* destroy index */
|
||||||
|
if(Zathura.UI.index)
|
||||||
|
{
|
||||||
|
gtk_widget_destroy(Zathura.UI.index);
|
||||||
|
Zathura.UI.index = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* destroy information */
|
||||||
|
if(Zathura.UI.information)
|
||||||
|
{
|
||||||
|
gtk_widget_destroy(Zathura.UI.information);
|
||||||
|
Zathura.UI.information = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free markers */
|
||||||
|
if(Zathura.Marker.markers)
|
||||||
|
free(Zathura.Marker.markers);
|
||||||
|
Zathura.Marker.number_of_markers = 0;
|
||||||
|
Zathura.Marker.last = -1;
|
||||||
|
|
||||||
|
update_status();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
enter_password()
|
enter_password()
|
||||||
{
|
{
|
||||||
|
@ -937,7 +1026,7 @@ open_file(char* path, char* password)
|
||||||
|
|
||||||
/* close old file */
|
/* close old file */
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
cmd_close(-1, NULL);
|
close_file(FALSE);
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
|
||||||
/* format path */
|
/* format path */
|
||||||
|
@ -985,7 +1074,7 @@ open_file(char* path, char* password)
|
||||||
Zathura.PDF.password = password;
|
Zathura.PDF.password = password;
|
||||||
|
|
||||||
/* inotify */
|
/* inotify */
|
||||||
if(!Zathura.FileMonitor.monitor || !Zathura.FileMonitor.file)
|
if(!Zathura.FileMonitor.monitor)
|
||||||
{
|
{
|
||||||
GFile* file = g_file_new_for_uri(file_uri);
|
GFile* file = g_file_new_for_uri(file_uri);
|
||||||
|
|
||||||
|
@ -1077,6 +1166,7 @@ open_file(char* path, char* password)
|
||||||
update_status();
|
update_status();
|
||||||
|
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
isc_abort(NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1551,27 +1641,7 @@ sc_recolor(Argument* argument)
|
||||||
void
|
void
|
||||||
sc_reload(Argument* argument)
|
sc_reload(Argument* argument)
|
||||||
{
|
{
|
||||||
if(!Zathura.PDF.document)
|
draw(Zathura.PDF.page_number);
|
||||||
return;
|
|
||||||
|
|
||||||
/* check if file is damaged */
|
|
||||||
char* file_uri = g_filename_to_uri(Zathura.PDF.file, NULL, NULL);
|
|
||||||
if(file_uri)
|
|
||||||
{
|
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
|
||||||
PopplerDocument* temporary_document = NULL;
|
|
||||||
if(!(temporary_document = poppler_document_new_from_file(file_uri, Zathura.PDF.password, NULL)))
|
|
||||||
{
|
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
||||||
g_free(file_uri);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_free(file_uri);
|
|
||||||
|
|
||||||
/* save old information */
|
/* save old information */
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
@ -1583,7 +1653,7 @@ sc_reload(Argument* argument)
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
|
|
||||||
/* reopen and restore settings */
|
/* reopen and restore settings */
|
||||||
cmd_close(0, NULL);
|
close_file(TRUE);
|
||||||
open_file(path, password);
|
open_file(path, password);
|
||||||
|
|
||||||
Zathura.PDF.scale = scale;
|
Zathura.PDF.scale = scale;
|
||||||
|
@ -2323,90 +2393,7 @@ cmd_open_bookmark(int argc, char** argv)
|
||||||
gboolean
|
gboolean
|
||||||
cmd_close(int argc, char** argv)
|
cmd_close(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if(!Zathura.PDF.document)
|
close_file(FALSE);
|
||||||
{
|
|
||||||
if(argc != -1)
|
|
||||||
notify(ERROR, "No file has been opened");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clean up pages */
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < Zathura.PDF.number_of_pages; i++)
|
|
||||||
{
|
|
||||||
Page* current_page = Zathura.PDF.pages[i];
|
|
||||||
g_object_unref(current_page->page);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save bookmarks */
|
|
||||||
if(Zathura.Bookmarks.data)
|
|
||||||
{
|
|
||||||
/* set current page */
|
|
||||||
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
||||||
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
|
||||||
|
|
||||||
/* set page offset */
|
|
||||||
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
||||||
BM_PAGE_OFFSET, Zathura.PDF.page_offset);
|
|
||||||
|
|
||||||
/* save bookmarks */
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
||||||
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
||||||
Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page);
|
|
||||||
|
|
||||||
/* convert file and save it */
|
|
||||||
gchar* bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL);
|
|
||||||
g_file_set_contents(Zathura.Bookmarks.file, bookmarks, -1, NULL);
|
|
||||||
g_free(bookmarks);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* inotify */
|
|
||||||
g_object_unref(Zathura.FileMonitor.monitor);
|
|
||||||
Zathura.FileMonitor.monitor = NULL;
|
|
||||||
|
|
||||||
/* reset values */
|
|
||||||
free(Zathura.PDF.pages);
|
|
||||||
g_object_unref(Zathura.PDF.document);
|
|
||||||
g_free(Zathura.State.pages);
|
|
||||||
gtk_window_set_title(Zathura.UI.window, "zathura");
|
|
||||||
|
|
||||||
Zathura.State.pages = g_strdup_printf("");
|
|
||||||
Zathura.State.filename = (char*) DEFAULT_TEXT;
|
|
||||||
|
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
|
||||||
Zathura.PDF.document = NULL;
|
|
||||||
Zathura.PDF.file = NULL;
|
|
||||||
Zathura.PDF.password = NULL;
|
|
||||||
Zathura.PDF.page_number = 0;
|
|
||||||
Zathura.PDF.number_of_pages = 0;
|
|
||||||
Zathura.PDF.scale = 0;
|
|
||||||
Zathura.PDF.rotate = 0;
|
|
||||||
Zathura.PDF.page_offset = 0;
|
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
||||||
|
|
||||||
/* destroy index */
|
|
||||||
if(Zathura.UI.index)
|
|
||||||
{
|
|
||||||
gtk_widget_destroy(Zathura.UI.index);
|
|
||||||
Zathura.UI.index = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* destroy information */
|
|
||||||
if(Zathura.UI.information)
|
|
||||||
{
|
|
||||||
gtk_widget_destroy(Zathura.UI.information);
|
|
||||||
Zathura.UI.information = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* free markers */
|
|
||||||
if(Zathura.Marker.markers)
|
|
||||||
free(Zathura.Marker.markers);
|
|
||||||
Zathura.Marker.number_of_markers = 0;
|
|
||||||
Zathura.Marker.last = -1;
|
|
||||||
|
|
||||||
update_status();
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3174,7 +3161,7 @@ cb_destroy(GtkWidget* widget, gpointer data)
|
||||||
pango_font_description_free(Zathura.Style.font);
|
pango_font_description_free(Zathura.Style.font);
|
||||||
|
|
||||||
if(Zathura.PDF.document)
|
if(Zathura.PDF.document)
|
||||||
cmd_close(0, NULL);
|
close_file(FALSE);
|
||||||
|
|
||||||
/* clean up other variables */
|
/* clean up other variables */
|
||||||
g_free(Zathura.Bookmarks.file);
|
g_free(Zathura.Bookmarks.file);
|
||||||
|
|
Loading…
Reference in a new issue