Skip to content

Commit

Permalink
infobars: Do not show reload and resave messages more than once since…
Browse files Browse the repository at this point in the history
… only the

last one (respectively) is significant to the user.
  • Loading branch information
kugel- committed May 24, 2014
1 parent 5117940 commit b487d8d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
52 changes: 36 additions & 16 deletions src/document.c
Expand Up @@ -3148,23 +3148,31 @@ static void on_monitor_reload_file_response(GtkWidget *bar, gint response_id, Ge

if (response_id == GTK_RESPONSE_ACCEPT)
document_reload_file(doc, doc->encoding);

doc->priv->info_bars[MSG_TYPE_RELOAD] = NULL;
}


static void monitor_reload_file(GeanyDocument *doc)
{
gchar *base_name = g_path_get_basename(doc->file_name);

document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response,
_("_Reload"), GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL, GTK_RESPONSE_NONE,
_("Do you want to reload it?"),
_("The file '%s' on the disk is more recent than the current buffer."),
base_name);
/* show this message only once */
if (doc->priv->info_bars[MSG_TYPE_RELOAD] == NULL)
{
GtkWidget *bar;

protect_document(doc);
bar = document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response,
_("_Reload"), GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL, GTK_RESPONSE_NONE,
_("Do you want to reload it?"),
_("The file '%s' on the disk is more recent than the current buffer."),
base_name);

protect_document(doc);
doc->priv->info_bars[MSG_TYPE_RELOAD] = bar;
}
g_free(base_name);
}

Expand All @@ -3186,20 +3194,31 @@ static void on_monitor_resave_missing_file_response(GtkWidget *bar,
/* don't prompt more than once */
SETPTR(doc->real_path, NULL);
}

doc->priv->info_bars[MSG_TYPE_RESAVE] = NULL;
}


static void monitor_resave_missing_file(GeanyDocument *doc)
{
document_show_message(doc, GTK_MESSAGE_WARNING, on_monitor_resave_missing_file_response,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL, GTK_RESPONSE_NONE,
_("Try to resave the file?"),
_("File \"%s\" was not found on disk!"),
doc->file_name);
GtkWidget *bar;

protect_document(doc);
if (doc->priv->info_bars[MSG_TYPE_RESAVE] == NULL)
{
GtkWidget *bar;

bar = document_show_message(doc, GTK_MESSAGE_WARNING,
on_monitor_resave_missing_file_response,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL, GTK_RESPONSE_NONE,
_("Try to resave the file?"),
_("File \"%s\" was not found on disk!"),
doc->file_name);

protect_document(doc);
doc->priv->info_bars[MSG_TYPE_RESAVE] = bar;
}
}


Expand Down Expand Up @@ -3253,6 +3272,7 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
}
else if (doc->priv->mtime < st.st_mtime)
{
/* make sure the user is not prompted again after he cancelled the "reload file?" message */
doc->priv->mtime = st.st_mtime;
monitor_reload_file(doc);
/* doc may be closed now */
Expand Down
9 changes: 9 additions & 0 deletions src/documentprivate.h
Expand Up @@ -53,6 +53,13 @@ typedef struct FileEncoding
}
FileEncoding;

enum
{
MSG_TYPE_RELOAD,
MSG_TYPE_RESAVE,

NUM_MSG_TYPES
};

/* Private GeanyDocument fields */
typedef struct GeanyDocumentPrivate
Expand Down Expand Up @@ -89,6 +96,8 @@ typedef struct GeanyDocumentPrivate
/* Whether it's temoporarily protected (read-only and saving is prevented). Does
* not imply doc->readonly as writable files can be protected */
gint protected;
/* Save pointer to info bars allowing to cancel them programatically (to avoid multiple ones) */
GtkWidget *info_bars[NUM_MSG_TYPES];
}
GeanyDocumentPrivate;

Expand Down

0 comments on commit b487d8d

Please sign in to comment.