Small code cleanup

Use foreach_document() in a few places where appropriate and make
some code more consistent.
This commit is contained in:
Colomban Wendling 2011-11-02 00:04:35 +01:00
parent c39390aae8
commit 0167f589b3
6 changed files with 15 additions and 23 deletions

View File

@ -189,6 +189,7 @@ void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
GeanyDocument *doc, *cur_doc = document_get_current();
gint count = 0;
/* iterate over documents in tabs order */
for (i = 0; i < max; i++)
{
doc = document_get_from_page(i);

View File

@ -2758,13 +2758,14 @@ GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename
* @return TRUE if all files were saved or had their changes discarded. */
gboolean document_account_for_unsaved(void)
{
guint i, p, page_count, len = documents_array->len;
GeanyDocument *doc;
guint i, p, page_count;
page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
/* iterate over documents in tabs order */
for (p = 0; p < page_count; p++)
{
doc = document_get_from_page(p);
GeanyDocument *doc = document_get_from_page(p);
if (DOC_VALID(doc) && doc->changed)
{
if (! dialogs_show_unsaved_file(doc))
@ -2772,13 +2773,9 @@ gboolean document_account_for_unsaved(void)
}
}
/* all documents should now be accounted for, so ignore any changes */
for (i = 0; i < len; i++)
foreach_document (i)
{
doc = documents[i];
if (doc->is_valid && doc->changed)
{
doc->changed = FALSE;
}
documents[i]->changed = FALSE;
}
return TRUE;
}

View File

@ -975,8 +975,7 @@ static gboolean check_fixed_kb(guint keyval, guint state)
if (keyval == GDK_Page_Up)
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), 0);
if (keyval == GDK_Page_Down)
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) - 1);
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), -1);
return TRUE;
}
}

View File

@ -330,7 +330,7 @@ void configuration_save_session_files(GKeyFile *config)
npage = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
g_key_file_set_integer(config, "files", "current_page", npage);
/* store the filenames to reopen them the next time */
/* store the filenames in the notebook tab order to reopen them the next time */
max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
for (i = 0; i < max; i++)
{

View File

@ -530,18 +530,13 @@ void sidebar_openfiles_update(GeanyDocument *doc)
void sidebar_openfiles_update_all()
{
guint i, page_count;
guint i;
GeanyDocument *doc;
gtk_tree_store_clear(store_openfiles);
page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
for (i = 0; i < page_count; i++)
foreach_document (i)
{
doc = document_get_from_page(i);
if (G_UNLIKELY(doc == NULL))
continue;
sidebar_openfiles_add(doc);
sidebar_openfiles_add(documents[i]);
}
}

View File

@ -659,7 +659,7 @@ void ui_save_buttons_toggle(gboolean enable)
gboolean dirty_tabs = FALSE;
if (ui_prefs.allow_always_save)
enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0 ? TRUE : FALSE;
enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
ui_widget_set_sensitive(widgets.save_buttons[0], enable);
ui_widget_set_sensitive(widgets.save_buttons[1], enable);
@ -769,7 +769,7 @@ static void init_document_widgets(void)
void ui_document_buttons_update(void)
{
guint i;
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) ? TRUE : FALSE;
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
for (i = 0; i < widgets.document_buttons->len; i++)
{
@ -797,7 +797,7 @@ static void on_doc_sensitive_widget_destroy(GtkWidget *widget, G_GNUC_UNUSED gpo
**/
void ui_add_document_sensitive(GtkWidget *widget)
{
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) ? TRUE : FALSE;
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
ui_widget_set_sensitive(widget, enable);