preferences-dialog: Clean up code styling

This commit is contained in:
JosephMcc 2016-12-30 11:54:48 -08:00
parent f3791ef8d2
commit 05738f44bb
1 changed files with 667 additions and 794 deletions

View File

@ -153,14 +153,9 @@ dialog_response_handler (GtkDialog *dlg,
switch (res_id) switch (res_id)
{ {
case GTK_RESPONSE_HELP: case GTK_RESPONSE_HELP:
xed_help_display (GTK_WINDOW (dlg), xed_help_display (GTK_WINDOW (dlg), NULL, "xed-prefs");
NULL,
"xed-prefs");
g_signal_stop_emission_by_name (dlg, "response"); g_signal_stop_emission_by_name (dlg, "response");
break; break;
default: default:
gtk_widget_destroy (GTK_WIDGET(dlg)); gtk_widget_destroy (GTK_WIDGET(dlg));
} }
@ -209,9 +204,7 @@ auto_save_checkbutton_toggled (GtkToggleButton *button,
if (gtk_toggle_button_get_active (button)) if (gtk_toggle_button_get_active (button))
{ {
gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, xed_prefs_manager_auto_save_interval_can_set());
xed_prefs_manager_auto_save_interval_can_set());
xed_prefs_manager_set_auto_save (TRUE); xed_prefs_manager_set_auto_save (TRUE);
} }
else else
@ -238,8 +231,7 @@ auto_save_spinbutton_value_changed (GtkSpinButton *spin_button,
{ {
g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton));
xed_prefs_manager_set_auto_save_interval ( xed_prefs_manager_set_auto_save_interval (MAX (1, gtk_spin_button_get_value_as_int (spin_button)));
MAX (1, gtk_spin_button_get_value_as_int (spin_button)));
} }
static void static void
@ -261,64 +253,45 @@ setup_editor_page (XedPreferencesDialog *dlg)
xed_prefs_manager_get_create_backup_copy ()); xed_prefs_manager_get_create_backup_copy ());
auto_save = xed_prefs_manager_get_auto_save (); auto_save = xed_prefs_manager_get_auto_save ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), auto_save);
auto_save);
auto_save_interval = xed_prefs_manager_get_auto_save_interval (); auto_save_interval = xed_prefs_manager_get_auto_save_interval ();
if (auto_save_interval <= 0) if (auto_save_interval <= 0)
{
auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
}
gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), auto_save_interval);
auto_save_interval);
/* Set widget sensitivity */ /* Set widget sensitivity */
gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, xed_prefs_manager_tabs_size_can_set ());
xed_prefs_manager_tabs_size_can_set ()); gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, xed_prefs_manager_insert_spaces_can_set ());
gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, xed_prefs_manager_auto_indent_can_set ());
xed_prefs_manager_insert_spaces_can_set ()); gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, xed_prefs_manager_create_backup_copy_can_set ());
gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, gtk_widget_set_sensitive (dlg->priv->autosave_hbox, xed_prefs_manager_auto_save_can_set ());
xed_prefs_manager_auto_indent_can_set ());
gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton,
xed_prefs_manager_create_backup_copy_can_set ());
gtk_widget_set_sensitive (dlg->priv->autosave_hbox,
xed_prefs_manager_auto_save_can_set ());
gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton,
auto_save && auto_save && xed_prefs_manager_auto_save_interval_can_set ());
xed_prefs_manager_auto_save_interval_can_set ());
/* Connect signal */ /* Connect signal */
g_signal_connect (dlg->priv->tabs_width_spinbutton, g_signal_connect (dlg->priv->tabs_width_spinbutton, "value_changed",
"value_changed", G_CALLBACK (tabs_width_spinbutton_value_changed), dlg);
G_CALLBACK (tabs_width_spinbutton_value_changed), g_signal_connect (dlg->priv->insert_spaces_checkbutton, "toggled",
dlg); G_CALLBACK (insert_spaces_checkbutton_toggled), dlg);
g_signal_connect (dlg->priv->insert_spaces_checkbutton, g_signal_connect (dlg->priv->auto_indent_checkbutton, "toggled",
"toggled", G_CALLBACK (auto_indent_checkbutton_toggled), dlg);
G_CALLBACK (insert_spaces_checkbutton_toggled), g_signal_connect (dlg->priv->auto_save_checkbutton, "toggled",
dlg); G_CALLBACK (auto_save_checkbutton_toggled), dlg);
g_signal_connect (dlg->priv->auto_indent_checkbutton, g_signal_connect (dlg->priv->backup_copy_checkbutton, "toggled",
"toggled", G_CALLBACK (backup_copy_checkbutton_toggled), dlg);
G_CALLBACK (auto_indent_checkbutton_toggled), g_signal_connect (dlg->priv->auto_save_spinbutton, "value_changed",
dlg); G_CALLBACK (auto_save_spinbutton_value_changed), dlg);
g_signal_connect (dlg->priv->auto_save_checkbutton,
"toggled",
G_CALLBACK (auto_save_checkbutton_toggled),
dlg);
g_signal_connect (dlg->priv->backup_copy_checkbutton,
"toggled",
G_CALLBACK (backup_copy_checkbutton_toggled),
dlg);
g_signal_connect (dlg->priv->auto_save_spinbutton,
"value_changed",
G_CALLBACK (auto_save_spinbutton_value_changed),
dlg);
} }
static void static void
display_line_numbers_checkbutton_toggled (GtkToggleButton *button, display_line_numbers_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton));
GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton));
xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button));
} }
@ -327,8 +300,7 @@ static void
highlight_current_line_checkbutton_toggled (GtkToggleButton *button, highlight_current_line_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton));
GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton));
xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button));
} }
@ -337,11 +309,9 @@ static void
bracket_matching_checkbutton_toggled (GtkToggleButton *button, bracket_matching_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton));
GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton));
xed_prefs_manager_set_bracket_matching ( xed_prefs_manager_set_bracket_matching (gtk_toggle_button_get_active (button));
gtk_toggle_button_get_active (button));
} }
static gboolean split_button_state = TRUE; static gboolean split_button_state = TRUE;
@ -354,30 +324,23 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button,
{ {
xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE);
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->split_checkbutton, FALSE);
FALSE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
gtk_toggle_button_set_inconsistent (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
} }
else else
{ {
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->split_checkbutton, TRUE);
TRUE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE);
gtk_toggle_button_set_inconsistent (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton)))
{ {
split_button_state = TRUE; split_button_state = TRUE;
xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD);
} }
else else
{ {
split_button_state = FALSE; split_button_state = FALSE;
xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR);
} }
} }
@ -396,8 +359,7 @@ right_margin_checkbutton_toggled (GtkToggleButton *button,
xed_prefs_manager_set_display_right_margin (active); xed_prefs_manager_set_display_right_margin (active);
gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox,
active && active && xed_prefs_manager_right_margin_position_can_set ());
xed_prefs_manager_right_margin_position_can_set ());
} }
static void static void
@ -436,35 +398,25 @@ setup_view_page (XedPreferencesDialog *dlg)
switch (wrap_mode ) switch (wrap_mode )
{ {
case GTK_WRAP_WORD: case GTK_WRAP_WORD:
gtk_toggle_button_set_active ( gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE);
GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
break; break;
case GTK_WRAP_CHAR: case GTK_WRAP_CHAR:
gtk_toggle_button_set_active ( gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE);
GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE);
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE);
break; break;
default: default:
gtk_toggle_button_set_active ( gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), FALSE);
GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), split_button_state);
gtk_toggle_button_set_active ( gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), split_button_state);
gtk_toggle_button_set_inconsistent (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
} }
display_right_margin = xed_prefs_manager_get_display_right_margin (); display_right_margin = xed_prefs_manager_get_display_right_margin ();
gtk_toggle_button_set_active ( gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), display_right_margin);
GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton),
display_right_margin);
gtk_spin_button_set_value ( gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton),
GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton),
(guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160));
/* Set widgets sensitivity */ /* Set widgets sensitivity */
@ -472,49 +424,29 @@ setup_view_page (XedPreferencesDialog *dlg)
xed_prefs_manager_display_line_numbers_can_set ()); xed_prefs_manager_display_line_numbers_can_set ());
gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton,
xed_prefs_manager_highlight_current_line_can_set ()); xed_prefs_manager_highlight_current_line_can_set ());
gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, xed_prefs_manager_bracket_matching_can_set ());
xed_prefs_manager_bracket_matching_can_set ());
wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set ();
gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, wrap_mode_can_set);
wrap_mode_can_set); gtk_widget_set_sensitive (dlg->priv->split_checkbutton, wrap_mode_can_set && (wrap_mode != GTK_WRAP_NONE));
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, xed_prefs_manager_display_right_margin_can_set ());
wrap_mode_can_set &&
(wrap_mode != GTK_WRAP_NONE));
gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton,
xed_prefs_manager_display_right_margin_can_set ());
gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox,
display_right_margin && display_right_margin && xed_prefs_manager_right_margin_position_can_set ());
xed_prefs_manager_right_margin_position_can_set ());
/* Connect signals */ /* Connect signals */
g_signal_connect (dlg->priv->display_line_numbers_checkbutton, g_signal_connect (dlg->priv->display_line_numbers_checkbutton, "toggled",
"toggled", G_CALLBACK (display_line_numbers_checkbutton_toggled), dlg);
G_CALLBACK (display_line_numbers_checkbutton_toggled), g_signal_connect (dlg->priv->highlight_current_line_checkbutton, "toggled",
dlg); G_CALLBACK (highlight_current_line_checkbutton_toggled), dlg);
g_signal_connect (dlg->priv->highlight_current_line_checkbutton, g_signal_connect (dlg->priv->bracket_matching_checkbutton, "toggled",
"toggled", G_CALLBACK (bracket_matching_checkbutton_toggled), dlg);
G_CALLBACK (highlight_current_line_checkbutton_toggled), g_signal_connect (dlg->priv->wrap_text_checkbutton, "toggled",
dlg); G_CALLBACK (wrap_mode_checkbutton_toggled), dlg);
g_signal_connect (dlg->priv->bracket_matching_checkbutton, g_signal_connect (dlg->priv->split_checkbutton, "toggled",
"toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), dlg);
G_CALLBACK (bracket_matching_checkbutton_toggled), g_signal_connect (dlg->priv->right_margin_checkbutton, "toggled",
dlg); G_CALLBACK (right_margin_checkbutton_toggled), dlg);
g_signal_connect (dlg->priv->wrap_text_checkbutton, g_signal_connect (dlg->priv->right_margin_position_spinbutton, "value_changed",
"toggled", G_CALLBACK (right_margin_position_spinbutton_value_changed), dlg);
G_CALLBACK (wrap_mode_checkbutton_toggled),
dlg);
g_signal_connect (dlg->priv->split_checkbutton,
"toggled",
G_CALLBACK (wrap_mode_checkbutton_toggled),
dlg);
g_signal_connect (dlg->priv->right_margin_checkbutton,
"toggled",
G_CALLBACK (right_margin_checkbutton_toggled),
dlg);
g_signal_connect (dlg->priv->right_margin_position_spinbutton,
"value_changed",
G_CALLBACK (right_margin_position_spinbutton_value_changed),
dlg);
} }
static void static void
@ -532,8 +464,7 @@ default_font_font_checkbutton_toggled (GtkToggleButton *button,
} }
else else
{ {
gtk_widget_set_sensitive (dlg->priv->font_hbox, gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ());
xed_prefs_manager_editor_font_can_set ());
xed_prefs_manager_set_use_default_font (FALSE); xed_prefs_manager_set_use_default_font (FALSE);
} }
} }
@ -579,45 +510,39 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg)
ATK_RELATION_CONTROLLER_FOR); ATK_RELATION_CONTROLLER_FOR);
editor_font = xed_prefs_manager_get_system_font (); editor_font = xed_prefs_manager_get_system_font ();
label = g_strdup_printf(_("_Use the system fixed width font (%s)"), label = g_strdup_printf(_("_Use the system fixed width font (%s)"), editor_font);
editor_font); gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton), label);
gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton),
label);
g_free (editor_font); g_free (editor_font);
g_free (label); g_free (label);
/* read current config and setup initial state */ /* read current config and setup initial state */
use_default_font = xed_prefs_manager_get_use_default_font (); use_default_font = xed_prefs_manager_get_use_default_font ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), use_default_font);
use_default_font);
editor_font = xed_prefs_manager_get_editor_font (); editor_font = xed_prefs_manager_get_editor_font ();
if (editor_font != NULL) if (editor_font != NULL)
{ {
gtk_font_button_set_font_name (GTK_FONT_BUTTON (dlg->priv->font_button), gtk_font_button_set_font_name (GTK_FONT_BUTTON (dlg->priv->font_button), editor_font);
editor_font);
g_free (editor_font); g_free (editor_font);
} }
/* Connect signals */ /* Connect signals */
g_signal_connect (dlg->priv->default_font_checkbutton, g_signal_connect (dlg->priv->default_font_checkbutton, "toggled",
"toggled", G_CALLBACK (default_font_font_checkbutton_toggled), dlg);
G_CALLBACK (default_font_font_checkbutton_toggled), g_signal_connect (dlg->priv->font_button, "font_set",
dlg); G_CALLBACK (editor_font_button_font_set), dlg);
g_signal_connect (dlg->priv->font_button,
"font_set",
G_CALLBACK (editor_font_button_font_set),
dlg);
/* Set initial widget sensitivity */ /* Set initial widget sensitivity */
gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, xed_prefs_manager_use_default_font_can_set ());
xed_prefs_manager_use_default_font_can_set ());
if (use_default_font) if (use_default_font)
{
gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE);
}
else else
gtk_widget_set_sensitive (dlg->priv->font_hbox, {
xed_prefs_manager_editor_font_can_set ()); gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ());
}
} }
static void static void
@ -627,12 +552,9 @@ set_buttons_sensisitivity_according_to_scheme (XedPreferencesDialog *dlg,
gboolean editable; gboolean editable;
editable = (scheme_id != NULL) && editable = (scheme_id != NULL) &&
_xed_style_scheme_manager_scheme_is_xed_user_scheme ( _xed_style_scheme_manager_scheme_is_xed_user_scheme (xed_get_style_scheme_manager (), scheme_id);
xed_get_style_scheme_manager (),
scheme_id);
gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, editable);
editable);
} }
static void static void
@ -644,11 +566,9 @@ style_scheme_changed (GtkWidget *treeview,
gchar *id; gchar *id;
gtk_tree_view_get_cursor (GTK_TREE_VIEW (dlg->priv->schemes_treeview), &path, NULL); gtk_tree_view_get_cursor (GTK_TREE_VIEW (dlg->priv->schemes_treeview), &path, NULL);
gtk_tree_model_get_iter (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), gtk_tree_model_get_iter (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, path);
&iter, path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, ID_COLUMN, &id, -1);
&iter, ID_COLUMN, &id, -1);
xed_prefs_manager_set_source_style_scheme (id); xed_prefs_manager_set_source_style_scheme (id);
@ -668,21 +588,18 @@ ensure_color_scheme_id (const gchar *id)
gchar *pref_id; gchar *pref_id;
pref_id = xed_prefs_manager_get_source_style_scheme (); pref_id = xed_prefs_manager_get_source_style_scheme ();
scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme = gtk_source_style_scheme_manager_get_scheme (manager, pref_id);
pref_id);
g_free (pref_id); g_free (pref_id);
} }
else else
{ {
scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme = gtk_source_style_scheme_manager_get_scheme (manager, id);
id);
} }
if (scheme == NULL) if (scheme == NULL)
{ {
/* Fall-back to classic style scheme */ /* Fall-back to classic style scheme */
scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme = gtk_source_style_scheme_manager_get_scheme (manager, "classic");
"classic");
} }
if (scheme == NULL) if (scheme == NULL)
@ -698,7 +615,8 @@ ensure_color_scheme_id (const gchar *id)
* xed_style_scheme_manager_get_default_scheme. If this one returns NULL * xed_style_scheme_manager_get_default_scheme. If this one returns NULL
* use the first available scheme as default */ * use the first available scheme as default */
static const gchar * static const gchar *
populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) populate_color_scheme_list (XedPreferencesDialog *dlg,
const gchar *def_id)
{ {
GSList *schemes; GSList *schemes;
GSList *l; GSList *l;
@ -774,16 +692,12 @@ add_scheme_chooser_response_cb (GtkDialog *chooser,
gtk_widget_hide (GTK_WIDGET (chooser)); gtk_widget_hide (GTK_WIDGET (chooser));
scheme_id = _xed_style_scheme_manager_install_scheme ( scheme_id = _xed_style_scheme_manager_install_scheme (xed_get_style_scheme_manager (), filename);
xed_get_style_scheme_manager (),
filename);
g_free (filename); g_free (filename);
if (scheme_id == NULL) if (scheme_id == NULL)
{ {
xed_warning (GTK_WINDOW (dlg), xed_warning (GTK_WINDOW (dlg), _("The selected color scheme cannot be installed."));
_("The selected color scheme cannot be installed."));
return; return;
} }
@ -801,7 +715,8 @@ install_scheme_clicked (GtkButton *button,
GtkWidget *chooser; GtkWidget *chooser;
GtkFileFilter *filter; GtkFileFilter *filter;
if (dlg->priv->install_scheme_file_schooser != NULL) { if (dlg->priv->install_scheme_file_schooser != NULL)
{
gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser)); gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser));
gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser); gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser);
return; return;
@ -813,10 +728,8 @@ install_scheme_clicked (GtkButton *button,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL); NULL);
xed_dialog_add_button (GTK_DIALOG (chooser), xed_dialog_add_button (GTK_DIALOG (chooser), _("A_dd Scheme"),
_("A_dd Scheme"), GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT);
GTK_STOCK_ADD,
GTK_RESPONSE_ACCEPT);
gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE);
@ -835,15 +748,12 @@ install_scheme_clicked (GtkButton *button,
gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
g_signal_connect (chooser, g_signal_connect (chooser, "response",
"response", G_CALLBACK (add_scheme_chooser_response_cb), dlg);
G_CALLBACK (add_scheme_chooser_response_cb),
dlg);
dlg->priv->install_scheme_file_schooser = chooser; dlg->priv->install_scheme_file_schooser = chooser;
g_object_add_weak_pointer (G_OBJECT (chooser), g_object_add_weak_pointer (G_OBJECT (chooser), (gpointer) &dlg->priv->install_scheme_file_schooser);
(gpointer) &dlg->priv->install_scheme_file_schooser);
gtk_widget_show (chooser); gtk_widget_show (chooser);
} }
@ -859,23 +769,16 @@ uninstall_scheme_clicked (GtkButton *button,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview));
model = GTK_TREE_MODEL (dlg->priv->schemes_treeview_model); model = GTK_TREE_MODEL (dlg->priv->schemes_treeview_model);
if (gtk_tree_selection_get_selected (selection, if (gtk_tree_selection_get_selected (selection, &model, &iter))
&model,
&iter))
{ {
gchar *id; gchar *id;
gchar *name; gchar *name;
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter, ID_COLUMN, &id, NAME_COLUMN, &name, -1);
ID_COLUMN, &id,
NAME_COLUMN, &name,
-1);
if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id))
{ {
xed_warning (GTK_WINDOW (dlg), xed_warning (GTK_WINDOW (dlg), _("Could not remove color scheme \"%s\"."), name);
_("Could not remove color scheme \"%s\"."),
name);
} }
else else
{ {
@ -908,17 +811,21 @@ uninstall_scheme_clicked (GtkButton *button,
gtk_tree_path_prev (path); gtk_tree_path_prev (path);
if (gtk_tree_model_get_iter (model, &new_iter, path)) if (gtk_tree_model_get_iter (model, &new_iter, path))
{
new_iter_set = TRUE; new_iter_set = TRUE;
} }
}
else else
{
new_iter_set = TRUE; new_iter_set = TRUE;
}
gtk_tree_path_free (path); gtk_tree_path_free (path);
if (new_iter_set) if (new_iter_set)
gtk_tree_model_get (model, &new_iter, {
ID_COLUMN, &new_id, gtk_tree_model_get (model, &new_iter, ID_COLUMN, &new_id, -1);
-1); }
real_new_id = populate_color_scheme_list (dlg, new_id); real_new_id = populate_color_scheme_list (dlg, new_id);
g_free (new_id); g_free (new_id);
@ -926,8 +833,10 @@ uninstall_scheme_clicked (GtkButton *button,
set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id);
if (real_new_id != NULL) if (real_new_id != NULL)
{
xed_prefs_manager_set_source_style_scheme (real_new_id); xed_prefs_manager_set_source_style_scheme (real_new_id);
} }
}
g_free (id); g_free (id);
g_free (name); g_free (name);
@ -945,30 +854,21 @@ scheme_description_cell_data_func (GtkTreeViewColumn *column,
gchar *desc; gchar *desc;
gchar *text; gchar *text;
gtk_tree_model_get (model, iter, gtk_tree_model_get (model, iter, NAME_COLUMN, &name, DESC_COLUMN, &desc, -1);
NAME_COLUMN, &name,
DESC_COLUMN, &desc,
-1);
if (desc != NULL) if (desc != NULL)
{ {
text = g_markup_printf_escaped ("<b>%s</b> - %s", text = g_markup_printf_escaped ("<b>%s</b> - %s", name, desc);
name,
desc);
} }
else else
{ {
text = g_markup_printf_escaped ("<b>%s</b>", text = g_markup_printf_escaped ("<b>%s</b>", name);
name);
} }
g_free (name); g_free (name);
g_free (desc); g_free (desc);
g_object_set (G_OBJECT (renderer), g_object_set (G_OBJECT (renderer), "markup", text, NULL);
"markup",
text,
NULL);
g_free (text); g_free (text);
} }
@ -991,8 +891,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
G_TYPE_STRING); G_TYPE_STRING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->schemes_treeview_model), gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->schemes_treeview_model),
0, 0, GTK_SORT_ASCENDING);
GTK_SORT_ASCENDING);
gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->schemes_treeview), gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->schemes_treeview),
GTK_TREE_MODEL (dlg->priv->schemes_treeview_model)); GTK_TREE_MODEL (dlg->priv->schemes_treeview_model));
@ -1007,8 +906,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
dlg, dlg,
NULL); NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->schemes_treeview), gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->schemes_treeview), column);
column);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
@ -1016,18 +914,12 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
def_id = populate_color_scheme_list (dlg, NULL); def_id = populate_color_scheme_list (dlg, NULL);
/* Connect signals */ /* Connect signals */
g_signal_connect (dlg->priv->schemes_treeview, g_signal_connect (dlg->priv->schemes_treeview, "cursor-changed",
"cursor-changed", G_CALLBACK (style_scheme_changed), dlg);
G_CALLBACK (style_scheme_changed), g_signal_connect (dlg->priv->install_scheme_button, "clicked",
dlg); G_CALLBACK (install_scheme_clicked), dlg);
g_signal_connect (dlg->priv->install_scheme_button, g_signal_connect (dlg->priv->uninstall_scheme_button, "clicked",
"clicked", G_CALLBACK (uninstall_scheme_clicked), dlg);
G_CALLBACK (install_scheme_clicked),
dlg);
g_signal_connect (dlg->priv->uninstall_scheme_button,
"clicked",
G_CALLBACK (uninstall_scheme_clicked),
dlg);
/* Set initial widget sensitivity */ /* Set initial widget sensitivity */
set_buttons_sensisitivity_according_to_scheme (dlg, def_id); set_buttons_sensisitivity_according_to_scheme (dlg, def_id);
@ -1050,11 +942,7 @@ setup_plugins_page (XedPreferencesDialog *dlg)
page_content = peas_gtk_plugin_manager_new (NULL); page_content = peas_gtk_plugin_manager_new (NULL);
g_return_if_fail (page_content != NULL); g_return_if_fail (page_content != NULL);
gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), page_content, TRUE, TRUE, 0);
page_content,
TRUE,
TRUE,
0);
gtk_widget_show_all (page_content); gtk_widget_show_all (page_content);
} }
@ -1079,10 +967,8 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg);
gtk_dialog_add_buttons (GTK_DIALOG (dlg), gtk_dialog_add_buttons (GTK_DIALOG (dlg),
GTK_STOCK_CLOSE, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
GTK_RESPONSE_CLOSE, GTK_STOCK_HELP, GTK_RESPONSE_HELP,
GTK_STOCK_HELP,
GTK_RESPONSE_HELP,
NULL); NULL);
gtk_window_set_title (GTK_WINDOW (dlg), _("Xed Preferences")); gtk_window_set_title (GTK_WINDOW (dlg), _("Xed Preferences"));
@ -1095,16 +981,11 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
g_signal_connect (dlg, g_signal_connect (dlg, "response",
"response", G_CALLBACK (dialog_response_handler), NULL);
G_CALLBACK (dialog_response_handler),
NULL);
file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui");
ret = xed_utils_get_ui_objects (file, ret = xed_utils_get_ui_objects (file, root_objects, &error_widget,
root_objects,
&error_widget,
"notebook", &dlg->priv->notebook, "notebook", &dlg->priv->notebook,
"display_line_numbers_checkbutton", &dlg->priv->display_line_numbers_checkbutton, "display_line_numbers_checkbutton", &dlg->priv->display_line_numbers_checkbutton,
@ -1144,16 +1025,11 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
if (!ret) if (!ret)
{ {
gtk_widget_show (error_widget); gtk_widget_show (error_widget);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
error_widget,
TRUE, TRUE, 0);
return; return;
} }
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))), dlg->priv->notebook, FALSE, FALSE, 0);
dlg->priv->notebook, FALSE, FALSE, 0);
g_object_unref (dlg->priv->notebook); g_object_unref (dlg->priv->notebook);
gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5); gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5);
@ -1173,16 +1049,13 @@ xed_show_preferences_dialog (XedWindow *parent)
if (preferences_dialog == NULL) if (preferences_dialog == NULL)
{ {
preferences_dialog = GTK_WIDGET (g_object_new (XED_TYPE_PREFERENCES_DIALOG, NULL)); preferences_dialog = GTK_WIDGET (g_object_new (XED_TYPE_PREFERENCES_DIALOG, NULL));
g_signal_connect (preferences_dialog, g_signal_connect (preferences_dialog, "destroy",
"destroy", G_CALLBACK (gtk_widget_destroyed), &preferences_dialog);
G_CALLBACK (gtk_widget_destroyed),
&preferences_dialog);
} }
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (preferences_dialog))) if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (preferences_dialog)))
{ {
gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog), gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog), GTK_WINDOW (parent));
GTK_WINDOW (parent));
} }
gtk_window_present (GTK_WINDOW (preferences_dialog)); gtk_window_present (GTK_WINDOW (preferences_dialog));