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