close-confirmation-dialog: Clean up code styling

This commit is contained in:
JosephMcc 2016-12-11 18:20:46 -08:00
parent 708d79dbf8
commit 2ab142b094
1 changed files with 466 additions and 509 deletions

View File

@ -67,13 +67,9 @@ enum
struct _XedCloseConfirmationDialogPrivate
{
gboolean logout_mode;
GList *unsaved_documents;
GList *selected_documents;
GtkTreeModel *list_store;
};
#define XED_CLOSE_CONFIRMATION_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
@ -88,7 +84,6 @@ G_DEFINE_TYPE(XedCloseConfirmationDialog, xed_close_confirmation_dialog, GTK_TYP
static void set_unsaved_document (XedCloseConfirmationDialog *dlg,
const GList *list);
static GList *get_selected_docs (GtkTreeModel *store);
/* Since we connect in the costructor we are sure this handler will be called
@ -106,21 +101,21 @@ response_cb (XedCloseConfirmationDialog *dlg,
priv = dlg->priv;
if (priv->selected_documents != NULL)
{
g_list_free (priv->selected_documents);
}
if (response_id == GTK_RESPONSE_YES)
{
if (GET_MODE (priv) == SINGLE_DOC_MODE)
{
priv->selected_documents =
g_list_copy (priv->unsaved_documents);
priv->selected_documents = g_list_copy (priv->unsaved_documents);
}
else
{
g_return_if_fail (priv->list_store);
priv->selected_documents =
get_selected_docs (priv->list_store);
priv->selected_documents = get_selected_docs (priv->list_store);
}
}
else
@ -135,23 +130,13 @@ set_logout_mode (XedCloseConfirmationDialog *dlg,
if (logout_mode)
{
gtk_dialog_add_button (GTK_DIALOG (dlg),
_("Log Out _without Saving"),
GTK_RESPONSE_NO);
xed_dialog_add_button (GTK_DIALOG (dlg),
_("_Cancel Logout"),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dlg), _("Log Out _without Saving"), GTK_RESPONSE_NO);
xed_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel Logout"), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
}
else
{
gtk_dialog_add_button (GTK_DIALOG (dlg),
_("Close _without Saving"),
GTK_RESPONSE_NO);
gtk_dialog_add_button (GTK_DIALOG (dlg),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dlg), _("Close _without Saving"), GTK_RESPONSE_NO);
gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
}
@ -163,17 +148,14 @@ set_logout_mode (XedCloseConfirmationDialog *dlg,
doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data);
if (xed_document_get_readonly (doc) ||
xed_document_is_untitled (doc))
if (xed_document_get_readonly (doc) || xed_document_is_untitled (doc))
{
stock_id = GTK_STOCK_SAVE_AS;
}
}
gtk_dialog_add_button (GTK_DIALOG (dlg),
stock_id,
GTK_RESPONSE_YES);
gtk_dialog_set_default_response (GTK_DIALOG (dlg),
GTK_RESPONSE_YES);
gtk_dialog_add_button (GTK_DIALOG (dlg), stock_id, GTK_RESPONSE_YES);
gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_YES);
}
static void
@ -184,8 +166,7 @@ xed_close_confirmation_dialog_init (XedCloseConfirmationDialog *dlg)
dlg->priv = XED_CLOSE_CONFIRMATION_DIALOG_GET_PRIVATE (dlg);
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
14);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 14);
gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), TRUE);
@ -198,10 +179,7 @@ xed_close_confirmation_dialog_init (XedCloseConfirmationDialog *dlg)
atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
atk_object_set_name (atk_obj, _("Question"));
g_signal_connect (dlg,
"response",
G_CALLBACK (response_cb),
NULL);
g_signal_connect (dlg, "response", G_CALLBACK (response_cb), NULL);
}
static void
@ -212,10 +190,14 @@ xed_close_confirmation_dialog_finalize (GObject *object)
priv = XED_CLOSE_CONFIRMATION_DIALOG (object)->priv;
if (priv->unsaved_documents != NULL)
{
g_list_free (priv->unsaved_documents);
}
if (priv->selected_documents != NULL)
{
g_list_free (priv->selected_documents);
}
/* Call the parent's destructor */
G_OBJECT_CLASS (xed_close_confirmation_dialog_parent_class)->finalize (object);
@ -289,8 +271,7 @@ xed_close_confirmation_dialog_class_init (XedCloseConfirmationDialogClass *klass
g_param_spec_pointer ("unsaved_documents",
"Unsaved Documents",
"List of Unsaved Documents",
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY)));
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
g_object_class_install_property (gobject_class,
PROP_LOGOUT_MODE,
@ -298,8 +279,7 @@ xed_close_confirmation_dialog_class_init (XedCloseConfirmationDialogClass *klass
"Logout Mode",
"Whether the dialog is in logout mode",
FALSE,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY)));
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
}
static GList *
@ -317,12 +297,11 @@ get_selected_docs (GtkTreeModel *store)
gboolean to_save;
XedDocument *doc;
gtk_tree_model_get (store, &iter,
SAVE_COLUMN, &to_save,
DOC_COLUMN, &doc,
-1);
gtk_tree_model_get (store, &iter, SAVE_COLUMN, &to_save, DOC_COLUMN, &doc, -1);
if (to_save)
{
list = g_list_prepend (list, doc);
}
valid = gtk_tree_model_iter_next (store, &iter);
}
@ -356,9 +335,7 @@ xed_close_confirmation_dialog_new (GtkWindow *parent,
if (parent != NULL)
{
gtk_window_group_add_window (xed_window_get_group (XED_WINDOW (parent)),
GTK_WINDOW (dlg));
gtk_window_group_add_window (xed_window_get_group (XED_WINDOW (parent)), GTK_WINDOW (dlg));
gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
}
@ -376,9 +353,7 @@ xed_close_confirmation_dialog_new_single (GtkWindow *parent,
unsaved_documents = g_list_prepend (NULL, doc);
dlg = xed_close_confirmation_dialog_new (parent,
unsaved_documents,
logout_mode);
dlg = xed_close_confirmation_dialog_new (parent, unsaved_documents, logout_mode);
g_list_free (unsaved_documents);
@ -395,8 +370,7 @@ get_text_secondary_label (XedDocument *doc)
if (seconds < 55)
{
secondary_msg = g_strdup_printf (
ngettext ("If you don't save, changes from the last %ld second "
secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %ld second "
"will be permanently lost.",
"If you don't save, changes from the last %ld seconds "
"will be permanently lost.",
@ -410,8 +384,7 @@ get_text_secondary_label (XedDocument *doc)
}
else if (seconds < 110) /* 75 <= seconds < 110 */
{
secondary_msg = g_strdup_printf (
ngettext ("If you don't save, changes from the last minute and %ld "
secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last minute and %ld "
"second will be permanently lost.",
"If you don't save, changes from the last minute and %ld "
"seconds will be permanently lost.",
@ -420,8 +393,7 @@ get_text_secondary_label (XedDocument *doc)
}
else if (seconds < 3600)
{
secondary_msg = g_strdup_printf (
ngettext ("If you don't save, changes from the last %ld minute "
secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %ld minute "
"will be permanently lost.",
"If you don't save, changes from the last %ld minutes "
"will be permanently lost.",
@ -441,8 +413,7 @@ get_text_secondary_label (XedDocument *doc)
}
else
{
secondary_msg = g_strdup_printf (
ngettext ("If you don't save, changes from the last hour and %d "
secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last hour and %d "
"minute will be permanently lost.",
"If you don't save, changes from the last hour and %d "
"minutes will be permanently lost.",
@ -456,8 +427,7 @@ get_text_secondary_label (XedDocument *doc)
hours = seconds / 3600;
secondary_msg = g_strdup_printf (
ngettext ("If you don't save, changes from the last %d hour "
secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %d hour "
"will be permanently lost.",
"If you don't save, changes from the last %d hours "
"will be permanently lost.",
@ -485,8 +455,7 @@ build_single_doc_dialog (XedCloseConfirmationDialog *dlg)
doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data);
/* Image */
image = gtk_image_new_from_icon_name ("dialog-warning",
GTK_ICON_SIZE_DIALOG);
image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG);
gtk_widget_set_halign (image, GTK_ALIGN_START);
gtk_widget_set_valign (image, GTK_ALIGN_END);
@ -527,22 +496,16 @@ build_single_doc_dialog (XedCloseConfirmationDialog *dlg)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), secondary_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
hbox,
FALSE,
FALSE,
0);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, FALSE, FALSE, 0);
gtk_widget_show_all (hbox);
}
static void
populate_model (GtkTreeModel *store, GList *docs)
populate_model (GtkTreeModel *store,
GList *docs)
{
GtkTreeIter iter;
@ -569,7 +532,9 @@ populate_model (GtkTreeModel *store, GList *docs)
}
static void
save_toggled (GtkCellRendererToggle *renderer, gchar *path_str, GtkTreeModel *store)
save_toggled (GtkCellRendererToggle *renderer,
gchar *path_str,
GtkTreeModel *store)
{
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
GtkTreeIter iter;
@ -580,8 +545,7 @@ save_toggled (GtkCellRendererToggle *renderer, gchar *path_str, GtkTreeModel *st
active ^= 1;
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
SAVE_COLUMN, active, -1);
gtk_list_store_set (GTK_LIST_STORE (store), &iter, SAVE_COLUMN, active, -1);
gtk_tree_path_free (path);
}
@ -612,8 +576,7 @@ create_treeview (XedCloseConfirmationDialogPrivate *priv)
/* Add columns */
renderer = gtk_cell_renderer_toggle_new ();
g_signal_connect (renderer, "toggled",
G_CALLBACK (save_toggled), store);
g_signal_connect (renderer, "toggled", G_CALLBACK (save_toggled), store);
column = gtk_tree_view_column_new_with_attributes ("Save?",
renderer,
@ -653,12 +616,10 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
hbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 0);
/* Image */
image = gtk_image_new_from_icon_name ("dialog-warning",
GTK_ICON_SIZE_DIALOG);
image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG);
gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
gtk_widget_set_valign (image, GTK_ALIGN_START);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
@ -673,8 +634,7 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg)
gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5);
gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
str = g_strdup_printf (
ngettext ("There is %d document with unsaved changes. "
str = g_strdup_printf (ngettext ("There is %d document with unsaved changes. "
"Save changes before closing?",
"There are %d documents with unsaved changes. "
"Save changes before closing?",
@ -699,11 +659,8 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg)
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), 60);
treeview = create_treeview (priv);