Skip to content

Commit

Permalink
Added GFileMonitor handling on file save/save-as.
Browse files Browse the repository at this point in the history
  • Loading branch information
David C. Rankin committed Jul 8, 2017
1 parent 07eca96 commit dcc27a8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $(APPNAME): $(OBJECTS)

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) $(DEFS) -c -o $@ $<

# $(OBJDIR)/gtk_common_dlg.o : gtk_common_dlg.h
# $(OBJDIR)/gtk_findreplace.o : gtk_findreplace.h
Expand Down
2 changes: 1 addition & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ copy/paste

file/buffer

* add monitor of current file for modification by foreign process. Implement GFileMonitor.
* complete

menu/toolbar

Expand Down
2 changes: 1 addition & 1 deletion gtk_appdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define HAVEMSWIN 1
#endif

#define VER "0.1.3"
#define VER "0.1.4"
#define SITE "https://www.rankinlawfirm.com"
#define LICENSE "gpl-2.0.txt"
#define CFGDIR "gtkwrite"
Expand Down
25 changes: 13 additions & 12 deletions gtk_filebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,19 @@ void buffer_handle_quit (kwinst *app)
cancel_save:;
}

/** buffer_save_file in new 'filename' or in existing if NULL.
* if 'filename' is provided, Save-As 'filename', otherwise if
* 'filename' is NULL, Save in existing app->filename or prompt
* with file_save dialog. cancel and add file monitoring as
* required. save file stats for existing file, update status.
* if HAVESOURCEVIEW, guess language syntax.
*/
void buffer_save_file (kwinst *app, gchar *filename)
{
if (filename) { /* file_save_as new filename */
if (app->filename) { /* if existing file, free */
if (filename) { /* file_save_as new filename */
if (app->filename) { /* if existing file, free filename */
app_free_filename (app);
if (!file_monitor_cancel (app))
if (!file_monitor_cancel (app)) /* cancel existing monitor */
{ /* handle error */ }
}
app->filename = filename; /* assign to app->filename */
Expand All @@ -558,8 +565,6 @@ void buffer_save_file (kwinst *app, gchar *filename)
"Do you want to cancel save?",
"Warning - Save Canceled", FALSE))
return;
//err_dialog ("error: filename not set/invalid!\nfile not saved.");
// return;
}
split_fname (app);
}
Expand All @@ -570,20 +575,16 @@ void buffer_save_file (kwinst *app, gchar *filename)

buffer_write_file (app, filename); /* write to file app->filename */

if (filename) { /* saving under new name */
if (app->mfp_handler) /* if existing monitor */
if (!file_monitor_cancel (app)) /* cancel exising watch */
{ /* handle error */ }
if (!app->mfp_handler) /* if not monitoring file */
file_monitor_add (app); /* setup monitoring on new name */
}

file_get_stats (app->filename, app); /* check/save file stats */

status_set_default (app); /* restore statusbar */

#ifdef HAVESOURCEVIEW
if (app->highlight)
sourceview_guess_language (app);
if (app->highlight) /* if syntax highlight enabled */
sourceview_guess_language (app); /* guess source language */
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion gtk_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void menu_file_new_activate (GtkMenuItem *menuitem, kwinst *app)

void menu_file_open_activate (GtkMenuItem *menuitem, kwinst *app)
{
/* get new filename and buffer character count */
/* get new filename */
gchar *newfile = get_open_filename (app);

/* open newfile in current or new editor instance */
Expand Down

0 comments on commit dcc27a8

Please sign in to comment.