diff options
43 files changed, 2225 insertions, 3858 deletions
diff --git a/data/org.mate.pluma.gschema.xml.in b/data/org.mate.pluma.gschema.xml.in index 3738720f..48a6e24d 100644 --- a/data/org.mate.pluma.gschema.xml.in +++ b/data/org.mate.pluma.gschema.xml.in @@ -41,7 +41,7 @@ <summary>Autosave</summary> <description>Whether pluma should automatically save modified files after a time interval. You can set the time interval with the "Autosave Interval" option.</description> </key> - <key name="auto-save-interval" type="i"> + <key name="auto-save-interval" type="u"> <default>10</default> <summary>Autosave Interval</summary> <description>Number of minutes after which pluma will automatically save modified files. This will only take effect if the "Autosave" option is turned on.</description> @@ -56,7 +56,7 @@ <summary>Writable VFS schemes</summary> <description>List of VFS schemes pluma supports in write mode. The 'file' scheme is writable by default.</description> </key> - <key name="max-undo-actions" type="i"> + <key name="max-undo-actions" type="u"> <default>2000</default> <summary>Maximum Number of Undo Actions</summary> <description>Maximum number of actions that pluma will be able to undo or redo. Use "-1" for unlimited number of actions.</description> @@ -66,7 +66,7 @@ <summary>Line Wrapping Mode</summary> <description>Specifies how to wrap long lines in the editing area. Use "GTK_WRAP_NONE" for no wrapping, "GTK_WRAP_WORD" for wrapping at word boundaries, and "GTK_WRAP_CHAR" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here.</description> </key> - <key name="tabs-size" type="i"> + <key name="tabs-size" type="u"> <default>4</default> <summary>Tab Size</summary> <description>Specifies the number of spaces that should be displayed instead of Tab characters.</description> @@ -101,7 +101,7 @@ <summary>Display Right Margin</summary> <description>Whether pluma should display the right margin in the editing area.</description> </key> - <key name="right-margin-position" type="i"> + <key name="right-margin-position" type="u"> <default>80</default> <summary>Right Margin Position</summary> <description>Specifies the position of the right margin.</description> @@ -116,12 +116,12 @@ <summary>Restore Previous Cursor Position</summary> <description>Whether pluma should restore the previous cursor position when a file is loaded.</description> </key> - <key name="enable-search-highlighting" type="b"> + <key name="search-highlighting" type="b"> <default>true</default> <summary>Enable Search Highlighting</summary> <description>Whether pluma should highlight all the occurrences of the searched text.</description> </key> - <key name="enable-syntax-highlighting" type="b"> + <key name="syntax-highlighting" type="b"> <default>true</default> <summary>Enable Syntax Highlighting</summary> <description>Whether pluma should enable syntax highlighting.</description> @@ -156,7 +156,7 @@ <summary>Bottom Panel is Visible</summary> <description>Whether the bottom panel at the bottom of editing windows should be visible.</description> </key> - <key name="max-recents" type="i"> + <key name="max-recents" type="u"> <default>5</default> <summary>Maximum Recent Files</summary> <description>Specifies the maximum number of recently opened files that will be displayed in the "Recent Files" submenu.</description> @@ -176,7 +176,7 @@ <summary>Printing Line Wrapping Mode</summary> <description>Specifies how to wrap long lines for printing. Use "GTK_WRAP_NONE" for no wrapping, "GTK_WRAP_WORD" for wrapping at word boundaries, and "GTK_WRAP_CHAR" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here.</description> </key> - <key name="print-line-numbers" type="i"> + <key name="print-line-numbers" type="u"> <default>0</default> <summary>Print Line Numbers</summary> <description>If this value is 0, then no line numbers will be inserted when printing a document. Otherwise, pluma will print line numbers every such number of lines.</description> @@ -241,5 +241,40 @@ <summary>Show spaces</summary> <description>Whether pluma should show spaces in the editor window: 'show-none' no showing; 'show-trailing' showing only trailing spaces; 'show-all' showing all spaces.</description> </key> + <key name="state" type="i"> + <default>0</default> + <summary>state</summary> + <description>The pluma window state</description> + </key> + <key name="size" type="(ii)"> + <default>(650, 500)</default> + <summary>size</summary> + <description>The pluma window size</description> + </key> + <key name="side-panel-size" type="i"> + <default>200</default> + <summary>side-panel-size</summary> + <description>The pluma side-panel-size</description> + </key> + <key name="side-panel-active-page" type="i"> + <default>0</default> + <summary>side-panel-active-page</summary> + <description>The pluma side-panel-active-page</description> + </key> + <key name="bottom-panel-size" type="i"> + <default>140</default> + <summary>bottom-panel-size</summary> + <description>The pluma bottom-panel-size</description> + </key> + <key name="bottom-panel-active-page" type="i"> + <default>0</default> + <summary>bottom-panel-active-page</summary> + <description>The pluma bottom-panel-active-page</description> + </key> + <key name="filter-id" type="i"> + <default>0</default> + <summary>filter-id</summary> + <description>The pluma filter-id</description> + </key> </schema> </schemalist> diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index 3f347a7b..c5ec0fe8 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -19,14 +19,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "modeline-parser.h" + #include <string.h> #include <stdlib.h> #include <stdio.h> #include <gtk/gtk.h> #include <pluma/pluma-language-manager.h> -#include <pluma/pluma-prefs-manager.h> #include <pluma/pluma-debug.h> -#include "modeline-parser.h" +#include <pluma/pluma-settings.h> #define MODELINES_LANGUAGE_MAPPINGS_FILE "language-mappings" @@ -675,6 +676,8 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; + /* FIXME: avoid making a new gsettings variable */ + GSettings *settings = g_settings_new (PLUMA_SCHEMA_ID); options.language_id = NULL; options.set = MODELINE_SET_NONE; @@ -766,13 +769,13 @@ modeline_parser_apply_modeline (GtkSourceView *view) if (has_option (&options, MODELINE_SET_INSERT_SPACES)) { gtk_source_view_set_insert_spaces_instead_of_tabs - (view, options.insert_spaces); + (view, options.insert_spaces); } else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES)) { gtk_source_view_set_insert_spaces_instead_of_tabs - (view, - pluma_prefs_manager_get_insert_spaces ()); + (view, + g_settings_get_boolean (settings, PLUMA_SETTINGS_INSERT_SPACES)); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) @@ -782,7 +785,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, - pluma_prefs_manager_get_tabs_size ()); + g_settings_get_uint (settings, PLUMA_SETTINGS_TABS_SIZE)); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) @@ -801,7 +804,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), - pluma_prefs_manager_get_wrap_mode ()); + g_settings_get_enum (settings, PLUMA_SETTINGS_WRAP_MODE)); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) @@ -811,7 +814,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, - pluma_prefs_manager_get_right_margin_position ()); + g_settings_get_uint (settings, PLUMA_SETTINGS_RIGHT_MARGIN_POSITION)); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) @@ -821,7 +824,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, - pluma_prefs_manager_get_display_right_margin ()); + g_settings_get_boolean (settings, PLUMA_SETTINGS_DISPLAY_RIGHT_MARGIN)); } if (previous) @@ -842,6 +845,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) } g_free (options.language_id); + g_object_unref (settings); } void diff --git a/plugins/spell/pluma-spell-plugin.c b/plugins/spell/pluma-spell-plugin.c index fdc2588f..c09c4cd0 100644 --- a/plugins/spell/pluma-spell-plugin.c +++ b/plugins/spell/pluma-spell-plugin.c @@ -36,7 +36,6 @@ #include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> -#include <pluma/pluma-prefs-manager.h> #include <pluma/pluma-statusbar.h> #include <pluma/pluma-utils.h> diff --git a/pluma/Makefile.am b/pluma/Makefile.am index e7c0639d..19654228 100644 --- a/pluma/Makefile.am +++ b/pluma/Makefile.am @@ -52,10 +52,10 @@ NOINST_H_FILES = \ pluma-io-error-message-area.h \ pluma-language-manager.h \ pluma-plugins-engine.h \ - pluma-prefs-manager-private.h \ pluma-print-job.h \ pluma-print-preview.h \ pluma-session.h \ + pluma-settings.h \ pluma-smart-charset-converter.h \ pluma-style-scheme-manager.h \ pluma-tab-label.h \ @@ -76,8 +76,6 @@ INST_H_FILES = \ pluma-message.h \ pluma-notebook.h \ pluma-panel.h \ - pluma-prefs-manager-app.h \ - pluma-prefs-manager.h \ pluma-progress-message-area.h \ pluma-statusbar.h \ pluma-status-combo-box.h \ @@ -126,13 +124,11 @@ libpluma_c_files = \ pluma-notebook.c \ pluma-panel.c \ pluma-plugins-engine.c \ - pluma-prefs-manager-app.c \ - pluma-prefs-manager.c \ - pluma-prefs-manager-private.h \ pluma-print-job.c \ pluma-print-preview.c \ pluma-progress-message-area.c \ pluma-session.c \ + pluma-settings.c \ pluma-smart-charset-converter.c \ pluma-statusbar.c \ pluma-status-combo-box.c \ diff --git a/pluma/dialogs/pluma-encodings-dialog.c b/pluma/dialogs/pluma-encodings-dialog.c index fe58ad54..cff41e2b 100644 --- a/pluma/dialogs/pluma-encodings-dialog.c +++ b/pluma/dialogs/pluma-encodings-dialog.c @@ -40,14 +40,16 @@ #include "pluma-encodings-dialog.h" #include "pluma-encodings.h" -#include "pluma-prefs-manager.h" #include "pluma-utils.h" #include "pluma-debug.h" #include "pluma-help.h" #include "pluma-dirs.h" +#include "pluma-settings.h" struct _PlumaEncodingsDialogPrivate { + GSettings *enc_settings; + GtkListStore *available_liststore; GtkListStore *displayed_liststore; GtkWidget *available_treeview; @@ -63,7 +65,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (PlumaEncodingsDialog, pluma_encodings_dialog, GTK_TY static void pluma_encodings_dialog_finalize (GObject *object) { - PlumaEncodingsDialogPrivate *priv = PLUMA_ENCODINGS_DIALOG (object)->priv; + PlumaEncodingsDialogPrivate *priv = pluma_encodings_dialog_get_instance_private (PLUMA_ENCODINGS_DIALOG(object)); g_slist_free (priv->show_in_menu_list); @@ -71,11 +73,22 @@ pluma_encodings_dialog_finalize (GObject *object) } static void +pluma_encodings_dialog_dispose (GObject *object) +{ + PlumaEncodingsDialogPrivate *priv = pluma_encodings_dialog_get_instance_private (PLUMA_ENCODINGS_DIALOG(object)); + + g_clear_object (&priv->enc_settings); + + G_OBJECT_CLASS (pluma_encodings_dialog_parent_class)->dispose (object); +} + +static void pluma_encodings_dialog_class_init (PlumaEncodingsDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = pluma_encodings_dialog_finalize; + object_class->dispose = pluma_encodings_dialog_dispose; } enum { @@ -232,14 +245,16 @@ static void init_shown_in_menu_tree_model (PlumaEncodingsDialog *dialog) { GtkTreeIter iter; + gchar **enc_strv; GSList *list, *tmp; /* add data to the list store */ - list = pluma_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (dialog->priv->enc_settings, + PLUMA_SETTINGS_ENCODING_SHOWN_IN_MENU); - tmp = list; + list = _pluma_encoding_strv_to_list ((const gchar * const *)enc_strv); - while (tmp != NULL) + for (tmp = list; tmp != NULL; tmp = g_slist_next (tmp)) { const PlumaEncoding *enc; @@ -256,10 +271,9 @@ init_shown_in_menu_tree_model (PlumaEncodingsDialog *dialog) pluma_encoding_get_charset (enc), COLUMN_NAME, pluma_encoding_get_name (enc), -1); - - tmp = g_slist_next (tmp); } + g_strfreev (enc_strv); g_slist_free (list); } @@ -277,8 +291,15 @@ response_handler (GtkDialog *dialog, if (response_id == GTK_RESPONSE_OK) { - g_return_if_fail (pluma_prefs_manager_shown_in_menu_encodings_can_set ()); - pluma_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list); + gchar **encs; + + encs = _pluma_encoding_list_to_strv (dlg->priv->show_in_menu_list); + + g_settings_set_strv (dlg->priv->enc_settings, + PLUMA_SETTINGS_ENCODING_SHOWN_IN_MENU, + (const gchar * const *)encs); + + g_strfreev (encs); } } @@ -303,6 +324,8 @@ pluma_encodings_dialog_init (PlumaEncodingsDialog *dlg) dlg->priv = pluma_encodings_dialog_get_instance_private (dlg); + dlg->priv->enc_settings = g_settings_new (PLUMA_SCHEMA_ID); + pluma_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel"), "process-stop", GTK_RESPONSE_CANCEL); pluma_dialog_add_button (GTK_DIALOG (dlg), _("_OK"), "gtk-ok", GTK_RESPONSE_OK); pluma_dialog_add_button (GTK_DIALOG (dlg), _("_Help"), "help-browser", GTK_RESPONSE_HELP); diff --git a/pluma/dialogs/pluma-preferences-dialog.c b/pluma/dialogs/pluma-preferences-dialog.c index 336ccb7d..246388e7 100644 --- a/pluma/dialogs/pluma-preferences-dialog.c +++ b/pluma/dialogs/pluma-preferences-dialog.c @@ -41,8 +41,6 @@ #include <gtksourceview/gtksource.h> #include <libpeas-gtk/peas-gtk-plugin-manager.h> -#include <pluma/pluma-prefs-manager.h> - #include "pluma-preferences-dialog.h" #include "pluma-utils.h" #include "pluma-debug.h" @@ -50,6 +48,8 @@ #include "pluma-style-scheme-manager.h" #include "pluma-help.h" #include "pluma-dirs.h" +#include "pluma-settings.h" +#include "pluma-utils.h" /* * pluma-preferences dialog is a singleton since we don't @@ -62,7 +62,6 @@ static GtkWidget *preferences_dialog = NULL; - enum { ID_COLUMN = 0, @@ -80,6 +79,8 @@ typedef enum struct _PlumaPreferencesDialogPrivate { + GSettings *editor_settings; + GtkWidget *notebook; /* Font */ @@ -138,12 +139,24 @@ struct _PlumaPreferencesDialogPrivate GtkWidget *plugin_manager_place_holder; }; - G_DEFINE_TYPE_WITH_PRIVATE (PlumaPreferencesDialog, pluma_preferences_dialog, GTK_TYPE_DIALOG) static void +pluma_preferences_dialog_dispose (GObject *object) +{ + PlumaPreferencesDialog *dlg = PLUMA_PREFERENCES_DIALOG (object); + + g_clear_object (&dlg->priv->editor_settings); + + G_OBJECT_CLASS (pluma_preferences_dialog_parent_class)->dispose (object); +} + +static void pluma_preferences_dialog_class_init (PlumaPreferencesDialogClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = pluma_preferences_dialog_dispose; } static void @@ -169,36 +182,13 @@ dialog_response_handler (GtkDialog *dlg, } static void -tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, - PlumaPreferencesDialog *dlg) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton)); - - pluma_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); -} - -static void -insert_spaces_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton)); - - pluma_prefs_manager_set_insert_spaces (gtk_toggle_button_get_active (button)); -} - -static void -auto_indent_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) +on_auto_save_changed (GSettings *settings, + const gchar *key, + PlumaPreferencesDialog *dlg) { - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton)); - - pluma_prefs_manager_set_auto_indent (gtk_toggle_button_get_active (button)); + gboolean value; + value = g_settings_get_boolean (settings, key); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, value); } static void @@ -206,6 +196,7 @@ draw_spaces_checkbutton_toggled (GtkToggleButton *button, PlumaPreferencesDialog *dlg) { DrawSpacesSettings setting; + pluma_debug (DEBUG_PREFS); g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->draw_spaces_checkbutton)); @@ -215,10 +206,12 @@ draw_spaces_checkbutton_toggled (GtkToggleButton *button, else setting = DRAW_NONE; - pluma_prefs_manager_set_draw_spaces (setting); + g_settings_set_enum (dlg->priv->editor_settings, PLUMA_SETTINGS_DRAWER_SPACE, setting); + #ifdef GTK_SOURCE_VERSION_3_24 if (setting == DRAW_NONE) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_spaces_checkbutton), setting > DRAW_NONE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), setting == DRAW_NONE); #endif @@ -233,13 +226,22 @@ draw_trailing_spaces_checkbutton_toggled (GtkToggleButton *button, g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton)); if (gtk_toggle_button_get_active (button)) - pluma_prefs_manager_set_draw_spaces (DRAW_TRAILING); + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_SPACE, + DRAW_TRAILING); else { - if (pluma_prefs_manager_get_draw_spaces ()) - pluma_prefs_manager_set_draw_spaces (DRAW_ALL); + gint draw_spaces = g_settings_get_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_SPACE); + + if (draw_spaces) + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_SPACE, + DRAW_ALL); else - pluma_prefs_manager_set_draw_spaces (DRAW_NONE); + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_SPACE, + DRAW_NONE); } } @@ -257,10 +259,13 @@ draw_tabs_checkbutton_toggled (GtkToggleButton *button, else setting = DRAW_NONE; - pluma_prefs_manager_set_draw_tabs (setting); + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_TAB, + setting); #ifdef GTK_SOURCE_VERSION_3_24 if (setting == DRAW_NONE) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET(dlg->priv->draw_trailing_tabs_checkbutton), setting > DRAW_NONE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON(dlg->priv->draw_trailing_tabs_checkbutton), setting == DRAW_NONE); #endif @@ -275,163 +280,109 @@ draw_trailing_tabs_checkbutton_toggled (GtkToggleButton *button, g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton)); if (gtk_toggle_button_get_active (button)) - pluma_prefs_manager_set_draw_tabs (DRAW_TRAILING); + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_TAB, + DRAW_TRAILING); else { - if (pluma_prefs_manager_get_draw_tabs ()) - pluma_prefs_manager_set_draw_tabs (DRAW_ALL); - else - pluma_prefs_manager_set_draw_tabs (DRAW_NONE); - } -} + gint draw_tabs = g_settings_get_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_TAB); -static void -draw_newlines_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->draw_newlines_checkbutton)); - - pluma_prefs_manager_set_draw_newlines (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton)); - - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - pluma_prefs_manager_auto_save_interval_can_set()); - - pluma_prefs_manager_set_auto_save (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); - pluma_prefs_manager_set_auto_save (FALSE); + if (draw_tabs) + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_TAB, + DRAW_ALL); + else + g_settings_set_enum (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_TAB, + DRAW_NONE); } } static void -backup_copy_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); - - pluma_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, - PlumaPreferencesDialog *dlg) -{ - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); - - pluma_prefs_manager_set_auto_save_interval ( - MAX (1, gtk_spin_button_get_value_as_int (spin_button))); -} - -static void setup_editor_page (PlumaPreferencesDialog *dlg) { gboolean auto_save; - gint auto_save_interval; pluma_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), - (guint) pluma_prefs_manager_get_tabs_size ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), - pluma_prefs_manager_get_insert_spaces ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), - pluma_prefs_manager_get_auto_indent ()); + /* Get values */ + auto_save = g_settings_get_boolean (dlg->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE); + + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, + auto_save); + + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_TABS_SIZE, + dlg->priv->tabs_width_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_INSERT_SPACES, + dlg->priv->insert_spaces_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_AUTO_INDENT, + dlg->priv->auto_indent_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_CREATE_BACKUP_COPY, + dlg->priv->backup_copy_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_BRACKET_MATCHING, + dlg->priv->bracket_matching_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE_INTERVAL, + dlg->priv->auto_save_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_signal_connect (dlg->priv->editor_settings, + "changed::auto-save", + G_CALLBACK (on_auto_save_changed), + dlg); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE, + dlg->priv->auto_save_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_DRAWER_NEWLINE, + dlg->priv->draw_newlines_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + + gint draw_spaces = g_settings_get_enum (dlg->priv->editor_settings, PLUMA_SETTINGS_DRAWER_SPACE); + gint draw_tabs = g_settings_get_enum (dlg->priv->editor_settings, PLUMA_SETTINGS_DRAWER_TAB); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_spaces_checkbutton), - pluma_prefs_manager_get_draw_spaces () > DRAW_NONE); + draw_spaces > DRAW_NONE); #ifdef GTK_SOURCE_VERSION_3_24 - gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_spaces_checkbutton), - pluma_prefs_manager_get_draw_spaces () > DRAW_NONE); - gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), - pluma_prefs_manager_get_draw_spaces () == DRAW_NONE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), - pluma_prefs_manager_get_draw_spaces () == DRAW_TRAILING); + gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_spaces_checkbutton), draw_spaces > DRAW_NONE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), draw_spaces == DRAW_NONE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), draw_spaces == DRAW_TRAILING); #else gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_spaces_checkbutton), FALSE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_spaces_checkbutton), FALSE); #endif - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_tabs_checkbutton), - pluma_prefs_manager_get_draw_tabs () > DRAW_NONE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_tabs_checkbutton), draw_tabs > DRAW_NONE); #ifdef GTK_SOURCE_VERSION_3_24 - gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_tabs_checkbutton), - pluma_prefs_manager_get_draw_tabs () > DRAW_NONE); - gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), - pluma_prefs_manager_get_draw_tabs () == DRAW_NONE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), - pluma_prefs_manager_get_draw_tabs () == DRAW_TRAILING); + gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_tabs_checkbutton), draw_tabs > DRAW_NONE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), draw_tabs == DRAW_NONE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), draw_tabs == DRAW_TRAILING); #else gtk_widget_set_sensitive (GTK_WIDGET (dlg->priv->draw_trailing_tabs_checkbutton), FALSE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_trailing_tabs_checkbutton), FALSE); #endif - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->draw_newlines_checkbutton), - pluma_prefs_manager_get_draw_newlines ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), - pluma_prefs_manager_get_create_backup_copy ()); - - auto_save = pluma_prefs_manager_get_auto_save (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), - auto_save); - - auto_save_interval = pluma_prefs_manager_get_auto_save_interval (); - if (auto_save_interval <= 0) - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), - auto_save_interval); - - /* Set widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, - pluma_prefs_manager_tabs_size_can_set ()); - gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, - pluma_prefs_manager_insert_spaces_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, - pluma_prefs_manager_auto_indent_can_set ()); - gtk_widget_set_sensitive (dlg->priv->draw_spaces_checkbutton, - pluma_prefs_manager_draw_spaces_can_set ()); - gtk_widget_set_sensitive (dlg->priv->draw_tabs_checkbutton, - pluma_prefs_manager_draw_tabs_can_set ()); - gtk_widget_set_sensitive (dlg->priv->draw_newlines_checkbutton, - pluma_prefs_manager_draw_newlines_can_set ()); - gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, - pluma_prefs_manager_create_backup_copy_can_set ()); - gtk_widget_set_sensitive (dlg->priv->autosave_hbox, - pluma_prefs_manager_auto_save_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - auto_save && - pluma_prefs_manager_auto_save_interval_can_set ()); - /* Connect signal */ - g_signal_connect (dlg->priv->tabs_width_spinbutton, - "value_changed", - G_CALLBACK (tabs_width_spinbutton_value_changed), - dlg); - g_signal_connect (dlg->priv->insert_spaces_checkbutton, - "toggled", - G_CALLBACK (insert_spaces_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->auto_indent_checkbutton, - "toggled", - G_CALLBACK (auto_indent_checkbutton_toggled), - dlg); g_signal_connect (dlg->priv->draw_spaces_checkbutton, "toggled", G_CALLBACK (draw_spaces_checkbutton_toggled), @@ -448,53 +399,6 @@ setup_editor_page (PlumaPreferencesDialog *dlg) "toggled", G_CALLBACK (draw_trailing_tabs_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->draw_newlines_checkbutton, - "toggled", - G_CALLBACK (draw_newlines_checkbutton_toggled), - 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 -display_line_numbers_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); - - pluma_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); -} - -static void -highlight_current_line_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); - - pluma_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); -} - -static void -bracket_matching_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) -{ - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); - - pluma_prefs_manager_set_bracket_matching ( - gtk_toggle_button_get_active (button)); } static gboolean split_button_state = TRUE; @@ -503,37 +407,39 @@ static void wrap_mode_checkbutton_toggled (GtkToggleButton *button, PlumaPreferencesDialog *dlg) { + GtkWrapMode mode; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) { - pluma_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); + mode = GTK_WRAP_NONE; - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - FALSE); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, FALSE); + + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); } else { - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - TRUE); - - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, TRUE); + 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))) { split_button_state = TRUE; - pluma_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); + mode = GTK_WRAP_WORD; } else { split_button_state = FALSE; - pluma_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); + mode = GTK_WRAP_CHAR; } } + + pluma_settings_set_wrap_mode (dlg->priv->editor_settings, + PLUMA_SETTINGS_WRAP_MODE, + mode); } static void @@ -546,24 +452,12 @@ right_margin_checkbutton_toggled (GtkToggleButton *button, active = gtk_toggle_button_get_active (button); - pluma_prefs_manager_set_display_right_margin (active); - - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - active && - pluma_prefs_manager_right_margin_position_can_set ()); -} - -static void -right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, - PlumaPreferencesDialog *dlg) -{ - gint value; - - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); + g_settings_set_boolean (dlg->priv->editor_settings, PLUMA_SETTINGS_DISPLAY_RIGHT_MARGIN, + active); - value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); - pluma_prefs_manager_set_right_margin_position (value); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, + active); } static void @@ -571,22 +465,18 @@ setup_view_page (PlumaPreferencesDialog *dlg) { GtkWrapMode wrap_mode; gboolean display_right_margin; - gboolean wrap_mode_can_set; pluma_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), - pluma_prefs_manager_get_display_line_numbers ()); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), - pluma_prefs_manager_get_highlight_current_line ()); + /* Get values */ + display_right_margin = g_settings_get_boolean (dlg->priv->editor_settings, + PLUMA_SETTINGS_DISPLAY_RIGHT_MARGIN); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), - pluma_prefs_manager_get_bracket_matching ()); + /* Set initial state */ + wrap_mode = pluma_settings_get_wrap_mode (dlg->priv->editor_settings, + PLUMA_SETTINGS_WRAP_MODE); - wrap_mode = pluma_prefs_manager_get_wrap_mode (); - switch (wrap_mode ) + switch (wrap_mode) { case GTK_WRAP_WORD: gtk_toggle_button_set_active ( @@ -610,48 +500,35 @@ setup_view_page (PlumaPreferencesDialog *dlg) } - display_right_margin = pluma_prefs_manager_get_display_right_margin (); - - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), - display_right_margin); - - gtk_spin_button_set_value ( - GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), - (guint)CLAMP (pluma_prefs_manager_get_right_margin_position (), 1, 160)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), + display_right_margin); /* Set widgets sensitivity */ - gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, - pluma_prefs_manager_display_line_numbers_can_set ()); - gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, - pluma_prefs_manager_highlight_current_line_can_set ()); - gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, - pluma_prefs_manager_bracket_matching_can_set ()); - wrap_mode_can_set = pluma_prefs_manager_wrap_mode_can_set (); - gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, - 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->right_margin_checkbutton, - pluma_prefs_manager_display_right_margin_can_set ()); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - display_right_margin && - pluma_prefs_manager_right_margin_position_can_set ()); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, (wrap_mode != GTK_WRAP_NONE)); + + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, display_right_margin); + + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_DISPLAY_LINE_NUMBERS, + dlg->priv->display_line_numbers_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_HIGHLIGHT_CURRENT_LINE, + dlg->priv->highlight_current_line_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_RIGHT_MARGIN_POSITION, + dlg->priv->right_margin_position_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE_INTERVAL, + dlg->priv->auto_save_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); - /* Connect signals */ - g_signal_connect (dlg->priv->display_line_numbers_checkbutton, - "toggled", - G_CALLBACK (display_line_numbers_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->highlight_current_line_checkbutton, - "toggled", - G_CALLBACK (highlight_current_line_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->bracket_matching_checkbutton, - "toggled", - G_CALLBACK (bracket_matching_checkbutton_toggled), - dlg); g_signal_connect (dlg->priv->wrap_text_checkbutton, "toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), @@ -664,59 +541,28 @@ setup_view_page (PlumaPreferencesDialog *dlg) "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 -default_font_font_checkbutton_toggled (GtkToggleButton *button, - PlumaPreferencesDialog *dlg) +on_use_default_font_changed (GSettings *settings, + const gchar *key, + PlumaPreferencesDialog *dlg) { - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton)); - - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - pluma_prefs_manager_set_use_default_font (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, - pluma_prefs_manager_editor_font_can_set ()); - pluma_prefs_manager_set_use_default_font (FALSE); - } -} - -static void -editor_font_button_font_set (GtkFontChooser *font_button, - PlumaPreferencesDialog *dlg) -{ - const gchar *font_name; + gboolean value; pluma_debug (DEBUG_PREFS); - g_return_if_fail (font_button == GTK_FONT_CHOOSER (dlg->priv->font_button)); - - /* FIXME: Can this fail? Gtk docs are a bit terse... 21-02-2004 pbor */ - font_name = gtk_font_chooser_get_font (font_button); - if (!font_name) - { - g_warning ("Could not get font name"); - return; - } + value = g_settings_get_boolean (settings, key); - pluma_prefs_manager_set_editor_font (font_name); + gtk_widget_set_sensitive (dlg->priv->font_hbox, !value); } static void setup_font_colors_page_font_section (PlumaPreferencesDialog *dlg) { + PlumaSettings *settings; gboolean use_default_font; - gchar *editor_font = NULL; + gchar *system_font = NULL; gchar *label; pluma_debug (DEBUG_PREFS); @@ -731,46 +577,40 @@ setup_font_colors_page_font_section (PlumaPreferencesDialog *dlg) dlg->priv->font_button, ATK_RELATION_CONTROLLER_FOR); - editor_font = pluma_prefs_manager_get_system_font (); - label = g_strdup_printf(_("_Use the system fixed width font (%s)"), - editor_font); + /* Get values */ + settings = _pluma_settings_get_singleton (); + system_font = pluma_settings_get_system_font (settings); + use_default_font = g_settings_get_boolean (dlg->priv->editor_settings, + PLUMA_SETTINGS_USE_DEFAULT_FONT); + + label = g_strdup_printf(_("_Use the system fixed width font (%s)"), system_font); gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton), label); - g_free (editor_font); + g_free (system_font); g_free (label); /* read current config and setup initial state */ - use_default_font = pluma_prefs_manager_get_use_default_font (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), use_default_font); - editor_font = pluma_prefs_manager_get_editor_font (); - if (editor_font != NULL) - { - gtk_font_chooser_set_font (GTK_FONT_CHOOSER (dlg->priv->font_button), - editor_font); - g_free (editor_font); - } - /* Connect signals */ - g_signal_connect (dlg->priv->default_font_checkbutton, - "toggled", - G_CALLBACK (default_font_font_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->font_button, - "font_set", - G_CALLBACK (editor_font_button_font_set), + g_signal_connect (dlg->priv->editor_settings, + "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), dlg); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_USE_DEFAULT_FONT, + dlg->priv->default_font_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor_settings, + PLUMA_SETTINGS_EDITOR_FONT, + dlg->priv->font_button, + "font-name", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); /* Set initial widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, - pluma_prefs_manager_use_default_font_can_set ()); - - if (use_default_font) - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - else - gtk_widget_set_sensitive (dlg->priv->font_hbox, - pluma_prefs_manager_editor_font_can_set ()); + gtk_widget_set_sensitive (dlg->priv->font_hbox, !use_default_font); } static void @@ -784,8 +624,7 @@ set_buttons_sensisitivity_according_to_scheme (PlumaPreferencesDialog *dlg, pluma_get_style_scheme_manager (), scheme_id); - gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, - editable); + gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, editable); } static void @@ -803,7 +642,7 @@ style_scheme_changed (GtkWidget *treeview, gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, ID_COLUMN, &id, -1); - pluma_prefs_manager_set_source_style_scheme (id); + g_settings_set_string (dlg->priv->editor_settings, PLUMA_SETTINGS_COLOR_SCHEME, id); set_buttons_sensisitivity_according_to_scheme (dlg, id); @@ -811,7 +650,8 @@ style_scheme_changed (GtkWidget *treeview, } static const gchar * -ensure_color_scheme_id (const gchar *id) +ensure_color_scheme_id (PlumaPreferencesDialog *dlg, + const gchar *id) { GtkSourceStyleScheme *scheme = NULL; GtkSourceStyleSchemeManager *manager = pluma_get_style_scheme_manager (); @@ -820,7 +660,9 @@ ensure_color_scheme_id (const gchar *id) { gchar *pref_id; - pref_id = pluma_prefs_manager_get_source_style_scheme (); + pref_id = g_settings_get_string (dlg->priv->editor_settings, + PLUMA_SETTINGS_COLOR_SCHEME); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, pref_id); g_free (pref_id); @@ -858,7 +700,7 @@ populate_color_scheme_list (PlumaPreferencesDialog *dlg, const gchar *def_id) gtk_list_store_clear (dlg->priv->schemes_treeview_model); - def_id = ensure_color_scheme_id (def_id); + def_id = ensure_color_scheme_id (dlg, def_id); if (def_id == NULL) { g_warning ("Cannot build the list of available color schemes.\n" @@ -940,7 +782,8 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, return; } - pluma_prefs_manager_set_source_style_scheme (scheme_id); + g_settings_set_string (dlg->priv->editor_settings, PLUMA_SETTINGS_COLOR_SCHEME, + scheme_id); scheme_id = populate_color_scheme_list (dlg, scheme_id); @@ -1132,7 +975,12 @@ uninstall_scheme_clicked (GtkButton *button, set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); if (real_new_id != NULL) - pluma_prefs_manager_set_source_style_scheme (real_new_id); + { + g_settings_set_string (dlg->priv->editor_settings, + PLUMA_SETTINGS_COLOR_SCHEME, + real_new_id); + } + } g_free (id); @@ -1346,6 +1194,8 @@ pluma_preferences_dialog_init (PlumaPreferencesDialog *dlg) dlg->priv = pluma_preferences_dialog_get_instance_private (dlg); + dlg->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + pluma_dialog_add_button (GTK_DIALOG (dlg), _("_Close"), "window-close", GTK_RESPONSE_CLOSE); pluma_dialog_add_button (GTK_DIALOG (dlg), _("_Help"), "help-browser", GTK_RESPONSE_HELP); @@ -1425,11 +1275,11 @@ pluma_preferences_dialog_init (PlumaPreferencesDialog *dlg) g_object_unref (dlg->priv->notebook); gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5); - gtk_widget_add_events (dlg->priv->notebook, GDK_SCROLL_MASK); - g_signal_connect (dlg->priv->notebook, - "scroll-event", - G_CALLBACK (on_notebook_scroll_event), - NULL); + gtk_widget_add_events (dlg->priv->notebook, GDK_SCROLL_MASK); + g_signal_connect (dlg->priv->notebook, + "scroll-event", + G_CALLBACK (on_notebook_scroll_event), + NULL); setup_editor_page (dlg); setup_view_page (dlg); diff --git a/pluma/pluma-app.c b/pluma/pluma-app.c index c9d2e614..60ce9bac 100644 --- a/pluma/pluma-app.c +++ b/pluma/pluma-app.c @@ -39,13 +39,13 @@ #include <gdk/gdk.h> #include <gdk/gdkx.h> #include "pluma-app.h" -#include "pluma-prefs-manager-app.h" #include "pluma-commands.h" #include "pluma-notebook.h" #include "pluma-debug.h" #include "pluma-utils.h" #include "pluma-enum-types.h" #include "pluma-dirs.h" +#include "pluma-settings.h" #define PLUMA_PAGE_SETUP_FILE "pluma-page-setup" #define PLUMA_PRINT_SETTINGS_FILE "pluma-print-settings" @@ -66,6 +66,8 @@ struct _PlumaAppPrivate GtkPageSetup *page_setup; GtkPrintSettings *print_settings; + + GSettings *window_settings; }; G_DEFINE_TYPE_WITH_PRIVATE (PlumaApp, pluma_app, G_TYPE_OBJECT) @@ -86,6 +88,17 @@ pluma_app_finalize (GObject *object) } static void +pluma_app_dispose (GObject *object) +{ + PlumaApp *app = PLUMA_APP (object); + + g_clear_object (&app->priv->window_settings); + + G_OBJECT_CLASS (pluma_app_parent_class)->dispose (object); +} + + +static void pluma_app_get_property (GObject *object, guint prop_id, GValue *value, @@ -110,6 +123,7 @@ pluma_app_class_init (PlumaAppClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = pluma_app_finalize; + object_class->dispose = pluma_app_dispose; object_class->get_property = pluma_app_get_property; g_object_class_install_property (object_class, @@ -326,12 +340,18 @@ save_print_settings (PlumaApp *app) static void pluma_app_init (PlumaApp *app) { + PlumaSettings *settings; + app->priv = pluma_app_get_instance_private (app); load_accels (); + /* Load/init settings */ + settings = _pluma_settings_get_singleton (); + app->priv->window_settings = g_settings_new (PLUMA_SCHEMA_ID); + /* initial lockdown state */ - app->priv->lockdown = pluma_prefs_manager_get_lockdown (); + app->priv->lockdown = pluma_settings_get_lockdown (settings); } static void @@ -504,17 +524,20 @@ pluma_app_create_window_real (PlumaApp *app, GdkWindowState state; gint w, h; - state = pluma_prefs_manager_get_window_state (); + state = g_settings_get_int (app->priv->window_settings, + PLUMA_SETTINGS_WINDOW_STATE); if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { - pluma_prefs_manager_get_default_window_size (&w, &h); + _pluma_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_maximize (GTK_WINDOW (window)); } else { - pluma_prefs_manager_get_window_size (&w, &h); + g_settings_get (app->priv->window_settings, + PLUMA_SETTINGS_WINDOW_SIZE, + "(ii)", &w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_unmaximize (GTK_WINDOW (window)); } diff --git a/pluma/pluma-app.h b/pluma/pluma-app.h index 22af85bd..8269d3a9 100644 --- a/pluma/pluma-app.h +++ b/pluma/pluma-app.h @@ -96,6 +96,7 @@ PlumaWindow *pluma_app_create_window (PlumaApp *app, GdkScreen *screen); const GList *pluma_app_get_windows (PlumaApp *app); + PlumaWindow *pluma_app_get_active_window (PlumaApp *app); /* Returns a newly allocated list with all the documents */ diff --git a/pluma/pluma-document-loader.c b/pluma/pluma-document-loader.c index aea0296f..ed551666 100644 --- a/pluma/pluma-document-loader.c +++ b/pluma/pluma-document-loader.c @@ -40,12 +40,12 @@ #include "pluma-document-loader.h" #include "pluma-document-output-stream.h" #include "pluma-smart-charset-converter.h" -#include "pluma-prefs-manager.h" #include "pluma-debug.h" #include "pluma-metadata-manager.h" #include "pluma-utils.h" #include "pluma-marshal.h" #include "pluma-enum-types.h" +#include "pluma-settings.h" #ifndef ENABLE_GVFS_METADATA #include "pluma-metadata-manager.h" @@ -92,6 +92,8 @@ static void open_async_read (AsyncData *async); struct _PlumaDocumentLoaderPrivate { + GSettings *enc_settings; + PlumaDocument *document; gboolean used; @@ -234,6 +236,8 @@ pluma_document_loader_dispose (GObject *object) priv->info = NULL; } + g_clear_object (&priv->enc_settings); + G_OBJECT_CLASS (pluma_document_loader_parent_class)->dispose (object); } @@ -309,6 +313,7 @@ pluma_document_loader_init (PlumaDocumentLoader *loader) loader->priv->auto_detected_newline_type = PLUMA_DOCUMENT_NEWLINE_TYPE_DEFAULT; loader->priv->converter = NULL; loader->priv->error = NULL; + loader->priv->enc_settings = g_settings_new (PLUMA_SCHEMA_ID); } PlumaDocumentLoader * @@ -585,9 +590,14 @@ static GSList * get_candidate_encodings (PlumaDocumentLoader *loader) { const PlumaEncoding *metadata; - GSList *encodings = NULL; + GSList *encodings; + gchar **enc_strv; + + enc_strv = g_settings_get_strv (loader->priv->enc_settings, + PLUMA_SETTINGS_ENCODING_AUTO_DETECTED); - encodings = pluma_prefs_manager_get_auto_detected_encodings (); + encodings = _pluma_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_strfreev (enc_strv); metadata = get_metadata_encoding (loader); if (metadata != NULL) diff --git a/pluma/pluma-document-saver.c b/pluma/pluma-document-saver.c index 913444d7..c215275c 100644 --- a/pluma/pluma-document-saver.c +++ b/pluma/pluma-document-saver.c @@ -38,11 +38,11 @@ #include "pluma-document-saver.h" #include "pluma-document-input-stream.h" -#include "pluma-prefs-manager.h" #include "pluma-debug.h" #include "pluma-marshal.h" #include "pluma-utils.h" #include "pluma-enum-types.h" +#include "pluma-settings.h" #define WRITE_CHUNK_SIZE 8192 @@ -85,6 +85,8 @@ static void check_modified_async (AsyncData *async); struct _PlumaDocumentSaverPrivate { + GSettings *editor_settings; + GFileInfo *info; PlumaDocument *document; gboolean used; @@ -223,6 +225,8 @@ pluma_document_saver_dispose (GObject *object) priv->info = NULL; } + g_clear_object (&priv->editor_settings); + G_OBJECT_CLASS (pluma_document_saver_parent_class)->dispose (object); } @@ -340,6 +344,7 @@ pluma_document_saver_init (PlumaDocumentSaver *saver) saver->priv->cancellable = g_cancellable_new (); saver->priv->error = NULL; saver->priv->used = FALSE; + saver->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); } PlumaDocumentSaver * @@ -945,7 +950,8 @@ pluma_document_saver_save (PlumaDocumentSaver *saver, if ((saver->priv->flags & PLUMA_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0) saver->priv->keep_backup = FALSE; else - saver->priv->keep_backup = pluma_prefs_manager_get_create_backup_copy (); + saver->priv->keep_backup = g_settings_get_boolean (saver->priv->editor_settings, + PLUMA_SETTINGS_CREATE_BACKUP_COPY); saver->priv->old_mtime = *old_mtime; saver->priv->gfile = g_file_new_for_uri (saver->priv->uri); diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 0e877668..49a9dad9 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -40,7 +40,7 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> -#include "pluma-prefs-manager-app.h" +#include "pluma-settings.h" #include "pluma-document.h" #include "pluma-debug.h" #include "pluma-utils.h" @@ -99,6 +99,8 @@ static void delete_range_cb (PlumaDocument *doc, struct _PlumaDocumentPrivate { + GSettings *editor_settings; + gchar *uri; gint untitled_number; gchar *short_name; @@ -279,6 +281,8 @@ pluma_document_dispose (GObject *object) doc->priv->metadata_info = NULL; } + g_clear_object (&doc->priv->editor_settings); + doc->priv->dispose_has_run = TRUE; G_OBJECT_CLASS (pluma_document_parent_class)->dispose (object); @@ -720,8 +724,15 @@ set_language (PlumaDocument *doc, gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang); if (lang != NULL) + { + gboolean syntax_hl; + + syntax_hl = g_settings_get_boolean (doc->priv->editor_settings, + PLUMA_SETTINGS_SYNTAX_HIGHLIGHTING); + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), - pluma_prefs_manager_get_enable_syntax_highlighting ()); + syntax_hl); + } else gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), FALSE); @@ -764,14 +775,14 @@ set_encoding (PlumaDocument *doc, } static GtkSourceStyleScheme * -get_default_style_scheme (void) +get_default_style_scheme (GSettings *editor_settings) { gchar *scheme_id; GtkSourceStyleScheme *def_style; GtkSourceStyleSchemeManager *manager; manager = pluma_get_style_scheme_manager (); - scheme_id = pluma_prefs_manager_get_source_style_scheme (); + scheme_id = g_settings_get_string (editor_settings, PLUMA_SETTINGS_COLOR_SCHEME); def_style = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); @@ -918,11 +929,16 @@ static void pluma_document_init (PlumaDocument *doc) { GtkSourceStyleScheme *style_scheme; + gint undo_actions; + gboolean bracket_matching; + gboolean search_hl; pluma_debug (DEBUG_DOCUMENT); doc->priv = pluma_document_get_instance_private (doc); + doc->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + doc->priv->uri = NULL; doc->priv->untitled_number = get_untitled_number (); @@ -947,16 +963,23 @@ pluma_document_init (PlumaDocument *doc) doc->priv->newline_type = PLUMA_DOCUMENT_NEWLINE_TYPE_DEFAULT; + undo_actions = g_settings_get_uint (doc->priv->editor_settings, PLUMA_SETTINGS_MAX_UNDO_ACTIONS); + + bracket_matching = g_settings_get_boolean (doc->priv->editor_settings, + PLUMA_SETTINGS_BRACKET_MATCHING); + search_hl = g_settings_get_boolean (doc->priv->editor_settings, + PLUMA_SETTINGS_SEARCH_HIGHLIGHTING); + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), - pluma_prefs_manager_get_undo_actions_limit ()); + undo_actions); gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), - pluma_prefs_manager_get_bracket_matching ()); + bracket_matching); - pluma_document_set_enable_search_highlighting (doc, - pluma_prefs_manager_get_enable_search_highlighting ()); + pluma_document_set_enable_search_highlighting (doc, search_hl); - style_scheme = get_default_style_scheme (); + + style_scheme = get_default_style_scheme (doc->priv->editor_settings); if (style_scheme != NULL) gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); @@ -1334,6 +1357,7 @@ document_loader_loaded (PlumaDocumentLoader *loader, { GtkTextIter iter; GFileInfo *info; + gboolean restore_cursor; const gchar *content_type = NULL; gboolean read_only = FALSE; guint64 mtime = 0; @@ -1379,6 +1403,9 @@ document_loader_loaded (PlumaDocumentLoader *loader, pluma_document_set_newline_type (doc, pluma_document_loader_get_newline_type (loader)); + restore_cursor = g_settings_get_boolean (doc->priv->editor_settings, + PLUMA_SETTINGS_RESTORE_CURSOR_POSITION); + /* move the cursor at the requested line if any */ if (doc->priv->requested_line_pos > 0) { @@ -1388,7 +1415,7 @@ document_loader_loaded (PlumaDocumentLoader *loader, doc->priv->requested_line_pos - 1); } /* else, if enabled, to the position stored in the metadata */ - else if (pluma_prefs_manager_get_restore_cursor_position ()) + else if (restore_cursor) { gchar *pos; gint offset; diff --git a/pluma/pluma-encodings-combo-box.c b/pluma/pluma-encodings-combo-box.c index 452fd46f..6d0e2fb5 100644 --- a/pluma/pluma-encodings-combo-box.c +++ b/pluma/pluma-encodings-combo-box.c @@ -37,11 +37,14 @@ #include <gtk/gtk.h> #include <pluma/pluma-encodings-combo-box.h> -#include <pluma/pluma-prefs-manager.h> #include <pluma/dialogs/pluma-encodings-dialog.h> +#include "pluma-settings.h" +#include "pluma-utils.h" struct _PlumaEncodingsComboBoxPrivate { + GSettings *enc_settings; + GtkListStore *store; glong changed_id; @@ -123,6 +126,8 @@ pluma_encodings_combo_box_dispose (GObject *object) combo->priv->store = NULL; } + g_clear_object (&combo->priv->enc_settings); + G_OBJECT_CLASS (pluma_encodings_combo_box_parent_class)->dispose (object); } @@ -245,6 +250,7 @@ update_menu (PlumaEncodingsComboBox *menu) gchar *str; const PlumaEncoding *utf8_encoding; const PlumaEncoding *current_encoding; + gchar **enc_strv; store = menu->priv->store; @@ -305,7 +311,11 @@ update_menu (PlumaEncodingsComboBox *menu) g_free (str); } - encodings = pluma_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (menu->priv->enc_settings, + PLUMA_SETTINGS_ENCODING_SHOWN_IN_MENU); + + encodings = _pluma_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_strfreev (enc_strv); for (l = encodings; l != NULL; l = g_slist_next (l)) { @@ -330,23 +340,20 @@ update_menu (PlumaEncodingsComboBox *menu) g_slist_free (encodings); - if (pluma_prefs_manager_shown_in_menu_encodings_can_set ()) - { - gtk_list_store_append (store, &iter); - /* separator */ - gtk_list_store_set (store, &iter, - NAME_COLUMN, "", - ENCODING_COLUMN, NULL, - ADD_COLUMN, FALSE, - -1); + gtk_list_store_append (store, &iter); + /* separator */ + gtk_list_store_set (store, &iter, + NAME_COLUMN, "", + ENCODING_COLUMN, NULL, + ADD_COLUMN, FALSE, + -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, _("Add or Remove..."), - ENCODING_COLUMN, NULL, - ADD_COLUMN, TRUE, - -1); - } + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, _("Add or Remove..."), + ENCODING_COLUMN, NULL, + ADD_COLUMN, TRUE, + -1); /* set the model back */ gtk_combo_box_set_model (GTK_COMBO_BOX (menu), @@ -363,6 +370,8 @@ pluma_encodings_combo_box_init (PlumaEncodingsComboBox *menu) menu->priv = pluma_encodings_combo_box_get_instance_private (menu); + menu->priv->enc_settings = g_settings_new (PLUMA_SCHEMA_ID); + menu->priv->store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, diff --git a/pluma/pluma-encodings.c b/pluma/pluma-encodings.c index 592bcf8f..78a9bd83 100644 --- a/pluma/pluma-encodings.c +++ b/pluma/pluma-encodings.c @@ -471,3 +471,71 @@ pluma_encoding_get_type (void) return our_type; } +static gboolean +data_exists (GSList *list, const gpointer data) +{ + while (list != NULL) + { + if (list->data == data) + return TRUE; + + list = g_slist_next (list); + } + + return FALSE; +} + +GSList * +_pluma_encoding_strv_to_list (const gchar * const *enc_str) +{ + GSList *res = NULL; + gchar **p; + const PlumaEncoding *enc; + + for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++) + { + const gchar *charset = *p; + + if (strcmp (charset, "CURRENT") == 0) + g_get_charset (&charset); + + g_return_val_if_fail (charset != NULL, NULL); + enc = pluma_encoding_get_from_charset (charset); + + if (enc != NULL) + { + if (!data_exists (res, (gpointer)enc)) + res = g_slist_prepend (res, (gpointer)enc); + + } + } + + return g_slist_reverse (res); +} + +gchar ** +_pluma_encoding_list_to_strv (const GSList *enc_list) +{ + GSList *l; + GPtrArray *array; + + array = g_ptr_array_sized_new (g_slist_length ((GSList *)enc_list) + 1); + + for (l = (GSList *)enc_list; l != NULL; l = g_slist_next (l)) + { + const PlumaEncoding *enc; + const gchar *charset; + + enc = (const PlumaEncoding *)l->data; + + charset = pluma_encoding_get_charset (enc); + g_return_val_if_fail (charset != NULL, NULL); + + g_ptr_array_add (array, g_strdup (charset)); + } + + g_ptr_array_add (array, NULL); + + return (gchar **)g_ptr_array_free (array, FALSE); +} + diff --git a/pluma/pluma-encodings.h b/pluma/pluma-encodings.h index 0b3a3123..fb40efc1 100644 --- a/pluma/pluma-encodings.h +++ b/pluma/pluma-encodings.h @@ -38,24 +38,27 @@ G_BEGIN_DECLS typedef struct _PlumaEncoding PlumaEncoding; -#define PLUMA_TYPE_ENCODING (pluma_encoding_get_type ()) +#define PLUMA_TYPE_ENCODING (pluma_encoding_get_type ()) -GType pluma_encoding_get_type (void) G_GNUC_CONST; +GType pluma_encoding_get_type (void) G_GNUC_CONST; -const PlumaEncoding *pluma_encoding_get_from_charset (const gchar *charset); -const PlumaEncoding *pluma_encoding_get_from_index (gint index); +const PlumaEncoding *pluma_encoding_get_from_charset (const gchar *charset); +const PlumaEncoding *pluma_encoding_get_from_index (gint index); -gchar *pluma_encoding_to_string (const PlumaEncoding *enc); +gchar *pluma_encoding_to_string (const PlumaEncoding *enc); -const gchar *pluma_encoding_get_name (const PlumaEncoding *enc); -const gchar *pluma_encoding_get_charset (const PlumaEncoding *enc); +const gchar *pluma_encoding_get_name (const PlumaEncoding *enc); +const gchar *pluma_encoding_get_charset (const PlumaEncoding *enc); -const PlumaEncoding *pluma_encoding_get_utf8 (void); -const PlumaEncoding *pluma_encoding_get_current (void); +const PlumaEncoding *pluma_encoding_get_utf8 (void); +const PlumaEncoding *pluma_encoding_get_current (void); /* These should not be used, they are just to make python bindings happy */ -PlumaEncoding *pluma_encoding_copy (const PlumaEncoding *enc); -void pluma_encoding_free (PlumaEncoding *enc); +PlumaEncoding *pluma_encoding_copy (const PlumaEncoding *enc); +void pluma_encoding_free (PlumaEncoding *enc); + +GSList *_pluma_encoding_strv_to_list (const gchar * const *enc_str); +gchar **_pluma_encoding_list_to_strv (const GSList *enc); G_END_DECLS diff --git a/pluma/pluma-file-chooser-dialog.c b/pluma/pluma-file-chooser-dialog.c index b51e48c2..290821d4 100644 --- a/pluma/pluma-file-chooser-dialog.c +++ b/pluma/pluma-file-chooser-dialog.c @@ -44,16 +44,18 @@ #include "pluma-file-chooser-dialog.h" #include "pluma-encodings-combo-box.h" #include "pluma-language-manager.h" -#include "pluma-prefs-manager-app.h" #include "pluma-debug.h" #include "pluma-enum-types.h" #include "pluma-utils.h" +#include "pluma-settings.h" #define ALL_FILES _("All Files") #define ALL_TEXT_FILES _("All Text Files") struct _PlumaFileChooserDialogPrivate { + GSettings *filter_settings; + GtkWidget *option_menu; GtkWidget *extra_widget; @@ -65,8 +67,21 @@ struct _PlumaFileChooserDialogPrivate G_DEFINE_TYPE_WITH_PRIVATE (PlumaFileChooserDialog, pluma_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG) static void +pluma_file_chooser_dialog_dispose (GObject *object) +{ + PlumaFileChooserDialog *dialog = PLUMA_FILE_CHOOSER_DIALOG (object); + + g_clear_object (&dialog->priv->filter_settings); + + G_OBJECT_CLASS (pluma_file_chooser_dialog_parent_class)->dispose (object); +} + +static void pluma_file_chooser_dialog_class_init (PlumaFileChooserDialogClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = pluma_file_chooser_dialog_dispose; } static void @@ -247,9 +262,6 @@ filter_changed (PlumaFileChooserDialog *dialog, { GtkFileFilter *filter; - if (!pluma_prefs_manager_active_file_filter_can_set ()) - return; - filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); if (filter != NULL) { @@ -264,7 +276,9 @@ filter_changed (PlumaFileChooserDialog *dialog, pluma_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); - pluma_prefs_manager_set_active_file_filter (id); + g_settings_set_int (dialog->priv->filter_settings, + PLUMA_SETTINGS_ACTIVE_FILE_FILTER, id); + } } @@ -350,6 +364,8 @@ static void pluma_file_chooser_dialog_init (PlumaFileChooserDialog *dialog) { dialog->priv = pluma_file_chooser_dialog_get_instance_private (dialog); + + dialog->priv->filter_settings = g_settings_new (PLUMA_SCHEMA_ID); } static GtkWidget * @@ -387,7 +403,8 @@ pluma_file_chooser_dialog_new_valist (const gchar *title, PLUMA_ENCODINGS_COMBO_BOX (PLUMA_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding); - active_filter = pluma_prefs_manager_get_active_file_filter (); + active_filter = g_settings_get_int (PLUMA_FILE_CHOOSER_DIALOG (result)->priv->filter_settings, + PLUMA_SETTINGS_ACTIVE_FILE_FILTER); pluma_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); /* Filters */ diff --git a/pluma/pluma-history-entry.c b/pluma/pluma-history-entry.c index 3dacc123..dff15d1a 100644 --- a/pluma/pluma-history-entry.c +++ b/pluma/pluma-history-entry.c @@ -38,7 +38,7 @@ #include <gio/gio.h> #include "pluma-history-entry.h" -#include "pluma-prefs-manager.h" +#include "pluma-settings.h" enum { PROP_0, @@ -125,7 +125,7 @@ pluma_history_entry_finalize (GObject *object) { PlumaHistoryEntryPrivate *priv; - priv = PLUMA_HISTORY_ENTRY (object)->priv; + priv = pluma_history_entry_get_instance_private (PLUMA_HISTORY_ENTRY(object)); g_free (priv->history_id); @@ -222,9 +222,9 @@ pluma_history_entry_save_history (PlumaHistoryEntry *entry) settings_items = get_history_list (entry); - pluma_prefs_manager_set_gslist (entry->priv->settings, - entry->priv->history_id, - settings_items); + pluma_settings_set_list (entry->priv->settings, + entry->priv->history_id, + settings_items); g_slist_free_full (settings_items, g_free); } @@ -355,8 +355,8 @@ pluma_history_entry_load_history (PlumaHistoryEntry *entry) store = get_history_store (entry); - settings_items = pluma_prefs_manager_get_gslist (entry->priv->settings, - entry->priv->history_id); + settings_items = pluma_settings_get_list (entry->priv->settings, + entry->priv->history_id); gtk_list_store_clear (store); @@ -401,7 +401,7 @@ pluma_history_entry_init (PlumaHistoryEntry *entry) priv->completion = NULL; - priv->settings = g_settings_new (PLUMA_SCHEMA); + priv->settings = g_settings_new (PLUMA_SCHEMA_ID); } void diff --git a/pluma/pluma-io-error-message-area.c b/pluma/pluma-io-error-message-area.c index 937bc880..846cb0e8 100644 --- a/pluma/pluma-io-error-message-area.c +++ b/pluma/pluma-io-error-message-area.c @@ -42,10 +42,10 @@ #include <glib/gi18n.h> #include <gio/gio.h> +#include "pluma-settings.h" #include "pluma-utils.h" #include "pluma-document.h" #include "pluma-io-error-message-area.h" -#include "pluma-prefs-manager.h" #include <pluma/pluma-encodings-combo-box.h> #define MAX_URI_IN_DIALOG_LENGTH 50 @@ -933,6 +933,8 @@ pluma_no_backup_saving_error_message_area_new (const gchar *uri, gchar *full_formatted_uri; gchar *uri_for_display; gchar *temp_uri_for_display; + gboolean create_backup_copy; + GSettings *editor_settings; g_return_val_if_fail (uri != NULL, NULL); g_return_val_if_fail (error != NULL, NULL); @@ -976,9 +978,14 @@ pluma_no_backup_saving_error_message_area_new (const gchar *uri, vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - // FIXME: review this messages + editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + + create_backup_copy = g_settings_get_boolean (editor_settings, + PLUMA_SETTINGS_CREATE_BACKUP_COPY); + g_object_unref (editor_settings); - if (pluma_prefs_manager_get_create_backup_copy ()) + // FIXME: review this messages + if (create_backup_copy) primary_text = g_strdup_printf (_("Could not create a backup file while saving %s"), uri_for_display); else diff --git a/pluma/pluma-language-manager.c b/pluma/pluma-language-manager.c index 9eb3f66a..40a990a2 100644 --- a/pluma/pluma-language-manager.c +++ b/pluma/pluma-language-manager.c @@ -32,7 +32,6 @@ #include <string.h> #include <gtk/gtk.h> #include "pluma-language-manager.h" -#include "pluma-prefs-manager.h" #include "pluma-utils.h" #include "pluma-debug.h" diff --git a/pluma/pluma-notebook.c b/pluma/pluma-notebook.c index aa995e2d..3f210c96 100644 --- a/pluma/pluma-notebook.c +++ b/pluma/pluma-notebook.c @@ -48,14 +48,15 @@ #include "pluma-tab-label.h" #include "pluma-marshal.h" #include "pluma-window.h" -#include "pluma-prefs-manager.h" -#include "pluma-prefs-manager-private.h" +#include "pluma-settings.h" #define AFTER_ALL_TABS -1 #define NOT_IN_APP_WINDOWS -2 struct _PlumaNotebookPrivate { + GSettings *editor_settings; + GList *focused_pages; gulong motion_notify_handler_id; gint x_start; @@ -68,8 +69,6 @@ struct _PlumaNotebookPrivate G_DEFINE_TYPE_WITH_PRIVATE (PlumaNotebook, pluma_notebook, GTK_TYPE_NOTEBOOK) -static void pluma_notebook_finalize (GObject *object); - static gboolean pluma_notebook_change_current_page (GtkNotebook *notebook, gint offset); @@ -98,6 +97,16 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; static void +pluma_notebook_finalize (GObject *object) +{ + PlumaNotebook *notebook = PLUMA_NOTEBOOK (object); + + g_list_free (notebook->priv->focused_pages); + + G_OBJECT_CLASS (pluma_notebook_parent_class)->finalize (object); +} + +static void pluma_notebook_dispose (GObject *object) { PlumaNotebook *notebook = PLUMA_NOTEBOOK (object); @@ -118,6 +127,8 @@ pluma_notebook_dispose (GObject *object) notebook->priv->destroy_has_run = TRUE; } + g_clear_object (¬ebook->priv->editor_settings); + G_OBJECT_CLASS (pluma_notebook_parent_class)->dispose (object); } @@ -786,13 +797,15 @@ update_tabs_visibility (PlumaNotebook *nb) num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb)); - show_tabs = (g_settings_get_boolean (pluma_prefs_manager->settings, "show-single-tab") || num > 1); + show_tabs = (g_settings_get_boolean (nb->priv->editor_settings, PLUMA_SETTINGS_SHOW_SINGLE_TAB) || (num > 1)); - if (g_settings_get_boolean (pluma_prefs_manager->settings, "show-tabs-with-side-pane")) + if (g_settings_get_boolean (nb->priv->editor_settings, PLUMA_SETTINGS_SHOW_TABS_WITH_SIDE_PANE)) gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); else { - if (pluma_prefs_manager_get_side_pane_visible ()) + gboolean visible = g_settings_get_boolean (nb->priv->editor_settings, PLUMA_SETTINGS_SIDE_PANE_VISIBLE); + + if (visible) gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE); else gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); @@ -804,6 +817,8 @@ pluma_notebook_init (PlumaNotebook *notebook) { notebook->priv = pluma_notebook_get_instance_private (notebook); + notebook->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + notebook->priv->close_buttons_sensitive = TRUE; notebook->priv->tab_drag_and_drop_enabled = TRUE; @@ -845,16 +860,6 @@ pluma_notebook_init (PlumaNotebook *notebook) NULL); } -static void -pluma_notebook_finalize (GObject *object) -{ - PlumaNotebook *notebook = PLUMA_NOTEBOOK (object); - - g_list_free (notebook->priv->focused_pages); - - G_OBJECT_CLASS (pluma_notebook_parent_class)->finalize (object); -} - /* * We need to override this because when we don't show the tabs, like in * fullscreen we need to have wrap around too diff --git a/pluma/pluma-plugins-engine.c b/pluma/pluma-plugins-engine.c index 9893fdea..8d4f5a5e 100644 --- a/pluma/pluma-plugins-engine.c +++ b/pluma/pluma-plugins-engine.c @@ -40,8 +40,8 @@ #include "pluma-plugins-engine.h" #include "pluma-debug.h" #include "pluma-app.h" -#include "pluma-prefs-manager.h" #include "pluma-dirs.h" +#include "pluma-settings.h" struct _PlumaPluginsEnginePrivate { @@ -64,7 +64,7 @@ pluma_plugins_engine_init (PlumaPluginsEngine *engine) engine->priv = pluma_plugins_engine_get_instance_private (engine); - engine->priv->plugin_settings = g_settings_new (PLUMA_SCHEMA); + engine->priv->plugin_settings = g_settings_new (PLUMA_SCHEMA_ID); /* This should be moved to libpeas */ if (!g_irepository_require (g_irepository_get_default (), @@ -104,7 +104,7 @@ pluma_plugins_engine_init (PlumaPluginsEngine *engine) pluma_dirs_get_pluma_plugins_data_dir ()); g_settings_bind (engine->priv->plugin_settings, - GPM_ACTIVE_PLUGINS, + PLUMA_SETTINGS_ACTIVE_PLUGINS, engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); diff --git a/pluma/pluma-prefs-manager-app.c b/pluma/pluma-prefs-manager-app.c deleted file mode 100644 index 97f0db0b..00000000 --- a/pluma/pluma-prefs-manager-app.c +++ /dev/null @@ -1,1619 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pluma-prefs-manager.c - * This file is part of pluma - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the pluma Team, 2002-2003. See the AUTHORS file for a - * list of people on the pluma Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gio/gio.h> -#include "pluma-prefs-manager.h" -#include "pluma-prefs-manager-private.h" -#include "pluma-prefs-manager-app.h" -#include "pluma-app.h" -#include "pluma-debug.h" -#include "pluma-view.h" -#include "pluma-window.h" -#include "pluma-window-private.h" -#include "pluma-plugins-engine.h" -#include "pluma-style-scheme-manager.h" -#include "pluma-dirs.h" - -static void pluma_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_bracket_matching_changed(GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_syntax_hl_enable_changed(GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_search_hl_enable_changed(GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_source_style_scheme_changed(GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_lockdown_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_draw_spaces_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_draw_tabs_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_draw_newlines_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void pluma_prefs_manager_draw_nbsp_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -/* GUI state is serialized to a .desktop file, not in GSettings */ - -#define PLUMA_STATE_DEFAULT_WINDOW_STATE 0 -#define PLUMA_STATE_DEFAULT_WINDOW_WIDTH 650 -#define PLUMA_STATE_DEFAULT_WINDOW_HEIGHT 500 -#define PLUMA_STATE_DEFAULT_SIDE_PANEL_SIZE 200 -#define PLUMA_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140 - -#define PLUMA_STATE_FILE_LOCATION "pluma.ini" - -#define PLUMA_STATE_WINDOW_GROUP "window" -#define PLUMA_STATE_WINDOW_STATE "state" -#define PLUMA_STATE_WINDOW_HEIGHT "height" -#define PLUMA_STATE_WINDOW_WIDTH "width" -#define PLUMA_STATE_SIDE_PANEL_SIZE "side_panel_size" -#define PLUMA_STATE_BOTTOM_PANEL_SIZE "bottom_panel_size" -#define PLUMA_STATE_SIDE_PANEL_ACTIVE_PAGE "side_panel_active_page" -#define PLUMA_STATE_BOTTOM_PANEL_ACTIVE_PAGE "bottom_panel_active_page" - -#define PLUMA_STATE_FILEFILTER_GROUP "filefilter" -#define PLUMA_STATE_FILEFILTER_ID "id" - -static gint window_state = -1; -static gint window_height = -1; -static gint window_width = -1; -static gint side_panel_size = -1; -static gint bottom_panel_size = -1; -static gint side_panel_active_page = -1; -static gint bottom_panel_active_page = -1; -static gint active_file_filter = -1; - - -static gchar * -get_state_filename (void) -{ - gchar *config_dir; - gchar *filename = NULL; - - config_dir = pluma_dirs_get_user_config_dir (); - - if (config_dir != NULL) - { - filename = g_build_filename (config_dir, - PLUMA_STATE_FILE_LOCATION, - NULL); - g_free (config_dir); - } - - return filename; -} - -static GKeyFile * -get_pluma_state_file (void) -{ - static GKeyFile *state_file = NULL; - - if (state_file == NULL) - { - gchar *filename; - GError *err = NULL; - - state_file = g_key_file_new (); - - filename = get_state_filename (); - - if (!g_key_file_load_from_file (state_file, - filename, - G_KEY_FILE_NONE, - &err)) - { - if (err->domain != G_FILE_ERROR || - err->code != G_FILE_ERROR_NOENT) - { - g_warning ("Could not load pluma state file: %s\n", - err->message); - } - - g_error_free (err); - } - - g_free (filename); - } - - return state_file; -} - -static void -pluma_state_get_int (const gchar *group, - const gchar *key, - gint defval, - gint *result) -{ - GKeyFile *state_file; - gint res; - GError *err = NULL; - - state_file = get_pluma_state_file (); - res = g_key_file_get_integer (state_file, - group, - key, - &err); - - if (err != NULL) - { - if ((err->domain != G_KEY_FILE_ERROR) || - ((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND && - err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND))) - { - g_warning ("Could not get state value %s::%s : %s\n", - group, - key, - err->message); - } - - *result = defval; - g_error_free (err); - } - else - { - *result = res; - } -} - -static void -pluma_state_set_int (const gchar *group, - const gchar *key, - gint value) -{ - GKeyFile *state_file; - - state_file = get_pluma_state_file (); - g_key_file_set_integer (state_file, - group, - key, - value); -} - -static gboolean -pluma_state_file_sync (void) -{ - GKeyFile *state_file; - gchar *config_dir; - gchar *filename = NULL; - gchar *content = NULL; - gsize length; - gint res; - GError *err = NULL; - gboolean ret = FALSE; - - state_file = get_pluma_state_file (); - g_return_val_if_fail (state_file != NULL, FALSE); - - config_dir = pluma_dirs_get_user_config_dir (); - if (config_dir == NULL) - { - g_warning ("Could not get config directory\n"); - return ret; - } - - res = g_mkdir_with_parents (config_dir, 0755); - if (res < 0) - { - g_warning ("Could not create config directory\n"); - goto out; - } - - content = g_key_file_to_data (state_file, - &length, - &err); - - if (err != NULL) - { - g_warning ("Could not get data from state file: %s\n", - err->message); - goto out; - } - - if (content != NULL) - { - filename = get_state_filename (); - if (!g_file_set_contents (filename, - content, - length, - &err)) - { - g_warning ("Could not write pluma state file: %s\n", - err->message); - goto out; - } - } - - ret = TRUE; - - out: - if (err != NULL) - g_error_free (err); - - g_free (config_dir); - g_free (filename); - g_free (content); - - return ret; -} - -/* Window state */ -gint -pluma_prefs_manager_get_window_state (void) -{ - if (window_state == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_STATE, - PLUMA_STATE_DEFAULT_WINDOW_STATE, - &window_state); - } - - return window_state; -} - -void -pluma_prefs_manager_set_window_state (gint ws) -{ - g_return_if_fail (ws > -1); - - window_state = ws; - - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_STATE, - ws); -} - -gboolean -pluma_prefs_manager_window_state_can_set (void) -{ - return TRUE; -} - -/* Window size */ -void -pluma_prefs_manager_get_window_size (gint *width, gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - if (window_width == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_WIDTH, - PLUMA_STATE_DEFAULT_WINDOW_WIDTH, - &window_width); - } - - if (window_height == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_HEIGHT, - PLUMA_STATE_DEFAULT_WINDOW_HEIGHT, - &window_height); - } - - *width = window_width; - *height = window_height; -} - -void -pluma_prefs_manager_get_default_window_size (gint *width, gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - *width = PLUMA_STATE_DEFAULT_WINDOW_WIDTH; - *height = PLUMA_STATE_DEFAULT_WINDOW_HEIGHT; -} - -void -pluma_prefs_manager_set_window_size (gint width, gint height) -{ - g_return_if_fail (width > -1 && height > -1); - - window_width = width; - window_height = height; - - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_WIDTH, - width); - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_WINDOW_HEIGHT, - height); -} - -gboolean -pluma_prefs_manager_window_size_can_set (void) -{ - return TRUE; -} - -/* Side panel */ -gint -pluma_prefs_manager_get_side_panel_size (void) -{ - if (side_panel_size == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_SIDE_PANEL_SIZE, - PLUMA_STATE_DEFAULT_SIDE_PANEL_SIZE, - &side_panel_size); - } - - return side_panel_size; -} - -gint -pluma_prefs_manager_get_default_side_panel_size (void) -{ - return PLUMA_STATE_DEFAULT_SIDE_PANEL_SIZE; -} - -void -pluma_prefs_manager_set_side_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (side_panel_size == ps) - return; - - side_panel_size = ps; - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_SIDE_PANEL_SIZE, - ps); -} - -gboolean -pluma_prefs_manager_side_panel_size_can_set (void) -{ - return TRUE; -} - -gint -pluma_prefs_manager_get_side_panel_active_page (void) -{ - if (side_panel_active_page == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_SIDE_PANEL_ACTIVE_PAGE, - 0, - &side_panel_active_page); - } - - return side_panel_active_page; -} - -void -pluma_prefs_manager_set_side_panel_active_page (gint id) -{ - if (side_panel_active_page == id) - return; - - side_panel_active_page = id; - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_SIDE_PANEL_ACTIVE_PAGE, - id); -} - -gboolean -pluma_prefs_manager_side_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* Bottom panel */ -gint -pluma_prefs_manager_get_bottom_panel_size (void) -{ - if (bottom_panel_size == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_BOTTOM_PANEL_SIZE, - PLUMA_STATE_DEFAULT_BOTTOM_PANEL_SIZE, - &bottom_panel_size); - } - - return bottom_panel_size; -} - -gint -pluma_prefs_manager_get_default_bottom_panel_size (void) -{ - return PLUMA_STATE_DEFAULT_BOTTOM_PANEL_SIZE; -} - -void -pluma_prefs_manager_set_bottom_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (bottom_panel_size == ps) - return; - - bottom_panel_size = ps; - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_BOTTOM_PANEL_SIZE, - ps); -} - -gboolean -pluma_prefs_manager_bottom_panel_size_can_set (void) -{ - return TRUE; -} - -gint -pluma_prefs_manager_get_bottom_panel_active_page (void) -{ - if (bottom_panel_active_page == -1) - { - pluma_state_get_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - 0, - &bottom_panel_active_page); - } - - return bottom_panel_active_page; -} - -void -pluma_prefs_manager_set_bottom_panel_active_page (gint id) -{ - if (bottom_panel_active_page == id) - return; - - bottom_panel_active_page = id; - pluma_state_set_int (PLUMA_STATE_WINDOW_GROUP, - PLUMA_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - id); -} - -gboolean -pluma_prefs_manager_bottom_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* File filter */ -gint -pluma_prefs_manager_get_active_file_filter (void) -{ - if (active_file_filter == -1) - { - pluma_state_get_int (PLUMA_STATE_FILEFILTER_GROUP, - PLUMA_STATE_FILEFILTER_ID, - 0, - &active_file_filter); - } - - return active_file_filter; -} - -void -pluma_prefs_manager_set_active_file_filter (gint id) -{ - g_return_if_fail (id >= 0); - - if (active_file_filter == id) - return; - - active_file_filter = id; - pluma_state_set_int (PLUMA_STATE_FILEFILTER_GROUP, - PLUMA_STATE_FILEFILTER_ID, - id); -} - -gboolean -pluma_prefs_manager_active_file_filter_can_set (void) -{ - return TRUE; -} - -/* Normal prefs are stored in GSettings */ - -gboolean -pluma_prefs_manager_app_init (void) -{ - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager == NULL, FALSE); - - pluma_prefs_manager_init (); - - if (pluma_prefs_manager != NULL) - { - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_USE_DEFAULT_FONT, - G_CALLBACK (pluma_prefs_manager_editor_font_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_EDITOR_FONT, - G_CALLBACK (pluma_prefs_manager_editor_font_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->interface_settings, - "changed::" GPM_SYSTEM_FONT, - G_CALLBACK (pluma_prefs_manager_system_font_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_TABS_SIZE, - G_CALLBACK (pluma_prefs_manager_tabs_size_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_INSERT_SPACES, - G_CALLBACK (pluma_prefs_manager_tabs_size_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_WRAP_MODE, - G_CALLBACK (pluma_prefs_manager_wrap_mode_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_DISPLAY_LINE_NUMBERS, - G_CALLBACK (pluma_prefs_manager_line_numbers_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_AUTO_INDENT, - G_CALLBACK (pluma_prefs_manager_auto_indent_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_UNDO_ACTIONS_LIMIT, - G_CALLBACK (pluma_prefs_manager_undo_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_DISPLAY_RIGHT_MARGIN, - G_CALLBACK (pluma_prefs_manager_right_margin_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_RIGHT_MARGIN_POSITION, - G_CALLBACK (pluma_prefs_manager_right_margin_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SMART_HOME_END, - G_CALLBACK (pluma_prefs_manager_smart_home_end_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_HIGHLIGHT_CURRENT_LINE, - G_CALLBACK (pluma_prefs_manager_hl_current_line_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_BRACKET_MATCHING, - G_CALLBACK (pluma_prefs_manager_bracket_matching_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SYNTAX_HL_ENABLE, - G_CALLBACK (pluma_prefs_manager_syntax_hl_enable_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE, - G_CALLBACK (pluma_prefs_manager_search_hl_enable_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SOURCE_STYLE_SCHEME, - G_CALLBACK (pluma_prefs_manager_source_style_scheme_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_MAX_RECENTS, - G_CALLBACK (pluma_prefs_manager_max_recents_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_CREATE_BACKUP_COPY, - G_CALLBACK (pluma_prefs_manager_auto_save_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_AUTO_SAVE_INTERVAL, - G_CALLBACK (pluma_prefs_manager_auto_save_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_WRITABLE_VFS_SCHEMES, - G_CALLBACK (pluma_prefs_manager_auto_save_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->lockdown_settings, - "changed", - G_CALLBACK (pluma_prefs_manager_lockdown_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SPACE_DRAWER_SPACE, - G_CALLBACK (pluma_prefs_manager_draw_spaces_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SPACE_DRAWER_TAB, - G_CALLBACK (pluma_prefs_manager_draw_tabs_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SPACE_DRAWER_NEWLINE, - G_CALLBACK (pluma_prefs_manager_draw_newlines_changed), - NULL); - - g_signal_connect (pluma_prefs_manager->settings, - "changed::" GPM_SPACE_DRAWER_NBSP, - G_CALLBACK (pluma_prefs_manager_draw_nbsp_changed), - NULL); - - } - - return pluma_prefs_manager != NULL; -} - -/* This function must be called before exiting pluma */ -void -pluma_prefs_manager_app_shutdown (void) -{ - pluma_debug (DEBUG_PREFS); - - pluma_prefs_manager_shutdown (); - - pluma_state_file_sync (); -} - - -static void -pluma_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font = NULL; - gboolean def = TRUE; - gint ts; - - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) - { - def = g_settings_get_boolean (settings, key); - - if (def) - font = pluma_prefs_manager_get_system_font (); - else - font = pluma_prefs_manager_get_editor_font (); - } - else if (strcmp (key, GPM_EDITOR_FONT) == 0) - { - font = g_settings_get_string (settings, key); - - def = pluma_prefs_manager_get_use_default_font (); - } - else - return; - - g_return_if_fail (font != NULL); - - ts = pluma_prefs_manager_get_tabs_size (); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid PlumaView to query GSettings */ - pluma_view_set_font (PLUMA_VIEW (l->data), FALSE, font); - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - - l = l->next; - } - - g_list_free (views); - g_free (font); -} - -static void -pluma_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font; - gint ts; - - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SYSTEM_FONT) != 0) - return; - - if (!pluma_prefs_manager_get_use_default_font ()) - return; - - font = g_settings_get_string (settings, key); - - ts = pluma_prefs_manager_get_tabs_size (); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid PlumaView to query GSettings */ - pluma_view_set_font (PLUMA_VIEW (l->data), FALSE, font); - - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - l = l->next; - } - - g_list_free (views); - g_free (font); -} - -static void -pluma_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_TABS_SIZE) == 0) - { - gint tab_width; - GList *views; - GList *l; - - tab_width = g_settings_get_int (settings, key); - - tab_width = CLAMP (tab_width, 1, 24); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), - tab_width); - - l = l->next; - } - - g_list_free (views); - } - else if (strcmp (key, GPM_INSERT_SPACES) == 0) - { - gboolean enable; - GList *views; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_insert_spaces_instead_of_tabs ( - GTK_SOURCE_VIEW (l->data), - enable); - - l = l->next; - } - - g_list_free (views); - } -} - -static GtkWrapMode -get_wrap_mode_from_string (const gchar* str) -{ - GtkWrapMode res; - - g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_CHAR") == 0) - res = GTK_WRAP_CHAR; - else - res = GTK_WRAP_WORD; - } - - return res; -} - -static void -pluma_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_WRAP_MODE) == 0) - { - GtkWrapMode wrap_mode; - GList *views; - GList *l; - - wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key)); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), - wrap_mode); - - l = l->next; - } - - g_list_free (views); - } -} - -static void -pluma_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0) - { - gboolean dln; - GList *views; - GList *l; - - dln = g_settings_get_boolean (settings, key); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), - dln); - - l = l->next; - } - - g_list_free (views); - } -} - -static void -pluma_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0) - { - gboolean hl; - GList *views; - GList *l; - - hl = g_settings_get_boolean (settings, key); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), - hl); - - l = l->next; - } - - g_list_free (views); - } -} - -static void -pluma_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_BRACKET_MATCHING) == 0) - { - gboolean enable; - GList *docs; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), - enable); - - l = l->next; - } - - g_list_free (docs); - } -} - -static void -pluma_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_INDENT) == 0) - { - gboolean enable; - GList *views; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), - enable); - - l = l->next; - } - - g_list_free (views); - } -} - -static void -pluma_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0) - { - gint ul; - GList *docs; - GList *l; - - ul = g_settings_get_int (settings, key); - - ul = CLAMP (ul, -1, 250); - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), - ul); - - l = l->next; - } - - g_list_free (docs); - } -} - -static void -pluma_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0) - { - gint pos; - GList *views; - GList *l; - - pos = g_settings_get_int (settings, key); - - pos = CLAMP (pos, 1, 160); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), - pos); - - l = l->next; - } - - g_list_free (views); - } - else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0) - { - gboolean display; - GList *views; - GList *l; - - display = g_settings_get_boolean (settings, key); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), - display); - - l = l->next; - } - - g_list_free (views); - } -} - -static GtkSourceSmartHomeEndType -get_smart_home_end_from_string (const gchar *str) -{ - GtkSourceSmartHomeEndType res; - - g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); - - if (strcmp (str, "DISABLED") == 0) - res = GTK_SOURCE_SMART_HOME_END_DISABLED; - else if (strcmp (str, "BEFORE") == 0) - res = GTK_SOURCE_SMART_HOME_END_BEFORE; - else if (strcmp (str, "ALWAYS") == 0) - res = GTK_SOURCE_SMART_HOME_END_ALWAYS; - else - res = GTK_SOURCE_SMART_HOME_END_AFTER; - - return res; -} - -static void -pluma_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SMART_HOME_END) == 0) - { - GtkSourceSmartHomeEndType smart_he; - GList *views; - GList *l; - - smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key)); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), - smart_he); - - l = l->next; - } - - g_list_free (views); - } -} - -static void -pluma_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; - const GList *windows; - - enable = g_settings_get_boolean (settings, key); - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), - enable); - - l = l->next; - } - - g_list_free (docs); - - /* update the sensitivity of the Higlight Mode menu item */ - windows = pluma_app_get_windows (pluma_app_get_default ()); - while (windows != NULL) - { - GtkUIManager *ui; - GtkAction *a; - - ui = pluma_window_get_ui_manager (PLUMA_WINDOW (windows->data)); - - a = gtk_ui_manager_get_action (ui, - "/MenuBar/ViewMenu/ViewHighlightModeMenu"); - - gtk_action_set_sensitive (a, enable); - - windows = g_list_next (windows); - } - } -} - -static void -pluma_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - g_return_if_fail (PLUMA_IS_DOCUMENT (l->data)); - - pluma_document_set_enable_search_highlighting (PLUMA_DOCUMENT (l->data), - enable); - - l = l->next; - } - - g_list_free (docs); - } -} - -static void -pluma_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) - { - static gchar *old_scheme = NULL; - gchar *scheme; - GtkSourceStyleScheme *style; - GList *docs; - GList *l; - - scheme = g_settings_get_string (settings, key); - - if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) - return; - - g_free (old_scheme); - old_scheme = scheme; - - style = gtk_source_style_scheme_manager_get_scheme ( - pluma_get_style_scheme_manager (), - scheme); - - if (style == NULL) - { - g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); - - style = gtk_source_style_scheme_manager_get_scheme ( - pluma_get_style_scheme_manager (), - "classic"); - - if (style == NULL) - { - g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); - return; - } - } - - docs = pluma_app_get_documents (pluma_app_get_default ()); - for (l = docs; l != NULL; l = l->next) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - - gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), - style); - } - - g_list_free (docs); - } -} - -static void -pluma_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_MAX_RECENTS) == 0) - { - const GList *windows; - gint max; - - max = g_settings_get_int (settings, key); - - if (max < 0) { - max = GPM_DEFAULT_MAX_RECENTS; - } - - windows = pluma_app_get_windows (pluma_app_get_default ()); - while (windows != NULL) - { - PlumaWindow *w = windows->data; - - gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu), - max); - - windows = g_list_next (windows); - } - - /* FIXME: we have no way at the moment to trigger the - * update of the inline recents in the File menu */ - } -} - -static void -pluma_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *docs; - GList *l; - - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_SAVE) == 0) - { - gboolean auto_save; - - auto_save = g_settings_get_boolean (settings, key); - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - PlumaDocument *doc = PLUMA_DOCUMENT (l->data); - PlumaTab *tab = pluma_tab_get_from_document (doc); - - pluma_tab_set_auto_save_enabled (tab, auto_save); - - l = l->next; - } - - g_list_free (docs); - } - else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0) - { - gint auto_save_interval; - - auto_save_interval = g_settings_get_int (settings, key); - - if (auto_save_interval <= 0) - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - - docs = pluma_app_get_documents (pluma_app_get_default ()); - l = docs; - - while (l != NULL) - { - PlumaDocument *doc = PLUMA_DOCUMENT (l->data); - PlumaTab *tab = pluma_tab_get_from_document (doc); - - pluma_tab_set_auto_save_interval (tab, auto_save_interval); - - l = l->next; - } - - g_list_free (docs); - } -} - -static void -pluma_prefs_manager_lockdown_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - PlumaApp *app; - gboolean locked; - - pluma_debug (DEBUG_PREFS); - - locked = g_settings_get_boolean (settings, key); - - app = pluma_app_get_default (); - - if (strcmp (key, GPM_LOCKDOWN_COMMAND_LINE) == 0) - _pluma_app_set_lockdown_bit (app, - PLUMA_LOCKDOWN_COMMAND_LINE, - locked); - - else if (strcmp (key, GPM_LOCKDOWN_PRINTING) == 0) - _pluma_app_set_lockdown_bit (app, - PLUMA_LOCKDOWN_PRINTING, - locked); - - else if (strcmp (key, GPM_LOCKDOWN_PRINT_SETUP) == 0) - _pluma_app_set_lockdown_bit (app, - PLUMA_LOCKDOWN_PRINT_SETUP, - locked); - - else if (strcmp (key, GPM_LOCKDOWN_SAVE_TO_DISK) == 0) - _pluma_app_set_lockdown_bit (app, - PLUMA_LOCKDOWN_SAVE_TO_DISK, - locked); -} - -#ifdef GTK_SOURCE_VERSION_3_24 -static void -pluma_prefs_manager_space_drawer_generic (GSettings *settings, - gint level, - GtkSourceSpaceTypeFlags type) -{ - - GList *views; - GList *l; - - pluma_debug (DEBUG_PREFS); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - pluma_set_source_space_drawer_by_level (GTK_SOURCE_VIEW (l->data), - level, type); - l = l->next; - } - - g_list_free (views); -} -#else -static void -pluma_prefs_manager_draw_generic (GSettings *settings, - gint level, - GtkSourceDrawSpacesFlags type) -{ - - GList *views; - GList *l; - - pluma_debug (DEBUG_PREFS); - - views = pluma_app_get_views (pluma_app_get_default ()); - l = views; - - while (l != NULL) - { - GtkSourceDrawSpacesFlags value; - - value = gtk_source_view_get_draw_spaces (GTK_SOURCE_VIEW (l->data)); - if (level > 0) - value |= type; - else - value &= ~type; - gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (l->data), - value); - l = l->next; - } - - g_list_free (views); -} -#endif - -static void -pluma_prefs_manager_draw_spaces_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SPACE_DRAWER_SPACE)) - return; - -#ifdef GTK_SOURCE_VERSION_3_24 - pluma_prefs_manager_space_drawer_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_SPACE_TYPE_SPACE); -#else - pluma_prefs_manager_draw_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_DRAW_SPACES_SPACE); -#endif -} - -static void -pluma_prefs_manager_draw_tabs_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SPACE_DRAWER_TAB)) - return; - -#ifdef GTK_SOURCE_VERSION_3_24 - pluma_prefs_manager_space_drawer_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_SPACE_TYPE_TAB); -#else - pluma_prefs_manager_draw_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_DRAW_SPACES_TAB); -#endif -} - -static void -pluma_prefs_manager_draw_newlines_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SPACE_DRAWER_NEWLINE)) - return; - -#ifdef GTK_SOURCE_VERSION_3_24 - pluma_prefs_manager_space_drawer_generic (settings, - g_settings_get_boolean (settings, key) ? 1 : 0, - GTK_SOURCE_SPACE_TYPE_NEWLINE); -#else - pluma_prefs_manager_draw_generic (settings, - g_settings_get_boolean (settings, key) ? 1 : 0, - GTK_SOURCE_DRAW_SPACES_NEWLINE); -#endif -} - -static void -pluma_prefs_manager_draw_nbsp_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - pluma_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SPACE_DRAWER_NBSP)) - return; - -#ifdef GTK_SOURCE_VERSION_3_24 - pluma_prefs_manager_space_drawer_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_SPACE_TYPE_NBSP); -#else - pluma_prefs_manager_draw_generic (settings, - g_settings_get_enum (settings, key), - GTK_SOURCE_DRAW_SPACES_NBSP); -#endif -} diff --git a/pluma/pluma-prefs-manager-app.h b/pluma/pluma-prefs-manager-app.h deleted file mode 100644 index debc594a..00000000 --- a/pluma/pluma-prefs-manager-app.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * pluma-prefs-manager-app.h - * This file is part of pluma - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the pluma Team, 2002-2005. See the AUTHORS file for a - * list of people on the pluma Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - * - */ - -#ifndef __PLUMA_PREFS_MANAGER_APP_H__ -#define __PLUMA_PREFS_MANAGER_APP_H__ - -#include <glib.h> -#include <pluma/pluma-prefs-manager.h> - -/* LIFE CYCLE MANAGEMENT FUNCTIONS */ - -gboolean pluma_prefs_manager_app_init (void); - -/* This function must be called before exiting pluma */ -void pluma_prefs_manager_app_shutdown (void); - - -/* Window state */ -gint pluma_prefs_manager_get_window_state (void); -void pluma_prefs_manager_set_window_state (gint ws); -gboolean pluma_prefs_manager_window_state_can_set (void); - -/* Window size */ -void pluma_prefs_manager_get_window_size (gint *width, - gint *height); -void pluma_prefs_manager_get_default_window_size (gint *width, - gint *height); -void pluma_prefs_manager_set_window_size (gint width, - gint height); -gboolean pluma_prefs_manager_window_size_can_set (void); - -/* Side panel */ -gint pluma_prefs_manager_get_side_panel_size (void); -gint pluma_prefs_manager_get_default_side_panel_size(void); -void pluma_prefs_manager_set_side_panel_size (gint ps); -gboolean pluma_prefs_manager_side_panel_size_can_set (void); -gint pluma_prefs_manager_get_side_panel_active_page (void); -void pluma_prefs_manager_set_side_panel_active_page (gint id); -gboolean pluma_prefs_manager_side_panel_active_page_can_set (void); - -/* Bottom panel */ -gint pluma_prefs_manager_get_bottom_panel_size (void); -gint pluma_prefs_manager_get_default_bottom_panel_size(void); -void pluma_prefs_manager_set_bottom_panel_size (gint ps); -gboolean pluma_prefs_manager_bottom_panel_size_can_set (void); -gint pluma_prefs_manager_get_bottom_panel_active_page (void); -void pluma_prefs_manager_set_bottom_panel_active_page (gint id); -gboolean pluma_prefs_manager_bottom_panel_active_page_can_set (void); - -/* File filter */ -gint pluma_prefs_manager_get_active_file_filter (void); -void pluma_prefs_manager_set_active_file_filter (gint id); -gboolean pluma_prefs_manager_active_file_filter_can_set (void); - - -#endif /* __PLUMA_PREFS_MANAGER_APP_H__ */ diff --git a/pluma/pluma-prefs-manager-private.h b/pluma/pluma-prefs-manager-private.h deleted file mode 100644 index 392397f3..00000000 --- a/pluma/pluma-prefs-manager-private.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pluma-prefs-manager-private.h - * This file is part of pluma - * - * Copyright (C) 2002 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the pluma Team, 2002. See the AUTHORS file for a - * list of people on the pluma Team. - * See the ChangeLog files for a list of changes. - */ - -#ifndef __PLUMA_PREFS_MANAGER_PRIVATE_H__ -#define __PLUMA_PREFS_MANAGER_PRIVATE_H__ - -#include <gio/gio.h> - -typedef struct _PlumaPrefsManager PlumaPrefsManager; - -struct _PlumaPrefsManager { - GSettings *settings; - GSettings *lockdown_settings; - GSettings *interface_settings; -}; - -extern PlumaPrefsManager *pluma_prefs_manager; - -#endif /* __PLUMA_PREFS_MANAGER_PRIVATE_H__ */ - - diff --git a/pluma/pluma-prefs-manager.c b/pluma/pluma-prefs-manager.c deleted file mode 100644 index f150d13b..00000000 --- a/pluma/pluma-prefs-manager.c +++ /dev/null @@ -1,1003 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pluma-prefs-manager.c - * This file is part of pluma - * - * Copyright (C) 2002 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the pluma Team, 2002. See the AUTHORS file for a - * list of people on the pluma Team. - * See the ChangeLog files for a list of changes. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <glib/gi18n.h> -#include <gio/gio.h> - -#include "pluma-prefs-manager.h" -#include "pluma-prefs-manager-private.h" -#include "pluma-debug.h" -#include "pluma-encodings.h" -#include "pluma-utils.h" - -#define DEFINE_BOOL_PREF(name, key) gboolean \ -pluma_prefs_manager_get_ ## name (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_get_bool (key); \ -} \ - \ -void \ -pluma_prefs_manager_set_ ## name (gboolean v) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - pluma_prefs_manager_set_bool (key, \ - v); \ -} \ - \ -gboolean \ -pluma_prefs_manager_ ## name ## _can_set (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_INT_PREF(name, key) gint \ -pluma_prefs_manager_get_ ## name (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_get_int (key); \ -} \ - \ -void \ -pluma_prefs_manager_set_ ## name (gint v) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - pluma_prefs_manager_set_int (key, \ - v); \ -} \ - \ -gboolean \ -pluma_prefs_manager_ ## name ## _can_set (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_STRING_PREF(name, key) gchar* \ -pluma_prefs_manager_get_ ## name (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_get_string (key); \ -} \ - \ -void \ -pluma_prefs_manager_set_ ## name (const gchar* v) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - pluma_prefs_manager_set_string (key, \ - v); \ -} \ - \ -gboolean \ -pluma_prefs_manager_ ## name ## _can_set (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_ENUM_PREF(name, key) gint \ -pluma_prefs_manager_get_ ## name (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_get_enum (key); \ -} \ - \ -void \ -pluma_prefs_manager_set_ ## name (gint v) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - pluma_prefs_manager_set_enum (key, \ - v); \ -} \ - \ -gboolean \ -pluma_prefs_manager_ ## name ## _can_set (void) \ -{ \ - pluma_debug (DEBUG_PREFS); \ - \ - return pluma_prefs_manager_key_is_writable (key); \ -} - - -PlumaPrefsManager *pluma_prefs_manager = NULL; - - -static GtkWrapMode get_wrap_mode_from_string (const gchar* str); - -static gboolean pluma_prefs_manager_get_bool (const gchar* key); - -static gint pluma_prefs_manager_get_int (const gchar* key); - -static gchar *pluma_prefs_manager_get_string (const gchar* key); - -static gint pluma_prefs_manager_get_enum (const gchar* key); - - -gboolean -pluma_prefs_manager_init (void) -{ - pluma_debug (DEBUG_PREFS); - - if (pluma_prefs_manager == NULL) - { - pluma_prefs_manager = g_new0 (PlumaPrefsManager, 1); - pluma_prefs_manager->settings = g_settings_new (PLUMA_SCHEMA); - pluma_prefs_manager->lockdown_settings = g_settings_new (GPM_LOCKDOWN_SCHEMA); - pluma_prefs_manager->interface_settings = g_settings_new (GPM_INTERFACE_SCHEMA); - } - - return pluma_prefs_manager != NULL; -} - -void -pluma_prefs_manager_shutdown (void) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (pluma_prefs_manager != NULL); - - g_object_unref (pluma_prefs_manager->settings); - pluma_prefs_manager->settings = NULL; - g_object_unref (pluma_prefs_manager->lockdown_settings); - pluma_prefs_manager->lockdown_settings = NULL; - g_object_unref (pluma_prefs_manager->interface_settings); - pluma_prefs_manager->interface_settings = NULL; -} - -static gboolean -pluma_prefs_manager_get_bool (const gchar* key) -{ - pluma_debug (DEBUG_PREFS); - - return g_settings_get_boolean (pluma_prefs_manager->settings, key); -} - -static gint -pluma_prefs_manager_get_int (const gchar* key) -{ - pluma_debug (DEBUG_PREFS); - - return g_settings_get_int (pluma_prefs_manager->settings, key); -} - -static gchar * -pluma_prefs_manager_get_string (const gchar* key) -{ - pluma_debug (DEBUG_PREFS); - - return g_settings_get_string (pluma_prefs_manager->settings, key); -} - -static gint -pluma_prefs_manager_get_enum (const gchar* key) -{ - pluma_debug (DEBUG_PREFS); - - return g_settings_get_enum (pluma_prefs_manager->settings, key); -} - -static void -pluma_prefs_manager_set_bool (const gchar* key, gboolean value) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - pluma_prefs_manager->settings, key)); - - g_settings_set_boolean (pluma_prefs_manager->settings, key, value); -} - -static void -pluma_prefs_manager_set_int (const gchar* key, gint value) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - pluma_prefs_manager->settings, key)); - - g_settings_set_int (pluma_prefs_manager->settings, key, value); -} - -static void -pluma_prefs_manager_set_string (const gchar* key, const gchar* value) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (value != NULL); - - g_return_if_fail (g_settings_is_writable ( - pluma_prefs_manager->settings, key)); - - g_settings_set_string (pluma_prefs_manager->settings, key, value); -} - -static void -pluma_prefs_manager_set_enum (const gchar* key, gint value) -{ - pluma_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - pluma_prefs_manager->settings, key)); - - g_settings_set_enum (pluma_prefs_manager->settings, key, value); -} - -static gboolean -pluma_prefs_manager_key_is_writable (const gchar* key) -{ - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager != NULL, FALSE); - g_return_val_if_fail (pluma_prefs_manager->settings != NULL, FALSE); - - return g_settings_is_writable (pluma_prefs_manager->settings, key); -} - -/* Use default font */ -DEFINE_BOOL_PREF (use_default_font, - GPM_USE_DEFAULT_FONT) - -/* Editor font */ -DEFINE_STRING_PREF (editor_font, - GPM_EDITOR_FONT) - -/* System font */ -gchar * -pluma_prefs_manager_get_system_font (void) -{ - pluma_debug (DEBUG_PREFS); - - return g_settings_get_string (pluma_prefs_manager->interface_settings, - GPM_SYSTEM_FONT); -} - -/* Create backup copy */ -DEFINE_BOOL_PREF (create_backup_copy, - GPM_CREATE_BACKUP_COPY) - -/* Auto save */ -DEFINE_BOOL_PREF (auto_save, - GPM_AUTO_SAVE) - -/* Auto save interval */ -DEFINE_INT_PREF (auto_save_interval, - GPM_AUTO_SAVE_INTERVAL) - - -/* Undo actions limit: if < 1 then no limits */ -DEFINE_INT_PREF (undo_actions_limit, - GPM_UNDO_ACTIONS_LIMIT) - -static GtkWrapMode -get_wrap_mode_from_string (const gchar* str) -{ - GtkWrapMode res; - - g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_CHAR") == 0) - res = GTK_WRAP_CHAR; - else - res = GTK_WRAP_WORD; - } - - return res; -} - -/* Wrap mode */ -GtkWrapMode -pluma_prefs_manager_get_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - pluma_debug (DEBUG_PREFS); - - str = pluma_prefs_manager_get_string (GPM_WRAP_MODE); - - res = get_wrap_mode_from_string (str); - - g_free (str); - - return res; -} - -void -pluma_prefs_manager_set_wrap_mode (GtkWrapMode wp) -{ - const gchar * str; - - pluma_debug (DEBUG_PREFS); - - switch (wp) - { - case GTK_WRAP_NONE: - str = "GTK_WRAP_NONE"; - break; - - case GTK_WRAP_CHAR: - str = "GTK_WRAP_CHAR"; - break; - - default: /* GTK_WRAP_WORD */ - str = "GTK_WRAP_WORD"; - } - - pluma_prefs_manager_set_string (GPM_WRAP_MODE, - str); -} - -gboolean -pluma_prefs_manager_wrap_mode_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_WRAP_MODE); -} - - -/* Tabs size */ -DEFINE_INT_PREF (tabs_size, - GPM_TABS_SIZE) - -/* Insert spaces */ -DEFINE_BOOL_PREF (insert_spaces, - GPM_INSERT_SPACES) - -/* Auto indent */ -DEFINE_BOOL_PREF (auto_indent, - GPM_AUTO_INDENT) - -/* Display line numbers */ -DEFINE_BOOL_PREF (display_line_numbers, - GPM_DISPLAY_LINE_NUMBERS) - -/* Toolbar visibility */ -DEFINE_BOOL_PREF (toolbar_visible, - GPM_TOOLBAR_VISIBLE) - - -/* Toolbar suttons style */ -PlumaToolbarSetting -pluma_prefs_manager_get_toolbar_buttons_style (void) -{ - gchar *str; - PlumaToolbarSetting res; - - pluma_debug (DEBUG_PREFS); - - str = pluma_prefs_manager_get_string (GPM_TOOLBAR_BUTTONS_STYLE); - - if (strcmp (str, "PLUMA_TOOLBAR_ICONS") == 0) - res = PLUMA_TOOLBAR_ICONS; - else - { - if (strcmp (str, "PLUMA_TOOLBAR_ICONS_AND_TEXT") == 0) - res = PLUMA_TOOLBAR_ICONS_AND_TEXT; - else - { - if (strcmp (str, "PLUMA_TOOLBAR_ICONS_BOTH_HORIZ") == 0) - res = PLUMA_TOOLBAR_ICONS_BOTH_HORIZ; - else - res = PLUMA_TOOLBAR_SYSTEM; - } - } - - g_free (str); - - return res; -} - -void -pluma_prefs_manager_set_toolbar_buttons_style (PlumaToolbarSetting tbs) -{ - const gchar * str; - - pluma_debug (DEBUG_PREFS); - - switch (tbs) - { - case PLUMA_TOOLBAR_ICONS: - str = "PLUMA_TOOLBAR_ICONS"; - break; - - case PLUMA_TOOLBAR_ICONS_AND_TEXT: - str = "PLUMA_TOOLBAR_ICONS_AND_TEXT"; - break; - - case PLUMA_TOOLBAR_ICONS_BOTH_HORIZ: - str = "PLUMA_TOOLBAR_ICONS_BOTH_HORIZ"; - break; - default: /* PLUMA_TOOLBAR_SYSTEM */ - str = "PLUMA_TOOLBAR_SYSTEM"; - } - - pluma_prefs_manager_set_string (GPM_TOOLBAR_BUTTONS_STYLE, - str); - -} - -gboolean -pluma_prefs_manager_toolbar_buttons_style_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_TOOLBAR_BUTTONS_STYLE); - -} - -/* Statusbar visiblity */ -DEFINE_BOOL_PREF (statusbar_visible, - GPM_STATUSBAR_VISIBLE) - -/* Side Pane visiblity */ -DEFINE_BOOL_PREF (side_pane_visible, - GPM_SIDE_PANE_VISIBLE) - -/* Bottom Panel visiblity */ -DEFINE_BOOL_PREF (bottom_panel_visible, - GPM_BOTTOM_PANEL_VISIBLE) - -/* Print syntax highlighting */ -DEFINE_BOOL_PREF (print_syntax_hl, - GPM_PRINT_SYNTAX) - -/* Print header */ -DEFINE_BOOL_PREF (print_header, - GPM_PRINT_HEADER) - - -/* Print Wrap mode */ -GtkWrapMode -pluma_prefs_manager_get_print_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - pluma_debug (DEBUG_PREFS); - - str = pluma_prefs_manager_get_string (GPM_PRINT_WRAP_MODE); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_WORD") == 0) - res = GTK_WRAP_WORD; - else - res = GTK_WRAP_CHAR; - } - - g_free (str); - - return res; -} - -void -pluma_prefs_manager_set_print_wrap_mode (GtkWrapMode pwp) -{ - const gchar *str; - - pluma_debug (DEBUG_PREFS); - - switch (pwp) - { - case GTK_WRAP_NONE: - str = "GTK_WRAP_NONE"; - break; - - case GTK_WRAP_WORD: - str = "GTK_WRAP_WORD"; - break; - - default: /* GTK_WRAP_CHAR */ - str = "GTK_WRAP_CHAR"; - } - - pluma_prefs_manager_set_string (GPM_PRINT_WRAP_MODE, str); -} - -gboolean -pluma_prefs_manager_print_wrap_mode_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_PRINT_WRAP_MODE); -} - -/* Print line numbers */ -DEFINE_INT_PREF (print_line_numbers, - GPM_PRINT_LINE_NUMBERS) - -/* Printing fonts */ -DEFINE_STRING_PREF (print_font_body, - GPM_PRINT_FONT_BODY) - -static gchar * -pluma_prefs_manager_get_default_string_value (const gchar *key) -{ - gchar *font = NULL; - g_settings_delay (pluma_prefs_manager->settings); - g_settings_reset (pluma_prefs_manager->settings, key); - font = g_settings_get_string (pluma_prefs_manager->settings, key); - g_settings_revert (pluma_prefs_manager->settings); - return font; -} - -gchar * -pluma_prefs_manager_get_default_print_font_body (void) -{ - return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_BODY); -} - -DEFINE_STRING_PREF (print_font_header, - GPM_PRINT_FONT_HEADER) - -gchar * -pluma_prefs_manager_get_default_print_font_header (void) -{ - return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_HEADER); -} - -DEFINE_STRING_PREF (print_font_numbers, - GPM_PRINT_FONT_NUMBERS) - -gchar * -pluma_prefs_manager_get_default_print_font_numbers (void) -{ - return pluma_prefs_manager_get_default_string_value (GPM_PRINT_FONT_NUMBERS); -} - -/* Max number of files in "Recent Files" menu. - * This is configurable only using gsettings, dconf or dconf-editor - */ -gint -pluma_prefs_manager_get_max_recents (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_get_int (GPM_MAX_RECENTS); - -} - -/* GSettings/GSList utility functions from mate-panel */ - -GSList* -pluma_prefs_manager_get_gslist (GSettings *settings, const gchar *key) -{ - gchar **array; - GSList *list = NULL; - gint i; - array = g_settings_get_strv (settings, key); - if (array != NULL) { - for (i = 0; array[i]; i++) { - list = g_slist_append (list, g_strdup (array[i])); - } - } - g_strfreev (array); - return list; -} - -void -pluma_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list) -{ - GArray *array; - GSList *l; - array = g_array_new (TRUE, TRUE, sizeof (gchar *)); - for (l = list; l; l = l->next) { - array = g_array_append_val (array, l->data); - } - g_settings_set_strv (settings, key, (const gchar **) array->data); - g_array_free (array, TRUE); -} - - -/* Encodings */ - -static gboolean -data_exists (GSList *list, - const gpointer data) -{ - while (list != NULL) - { - if (list->data == data) - return TRUE; - - list = g_slist_next (list); - } - - return FALSE; -} - -GSList * -pluma_prefs_manager_get_auto_detected_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager != NULL, NULL); - g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL); - - strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_AUTO_DETECTED_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const PlumaEncoding *enc; - - tmp = strings; - - while (tmp) - { - const char *charset = tmp->data; - - if (strcmp (charset, "CURRENT") == 0) - g_get_charset (&charset); - - g_return_val_if_fail (charset != NULL, NULL); - enc = pluma_encoding_get_from_charset (charset); - - if (enc != NULL) - { - if (!data_exists (res, (gpointer)enc)) - res = g_slist_prepend (res, (gpointer)enc); - - } - - tmp = g_slist_next (tmp); - } - - g_slist_free_full (strings, g_free); - - res = g_slist_reverse (res); - } - - pluma_debug_message (DEBUG_PREFS, "Done"); - - return res; -} - -GSList * -pluma_prefs_manager_get_shown_in_menu_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager != NULL, NULL); - g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL); - - strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const PlumaEncoding *enc; - - tmp = strings; - - while (tmp) - { - const char *charset = tmp->data; - - if (strcmp (charset, "CURRENT") == 0) - g_get_charset (&charset); - - g_return_val_if_fail (charset != NULL, NULL); - enc = pluma_encoding_get_from_charset (charset); - - if (enc != NULL) - { - if (!data_exists (res, (gpointer)enc)) - res = g_slist_prepend (res, (gpointer)enc); - } - - tmp = g_slist_next (tmp); - } - - g_slist_free_full (strings, g_free); - - res = g_slist_reverse (res); - } - - return res; -} - -void -pluma_prefs_manager_set_shown_in_menu_encodings (const GSList *encs) -{ - GSList *list = NULL; - - g_return_if_fail (pluma_prefs_manager != NULL); - g_return_if_fail (pluma_prefs_manager->settings != NULL); - g_return_if_fail (pluma_prefs_manager_shown_in_menu_encodings_can_set ()); - - while (encs != NULL) - { - const PlumaEncoding *enc; - const gchar *charset; - - enc = (const PlumaEncoding *)encs->data; - - charset = pluma_encoding_get_charset (enc); - g_return_if_fail (charset != NULL); - - list = g_slist_prepend (list, (gpointer)charset); - - encs = g_slist_next (encs); - } - - list = g_slist_reverse (list); - - pluma_prefs_manager_set_gslist (pluma_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS, list); - - g_slist_free (list); -} - -gboolean -pluma_prefs_manager_shown_in_menu_encodings_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_SHOWN_IN_MENU_ENCODINGS); - -} - -/* Highlight current line */ -DEFINE_BOOL_PREF (highlight_current_line, - GPM_HIGHLIGHT_CURRENT_LINE) - -/* Highlight matching bracket */ -DEFINE_BOOL_PREF (bracket_matching, - GPM_BRACKET_MATCHING) - -/* Display Right Margin */ -DEFINE_BOOL_PREF (display_right_margin, - GPM_DISPLAY_RIGHT_MARGIN) - -/* Right Margin Position */ -DEFINE_INT_PREF (right_margin_position, - GPM_RIGHT_MARGIN_POSITION) - -static GtkSourceSmartHomeEndType -get_smart_home_end_from_string (const gchar *str) -{ - GtkSourceSmartHomeEndType res; - - g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); - - if (strcmp (str, "DISABLED") == 0) - res = GTK_SOURCE_SMART_HOME_END_DISABLED; - else if (strcmp (str, "BEFORE") == 0) - res = GTK_SOURCE_SMART_HOME_END_BEFORE; - else if (strcmp (str, "ALWAYS") == 0) - res = GTK_SOURCE_SMART_HOME_END_ALWAYS; - else - res = GTK_SOURCE_SMART_HOME_END_AFTER; - - return res; -} - -GtkSourceSmartHomeEndType -pluma_prefs_manager_get_smart_home_end (void) -{ - gchar *str; - GtkSourceSmartHomeEndType res; - - pluma_debug (DEBUG_PREFS); - - str = pluma_prefs_manager_get_string (GPM_SMART_HOME_END); - - res = get_smart_home_end_from_string (str); - - g_free (str); - - return res; -} - -void -pluma_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he) -{ - const gchar *str; - - pluma_debug (DEBUG_PREFS); - - switch (smart_he) - { - case GTK_SOURCE_SMART_HOME_END_DISABLED: - str = "DISABLED"; - break; - - case GTK_SOURCE_SMART_HOME_END_BEFORE: - str = "BEFORE"; - break; - - case GTK_SOURCE_SMART_HOME_END_ALWAYS: - str = "ALWAYS"; - break; - - default: /* GTK_SOURCE_SMART_HOME_END_AFTER */ - str = "AFTER"; - } - - pluma_prefs_manager_set_string (GPM_WRAP_MODE, str); -} - -gboolean -pluma_prefs_manager_smart_home_end_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_SMART_HOME_END); -} - -/* Enable syntax highlighting */ -DEFINE_BOOL_PREF (enable_syntax_highlighting, - GPM_SYNTAX_HL_ENABLE) - -/* Enable search highlighting */ -DEFINE_BOOL_PREF (enable_search_highlighting, - GPM_SEARCH_HIGHLIGHTING_ENABLE) - -/* Source style scheme */ -DEFINE_STRING_PREF (source_style_scheme, - GPM_SOURCE_STYLE_SCHEME) - -GSList * -pluma_prefs_manager_get_writable_vfs_schemes (void) -{ - GSList *strings; - - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager != NULL, NULL); - g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL); - - strings = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_WRITABLE_VFS_SCHEMES); - - /* The 'file' scheme is writable by default. */ - strings = g_slist_prepend (strings, g_strdup ("file")); - - pluma_debug_message (DEBUG_PREFS, "Done"); - - return strings; -} - -gboolean -pluma_prefs_manager_get_restore_cursor_position (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_get_bool (GPM_RESTORE_CURSOR_POSITION); -} - -/* Plugins: we just store/return a list of strings, all the magic has to - * happen in the plugin engine */ - -GSList * -pluma_prefs_manager_get_active_plugins (void) -{ - GSList *plugins; - - pluma_debug (DEBUG_PREFS); - - g_return_val_if_fail (pluma_prefs_manager != NULL, NULL); - g_return_val_if_fail (pluma_prefs_manager->settings != NULL, NULL); - - plugins = pluma_prefs_manager_get_gslist (pluma_prefs_manager->settings, GPM_ACTIVE_PLUGINS); - - return plugins; -} - -void -pluma_prefs_manager_set_active_plugins (const GSList *plugins) -{ - g_return_if_fail (pluma_prefs_manager != NULL); - g_return_if_fail (pluma_prefs_manager->settings != NULL); - g_return_if_fail (pluma_prefs_manager_active_plugins_can_set ()); - - pluma_prefs_manager_set_gslist (pluma_prefs_manager->settings, GPM_ACTIVE_PLUGINS, (GSList *) plugins); -} - -gboolean -pluma_prefs_manager_active_plugins_can_set (void) -{ - pluma_debug (DEBUG_PREFS); - - return pluma_prefs_manager_key_is_writable (GPM_ACTIVE_PLUGINS); -} - -/* Global Lockdown */ - -PlumaLockdownMask -pluma_prefs_manager_get_lockdown (void) -{ - guint lockdown = 0; - - if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_COMMAND_LINE)) - lockdown |= PLUMA_LOCKDOWN_COMMAND_LINE; - - if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_PRINTING)) - lockdown |= PLUMA_LOCKDOWN_PRINTING; - - if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_PRINT_SETUP)) - lockdown |= PLUMA_LOCKDOWN_PRINT_SETUP; - - if (g_settings_get_boolean (pluma_prefs_manager->lockdown_settings, GPM_LOCKDOWN_SAVE_TO_DISK)) - lockdown |= PLUMA_LOCKDOWN_SAVE_TO_DISK; - - return lockdown; -} - -/* enable drawing 'normal' spaces */ -DEFINE_ENUM_PREF(draw_spaces, - GPM_SPACE_DRAWER_SPACE) - -/* enable drawing tabs */ -DEFINE_ENUM_PREF(draw_tabs, - GPM_SPACE_DRAWER_TAB) - -/* enable drawing newline */ -DEFINE_BOOL_PREF(draw_newlines, - GPM_SPACE_DRAWER_NEWLINE) - -/* enable drawing nbsp */ -DEFINE_ENUM_PREF(draw_nbsp, - GPM_SPACE_DRAWER_NBSP) diff --git a/pluma/pluma-prefs-manager.h b/pluma/pluma-prefs-manager.h deleted file mode 100644 index 3d170dcb..00000000 --- a/pluma/pluma-prefs-manager.h +++ /dev/null @@ -1,359 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pluma-prefs-manager.h - * This file is part of pluma - * - * Copyright (C) 2002 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the pluma Team, 2002. See the AUTHORS file for a - * list of people on the pluma Team. - * See the ChangeLog files for a list of changes. - */ - -#ifndef __PLUMA_PREFS_MANAGER_H__ -#define __PLUMA_PREFS_MANAGER_H__ - -#include <gtk/gtk.h> -#include <glib.h> -#include <gtksourceview/gtksource.h> -#include "pluma-app.h" - -#define PLUMA_SCHEMA "org.mate.pluma" - -/* Editor */ -#define GPM_USE_DEFAULT_FONT "use-default-font" -#define GPM_EDITOR_FONT "editor-font" - -#define GPM_CREATE_BACKUP_COPY "create-backup-copy" - -#define GPM_AUTO_SAVE "auto-save" -#define GPM_AUTO_SAVE_INTERVAL "auto-save-interval" - -#define GPM_UNDO_ACTIONS_LIMIT "max-undo-actions" - -#define GPM_WRAP_MODE "wrap-mode" - -#define GPM_TABS_SIZE "tabs-size" -#define GPM_INSERT_SPACES "insert-spaces" - -#define GPM_AUTO_INDENT "auto-indent" - -#define GPM_DISPLAY_LINE_NUMBERS "display-line-numbers" - -#define GPM_HIGHLIGHT_CURRENT_LINE "highlight-current-line" - -#define GPM_BRACKET_MATCHING "bracket-matching" - -#define GPM_DISPLAY_RIGHT_MARGIN "display-right-margin" -#define GPM_RIGHT_MARGIN_POSITION "right-margin-position" - -#define GPM_SMART_HOME_END "smart-home-end" - -#define GPM_RESTORE_CURSOR_POSITION "restore-cursor-position" - -#define GPM_SEARCH_HIGHLIGHTING_ENABLE "enable-search-highlighting" - -#define GPM_SOURCE_STYLE_SCHEME "color-scheme" - -/* UI */ -#define GPM_TOOLBAR_VISIBLE "toolbar-visible" -#define GPM_TOOLBAR_BUTTONS_STYLE "toolbar-buttons-style" - -#define GPM_STATUSBAR_VISIBLE "statusbar-visible" - -#define GPM_SIDE_PANE_VISIBLE "side-pane-visible" - -#define GPM_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" - -#define GPM_MAX_RECENTS "max-recents" - -/* Print */ -#define GPM_PRINT_SYNTAX "print-syntax-highlighting" -#define GPM_PRINT_HEADER "print-header" -#define GPM_PRINT_WRAP_MODE "print-wrap-mode" -#define GPM_PRINT_LINE_NUMBERS "print-line-numbers" - -#define GPM_PRINT_FONT_BODY "print-font-body-pango" -#define GPM_PRINT_FONT_HEADER "print-font-header-pango" -#define GPM_PRINT_FONT_NUMBERS "print-font-numbers-pango" - -/* Encodings */ -#define GPM_AUTO_DETECTED_ENCODINGS "auto-detected-encodings" -#define GPM_SHOWN_IN_MENU_ENCODINGS "shown-in-menu-encodings" - -/* Syntax highlighting */ -#define GPM_SYNTAX_HL_ENABLE "enable-syntax-highlighting" - -/* White list of writable mate-vfs methods */ -#define GPM_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" - -/* Plugins */ -#define GPM_ACTIVE_PLUGINS "active-plugins" - -/* Global Interface keys */ -#define GPM_INTERFACE_SCHEMA "org.mate.interface" -#define GPM_SYSTEM_FONT "monospace-font-name" - -/* Global Lockdown keys */ -#define GPM_LOCKDOWN_SCHEMA "org.mate.lockdown" -#define GPM_LOCKDOWN_COMMAND_LINE "disable-command-line" -#define GPM_LOCKDOWN_PRINTING "disable-printing" -#define GPM_LOCKDOWN_PRINT_SETUP "disable-print-setup" -#define GPM_LOCKDOWN_SAVE_TO_DISK "disable-save-to-disk" - -/* Fallback default values. Keep in sync with org.mate.pluma.gschema.xml */ -#define GPM_DEFAULT_AUTO_SAVE_INTERVAL 10 /* minutes */ -#define GPM_DEFAULT_MAX_RECENTS 5 - -/* space drawer settings */ -#define GPM_SPACE_DRAWER_SPACE "enable-space-drawer-space" -#define GPM_SPACE_DRAWER_TAB "enable-space-drawer-tab" -#define GPM_SPACE_DRAWER_NEWLINE "enable-space-drawer-newline" -#define GPM_SPACE_DRAWER_NBSP "enable-space-drawer-nbsp" - -typedef enum { - PLUMA_TOOLBAR_SYSTEM = 0, - PLUMA_TOOLBAR_ICONS, - PLUMA_TOOLBAR_ICONS_AND_TEXT, - PLUMA_TOOLBAR_ICONS_BOTH_HORIZ -} PlumaToolbarSetting; - -/* LIFE CYCLE MANAGEMENT FUNCTIONS */ - -gboolean pluma_prefs_manager_init (void); - -/* This function must be called before exiting pluma */ -void pluma_prefs_manager_shutdown (void); - - -/* PREFS MANAGEMENT FUNCTIONS */ - -/* Use default font */ -gboolean pluma_prefs_manager_get_use_default_font (void); -void pluma_prefs_manager_set_use_default_font (gboolean udf); -gboolean pluma_prefs_manager_use_default_font_can_set (void); - -/* Editor font */ -gchar *pluma_prefs_manager_get_editor_font (void); -void pluma_prefs_manager_set_editor_font (const gchar *font); -gboolean pluma_prefs_manager_editor_font_can_set (void); - -/* System font */ -gchar *pluma_prefs_manager_get_system_font (void); - -/* Create backup copy */ -gboolean pluma_prefs_manager_get_create_backup_copy (void); -void pluma_prefs_manager_set_create_backup_copy (gboolean cbc); -gboolean pluma_prefs_manager_create_backup_copy_can_set (void); - -/* Auto save */ -gboolean pluma_prefs_manager_get_auto_save (void); -void pluma_prefs_manager_set_auto_save (gboolean as); -gboolean pluma_prefs_manager_auto_save_can_set (void); - -/* Auto save interval */ -gint pluma_prefs_manager_get_auto_save_interval (void); -void pluma_prefs_manager_set_auto_save_interval (gint asi); -gboolean pluma_prefs_manager_auto_save_interval_can_set (void); - -/* Undo actions limit: if < 1 then no limits */ -gint pluma_prefs_manager_get_undo_actions_limit (void); -void pluma_prefs_manager_set_undo_actions_limit (gint ual); -gboolean pluma_prefs_manager_undo_actions_limit_can_set (void); - -/* Wrap mode */ -GtkWrapMode pluma_prefs_manager_get_wrap_mode (void); -void pluma_prefs_manager_set_wrap_mode (GtkWrapMode wp); -gboolean pluma_prefs_manager_wrap_mode_can_set (void); - -/* Tabs size */ -gint pluma_prefs_manager_get_tabs_size (void); -void pluma_prefs_manager_set_tabs_size (gint ts); -gboolean pluma_prefs_manager_tabs_size_can_set (void); - -/* Insert spaces */ -gboolean pluma_prefs_manager_get_insert_spaces (void); -void pluma_prefs_manager_set_insert_spaces (gboolean ai); -gboolean pluma_prefs_manager_insert_spaces_can_set (void); - -/* Auto indent */ -gboolean pluma_prefs_manager_get_auto_indent (void); -void pluma_prefs_manager_set_auto_indent (gboolean ai); -gboolean pluma_prefs_manager_auto_indent_can_set (void); - -/* Display line numbers */ -gboolean pluma_prefs_manager_get_display_line_numbers (void); -void pluma_prefs_manager_set_display_line_numbers (gboolean dln); -gboolean pluma_prefs_manager_display_line_numbers_can_set (void); - -/* Toolbar visible */ -gboolean pluma_prefs_manager_get_toolbar_visible (void); -void pluma_prefs_manager_set_toolbar_visible (gboolean tv); -gboolean pluma_prefs_manager_toolbar_visible_can_set (void); - -/* Toolbar buttons style */ -PlumaToolbarSetting pluma_prefs_manager_get_toolbar_buttons_style (void); -void pluma_prefs_manager_set_toolbar_buttons_style (PlumaToolbarSetting tbs); -gboolean pluma_prefs_manager_toolbar_buttons_style_can_set (void); - -/* Statusbar visible */ -gboolean pluma_prefs_manager_get_statusbar_visible (void); -void pluma_prefs_manager_set_statusbar_visible (gboolean sv); -gboolean pluma_prefs_manager_statusbar_visible_can_set (void); - -/* Side pane visible */ -gboolean pluma_prefs_manager_get_side_pane_visible (void); -void pluma_prefs_manager_set_side_pane_visible (gboolean tv); -gboolean pluma_prefs_manager_side_pane_visible_can_set (void); - -/* Bottom panel visible */ -gboolean pluma_prefs_manager_get_bottom_panel_visible (void); -void pluma_prefs_manager_set_bottom_panel_visible (gboolean tv); -gboolean pluma_prefs_manager_bottom_panel_visible_can_set(void); -/* Print syntax highlighting */ -gboolean pluma_prefs_manager_get_print_syntax_hl (void); -void pluma_prefs_manager_set_print_syntax_hl (gboolean ps); -gboolean pluma_prefs_manager_print_syntax_hl_can_set (void); - -/* Print header */ -gboolean pluma_prefs_manager_get_print_header (void); -void pluma_prefs_manager_set_print_header (gboolean ph); -gboolean pluma_prefs_manager_print_header_can_set (void); - -/* Wrap mode while printing */ -GtkWrapMode pluma_prefs_manager_get_print_wrap_mode (void); -void pluma_prefs_manager_set_print_wrap_mode (GtkWrapMode pwm); -gboolean pluma_prefs_manager_print_wrap_mode_can_set (void); - -/* Print line numbers */ -gint pluma_prefs_manager_get_print_line_numbers (void); -void pluma_prefs_manager_set_print_line_numbers (gint pln); -gboolean pluma_prefs_manager_print_line_numbers_can_set (void); - -/* Font used to print the body of documents */ -gchar *pluma_prefs_manager_get_print_font_body (void); -void pluma_prefs_manager_set_print_font_body (const gchar *font); -gboolean pluma_prefs_manager_print_font_body_can_set (void); -gchar *pluma_prefs_manager_get_default_print_font_body (void); - -/* Font used to print headers */ -gchar *pluma_prefs_manager_get_print_font_header (void); -void pluma_prefs_manager_set_print_font_header (const gchar *font); -gboolean pluma_prefs_manager_print_font_header_can_set (void); -gchar *pluma_prefs_manager_get_default_print_font_header (void); - -/* Font used to print line numbers */ -gchar *pluma_prefs_manager_get_print_font_numbers (void); -void pluma_prefs_manager_set_print_font_numbers (const gchar *font); -gboolean pluma_prefs_manager_print_font_numbers_can_set (void); -gchar *pluma_prefs_manager_get_default_print_font_numbers (void); - -/* Max number of files in "Recent Files" menu. - * This is configurable only using gsettings, dconf or dconf-editor - */ -gint pluma_prefs_manager_get_max_recents (void); - -/* Encodings */ -GSList *pluma_prefs_manager_get_auto_detected_encodings (void); - -GSList *pluma_prefs_manager_get_shown_in_menu_encodings (void); -void pluma_prefs_manager_set_shown_in_menu_encodings (const GSList *encs); -gboolean pluma_prefs_manager_shown_in_menu_encodings_can_set (void); - -/* Highlight current line */ -gboolean pluma_prefs_manager_get_highlight_current_line (void); -void pluma_prefs_manager_set_highlight_current_line (gboolean hl); -gboolean pluma_prefs_manager_highlight_current_line_can_set (void); - -/* Highlight matching bracket */ -gboolean pluma_prefs_manager_get_bracket_matching (void); -void pluma_prefs_manager_set_bracket_matching (gboolean bm); -gboolean pluma_prefs_manager_bracket_matching_can_set (void); - -/* Display right margin */ -gboolean pluma_prefs_manager_get_display_right_margin (void); -void pluma_prefs_manager_set_display_right_margin (gboolean drm); -gboolean pluma_prefs_manager_display_right_margin_can_set (void); - -/* Right margin position */ -gint pluma_prefs_manager_get_right_margin_position (void); -void pluma_prefs_manager_set_right_margin_position (gint rmp); -gboolean pluma_prefs_manager_right_margin_position_can_set (void); - -/* Smart home end */ -GtkSourceSmartHomeEndType - pluma_prefs_manager_get_smart_home_end (void); -void pluma_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he); -gboolean pluma_prefs_manager_smart_home_end_can_set (void); - -/* Enable syntax highlighting */ -gboolean pluma_prefs_manager_get_enable_syntax_highlighting (void); -void pluma_prefs_manager_set_enable_syntax_highlighting (gboolean esh); -gboolean pluma_prefs_manager_enable_syntax_highlighting_can_set (void); - -/* Writable VFS schemes */ -GSList *pluma_prefs_manager_get_writable_vfs_schemes (void); - -/* Restore cursor position */ -gboolean pluma_prefs_manager_get_restore_cursor_position (void); - -/* Enable search highlighting */ -gboolean pluma_prefs_manager_get_enable_search_highlighting (void); -void pluma_prefs_manager_set_enable_search_highlighting (gboolean esh); -gboolean pluma_prefs_manager_enable_search_highlighting_can_set (void); - -/* Style scheme */ -gchar *pluma_prefs_manager_get_source_style_scheme (void); -void pluma_prefs_manager_set_source_style_scheme (const gchar *scheme); -gboolean pluma_prefs_manager_source_style_scheme_can_set(void); - -/* Plugins */ -GSList *pluma_prefs_manager_get_active_plugins (void); -void pluma_prefs_manager_set_active_plugins (const GSList *plugins); -gboolean pluma_prefs_manager_active_plugins_can_set (void); - -/* Global lockdown */ -PlumaLockdownMask pluma_prefs_manager_get_lockdown (void); - -/* GSettings utilities */ -GSList* pluma_prefs_manager_get_gslist (GSettings *settings, const gchar *key); -void pluma_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list); - -/* Enable drawing space */ -gint pluma_prefs_manager_get_draw_spaces (void); -void pluma_prefs_manager_set_draw_spaces (gint enable_draw_spaces); -gboolean pluma_prefs_manager_draw_spaces_can_set (void); - -/* Enable drawing tab */ -gint pluma_prefs_manager_get_draw_tabs (void); -void pluma_prefs_manager_set_draw_tabs (gint enable_draw_tabs); -gboolean pluma_prefs_manager_draw_tabs_can_set (void); - -/* Enable drawing newline */ -gboolean pluma_prefs_manager_get_draw_newlines (void); -void pluma_prefs_manager_set_draw_newlines (gboolean enable_draw_newlines); -gboolean pluma_prefs_manager_draw_newlines_can_set (void); - -/* Enable drawing nbsp */ -gint pluma_prefs_manager_get_draw_nbsp (void); -void pluma_prefs_manager_set_draw_nbsp (gint enable_draw_nbsp); -gboolean pluma_prefs_manager_draw_nbsp_can_set (void); - -#endif /* __PLUMA_PREFS_MANAGER_H__ */ diff --git a/pluma/pluma-print-job.c b/pluma/pluma-print-job.c index 63b4cf0a..4fc92b87 100644 --- a/pluma/pluma-print-job.c +++ b/pluma/pluma-print-job.c @@ -38,15 +38,16 @@ #include "pluma-print-job.h" #include "pluma-debug.h" -#include "pluma-prefs-manager.h" #include "pluma-print-preview.h" #include "pluma-marshal.h" #include "pluma-utils.h" #include "pluma-dirs.h" - +#include "pluma-settings.h" struct _PlumaPrintJobPrivate { + GSettings *print_settings; + PlumaView *view; PlumaDocument *doc; @@ -164,6 +165,16 @@ pluma_print_job_finalize (GObject *object) } static void +pluma_print_job_dispose (GObject *object) +{ + PlumaPrintJob *job = PLUMA_PRINT_JOB (object); + + g_clear_object (&job->priv->print_settings); + + G_OBJECT_CLASS (pluma_print_job_parent_class)->dispose (object); +} + +static void pluma_print_job_class_init (PlumaPrintJobClass *klass) { GObjectClass *object_class; @@ -173,6 +184,7 @@ pluma_print_job_class_init (PlumaPrintJobClass *klass) object_class->get_property = pluma_print_job_get_property; object_class->set_property = pluma_print_job_set_property; object_class->finalize = pluma_print_job_finalize; + object_class->dispose = pluma_print_job_dispose; g_object_class_install_property (object_class, PROP_VIEW, @@ -223,15 +235,8 @@ static void line_numbers_checkbutton_toggled (GtkToggleButton *button, PlumaPrintJob *job) { - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, - pluma_prefs_manager_print_line_numbers_can_set ()); - } - else - { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, FALSE); - } + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, + gtk_toggle_button_get_active (button)); } static void @@ -261,41 +266,27 @@ restore_button_clicked (GtkButton *button, PlumaPrintJob *job) { - if (pluma_prefs_manager_print_font_body_can_set ()) - { - gchar *font; - - font = pluma_prefs_manager_get_default_print_font_body (); - - gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->body_fontbutton), - font); - - g_free (font); - } - - if (pluma_prefs_manager_print_font_header_can_set ()) - { - gchar *font; + gchar *body, *header, *numbers; - font = pluma_prefs_manager_get_default_print_font_header (); - - gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->headers_fontbutton), - font); - - g_free (font); - } + body = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_BODY_PANGO); + header = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_HEADER_PANGO); + numbers = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_NUMBERS_PANGO); - if (pluma_prefs_manager_print_font_numbers_can_set ()) - { - gchar *font; + gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->body_fontbutton), + body); - font = pluma_prefs_manager_get_default_print_font_numbers (); + gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->headers_fontbutton), + header); - gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->numbers_fontbutton), - font); + gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->numbers_fontbutton), + numbers); - g_free (font); - } + g_free (body); + g_free (header); + g_free (numbers); } static GObject * @@ -305,11 +296,12 @@ create_custom_widget_cb (GtkPrintOperation *operation, gboolean ret; GtkWidget *widget; GtkWidget *error_widget; - gchar *font; - gint line_numbers; - gboolean can_set; + guint line_numbers; GtkWrapMode wrap_mode; gchar *file; + gboolean syntax_hl; + gboolean print_header; + gchar *font_body, *font_header, *font_numbers; gchar *root_objects[] = { "adjustment1", "contents", @@ -344,31 +336,38 @@ create_custom_widget_cb (GtkPrintOperation *operation, return G_OBJECT (error_widget); } + /* Get all settings values */ + syntax_hl = g_settings_get_boolean (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_header = g_settings_get_boolean (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_HEADER); + line_numbers = g_settings_get_uint (job->priv->print_settings, PLUMA_SETTINGS_PRINT_LINE_NUMBERS); + + font_body = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_BODY_PANGO); + font_header = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_HEADER_PANGO); + font_numbers = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + /* Print syntax */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), - pluma_prefs_manager_get_print_syntax_hl ()); - gtk_widget_set_sensitive (job->priv->syntax_checkbutton, - pluma_prefs_manager_print_syntax_hl_can_set ()); + syntax_hl); /* Print page headers */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), - pluma_prefs_manager_get_print_header ()); - gtk_widget_set_sensitive (job->priv->page_header_checkbutton, - pluma_prefs_manager_print_header_can_set ()); + print_header); - /* Line numbers */ - line_numbers = pluma_prefs_manager_get_print_line_numbers (); - can_set = pluma_prefs_manager_print_line_numbers_can_set (); + /* Line numbers */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), line_numbers > 0); - gtk_widget_set_sensitive (job->priv->line_numbers_checkbutton, can_set); if (line_numbers > 0) { gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), (guint) line_numbers); - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, can_set); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, TRUE); } else { @@ -378,7 +377,8 @@ create_custom_widget_cb (GtkPrintOperation *operation, } /* Text wrapping */ - wrap_mode = pluma_prefs_manager_get_print_wrap_mode (); + wrap_mode = pluma_settings_get_wrap_mode (job->priv->print_settings, + PLUMA_SETTINGS_WRAP_MODE); switch (wrap_mode) { @@ -401,39 +401,21 @@ create_custom_widget_cb (GtkPrintOperation *operation, GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); } - can_set = pluma_prefs_manager_print_wrap_mode_can_set (); - - gtk_widget_set_sensitive (job->priv->text_wrapping_checkbutton, can_set); gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, - can_set && (wrap_mode != GTK_WRAP_NONE)); + (wrap_mode != GTK_WRAP_NONE)); /* Set initial values */ - font = pluma_prefs_manager_get_print_font_body (); gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->body_fontbutton), - font); - g_free (font); + font_body); + g_free (font_body); - font = pluma_prefs_manager_get_print_font_header (); gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->headers_fontbutton), - font); - g_free (font); + font_header); + g_free (font_header); - font = pluma_prefs_manager_get_print_font_numbers (); gtk_font_chooser_set_font (GTK_FONT_CHOOSER (job->priv->numbers_fontbutton), - font); - g_free (font); - - can_set = pluma_prefs_manager_print_font_body_can_set (); - gtk_widget_set_sensitive (job->priv->body_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->body_font_label, can_set); - - can_set = pluma_prefs_manager_print_font_header_can_set (); - gtk_widget_set_sensitive (job->priv->headers_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->headers_font_label, can_set); - - can_set = pluma_prefs_manager_print_font_numbers_can_set (); - gtk_widget_set_sensitive (job->priv->numbers_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->numbers_font_label, can_set); + font_numbers); + g_free (font_numbers); g_signal_connect (job->priv->line_numbers_checkbutton, "toggled", @@ -460,39 +442,63 @@ custom_widget_apply_cb (GtkPrintOperation *operation, GtkWidget *widget, PlumaPrintJob *job) { - pluma_prefs_manager_set_print_syntax_hl (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton))); + gboolean syntax, page_header; + const gchar *body, *header, *numbers; + + syntax = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton)); + page_header = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton)); + body = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->body_fontbutton)); + header = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->headers_fontbutton)); + numbers = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->numbers_fontbutton)); + + g_settings_set_boolean (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING, syntax); + g_settings_set_boolean (job->priv->print_settings, PLUMA_SETTINGS_PRINT_HEADER, + page_header); + g_settings_set_string (job->priv->print_settings, PLUMA_SETTINGS_PRINT_FONT_BODY_PANGO, + body); + g_settings_set_string (job->priv->print_settings, PLUMA_SETTINGS_PRINT_FONT_HEADER_PANGO, + header); + g_settings_set_string (job->priv->print_settings, PLUMA_SETTINGS_PRINT_FONT_NUMBERS_PANGO, + numbers); - pluma_prefs_manager_set_print_header (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton))); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton))) { - pluma_prefs_manager_set_print_line_numbers ( - MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); + g_settings_set_uint (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_LINE_NUMBERS, + MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); + } else { - pluma_prefs_manager_set_print_line_numbers (0); + g_settings_set_uint (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_LINE_NUMBERS, 0); } if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) { - pluma_prefs_manager_set_print_wrap_mode (GTK_WRAP_NONE); + pluma_settings_set_wrap_mode (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_WRAP_MODE, + GTK_WRAP_NONE); } else { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton))) { - pluma_prefs_manager_set_print_wrap_mode (GTK_WRAP_WORD); + pluma_settings_set_wrap_mode (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_WRAP_MODE, + GTK_WRAP_WORD); + } else { - pluma_prefs_manager_set_print_wrap_mode (GTK_WRAP_CHAR); + pluma_settings_set_wrap_mode (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_WRAP_MODE, + GTK_WRAP_CHAR); + } } - - pluma_prefs_manager_set_print_font_body (gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->body_fontbutton))); - pluma_prefs_manager_set_print_font_header (gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->headers_fontbutton))); - pluma_prefs_manager_set_print_font_numbers (gtk_font_chooser_get_font (GTK_FONT_CHOOSER (job->priv->numbers_fontbutton))); } static void @@ -501,21 +507,40 @@ create_compositor (PlumaPrintJob *job) gchar *print_font_body; gchar *print_font_header; gchar *print_font_numbers; + gboolean syntax_hl; + GtkWrapMode wrap_mode; + guint print_line_numbers; + gboolean print_header; + /* Create and initialize print compositor */ - print_font_body = pluma_prefs_manager_get_print_font_body (); - print_font_header = pluma_prefs_manager_get_print_font_header (); - print_font_numbers = pluma_prefs_manager_get_print_font_numbers (); + print_font_body = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_BODY_PANGO); + print_font_header = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_HEADER_PANGO); + print_font_numbers = g_settings_get_string (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + syntax_hl = g_settings_get_boolean (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_line_numbers = g_settings_get_uint (job->priv->print_settings, PLUMA_SETTINGS_PRINT_LINE_NUMBERS); + print_header = g_settings_get_boolean (job->priv->print_settings, + PLUMA_SETTINGS_PRINT_HEADER); + wrap_mode = pluma_settings_get_wrap_mode (job->priv->print_settings, + PLUMA_SETTINGS_WRAP_MODE); + job->priv->compositor = GTK_SOURCE_PRINT_COMPOSITOR ( g_object_new (GTK_SOURCE_TYPE_PRINT_COMPOSITOR, "buffer", GTK_SOURCE_BUFFER (job->priv->doc), "tab-width", gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (job->priv->view)), "highlight-syntax", gtk_source_buffer_get_highlight_syntax (GTK_SOURCE_BUFFER (job->priv->doc)) && - pluma_prefs_manager_get_print_syntax_hl (), - "wrap-mode", pluma_prefs_manager_get_print_wrap_mode (), - "print-line-numbers", pluma_prefs_manager_get_print_line_numbers (), - "print-header", pluma_prefs_manager_get_print_header (), + syntax_hl, + "wrap-mode", wrap_mode, + "print-line-numbers", print_line_numbers, + "print-header", print_header, + "print-footer", FALSE, + "body-font-name", print_font_body, + "line-numbers-font-name", print_font_numbers, "print-footer", FALSE, "body-font-name", print_font_body, "line-numbers-font-name", print_font_numbers, @@ -526,7 +551,7 @@ create_compositor (PlumaPrintJob *job) g_free (print_font_header); g_free (print_font_numbers); - if (pluma_prefs_manager_get_print_header ()) + if (print_header) { gchar *doc_name; gchar *name_to_display; @@ -799,6 +824,8 @@ pluma_print_job_init (PlumaPrintJob *job) { job->priv = pluma_print_job_get_instance_private (job); + job->priv->print_settings = g_settings_new (PLUMA_SCHEMA_ID); + job->priv->status = PLUMA_PRINT_JOB_STATUS_INIT; job->priv->status_string = g_strdup (_("Preparing...")); diff --git a/pluma/pluma-session.c b/pluma/pluma-session.c index 85773460..ff154609 100644 --- a/pluma/pluma-session.c +++ b/pluma/pluma-session.c @@ -46,7 +46,6 @@ #include "pluma-debug.h" #include "pluma-plugins-engine.h" -#include "pluma-prefs-manager-app.h" #include "pluma-metadata-manager.h" #include "pluma-window.h" #include "pluma-app.h" diff --git a/pluma/pluma-settings.c b/pluma/pluma-settings.c new file mode 100644 index 00000000..1cfb7ea3 --- /dev/null +++ b/pluma/pluma-settings.c @@ -0,0 +1,1110 @@ +/* + * pluma-settings.c + * This file is part of pluma + * + * Copyright (C) 2002-2005 - Paolo Maggi + * Copyright (C) 2009 - Ignacio Casal Quinteiro + * Copyright (C) 2020 - MATE Desktop Team + * + * pluma is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * pluma is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with pluma; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include <string.h> + +#include "pluma-settings.h" +#include "pluma-debug.h" +#include "pluma-view.h" +#include "pluma-window.h" +#include "pluma-style-scheme-manager.h" +#include "pluma-window-private.h" + +#define PLUMA_SETTINGS_LOCKDOWN_COMMAND_LINE "disable-command-line" +#define PLUMA_SETTINGS_LOCKDOWN_PRINTING "disable-printing" +#define PLUMA_SETTINGS_LOCKDOWN_PRINT_SETUP "disable-print-setup" +#define PLUMA_SETTINGS_LOCKDOWN_SAVE_TO_DISK "disable-save-to-disk" + +#define PLUMA_SETTINGS_SYSTEM_FONT "monospace-font-name" + +struct _PlumaSettingsPrivate +{ + GSettings *editor_settings; + GSettings *lockdown_settings; + GSettings *interface_settings; + + gchar *old_scheme; +}; + +/* PlumaSettings is a singleton. */ +static PlumaSettings *singleton = NULL; + +G_DEFINE_TYPE_WITH_PRIVATE (PlumaSettings, pluma_settings, G_TYPE_OBJECT) + +static void +pluma_settings_dispose (GObject *object) +{ + PlumaSettingsPrivate *priv = pluma_settings_get_instance_private (PLUMA_SETTINGS(object)); + + g_clear_object (&priv->lockdown_settings); + g_clear_object (&priv->interface_settings); + g_clear_object (&priv->editor_settings); + + G_OBJECT_CLASS (pluma_settings_parent_class)->dispose (object); +} + +static void +pluma_settings_finalize (GObject *object) +{ + PlumaSettings *self = PLUMA_SETTINGS (object); + + g_free (self->priv->old_scheme); + + if (singleton == self) + { + singleton = NULL; + } + + G_OBJECT_CLASS (pluma_settings_parent_class)->finalize (object); +} + +#ifdef GTK_SOURCE_VERSION_3_24 +static void +pluma_settings_space_drawer_generic (GSettings *settings, + gint level, + GtkSourceSpaceTypeFlags type) +{ + GList *views; + GList *l; + + pluma_debug (DEBUG_PREFS); + + views = pluma_app_get_views (pluma_app_get_default ()); + l = views; + + while (l != NULL) + { + pluma_set_source_space_drawer_by_level (GTK_SOURCE_VIEW (l->data), + level, type); + l = l->next; + } + + g_list_free (views); +} +#else +static void +pluma_settings_draw_generic (GSettings *settings, + gint level, + GtkSourceSpaceTypeFlags type) +{ + GList *views; + GList *l; + + pluma_debug (DEBUG_PREFS); + + views = pluma_app_get_views (pluma_app_get_default ()); + l = views; + + while (l != NULL) + { + GtkSourceSpaceTypeFlags value; + + value = gtk_source_view_get_draw_spaces (GTK_SOURCE_VIEW (l->data)); + if (level > 0) + value |= type; + else + value &= ~type; + gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (l->data), + value); + l = l->next; + } + + g_list_free (views); +} +#endif + +static void +on_lockdown_changed (GSettings *settings, + const gchar *key, + gpointer useless) +{ + gboolean locked; + PlumaApp *app; + + locked = g_settings_get_boolean (settings, key); + app = pluma_app_get_default (); + + if (strcmp (key, PLUMA_SETTINGS_LOCKDOWN_COMMAND_LINE) == 0) + _pluma_app_set_lockdown_bit (app, + PLUMA_LOCKDOWN_COMMAND_LINE, + locked); + else if (strcmp (key, PLUMA_SETTINGS_LOCKDOWN_PRINTING) == 0) + _pluma_app_set_lockdown_bit (app, + PLUMA_LOCKDOWN_PRINTING, + locked); + else if (strcmp (key, PLUMA_SETTINGS_LOCKDOWN_PRINT_SETUP) == 0) + _pluma_app_set_lockdown_bit (app, + PLUMA_LOCKDOWN_PRINT_SETUP, + locked); + else if (strcmp (key, PLUMA_SETTINGS_LOCKDOWN_SAVE_TO_DISK) == 0) + _pluma_app_set_lockdown_bit (app, + PLUMA_LOCKDOWN_SAVE_TO_DISK, + locked); +} + +static void +set_font (PlumaSettings *self, + const gchar *font) +{ + GList *views, *l; + guint ts; + + ts = g_settings_get_uint (self->priv->editor_settings, PLUMA_SETTINGS_TABS_SIZE); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + /* Note: we use def=FALSE to avoid PlumaView to query gconf */ + pluma_view_set_font (PLUMA_VIEW (l->data), FALSE, font); + + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + } + + g_list_free (views); +} + +static void +on_system_font_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (self->priv->editor_settings, + PLUMA_SETTINGS_USE_DEFAULT_FONT); + if (!use_default_font) + return; + + font = g_settings_get_string (settings, key); + + set_font (self, font); + + g_free (font); +} + +static void +on_use_default_font_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + gboolean def; + gchar *font; + + def = g_settings_get_boolean (settings, key); + + if (def) + { + font = g_settings_get_string (self->priv->interface_settings, + PLUMA_SETTINGS_SYSTEM_FONT); + } + else + { + font = g_settings_get_string (self->priv->editor_settings, + PLUMA_SETTINGS_EDITOR_FONT); + } + + set_font (self, font); + + g_free (font); +} + +static void +on_editor_font_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (self->priv->editor_settings, + PLUMA_SETTINGS_USE_DEFAULT_FONT); + if (use_default_font) + return; + + font = g_settings_get_string (settings, key); + + set_font (self, font); + + g_free (font); +} + +static void +on_scheme_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GtkSourceStyleScheme *style; + gchar *scheme; + GList *docs; + GList *l; + + scheme = g_settings_get_string (settings, key); + + if (self->priv->old_scheme != NULL && (strcmp (scheme, self->priv->old_scheme) == 0)) + { + g_free (scheme); + return; + } + + g_free (self->priv->old_scheme); + self->priv->old_scheme = scheme; + + style = gtk_source_style_scheme_manager_get_scheme (pluma_get_style_scheme_manager (), + scheme); + + if (style == NULL) + { + g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); + + style = gtk_source_style_scheme_manager_get_scheme (pluma_get_style_scheme_manager (), + "classic"); + + if (style == NULL) + { + g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); + return; + } + } + + docs = pluma_app_get_documents (pluma_app_get_default ()); + for (l = docs; l != NULL; l = g_list_next (l)) + { + g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); + + gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); + } + + g_list_free (docs); +} + +static void +on_auto_save_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *docs, *l; + gboolean auto_save; + + auto_save = g_settings_get_boolean (settings, key); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + PlumaTab *tab = pluma_tab_get_from_document (PLUMA_DOCUMENT (l->data)); + + pluma_tab_set_auto_save_enabled (tab, auto_save); + } + + g_list_free (docs); +} + +static void +on_auto_save_interval_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *docs, *l; + guint auto_save_interval; + + auto_save_interval = g_settings_get_uint (settings, key); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + PlumaTab *tab = pluma_tab_get_from_document (PLUMA_DOCUMENT (l->data)); + + pluma_tab_set_auto_save_interval (tab, auto_save_interval); + } + + g_list_free (docs); +} + +static void +on_undo_actions_limit_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *docs, *l; + gint ul; + + ul = g_settings_get_int (settings, key); + + ul = CLAMP (ul, -1, 250); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); + } + + g_list_free (docs); +} + +static void +on_wrap_mode_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GtkWrapMode wrap_mode; + GList *views, *l; + + wrap_mode = pluma_settings_get_wrap_mode (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), wrap_mode); + } + + g_list_free (views); +} + +static void +on_tabs_size_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + guint ts; + + ts = g_settings_get_uint (settings, key); + + ts = CLAMP (ts, 1, 24); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + } + + g_list_free (views); +} + +static void +on_insert_spaces_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + gboolean spaces; + + spaces = g_settings_get_boolean (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), + spaces); + } + + g_list_free (views); +} + +static void +on_auto_indent_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); + } + + g_list_free (views); +} + +static void +on_display_line_numbers_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + gboolean line_numbers; + + line_numbers = g_settings_get_boolean (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), line_numbers); + } + + g_list_free (views); +} + +static void +on_hl_current_line_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + gboolean hl; + + hl = g_settings_get_boolean (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); + } + + g_list_free (views); +} + +static void +on_bracket_matching_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), + enable); + } + + g_list_free (docs); +} + +static void +on_display_right_margin_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + gboolean display; + + display = g_settings_get_boolean (settings, key); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); + } + + g_list_free (views); +} + +static void +on_right_margin_position_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *views, *l; + guint pos; + + pos = g_settings_get_uint (settings, key); + + pos = CLAMP (pos, 1, 160); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); + } + + g_list_free (views); +} + +static void +on_smart_home_end_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GtkSourceSmartHomeEndType smart_he; + GList *views, *l; + + smart_he = pluma_settings_get_smart_home_end (self); + + views = pluma_app_get_views (pluma_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); + } + + g_list_free (views); +} + +static void +on_syntax_highlighting_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + const GList *windows; + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); + } + + g_list_free (docs); + + /* update the sensitivity of the Higlight Mode menu item */ + windows = pluma_app_get_windows (pluma_app_get_default ()); + while (windows != NULL) + { + GtkUIManager *ui; + GtkAction *a; + + ui = pluma_window_get_ui_manager (PLUMA_WINDOW (windows->data)); + + a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); + + gtk_action_set_sensitive (a, enable); + + windows = g_list_next (windows); + } +} + +static void +on_search_highlighting_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = pluma_app_get_documents (pluma_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + pluma_document_set_enable_search_highlighting (PLUMA_DOCUMENT (l->data), + enable); + } + + g_list_free (docs); +} + +static void +on_max_recents_changed (GSettings *settings, + const gchar *key, + PlumaSettings *self) +{ + const GList *windows; + guint max; + + max = g_settings_get_uint (settings, key); + + windows = pluma_app_get_windows (pluma_app_get_default ()); + while (windows != NULL) + { + PlumaWindow *w = PLUMA_WINDOW (windows->data); + + gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu), + max); + + windows = g_list_next (windows); + } + + /* FIXME: we have no way at the moment to trigger the + * update of the inline recents in the File menu */ +} + +static void +on_draw_spaces_changed (GSettings *settings, + gchar *key, + gpointer user_data) +{ + pluma_debug (DEBUG_PREFS); + + if (strcmp (key, PLUMA_SETTINGS_DRAWER_SPACE)) + return; + +#ifdef GTK_SOURCE_VERSION_3_24 + pluma_settings_space_drawer_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_SPACE_TYPE_SPACE); +#else + pluma_settings_draw_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_DRAW_SPACES_SPACE); +#endif +} + +static void +on_draw_tabs_changed (GSettings *settings, + gchar *key, + gpointer user_data) +{ + pluma_debug (DEBUG_PREFS); + + if (strcmp (key, PLUMA_SETTINGS_DRAWER_TAB)) + return; + +#ifdef GTK_SOURCE_VERSION_3_24 + pluma_settings_space_drawer_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_SPACE_TYPE_TAB); +#else + pluma_settings_draw_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_DRAW_SPACES_TAB); +#endif +} + +static void +on_draw_newlines_changed (GSettings *settings, + gchar *key, + gpointer user_data) +{ + pluma_debug (DEBUG_PREFS); + + if (strcmp (key, PLUMA_SETTINGS_DRAWER_NEWLINE)) + return; + +#ifdef GTK_SOURCE_VERSION_3_24 + pluma_settings_space_drawer_generic (settings, + g_settings_get_boolean (settings, key) ? 1 : 0, + GTK_SOURCE_SPACE_TYPE_NEWLINE); +#else + pluma_settings_draw_generic (settings, + g_settings_get_boolean (settings, key) ? 1 : 0, + GTK_SOURCE_DRAW_SPACES_NEWLINE); +#endif +} + +static void +on_draw_nbsp_changed (GSettings *settings, + gchar *key, + gpointer user_data) +{ + pluma_debug (DEBUG_PREFS); + + if (strcmp (key, PLUMA_SETTINGS_DRAWER_NBSP)) + return; + +#ifdef GTK_SOURCE_VERSION_3_24 + pluma_settings_space_drawer_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_SPACE_TYPE_NBSP); +#else + pluma_settings_draw_generic (settings, + g_settings_get_enum (settings, key), + GTK_SOURCE_DRAW_SPACES_NBSP); +#endif +} + +static void +pluma_settings_class_init (PlumaSettingsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = pluma_settings_finalize; + object_class->dispose = pluma_settings_dispose; +} + +static void +pluma_settings_init (PlumaSettings *self) +{ + self->priv = pluma_settings_get_instance_private (self); + + self->priv->old_scheme = NULL; + + self->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + + /* Load settings */ + self->priv->lockdown_settings = g_settings_new ("org.mate.lockdown"); + + g_signal_connect (self->priv->lockdown_settings, + "changed", + G_CALLBACK (on_lockdown_changed), + NULL); + + self->priv->interface_settings = g_settings_new ("org.mate.interface"); + + g_signal_connect (self->priv->interface_settings, + "changed::monospace-font-name", + G_CALLBACK (on_system_font_changed), + self); + + /* editor changes */ + g_signal_connect (self->priv->editor_settings, + "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::editor-font", + G_CALLBACK (on_editor_font_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::color-scheme", + G_CALLBACK (on_scheme_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::auto-save", + G_CALLBACK (on_auto_save_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::auto-save-interval", + G_CALLBACK (on_auto_save_interval_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::undo-actions-limit", + G_CALLBACK (on_undo_actions_limit_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::wrap-mode", + G_CALLBACK (on_wrap_mode_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::tabs-size", + G_CALLBACK (on_tabs_size_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::insert-spaces", + G_CALLBACK (on_insert_spaces_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::auto-indent", + G_CALLBACK (on_auto_indent_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::display-line-numbers", + G_CALLBACK (on_display_line_numbers_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::highlight-current-line", + G_CALLBACK (on_hl_current_line_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::bracket-matching", + G_CALLBACK (on_bracket_matching_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::display-right-margin", + G_CALLBACK (on_display_right_margin_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::right-margin-position", + G_CALLBACK (on_right_margin_position_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::smart-home-end", + G_CALLBACK (on_smart_home_end_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::syntax-highlighting", + G_CALLBACK (on_syntax_highlighting_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::search-highlighting", + G_CALLBACK (on_search_highlighting_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::max-recents", + G_CALLBACK (on_max_recents_changed), + self); + g_signal_connect (self->priv->editor_settings, + "changed::enable-space-drawer-space", + G_CALLBACK (on_draw_spaces_changed), + NULL); + g_signal_connect (self->priv->editor_settings, + "changed::enable-space-drawer-tab", + G_CALLBACK (on_draw_tabs_changed), + NULL); + g_signal_connect (self->priv->editor_settings, + "changed::enable-space-drawer-newline", + G_CALLBACK (on_draw_newlines_changed), + NULL); + g_signal_connect (self->priv->editor_settings, + "changed::enable-space-drawer-nbsp", + G_CALLBACK (on_draw_nbsp_changed), + NULL); +} + +PlumaSettings * +_pluma_settings_get_singleton (void) +{ + if (singleton == NULL) + { + singleton = g_object_new (PLUMA_TYPE_SETTINGS, NULL); + } + + return singleton; +} + +void +pluma_settings_unref_singleton (void) +{ + if (singleton != NULL) + { + g_object_unref (singleton); + } + + /* singleton is not set to NULL here, it is set to NULL in + * pluma_settings_finalize() (i.e. when we are sure that the ref count + * reaches 0). + */ +} + +PlumaLockdownMask +pluma_settings_get_lockdown (PlumaSettings *self) +{ + guint lockdown = 0; + gboolean command_line, printing, print_setup, save_to_disk; + + command_line = g_settings_get_boolean (self->priv->lockdown_settings, + PLUMA_SETTINGS_LOCKDOWN_COMMAND_LINE); + printing = g_settings_get_boolean (self->priv->lockdown_settings, + PLUMA_SETTINGS_LOCKDOWN_PRINTING); + print_setup = g_settings_get_boolean (self->priv->lockdown_settings, + PLUMA_SETTINGS_LOCKDOWN_PRINT_SETUP); + save_to_disk = g_settings_get_boolean (self->priv->lockdown_settings, + PLUMA_SETTINGS_LOCKDOWN_SAVE_TO_DISK); + + if (command_line) + lockdown |= PLUMA_LOCKDOWN_COMMAND_LINE; + + if (printing) + lockdown |= PLUMA_LOCKDOWN_PRINTING; + + if (print_setup) + lockdown |= PLUMA_LOCKDOWN_PRINT_SETUP; + + if (save_to_disk) + lockdown |= PLUMA_LOCKDOWN_SAVE_TO_DISK; + + return lockdown; +} + +gchar * +pluma_settings_get_system_font (PlumaSettings *self) +{ + gchar *system_font; + + g_return_val_if_fail (PLUMA_IS_SETTINGS (self), NULL); + + system_font = g_settings_get_string (self->priv->interface_settings, + "monospace-font-name"); + + return system_font; +} + +PlumaToolbarSetting +pluma_settings_get_toolbar_style (PlumaSettings *self) +{ + PlumaToolbarSetting res; + gchar *str; + + g_return_val_if_fail (PLUMA_IS_SETTINGS (self), 0); + + str = g_settings_get_string (self->priv->editor_settings, + "toolbar-buttons-style"); + + g_return_val_if_fail (str != NULL, 0); + + if (strcmp (str, "PLUMA_TOOLBAR_ICONS") == 0) + res = PLUMA_TOOLBAR_ICONS; + else + { + if (strcmp (str, "PLUMA_TOOLBAR_ICONS_AND_TEXT") == 0) + res = PLUMA_TOOLBAR_ICONS_AND_TEXT; + else + { + if (strcmp (str, "PLUMA_TOOLBAR_ICONS_BOTH_HORIZ") == 0) + res = PLUMA_TOOLBAR_ICONS_BOTH_HORIZ; + else + res = PLUMA_TOOLBAR_SYSTEM; + } + } + + g_free (str); + + return res; +} + +GtkSourceSmartHomeEndType +pluma_settings_get_smart_home_end (PlumaSettings *self) +{ + GtkSourceSmartHomeEndType res; + gchar *str; + + g_return_val_if_fail (PLUMA_IS_SETTINGS (self), GTK_SOURCE_SMART_HOME_END_AFTER); + + str = g_settings_get_string (self->priv->editor_settings, "smart-home-end"); + + g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); + + if (strcmp (str, "DISABLED") == 0) + res = GTK_SOURCE_SMART_HOME_END_DISABLED; + else if (strcmp (str, "BEFORE") == 0) + res = GTK_SOURCE_SMART_HOME_END_BEFORE; + else if (strcmp (str, "ALWAYS") == 0) + res = GTK_SOURCE_SMART_HOME_END_ALWAYS; + else + res = GTK_SOURCE_SMART_HOME_END_AFTER; + + g_free (str); + + return res; +} + +static gchar * +get_wrap_str (guint mode) +{ + gchar *str; + + switch (mode) + { + case GTK_WRAP_NONE: + str = g_strdup ("GTK_WRAP_NONE"); + break; + + case GTK_WRAP_CHAR: + str = g_strdup ("GTK_WRAP_CHAR"); + break; + + default: /* GTK_WRAP_WORD */ + str = g_strdup ("GTK_WRAP_WORD"); + } + + return str; +} + +GtkWrapMode +pluma_settings_get_wrap_mode (GSettings *settings, + const gchar *key) +{ + GtkWrapMode res; + gchar *str; + + g_return_val_if_fail (G_IS_SETTINGS (settings), GTK_WRAP_WORD); + g_return_val_if_fail (key != NULL, GTK_WRAP_WORD); + + str = g_settings_get_string (settings, key); + + g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); + + if (strcmp (str, "GTK_WRAP_NONE") == 0) + res = GTK_WRAP_NONE; + else + { + if (strcmp (str, "GTK_WRAP_CHAR") == 0) + res = GTK_WRAP_CHAR; + else + res = GTK_WRAP_WORD; + } + + g_free (str); + + return res; +} + +void +pluma_settings_set_wrap_mode (GSettings *settings, + const gchar *key, + GtkWrapMode mode) +{ + gchar *str; + + g_return_if_fail (G_IS_SETTINGS (settings)); + g_return_if_fail (key != NULL); + + str = get_wrap_str (mode); + + g_settings_set_string (settings, key, str); +} + +/* GSettings/GSList utility functions from mate-panel */ + +GSList* +pluma_settings_get_list (GSettings *settings, const gchar *key) +{ + gchar **array; + GSList *list = NULL; + gint i; + array = g_settings_get_strv (settings, key); + if (array != NULL) { + for (i = 0; array[i]; i++) { + list = g_slist_append (list, g_strdup (array[i])); + } + } + g_strfreev (array); + return list; +} + +void +pluma_settings_set_list (GSettings *settings, const gchar *key, GSList *list) +{ + GArray *array; + GSList *l; + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); + for (l = list; l; l = l->next) { + array = g_array_append_val (array, l->data); + } + g_settings_set_strv (settings, key, (const gchar **) array->data); + g_array_free (array, TRUE); +} + +GSList * +pluma_settings_get_writable_vfs_schemes (GSettings *settings) +{ + GSList *strings; + + pluma_debug (DEBUG_PREFS); + + strings = pluma_settings_get_list (settings, PLUMA_SETTINGS_WRITABLE_VFS_SCHEMES); + + /* The 'file' scheme is writable by default. */ + strings = g_slist_prepend (strings, g_strdup ("file")); + + pluma_debug_message (DEBUG_PREFS, "Done"); + + return strings; +} + diff --git a/pluma/pluma-settings.h b/pluma/pluma-settings.h new file mode 100644 index 00000000..1a15f4b3 --- /dev/null +++ b/pluma/pluma-settings.h @@ -0,0 +1,159 @@ +/* + * pluma-settings.h + * This file is part of pluma + * + * Copyright (C) 2009 - Ignacio Casal Quinteiro + * 2002 - Paolo Maggi + * 2020 - MATE Desktop Team + * + * pluma is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * pluma is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with pluma; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __PLUMA_SETTINGS_H__ +#define __PLUMA_SETTINGS_H__ + +#include <glib-object.h> +#include <glib.h> +#include "pluma-app.h" + +G_BEGIN_DECLS + +#define PLUMA_TYPE_SETTINGS (pluma_settings_get_type ()) +#define PLUMA_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLUMA_TYPE_SETTINGS, PlumaSettings)) +#define PLUMA_SETTINGS_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLUMA_TYPE_SETTINGS, PlumaSettings const)) +#define PLUMA_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLUMA_TYPE_SETTINGS, PlumaSettingsClass)) +#define PLUMA_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLUMA_TYPE_SETTINGS)) +#define PLUMA_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLUMA_TYPE_SETTINGS)) +#define PLUMA_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLUMA_TYPE_SETTINGS, PlumaSettingsClass)) + +typedef struct _PlumaSettings PlumaSettings; +typedef struct _PlumaSettingsClass PlumaSettingsClass; +typedef struct _PlumaSettingsPrivate PlumaSettingsPrivate; + +struct _PlumaSettings +{ + GObject parent; + + PlumaSettingsPrivate *priv; +}; + +struct _PlumaSettingsClass +{ + GObjectClass parent_class; +}; + +typedef enum { + PLUMA_TOOLBAR_SYSTEM = 0, + PLUMA_TOOLBAR_ICONS, + PLUMA_TOOLBAR_ICONS_AND_TEXT, + PLUMA_TOOLBAR_ICONS_BOTH_HORIZ +} PlumaToolbarSetting; + +GType pluma_settings_get_type (void) G_GNUC_CONST; + +G_GNUC_INTERNAL +PlumaSettings * _pluma_settings_get_singleton (void); + +void pluma_settings_unref_singleton (void); + +PlumaLockdownMask pluma_settings_get_lockdown (PlumaSettings *self); + +gchar *pluma_settings_get_system_font (PlumaSettings *self); + +GtkSourceSmartHomeEndType pluma_settings_get_smart_home_end (PlumaSettings *self); + +PlumaToolbarSetting pluma_settings_get_toolbar_style (PlumaSettings *self); + +/* Utility functions */ +GSList *pluma_settings_get_list (GSettings *settings, + const gchar *key); + +void pluma_settings_set_list (GSettings *settings, + const gchar *key, + GSList *list); + +GtkWrapMode pluma_settings_get_wrap_mode (GSettings *settings, + const gchar *key); + +void pluma_settings_set_wrap_mode (GSettings *settings, + const gchar *key, + GtkWrapMode mode); + +GSList * pluma_settings_get_writable_vfs_schemes (GSettings *settings); + +#define PLUMA_SCHEMA_ID "org.mate.pluma" + +/* key constants */ +#define PLUMA_SETTINGS_USE_DEFAULT_FONT "use-default-font" +#define PLUMA_SETTINGS_EDITOR_FONT "editor-font" +#define PLUMA_SETTINGS_COLOR_SCHEME "color-scheme" +#define PLUMA_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy" +#define PLUMA_SETTINGS_AUTO_SAVE "auto-save" +#define PLUMA_SETTINGS_AUTO_SAVE_INTERVAL "auto-save-interval" +#define PLUMA_SETTINGS_MAX_UNDO_ACTIONS "max-undo-actions" +#define PLUMA_SETTINGS_WRAP_MODE "wrap-mode" +#define PLUMA_SETTINGS_TABS_SIZE "tabs-size" +#define PLUMA_SETTINGS_INSERT_SPACES "insert-spaces" +#define PLUMA_SETTINGS_AUTO_INDENT "auto-indent" +#define PLUMA_SETTINGS_DISPLAY_LINE_NUMBERS "display-line-numbers" +#define PLUMA_SETTINGS_HIGHLIGHT_CURRENT_LINE "highlight-current-line" +#define PLUMA_SETTINGS_BRACKET_MATCHING "bracket-matching" +#define PLUMA_SETTINGS_DISPLAY_RIGHT_MARGIN "display-right-margin" +#define PLUMA_SETTINGS_RIGHT_MARGIN_POSITION "right-margin-position" +#define PLUMA_SETTINGS_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" +#define PLUMA_SETTINGS_RESTORE_CURSOR_POSITION "restore-cursor-position" +#define PLUMA_SETTINGS_SYNTAX_HIGHLIGHTING "syntax-highlighting" +#define PLUMA_SETTINGS_SEARCH_HIGHLIGHTING "search-highlighting" +#define PLUMA_SETTINGS_TOOLBAR_VISIBLE "toolbar-visible" +#define PLUMA_SETTINGS_STATUSBAR_VISIBLE "statusbar-visible" +#define PLUMA_SETTINGS_SIDE_PANE_VISIBLE "side-pane-visible" +#define PLUMA_SETTINGS_BOTTOM_PANE_VISIBLE "bottom-panel-visible" +#define PLUMA_SETTINGS_MAX_RECENTS "max-recents" +#define PLUMA_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING "print-syntax-highlighting" +#define PLUMA_SETTINGS_PRINT_HEADER "print-header" +#define PLUMA_SETTINGS_PRINT_WRAP_MODE "print-wrap-mode" +#define PLUMA_SETTINGS_PRINT_LINE_NUMBERS "print-line-numbers" +#define PLUMA_SETTINGS_PRINT_FONT_BODY_PANGO "print-font-body-pango" +#define PLUMA_SETTINGS_PRINT_FONT_HEADER_PANGO "print-font-header-pango" +#define PLUMA_SETTINGS_PRINT_FONT_NUMBERS_PANGO "print-font-numbers-pango" +#define PLUMA_SETTINGS_ENCODING_AUTO_DETECTED "auto-detected-encodings" +#define PLUMA_SETTINGS_ENCODING_SHOWN_IN_MENU "shown-in-menu-encodings" +#define PLUMA_SETTINGS_ACTIVE_PLUGINS "active-plugins" +#define PLUMA_SETTINGS_SHOW_SINGLE_TAB "show-single-tab" +#define PLUMA_SETTINGS_SHOW_TABS_WITH_SIDE_PANE "show-tabs-with-side-pane" +#define PLUMA_SETTINGS_CTRL_TABS_SWITCH_TABS "ctrl-tab-switch-tabs" +#define PLUMA_SETTINGS_SHOW_SAVE_CONFIRMATION "show-save-confirmation" +#define PLUMA_SETTINGS_DRAWER_SPACE "enable-space-drawer-space" +#define PLUMA_SETTINGS_DRAWER_TAB "enable-space-drawer-tab" +#define PLUMA_SETTINGS_DRAWER_NEWLINE "enable-space-drawer-newline" +#define PLUMA_SETTINGS_DRAWER_NBSP "enable-space-drawer-nbsp" + +/* White list of writable mate-vfs methods */ +#define PLUMA_SETTINGS_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" +#define PLUMA_SETTINGS_SMART_HOME_END "smart-home-end" + +/* window state keys */ +#define PLUMA_SETTINGS_WINDOW_STATE "state" +#define PLUMA_SETTINGS_WINDOW_SIZE "size" +#define PLUMA_SETTINGS_SIDE_PANEL_SIZE "side-panel-size" +#define PLUMA_SETTINGS_SIDE_PANEL_ACTIVE_PAGE "side-panel-active-page" +#define PLUMA_SETTINGS_BOTTOM_PANEL_SIZE "bottom-panel-size" +#define PLUMA_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE "bottom-panel-active-page" +#define PLUMA_SETTINGS_ACTIVE_FILE_FILTER "filter-id" + +G_END_DECLS + +#endif /* __PLUMA_SETTINGS_H__ */ diff --git a/pluma/pluma-style-scheme-manager.c b/pluma/pluma-style-scheme-manager.c index f002b88b..7484881d 100644 --- a/pluma/pluma-style-scheme-manager.c +++ b/pluma/pluma-style-scheme-manager.c @@ -41,7 +41,6 @@ #include <gtk/gtk.h> #include "pluma-style-scheme-manager.h" -#include "pluma-prefs-manager.h" #include "pluma-dirs.h" static GtkSourceStyleSchemeManager *style_scheme_manager = NULL; diff --git a/pluma/pluma-tab.c b/pluma/pluma-tab.c index 505b64b7..9b1f6080 100644 --- a/pluma/pluma-tab.c +++ b/pluma/pluma-tab.c @@ -42,14 +42,14 @@ #include "pluma-print-preview.h" #include "pluma-progress-message-area.h" #include "pluma-debug.h" -#include "pluma-prefs-manager-app.h" -#include "pluma-prefs-manager-private.h" #include "pluma-enum-types.h" +#include "pluma-settings.h" #define PLUMA_TAB_KEY "PLUMA_TAB_KEY" struct _PlumaTabPrivate { + GSettings *editor_settings; PlumaTabState state; GtkWidget *view; @@ -240,6 +240,10 @@ pluma_tab_finalize (GObject *object) tab->priv->idle_scroll = 0; } + /* settings must be cleared in finalize and not in dispose to prevent + a warning when trying to close pluma while print-preview is active */ + g_clear_object (&tab->priv->editor_settings); + G_OBJECT_CLASS (pluma_tab_parent_class)->finalize (object); } @@ -364,6 +368,10 @@ set_view_properties_according_to_state (PlumaTab *tab, PlumaTabState state) { gboolean val; + gboolean hl_current_line; + + hl_current_line = g_settings_get_boolean (tab->priv->editor_settings, + PLUMA_SETTINGS_HIGHLIGHT_CURRENT_LINE); val = ((state == PLUMA_TAB_STATE_NORMAL) && (tab->priv->print_preview == NULL) && @@ -376,7 +384,7 @@ set_view_properties_according_to_state (PlumaTab *tab, val = ((state != PLUMA_TAB_STATE_LOADING) && (state != PLUMA_TAB_STATE_CLOSING) && - (pluma_prefs_manager_get_highlight_current_line ())); + hl_current_line); gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); } @@ -1484,9 +1492,13 @@ pluma_tab_init (PlumaTab *tab) GtkWidget *sw; PlumaDocument *doc; PlumaLockdownMask lockdown; + gboolean auto_save; + gint auto_save_interval; tab->priv = pluma_tab_get_instance_private (tab); + tab->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + tab->priv->state = PLUMA_TAB_STATE_NORMAL; tab->priv->not_editable = FALSE; @@ -1507,14 +1519,19 @@ pluma_tab_init (PlumaTab *tab) GTK_POLICY_AUTOMATIC); /* Manage auto save data */ + auto_save = g_settings_get_boolean (tab->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE); + auto_save_interval = g_settings_get_uint (tab->priv->editor_settings, PLUMA_SETTINGS_AUTO_SAVE_INTERVAL); + lockdown = pluma_app_get_lockdown (pluma_app_get_default ()); - tab->priv->auto_save = pluma_prefs_manager_get_auto_save () && + tab->priv->auto_save = auto_save && !(lockdown & PLUMA_LOCKDOWN_SAVE_TO_DISK); tab->priv->auto_save = (tab->priv->auto_save != FALSE); - tab->priv->auto_save_interval = pluma_prefs_manager_get_auto_save_interval (); + tab->priv->auto_save_interval = auto_save_interval; + /*FIXME if (tab->priv->auto_save_interval <= 0) - tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;*/ /* Create the view */ doc = pluma_document_new (); @@ -2617,7 +2634,7 @@ _pluma_tab_can_close (PlumaTab *tab) (ts == PLUMA_TAB_STATE_REVERTING) || (ts == PLUMA_TAB_STATE_REVERTING_ERROR) || /* CHECK: I'm not sure this is the right behavior for REVERTING ERROR */ (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) || - (!g_settings_get_boolean (pluma_prefs_manager->settings, "show-save-confirmation"))) + (!g_settings_get_boolean (tab->priv->editor_settings, PLUMA_SETTINGS_SHOW_SAVE_CONFIRMATION))) return TRUE; /* Do not close tab with saving errors */ diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index 9a8c5114..445f15af 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -47,8 +47,8 @@ #include "pluma-utils.h" +#include "pluma-settings.h" #include "pluma-document.h" -#include "pluma-prefs-manager.h" #include "pluma-debug.h" /* For the workspace/viewport stuff */ @@ -79,11 +79,14 @@ pluma_utils_uri_has_file_scheme (const gchar *uri) gboolean pluma_utils_uri_has_writable_scheme (const gchar *uri) { + /* FIXME: Avoid making a new settings variable here. */ + GSettings *settings; GFile *gfile; gchar *scheme; GSList *writable_schemes; gboolean res; + settings = g_settings_new (PLUMA_SCHEMA_ID); gfile = g_file_new_for_uri (uri); scheme = g_file_get_uri_scheme (gfile); @@ -91,7 +94,7 @@ pluma_utils_uri_has_writable_scheme (const gchar *uri) g_object_unref (gfile); - writable_schemes = pluma_prefs_manager_get_writable_vfs_schemes (); + writable_schemes = pluma_settings_get_writable_vfs_schemes (settings); /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */ res = (g_slist_find_custom (writable_schemes, @@ -101,6 +104,7 @@ pluma_utils_uri_has_writable_scheme (const gchar *uri) g_slist_free_full (writable_schemes, g_free); g_free (scheme); + g_object_unref (settings); return res; } @@ -1694,3 +1698,4 @@ pluma_image_menu_item_new_from_pixbuf (GdkPixbuf *icon_pixbuf, return menuitem; } + diff --git a/pluma/pluma-utils.h b/pluma/pluma-utils.h index c62c223b..7c9881cf 100644 --- a/pluma/pluma-utils.h +++ b/pluma/pluma-utils.h @@ -37,6 +37,7 @@ #include <gtk/gtk.h> #include <atk/atk.h> #include <pluma/pluma-encodings.h> +#include <gtksourceview/gtksource.h> G_BEGIN_DECLS @@ -163,4 +164,3 @@ pluma_image_menu_item_new_from_pixbuf (GdkPixbuf *icon_pixbuf, G_END_DECLS #endif /* __PLUMA_UTILS_H__ */ - diff --git a/pluma/pluma-view.c b/pluma/pluma-view.c index 6dce6273..24bc0007 100644 --- a/pluma/pluma-view.c +++ b/pluma/pluma-view.c @@ -44,11 +44,9 @@ #include "pluma-view.h" #include "pluma-debug.h" -#include "pluma-prefs-manager.h" -#include "pluma-prefs-manager-app.h" -#include "pluma-prefs-manager-private.h" #include "pluma-marshal.h" #include "pluma-utils.h" +#include "pluma-settings.h" #define PLUMA_VIEW_SCROLL_MARGIN 0.02 #define PLUMA_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */ @@ -71,6 +69,9 @@ enum struct _PlumaViewPrivate { + GSettings *editor_settings; + GSettings *interface_settings; + SearchMode search_mode; GtkTextIter start_search_iter; @@ -376,15 +377,14 @@ pluma_set_source_space_drawer_by_level (GtkSourceView *view, GtkSourceSpaceTypeFlags type) { GtkSourceSpaceLocationFlags locs[] = {GTK_SOURCE_SPACE_LOCATION_LEADING, - GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT, - GTK_SOURCE_SPACE_LOCATION_TRAILING}; + GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT, + GTK_SOURCE_SPACE_LOCATION_TRAILING}; /* this array links the level to the location */ - GtkSourceSpaceLocationFlags levels[] = { - 0, - GTK_SOURCE_SPACE_LOCATION_TRAILING, - GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT | - GTK_SOURCE_SPACE_LOCATION_TRAILING | - GTK_SOURCE_SPACE_LOCATION_LEADING + GtkSourceSpaceLocationFlags levels[] = {0, + GTK_SOURCE_SPACE_LOCATION_TRAILING, + GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT | + GTK_SOURCE_SPACE_LOCATION_TRAILING | + GTK_SOURCE_SPACE_LOCATION_LEADING }; gint i; @@ -409,42 +409,42 @@ pluma_set_source_space_drawer_by_level (GtkSourceView *view, #ifdef GTK_SOURCE_VERSION_3_24 static void -pluma_set_source_space_drawer (GtkSourceView *view) +pluma_set_source_space_drawer (GSettings *settings, GtkSourceView *view) { pluma_set_source_space_drawer_by_level (view, - pluma_prefs_manager_get_draw_spaces (), - GTK_SOURCE_SPACE_TYPE_SPACE); + g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_SPACE), + GTK_SOURCE_SPACE_TYPE_SPACE); pluma_set_source_space_drawer_by_level (view, - pluma_prefs_manager_get_draw_tabs (), - GTK_SOURCE_SPACE_TYPE_TAB); + g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_TAB), + GTK_SOURCE_SPACE_TYPE_TAB); pluma_set_source_space_drawer_by_level (view, - pluma_prefs_manager_get_draw_newlines () ? 2 : 0, - GTK_SOURCE_SPACE_TYPE_NEWLINE); + g_settings_get_boolean (settings, PLUMA_SETTINGS_DRAWER_NEWLINE) ? 2 : 0, + GTK_SOURCE_SPACE_TYPE_NEWLINE); pluma_set_source_space_drawer_by_level (view, - pluma_prefs_manager_get_draw_nbsp (), - GTK_SOURCE_SPACE_TYPE_NBSP); + g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_NBSP), + GTK_SOURCE_SPACE_TYPE_NBSP); gtk_source_space_drawer_set_enable_matrix (gtk_source_view_get_space_drawer (view), - TRUE); + TRUE); } #else static void -pluma_set_source_space_drawer (GtkSourceView *view) +pluma_set_source_space_drawer (GSettings *settings, GtkSourceView *view) { GtkSourceDrawSpacesFlags flags = 0; - if (pluma_prefs_manager_get_draw_spaces () > 0) + if (g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_SPACE) > 0) flags |= GTK_SOURCE_DRAW_SPACES_SPACE; - if (pluma_prefs_manager_get_draw_tabs () > 0) + if (g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_TAB) > 0) flags |= GTK_SOURCE_DRAW_SPACES_TAB; - if (pluma_prefs_manager_get_draw_newlines ()) + if (g_settings_get_boolean (settings, PLUMA_SETTINGS_DRAWER_NEWLINE)) flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE; - if (pluma_prefs_manager_get_draw_nbsp () > 0) + if (g_settings_get_enum (settings, PLUMA_SETTINGS_DRAWER_NBSP) > 0) flags |= GTK_SOURCE_DRAW_SPACES_NBSP; flags |= GTK_SOURCE_DRAW_SPACES_TRAILING | - GTK_SOURCE_DRAW_SPACES_TEXT | - GTK_SOURCE_DRAW_SPACES_LEADING; + GTK_SOURCE_DRAW_SPACES_TEXT | + GTK_SOURCE_DRAW_SPACES_LEADING; gtk_source_view_set_draw_spaces (view, flags); } @@ -453,21 +453,42 @@ pluma_set_source_space_drawer (GtkSourceView *view) static void pluma_view_init (PlumaView *view) { + PlumaSettings *settings; GtkTargetList *tl; + gboolean use_default_font; + gboolean display_line_numbers; + gboolean auto_indent; + gboolean insert_spaces; + gboolean display_right_margin; + gboolean hl_current_line; + guint tabs_size; + guint right_margin_position; + GtkWrapMode wrap_mode; + GtkSourceSmartHomeEndType smart_home_end; pluma_debug (DEBUG_VIEW); view->priv = pluma_view_get_instance_private (view); + settings = _pluma_settings_get_singleton (); + view->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); + view->priv->interface_settings = g_settings_new ("org.mate.interface"); + + /* Get setting values */ + use_default_font = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_USE_DEFAULT_FONT); + /* * Set tab, fonts, wrap mode, colors, etc. according * to preferences */ - if (!pluma_prefs_manager_get_use_default_font ()) + if (!use_default_font) { gchar *editor_font; - editor_font = pluma_prefs_manager_get_editor_font (); + editor_font = g_settings_get_string (view->priv->editor_settings, + PLUMA_SETTINGS_EDITOR_FONT); + pluma_view_set_font (view, FALSE, editor_font); @@ -478,20 +499,39 @@ pluma_view_init (PlumaView *view) pluma_view_set_font (view, TRUE, NULL); } + display_line_numbers = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_DISPLAY_LINE_NUMBERS); + auto_indent = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_AUTO_INDENT); + tabs_size = g_settings_get_uint (view->priv->editor_settings, PLUMA_SETTINGS_TABS_SIZE); + insert_spaces = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_INSERT_SPACES); + display_right_margin = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_DISPLAY_RIGHT_MARGIN); + right_margin_position = g_settings_get_uint (view->priv->editor_settings, + PLUMA_SETTINGS_RIGHT_MARGIN_POSITION); + hl_current_line = g_settings_get_boolean (view->priv->editor_settings, + PLUMA_SETTINGS_HIGHLIGHT_CURRENT_LINE); + + wrap_mode = pluma_settings_get_wrap_mode (view->priv->editor_settings, + PLUMA_SETTINGS_WRAP_MODE); + + smart_home_end = pluma_settings_get_smart_home_end (settings); + g_object_set (G_OBJECT (view), - "wrap_mode", pluma_prefs_manager_get_wrap_mode (), - "show_line_numbers", pluma_prefs_manager_get_display_line_numbers (), - "auto_indent", pluma_prefs_manager_get_auto_indent (), - "tab_width", pluma_prefs_manager_get_tabs_size (), - "insert_spaces_instead_of_tabs", pluma_prefs_manager_get_insert_spaces (), - "show_right_margin", pluma_prefs_manager_get_display_right_margin (), - "right_margin_position", pluma_prefs_manager_get_right_margin_position (), - "highlight_current_line", pluma_prefs_manager_get_highlight_current_line (), - "smart_home_end", pluma_prefs_manager_get_smart_home_end (), + "wrap_mode", wrap_mode, + "show_line_numbers", display_line_numbers, + "auto_indent", auto_indent, + "tab_width", tabs_size, + "insert_spaces_instead_of_tabs", insert_spaces, + "show_right_margin", display_right_margin, + "right_margin_position", right_margin_position, + "highlight_current_line", hl_current_line, + "smart_home_end", smart_home_end, "indent_on_tab", TRUE, NULL); - pluma_set_source_space_drawer (GTK_SOURCE_VIEW (view)); + pluma_set_source_space_drawer (view->priv->editor_settings, GTK_SOURCE_VIEW (view)); view->priv->typeselect_flush_timeout = 0; view->priv->wrap_around = TRUE; @@ -529,6 +569,9 @@ pluma_view_dispose (GObject *object) } } + g_clear_object (&view->priv->editor_settings); + g_clear_object (&view->priv->interface_settings); + /* Disconnect notify buffer because the destroy of the textview will set the buffer to NULL, and we call get_buffer in the notify which would reinstate a GtkTextBuffer which we don't want */ @@ -759,12 +802,12 @@ pluma_view_scroll_to_cursor (PlumaView *view) 0.0); } -static PangoFontDescription* get_system_font (void) +static PangoFontDescription* get_system_font (GSettings *settings) { PangoFontDescription *desc = NULL; char *name; - name = g_settings_get_string (pluma_prefs_manager->interface_settings, "font-name"); + name = g_settings_get_string (settings, "font-name"); if (name) { @@ -781,18 +824,18 @@ system_font_changed_cb (GSettings *settings, gpointer user_data) { PangoFontDescription *sys_font_desc = NULL; - sys_font_desc = get_system_font (); + sys_font_desc = get_system_font (settings); if (sys_font_desc) { - pluma_override_font ("label", NULL, sys_font_desc); + pluma_override_font (NULL, "label", sys_font_desc); pango_font_description_free (sys_font_desc); } } void -pluma_override_font (const gchar *item, - GtkWidget *widget, - PangoFontDescription *font) +pluma_override_font (PlumaView *view, + const gchar *item, + PangoFontDescription *font) { static GtkCssProvider *provider = NULL; /*We need to keep this as long as Pluma is running*/ gchar *prov_str; @@ -821,11 +864,11 @@ pluma_override_font (const gchar *item, { provider = gtk_css_provider_new (); - g_signal_connect (pluma_prefs_manager->interface_settings, + g_signal_connect (view->priv->interface_settings, "changed::" "font-name", G_CALLBACK (system_font_changed_cb), NULL); - gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget), + gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET(view)), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -880,9 +923,11 @@ pluma_view_set_font (PlumaView *view, if (def) { + PlumaSettings *settings; gchar *font; - font = pluma_prefs_manager_get_system_font (); + settings = _pluma_settings_get_singleton (); + font = pluma_settings_get_system_font (settings); font_desc = pango_font_description_from_string (font); g_free (font); } @@ -895,11 +940,11 @@ pluma_view_set_font (PlumaView *view, g_return_if_fail (font_desc != NULL); - pluma_override_font ("textview", GTK_WIDGET (view), font_desc); + pluma_override_font (view, "textview", font_desc); - sys_font_desc = get_system_font (); + sys_font_desc = get_system_font (view->priv->interface_settings); if (sys_font_desc) { - pluma_override_font ("label", GTK_WIDGET (view), sys_font_desc); + pluma_override_font (view, "label", sys_font_desc); pango_font_description_free (sys_font_desc); } @@ -2163,17 +2208,6 @@ pluma_view_drag_drop (GtkWidget *widget, return result; } -static void -show_line_numbers_toggled (GtkMenu *menu, - PlumaView *view) -{ - gboolean show; - - show = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu)); - - pluma_prefs_manager_set_display_line_numbers (show); -} - static GtkWidget * create_line_numbers_menu (GtkWidget *view) { @@ -2185,8 +2219,13 @@ create_line_numbers_menu (GtkWidget *view) item = gtk_check_menu_item_new_with_mnemonic (_("_Display line numbers")); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), gtk_source_view_get_show_line_numbers (GTK_SOURCE_VIEW (view))); - g_signal_connect (item, "toggled", - G_CALLBACK (show_line_numbers_toggled), view); + + g_settings_bind (PLUMA_VIEW (view)->priv->editor_settings, + "active", + item, + PLUMA_SETTINGS_DISPLAY_LINE_NUMBERS, + G_SETTINGS_BIND_SET); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show_all (menu); diff --git a/pluma/pluma-view.h b/pluma/pluma-view.h index 4caf2af2..c2f5e1df 100644 --- a/pluma/pluma-view.h +++ b/pluma/pluma-view.h @@ -99,8 +99,8 @@ void pluma_view_select_all (PlumaView *view); void pluma_view_scroll_to_cursor (PlumaView *view); -void pluma_override_font (const gchar *item, - GtkWidget *widget, +void pluma_override_font (PlumaView *view, + const gchar *item, PangoFontDescription *font); void pluma_view_set_font (PlumaView *view, diff --git a/pluma/pluma-window-private.h b/pluma/pluma-window-private.h index 3d983008..2179da9c 100644 --- a/pluma/pluma-window-private.h +++ b/pluma/pluma-window-private.h @@ -34,8 +34,8 @@ #include <libpeas/peas-extension-set.h> #include "pluma/pluma-window.h" -#include "pluma-prefs-manager.h" #include "pluma-message-bus.h" +#include "pluma-settings.h" G_BEGIN_DECLS @@ -43,6 +43,8 @@ G_BEGIN_DECLS struct _PlumaWindowPrivate { + GSettings *editor_settings; + GtkWidget *notebook; GtkWidget *side_panel; diff --git a/pluma/pluma-window.c b/pluma/pluma-window.c index ac78ff71..17da00e8 100644 --- a/pluma/pluma-window.c +++ b/pluma/pluma-window.c @@ -54,14 +54,13 @@ #include "pluma-commands.h" #include "pluma-debug.h" #include "pluma-language-manager.h" -#include "pluma-prefs-manager-app.h" -#include "pluma-prefs-manager-private.h" #include "pluma-panel.h" #include "pluma-documents-panel.h" #include "pluma-plugins-engine.h" #include "pluma-enum-types.h" #include "pluma-dirs.h" #include "pluma-status-combo-box.h" +#include "pluma-settings.h" #define LANGUAGE_NONE (const gchar *)"LangNone" #define PLUMA_UIFILE "pluma-ui.xml" @@ -69,6 +68,9 @@ #define LANGUAGE_DATA "PlumaWindowLanguageData" #define FULLSCREEN_ANIMATION_SPEED 4 +#define PLUMA_WINDOW_DEFAULT_WIDTH 650 +#define PLUMA_WINDOW_DEFAULT_HEIGHT 500 + /* Local variables */ static gboolean cansave = TRUE; @@ -128,32 +130,32 @@ save_panes_state (PlumaWindow *window) pluma_debug (DEBUG_WINDOW); - if (pluma_prefs_manager_window_size_can_set ()) - pluma_prefs_manager_set_window_size (window->priv->width, - window->priv->height); + g_settings_set (window->priv->editor_settings, PLUMA_SETTINGS_WINDOW_SIZE, + "(ii)", window->priv->width, window->priv->height); - if (pluma_prefs_manager_window_state_can_set ()) - pluma_prefs_manager_set_window_state (window->priv->window_state); + g_settings_set_int (window->priv->editor_settings, PLUMA_SETTINGS_WINDOW_STATE, + window->priv->window_state); - if ((window->priv->side_panel_size > 0) && - pluma_prefs_manager_side_panel_size_can_set ()) - pluma_prefs_manager_set_side_panel_size ( - window->priv->side_panel_size); + if (window->priv->side_panel_size > 0) + g_settings_set_int (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANEL_SIZE, + window->priv->side_panel_size); pane_page = _pluma_panel_get_active_item_id (PLUMA_PANEL (window->priv->side_panel)); - if (pane_page != 0 && - pluma_prefs_manager_side_panel_active_page_can_set ()) - pluma_prefs_manager_set_side_panel_active_page (pane_page); + if (pane_page != 0) + g_settings_set_int (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANEL_ACTIVE_PAGE, + pane_page); - if ((window->priv->bottom_panel_size > 0) && - pluma_prefs_manager_bottom_panel_size_can_set ()) - pluma_prefs_manager_set_bottom_panel_size ( - window->priv->bottom_panel_size); + if (window->priv->bottom_panel_size > 0) + g_settings_set_int (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANEL_SIZE, + window->priv->bottom_panel_size); pane_page = _pluma_panel_get_active_item_id (PLUMA_PANEL (window->priv->bottom_panel)); - if (pane_page != 0 && - pluma_prefs_manager_bottom_panel_active_page_can_set ()) - pluma_prefs_manager_set_bottom_panel_active_page (pane_page); + if (pane_page != 0) + g_settings_set_int (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE, pane_page); } static void @@ -236,6 +238,9 @@ pluma_window_dispose (GObject *object) window->priv->window_group = NULL; } + /* We must free the settings after saving the panels */ + g_clear_object (&window->priv->editor_settings); + /* Now that there have broken some reference loops, * force collection again. */ @@ -297,6 +302,8 @@ pluma_window_key_press_event (GtkWidget *widget, static gpointer grand_parent_class = NULL; GtkWindow *window = GTK_WINDOW (widget); gboolean handled = FALSE; + /* FIXME: avoid making a new gsettings variable here */ + GSettings *settings = g_settings_new (PLUMA_SCHEMA_ID); if (event->state & GDK_CONTROL_MASK) { @@ -304,7 +311,7 @@ pluma_window_key_press_event (GtkWidget *widget, gchar *tempsize; gint nsize; - font = g_settings_get_string (pluma_prefs_manager->settings, "editor-font"); + font = g_settings_get_string (settings, PLUMA_SETTINGS_EDITOR_FONT); tempsize = g_strdup (font); g_strreverse (tempsize); @@ -322,10 +329,10 @@ pluma_window_key_press_event (GtkWidget *widget, nsize = nsize + 1; sprintf (tempsize, "%d", nsize); - if (!g_settings_get_boolean (pluma_prefs_manager->settings, "use-default-font") && (nsize < 73)) + if (!g_settings_get_boolean (settings, PLUMA_SETTINGS_USE_DEFAULT_FONT) && (nsize < 73)) { gchar *tmp = g_strconcat (tempfont, tempsize, NULL); - g_settings_set_string (pluma_prefs_manager->settings, "editor-font", tmp); + g_settings_set_string (settings, PLUMA_SETTINGS_EDITOR_FONT, tmp); g_free (tmp); } } @@ -334,15 +341,15 @@ pluma_window_key_press_event (GtkWidget *widget, nsize = nsize - 1; sprintf (tempsize, "%d", nsize); - if (!g_settings_get_boolean (pluma_prefs_manager->settings, "use-default-font") && (nsize > 5)) + if (!g_settings_get_boolean (settings, PLUMA_SETTINGS_USE_DEFAULT_FONT) && (nsize > 5)) { gchar *tmp = g_strconcat (tempfont, tempsize, NULL); - g_settings_set_string (pluma_prefs_manager->settings, "editor-font", tmp); + g_settings_set_string (settings, PLUMA_SETTINGS_EDITOR_FONT, tmp); g_free (tmp); } } - if (g_settings_get_boolean (pluma_prefs_manager->settings, "ctrl-tab-switch-tabs")) + if (g_settings_get_boolean (settings, PLUMA_SETTINGS_CTRL_TABS_SWITCH_TABS)) { GtkNotebook *notebook = GTK_NOTEBOOK (_pluma_window_get_notebook (PLUMA_WINDOW (window))); @@ -371,6 +378,8 @@ pluma_window_key_press_event (GtkWidget *widget, g_free (tempsize); } + g_object_unref (settings); + if (grand_parent_class == NULL) grand_parent_class = g_type_class_peek_parent (pluma_window_parent_class); @@ -574,7 +583,8 @@ set_toolbar_style (PlumaWindow *window, GtkAction *action; if (origin == NULL) - visible = pluma_prefs_manager_get_toolbar_visible (); + visible = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_TOOLBAR_VISIBLE); else visible = gtk_widget_get_visible (origin->priv->toolbar); @@ -592,9 +602,16 @@ set_toolbar_style (PlumaWindow *window, /* Set style */ if (origin == NULL) - style = pluma_prefs_manager_get_toolbar_buttons_style (); + { + PlumaSettings *settings; + + settings = _pluma_settings_get_singleton (); + style = pluma_settings_get_toolbar_style (settings); + } else + { style = origin->priv->toolbar_style; + } window->priv->toolbar_style = style; @@ -730,11 +747,15 @@ set_sensitivity_according_to_tab (PlumaWindow *window, PlumaTabState state; GtkClipboard *clipboard; PlumaLockdownMask lockdown; + gboolean enable_syntax_highlighting; g_return_if_fail (PLUMA_TAB (tab)); pluma_debug (DEBUG_WINDOW); + enable_syntax_highlighting = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_SYNTAX_HIGHLIGHTING); + lockdown = pluma_app_get_lockdown (pluma_app_get_default ()); state = pluma_tab_get_state (tab); @@ -896,7 +917,7 @@ set_sensitivity_according_to_tab (PlumaWindow *window, "ViewHighlightMode"); gtk_action_set_sensitive (action, (state != PLUMA_TAB_STATE_CLOSING) && - pluma_prefs_manager_get_enable_syntax_highlighting ()); + enable_syntax_highlighting); update_next_prev_doc_sensitivity (window, tab); @@ -1263,14 +1284,14 @@ update_recent_files_menu (PlumaWindow *window) { PlumaWindowPrivate *p = window->priv; GtkRecentManager *recent_manager; - gint max_recents; + guint max_recents; GList *actions, *l, *items; GList *filtered_items = NULL; gint i; pluma_debug (DEBUG_WINDOW); - max_recents = pluma_prefs_manager_get_max_recents (); + max_recents = g_settings_get_uint (window->priv->editor_settings, PLUMA_SETTINGS_MAX_RECENTS); g_return_if_fail (p->recents_action_group != NULL); @@ -1404,8 +1425,8 @@ toolbar_visibility_changed (GtkWidget *toolbar, visible = gtk_widget_get_visible (toolbar); - if (pluma_prefs_manager_toolbar_visible_can_set ()) - pluma_prefs_manager_set_toolbar_visible (visible); + g_settings_set_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_TOOLBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewToolbar"); @@ -1423,9 +1444,12 @@ setup_toolbar_open_button (PlumaWindow *window, GtkWidget *toolbar_recent_menu; GtkToolItem *open_button; GtkAction *action; + guint max_recents; recent_manager = gtk_recent_manager_get_default (); + max_recents = g_settings_get_uint (window->priv->editor_settings, PLUMA_SETTINGS_MAX_RECENTS); + /* recent files menu tool button */ toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (recent_manager); @@ -1434,7 +1458,7 @@ setup_toolbar_open_button (PlumaWindow *window, gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu), GTK_RECENT_SORT_MRU); gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu), - pluma_prefs_manager_get_max_recents ()); + max_recents); filter = gtk_recent_filter_new (); gtk_recent_filter_add_group (filter, "pluma"); @@ -1792,11 +1816,11 @@ set_statusbar_style (PlumaWindow *window, PlumaWindow *origin) { GtkAction *action; - gboolean visible; if (origin == NULL) - visible = pluma_prefs_manager_get_statusbar_visible (); + visible = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_STATUSBAR_VISIBLE); else visible = gtk_widget_get_visible (origin->priv->statusbar); @@ -1823,8 +1847,8 @@ statusbar_visibility_changed (GtkWidget *statusbar, visible = gtk_widget_get_visible (statusbar); - if (pluma_prefs_manager_statusbar_visible_can_set ()) - pluma_prefs_manager_set_statusbar_visible (visible); + g_settings_set_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_STATUSBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewStatusbar"); @@ -2063,7 +2087,7 @@ clone_window (PlumaWindow *origin) { gint w, h; - pluma_prefs_manager_get_default_window_size (&w, &h); + _pluma_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_maximize (GTK_WINDOW (window)); } @@ -2611,7 +2635,8 @@ _pluma_window_set_lockdown (PlumaWindow *window, gboolean autosave; /* start/stop autosave in each existing tab */ - autosave = pluma_prefs_manager_get_auto_save (); + autosave = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_AUTO_SAVE); gtk_container_foreach (GTK_CONTAINER (window->priv->notebook), update_tab_autosave, &autosave); @@ -3618,22 +3643,23 @@ side_panel_visibility_changed (GtkWidget *side_panel, visible = gtk_widget_get_visible (side_panel); - if (!g_settings_get_boolean (pluma_prefs_manager->settings, "show-tabs-with-side-pane")) + if (!g_settings_get_boolean (window->priv->editor_settings, "show-tabs-with-side-pane")) { if (visible) gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), FALSE); else gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), - g_settings_get_boolean (pluma_prefs_manager->settings, "show-single-tab") || + g_settings_get_boolean (window->priv->editor_settings, "show-single-tab") || (gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)) > 1)); } else gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), - g_settings_get_boolean (pluma_prefs_manager->settings, "show-single-tab") || + g_settings_get_boolean (window->priv->editor_settings, "show-single-tab") || (gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)) > 1)); - if (pluma_prefs_manager_side_pane_visible_can_set ()) - pluma_prefs_manager_set_side_pane_visible (visible); + g_settings_set_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANE_VISIBLE, + visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewSidePane"); @@ -3686,8 +3712,9 @@ bottom_panel_visibility_changed (PlumaPanel *bottom_panel, visible = gtk_widget_get_visible (GTK_WIDGET (bottom_panel)); - if (pluma_prefs_manager_bottom_panel_visible_can_set ()) - pluma_prefs_manager_set_bottom_panel_visible (visible); + g_settings_set_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANE_VISIBLE, + visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); @@ -3766,15 +3793,24 @@ static void init_panels_visibility (PlumaWindow *window) { gint active_page; + gboolean side_pane_visible; + gboolean bottom_pane_visible; pluma_debug (DEBUG_WINDOW); /* side pane */ - active_page = pluma_prefs_manager_get_side_panel_active_page (); + active_page = g_settings_get_int (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANEL_ACTIVE_PAGE); _pluma_panel_set_active_item_by_id (PLUMA_PANEL (window->priv->side_panel), active_page); - if (pluma_prefs_manager_get_side_pane_visible ()) + side_pane_visible = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANE_VISIBLE); + bottom_pane_visible = g_settings_get_boolean (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANE_VISIBLE); + + if (side_pane_visible) + { gtk_widget_show (window->priv->side_panel); } @@ -3782,11 +3818,12 @@ init_panels_visibility (PlumaWindow *window) /* bottom pane, it can be empty */ if (pluma_panel_get_n_items (PLUMA_PANEL (window->priv->bottom_panel)) > 0) { - active_page = pluma_prefs_manager_get_bottom_panel_active_page (); + active_page = g_settings_get_int (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE); _pluma_panel_set_active_item_by_id (PLUMA_PANEL (window->priv->bottom_panel), active_page); - if (pluma_prefs_manager_get_bottom_panel_visible ()) + if (bottom_pane_visible) { gtk_widget_show (window->priv->bottom_panel); } @@ -3965,6 +4002,7 @@ pluma_window_init (PlumaWindow *window) window->priv->dispose_has_run = FALSE; window->priv->fullscreen_controls = NULL; window->priv->fullscreen_animation_timeout_id = 0; + window->priv->editor_settings = g_settings_new (PLUMA_SCHEMA_ID); window->priv->message_bus = pluma_message_bus_new (); @@ -4011,8 +4049,10 @@ pluma_window_init (PlumaWindow *window) /* panes' state must be restored after panels have been mapped, * since the bottom pane position depends on the size of the vpaned. */ - window->priv->side_panel_size = pluma_prefs_manager_get_side_panel_size (); - window->priv->bottom_panel_size = pluma_prefs_manager_get_bottom_panel_size (); + window->priv->side_panel_size = g_settings_get_int (window->priv->editor_settings, + PLUMA_SETTINGS_SIDE_PANEL_SIZE); + window->priv->bottom_panel_size = g_settings_get_int (window->priv->editor_settings, + PLUMA_SETTINGS_BOTTOM_PANEL_SIZE); g_signal_connect_after (window->priv->hpaned, "map", @@ -4797,3 +4837,13 @@ pluma_window_get_message_bus (PlumaWindow *window) return window->priv->message_bus; } + +void +_pluma_window_get_default_size (gint *width, gint *height) +{ + g_return_if_fail (width != NULL && height != NULL); + + *width = PLUMA_WINDOW_DEFAULT_WIDTH; + *height = PLUMA_WINDOW_DEFAULT_HEIGHT; +} + diff --git a/pluma/pluma-window.h b/pluma/pluma-window.h index ebd2c814..32a96997 100644 --- a/pluma/pluma-window.h +++ b/pluma/pluma-window.h @@ -187,6 +187,9 @@ void _pluma_recent_add (PlumaWindow *window, void _pluma_recent_remove (PlumaWindow *window, const gchar *uri); +void _pluma_window_get_default_size (gint *width, + gint *height); + G_END_DECLS #endif /* __PLUMA_WINDOW_H__ */ diff --git a/pluma/pluma.c b/pluma/pluma.c index c396429f..9988b557 100644 --- a/pluma/pluma.c +++ b/pluma/pluma.c @@ -52,10 +52,10 @@ #include "pluma-dirs.h" #include "pluma-encodings.h" #include "pluma-plugins-engine.h" -#include "pluma-prefs-manager-app.h" #include "pluma-session.h" #include "pluma-utils.h" #include "pluma-window.h" +#include "pluma-settings.h" #include "eggsmclient.h" #include "eggdesktopfile.h" @@ -599,10 +599,6 @@ main (int argc, char *argv[]) /* Set the associated .desktop file */ egg_set_desktop_file (DATADIR "/applications/pluma.desktop"); - /* Load user preferences */ - pluma_debug_message (DEBUG_APP, "Init prefs manager"); - pluma_prefs_manager_app_init (); - /* Init plugins engine */ pluma_debug_message (DEBUG_APP, "Init plugins"); engine = pluma_plugins_engine_get_default (); @@ -661,7 +657,8 @@ main (int argc, char *argv[]) * finalize it properly. */ g_object_unref (engine); - pluma_prefs_manager_app_shutdown (); + + pluma_settings_unref_singleton (); #ifndef ENABLE_GVFS_METADATA pluma_metadata_manager_shutdown (); diff --git a/po/POTFILES.in b/po/POTFILES.in index e87f0bab..d3754054 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,7 +27,6 @@ pluma/pluma-io-error-message-area.c pluma/pluma-notebook.c pluma/pluma-panel.c pluma/pluma-plugins-engine.c -pluma/pluma-prefs-manager.c pluma/pluma-print-job.c pluma/pluma-print-preferences.ui pluma/pluma-print-preview.c diff --git a/tests/document-loader.c b/tests/document-loader.c index d2c21cc0..7cc3cd03 100644 --- a/tests/document-loader.c +++ b/tests/document-loader.c @@ -21,7 +21,6 @@ */ #include "pluma-document-loader.h" -#include "pluma-prefs-manager-app.h" #include <gio/gio.h> #include <gtk/gtk.h> #include <glib.h> @@ -239,8 +238,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - pluma_prefs_manager_app_init (); - g_test_add_func ("/document-loader/end-line-stripping", test_end_line_stripping); g_test_add_func ("/document-loader/end-new-line-detection", test_end_new_line_detection); g_test_add_func ("/document-loader/begin-new-line-detection", test_begin_new_line_detection); diff --git a/tests/document-output-stream.c b/tests/document-output-stream.c index 05d14ff2..88997e26 100644 --- a/tests/document-output-stream.c +++ b/tests/document-output-stream.c @@ -22,7 +22,6 @@ #include "pluma-document-output-stream.h" -#include "pluma-prefs-manager-app.h" #include <gio/gio.h> #include <gtk/gtk.h> #include <glib.h> @@ -125,8 +124,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - pluma_prefs_manager_app_init (); - g_test_add_func ("/document-output-stream/empty", test_empty); g_test_add_func ("/document-output-stream/consecutive", test_consecutive); diff --git a/tests/document-saver.c b/tests/document-saver.c index a80ba02e..a85b4050 100644 --- a/tests/document-saver.c +++ b/tests/document-saver.c @@ -21,7 +21,6 @@ */ #include "pluma-document-loader.h" -#include "pluma-prefs-manager-app.h" #include <gio/gio.h> #include <gtk/gtk.h> #include <glib.h> @@ -688,8 +687,6 @@ int main (int argc, g_test_init (&argc, &argv, NULL); - pluma_prefs_manager_app_init (); - g_printf ("\n***\n"); have_unowned = check_unowned_directory (); have_unowned_group = check_unowned_group (); |