diff --git a/data/Makefile.am b/data/Makefile.am index 067ad8f..8591f2b 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -4,11 +4,13 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ @INTLTOOL_XML_RULE@ + appdatadir = $(datadir)/appdata appdata_in_files = xed.appdata.xml.in appdata_DATA = $(appdata_in_files:.xml.in=.xml) gsettings_SCHEMAS = org.x.editor.gschema.xml + @GSETTINGS_RULES@ man_MANS = xed.1 diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in index 3d27f97..012b278 100644 --- a/data/org.x.editor.gschema.xml.in +++ b/data/org.x.editor.gschema.xml.in @@ -1,200 +1,330 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true Use Default Font Whether to use the system's default fixed width font for editing text instead of a font specific to xed. If this option is turned off, then the font named in the "Editor Font" option will be used instead of the system font. + 'Monospace 12' Editor Font A custom font that will be used for the editing area. This will only take effect if the "Use Default Font" option is turned off. - + + 'tango' Style Scheme The ID of a GtkSourceView Style Scheme used to color the text. + false Create Backup Copies Whether xed should create backup copies for the files it saves. You can set the backup file extension with the "Backup Copy Extension" option. + false Autosave Whether xed should automatically save modified files after a time interval. You can set the time interval with the "Autosave Interval" option. - + + 10 Autosave Interval Number of minutes after which xed will automatically save modified files. This will only take effect if the "Autosave" option is turned on. + [ 'dav', 'davs', 'ftp', 'sftp', 'smb', 'ssh' ] Writable VFS schemes List of VFS schemes xed supports in write mode. The 'file' scheme is writable by default. + 2000 Maximum Number of Undo Actions Maximum number of actions that xed will be able to undo or redo. Use "-1" for unlimited number of actions. - - 'GTK_WRAP_WORD' + + + 'word' Line Wrapping Mode - 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. + Specifies how to wrap long lines in the editing area. Use "none" for no wrapping, "word" for wrapping at word boundaries, and "char" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. - + + 4 Tab Size Specifies the number of spaces that should be displayed instead of Tab characters. + true Insert spaces Whether xed should insert spaces instead of tabs. + false Automatic indent Whether xed should enable automatic indentation. + false Display Line Numbers Whether xed should display line numbers in the editing area. + false Highlight Current Line Whether xed should highlight the current line. + false Highlight Matching Bracket Whether xed should highlight the bracket matching the selected one. + false Display Right Margin Whether xed should display the right margin in the editing area. - + + 120 Right Margin Position Specifies the position of the right margin. - + + 'after' Smart Home End - Specifies how the cursor moves when the HOME and END keys are pressed. Use "DISABLED" to always move at the start/end of the line, "AFTER" to move to the start/end of the line the first time the keys are pressed and to the start/end of the text ignoring whitespaces the second time the keys are pressed, "BEFORE" to move to the start/end of the text before moving to the start/end of the line and "ALWAYS" to always move to the start/end of the text instead of the start/end of the line. + Specifies how the cursor moves when the HOME and END keys are pressed. Use "disabled" to always move at the start/end of the line, "after" to move to the start/end of the line the first time the keys are pressed and to the start/end of the text ignoring whitespaces the second time the keys are pressed, "before" to move to the start/end of the text before moving to the start/end of the line and "always" to always move to the start/end of the text instead of the start/end of the line. + true Restore Previous Cursor Position Whether xed should restore the previous cursor position when a file is loaded. - + + true Enable Search Highlighting Whether xed should highlight all the occurrences of the searched text. - + + true Enable Syntax Highlighting Whether xed should enable syntax highlighting. + + + + + true Toolbar is Visible Whether the toolbar should be visible in editing windows. + true Status Bar is Visible Whether the status bar at the bottom of editing windows should be visible. - + + false Side Pane is Visible Whether the side pane at the left of editing windows should be visible. + false Bottom Panel is Visible Whether the bottom panel at the bottom of editing windows should be visible. + true Allow changing active tabs by scrolling Whether you can change active tabs by scrolling. - + + 5 Maximum Recent Files Specifies the maximum number of recently opened files that will be displayed in the "Recent Files" submenu. + + + + + true Print Syntax Highlighting Whether xed should print syntax highlighting when printing documents. + true Print Header Whether xed should include a document header when printing documents. - - 'GTK_WRAP_WORD' + + + 'word' Printing Line Wrapping Mode - 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. + Specifies how to wrap long lines for printing. Use "none" for no wrapping, "word" for wrapping at word boundaries, and "char" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. - + + 0 Print Line Numbers If this value is 0, then no line numbers will be inserted when printing a document. Otherwise, xed will print line numbers every such number of lines. + 'Monospace 9' Body Font for Printing Specifies the font to use for a document's body when printing documents. + 'Sans 11' Header Font for Printing Specifies the font to use for page headers when printing a document. This will only take effect if the "Print Header" option is turned on. + 'Sans 8' Line Number Font for Printing Specifies the font to use for line numbers when printing. This will only take effect if the "Print Line Numbers" option is non-zero. - + + + + + + [ 'UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16' ] Automatically Detected Encodings Sorted list of encodings used by xed for automatically detecting the encoding of a file. "CURRENT" represents the current locale encoding. Only recognized encodings are used. - + + [ 'ISO-8859-15' ] Encodings shown in menu List of encodings shown in the Character Encoding menu in open/save file selector. Only recognized encodings are used. + + + + + + + + + + + + + 0 + + + + (650,500) + + + + 200 + + + + 0 + + + + 140 + + + + 0 + + + + + + + + 0 + + + + + + [] History for "search for" entries List of entries in "search for" textbox. + [] History for "replace with" entries List of entries in "replace with" textbox. + + + + + [ 'docinfo', 'modelines', 'filebrowser', 'spell', 'time' ] Active plugins List of active plugins. It contains the "Location" of the active plugins. See the .xed-plugin file for obtaining the "Location" of a given plugin. + + diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index 2661912..c900eab 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -25,8 +25,9 @@ #include #include #include -#include #include +#include +#include #include "modeline-parser.h" #define MODELINES_LANGUAGE_MAPPINGS_FILE "language-mappings" @@ -678,6 +679,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; + GSettings *settings; options.language_id = NULL; options.set = MODELINE_SET_NONE; @@ -764,6 +766,8 @@ modeline_parser_apply_modeline (GtkSourceView *view) ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY); + settings = g_settings_new ("org.x.editor.preferences.editor"); + /* Apply the options we got from modelines and restore defaults if we set them before */ if (has_option (&options, MODELINE_SET_INSERT_SPACES)) @@ -773,9 +777,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES)) { - gtk_source_view_set_insert_spaces_instead_of_tabs - (view, - xed_prefs_manager_get_insert_spaces ()); + gboolean insert_spaces; + + insert_spaces = g_settings_get_boolean (settings, XED_SETTINGS_INSERT_SPACES); + gtk_source_view_set_insert_spaces_instead_of_tabs (view, insert_spaces); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) @@ -784,8 +789,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { - gtk_source_view_set_tab_width (view, - xed_prefs_manager_get_tabs_size ()); + guint tab_width; + + tab_width = g_settings_get_uint (settings, XED_SETTINGS_TABS_SIZE); + gtk_source_view_set_tab_width (view, tab_width); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) @@ -803,8 +810,10 @@ 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), - xed_prefs_manager_get_wrap_mode ()); + GtkWrapMode mode; + + mode = g_settings_get_enum (settings, XED_SETTINGS_WRAP_MODE); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), mode); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) @@ -813,8 +822,10 @@ 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, - xed_prefs_manager_get_right_margin_position ()); + guint right_margin_pos; + + right_margin_pos = g_settings_get_uint (settings, XED_SETTINGS_RIGHT_MARGIN_POSITION); + gtk_source_view_set_right_margin_position (view, right_margin_pos); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) @@ -823,8 +834,10 @@ 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, - xed_prefs_manager_get_display_right_margin ()); + gboolean display_right_margin; + + display_right_margin = g_settings_get_boolean (settings, XED_SETTINGS_DISPLAY_RIGHT_MARGIN); + gtk_source_view_set_show_right_margin (view, display_right_margin); } if (previous) diff --git a/tests/document-loader.c b/tests/document-loader.c index 54ad365..1ad87ff 100644 --- a/tests/document-loader.c +++ b/tests/document-loader.c @@ -21,7 +21,6 @@ */ #include "xed-document-loader.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -241,8 +240,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - xed_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 b64bbe5..f74036a 100644 --- a/tests/document-output-stream.c +++ b/tests/document-output-stream.c @@ -16,13 +16,12 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include "xed-document-output-stream.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -125,8 +124,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - xed_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 9235adf..646acff 100644 --- a/tests/document-saver.c +++ b/tests/document-saver.c @@ -21,7 +21,6 @@ */ #include "xed-document-loader.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -684,8 +683,6 @@ int main (int argc, g_test_init (&argc, &argv, NULL); - xed_prefs_manager_app_init (); - g_printf ("\n***\n"); have_unowned = check_unowned_directory (); have_unowned_group = check_unowned_group (); diff --git a/xed/Makefile.am b/xed/Makefile.am index 3b2b1dd..2bb2c57 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -55,10 +55,10 @@ NOINST_H_FILES = \ xed-io-error-message-area.h \ xed-language-manager.h \ xed-plugins-engine.h \ - xed-prefs-manager-private.h \ xed-print-job.h \ xed-print-preview.h \ xed-session.h \ + xed-settings.h \ xed-smart-charset-converter.h \ xed-style-scheme-manager.h \ xed-tab-label.h \ @@ -81,8 +81,6 @@ INST_H_FILES = \ xed-message.h \ xed-notebook.h \ xed-panel.h \ - xed-prefs-manager-app.h \ - xed-prefs-manager.h \ xed-progress-message-area.h \ xed-searchbar.h \ xed-statusbar.h \ @@ -136,13 +134,11 @@ libxed_c_files = \ xed-notebook.c \ xed-panel.c \ xed-plugins-engine.c \ - xed-prefs-manager-app.c \ - xed-prefs-manager.c \ - xed-prefs-manager-private.h \ xed-print-job.c \ xed-print-preview.c \ xed-progress-message-area.c \ xed-session.c \ + xed-settings.c \ xed-smart-charset-converter.c \ xed-searchbar.c \ xed-statusbar.c \ diff --git a/xed/dialogs/xed-encodings-dialog.c b/xed/dialogs/xed-encodings-dialog.c index f94d16a..38028d6 100755 --- a/xed/dialogs/xed-encodings-dialog.c +++ b/xed/dialogs/xed-encodings-dialog.c @@ -40,11 +40,11 @@ #include "xed-encodings-dialog.h" #include "xed-encodings.h" -#include "xed-prefs-manager.h" #include "xed-utils.h" #include "xed-debug.h" #include "xed-help.h" #include "xed-dirs.h" +#include "xed-settings.h" #define XED_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ XED_TYPE_ENCODINGS_DIALOG, \ @@ -52,12 +52,15 @@ struct _XedEncodingsDialogPrivate { + GSettings *enc_settings; + GtkListStore *available_liststore; GtkListStore *displayed_liststore; - GtkWidget *available_treeview; - GtkWidget *displayed_treeview; - GtkWidget *add_button; - GtkWidget *remove_button; + + GtkWidget *available_treeview; + GtkWidget *displayed_treeview; + GtkWidget *add_button; + GtkWidget *remove_button; GSList *show_in_menu_list; }; @@ -74,12 +77,23 @@ xed_encodings_dialog_finalize (GObject *object) G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object); } +static void +xed_encodings_dialog_dispose (GObject *object) +{ + XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv; + + g_clear_object (&priv->enc_settings); + + G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->dispose (object); +} + static void xed_encodings_dialog_class_init (XedEncodingsDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = xed_encodings_dialog_finalize; + object_class->dispose = xed_encodings_dialog_dispose; g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate)); } @@ -228,14 +242,15 @@ static void init_shown_in_menu_tree_model (XedEncodingsDialog *dialog) { GtkTreeIter iter; + gchar **enc_strv; GSList *list, *tmp; /* add data to the list store */ - list = xed_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (dialog->priv->enc_settings, XED_SETTINGS_ENCODING_SHOWN_IN_MENU); - tmp = list; + list = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); - while (tmp != NULL) + for (tmp = list; tmp != NULL; tmp = g_slist_next (tmp)) { const XedEncoding *enc; @@ -248,8 +263,6 @@ init_shown_in_menu_tree_model (XedEncodingsDialog *dialog) COLUMN_CHARSET, xed_encoding_get_charset (enc), COLUMN_NAME, xed_encoding_get_name (enc), -1); - - tmp = g_slist_next (tmp); } g_slist_free (list); @@ -269,8 +282,14 @@ response_handler (GtkDialog *dialog, if (response_id == GTK_RESPONSE_OK) { - g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); - xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list); + gchar **encs; + + encs = _xed_encoding_list_to_strv (dlg->priv->show_in_menu_list); + g_settings_set_strv (dlg->priv->enc_settings, + XED_SETTINGS_ENCODING_SHOWN_IN_MENU, + (const gchar * const *)encs); + + g_strfreev (encs); } } @@ -294,6 +313,7 @@ xed_encodings_dialog_init (XedEncodingsDialog *dlg) }; dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg); + dlg->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); gtk_dialog_add_buttons (GTK_DIALOG (dlg), _("_Cancel"), GTK_RESPONSE_CANCEL, diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 28c4dfa..0469f17 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -41,8 +41,6 @@ #include #include -#include - #include "xed-preferences-dialog.h" #include "xed-utils.h" #include "xed-debug.h" @@ -50,6 +48,8 @@ #include "xed-style-scheme-manager.h" #include "xed-help.h" #include "xed-dirs.h" +#include "xed-settings.h" +#include "xed-utils.h" /* * xed-preferences dialog is a singleton since we don't @@ -78,72 +78,87 @@ enum struct _XedPreferencesDialogPrivate { + GSettings *editor; + GSettings *ui; + GtkWidget *notebook; /* Font */ - GtkWidget *default_font_checkbutton; - GtkWidget *font_button; - GtkWidget *font_hbox; + GtkWidget *default_font_checkbutton; + GtkWidget *font_button; + GtkWidget *font_hbox; /* Style Scheme */ - GtkListStore *schemes_treeview_model; - GtkWidget *schemes_treeview; - GtkWidget *install_scheme_button; - GtkWidget *uninstall_scheme_button; + GtkListStore *schemes_treeview_model; + GtkWidget *schemes_treeview; + GtkWidget *install_scheme_button; + GtkWidget *uninstall_scheme_button; - GtkWidget *install_scheme_file_schooser; + GtkWidget *install_scheme_file_schooser; /* Tabs */ - GtkWidget *tabs_width_spinbutton; - GtkWidget *insert_spaces_checkbutton; - GtkWidget *tabs_width_hbox; + GtkWidget *tabs_width_spinbutton; + GtkWidget *insert_spaces_checkbutton; + GtkWidget *tabs_width_hbox; /* Auto indentation */ - GtkWidget *auto_indent_checkbutton; + GtkWidget *auto_indent_checkbutton; /* Text Wrapping */ - GtkWidget *wrap_text_checkbutton; - GtkWidget *split_checkbutton; + GtkWidget *wrap_text_checkbutton; + GtkWidget *split_checkbutton; /* File Saving */ - GtkWidget *backup_copy_checkbutton; - GtkWidget *auto_save_checkbutton; - GtkWidget *auto_save_spinbutton; - GtkWidget *autosave_hbox; + GtkWidget *backup_copy_checkbutton; + GtkWidget *auto_save_checkbutton; + GtkWidget *auto_save_spinbutton; + GtkWidget *autosave_hbox; /* Line numbers */ - GtkWidget *display_line_numbers_checkbutton; + GtkWidget *display_line_numbers_checkbutton; /* Highlight current line */ - GtkWidget *highlight_current_line_checkbutton; + GtkWidget *highlight_current_line_checkbutton; /* Highlight matching bracket */ - GtkWidget *bracket_matching_checkbutton; + GtkWidget *bracket_matching_checkbutton; /* Right margin */ - GtkWidget *right_margin_checkbutton; - GtkWidget *right_margin_position_spinbutton; - GtkWidget *right_margin_position_hbox; + GtkWidget *right_margin_checkbutton; + GtkWidget *right_margin_position_spinbutton; + GtkWidget *right_margin_position_hbox; /* Tab scrolling */ - GtkWidget *tab_scrolling_checkbutton; + GtkWidget *tab_scrolling_checkbutton; /* Plugins manager */ - GtkWidget *plugin_manager_place_holder; + GtkWidget *plugin_manager_place_holder; /* Style Scheme editor dialog */ - GtkWidget *style_scheme_dialog; + GtkWidget *style_scheme_dialog; }; G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG) +static void +xed_preferences_dialog_dispose (GObject *object) +{ + XedPreferencesDialog *dlg = XED_PREFERENCES_DIALOG (object); + + g_clear_object (&dlg->priv->editor); + g_clear_object (&dlg->priv->ui); + + G_OBJECT_CLASS (xed_preferences_dialog_parent_class)->dispose (object); +} static void xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_preferences_dialog_dispose; + g_type_class_add_private (object_class, sizeof (XedPreferencesDialogPrivate)); } @@ -165,172 +180,75 @@ dialog_response_handler (GtkDialog *dlg, } static void -tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) +on_auto_save_changed (GSettings *settings, + const gchar *key, + XedPreferencesDialog *dlg) { + gboolean value; + xed_debug (DEBUG_PREFS); - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton)); + value = g_settings_get_boolean (settings, key); - xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); -} - -static void -insert_spaces_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton)); - - xed_prefs_manager_set_insert_spaces (gtk_toggle_button_get_active (button)); -} - -static void -auto_indent_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton)); - - xed_prefs_manager_set_auto_indent (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_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, xed_prefs_manager_auto_save_interval_can_set()); - xed_prefs_manager_set_auto_save (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); - xed_prefs_manager_set_auto_save (FALSE); - } -} - -static void -backup_copy_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); - - xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); - - xed_prefs_manager_set_auto_save_interval (MAX (1, gtk_spin_button_get_value_as_int (spin_button))); -} - -static void -tab_scrolling_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton)); - - xed_prefs_manager_set_enable_tab_scrolling (gtk_toggle_button_get_active (button)); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, value); } static void setup_editor_page (XedPreferencesDialog *dlg) { gboolean auto_save; - gint auto_save_interval; xed_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), - (guint) xed_prefs_manager_get_tabs_size ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), - xed_prefs_manager_get_insert_spaces ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), - xed_prefs_manager_get_auto_indent ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), - xed_prefs_manager_get_create_backup_copy ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton), - xed_prefs_manager_get_enable_tab_scrolling ()); - - auto_save = xed_prefs_manager_get_auto_save (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), auto_save); - - auto_save_interval = xed_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); + /* Get values */ + auto_save = g_settings_get_boolean (dlg->priv->editor, XED_SETTINGS_AUTO_SAVE); /* Set widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, xed_prefs_manager_tabs_size_can_set ()); - gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, xed_prefs_manager_insert_spaces_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, xed_prefs_manager_auto_indent_can_set ()); - gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, xed_prefs_manager_create_backup_copy_can_set ()); - gtk_widget_set_sensitive (dlg->priv->autosave_hbox, xed_prefs_manager_auto_save_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - auto_save && xed_prefs_manager_auto_save_interval_can_set ()); - gtk_widget_set_sensitive (dlg->priv->tab_scrolling_checkbutton, xed_prefs_manager_enable_tab_scrolling_can_set ()); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, auto_save); /* 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->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); - g_signal_connect (dlg->priv->tab_scrolling_checkbutton, "toggled", - G_CALLBACK (tab_scrolling_checkbutton_toggled), dlg); -} - -static void -display_line_numbers_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); - - xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); -} - -static void -highlight_current_line_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); - - xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); -} - -static void -bracket_matching_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); - - xed_prefs_manager_set_bracket_matching (gtk_toggle_button_get_active (button)); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_TABS_SIZE, + dlg->priv->tabs_width_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_INSERT_SPACES, + dlg->priv->insert_spaces_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_INDENT, + dlg->priv->auto_indent_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_CREATE_BACKUP_COPY, + dlg->priv->backup_copy_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_BRACKET_MATCHING, + dlg->priv->bracket_matching_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_SAVE_INTERVAL, + dlg->priv->auto_save_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_signal_connect (dlg->priv->editor, "changed::auto_save", + G_CALLBACK (on_auto_save_changed), dlg); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_SAVE, + dlg->priv->auto_save_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->ui, + XED_SETTINGS_ENABLE_TAB_SCROLLING, + dlg->priv->tab_scrolling_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); } static gboolean split_button_state = TRUE; @@ -339,9 +257,11 @@ static void wrap_mode_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { + GtkWrapMode mode; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) { - xed_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); @@ -355,14 +275,16 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button, if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) { split_button_state = TRUE; - xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); + mode = GTK_WRAP_WORD; } else { split_button_state = FALSE; - xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); + mode = GTK_WRAP_CHAR; } } + + g_settings_set_enum (dlg->priv->editor, XED_SETTINGS_WRAP_MODE, mode); } static void @@ -375,23 +297,9 @@ right_margin_checkbutton_toggled (GtkToggleButton *button, active = gtk_toggle_button_get_active (button); - xed_prefs_manager_set_display_right_margin (active); + g_settings_set_boolean (dlg->priv->editor, XED_SETTINGS_DISPLAY_RIGHT_MARGIN, active); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - active && xed_prefs_manager_right_margin_position_can_set ()); -} - -static void -right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) -{ - gint value; - - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); - - value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); - - xed_prefs_manager_set_right_margin_position (value); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, active); } static void @@ -399,22 +307,18 @@ setup_view_page (XedPreferencesDialog *dlg) { GtkWrapMode wrap_mode; gboolean display_right_margin; - gboolean wrap_mode_can_set; + guint right_margin_position; xed_debug (DEBUG_PREFS); + /* Get values */ + display_right_margin = g_settings_get_boolean (dlg->priv->editor, XED_SETTINGS_DISPLAY_RIGHT_MARGIN); + right_margin_position = g_settings_get_uint (dlg->priv->editor, XED_SETTINGS_RIGHT_MARGIN_POSITION); + /* Set initial state */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), - xed_prefs_manager_get_display_line_numbers ()); + wrap_mode = g_settings_get_enum (dlg->priv->editor, XED_SETTINGS_WRAP_MODE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), - xed_prefs_manager_get_highlight_current_line ()); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), - xed_prefs_manager_get_bracket_matching ()); - - wrap_mode = xed_prefs_manager_get_wrap_mode (); - switch (wrap_mode ) + switch (wrap_mode) { case GTK_WRAP_WORD: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); @@ -431,89 +335,55 @@ setup_view_page (XedPreferencesDialog *dlg) } - display_right_margin = xed_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 (xed_prefs_manager_get_right_margin_position (), 1, 160)); - /* Set widgets sensitivity */ - gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, - xed_prefs_manager_display_line_numbers_can_set ()); - gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, - xed_prefs_manager_highlight_current_line_can_set ()); - gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, xed_prefs_manager_bracket_matching_can_set ()); - wrap_mode_can_set = xed_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, xed_prefs_manager_display_right_margin_can_set ()); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - display_right_margin && xed_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); /* 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_settings_bind (dlg->priv->editor, + XED_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, + XED_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, + XED_SETTINGS_RIGHT_MARGIN_POSITION, + dlg->priv->right_margin_position_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); g_signal_connect (dlg->priv->wrap_text_checkbutton, "toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->split_checkbutton, "toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->right_margin_checkbutton, "toggled", G_CALLBACK (right_margin_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->right_margin_position_spinbutton, "value_changed", - G_CALLBACK (right_margin_position_spinbutton_value_changed), dlg); } static void -default_font_font_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_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); - xed_prefs_manager_set_use_default_font (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); - xed_prefs_manager_set_use_default_font (FALSE); - } -} - -static void -editor_font_button_font_set (GtkFontButton *font_button, +on_use_default_font_changed (GSettings *settings, + const gchar *key, XedPreferencesDialog *dlg) { - const gchar *font_name; + gboolean value; xed_debug (DEBUG_PREFS); - g_return_if_fail (font_button == GTK_FONT_BUTTON (dlg->priv->font_button)); - - /* FIXME: Can this fail? Gtk docs are a bit terse... 21-02-2004 pbor */ - font_name = gtk_font_button_get_font_name (font_button); - if (!font_name) - { - g_warning ("Could not get font name"); - return; - } - - xed_prefs_manager_set_editor_font (font_name); + value = g_settings_get_boolean (settings, key); + gtk_widget_set_sensitive (dlg->priv->font_hbox, value); } static void setup_font_colors_page_font_section (XedPreferencesDialog *dlg) { + GSettings *settings; gboolean use_default_font; - gchar *editor_font = NULL; + gchar *system_font = NULL; gchar *label; xed_debug (DEBUG_PREFS); @@ -528,40 +398,35 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) dlg->priv->font_button, ATK_RELATION_CONTROLLER_FOR); - editor_font = xed_prefs_manager_get_system_font (); - label = g_strdup_printf(_("_Use the system fixed width font (%s)"), editor_font); + /* Get values */ + settings = _xed_app_get_settings (xed_app_get_default ()); + system_font = xed_settings_get_system_font (XED_SETTINGS (settings)); + use_default_font = g_settings_get_boolean (dlg->priv->editor, XED_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 = xed_prefs_manager_get_use_default_font (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), use_default_font); - editor_font = xed_prefs_manager_get_editor_font (); - if (editor_font != NULL) - { - gtk_font_button_set_font_name (GTK_FONT_BUTTON (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), dlg); + g_signal_connect (dlg->priv->editor, "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), dlg); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_USE_DEFAULT_FONT, + dlg->priv->default_font_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_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, xed_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, xed_prefs_manager_editor_font_can_set ()); - } + gtk_widget_set_sensitive (dlg->priv->font_hbox, use_default_font); } static void @@ -589,7 +454,7 @@ style_scheme_changed (GtkWidget *treeview, gtk_tree_path_free (path); gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, ID_COLUMN, &id, -1); - xed_prefs_manager_set_source_style_scheme (id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, id); set_buttons_sensisitivity_according_to_scheme (dlg, id); @@ -597,7 +462,8 @@ style_scheme_changed (GtkWidget *treeview, } static const gchar * -ensure_color_scheme_id (const gchar *id) +ensure_color_scheme_id (XedPreferencesDialog *dlg, + const gchar *id) { GtkSourceStyleScheme *scheme = NULL; GtkSourceStyleSchemeManager *manager = xed_get_style_scheme_manager (); @@ -606,7 +472,7 @@ ensure_color_scheme_id (const gchar *id) { gchar *pref_id; - pref_id = xed_prefs_manager_get_source_style_scheme (); + pref_id = g_settings_get_string (dlg->priv->editor, XED_SETTINGS_SCHEME); scheme = gtk_source_style_scheme_manager_get_scheme (manager, pref_id); g_free (pref_id); } @@ -642,7 +508,7 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, 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" @@ -720,7 +586,7 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, return; } - xed_prefs_manager_set_source_style_scheme (scheme_id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, scheme_id); scheme_id = populate_color_scheme_list (dlg, scheme_id); @@ -852,7 +718,7 @@ uninstall_scheme_clicked (GtkButton *button, if (real_new_id != NULL) { - xed_prefs_manager_set_source_style_scheme (real_new_id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, real_new_id); } } @@ -983,6 +849,8 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) xed_debug (DEBUG_PREFS); dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); + dlg->priv->editor = g_settings_new ("org.x.editor.preferences.editor"); + dlg->priv->ui = g_settings_new ("org.x.editor.preferences.ui"); gtk_dialog_add_buttons (GTK_DIALOG (dlg), _("Close"), GTK_RESPONSE_CLOSE, diff --git a/xed/xed-app.c b/xed/xed-app.c index 70c520c..a06f2be 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -39,7 +39,6 @@ #include #include "xed-app.h" -#include "xed-prefs-manager-app.h" #include "xed-commands.h" #include "xed-notebook.h" #include "xed-debug.h" @@ -48,6 +47,7 @@ #include "xed-dirs.h" #include "xed-app-activatable.h" #include "xed-plugins-engine.h" +#include "xed-settings.h" #define XED_PAGE_SETUP_FILE "xed-page-setup" #define XED_PRINT_SETTINGS_FILE "xed-print-settings" @@ -62,12 +62,15 @@ enum struct _XedAppPrivate { - GList *windows; - XedWindow *active_window; + GList *windows; + XedWindow *active_window; - GtkPageSetup *page_setup; + GtkPageSetup *page_setup; GtkPrintSettings *print_settings; + GSettings *settings; + GSettings *window_settings; + PeasExtensionSet *extensions; }; @@ -98,6 +101,8 @@ xed_app_dispose (GObject *object) { XedApp *app = XED_APP (object); + g_clear_object (&app->priv->window_settings); + g_clear_object (&app->priv->settings); g_clear_object (&app->priv->extensions); G_OBJECT_CLASS (xed_app_parent_class)->dispose (object); @@ -350,6 +355,8 @@ xed_app_init (XedApp *app) load_accels (); + app->priv->settings = xed_settings_new (); + app->priv->window_settings = g_settings_new ("org.x.editor.state.window"); app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), XED_TYPE_APP_ACTIVATABLE, "app", app, NULL); @@ -525,17 +532,17 @@ xed_app_create_window_real (XedApp *app, GdkWindowState state; gint w, h; - state = xed_prefs_manager_get_window_state (); + state = g_settings_get_int (app->priv->window_settings, XED_SETTINGS_WINDOW_STATE); if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { - xed_prefs_manager_get_default_window_size (&w, &h); + _xed_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_maximize (GTK_WINDOW (window)); } else { - xed_prefs_manager_get_window_size (&w, &h); + g_settings_get (app->priv->window_settings, XED_SETTINGS_WINDOW_SIZE, "(ii)", &w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_unmaximize (GTK_WINDOW (window)); } @@ -867,3 +874,10 @@ _xed_app_set_default_print_settings (XedApp *app, app->priv->print_settings = g_object_ref (settings); } +GSettings * +_xed_app_get_settings (XedApp *app) +{ + g_return_val_if_fail (XED_IS_APP (app), NULL); + + return app->priv->settings; +} diff --git a/xed/xed-app.h b/xed/xed-app.h index 82988c1..f60acd5 100644 --- a/xed/xed-app.h +++ b/xed/xed-app.h @@ -2,7 +2,7 @@ * xed-app.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 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 @@ -16,14 +16,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -37,9 +37,6 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ #define XED_TYPE_APP (xed_app_get_type()) #define XED_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_APP, XedApp)) #define XED_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_APP, XedAppClass)) @@ -47,69 +44,62 @@ G_BEGIN_DECLS #define XED_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_APP)) #define XED_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_APP, XedAppClass)) -/* Private structure type */ -typedef struct _XedAppPrivate XedAppPrivate; +typedef struct _XedApp XedApp; +typedef struct _XedAppPrivate XedAppPrivate; +typedef struct _XedAppClass XedAppClass; -/* - * Main object structure - */ -typedef struct _XedApp XedApp; - -struct _XedApp +struct _XedApp { - GObject object; + GObject object; - /*< private > */ - XedAppPrivate *priv; + /*< private > */ + XedAppPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedAppClass XedAppClass; - -struct _XedAppClass +struct _XedAppClass { - GObjectClass parent_class; + GObjectClass parent_class; }; /* * Public methods */ -GType xed_app_get_type (void) G_GNUC_CONST; +GType xed_app_get_type (void) G_GNUC_CONST; -XedApp *xed_app_get_default (void); +XedApp *xed_app_get_default (void); -XedWindow *xed_app_create_window (XedApp *app, - GdkScreen *screen); +XedWindow *xed_app_create_window (XedApp *app, + GdkScreen *screen); -const GList *xed_app_get_windows (XedApp *app); -XedWindow *xed_app_get_active_window (XedApp *app); +const GList *xed_app_get_windows (XedApp *app); +XedWindow *xed_app_get_active_window (XedApp *app); /* Returns a newly allocated list with all the documents */ -GList *xed_app_get_documents (XedApp *app); +GList *xed_app_get_documents (XedApp *app); /* Returns a newly allocated list with all the views */ -GList *xed_app_get_views (XedApp *app); +GList *xed_app_get_views (XedApp *app); /* * Non exported functions */ -XedWindow *_xed_app_restore_window (XedApp *app, - const gchar *role); -XedWindow *_xed_app_get_window_in_viewport (XedApp *app, - GdkScreen *screen, - gint workspace, - gint viewport_x, - gint viewport_y); +XedWindow *_xed_app_restore_window (XedApp *app, + const gchar *role); +XedWindow *_xed_app_get_window_in_viewport (XedApp *app, + GdkScreen *screen, + gint workspace, + gint viewport_x, + gint viewport_y); /* global print config */ -GtkPageSetup *_xed_app_get_default_page_setup (XedApp *app); -void _xed_app_set_default_page_setup (XedApp *app, - GtkPageSetup *page_setup); -GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app); -void _xed_app_set_default_print_settings (XedApp *app, - GtkPrintSettings *settings); +GtkPageSetup *_xed_app_get_default_page_setup (XedApp *app); +void _xed_app_set_default_page_setup (XedApp *app, + GtkPageSetup *page_setup); +GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app); +void _xed_app_set_default_print_settings (XedApp *app, + GtkPrintSettings *settings); + +GSettings *_xed_app_get_settings (XedApp *app); G_END_DECLS diff --git a/xed/xed-document-loader.c b/xed/xed-document-loader.c index aaee954..3f40f2e 100644 --- a/xed/xed-document-loader.c +++ b/xed/xed-document-loader.c @@ -40,12 +40,12 @@ #include "xed-document-loader.h" #include "xed-document-output-stream.h" #include "xed-smart-charset-converter.h" -#include "xed-prefs-manager.h" #include "xed-debug.h" #include "xed-metadata-manager.h" #include "xed-utils.h" #include "xed-marshal.h" #include "xed-enum-types.h" +#include "xed-settings.h" #ifndef ENABLE_GVFS_METADATA #include "xed_metadata-manager.h" @@ -94,6 +94,8 @@ static void open_async_read (AsyncData *async); struct _XedDocumentLoaderPrivate { + GSettings *enc_settings; + XedDocument *document; gboolean used; @@ -228,6 +230,8 @@ xed_document_loader_dispose (GObject *object) priv->location = NULL; } + g_clear_object (&priv->enc_settings); + G_OBJECT_CLASS (xed_document_loader_parent_class)->dispose (object); } @@ -303,6 +307,7 @@ xed_document_loader_init (XedDocumentLoader *loader) loader->priv->auto_detected_newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; loader->priv->converter = NULL; loader->priv->error = NULL; + loader->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); } XedDocumentLoader * @@ -585,9 +590,12 @@ static GSList * get_candidate_encodings (XedDocumentLoader *loader) { const XedEncoding *metadata; - GSList *encodings = NULL; + GSList *encodings; + gchar **enc_strv; - encodings = xed_prefs_manager_get_auto_detected_encodings (); + enc_strv = g_settings_get_strv (loader->priv->enc_settings, XED_SETTINGS_ENCODING_AUTO_DETECTED); + encodings = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_free (enc_strv); metadata = get_metadata_encoding (loader); if (metadata != NULL) diff --git a/xed/xed-document-saver.c b/xed/xed-document-saver.c index 25718c7..0d795c4 100644 --- a/xed/xed-document-saver.c +++ b/xed/xed-document-saver.c @@ -39,10 +39,10 @@ #include "xed-document-saver.h" #include "xed-debug.h" #include "xed-document-input-stream.h" -#include "xed-prefs-manager.h" #include "xed-marshal.h" #include "xed-utils.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define WRITE_CHUNK_SIZE 8192 @@ -86,6 +86,8 @@ static void check_modified_async (AsyncData *async); struct _XedDocumentSaverPrivate { + GSettings *editor_settings; + GFileInfo *info; XedDocument *document; gboolean used; @@ -219,6 +221,8 @@ xed_document_saver_dispose (GObject *object) priv->location = NULL; } + g_clear_object (&priv->editor_settings); + G_OBJECT_CLASS (xed_document_saver_parent_class)->dispose (object); } @@ -314,17 +318,16 @@ xed_document_saver_class_init (XedDocumentSaverClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - signals[SAVING] = - g_signal_new ("saving", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentSaverClass, saving), - NULL, NULL, - xed_marshal_VOID__BOOLEAN_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); + signals[SAVING] = g_signal_new ("saving", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentSaverClass, saving), + NULL, NULL, + xed_marshal_VOID__BOOLEAN_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_BOOLEAN, + G_TYPE_POINTER); g_type_class_add_private (object_class, sizeof (XedDocumentSaverPrivate)); } @@ -337,6 +340,7 @@ xed_document_saver_init (XedDocumentSaver *saver) saver->priv->cancellable = g_cancellable_new (); saver->priv->error = NULL; saver->priv->used = FALSE; + saver->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); } XedDocumentSaver * @@ -940,7 +944,8 @@ xed_document_saver_save (XedDocumentSaver *saver, } else { - saver->priv->keep_backup = xed_prefs_manager_get_create_backup_copy (); + saver->priv->keep_backup = g_settings_get_boolean (saver->priv->editor_settings, + XED_SETTINGS_CREATE_BACKUP_COPY); } saver->priv->old_mtime = *old_mtime; diff --git a/xed/xed-document.c b/xed/xed-document.c index 51a4d15..371fa9e 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -41,7 +41,7 @@ #include #include -#include "xed-prefs-manager-app.h" +#include "xed-settings.h" #include "xed-document.h" #include "xed-debug.h" #include "xed-utils.h" @@ -102,7 +102,10 @@ static void delete_range_cb (XedDocument *doc, struct _XedDocumentPrivate { + GSettings *editor_settings; + GFile *location; + gint untitled_number; gchar *short_name; @@ -284,6 +287,8 @@ xed_document_dispose (GObject *object) doc->priv->loader = NULL; } + g_clear_object (&doc->priv->editor_settings); + if (doc->priv->metadata_info != NULL) { g_object_unref (doc->priv->metadata_info); @@ -676,8 +681,11 @@ set_language (XedDocument *doc, if (lang != NULL) { - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_enable_syntax_highlighting ()); + gboolean syntax_hl; + + syntax_hl = g_settings_get_boolean (doc->priv->editor_settings, + XED_SETTINGS_SYNTAX_HIGHLIGHTING); + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), syntax_hl); } else { @@ -723,16 +731,15 @@ set_encoding (XedDocument *doc, } static GtkSourceStyleScheme * -get_default_style_scheme (void) +get_default_style_scheme (GSettings *editor_settings) { gchar *scheme_id; GtkSourceStyleScheme *def_style; GtkSourceStyleSchemeManager *manager; manager = xed_get_style_scheme_manager (); - scheme_id = xed_prefs_manager_get_source_style_scheme (); - def_style = gtk_source_style_scheme_manager_get_scheme (manager, - scheme_id); + scheme_id = g_settings_get_string (editor_settings, XED_SETTINGS_SCHEME); + def_style = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); if (def_style == NULL) { @@ -874,11 +881,16 @@ static void xed_document_init (XedDocument *doc) { GtkSourceStyleScheme *style_scheme; + gint undo_actions; + gboolean bracket_matching; + gboolean search_hl; xed_debug (DEBUG_DOCUMENT); doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); + doc->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + doc->priv->location = NULL; doc->priv->untitled_number = get_untitled_number (); @@ -904,12 +916,15 @@ xed_document_init (XedDocument *doc) doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), xed_prefs_manager_get_undo_actions_limit ()); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_bracket_matching ()); - xed_document_set_enable_search_highlighting (doc, xed_prefs_manager_get_enable_search_highlighting ()); + undo_actions = g_settings_get_int (doc->priv->editor_settings, XED_SETTINGS_MAX_UNDO_ACTIONS); + bracket_matching = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_BRACKET_MATCHING); + search_hl = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_SEARCH_HIGHLIGHTING); - style_scheme = get_default_style_scheme (); + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), undo_actions); + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), bracket_matching); + xed_document_set_enable_search_highlighting (doc, search_hl); + + 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); @@ -1275,6 +1290,7 @@ document_loader_loaded (XedDocumentLoader *loader, { GtkTextIter iter; GFileInfo *info; + gboolean restore_cursor; const gchar *content_type = NULL; gboolean read_only = FALSE; GTimeVal mtime = {0, 0}; @@ -1309,6 +1325,8 @@ document_loader_loaded (XedDocumentLoader *loader, xed_document_set_newline_type (doc, xed_document_loader_get_newline_type (loader)); + restore_cursor = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_RESTORE_CURSOR_POSITION); + /* move the cursor at the requested line if any */ if (doc->priv->requested_line_pos > 0) { @@ -1318,7 +1336,7 @@ document_loader_loaded (XedDocumentLoader *loader, doc->priv->requested_line_pos - 1); } /* else, if enabled, to the position stored in the metadata */ - else if (xed_prefs_manager_get_restore_cursor_position ()) + else if (restore_cursor) { gchar *pos; gint offset; diff --git a/xed/xed-encodings-combo-box.c b/xed/xed-encodings-combo-box.c index f9cf161..d11dee2 100644 --- a/xed/xed-encodings-combo-box.c +++ b/xed/xed-encodings-combo-box.c @@ -37,8 +37,9 @@ #include #include -#include #include +#include "xed-settings.h" +#include "xed-utils.h" #define ENCODING_KEY "Enconding" @@ -48,6 +49,8 @@ struct _XedEncodingsComboBoxPrivate { + GSettings *enc_settings; + GtkListStore *store; glong changed_id; @@ -248,6 +251,7 @@ update_menu (XedEncodingsComboBox *menu) gchar *str; const XedEncoding *utf8_encoding; const XedEncoding *current_encoding; + gchar **enc_strv; store = menu->priv->store; @@ -308,7 +312,9 @@ update_menu (XedEncodingsComboBox *menu) g_free (str); } - encodings = xed_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (menu->priv->enc_settings, XED_SETTINGS_ENCODING_SHOWN_IN_MENU); + encodings = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_strfreev (enc_strv); for (l = encodings; l != NULL; l = g_slist_next (l)) { @@ -331,23 +337,20 @@ update_menu (XedEncodingsComboBox *menu) g_slist_free (encodings); - if (xed_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), GTK_TREE_MODEL (menu->priv->store)); @@ -363,6 +366,7 @@ xed_encodings_combo_box_init (XedEncodingsComboBox *menu) menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu); + menu->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); menu->priv->store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); /* Setup up the cells */ diff --git a/xed/xed-encodings.c b/xed/xed-encodings.c index d829578..b989e83 100644 --- a/xed/xed-encodings.c +++ b/xed/xed-encodings.c @@ -2,7 +2,7 @@ * xed-encodings.c * This file is part of xed * - * Copyright (C) 2002-2005 Paolo Maggi + * 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 @@ -16,14 +16,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -46,8 +46,8 @@ struct _XedEncoding const gchar *name; }; -/* - * The original versions of the following tables are taken from profterm +/* + * The original versions of the following tables are taken from profterm * * Copyright (C) 2002 Red Hat, Inc. */ @@ -108,7 +108,7 @@ typedef enum XED_ENCODING_KOI8_R, XED_ENCODING_KOI8__R, XED_ENCODING_KOI8_U, - + XED_ENCODING_SHIFT_JIS, XED_ENCODING_TCVN, XED_ENCODING_TIS_620, @@ -129,7 +129,7 @@ typedef enum XED_ENCODING_UTF_8, XED_ENCODING_UNKNOWN - + } XedEncodingIndex; static const XedEncoding utf8_encoding = { @@ -141,8 +141,8 @@ static const XedEncoding utf8_encoding = { /* initialized in xed_encoding_lazy_init() */ static XedEncoding unknown_encoding = { XED_ENCODING_UNKNOWN, - NULL, - NULL + NULL, + NULL }; static const XedEncoding encodings [] = { @@ -248,7 +248,7 @@ static const XedEncoding encodings [] = { "KOI8-R", N_("Cyrillic") }, { XED_ENCODING_KOI8_U, "KOI8U", N_("Cyrillic/Ukrainian") }, - + { XED_ENCODING_SHIFT_JIS, "SHIFT_JIS", N_("Japanese") }, { XED_ENCODING_TCVN, @@ -312,12 +312,12 @@ xed_encoding_get_from_charset (const gchar *charset) if (g_ascii_strcasecmp (charset, "UTF-8") == 0) return xed_encoding_get_utf8 (); - i = 0; + i = 0; while (i < XED_ENCODING_LAST) { if (g_ascii_strcasecmp (charset, encodings[i].charset) == 0) return &encodings[i]; - + ++i; } @@ -364,17 +364,17 @@ xed_encoding_get_current (void) if (initialized != FALSE) return locale_encoding; - if (g_get_charset (&locale_charset) == FALSE) + if (g_get_charset (&locale_charset) == FALSE) { g_return_val_if_fail (locale_charset != NULL, &utf8_encoding); - + locale_encoding = xed_encoding_get_from_charset (locale_charset); } else { locale_encoding = &utf8_encoding; } - + if (locale_encoding == NULL) { locale_encoding = &unknown_encoding; @@ -391,7 +391,7 @@ gchar * xed_encoding_to_string (const XedEncoding* enc) { g_return_val_if_fail (enc != NULL, NULL); - + xed_encoding_lazy_init (); g_return_val_if_fail (enc->charset != NULL, NULL); @@ -443,7 +443,7 @@ xed_encoding_copy (const XedEncoding *enc) return (XedEncoding *) enc; } -void +void xed_encoding_free (XedEncoding *enc) { g_return_if_fail (enc != NULL); @@ -451,13 +451,13 @@ xed_encoding_free (XedEncoding *enc) /** * xed_encoding_get_type: - * + * * Retrieves the GType object which is associated with the * #XedEncoding class. - * + * * Return value: the GType associated with #XedEncoding. **/ -GType +GType xed_encoding_get_type (void) { static GType our_type = 0; @@ -469,5 +469,77 @@ xed_encoding_get_type (void) (GBoxedFreeFunc) xed_encoding_free); 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 * +_xed_encoding_strv_to_list (const gchar * const *enc_str) +{ + GSList *res = NULL; + gchar **p; + const XedEncoding *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 = xed_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 ** +_xed_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 XedEncoding *enc; + const gchar *charset; + + enc = (const XedEncoding *)l->data; + + charset = xed_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/xed/xed-encodings.h b/xed/xed-encodings.h index eb890eb..0ba2bd0 100644 --- a/xed/xed-encodings.h +++ b/xed/xed-encodings.h @@ -2,7 +2,7 @@ * xed-encodings.h * This file is part of xed * - * Copyright (C) 2002-2005 Paolo Maggi + * 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 @@ -16,14 +16,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -57,6 +57,9 @@ const XedEncoding *xed_encoding_get_current (void); XedEncoding *xed_encoding_copy (const XedEncoding *enc); void xed_encoding_free (XedEncoding *enc); +GSList *_xed_encoding_strv_to_list (const gchar * const *enc_str); +gchar **_xed_encoding_list_to_strv (const GSList *enc); + G_END_DECLS #endif /* __XED_ENCODINGS_H__ */ diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index b87add6..909a05b 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -44,9 +44,9 @@ #include "xed-file-chooser-dialog.h" #include "xed-encodings-combo-box.h" #include "xed-language-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-debug.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define XED_FILE_CHOOSER_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogPrivate)) @@ -55,6 +55,8 @@ struct _XedFileChooserDialogPrivate { + GSettings *filter_settings; + GtkWidget *option_menu; GtkWidget *extra_widget; @@ -65,11 +67,23 @@ struct _XedFileChooserDialogPrivate G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG) +static void +xed_file_chooser_dialog_dispose (GObject *object) +{ + XedFileChooserDialog *dialog = XED_FILE_CHOOSER_DIALOG (object); + + g_clear_object (&dialog->priv->filter_settings); + + G_OBJECT_CLASS (xed_file_chooser_dialog_parent_class)->dispose (object); +} + static void xed_file_chooser_dialog_class_init (XedFileChooserDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_file_chooser_dialog_dispose; + g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate)); } @@ -209,11 +223,6 @@ filter_changed (XedFileChooserDialog *dialog, { GtkFileFilter *filter; - if (!xed_prefs_manager_active_file_filter_can_set ()) - { - return; - } - filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); if (filter != NULL) { @@ -230,7 +239,7 @@ filter_changed (XedFileChooserDialog *dialog, xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); - xed_prefs_manager_set_active_file_filter (id); + g_settings_set_int (dialog->priv->filter_settings, XED_SETTINGS_ACTIVE_FILE_FILTER, id); } } @@ -323,6 +332,8 @@ static void xed_file_chooser_dialog_init (XedFileChooserDialog *dialog) { dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); + + dialog->priv->filter_settings = g_settings_new ("org.x.editor.state.file-filter"); } static GtkWidget * @@ -359,7 +370,8 @@ xed_file_chooser_dialog_new_valist (const gchar *title, XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding); } - active_filter = xed_prefs_manager_get_active_file_filter (); + active_filter = g_settings_get_int (XED_FILE_CHOOSER_DIALOG (result)->priv->filter_settings, + XED_SETTINGS_ACTIVE_FILE_FILTER); xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); /* Filters */ diff --git a/xed/xed-history-entry.c b/xed/xed-history-entry.c index 2e23d9b..d0d2605 100644 --- a/xed/xed-history-entry.c +++ b/xed/xed-history-entry.c @@ -16,14 +16,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -38,12 +38,12 @@ #include #include "xed-history-entry.h" -#include "xed-prefs-manager.h" -enum { - PROP_0, - PROP_HISTORY_ID, - PROP_HISTORY_LENGTH +enum +{ + PROP_0, + PROP_HISTORY_ID, + PROP_HISTORY_LENGTH }; #define MIN_ITEM_LEN 3 @@ -51,494 +51,460 @@ enum { #define XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT 10 #define XED_HISTORY_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_HISTORY_ENTRY, \ - XedHistoryEntryPrivate)) + XED_TYPE_HISTORY_ENTRY, \ + XedHistoryEntryPrivate)) struct _XedHistoryEntryPrivate { - gchar *history_id; - guint history_length; - - GtkEntryCompletion *completion; - - GSettings *settings; + gchar *history_id; + guint history_length; + GtkEntryCompletion *completion; + GSettings *settings; }; G_DEFINE_TYPE(XedHistoryEntry, xed_history_entry, GTK_TYPE_COMBO_BOX_TEXT) static void xed_history_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *spec) + guint prop_id, + const GValue *value, + GParamSpec *spec) { - XedHistoryEntry *entry; + XedHistoryEntry *entry; - g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); - entry = XED_HISTORY_ENTRY (object); + entry = XED_HISTORY_ENTRY (object); - switch (prop_id) { - case PROP_HISTORY_ID: - entry->priv->history_id = g_value_dup_string (value); - break; - case PROP_HISTORY_LENGTH: - xed_history_entry_set_history_length (entry, - g_value_get_uint (value)); - break; - default: - break; - } + switch (prop_id) + { + case PROP_HISTORY_ID: + entry->priv->history_id = g_value_dup_string (value); + break; + case PROP_HISTORY_LENGTH: + xed_history_entry_set_history_length (entry, g_value_get_uint (value)); + break; + default: + break; + } } static void xed_history_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *spec) + guint prop_id, + GValue *value, + GParamSpec *spec) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); - priv = XED_HISTORY_ENTRY (object)->priv; + priv = XED_HISTORY_ENTRY (object)->priv; - switch (prop_id) { - case PROP_HISTORY_ID: - g_value_set_string (value, priv->history_id); - break; - case PROP_HISTORY_LENGTH: - g_value_set_uint (value, priv->history_length); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec); - } + switch (prop_id) + { + case PROP_HISTORY_ID: + g_value_set_string (value, priv->history_id); + break; + case PROP_HISTORY_LENGTH: + g_value_set_uint (value, priv->history_length); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec); + } } static void xed_history_entry_dispose (GObject *object) { - xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (object), - FALSE); + XedHistoryEntryPrivate *priv; - G_OBJECT_CLASS (xed_history_entry_parent_class)->dispose (object); + priv = XED_HISTORY_ENTRY (object)->priv; + xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (object), FALSE); + + g_clear_object (&priv->settings); + + G_OBJECT_CLASS (xed_history_entry_parent_class)->dispose (object); } static void xed_history_entry_finalize (GObject *object) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - priv = XED_HISTORY_ENTRY (object)->priv; - - g_free (priv->history_id); + priv = XED_HISTORY_ENTRY (object)->priv; - if (priv->settings != NULL) - { - g_object_unref (G_OBJECT (priv->settings)); - priv->settings = NULL; - } + g_free (priv->history_id); - G_OBJECT_CLASS (xed_history_entry_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_history_entry_parent_class)->finalize (object); } -static void +static void xed_history_entry_class_init (XedHistoryEntryClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = xed_history_entry_set_property; - object_class->get_property = xed_history_entry_get_property; - object_class->finalize = xed_history_entry_finalize; - object_class->dispose = xed_history_entry_dispose; - - g_object_class_install_property (object_class, - PROP_HISTORY_ID, - g_param_spec_string ("history-id", - "History ID", - "History ID", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_object_class_install_property (object_class, - PROP_HISTORY_LENGTH, - g_param_spec_uint ("history-length", - "Max History Length", - "Max History Length", - 0, - G_MAXUINT, - XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + object_class->set_property = xed_history_entry_set_property; + object_class->get_property = xed_history_entry_get_property; + object_class->finalize = xed_history_entry_finalize; + object_class->dispose = xed_history_entry_dispose; - /* TODO: Add enable-completion property */ + g_object_class_install_property (object_class, + PROP_HISTORY_ID, + g_param_spec_string ("history-id", + "History ID", + "History ID", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof(XedHistoryEntryPrivate)); + g_object_class_install_property (object_class, + PROP_HISTORY_LENGTH, + g_param_spec_uint ("history-length", + "Max History Length", + "Max History Length", + 0, + G_MAXUINT, + XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + /* TODO: Add enable-completion property */ + + g_type_class_add_private (object_class, sizeof(XedHistoryEntryPrivate)); } static GtkListStore * get_history_store (XedHistoryEntry *entry) { - GtkTreeModel *store; + GtkTreeModel *store; - store = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); - g_return_val_if_fail (GTK_IS_LIST_STORE (store), NULL); + store = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); + g_return_val_if_fail (GTK_IS_LIST_STORE (store), NULL); - return (GtkListStore *) store; + return (GtkListStore *) store; } -static GSList * -get_history_list (XedHistoryEntry *entry) +static gchar ** +get_history_items (XedHistoryEntry *entry) { - GtkListStore *store; - GtkTreeIter iter; - gboolean valid; - GSList *list = NULL; + GtkListStore *store; + GtkTreeIter iter; + GPtrArray *array; + gboolean valid; + gint n_children; + gint text_column; - store = get_history_store (entry); + store = get_history_store (entry); + text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (entry)); + valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + n_children = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL); + array = g_ptr_array_sized_new (n_children + 1); - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), - &iter); + while (valid) + { + gchar *str; - while (valid) - { - gchar *str; + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, text_column, &str, -1); - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, - 0, &str, - -1); + g_ptr_array_add (array, str); + valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); + } - list = g_slist_prepend (list, str); + g_ptr_array_add (array, NULL); - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), - &iter); - } - - return g_slist_reverse (list); + return (gchar **)g_ptr_array_free (array, FALSE); } static void xed_history_entry_save_history (XedHistoryEntry *entry) { - GSList *settings_items; + gchar **items; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - settings_items = get_history_list (entry); + items = get_history_items (entry); - xed_prefs_manager_set_gslist (entry->priv->settings, - entry->priv->history_id, - settings_items); + g_settings_set_strv (entry->priv->settings, entry->priv->history_id, (const gchar * const *)items); - g_slist_foreach (settings_items, (GFunc) g_free, NULL); - g_slist_free (settings_items); + g_strfreev (items); } static gboolean -remove_item (GtkListStore *store, - const gchar *text) +remove_item (XedHistoryEntry *entry, + const gchar *text) { - GtkTreeIter iter; + GtkListStore *store; + GtkTreeIter iter; + gint text_column; - g_return_val_if_fail (text != NULL, FALSE); + g_return_val_if_fail (text != NULL, FALSE); - if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) - return FALSE; + store = get_history_store (entry); + text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (entry)); - do - { - gchar *item_text; + if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) + { + return FALSE; + } - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, - 0, - &item_text, - -1); + do + { + gchar *item_text; - if (item_text != NULL && - strcmp (item_text, text) == 0) - { - gtk_list_store_remove (store, &iter); - g_free (item_text); - return TRUE; - } + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, text_column, &item_text, -1); - g_free (item_text); + if (item_text != NULL && strcmp (item_text, text) == 0) + { + gtk_list_store_remove (store, &iter); + g_free (item_text); + return TRUE; + } - } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); + g_free (item_text); - return FALSE; + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); + + return FALSE; } static void clamp_list_store (GtkListStore *store, - guint max) + guint max) { - GtkTreePath *path; - GtkTreeIter iter; + GtkTreePath *path; + GtkTreeIter iter; - /* -1 because TreePath counts from 0 */ - path = gtk_tree_path_new_from_indices (max - 1, -1); + /* -1 because TreePath counts from 0 */ + path = gtk_tree_path_new_from_indices (max - 1, -1); - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) - { - while (1) - { - if (!gtk_list_store_remove (store, &iter)) - break; - } - } + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) + { + while (1) + { + if (!gtk_list_store_remove (store, &iter)) + { + break; + } + } + } - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static void insert_history_item (XedHistoryEntry *entry, - const gchar *text, - gboolean prepend) + const gchar *text, + gboolean prepend) { - GtkListStore *store; - GtkTreeIter iter; + GtkListStore *store; - if (g_utf8_strlen (text, -1) <= MIN_ITEM_LEN) - return; - - store = get_history_store (entry); + if (g_utf8_strlen (text, -1) <= MIN_ITEM_LEN) + { + return; + } - /* remove the text from the store if it was already - * present. If it wasn't, clamp to max history - 1 - * before inserting the new row, otherwise appending - * would not work */ + store = get_history_store (entry); - if (!remove_item (store, text)) - clamp_list_store (store, - entry->priv->history_length - 1); + /* remove the text from the store if it was already + * present. If it wasn't, clamp to max history - 1 + * before inserting the new row, otherwise appending + * would not work */ - if (prepend) - gtk_list_store_insert (store, &iter, 0); - else - gtk_list_store_append (store, &iter); + if (!remove_item (entry, text)) + { + clamp_list_store (store, entry->priv->history_length - 1); + } - gtk_list_store_set (store, - &iter, - 0, - text, - -1); + if (prepend) + { + gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (entry), text); + } + else + { + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (entry), text); + } - xed_history_entry_save_history (entry); + xed_history_entry_save_history (entry); } void xed_history_entry_prepend_text (XedHistoryEntry *entry, - const gchar *text) + const gchar *text) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (text != NULL); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (text != NULL); - insert_history_item (entry, text, TRUE); + insert_history_item (entry, text, TRUE); } void xed_history_entry_append_text (XedHistoryEntry *entry, - const gchar *text) + const gchar *text) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (text != NULL); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (text != NULL); - insert_history_item (entry, text, FALSE); + insert_history_item (entry, text, FALSE); } static void xed_history_entry_load_history (XedHistoryEntry *entry) { - GSList *settings_items, *l; - GtkListStore *store; - GtkTreeIter iter; - guint i; + gchar **items; + gsize i; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - store = get_history_store (entry); + items = g_settings_get_strv (entry->priv->settings, entry->priv->history_id); + i = 0; - settings_items = xed_prefs_manager_get_gslist (entry->priv->settings, - entry->priv->history_id); + gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (entry)); - gtk_list_store_clear (store); + /* Now the default value is an empty string so we have to take care of it to not + add the empty string in the search list */ + while (items[i] != NULL && *items[i] != '\0' && i < entry->priv->history_length) + { + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (entry), items[i]); + i++; + } - for (l = settings_items, i = 0; - l != NULL && i < entry->priv->history_length; - l = l->next, i++) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, - &iter, - 0, - l->data, - -1); - } - - g_slist_foreach (settings_items, (GFunc) g_free, NULL); - g_slist_free (settings_items); + g_strfreev (items); } void xed_history_entry_clear (XedHistoryEntry *entry) { - GtkListStore *store; + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (entry)); - store = get_history_store (entry); - gtk_list_store_clear (store); - - xed_history_entry_save_history (entry); + xed_history_entry_save_history (entry); } static void xed_history_entry_init (XedHistoryEntry *entry) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - priv = XED_HISTORY_ENTRY_GET_PRIVATE (entry); - entry->priv = priv; + priv = XED_HISTORY_ENTRY_GET_PRIVATE (entry); + entry->priv = priv; - priv->history_id = NULL; - priv->history_length = XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT; + priv->history_id = NULL; + priv->history_length = XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT; - priv->completion = NULL; + priv->completion = NULL; - priv->settings = g_settings_new (XED_SCHEMA); + priv->settings = g_settings_new ("org.x.editor.state.history-entry"); } void xed_history_entry_set_history_length (XedHistoryEntry *entry, - guint history_length) + guint history_length) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (history_length > 0); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (history_length > 0); - entry->priv->history_length = history_length; + entry->priv->history_length = history_length; - /* TODO: update if we currently have more items than max */ + /* TODO: update if we currently have more items than max */ } guint xed_history_entry_get_history_length (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), 0); + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), 0); - return entry->priv->history_length; -} - -gchar * -xed_history_entry_get_history_id (XedHistoryEntry *entry) -{ - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); - - return g_strdup (entry->priv->history_id); + return entry->priv->history_length; } void xed_history_entry_set_enable_completion (XedHistoryEntry *entry, - gboolean enable) + gboolean enable) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - - if (enable) - { - if (entry->priv->completion != NULL) - return; - - entry->priv->completion = gtk_entry_completion_new (); - gtk_entry_completion_set_model (entry->priv->completion, - GTK_TREE_MODEL (get_history_store (entry))); - - /* Use model column 0 as the text column */ - gtk_entry_completion_set_text_column (entry->priv->completion, 0); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - gtk_entry_completion_set_minimum_key_length (entry->priv->completion, - MIN_ITEM_LEN); + if (enable) + { + if (entry->priv->completion != NULL) + { + return; + } - gtk_entry_completion_set_popup_completion (entry->priv->completion, FALSE); - gtk_entry_completion_set_inline_completion (entry->priv->completion, TRUE); - - /* Assign the completion to the entry */ - gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry(entry)), - entry->priv->completion); - } - else - { - if (entry->priv->completion == NULL) - return; + entry->priv->completion = gtk_entry_completion_new (); + gtk_entry_completion_set_model (entry->priv->completion, GTK_TREE_MODEL (get_history_store (entry))); - gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry (entry)), - NULL); - - g_object_unref (entry->priv->completion); - - entry->priv->completion = NULL; - } + /* Use model column 0 as the text column */ + gtk_entry_completion_set_text_column (entry->priv->completion, 0); + + gtk_entry_completion_set_minimum_key_length (entry->priv->completion, MIN_ITEM_LEN); + + gtk_entry_completion_set_popup_completion (entry->priv->completion, FALSE); + gtk_entry_completion_set_inline_completion (entry->priv->completion, TRUE); + + /* Assign the completion to the entry */ + gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry(entry)), entry->priv->completion); + } + else + { + if (entry->priv->completion == NULL) + { + return; + } + + gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry (entry)), NULL); + + g_object_unref (entry->priv->completion); + + entry->priv->completion = NULL; + } } - + gboolean xed_history_entry_get_enable_completion (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), FALSE); - - return entry->priv->completion != NULL; + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), FALSE); + + return entry->priv->completion != NULL; } GtkWidget * xed_history_entry_new (const gchar *history_id, - gboolean enable_completion) + gboolean enable_completion) { - GtkWidget *ret; - GtkListStore *store; + GtkWidget *ret; - g_return_val_if_fail (history_id != NULL, NULL); + g_return_val_if_fail (history_id != NULL, NULL); - /* Note that we are setting the model, so - * user must be careful to always manipulate - * data in the history through xed_history_entry_ - * functions. - */ + ret = g_object_new (XED_TYPE_HISTORY_ENTRY, + "has-entry", TRUE, + "entry-text-column", 0, + "id-column", 1, + "history-id", history_id, + NULL); - store = gtk_list_store_new (1, G_TYPE_STRING); + /* loading has to happen after the model + * has been set. However the model is not a + * G_PARAM_CONSTRUCT property of GtkComboBox + * so we cannot do this in the constructor. + * For now we simply do here since this widget is + * not bound to other programming languages. + * A maybe better alternative is to override the + * model property of combobox and mark CONTRUCT_ONLY. + * This would also ensure that the model cannot be + * set explicitely at a later time. + */ + xed_history_entry_load_history (XED_HISTORY_ENTRY (ret)); - ret = g_object_new (XED_TYPE_HISTORY_ENTRY, - "history-id", history_id, - "model", store, - "has-entry", TRUE, - "entry-text-column", 0, - NULL); + xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (ret), enable_completion); - g_object_unref (store); - - /* loading has to happen after the model - * has been set. However the model is not a - * G_PARAM_CONSTRUCT property of GtkComboBox - * so we cannot do this in the constructor. - * For now we simply do here since this widget is - * not bound to other programming languages. - * A maybe better alternative is to override the - * model property of combobox and mark CONTRUCT_ONLY. - * This would also ensure that the model cannot be - * set explicitely at a later time. - */ - xed_history_entry_load_history (XED_HISTORY_ENTRY (ret)); - - xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (ret), - enable_completion); - - return ret; + return ret; } /* * Utility function to get the editable text entry internal widget. - * I would prefer to not expose this implementation detail and - * simply make the XedHistoryEntry widget implement the + * I would prefer to not expose this implementation detail and + * simply make the XedHistoryEntry widget implement the * GtkEditable interface. Unfortunately both GtkEditable and * GtkComboBox have a "changed" signal and I am not sure how to * handle the conflict. @@ -546,54 +512,58 @@ xed_history_entry_new (const gchar *history_id, GtkWidget * xed_history_entry_get_entry (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); - return gtk_bin_get_child (GTK_BIN (entry)); + return gtk_bin_get_child (GTK_BIN (entry)); } static void escape_cell_data_func (GtkTreeViewColumn *col, - GtkCellRenderer *renderer, - GtkTreeModel *model, - GtkTreeIter *iter, - XedHistoryEntryEscapeFunc escape_func) + GtkCellRenderer *renderer, + GtkTreeModel *model, + GtkTreeIter *iter, + XedHistoryEntryEscapeFunc escape_func) { - gchar *str; - gchar *escaped; + gchar *str; + gchar *escaped; - gtk_tree_model_get (model, iter, 0, &str, -1); - escaped = escape_func (str); - g_object_set (renderer, "text", escaped, NULL); + gtk_tree_model_get (model, iter, 0, &str, -1); + escaped = escape_func (str); + g_object_set (renderer, "text", escaped, NULL); - g_free (str); - g_free (escaped); + g_free (str); + g_free (escaped); } void xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func) + XedHistoryEntryEscapeFunc escape_func) { - GList *cells; + GList *cells; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry)); + cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry)); - /* We only have one cell renderer */ - g_return_if_fail (cells->data != NULL && cells->next == NULL); + /* We only have one cell renderer */ + g_return_if_fail (cells->data != NULL && cells->next == NULL); - if (escape_func != NULL) - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - (GtkCellLayoutDataFunc) escape_cell_data_func, - escape_func, - NULL); - else - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - NULL, - NULL, - NULL); + if (escape_func != NULL) + { + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), + GTK_CELL_RENDERER (cells->data), + (GtkCellLayoutDataFunc) escape_cell_data_func, + escape_func, + NULL); + } + else + { + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), + GTK_CELL_RENDERER (cells->data), + NULL, + NULL, + NULL); + } - g_list_free (cells); + g_list_free (cells); } diff --git a/xed/xed-history-entry.h b/xed/xed-history-entry.h index 0fa844c..ef7447f 100644 --- a/xed/xed-history-entry.h +++ b/xed/xed-history-entry.h @@ -16,14 +16,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -48,48 +48,41 @@ typedef struct _XedHistoryEntryPrivate XedHistoryEntryPrivate; struct _XedHistoryEntryClass { - GtkComboBoxTextClass parent_class; + GtkComboBoxTextClass parent_class; }; struct _XedHistoryEntry { - GtkComboBoxText parent_instance; + GtkComboBoxText parent_instance; - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; }; -GType xed_history_entry_get_type (void) G_GNUC_CONST; +GType xed_history_entry_get_type (void) G_GNUC_CONST; -GtkWidget *xed_history_entry_new (const gchar *history_id, - gboolean enable_completion); +GtkWidget *xed_history_entry_new (const gchar *history_id, + gboolean enable_completion); -void xed_history_entry_prepend_text (XedHistoryEntry *entry, - const gchar *text); +void xed_history_entry_prepend_text (XedHistoryEntry *entry, + const gchar *text); +void xed_history_entry_append_text (XedHistoryEntry *entry, + const gchar *text); -void xed_history_entry_append_text (XedHistoryEntry *entry, - const gchar *text); +void xed_history_entry_clear (XedHistoryEntry *entry); -void xed_history_entry_clear (XedHistoryEntry *entry); +void xed_history_entry_set_history_length (XedHistoryEntry *entry, + guint max_saved); +guint xed_history_entry_get_history_length (XedHistoryEntry *gentry); -void xed_history_entry_set_history_length (XedHistoryEntry *entry, - guint max_saved); +void xed_history_entry_set_enable_completion (XedHistoryEntry *entry, + gboolean enable); +gboolean xed_history_entry_get_enable_completion (XedHistoryEntry *entry); -guint xed_history_entry_get_history_length (XedHistoryEntry *gentry); - -gchar *xed_history_entry_get_history_id (XedHistoryEntry *entry); - -void xed_history_entry_set_enable_completion - (XedHistoryEntry *entry, - gboolean enable); - -gboolean xed_history_entry_get_enable_completion - (XedHistoryEntry *entry); - -GtkWidget *xed_history_entry_get_entry (XedHistoryEntry *entry); +GtkWidget *xed_history_entry_get_entry (XedHistoryEntry *entry); typedef gchar * (* XedHistoryEntryEscapeFunc) (const gchar *str); -void xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func); +void xed_history_entry_set_escape_func (XedHistoryEntry *entry, + XedHistoryEntryEscapeFunc escape_func); G_END_DECLS diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index c4a2fae..0362f0f 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -42,10 +42,10 @@ #include #include +#include "xed-settings.h" #include "xed-utils.h" #include "xed-document.h" #include "xed-io-error-message-area.h" -#include "xed-prefs-manager.h" #include #define MAX_URI_IN_DIALOG_LENGTH 50 @@ -856,6 +856,8 @@ xed_no_backup_saving_error_message_area_new (GFile *location, 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 (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); @@ -893,9 +895,12 @@ xed_no_backup_saving_error_message_area_new (GFile *location, 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 ("org.x.editor.preferences.editor"); + create_backup_copy = g_settings_get_boolean (editor_settings, XED_SETTINGS_CREATE_BACKUP_COPY); + g_object_unref (editor_settings); - if (xed_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); } diff --git a/xed/xed-language-manager.c b/xed/xed-language-manager.c index 0871708..6ae2e44 100644 --- a/xed/xed-language-manager.c +++ b/xed/xed-language-manager.c @@ -3,7 +3,7 @@ * xed-languages-manager.c * This file is part of xed * - * Copyright (C) 2003-2006 - Paolo Maggi + * Copyright (C) 2003-2006 - 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 @@ -17,14 +17,14 @@ * * 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, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2003-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2003-2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -33,7 +33,6 @@ #include #include #include "xed-language-manager.h" -#include "xed-prefs-manager.h" #include "xed-utils.h" #include "xed-debug.h" diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index 0b21bc0..b0ee7c1 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -56,15 +56,16 @@ struct _XedNotebookPrivate { - GList *focused_pages; - gulong motion_notify_handler_id; - gint x_start; - gint y_start; - gint drag_in_progress : 1; - gint close_buttons_sensitive : 1; - gint tab_drag_and_drop_enabled : 1; - gint tab_scrolling_enabled : 1; - guint destroy_has_run : 1; + GSettings *ui_settings; + GList *focused_pages; + gulong motion_notify_handler_id; + gint x_start; + gint y_start; + gint drag_in_progress : 1; + gint close_buttons_sensitive : 1; + gint tab_drag_and_drop_enabled : 1; + gint tab_scrolling_enabled : 1; + guint destroy_has_run : 1; }; G_DEFINE_TYPE(XedNotebook, xed_notebook, GTK_TYPE_NOTEBOOK) @@ -115,6 +116,8 @@ xed_notebook_dispose (GObject *object) notebook->priv->destroy_has_run = TRUE; } + g_clear_object (¬ebook->priv->ui_settings); + G_OBJECT_CLASS (xed_notebook_parent_class)->dispose (object); } @@ -707,7 +710,8 @@ xed_notebook_init (XedNotebook *notebook) notebook->priv->close_buttons_sensitive = TRUE; notebook->priv->tab_drag_and_drop_enabled = TRUE; - notebook->priv->tab_scrolling_enabled = TRUE; + notebook->priv->ui_settings = g_settings_new ("org.x.editor.preferences.ui"); + notebook->priv->tab_scrolling_enabled = g_settings_get_boolean (notebook->priv->ui_settings, "enable-tab-scrolling"); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); // gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); diff --git a/xed/xed-plugins-engine.c b/xed/xed-plugins-engine.c index d0a6caf..6b96972 100644 --- a/xed/xed-plugins-engine.c +++ b/xed/xed-plugins-engine.c @@ -40,8 +40,9 @@ #include "xed-plugins-engine.h" #include "xed-debug.h" #include "xed-app.h" -#include "xed-prefs-manager.h" #include "xed-dirs.h" +#include "xed-settings.h" +#include "xed-utils.h" G_DEFINE_TYPE (XedPluginsEngine, xed_plugins_engine, PEAS_TYPE_ENGINE) @@ -62,7 +63,7 @@ xed_plugins_engine_init (XedPluginsEngine *engine) engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, XED_TYPE_PLUGINS_ENGINE, XedPluginsEnginePrivate); - engine->priv->plugin_settings = g_settings_new (XED_SCHEMA); + engine->priv->plugin_settings = g_settings_new ("org.x.editor.plugins"); peas_engine_enable_loader (PEAS_ENGINE (engine), "python3"); @@ -111,8 +112,11 @@ xed_plugins_engine_init (XedPluginsEngine *engine) xed_dirs_get_xed_plugins_dir(), xed_dirs_get_xed_plugins_data_dir()); - g_settings_bind (engine->priv->plugin_settings, GPM_ACTIVE_PLUGINS, - engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (engine->priv->plugin_settings, + XED_SETTINGS_ACTIVE_PLUGINS, + engine, + "loaded-plugins", + G_SETTINGS_BIND_DEFAULT); } static void diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c deleted file mode 100644 index 741b2c1..0000000 --- a/xed/xed-prefs-manager-app.c +++ /dev/null @@ -1,1345 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.c - * This file is part of xed - * - * 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 xed Team, 2002-2003. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-private.h" -#include "xed-prefs-manager-app.h" -#include "xed-app.h" -#include "xed-debug.h" -#include "xed-view.h" -#include "xed-window.h" -#include "xed-notebook.h" -#include "xed-window-private.h" -#include "xed-plugins-engine.h" -#include "xed-style-scheme-manager.h" -#include "xed-dirs.h" - -static void xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -/* GUI state is serialized to a .desktop file, not in GSettings */ - -#define XED_STATE_DEFAULT_WINDOW_STATE 0 -#define XED_STATE_DEFAULT_WINDOW_WIDTH 650 -#define XED_STATE_DEFAULT_WINDOW_HEIGHT 500 -#define XED_STATE_DEFAULT_SIDE_PANEL_SIZE 200 -#define XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140 - -#define XED_STATE_FILE_LOCATION "xed.ini" - -#define XED_STATE_WINDOW_GROUP "window" -#define XED_STATE_WINDOW_STATE "state" -#define XED_STATE_WINDOW_HEIGHT "height" -#define XED_STATE_WINDOW_WIDTH "width" -#define XED_STATE_SIDE_PANEL_SIZE "side_panel_size" -#define XED_STATE_BOTTOM_PANEL_SIZE "bottom_panel_size" -#define XED_STATE_SIDE_PANEL_ACTIVE_PAGE "side_panel_active_page" -#define XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE "bottom_panel_active_page" - -#define XED_STATE_FILEFILTER_GROUP "filefilter" -#define XED_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 = xed_dirs_get_user_config_dir (); - - if (config_dir != NULL) - { - filename = g_build_filename (config_dir, XED_STATE_FILE_LOCATION, NULL); - g_free (config_dir); - } - - return filename; -} - -static GKeyFile * -get_xed_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 xed state file: %s\n", err->message); - } - - g_error_free (err); - } - - g_free (filename); - } - - return state_file; -} - -static void -xed_state_get_int (const gchar *group, - const gchar *key, - gint defval, - gint *result) -{ - GKeyFile *state_file; - gint res; - GError *err = NULL; - - state_file = get_xed_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 -xed_state_set_int (const gchar *group, - const gchar *key, - gint value) -{ - GKeyFile *state_file; - - state_file = get_xed_state_file (); - g_key_file_set_integer (state_file, group, key, value); -} - -static gboolean -xed_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_xed_state_file (); - g_return_val_if_fail (state_file != NULL, FALSE); - - config_dir = xed_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 xed 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 -xed_prefs_manager_get_window_state (void) -{ - if (window_state == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_STATE, - XED_STATE_DEFAULT_WINDOW_STATE, - &window_state); - } - - return window_state; -} - -void -xed_prefs_manager_set_window_state (gint ws) -{ - g_return_if_fail (ws > -1); - - window_state = ws; - - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_STATE, ws); -} - -gboolean -xed_prefs_manager_window_state_can_set (void) -{ - return TRUE; -} - -/* Window size */ -void -xed_prefs_manager_get_window_size (gint *width, - gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - if (window_width == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_WIDTH, - XED_STATE_DEFAULT_WINDOW_WIDTH, - &window_width); - } - - if (window_height == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_HEIGHT, - XED_STATE_DEFAULT_WINDOW_HEIGHT, - &window_height); - } - - *width = window_width; - *height = window_height; -} - -void -xed_prefs_manager_get_default_window_size (gint *width, - gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - *width = XED_STATE_DEFAULT_WINDOW_WIDTH; - *height = XED_STATE_DEFAULT_WINDOW_HEIGHT; -} - -void -xed_prefs_manager_set_window_size (gint width, - gint height) -{ - g_return_if_fail (width > -1 && height > -1); - - window_width = width; - window_height = height; - - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_WIDTH, width); - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_HEIGHT, height); -} - -gboolean -xed_prefs_manager_window_size_can_set (void) -{ - return TRUE; -} - -/* Side panel */ -gint -xed_prefs_manager_get_side_panel_size (void) -{ - if (side_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_SIZE, - XED_STATE_DEFAULT_SIDE_PANEL_SIZE, - &side_panel_size); - } - - return side_panel_size; -} - -gint -xed_prefs_manager_get_default_side_panel_size (void) -{ - return XED_STATE_DEFAULT_SIDE_PANEL_SIZE; -} - -void -xed_prefs_manager_set_side_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (side_panel_size == ps) - { - return; - } - - side_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_SIZE, ps); -} - -gboolean -xed_prefs_manager_side_panel_size_can_set (void) -{ - return TRUE; -} - -gint -xed_prefs_manager_get_side_panel_active_page (void) -{ - if (side_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_ACTIVE_PAGE, - 0, - &side_panel_active_page); - } - - return side_panel_active_page; -} - -void -xed_prefs_manager_set_side_panel_active_page (gint id) -{ - if (side_panel_active_page == id) - { - return; - } - - side_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_ACTIVE_PAGE, id); -} - -gboolean -xed_prefs_manager_side_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* Bottom panel */ -gint -xed_prefs_manager_get_bottom_panel_size (void) -{ - if (bottom_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_SIZE, - XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE, - &bottom_panel_size); - } - - return bottom_panel_size; -} - -gint -xed_prefs_manager_get_default_bottom_panel_size (void) -{ - return XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE; -} - -void -xed_prefs_manager_set_bottom_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (bottom_panel_size == ps) - { - return; - } - - bottom_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_SIZE, ps); -} - -gboolean -xed_prefs_manager_bottom_panel_size_can_set (void) -{ - return TRUE; -} - -gint -xed_prefs_manager_get_bottom_panel_active_page (void) -{ - if (bottom_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - 0, - &bottom_panel_active_page); - } - - return bottom_panel_active_page; -} - -void -xed_prefs_manager_set_bottom_panel_active_page (gint id) -{ - if (bottom_panel_active_page == id) - { - return; - } - - bottom_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, id); -} - -gboolean -xed_prefs_manager_bottom_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* File filter */ -gint -xed_prefs_manager_get_active_file_filter (void) -{ - if (active_file_filter == -1) - { - xed_state_get_int (XED_STATE_FILEFILTER_GROUP, - XED_STATE_FILEFILTER_ID, - 0, - &active_file_filter); - } - - return active_file_filter; -} - -void -xed_prefs_manager_set_active_file_filter (gint id) -{ - g_return_if_fail (id >= 0); - - if (active_file_filter == id) - { - return; - } - - active_file_filter = id; - xed_state_set_int (XED_STATE_FILEFILTER_GROUP, XED_STATE_FILEFILTER_ID, id); -} - -gboolean -xed_prefs_manager_active_file_filter_can_set (void) -{ - return TRUE; -} - -/* Normal prefs are stored in GSettings */ - -gboolean -xed_prefs_manager_app_init (void) -{ - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager == NULL, FALSE); - - xed_prefs_manager_init (); - - if (xed_prefs_manager != NULL) - { - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_USE_DEFAULT_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_EDITOR_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->interface_settings, "changed::" GPM_SYSTEM_FONT, - G_CALLBACK (xed_prefs_manager_system_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_TABS_SIZE, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_INSERT_SPACES, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRAP_MODE, - G_CALLBACK (xed_prefs_manager_wrap_mode_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_LINE_NUMBERS, - G_CALLBACK (xed_prefs_manager_line_numbers_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_INDENT, - G_CALLBACK (xed_prefs_manager_auto_indent_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_UNDO_ACTIONS_LIMIT, - G_CALLBACK (xed_prefs_manager_undo_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_RIGHT_MARGIN, - G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_RIGHT_MARGIN_POSITION, - G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SMART_HOME_END, - G_CALLBACK (xed_prefs_manager_smart_home_end_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_ENABLE_TAB_SCROLLING, - G_CALLBACK (xed_prefs_manager_enable_tab_scrolling_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_HIGHLIGHT_CURRENT_LINE, - G_CALLBACK (xed_prefs_manager_hl_current_line_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_BRACKET_MATCHING, - G_CALLBACK (xed_prefs_manager_bracket_matching_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SYNTAX_HL_ENABLE, - G_CALLBACK (xed_prefs_manager_syntax_hl_enable_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE, - G_CALLBACK (xed_prefs_manager_search_hl_enable_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SOURCE_STYLE_SCHEME, - G_CALLBACK (xed_prefs_manager_source_style_scheme_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_MAX_RECENTS, - G_CALLBACK (xed_prefs_manager_max_recents_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_CREATE_BACKUP_COPY, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_SAVE_INTERVAL, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRITABLE_VFS_SCHEMES, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - } - - return xed_prefs_manager != NULL; -} - -/* This function must be called before exiting xed */ -void -xed_prefs_manager_app_shutdown (void) -{ - xed_debug (DEBUG_PREFS); - - xed_prefs_manager_shutdown (); - - xed_state_file_sync (); -} - - -static void -xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font = NULL; - gboolean def = TRUE; - gint ts; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) - { - def = g_settings_get_boolean (settings, key); - - if (def) - { - font = xed_prefs_manager_get_system_font (); - } - else - { - font = xed_prefs_manager_get_editor_font (); - } - } - else if (strcmp (key, GPM_EDITOR_FONT) == 0) - { - font = g_settings_get_string (settings, key); - def = xed_prefs_manager_get_use_default_font (); - } - else - { - return; - } - - g_return_if_fail (font != NULL); - - ts = xed_prefs_manager_get_tabs_size (); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_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 -xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font; - gint ts; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SYSTEM_FONT) != 0) - { - return; - } - - if (!xed_prefs_manager_get_use_default_font ()) - { - return; - } - - font = g_settings_get_string (settings, key); - - ts = xed_prefs_manager_get_tabs_size (); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_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 -xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_BRACKET_MATCHING) == 0) - { - gboolean enable; - GList *docs; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_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 -xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_INDENT) == 0) - { - gboolean enable; - GList *views; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_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 -xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_documents (xed_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 -xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_views (xed_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 -xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_ENABLE_TAB_SCROLLING) == 0) - { - gboolean enable; - const GList *windows; - - enable = g_settings_get_boolean (settings, key); - - windows = xed_app_get_windows (xed_app_get_default ()); - while (windows != NULL) - { - XedNotebook *notebook; - - notebook = XED_NOTEBOOK (_xed_window_get_notebook (windows->data)); - xed_notebook_set_tab_scrolling_enabled (notebook, enable); - - windows = g_list_next (windows); - } - } -} - -static void -xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_documents (xed_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 = xed_app_get_windows (xed_app_get_default ()); - while (windows != NULL) - { - GtkUIManager *ui; - GtkAction *a; - - ui = xed_window_get_ui_manager (XED_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 -xed_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - g_return_if_fail (XED_IS_DOCUMENT (l->data)); - - xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); - l = l->next; - } - - g_list_free (docs); - } -} - -static void -xed_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_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 (xed_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 (xed_get_style_scheme_manager (), "classic"); - - if (style == NULL) - { - g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); - return; - } - } - - docs = xed_app_get_documents (xed_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 -xed_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_MAX_RECENTS) == 0) - { - gint max; - - max = g_settings_get_int (settings, key); - - if (max < 0) - { - max = GPM_DEFAULT_MAX_RECENTS; - } - - /* FIXME: we have no way at the moment to trigger the - * update of the inline recents in the File menu */ - } -} - -static void -xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *docs; - GList *l; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_SAVE) == 0) - { - gboolean auto_save; - - auto_save = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); - - xed_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 = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); - - xed_tab_set_auto_save_interval (tab, auto_save_interval); - - l = l->next; - } - - g_list_free (docs); - } -} diff --git a/xed/xed-prefs-manager-app.h b/xed/xed-prefs-manager-app.h deleted file mode 100644 index 817dc51..0000000 --- a/xed/xed-prefs-manager-app.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * xed-prefs-manager-app.h - * This file is part of xed - * - * 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 xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - * - */ - -#ifndef __XED_PREFS_MANAGER_APP_H__ -#define __XED_PREFS_MANAGER_APP_H__ - -#include -#include - -/** LIFE CYCLE MANAGEMENT FUNCTIONS **/ - -gboolean xed_prefs_manager_app_init (void); - -/* This function must be called before exiting xed */ -void xed_prefs_manager_app_shutdown (void); - - -/* Window state */ -gint xed_prefs_manager_get_window_state (void); -void xed_prefs_manager_set_window_state (gint ws); -gboolean xed_prefs_manager_window_state_can_set (void); - -/* Window size */ -void xed_prefs_manager_get_window_size (gint *width, - gint *height); -void xed_prefs_manager_get_default_window_size (gint *width, - gint *height); -void xed_prefs_manager_set_window_size (gint width, - gint height); -gboolean xed_prefs_manager_window_size_can_set (void); - -/* Side panel */ -gint xed_prefs_manager_get_side_panel_size (void); -gint xed_prefs_manager_get_default_side_panel_size(void); -void xed_prefs_manager_set_side_panel_size (gint ps); -gboolean xed_prefs_manager_side_panel_size_can_set (void); -gint xed_prefs_manager_get_side_panel_active_page (void); -void xed_prefs_manager_set_side_panel_active_page (gint id); -gboolean xed_prefs_manager_side_panel_active_page_can_set (void); - -/* Bottom panel */ -gint xed_prefs_manager_get_bottom_panel_size (void); -gint xed_prefs_manager_get_default_bottom_panel_size(void); -void xed_prefs_manager_set_bottom_panel_size (gint ps); -gboolean xed_prefs_manager_bottom_panel_size_can_set (void); -gint xed_prefs_manager_get_bottom_panel_active_page (void); -void xed_prefs_manager_set_bottom_panel_active_page (gint id); -gboolean xed_prefs_manager_bottom_panel_active_page_can_set (void); - -/* File filter */ -gint xed_prefs_manager_get_active_file_filter (void); -void xed_prefs_manager_set_active_file_filter (gint id); -gboolean xed_prefs_manager_active_file_filter_can_set (void); - - -#endif /* __XED_PREFS_MANAGER_APP_H__ */ diff --git a/xed/xed-prefs-manager.c b/xed/xed-prefs-manager.c deleted file mode 100644 index 1834341..0000000 --- a/xed/xed-prefs-manager.c +++ /dev/null @@ -1,849 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.c - * This file is part of xed - * - * 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 xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include - -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-private.h" -#include "xed-debug.h" -#include "xed-encodings.h" -#include "xed-utils.h" - -#define DEFINE_BOOL_PREF(name, key) gboolean \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_bool (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (gboolean v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_bool (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_INT_PREF(name, key) gint \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_int (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (gint v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_int (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_STRING_PREF(name, key) gchar* \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_string (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (const gchar* v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_string (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - -XedPrefsManager *xed_prefs_manager = NULL; - - -static GtkWrapMode get_wrap_mode_from_string (const gchar* str); - -static gboolean xed_prefs_manager_get_bool (const gchar* key); - -static gint xed_prefs_manager_get_int (const gchar* key); - -static gchar *xed_prefs_manager_get_string (const gchar* key); - - -gboolean -xed_prefs_manager_init (void) -{ - xed_debug (DEBUG_PREFS); - - if (xed_prefs_manager == NULL) - { - xed_prefs_manager = g_new0 (XedPrefsManager, 1); - xed_prefs_manager->settings = g_settings_new (XED_SCHEMA); - xed_prefs_manager->interface_settings = g_settings_new (GPM_INTERFACE_SCHEMA); - } - - return xed_prefs_manager != NULL; -} - -void -xed_prefs_manager_shutdown (void) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (xed_prefs_manager != NULL); - - g_object_unref (xed_prefs_manager->settings); - xed_prefs_manager->settings = NULL; - g_object_unref (xed_prefs_manager->interface_settings); - xed_prefs_manager->interface_settings = NULL; -} - -static gboolean -xed_prefs_manager_get_bool (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_boolean (xed_prefs_manager->settings, key); -} - -static gint -xed_prefs_manager_get_int (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_int (xed_prefs_manager->settings, key); -} - -static gchar * -xed_prefs_manager_get_string (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_string (xed_prefs_manager->settings, key); -} - -static void -xed_prefs_manager_set_bool (const gchar* key, gboolean value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_boolean (xed_prefs_manager->settings, key, value); -} - -static void -xed_prefs_manager_set_int (const gchar* key, gint value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_int (xed_prefs_manager->settings, key, value); -} - -static void -xed_prefs_manager_set_string (const gchar* key, const gchar* value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (value != NULL); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_string (xed_prefs_manager->settings, key, value); -} - -static gboolean -xed_prefs_manager_key_is_writable (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, FALSE); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, FALSE); - - return g_settings_is_writable (xed_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 * -xed_prefs_manager_get_system_font (void) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_string (xed_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 -xed_prefs_manager_get_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - xed_debug (DEBUG_PREFS); - - str = xed_prefs_manager_get_string (GPM_WRAP_MODE); - - res = get_wrap_mode_from_string (str); - - g_free (str); - - return res; -} - -void -xed_prefs_manager_set_wrap_mode (GtkWrapMode wp) -{ - const gchar * str; - - xed_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"; - } - - xed_prefs_manager_set_string (GPM_WRAP_MODE, - str); -} - -gboolean -xed_prefs_manager_wrap_mode_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_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) - -/* 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) - -/* Tab scrolling */ -DEFINE_BOOL_PREF (enable_tab_scrolling, GPM_ENABLE_TAB_SCROLLING) - -/* 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 -xed_prefs_manager_get_print_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - xed_debug (DEBUG_PREFS); - - str = xed_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 -xed_prefs_manager_set_print_wrap_mode (GtkWrapMode pwp) -{ - const gchar *str; - - xed_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"; - } - - xed_prefs_manager_set_string (GPM_PRINT_WRAP_MODE, str); -} - -gboolean -xed_prefs_manager_print_wrap_mode_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_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 * -xed_prefs_manager_get_default_string_value (const gchar *key) -{ - gchar *font = NULL; - g_settings_delay (xed_prefs_manager->settings); - g_settings_reset (xed_prefs_manager->settings, key); - font = g_settings_get_string (xed_prefs_manager->settings, key); - g_settings_revert (xed_prefs_manager->settings); - return font; -} - -gchar * -xed_prefs_manager_get_default_print_font_body (void) -{ - return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_BODY); -} - -DEFINE_STRING_PREF (print_font_header, - GPM_PRINT_FONT_HEADER) - -gchar * -xed_prefs_manager_get_default_print_font_header (void) -{ - return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_HEADER); -} - -DEFINE_STRING_PREF (print_font_numbers, - GPM_PRINT_FONT_NUMBERS) - -gchar * -xed_prefs_manager_get_default_print_font_numbers (void) -{ - return xed_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 -xed_prefs_manager_get_max_recents (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_get_int (GPM_MAX_RECENTS); - -} - -/* GSettings/GSList utility functions from mate-panel */ - -GSList* -xed_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 -xed_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 * -xed_prefs_manager_get_auto_detected_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_AUTO_DETECTED_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const XedEncoding *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 = xed_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_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); - - res = g_slist_reverse (res); - } - - xed_debug_message (DEBUG_PREFS, "Done"); - - return res; -} - -GSList * -xed_prefs_manager_get_shown_in_menu_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const XedEncoding *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 = xed_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_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); - - res = g_slist_reverse (res); - } - - return res; -} - -void -xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs) -{ - GSList *list = NULL; - - g_return_if_fail (xed_prefs_manager != NULL); - g_return_if_fail (xed_prefs_manager->settings != NULL); - g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); - - while (encs != NULL) - { - const XedEncoding *enc; - const gchar *charset; - - enc = (const XedEncoding *)encs->data; - - charset = xed_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); - - xed_prefs_manager_set_gslist (xed_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS, list); - - g_slist_free (list); -} - -gboolean -xed_prefs_manager_shown_in_menu_encodings_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_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 -xed_prefs_manager_get_smart_home_end (void) -{ - gchar *str; - GtkSourceSmartHomeEndType res; - - xed_debug (DEBUG_PREFS); - - str = xed_prefs_manager_get_string (GPM_SMART_HOME_END); - - res = get_smart_home_end_from_string (str); - - g_free (str); - - return res; -} - -void -xed_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he) -{ - const gchar *str; - - xed_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"; - } - - xed_prefs_manager_set_string (GPM_WRAP_MODE, str); -} - -gboolean -xed_prefs_manager_smart_home_end_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_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 * -xed_prefs_manager_get_writable_vfs_schemes (void) -{ - GSList *strings; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_WRITABLE_VFS_SCHEMES); - - /* The 'file' scheme is writable by default. */ - strings = g_slist_prepend (strings, g_strdup ("file")); - - xed_debug_message (DEBUG_PREFS, "Done"); - - return strings; -} - -gboolean -xed_prefs_manager_get_restore_cursor_position (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_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 * -xed_prefs_manager_get_active_plugins (void) -{ - GSList *plugins; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - plugins = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_ACTIVE_PLUGINS); - - return plugins; -} - -void -xed_prefs_manager_set_active_plugins (const GSList *plugins) -{ - g_return_if_fail (xed_prefs_manager != NULL); - g_return_if_fail (xed_prefs_manager->settings != NULL); - g_return_if_fail (xed_prefs_manager_active_plugins_can_set ()); - - xed_prefs_manager_set_gslist (xed_prefs_manager->settings, GPM_ACTIVE_PLUGINS, (GSList *) plugins); -} - -gboolean -xed_prefs_manager_active_plugins_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_ACTIVE_PLUGINS); -} diff --git a/xed/xed-prefs-manager.h b/xed/xed-prefs-manager.h deleted file mode 100644 index 600ff61..0000000 --- a/xed/xed-prefs-manager.h +++ /dev/null @@ -1,321 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.h - * This file is part of xed - * - * 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 xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifndef __XED_PREFS_MANAGER_H__ -#define __XED_PREFS_MANAGER_H__ - -#include -#include -#include -#include "xed-app.h" - -#define XED_SCHEMA "org.x.editor" - -/* 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_STATUSBAR_VISIBLE "statusbar-visible" - -#define GPM_SIDE_PANE_VISIBLE "side-pane-visible" - -#define GPM_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" - -#define GPM_ENABLE_TAB_SCROLLING "enable-tab-scrolling" - -#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.gnome.desktop.interface" -#define GPM_SYSTEM_FONT "monospace-font-name" - -/* Fallback default values. Keep in sync with org.x.editor.gschema.xml */ -#define GPM_DEFAULT_AUTO_SAVE_INTERVAL 10 /* minutes */ -#define GPM_DEFAULT_MAX_RECENTS 5 - -/** LIFE CYCLE MANAGEMENT FUNCTIONS **/ - -gboolean xed_prefs_manager_init (void); - -/* This function must be called before exiting xed */ -void xed_prefs_manager_shutdown (void); - - -/** PREFS MANAGEMENT FUNCTIONS **/ - -/* Use default font */ -gboolean xed_prefs_manager_get_use_default_font (void); -void xed_prefs_manager_set_use_default_font (gboolean udf); -gboolean xed_prefs_manager_use_default_font_can_set (void); - -/* Editor font */ -gchar *xed_prefs_manager_get_editor_font (void); -void xed_prefs_manager_set_editor_font (const gchar *font); -gboolean xed_prefs_manager_editor_font_can_set (void); - -/* System font */ -gchar *xed_prefs_manager_get_system_font (void); - -/* Create backup copy */ -gboolean xed_prefs_manager_get_create_backup_copy (void); -void xed_prefs_manager_set_create_backup_copy (gboolean cbc); -gboolean xed_prefs_manager_create_backup_copy_can_set (void); - -/* Auto save */ -gboolean xed_prefs_manager_get_auto_save (void); -void xed_prefs_manager_set_auto_save (gboolean as); -gboolean xed_prefs_manager_auto_save_can_set (void); - -/* Auto save interval */ -gint xed_prefs_manager_get_auto_save_interval (void); -void xed_prefs_manager_set_auto_save_interval (gint asi); -gboolean xed_prefs_manager_auto_save_interval_can_set (void); - -/* Undo actions limit: if < 1 then no limits */ -gint xed_prefs_manager_get_undo_actions_limit (void); -void xed_prefs_manager_set_undo_actions_limit (gint ual); -gboolean xed_prefs_manager_undo_actions_limit_can_set (void); - -/* Wrap mode */ -GtkWrapMode xed_prefs_manager_get_wrap_mode (void); -void xed_prefs_manager_set_wrap_mode (GtkWrapMode wp); -gboolean xed_prefs_manager_wrap_mode_can_set (void); - -/* Tabs size */ -gint xed_prefs_manager_get_tabs_size (void); -void xed_prefs_manager_set_tabs_size (gint ts); -gboolean xed_prefs_manager_tabs_size_can_set (void); - -/* Insert spaces */ -gboolean xed_prefs_manager_get_insert_spaces (void); -void xed_prefs_manager_set_insert_spaces (gboolean ai); -gboolean xed_prefs_manager_insert_spaces_can_set (void); - -/* Auto indent */ -gboolean xed_prefs_manager_get_auto_indent (void); -void xed_prefs_manager_set_auto_indent (gboolean ai); -gboolean xed_prefs_manager_auto_indent_can_set (void); - -/* Display line numbers */ -gboolean xed_prefs_manager_get_display_line_numbers (void); -void xed_prefs_manager_set_display_line_numbers (gboolean dln); -gboolean xed_prefs_manager_display_line_numbers_can_set (void); - -/* Toolbar visible */ -gboolean xed_prefs_manager_get_toolbar_visible (void); -void xed_prefs_manager_set_toolbar_visible (gboolean tv); -gboolean xed_prefs_manager_toolbar_visible_can_set (void); - -/* Statusbar visible */ -gboolean xed_prefs_manager_get_statusbar_visible (void); -void xed_prefs_manager_set_statusbar_visible (gboolean sv); -gboolean xed_prefs_manager_statusbar_visible_can_set (void); - -/* Side pane visible */ -gboolean xed_prefs_manager_get_side_pane_visible (void); -void xed_prefs_manager_set_side_pane_visible (gboolean tv); -gboolean xed_prefs_manager_side_pane_visible_can_set (void); - -/* Bottom panel visible */ -gboolean xed_prefs_manager_get_bottom_panel_visible (void); -void xed_prefs_manager_set_bottom_panel_visible (gboolean tv); -gboolean xed_prefs_manager_bottom_panel_visible_can_set(void); - -/* Tab scrolling enabled */ -gboolean xed_prefs_manager_get_enable_tab_scrolling (void); -void xed_prefs_manager_set_enable_tab_scrolling (gboolean tv); -gboolean xed_prefs_manager_enable_tab_scrolling_can_set (void); - -/* Print syntax highlighting */ -gboolean xed_prefs_manager_get_print_syntax_hl (void); -void xed_prefs_manager_set_print_syntax_hl (gboolean ps); -gboolean xed_prefs_manager_print_syntax_hl_can_set (void); - -/* Print header */ -gboolean xed_prefs_manager_get_print_header (void); -void xed_prefs_manager_set_print_header (gboolean ph); -gboolean xed_prefs_manager_print_header_can_set (void); - -/* Wrap mode while printing */ -GtkWrapMode xed_prefs_manager_get_print_wrap_mode (void); -void xed_prefs_manager_set_print_wrap_mode (GtkWrapMode pwm); -gboolean xed_prefs_manager_print_wrap_mode_can_set (void); - -/* Print line numbers */ -gint xed_prefs_manager_get_print_line_numbers (void); -void xed_prefs_manager_set_print_line_numbers (gint pln); -gboolean xed_prefs_manager_print_line_numbers_can_set (void); - -/* Font used to print the body of documents */ -gchar *xed_prefs_manager_get_print_font_body (void); -void xed_prefs_manager_set_print_font_body (const gchar *font); -gboolean xed_prefs_manager_print_font_body_can_set (void); -gchar *xed_prefs_manager_get_default_print_font_body (void); - -/* Font used to print headers */ -gchar *xed_prefs_manager_get_print_font_header (void); -void xed_prefs_manager_set_print_font_header (const gchar *font); -gboolean xed_prefs_manager_print_font_header_can_set (void); -gchar *xed_prefs_manager_get_default_print_font_header (void); - -/* Font used to print line numbers */ -gchar *xed_prefs_manager_get_print_font_numbers (void); -void xed_prefs_manager_set_print_font_numbers (const gchar *font); -gboolean xed_prefs_manager_print_font_numbers_can_set (void); -gchar *xed_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 xed_prefs_manager_get_max_recents (void); - -/* Encodings */ -GSList *xed_prefs_manager_get_auto_detected_encodings (void); - -GSList *xed_prefs_manager_get_shown_in_menu_encodings (void); -void xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs); -gboolean xed_prefs_manager_shown_in_menu_encodings_can_set (void); - -/* Highlight current line */ -gboolean xed_prefs_manager_get_highlight_current_line (void); -void xed_prefs_manager_set_highlight_current_line (gboolean hl); -gboolean xed_prefs_manager_highlight_current_line_can_set (void); - -/* Highlight matching bracket */ -gboolean xed_prefs_manager_get_bracket_matching (void); -void xed_prefs_manager_set_bracket_matching (gboolean bm); -gboolean xed_prefs_manager_bracket_matching_can_set (void); - -/* Display right margin */ -gboolean xed_prefs_manager_get_display_right_margin (void); -void xed_prefs_manager_set_display_right_margin (gboolean drm); -gboolean xed_prefs_manager_display_right_margin_can_set (void); - -/* Right margin position */ -gint xed_prefs_manager_get_right_margin_position (void); -void xed_prefs_manager_set_right_margin_position (gint rmp); -gboolean xed_prefs_manager_right_margin_position_can_set (void); - -/* Smart home end */ -GtkSourceSmartHomeEndType - xed_prefs_manager_get_smart_home_end (void); -void xed_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he); -gboolean xed_prefs_manager_smart_home_end_can_set (void); - -/* Enable syntax highlighting */ -gboolean xed_prefs_manager_get_enable_syntax_highlighting (void); -void xed_prefs_manager_set_enable_syntax_highlighting (gboolean esh); -gboolean xed_prefs_manager_enable_syntax_highlighting_can_set (void); - -/* Writable VFS schemes */ -GSList *xed_prefs_manager_get_writable_vfs_schemes (void); - -/* Restore cursor position */ -gboolean xed_prefs_manager_get_restore_cursor_position (void); - -/* Enable search highlighting */ -gboolean xed_prefs_manager_get_enable_search_highlighting (void); -void xed_prefs_manager_set_enable_search_highlighting (gboolean esh); -gboolean xed_prefs_manager_enable_search_highlighting_can_set (void); - -/* Style scheme */ -gchar *xed_prefs_manager_get_source_style_scheme (void); -void xed_prefs_manager_set_source_style_scheme (const gchar *scheme); -gboolean xed_prefs_manager_source_style_scheme_can_set(void); - -/* Plugins */ -GSList *xed_prefs_manager_get_active_plugins (void); -void xed_prefs_manager_set_active_plugins (const GSList *plugins); -gboolean xed_prefs_manager_active_plugins_can_set (void); - -/* GSettings utilities */ -GSList* xed_prefs_manager_get_gslist (GSettings *settings, const gchar *key); -void xed_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list); - - -#endif /* __XED_PREFS_MANAGER_H__ */ - - diff --git a/xed/xed-print-job.c b/xed/xed-print-job.c index 9be4b00..5963b2b 100644 --- a/xed/xed-print-job.c +++ b/xed/xed-print-job.c @@ -3,7 +3,7 @@ * This file is part of xed * * Copyright (C) 2000-2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002-2008 Paolo Maggi + * Copyright (C) 2002-2008 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 @@ -17,14 +17,14 @@ * * 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. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id: xed-print.c 6022 2007-12-09 14:38:57Z pborelli $ */ @@ -38,11 +38,11 @@ #include "xed-print-job.h" #include "xed-debug.h" -#include "xed-prefs-manager.h" #include "xed-print-preview.h" #include "xed-marshal.h" #include "xed-utils.h" #include "xed-dirs.h" +#include "xed-settings.h" #define XED_PRINT_JOB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ @@ -51,6 +51,8 @@ struct _XedPrintJobPrivate { + GSettings *print_settings; + XedView *view; XedDocument *doc; @@ -62,7 +64,7 @@ struct _XedPrintJobPrivate GtkWidget *preview; XedPrintJobStatus status; - + gchar *status_string; gdouble progress; @@ -94,7 +96,7 @@ enum PROP_VIEW }; -enum +enum { PRINTING, SHOW_PREVIEW, @@ -113,7 +115,7 @@ set_view (XedPrintJob *job, XedView *view) job->priv->doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); } -static void +static void xed_print_job_get_property (GObject *object, guint prop_id, GValue *value, @@ -132,7 +134,7 @@ xed_print_job_get_property (GObject *object, } } -static void +static void xed_print_job_set_property (GObject *object, guint prop_id, const GValue *value, @@ -157,7 +159,7 @@ xed_print_job_finalize (GObject *object) XedPrintJob *job = XED_PRINT_JOB (object); g_free (job->priv->status_string); - + if (job->priv->compositor != NULL) g_object_unref (job->priv->compositor); @@ -167,7 +169,17 @@ xed_print_job_finalize (GObject *object) G_OBJECT_CLASS (xed_print_job_parent_class)->finalize (object); } -static void +static void +xed_print_job_dispose (GObject *object) +{ + XedPrintJob *job = XED_PRINT_JOB (object); + + g_clear_object (&job->priv->print_settings); + + G_OBJECT_CLASS (xed_print_job_parent_class)->dispose (object); +} + +static void xed_print_job_class_init (XedPrintJobClass *klass) { GObjectClass *object_class; @@ -177,6 +189,7 @@ xed_print_job_class_init (XedPrintJobClass *klass) object_class->get_property = xed_print_job_get_property; object_class->set_property = xed_print_job_set_property; object_class->finalize = xed_print_job_finalize; + object_class->dispose = xed_print_job_dispose; g_object_class_install_property (object_class, PROP_VIEW, @@ -221,7 +234,7 @@ xed_print_job_class_init (XedPrintJobClass *klass) 2, G_TYPE_UINT, G_TYPE_POINTER); - + g_type_class_add_private (object_class, sizeof (XedPrintJobPrivate)); } @@ -229,15 +242,7 @@ static void line_numbers_checkbutton_toggled (GtkToggleButton *button, XedPrintJob *job) { - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, - xed_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 @@ -246,7 +251,7 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button, { if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) { - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, FALSE); gtk_toggle_button_set_inconsistent ( GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), @@ -267,58 +272,36 @@ restore_button_clicked (GtkButton *button, XedPrintJob *job) { - if (xed_prefs_manager_print_font_body_can_set ()) - { - gchar *font; + gchar *body; + gchar *header; + gchar *numbers; - font = xed_prefs_manager_get_default_print_font_body (); + body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->body_fontbutton), - font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), body); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), header); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), numbers); - g_free (font); - } - - if (xed_prefs_manager_print_font_header_can_set ()) - { - gchar *font; - - font = xed_prefs_manager_get_default_print_font_header (); - - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->headers_fontbutton), - font); - - g_free (font); - } - - if (xed_prefs_manager_print_font_numbers_can_set ()) - { - gchar *font; - - font = xed_prefs_manager_get_default_print_font_numbers (); - - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->numbers_fontbutton), - font); - - g_free (font); - } + g_free (body); + g_free (header); + g_free (numbers); } static GObject * -create_custom_widget_cb (GtkPrintOperation *operation, +create_custom_widget_cb (GtkPrintOperation *operation, XedPrintJob *job) { 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", @@ -353,31 +336,27 @@ 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, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_header = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER); + line_numbers = g_settings_get_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS); + font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + /* Print syntax */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), - xed_prefs_manager_get_print_syntax_hl ()); - gtk_widget_set_sensitive (job->priv->syntax_checkbutton, - xed_prefs_manager_print_syntax_hl_can_set ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), syntax_hl); /* Print page headers */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), - xed_prefs_manager_get_print_header ()); - gtk_widget_set_sensitive (job->priv->page_header_checkbutton, - xed_prefs_manager_print_header_can_set ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), print_header); /* Line numbers */ - line_numbers = xed_prefs_manager_get_print_line_numbers (); - can_set = xed_prefs_manager_print_line_numbers_can_set (); - - 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); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), line_numbers > 0); 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_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), (guint) line_numbers); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, TRUE); } else { @@ -387,7 +366,7 @@ create_custom_widget_cb (GtkPrintOperation *operation, } /* Text wrapping */ - wrap_mode = xed_prefs_manager_get_print_wrap_mode (); + wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); switch (wrap_mode) { @@ -410,39 +389,17 @@ create_custom_widget_cb (GtkPrintOperation *operation, GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); } - can_set = xed_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)); + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, wrap_mode != GTK_WRAP_NONE); /* Set initial values */ - font = xed_prefs_manager_get_print_font_body (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), - font); - g_free (font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), font_body); + g_free (font_body); - font = xed_prefs_manager_get_print_font_header (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), - font); - g_free (font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), font_header); + g_free (font_header); - font = xed_prefs_manager_get_print_font_numbers (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), - font); - g_free (font); - - can_set = xed_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 = xed_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 = xed_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); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), font_numbers); + g_free (font_numbers); g_signal_connect (job->priv->line_numbers_checkbutton, "toggled", @@ -469,39 +426,49 @@ custom_widget_apply_cb (GtkPrintOperation *operation, GtkWidget *widget, XedPrintJob *job) { - xed_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; + GtkWrapMode wrap_mode; - xed_prefs_manager_set_print_header (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton))); + 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_button_get_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton)); + header = gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton)); + numbers = gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton)); + + g_settings_set_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING, syntax); + g_settings_set_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER, page_header); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO, body); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO, header); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO, numbers); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton))) { - xed_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, XED_SETTINGS_PRINT_LINE_NUMBERS, + MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); } else { - xed_prefs_manager_set_print_line_numbers (0); + g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, 0); } if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_NONE); + wrap_mode = GTK_WRAP_NONE; } else { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton))) { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_WORD); + wrap_mode = GTK_WRAP_WORD; } else { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_CHAR); - } + wrap_mode = GTK_WRAP_CHAR; + } } - xed_prefs_manager_set_print_font_body (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton))); - xed_prefs_manager_set_print_font_header (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton))); - xed_prefs_manager_set_print_font_numbers (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton))); + g_settings_set_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE, wrap_mode); } static void @@ -510,21 +477,29 @@ create_compositor (XedPrintJob *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 = xed_prefs_manager_get_print_font_body (); - print_font_header = xed_prefs_manager_get_print_font_header (); - print_font_numbers = xed_prefs_manager_get_print_font_numbers (); - + print_font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + print_font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + print_font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + syntax_hl = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_line_numbers = g_settings_get_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS); + print_header = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER); + wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_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)) && - xed_prefs_manager_get_print_syntax_hl (), - "wrap-mode", xed_prefs_manager_get_print_wrap_mode (), - "print-line-numbers", xed_prefs_manager_get_print_line_numbers (), - "print-header", xed_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, @@ -534,8 +509,8 @@ create_compositor (XedPrintJob *job) g_free (print_font_body); g_free (print_font_header); g_free (print_font_numbers); - - if (xed_prefs_manager_get_print_header ()) + + if (print_header) { gchar *doc_name; gchar *name_to_display; @@ -547,7 +522,7 @@ create_compositor (XedPrintJob *job) left = g_strdup_printf (_("File: %s"), name_to_display); /* Translators: %N is the current page number, %Q is the total - * number of pages (ex. Page 2 of 10) + * number of pages (ex. Page 2 of 10) */ gtk_source_print_compositor_set_header_format (job->priv->compositor, TRUE, @@ -558,11 +533,11 @@ create_compositor (XedPrintJob *job) g_free (doc_name); g_free (name_to_display); g_free (left); - } + } } static void -begin_print_cb (GtkPrintOperation *operation, +begin_print_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { @@ -571,7 +546,7 @@ begin_print_cb (GtkPrintOperation *operation, job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; job->priv->progress = 0.0; - + g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); } @@ -592,7 +567,7 @@ preview_destroyed (GtkWidget *preview, gtk_print_operation_preview_end_preview (gtk_preview); } -static gboolean +static gboolean preview_cb (GtkPrintOperation *op, GtkPrintOperationPreview *gtk_preview, GtkPrintContext *context, @@ -616,16 +591,16 @@ preview_cb (GtkPrintOperation *op, } static gboolean -paginate_cb (GtkPrintOperation *operation, +paginate_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { - gboolean res; - + gboolean res; + job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; - + res = gtk_source_print_compositor_paginate (job->priv->compositor, context); - + if (res) { gint n_pages; @@ -659,25 +634,25 @@ draw_page_cb (GtkPrintOperation *operation, if (!job->priv->is_preview) { g_free (job->priv->status_string); - + n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); - + job->priv->status = XED_PRINT_JOB_STATUS_DRAWING; - - job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", + + job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", page_nr + 1, n_pages); - + job->priv->progress = page_nr / (2.0 * n_pages) + 0.5; g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); - } + } gtk_source_print_compositor_draw_page (job->priv->compositor, context, page_nr); } static void -end_print_cb (GtkPrintOperation *operation, +end_print_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { @@ -693,7 +668,7 @@ done_cb (GtkPrintOperation *operation, GError *error = NULL; XedPrintJobResult print_result; - switch (result) + switch (result) { case GTK_PRINT_OPERATION_RESULT_CANCEL: print_result = XED_PRINT_JOB_RESULT_CANCEL; @@ -711,20 +686,20 @@ done_cb (GtkPrintOperation *operation, default: g_return_if_reached (); } - + /* Avoid job is destroyed in the handler of the "done" message */ g_object_ref (job); - + g_signal_emit (job, print_job_signals[DONE], 0, print_result, error); - + g_object_unref (operation); job->priv->operation = NULL; - + g_object_unref (job); } /* Note that xed_print_job_print can can only be called once on a given XedPrintJob */ -GtkPrintOperationResult +GtkPrintOperationResult xed_print_job_print (XedPrintJob *job, GtkPrintOperationAction action, GtkPageSetup *page_setup, @@ -765,15 +740,15 @@ xed_print_job_print (XedPrintJob *job, gtk_print_operation_set_allow_async (priv->operation, TRUE); g_signal_connect (priv->operation, - "create-custom-widget", + "create-custom-widget", G_CALLBACK (create_custom_widget_cb), job); g_signal_connect (priv->operation, - "custom-widget-apply", - G_CALLBACK (custom_widget_apply_cb), + "custom-widget-apply", + G_CALLBACK (custom_widget_apply_cb), job); g_signal_connect (priv->operation, - "begin-print", + "begin-print", G_CALLBACK (begin_print_cb), job); g_signal_connect (priv->operation, @@ -781,23 +756,23 @@ xed_print_job_print (XedPrintJob *job, G_CALLBACK (preview_cb), job); g_signal_connect (priv->operation, - "paginate", + "paginate", G_CALLBACK (paginate_cb), job); g_signal_connect (priv->operation, - "draw-page", + "draw-page", G_CALLBACK (draw_page_cb), job); g_signal_connect (priv->operation, - "end-print", + "end-print", G_CALLBACK (end_print_cb), job); g_signal_connect (priv->operation, - "done", + "done", G_CALLBACK (done_cb), - job); + job); - return gtk_print_operation_run (priv->operation, + return gtk_print_operation_run (priv->operation, action, parent, error); @@ -807,9 +782,11 @@ static void xed_print_job_init (XedPrintJob *job) { job->priv = XED_PRINT_JOB_GET_PRIVATE (job); - + + job->priv->print_settings = g_settings_new ("org.x.editor.preferences.print"); + job->priv->status = XED_PRINT_JOB_STATUS_INIT; - + job->priv->status_string = g_strdup (_("Preparing...")); } @@ -817,9 +794,9 @@ XedPrintJob * xed_print_job_new (XedView *view) { XedPrintJob *job; - + g_return_val_if_fail (XED_IS_VIEW (view), NULL); - + job = XED_PRINT_JOB (g_object_new (XED_TYPE_PRINT_JOB, "view", view, NULL)); @@ -840,7 +817,7 @@ xed_print_job_get_status_string (XedPrintJob *job) { g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); g_return_val_if_fail (job->priv->status_string != NULL, NULL); - + return job->priv->status_string; } diff --git a/xed/xed-session.c b/xed/xed-session.c index 6067974..3f57e27 100644 --- a/xed/xed-session.c +++ b/xed/xed-session.c @@ -46,7 +46,6 @@ #include "xed-debug.h" #include "xed-plugins-engine.h" -#include "xed-prefs-manager-app.h" #include "xed-metadata-manager.h" #include "xed-window.h" #include "xed-app.h" diff --git a/xed/xed-settings.c b/xed/xed-settings.c new file mode 100644 index 0000000..02d263c --- /dev/null +++ b/xed/xed-settings.c @@ -0,0 +1,750 @@ +/* + * xed-settings.c + * This file is part of xed + * + * Copyright (C) 2002-2005 - Paolo Maggi + * 2009 - Ignacio Casal Quinteiro + * + * xed 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. + * + * xed 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 xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include + +#include "xed-settings.h" +#include "xed-app.h" +#include "xed-debug.h" +#include "xed-view.h" +#include "xed-window.h" +#include "xed-notebook.h" +#include "xed-plugins-engine.h" +#include "xed-style-scheme-manager.h" +#include "xed-dirs.h" +#include "xed-utils.h" +#include "xed-window-private.h" + +#define XED_SETTINGS_SYSTEM_FONT "monospace-font-name" + +#define XED_SETTINGS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_SETTINGS, XedSettingsPrivate)) + +struct _XedSettingsPrivate +{ + GSettings *interface; + GSettings *editor; + GSettings *ui; + GSettings *plugins; + + gchar *old_scheme; +}; + +G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_SETTINGS) + +static void +xed_settings_finalize (GObject *object) +{ + XedSettings *xs = XED_SETTINGS (object); + + g_free (xs->priv->old_scheme); + + G_OBJECT_CLASS (xed_settings_parent_class)->finalize (object); +} + +static void +xed_settings_dispose (GObject *object) +{ + XedSettings *xs = XED_SETTINGS (object); + + if (xs->priv->interface != NULL) + { + g_object_unref (xs->priv->interface); + xs->priv->interface = NULL; + } + + if (xs->priv->editor != NULL) + { + g_object_unref (xs->priv->editor); + xs->priv->editor = NULL; + } + + if (xs->priv->ui != NULL) + { + g_object_unref (xs->priv->ui); + xs->priv->ui = NULL; + } + + if (xs->priv->plugins != NULL) + { + g_object_unref (xs->priv->plugins); + xs->priv->plugins = NULL; + } + + G_OBJECT_CLASS (xed_settings_parent_class)->dispose (object); +} + +static void +set_font (XedSettings *xs, + const gchar *font) +{ + GList *views, *l; + guint ts; + + ts = g_settings_get_uint (xs->priv->editor, XED_SETTINGS_TABS_SIZE); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + /* Note: we use def=FALSE to avoid XedView to query gconf */ + xed_view_set_font (XED_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, + XedSettings *xs) +{ + + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_USE_DEFAULT_FONT); + if (!use_default_font) + { + return; + } + + font = g_settings_get_string (settings, key); + + set_font (xs, font); + + g_free (font); +} + +static void +on_use_default_font_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + gboolean def; + gchar *font; + + def = g_settings_get_boolean (settings, key); + + if (def) + { + font = g_settings_get_string (xs->priv->interface, XED_SETTINGS_SYSTEM_FONT); + } + else + { + font = g_settings_get_string (xs->priv->editor, XED_SETTINGS_EDITOR_FONT); + } + + set_font (xs, font); + + g_free (font); +} + +static void +on_editor_font_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_USE_DEFAULT_FONT); + if (use_default_font) + { + return; + } + + font = g_settings_get_string (settings, key); + + set_font (xs, font); + + g_free (font); +} + +static void +on_scheme_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GtkSourceStyleScheme *style; + gchar *scheme; + GList *docs; + GList *l; + + scheme = g_settings_get_string (settings, key); + + if (xs->priv->old_scheme != NULL && (strcmp (scheme, xs->priv->old_scheme) == 0)) + { + return; + } + + g_free (xs->priv->old_scheme); + xs->priv->old_scheme = scheme; + + style = gtk_source_style_scheme_manager_get_scheme (xed_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 (xed_get_style_scheme_manager (), "classic"); + + if (style == NULL) + { + g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); + return; + } + } + + docs = xed_app_get_documents (xed_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, + XedSettings *xs) +{ + GList *docs, *l; + gboolean auto_save; + + auto_save = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + XedTab *tab = xed_tab_get_from_document (XED_DOCUMENT (l->data)); + + xed_tab_set_auto_save_enabled (tab, auto_save); + } + + g_list_free (docs); +} + +static void +on_auto_save_interval_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gint auto_save_interval; + + g_settings_get (settings, key, "u", &auto_save_interval); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + XedTab *tab = xed_tab_get_from_document (XED_DOCUMENT (l->data)); + + xed_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, + XedSettings *xs) +{ + GList *docs, *l; + gint ul; + + g_settings_get (settings, key, "u", &ul); + + ul = CLAMP (ul, -1, 250); + + docs = xed_app_get_documents (xed_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, + XedSettings *xs) +{ + GtkWrapMode wrap_mode; + GList *views, *l; + + wrap_mode = g_settings_get_enum (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *views, *l; + guint ts; + + g_settings_get (settings, key, "u", &ts); + + ts = CLAMP (ts, 1, 24); + + views = xed_app_get_views (xed_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); +} + +/* FIXME: insert_spaces and line_numbers are mostly the same it just changes + the func called, maybe typedef the func and refactorize? */ +static void +on_insert_spaces_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean spaces; + + spaces = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *views, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *views, *l; + gboolean line_numbers; + + line_numbers = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *views, *l; + gboolean hl; + + hl = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_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, + XedSettings *xs) +{ + GList *views, *l; + gboolean display; + + display = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GList *views, *l; + gint pos; + + g_settings_get (settings, key, "u", &pos); + + pos = CLAMP (pos, 1, 160); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + GtkSourceSmartHomeEndType smart_he; + GList *views, *l; + + smart_he = g_settings_get_enum (settings, key); + + views = xed_app_get_views (xed_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, + XedSettings *xs) +{ + const GList *windows; + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_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 = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + GtkUIManager *ui; + GtkAction *a; + + ui = xed_window_get_ui_manager (XED_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, + XedSettings *xs) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); + } + + g_list_free (docs); +} + +static void +on_enable_tab_scrolling_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + const GList *windows; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + windows = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + XedNotebook *notebook; + + notebook = XED_NOTEBOOK (_xed_window_get_notebook (windows->data)); + xed_notebook_set_tab_scrolling_enabled (notebook, enable); + + windows = g_list_next (windows); + } +} + +static void +on_max_recents_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + /* FIXME: we have no way at the moment to trigger the + * update of the inline recents in the File menu */ +} + +static void +xed_settings_init (XedSettings *xs) +{ + xs->priv = XED_SETTINGS_GET_PRIVATE (xs); + + xs->priv->old_scheme = NULL; +} + +static void +initialize (XedSettings *xs) +{ + GSettings *prefs; + + prefs = g_settings_get_child (G_SETTINGS (xs), "preferences"); + xs->priv->editor = g_settings_get_child (prefs, "editor"); + xs->priv->ui = g_settings_get_child (prefs, "ui"); + g_object_unref (prefs); + xs->priv->plugins = g_settings_get_child (G_SETTINGS (xs), "plugins"); + + /* Load settings */ + xs->priv->interface = g_settings_new ("org.gnome.desktop.interface"); + + g_signal_connect (xs->priv->interface, "changed", + G_CALLBACK (on_system_font_changed), xs); + + /* editor changes */ + g_signal_connect (xs->priv->editor, "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), xs); + g_signal_connect (xs->priv->editor, "changed::editor-font", + G_CALLBACK (on_editor_font_changed), xs); + g_signal_connect (xs->priv->editor, "changed::scheme", + G_CALLBACK (on_scheme_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-save", + G_CALLBACK (on_auto_save_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-save-interval", + G_CALLBACK (on_auto_save_interval_changed), xs); + g_signal_connect (xs->priv->editor, "changed::undo-actions-limit", + G_CALLBACK (on_undo_actions_limit_changed), xs); + g_signal_connect (xs->priv->editor, "changed::wrap-mode", + G_CALLBACK (on_wrap_mode_changed), xs); + g_signal_connect (xs->priv->editor, "changed::tabs-size", + G_CALLBACK (on_tabs_size_changed), xs); + g_signal_connect (xs->priv->editor, "changed::insert-spaces", + G_CALLBACK (on_insert_spaces_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-indent", + G_CALLBACK (on_auto_indent_changed), xs); + g_signal_connect (xs->priv->editor, "changed::display-line-numbers", + G_CALLBACK (on_display_line_numbers_changed), xs); + g_signal_connect (xs->priv->editor, "changed::highlight-current-line", + G_CALLBACK (on_hl_current_line_changed), xs); + g_signal_connect (xs->priv->editor, "changed::bracket-matching", + G_CALLBACK (on_bracket_matching_changed), xs); + g_signal_connect (xs->priv->editor, "changed::display-right-margin", + G_CALLBACK (on_display_right_margin_changed), xs); + g_signal_connect (xs->priv->editor, "changed::right-margin-position", + G_CALLBACK (on_right_margin_position_changed), xs); + g_signal_connect (xs->priv->editor, "changed::smart-home-end", + G_CALLBACK (on_smart_home_end_changed), xs); + g_signal_connect (xs->priv->editor, "changed::syntax-highlighting", + G_CALLBACK (on_syntax_highlighting_changed), xs); + g_signal_connect (xs->priv->editor, "changed::search-highlighting", + G_CALLBACK (on_search_highlighting_changed), xs); + g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling", + G_CALLBACK (on_enable_tab_scrolling_changed), xs); + + /* ui changes */ + g_signal_connect (xs->priv->ui, "changed::max-recents", + G_CALLBACK (on_max_recents_changed), xs); +} + +static void +xed_settings_class_init (XedSettingsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = xed_settings_finalize; + object_class->dispose = xed_settings_dispose; + + g_type_class_add_private (object_class, sizeof (XedSettingsPrivate)); +} + +GSettings * +xed_settings_new () +{ + XedSettings *settings; + + settings = g_object_new (XED_TYPE_SETTINGS, + "schema", "org.x.editor", + NULL); + + initialize (settings); + + return G_SETTINGS (settings); +} + +gchar * +xed_settings_get_system_font (XedSettings *xs) +{ + gchar *system_font; + + g_return_val_if_fail (XED_IS_SETTINGS (xs), NULL); + + system_font = g_settings_get_string (xs->priv->interface, "monospace-font-name"); + + return system_font; +} + +GSList * +xed_settings_get_list (GSettings *settings, + const gchar *key) +{ + GSList *list = NULL; + gchar **values; + gsize i; + + g_return_val_if_fail (G_IS_SETTINGS (settings), NULL); + g_return_val_if_fail (key != NULL, NULL); + + values = g_settings_get_strv (settings, key); + i = 0; + + while (values[i] != NULL) + { + list = g_slist_prepend (list, values[i]); + i++; + } + + g_free (values); + + return g_slist_reverse (list); +} + +void +xed_settings_set_list (GSettings *settings, + const gchar *key, + const GSList *list) +{ + gchar **values = NULL; + const GSList *l; + + g_return_if_fail (G_IS_SETTINGS (settings)); + g_return_if_fail (key != NULL); + + if (list != NULL) + { + gint i, len; + + len = g_slist_length ((GSList *)list); + values = g_new (gchar *, len + 1); + + for (l = list, i = 0; l != NULL; l = g_slist_next (l), i++) + { + values[i] = l->data; + } + values [i] = NULL; + } + + g_settings_set_strv (settings, key, (const gchar * const *)values); + g_free (values); +} diff --git a/xed/xed-settings.h b/xed/xed-settings.h new file mode 100644 index 0000000..3da7182 --- /dev/null +++ b/xed/xed-settings.h @@ -0,0 +1,132 @@ +/* + * xed-settings.h + * This file is part of xed + * + * Copyright (C) 2009 - Ignacio Casal Quinteiro + * 2002 - Paolo Maggi + * + * xed 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. + * + * xed 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 xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + + +#ifndef __XED_SETTINGS_H__ +#define __XED_SETTINGS_H__ + +#include +#include +#include "xed-app.h" + +G_BEGIN_DECLS + +#define XED_TYPE_SETTINGS (xed_settings_get_type ()) +#define XED_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SETTINGS, XedSettings)) +#define XED_SETTINGS_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SETTINGS, XedSettings const)) +#define XED_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_SETTINGS, XedSettingsClass)) +#define XED_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_SETTINGS)) +#define XED_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SETTINGS)) +#define XED_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_SETTINGS, XedSettingsClass)) + +typedef struct _XedSettings XedSettings; +typedef struct _XedSettingsClass XedSettingsClass; +typedef struct _XedSettingsPrivate XedSettingsPrivate; + +struct _XedSettings +{ + GSettings parent; + + XedSettingsPrivate *priv; +}; + +struct _XedSettingsClass +{ + GSettingsClass parent_class; +}; + +// typedef enum { +// XED_TOOLBAR_SYSTEM = 0, +// XED_TOOLBAR_ICONS, +// XED_TOOLBAR_ICONS_AND_TEXT, +// XED_TOOLBAR_ICONS_BOTH_HORIZ +// } XedToolbarSetting; + +GType xed_settings_get_type (void) G_GNUC_CONST; + +GSettings *xed_settings_new (void); + +// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs); + +gchar *xed_settings_get_system_font (XedSettings *xs); + +/* Utility functions */ +GSList *xed_settings_get_list (GSettings *settings, + const gchar *key); + +void xed_settings_set_list (GSettings *settings, + const gchar *key, + const GSList *list); + +/* key constants */ +#define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font" +#define XED_SETTINGS_EDITOR_FONT "editor-font" +#define XED_SETTINGS_SCHEME "scheme" +#define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy" +#define XED_SETTINGS_AUTO_SAVE "auto-save" +#define XED_SETTINGS_AUTO_SAVE_INTERVAL "auto-save-interval" +#define XED_SETTINGS_UNDO_ACTIONS_LIMIT "undo-actions-limit" +#define XED_SETTINGS_MAX_UNDO_ACTIONS "max-undo-actions" +#define XED_SETTINGS_WRAP_MODE "wrap-mode" +#define XED_SETTINGS_TABS_SIZE "tabs-size" +#define XED_SETTINGS_INSERT_SPACES "insert-spaces" +#define XED_SETTINGS_AUTO_INDENT "auto-indent" +#define XED_SETTINGS_DISPLAY_LINE_NUMBERS "display-line-numbers" +#define XED_SETTINGS_HIGHLIGHT_CURRENT_LINE "highlight-current-line" +#define XED_SETTINGS_BRACKET_MATCHING "bracket-matching" +#define XED_SETTINGS_DISPLAY_RIGHT_MARGIN "display-right-margin" +#define XED_SETTINGS_RIGHT_MARGIN_POSITION "right-margin-position" +#define XED_SETTINGS_SMART_HOME_END "smart-home-end" +#define XED_SETTINGS_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" +#define XED_SETTINGS_RESTORE_CURSOR_POSITION "restore-cursor-position" +#define XED_SETTINGS_SYNTAX_HIGHLIGHTING "syntax-highlighting" +#define XED_SETTINGS_SEARCH_HIGHLIGHTING "search-highlighting" +#define XED_SETTINGS_ENABLE_TAB_SCROLLING "enable-tab-scrolling" +#define XED_SETTINGS_TOOLBAR_VISIBLE "toolbar-visible" +#define XED_SETTINGS_STATUSBAR_VISIBLE "statusbar-visible" +#define XED_SETTINGS_SIDE_PANEL_VISIBLE "side-panel-visible" +#define XED_SETTINGS_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" +#define XED_SETTINGS_MAX_RECENTS "max-recents" +#define XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING "print-syntax-highlighting" +#define XED_SETTINGS_PRINT_HEADER "print-header" +#define XED_SETTINGS_PRINT_WRAP_MODE "print-wrap-mode" +#define XED_SETTINGS_PRINT_LINE_NUMBERS "print-line-numbers" +#define XED_SETTINGS_PRINT_FONT_BODY_PANGO "print-font-body-pango" +#define XED_SETTINGS_PRINT_FONT_HEADER_PANGO "print-font-header-pango" +#define XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO "print-font-numbers-pango" +#define XED_SETTINGS_ENCODING_AUTO_DETECTED "auto-detected" +#define XED_SETTINGS_ENCODING_SHOWN_IN_MENU "shown-in-menu" +#define XED_SETTINGS_ACTIVE_PLUGINS "active-plugins" + +/* window state keys */ +#define XED_SETTINGS_WINDOW_STATE "state" +#define XED_SETTINGS_WINDOW_SIZE "size" +#define XED_SETTINGS_SIDE_PANEL_SIZE "side-panel-size" +#define XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE "side-panel-active-page" +#define XED_SETTINGS_BOTTOM_PANEL_SIZE "bottom-panel-size" +#define XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE "bottom-panel-active-page" +#define XED_SETTINGS_ACTIVE_FILE_FILTER "filter-id" + +G_END_DECLS + +#endif /* __XED_SETTINGS_H__ */ diff --git a/xed/xed-style-scheme-manager.c b/xed/xed-style-scheme-manager.c index 82ea3b5..cb40bfa 100644 --- a/xed/xed-style-scheme-manager.c +++ b/xed/xed-style-scheme-manager.c @@ -42,7 +42,6 @@ #include #include "xed-style-scheme-manager.h" -#include "xed-prefs-manager.h" #include "xed-dirs.h" static GtkSourceStyleSchemeManager *style_scheme_manager = NULL; @@ -62,7 +61,7 @@ get_xed_styles_path (void) NULL); g_free (config_dir); } - + return dir; } @@ -77,7 +76,7 @@ add_xed_styles_path (GtkSourceStyleSchemeManager *mgr) { gtk_source_style_scheme_manager_append_search_path (mgr, dir); g_free (dir); - } + } } GtkSourceStyleSchemeManager * @@ -113,12 +112,12 @@ xed_style_scheme_manager_list_schemes_sorted (GtkSourceStyleSchemeManager *manag g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL); scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); - + while (*scheme_ids != NULL) { GtkSourceStyleScheme *scheme; - scheme = gtk_source_style_scheme_manager_get_scheme (manager, + scheme = gtk_source_style_scheme_manager_get_scheme (manager, *scheme_ids); schemes = g_slist_prepend (schemes, scheme); @@ -365,9 +364,9 @@ _xed_style_scheme_manager_uninstall_scheme (GtkSourceStyleSchemeManager *manager if (g_unlink (filename) == -1) return FALSE; - + /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan (manager); - - return TRUE; + + return TRUE; } diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 2fd7ebb..c090289 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -42,8 +42,8 @@ #include "xed-print-preview.h" #include "xed-progress-message-area.h" #include "xed-debug.h" -#include "xed-prefs-manager-app.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define XED_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAB, XedTabPrivate)) @@ -51,6 +51,8 @@ struct _XedTabPrivate { + GSettings *editor; + XedTabState state; GtkWidget *view; @@ -73,7 +75,7 @@ struct _XedTabPrivate XedDocumentSaveFlags save_flags; - gint auto_save_interval; + guint auto_save_interval; guint auto_save_timeout; gint not_editable : 1; @@ -223,6 +225,8 @@ xed_tab_dispose (GObject *object) tab->priv->tmp_save_location = NULL; } + g_clear_object (&tab->priv->editor); + G_OBJECT_CLASS (xed_tab_parent_class)->dispose (object); } @@ -372,7 +376,9 @@ set_view_properties_according_to_state (XedTab *tab, XedTabState state) { gboolean val; + gboolean hl_current_line; + hl_current_line = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_HIGHLIGHT_CURRENT_LINE); val = ((state == XED_TAB_STATE_NORMAL) && (tab->priv->print_preview == NULL) && !tab->priv->not_editable); gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val); @@ -381,7 +387,7 @@ set_view_properties_according_to_state (XedTab *tab, val = ((state != XED_TAB_STATE_LOADING) && (state != XED_TAB_STATE_CLOSING) && - (xed_prefs_manager_get_highlight_current_line ())); + (hl_current_line)); gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); } @@ -1418,15 +1424,15 @@ xed_tab_init (XedTab *tab) { GtkWidget *sw; XedDocument *doc; + gboolean auto_save; + guint auto_save_interval; tab->priv = XED_TAB_GET_PRIVATE (tab); + tab->priv->editor = g_settings_new ("org.x.editor.preferences.editor"); tab->priv->state = XED_TAB_STATE_NORMAL; - tab->priv->not_editable = FALSE; - tab->priv->save_flags = 0; - tab->priv->ask_if_externally_modified = TRUE; gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), GTK_ORIENTATION_VERTICAL); @@ -1438,14 +1444,17 @@ xed_tab_init (XedTab *tab) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* Manage auto save data */ - tab->priv->auto_save = xed_prefs_manager_get_auto_save (); + auto_save = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_AUTO_SAVE); + auto_save_interval = g_settings_get_uint (tab->priv->editor, XED_SETTINGS_AUTO_SAVE_INTERVAL); + tab->priv->auto_save = auto_save; tab->priv->auto_save = (tab->priv->auto_save != FALSE); - tab->priv->auto_save_interval = xed_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; - } + }*/ /* Create the view */ doc = xed_document_new (); diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 56bda94..cb74976 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -48,7 +48,6 @@ #include "xed-utils.h" #include "xed-document.h" -#include "xed-prefs-manager.h" #include "xed-debug.h" /* For the workspace/viewport stuff */ diff --git a/xed/xed-utils.h b/xed/xed-utils.h index abe83be..79749f5 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -37,6 +37,7 @@ #include #include #include +#include G_BEGIN_DECLS diff --git a/xed/xed-view.c b/xed/xed-view.c index 74cce53..76998a1 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -13,10 +13,10 @@ #include "xed-view-activatable.h" #include "xed-plugins-engine.h" #include "xed-debug.h" -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-marshal.h" #include "xed-utils.h" +#include "xed-settings.h" +#include "xed-app.h" #define XED_VIEW_SCROLL_MARGIN 0.02 #define XED_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */ @@ -30,6 +30,7 @@ enum struct _XedViewPrivate { + GSettings *editor_settings; GtkTextIter start_search_iter; GtkWidget *search_window; GtkWidget *search_entry; @@ -41,20 +42,9 @@ struct _XedViewPrivate guint view_realized : 1; }; -static void xed_view_dispose (GObject *object); -static void xed_view_finalize (GObject *object); -static void xed_view_realize (GtkWidget *widget); -static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event); -static gboolean xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); -static void xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *selection_data, guint info, guint timestamp); -static gboolean xed_view_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); -static gboolean xed_view_button_press_event (GtkWidget *widget, GdkEventButton *event); + static gboolean start_interactive_goto_line (XedView *view); static void hide_search_window (XedView *view, gboolean cancel); -static gboolean xed_view_draw (GtkWidget *widget, cairo_t *cr); -static void search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, GtkTextIter *end, XedView *view); -static void xed_view_delete_from_cursor (GtkTextView *text_view, GtkDeleteType type, gint count); G_DEFINE_TYPE(XedView, xed_view, GTK_SOURCE_TYPE_VIEW) @@ -81,76 +71,52 @@ document_read_only_notify_handler (XedDocument *document, } static void -xed_view_class_init (XedViewClass *klass) +search_highlight_updated_cb (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end, + XedView *view) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass); + GdkRectangle visible_rect; + GdkRectangle updated_rect; + GdkRectangle redraw_rect; + gint y; + gint height; + GtkTextView *text_view; - GtkBindingSet *binding_set; + text_view = GTK_TEXT_VIEW(view); - object_class->dispose = xed_view_dispose; - object_class->finalize = xed_view_finalize; + g_return_if_fail(xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view)))); - widget_class->focus_out_event = xed_view_focus_out; - widget_class->draw = xed_view_draw; + /* get visible area */ + gtk_text_view_get_visible_rect (text_view, &visible_rect); - /* - * Override the gtk_text_view_drag_motion and drag_drop - * functions to get URIs - * - * If the mime type is text/uri-list, then we will accept - * the potential drop, or request the data (depending on the - * function). - * - * If the drag context has any other mime type, then pass the - * information onto the GtkTextView's standard handlers. - * (widget_class->function_name). - * - * See bug #89881 for details - */ - widget_class->drag_motion = xed_view_drag_motion; - widget_class->drag_data_received = xed_view_drag_data_received; - widget_class->drag_drop = xed_view_drag_drop; - widget_class->button_press_event = xed_view_button_press_event; - widget_class->realize = xed_view_realize; - klass->start_interactive_goto_line = start_interactive_goto_line; + /* get updated rectangle */ + gtk_text_view_get_line_yrange (text_view, start, &y, &height); + updated_rect.y = y; + gtk_text_view_get_line_yrange (text_view, end, &y, &height); + updated_rect.height = y + height - updated_rect.y; + updated_rect.x = visible_rect.x; + updated_rect.width = visible_rect.width; - text_view_class->delete_from_cursor = xed_view_delete_from_cursor; + /* intersect both rectangles to see whether we need to queue a redraw */ + if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect)) + { + GdkRectangle widget_rect; + gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, redraw_rect.x, redraw_rect.y, + &widget_rect.x, &widget_rect.y); - view_signals[START_INTERACTIVE_GOTO_LINE] = g_signal_new ("start_interactive_goto_line", - G_TYPE_FROM_CLASS(object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(XedViewClass, start_interactive_goto_line), - NULL, NULL, xed_marshal_BOOLEAN__NONE, G_TYPE_BOOLEAN, 0); + widget_rect.width = redraw_rect.width; + widget_rect.height = redraw_rect.height; - /* A new signal DROP_URIS has been added to allow plugins to intercept - * the default dnd behaviour of 'text/uri-list'. XedView now handles - * dnd in the default handlers of drag_drop, drag_motion and - * drag_data_received. The view emits drop_uris from drag_data_received - * if valid uris have been dropped. Plugins should connect to - * drag_motion, drag_drop and drag_data_received to change this - * default behaviour. They should _NOT_ use this signal because this - * will not prevent xed from loading the uri - */ - view_signals[DROP_URIS] = g_signal_new ("drop_uris", G_TYPE_FROM_CLASS(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(XedViewClass, drop_uris), - NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_STRV); - - g_type_class_add_private (klass, sizeof(XedViewPrivate)); - - binding_set = gtk_binding_set_by_class (klass); - - gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "start_interactive_goto_line", 0); - - gtk_binding_entry_add_signal (binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, - GTK_DELETE_PARAGRAPHS, G_TYPE_INT, 1); + gtk_widget_queue_draw_area (GTK_WIDGET(text_view), widget_rect.x, widget_rect.y, widget_rect.width, + widget_rect.height); + } } static void current_buffer_removed (XedView *view) { - if (view->priv->current_buffer) + if (view->priv->current_buffer != NULL) { g_signal_handlers_disconnect_by_func(view->priv->current_buffer, document_read_only_notify_handler, view); g_signal_handlers_disconnect_by_func(view->priv->current_buffer, search_highlight_updated_cb, view); @@ -207,36 +173,9 @@ xed_view_init (XedView *view) xed_debug (DEBUG_VIEW); - view->priv = XED_VIEW_GET_PRIVATE(view); + view->priv = XED_VIEW_GET_PRIVATE (view); - /* - * Set tab, fonts, wrap mode, colors, etc. according - * to preferences - */ - if (!xed_prefs_manager_get_use_default_font ()) - { - gchar *editor_font; - editor_font = xed_prefs_manager_get_editor_font (); - xed_view_set_font (view, FALSE, editor_font); - g_free (editor_font); - } - else - { - xed_view_set_font (view, TRUE, NULL); - } - - g_object_set (G_OBJECT(view), - "wrap_mode", xed_prefs_manager_get_wrap_mode (), - "show_line_numbers", xed_prefs_manager_get_display_line_numbers (), - "auto_indent", xed_prefs_manager_get_auto_indent (), - "tab_width", xed_prefs_manager_get_tabs_size (), - "insert_spaces_instead_of_tabs", xed_prefs_manager_get_insert_spaces (), - "show_right_margin", xed_prefs_manager_get_display_right_margin (), - "right_margin_position", xed_prefs_manager_get_right_margin_position (), - "highlight_current_line", xed_prefs_manager_get_highlight_current_line (), - "smart_home_end", xed_prefs_manager_get_smart_home_end (), - "indent_on_tab", TRUE, - NULL); + view->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); view->priv->typeselect_flush_timeout = 0; @@ -263,15 +202,10 @@ xed_view_init (XedView *view) static void xed_view_dispose (GObject *object) { - XedView *view; + XedView *view = XED_VIEW (object); - view = XED_VIEW(object); - - if (view->priv->extensions != NULL) - { - g_object_unref (view->priv->extensions); - view->priv->extensions = NULL; - } + g_clear_object (&view->priv->extensions); + g_clear_object (&view->priv->editor_settings); if (view->priv->search_window != NULL) { @@ -285,30 +219,116 @@ xed_view_dispose (GObject *object) } } - /* 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 */ current_buffer_removed (view); - g_signal_handlers_disconnect_by_func(view, on_notify_buffer_cb, NULL); - (* G_OBJECT_CLASS (xed_view_parent_class)->dispose) (object); + /* 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 buffer which we don't want. + * There is no problem calling g_signal_handlers_disconnect_by_func() + * several times (if dispose() is called several times). + */ + g_signal_handlers_disconnect_by_func (view, on_notify_buffer_cb, NULL); + + G_OBJECT_CLASS (xed_view_parent_class)->dispose (object); } static void -xed_view_finalize (GObject *object) +xed_view_constructed (GObject *object) { XedView *view; - view = XED_VIEW(object); - current_buffer_removed (view); + XedViewPrivate *priv; + gboolean use_default_font; - G_OBJECT_CLASS (xed_view_parent_class)->finalize (object); + view = XED_VIEW (object); + priv = view->priv; + + /* Get setting values */ + use_default_font = g_settings_get_boolean (view->priv->editor_settings, XED_SETTINGS_USE_DEFAULT_FONT); + + /* + * Set tab, fonts, wrap mode, colors, etc. according to preferences + */ + if (!use_default_font) + { + gchar *editor_font; + + editor_font = g_settings_get_string (view->priv->editor_settings, XED_SETTINGS_EDITOR_FONT); + + xed_view_set_font (view, FALSE, editor_font); + + g_free (editor_font); + } + else + { + xed_view_set_font (view, TRUE, NULL); + } + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_DISPLAY_LINE_NUMBERS, + view, + "show-line-numbers", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_AUTO_INDENT, + view, + "auto-indent", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_TABS_SIZE, + view, + "tab-width", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_INSERT_SPACES, + view, + "insert-spaces-instead-of-tabs", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_DISPLAY_RIGHT_MARGIN, + view, + "show-right-margin", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_RIGHT_MARGIN_POSITION, + view, + "right-margin-position", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_HIGHLIGHT_CURRENT_LINE, + view, + "highlight-current-line", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_WRAP_MODE, + view, + "wrap-mode", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_SMART_HOME_END, + view, + "smart-home-end", + G_SETTINGS_BIND_GET); + + g_object_set (G_OBJECT (view), + "indent_on_tab", TRUE, + NULL); + + G_OBJECT_CLASS (xed_view_parent_class)->constructed (object); } static gint -xed_view_focus_out (GtkWidget *widget, +xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event) { - XedView *view = XED_VIEW(widget); + XedView *view = XED_VIEW (widget); gtk_widget_queue_draw (widget); @@ -318,11 +338,384 @@ xed_view_focus_out (GtkWidget *widget, hide_search_window (view, FALSE); } - (* GTK_WIDGET_CLASS (xed_view_parent_class)->focus_out_event) (widget, event); + GTK_WIDGET_CLASS (xed_view_parent_class)->focus_out_event (widget, event); return FALSE; } +static gboolean +xed_view_draw (GtkWidget *widget, + cairo_t *cr) +{ + GtkTextView *text_view; + XedDocument *doc; + GdkWindow *window; + + text_view = GTK_TEXT_VIEW(widget); + + doc = XED_DOCUMENT(gtk_text_view_get_buffer (text_view)); + window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT); + + if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc)) + { + GdkRectangle visible_rect; + GtkTextIter iter1, iter2; + + gtk_text_view_get_visible_rect (text_view, &visible_rect); + gtk_text_view_get_line_at_y (text_view, &iter1, visible_rect.y, NULL); + gtk_text_view_get_line_at_y (text_view, &iter2, visible_rect.y + visible_rect.height, NULL); + gtk_text_iter_forward_line (&iter2); + + _xed_document_search_region (doc, &iter1, &iter2); + } + + return GTK_WIDGET_CLASS (xed_view_parent_class)->draw (widget, cr); +} + +static GdkAtom +drag_get_uri_target (GtkWidget *widget, + GdkDragContext *context) +{ + GdkAtom target; + GtkTargetList *tl; + + tl = gtk_target_list_new (NULL, 0); + gtk_target_list_add_uri_targets (tl, 0); + + target = gtk_drag_dest_find_target (widget, context, tl); + gtk_target_list_unref (tl); + + return target; +} + +static gboolean +xed_view_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint timestamp) +{ + gboolean result; + + /* Chain up to allow textview to scroll and position dnd mark, note + * that this needs to be checked if gtksourceview or gtktextview + * changes drag_motion behaviour */ + result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_motion (widget, context, x, y, timestamp); + + /* If this is a URL, deal with it here */ + if (drag_get_uri_target (widget, context) != GDK_NONE) + { + gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), timestamp); + result = TRUE; + } + + return result; +} + +static void +xed_view_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint timestamp) +{ + gchar **uri_list; + + /* If this is an URL emit DROP_URIS, otherwise chain up the signal */ + if (info == TARGET_URI_LIST) + { + uri_list = xed_utils_drop_get_uris (selection_data); + + if (uri_list != NULL) + { + g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list); + g_strfreev (uri_list); + gtk_drag_finish (context, TRUE, FALSE, timestamp); + } + } + else + { + GTK_WIDGET_CLASS (xed_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, + timestamp); + } +} + +static gboolean +xed_view_drag_drop (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint timestamp) +{ + gboolean result; + GdkAtom target; + + /* If this is a URL, just get the drag data */ + target = drag_get_uri_target (widget, context); + + if (target != GDK_NONE) + { + gtk_drag_get_data (widget, context, target, timestamp); + result = TRUE; + } + else + { + /* Chain up */ + result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_drop (widget, context, x, y, timestamp); + } + + return result; +} + +static GtkWidget * +create_line_numbers_menu (GtkWidget *view) +{ + GtkWidget *menu; + GtkWidget *item; + + menu = gtk_menu_new (); + + 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_settings_bind (XED_VIEW (view)->priv->editor_settings, + "active", + item, + XED_SETTINGS_DISPLAY_LINE_NUMBERS, + G_SETTINGS_BIND_SET); + + gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); + + gtk_widget_show_all (menu); + + return menu; +} + +static void +show_line_numbers_menu (GtkWidget *view, + GdkEventButton *event) +{ + GtkWidget *menu; + + menu = create_line_numbers_menu (view); + gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); +} + +static gboolean +xed_view_button_press_event (GtkWidget *widget, + GdkEventButton *event) +{ + if ((event->type == GDK_BUTTON_PRESS) + && (event->button == 3) + && (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) + { + + show_line_numbers_menu (widget, event); + + return TRUE; + } + + return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); +} + +static void +xed_view_realize (GtkWidget *widget) +{ + XedView *view = XED_VIEW (widget); + + if (!view->priv->view_realized) + { + peas_extension_set_call (view->priv->extensions, "activate"); + view->priv->view_realized = TRUE; + } + + GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget); +} + +static void +delete_line (GtkTextView *text_view, + gint count) +{ + GtkTextIter start; + GtkTextIter end; + GtkTextBuffer *buffer; + + buffer = gtk_text_view_get_buffer (text_view); + + gtk_text_view_reset_im_context (text_view); + + /* If there is a selection delete the selected lines and + * ignore count */ + if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) + { + gtk_text_iter_order (&start, &end); + if (gtk_text_iter_starts_line (&end)) + { + /* Do no delete the line with the cursor if the cursor + * is at the beginning of the line */ + count = 0; + } + else + { + count = 1; + } + } + + gtk_text_iter_set_line_offset (&start, 0); + + if (count > 0) + { + gtk_text_iter_forward_lines (&end, count); + if (gtk_text_iter_is_end (&end)) + { + if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&start); + } + } + } + else if (count < 0) + { + if (!gtk_text_iter_ends_line (&end)) + { + gtk_text_iter_forward_to_line_end (&end); + } + + while (count < 0) + { + if (!gtk_text_iter_backward_line (&start)) + { + break; + } + ++count; + } + + if (count == 0) + { + if (!gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&start); + } + } + else + { + gtk_text_iter_forward_line (&end); + } + } + + if (!gtk_text_iter_equal (&start, &end)) + { + GtkTextIter cur = start; + gtk_text_iter_set_line_offset (&cur, 0); + gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_place_cursor (buffer, &cur); + gtk_text_buffer_delete_interactive (buffer, &start, &end, gtk_text_view_get_editable (text_view)); + gtk_text_buffer_end_user_action (buffer); + gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer)); + } + else + { + gtk_widget_error_bell (GTK_WIDGET(text_view)); + } +} + +static void +xed_view_delete_from_cursor (GtkTextView *text_view, + GtkDeleteType type, + gint count) +{ + /* We override the standard handler for delete_from_cursor since + the GTK_DELETE_PARAGRAPHS case is not implemented as we like (i.e. it + does not remove the carriage return in the previous line) + */ + switch (type) + { + case GTK_DELETE_PARAGRAPHS: + delete_line (text_view, count); + break; + default: + GTK_TEXT_VIEW_CLASS (xed_view_parent_class)->delete_from_cursor (text_view, type, count); + break; + } +} + +static void +xed_view_class_init (XedViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass); + GtkBindingSet *binding_set; + + object_class->dispose = xed_view_dispose; + object_class->constructed = xed_view_constructed; + + widget_class->focus_out_event = xed_view_focus_out; + widget_class->draw = xed_view_draw; + + /* + * Override the gtk_text_view_drag_motion and drag_drop + * functions to get URIs + * + * If the mime type is text/uri-list, then we will accept + * the potential drop, or request the data (depending on the + * function). + * + * If the drag context has any other mime type, then pass the + * information onto the GtkTextView's standard handlers. + * (widget_class->function_name). + * + * See bug #89881 for details + */ + widget_class->drag_motion = xed_view_drag_motion; + widget_class->drag_data_received = xed_view_drag_data_received; + widget_class->drag_drop = xed_view_drag_drop; + widget_class->button_press_event = xed_view_button_press_event; + widget_class->realize = xed_view_realize; + klass->start_interactive_goto_line = start_interactive_goto_line; + + text_view_class->delete_from_cursor = xed_view_delete_from_cursor; + + view_signals[START_INTERACTIVE_GOTO_LINE] = + g_signal_new ("start_interactive_goto_line", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedViewClass, start_interactive_goto_line), + NULL, NULL, + xed_marshal_BOOLEAN__NONE, + G_TYPE_BOOLEAN, 0); + + /* A new signal DROP_URIS has been added to allow plugins to intercept + * the default dnd behaviour of 'text/uri-list'. XedView now handles + * dnd in the default handlers of drag_drop, drag_motion and + * drag_data_received. The view emits drop_uris from drag_data_received + * if valid uris have been dropped. Plugins should connect to + * drag_motion, drag_drop and drag_data_received to change this + * default behaviour. They should _NOT_ use this signal because this + * will not prevent xed from loading the uri + */ + view_signals[DROP_URIS] = + g_signal_new ("drop_uris", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedViewClass, drop_uris), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, G_TYPE_STRV); + + g_type_class_add_private (klass, sizeof (XedViewPrivate)); + + binding_set = gtk_binding_set_by_class (klass); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "start_interactive_goto_line", 0); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, + GTK_DELETE_PARAGRAPHS, G_TYPE_INT, 1); +} + /** * xed_view_new: * @doc: a #XedDocument @@ -338,10 +731,15 @@ xed_view_new (XedDocument *doc) GtkWidget *view; xed_debug_message (DEBUG_VIEW, "START"); + g_return_val_if_fail(XED_IS_DOCUMENT (doc), NULL); + view = GTK_WIDGET(g_object_new (XED_TYPE_VIEW, "buffer", doc, NULL)); + xed_debug_message (DEBUG_VIEW, "END: %d", G_OBJECT (view)->ref_count); + gtk_widget_show_all (view); + return view; } @@ -485,8 +883,8 @@ xed_view_scroll_to_cursor (XedView *view) * otherwise sets it to @font_name. **/ void -xed_view_set_font (XedView *view, - gboolean def, +xed_view_set_font (XedView *view, + gboolean def, const gchar *font_name) { PangoFontDescription *font_desc = NULL; @@ -497,24 +895,28 @@ xed_view_set_font (XedView *view, if (def) { + GSettings *settings; gchar *font; - font = xed_prefs_manager_get_system_font (); + + settings = _xed_app_get_settings (xed_app_get_default ()); + font = xed_settings_get_system_font (XED_SETTINGS (settings)); font_desc = pango_font_description_from_string (font); + g_free (font); } else { - g_return_if_fail(font_name != NULL); + g_return_if_fail (font_name != NULL); font_desc = pango_font_description_from_string (font_name); } - g_return_if_fail(font_desc != NULL); - gtk_widget_modify_font (GTK_WIDGET(view), font_desc); + g_return_if_fail (font_desc != NULL); + gtk_widget_modify_font (GTK_WIDGET (view), font_desc); pango_font_description_free (font_desc); } static void -set_entry_state (GtkWidget *entry, +set_entry_state (GtkWidget *entry, XedSearchEntryState state) { GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(entry)); @@ -532,7 +934,7 @@ set_entry_state (GtkWidget *entry, /* Cut and paste from gtkwindow.c */ static void send_focus_change (GtkWidget *widget, - gboolean in) + gboolean in) { GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE); @@ -614,18 +1016,18 @@ update_search_window_position (XedView *view) } static gboolean -search_window_deleted (GtkWidget *widget, +search_window_deleted (GtkWidget *widget, GdkEventAny *event, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); return TRUE; } static gboolean -search_window_button_pressed (GtkWidget *widget, +search_window_button_pressed (GtkWidget *widget, GdkEventButton *event, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); gtk_propagate_event (GTK_WIDGET(view), (GdkEvent *) event); @@ -633,9 +1035,9 @@ search_window_button_pressed (GtkWidget *widget, } static gboolean -search_window_key_pressed (GtkWidget *widget, +search_window_key_pressed (GtkWidget *widget, GdkEventKey *event, - XedView *view) + XedView *view) { gboolean retval = FALSE; guint modifiers; @@ -661,7 +1063,7 @@ search_window_key_pressed (GtkWidget *widget, static void search_entry_activate (GtkEntry *entry, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); } @@ -692,8 +1094,8 @@ search_enable_popdown (GtkWidget *widget, static void search_entry_populate_popup (GtkEntry *entry, - GtkMenu *menu, - XedView *view) + GtkMenu *menu, + XedView *view) { GtkWidget *menu_item; view->priv->disable_popdown = TRUE; @@ -703,9 +1105,9 @@ search_entry_populate_popup (GtkEntry *entry, static void search_entry_insert_text (GtkEditable *editable, const gchar *text, - gint length, - gint *position, - XedView *view) + gint length, + gint *position, + XedView *view) { gunichar c; const gchar *p; @@ -1000,347 +1402,3 @@ start_interactive_goto_line (XedView *view) return TRUE; } - -static gboolean -xed_view_draw (GtkWidget *widget, - cairo_t *cr) -{ - GtkTextView *text_view; - XedDocument *doc; - GdkWindow *window; - - text_view = GTK_TEXT_VIEW(widget); - - doc = XED_DOCUMENT(gtk_text_view_get_buffer (text_view)); - window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT); - if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc)) - { - GdkRectangle visible_rect; - GtkTextIter iter1, iter2; - - gtk_text_view_get_visible_rect (text_view, &visible_rect); - gtk_text_view_get_line_at_y (text_view, &iter1, visible_rect.y, NULL); - gtk_text_view_get_line_at_y (text_view, &iter2, visible_rect.y + visible_rect.height, NULL); - gtk_text_iter_forward_line (&iter2); - - _xed_document_search_region (doc, &iter1, &iter2); - } - - return GTK_WIDGET_CLASS (xed_view_parent_class)->draw (widget, cr); -} - -static GdkAtom -drag_get_uri_target (GtkWidget *widget, - GdkDragContext *context) -{ - GdkAtom target; - GtkTargetList *tl; - - tl = gtk_target_list_new (NULL, 0); - gtk_target_list_add_uri_targets (tl, 0); - target = gtk_drag_dest_find_target (widget, context, tl); - gtk_target_list_unref (tl); - - return target; -} - -static gboolean -xed_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint timestamp) -{ - gboolean result; - - /* Chain up to allow textview to scroll and position dnd mark, note - * that this needs to be checked if gtksourceview or gtktextview - * changes drag_motion behaviour */ - result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_motion (widget, context, x, y, timestamp); - - /* If this is a URL, deal with it here */ - if (drag_get_uri_target (widget, context) != GDK_NONE) - { - gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), timestamp); - result = TRUE; - } - - return result; -} - -static void -xed_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint timestamp) -{ - gchar **uri_list; - - /* If this is an URL emit DROP_URIS, otherwise chain up the signal */ - if (info == TARGET_URI_LIST) - { - uri_list = xed_utils_drop_get_uris (selection_data); - - if (uri_list != NULL) - { - g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list); - g_strfreev (uri_list); - gtk_drag_finish (context, TRUE, FALSE, timestamp); - } - } - else - { - GTK_WIDGET_CLASS (xed_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, - timestamp); - } -} - -static gboolean -xed_view_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint timestamp) -{ - gboolean result; - GdkAtom target; - - /* If this is a URL, just get the drag data */ - target = drag_get_uri_target (widget, context); - - if (target != GDK_NONE) - { - gtk_drag_get_data (widget, context, target, timestamp); - result = TRUE; - } - else - { - /* Chain up */ - result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_drop (widget, context, x, y, timestamp); - } - - return result; -} - -static void -show_line_numbers_toggled (GtkMenu *menu, - XedView *view) -{ - gboolean show; - - show = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(menu)); - xed_prefs_manager_set_display_line_numbers (show); -} - -static GtkWidget * -create_line_numbers_menu (GtkWidget *view) -{ - GtkWidget *menu; - GtkWidget *item; - - menu = gtk_menu_new (); - - 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); - gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); - - gtk_widget_show_all (menu); - - return menu; -} - -static void -show_line_numbers_menu (GtkWidget *view, - GdkEventButton *event) -{ - GtkWidget *menu; - - menu = create_line_numbers_menu (view); - gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); -} - -static gboolean -xed_view_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - if ((event->type == GDK_BUTTON_PRESS) - && (event->button == 3) - && (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) - { - - show_line_numbers_menu (widget, event); - - return TRUE; - } - - return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); -} - -static void -xed_view_realize (GtkWidget *widget) -{ - XedView *view = XED_VIEW (widget); - - if (!view->priv->view_realized) - { - peas_extension_set_call (view->priv->extensions, "activate"); - view->priv->view_realized = TRUE; - } - - GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget); -} - -static void -search_highlight_updated_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end, - XedView *view) -{ - GdkRectangle visible_rect; - GdkRectangle updated_rect; - GdkRectangle redraw_rect; - gint y; - gint height; - GtkTextView *text_view; - - text_view = GTK_TEXT_VIEW(view); - - g_return_if_fail(xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view)))); - - /* get visible area */ - gtk_text_view_get_visible_rect (text_view, &visible_rect); - - /* get updated rectangle */ - gtk_text_view_get_line_yrange (text_view, start, &y, &height); - updated_rect.y = y; - gtk_text_view_get_line_yrange (text_view, end, &y, &height); - updated_rect.height = y + height - updated_rect.y; - updated_rect.x = visible_rect.x; - updated_rect.width = visible_rect.width; - - /* intersect both rectangles to see whether we need to queue a redraw */ - if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect)) - { - GdkRectangle widget_rect; - gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, redraw_rect.x, redraw_rect.y, - &widget_rect.x, &widget_rect.y); - - widget_rect.width = redraw_rect.width; - widget_rect.height = redraw_rect.height; - - gtk_widget_queue_draw_area (GTK_WIDGET(text_view), widget_rect.x, widget_rect.y, widget_rect.width, - widget_rect.height); - } -} - -static void -delete_line (GtkTextView *text_view, - gint count) -{ - GtkTextIter start; - GtkTextIter end; - GtkTextBuffer *buffer; - - buffer = gtk_text_view_get_buffer (text_view); - - gtk_text_view_reset_im_context (text_view); - - /* If there is a selection delete the selected lines and - * ignore count */ - if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) - { - gtk_text_iter_order (&start, &end); - if (gtk_text_iter_starts_line (&end)) - { - /* Do no delete the line with the cursor if the cursor - * is at the beginning of the line */ - count = 0; - } - else - { - count = 1; - } - } - - gtk_text_iter_set_line_offset (&start, 0); - - if (count > 0) - { - gtk_text_iter_forward_lines (&end, count); - if (gtk_text_iter_is_end (&end)) - { - if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start)) - { - gtk_text_iter_forward_to_line_end (&start); - } - } - } - else if (count < 0) - { - if (!gtk_text_iter_ends_line (&end)) - { - gtk_text_iter_forward_to_line_end (&end); - } - - while (count < 0) - { - if (!gtk_text_iter_backward_line (&start)) - { - break; - } - ++count; - } - - if (count == 0) - { - if (!gtk_text_iter_ends_line (&start)) - { - gtk_text_iter_forward_to_line_end (&start); - } - } - else - { - gtk_text_iter_forward_line (&end); - } - } - - if (!gtk_text_iter_equal (&start, &end)) - { - GtkTextIter cur = start; - gtk_text_iter_set_line_offset (&cur, 0); - gtk_text_buffer_begin_user_action (buffer); - gtk_text_buffer_place_cursor (buffer, &cur); - gtk_text_buffer_delete_interactive (buffer, &start, &end, gtk_text_view_get_editable (text_view)); - gtk_text_buffer_end_user_action (buffer); - gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer)); - } - else - { - gtk_widget_error_bell (GTK_WIDGET(text_view)); - } -} - -static void -xed_view_delete_from_cursor (GtkTextView *text_view, - GtkDeleteType type, - gint count) -{ - /* We override the standard handler for delete_from_cursor since - the GTK_DELETE_PARAGRAPHS case is not implemented as we like (i.e. it - does not remove the carriage return in the previous line) - */ - switch (type) - { - case GTK_DELETE_PARAGRAPHS: - delete_line (text_view, count); - break; - default: - GTK_TEXT_VIEW_CLASS (xed_view_parent_class)->delete_from_cursor (text_view, type, count); - break; - } -} diff --git a/xed/xed-window-private.h b/xed/xed-window-private.h index 20ecea2..6796964 100644 --- a/xed/xed-window-private.h +++ b/xed/xed-window-private.h @@ -34,8 +34,8 @@ #include #include "xed/xed-window.h" -#include "xed-prefs-manager.h" #include "xed-message-bus.h" +#include "xed-settings.h" G_BEGIN_DECLS @@ -43,38 +43,42 @@ G_BEGIN_DECLS struct _XedWindowPrivate { - GtkWidget *notebook; + GSettings *editor_settings; + GSettings *ui_settings; + GSettings *window_settings; - GtkWidget *side_panel; - GtkWidget *bottom_panel; + GtkWidget *notebook; - GtkWidget *hpaned; - GtkWidget *vpaned; + GtkWidget *side_panel; + GtkWidget *bottom_panel; - GtkWidget *tab_width_combo; - GtkWidget *language_combo; - GtkWidget *show_side_pane_button; - GtkWidget *show_bottom_pane_button; - GtkWidget *bottom_pane_button_revealer; + GtkWidget *hpaned; + GtkWidget *vpaned; + + GtkWidget *tab_width_combo; + GtkWidget *language_combo; + GtkWidget *show_side_pane_button; + GtkWidget *show_bottom_pane_button; + GtkWidget *bottom_pane_button_revealer; XedMessageBus *message_bus; PeasExtensionSet *extensions; /* Widgets for fullscreen mode */ - GtkWidget *fullscreen_controls; - GtkWidget *fullscreen_controls_container; - guint fullscreen_animation_timeout_id; - gboolean fullscreen_animation_enter; + GtkWidget *fullscreen_controls; + GtkWidget *fullscreen_controls_container; + guint fullscreen_animation_timeout_id; + gboolean fullscreen_animation_enter; /* statusbar and context ids for statusbar messages */ - GtkWidget *statusbar; - GtkWidget *searchbar; - guint generic_message_cid; - guint tip_message_cid; - guint tab_width_id; - guint spaces_instead_of_tabs_id; - guint language_changed_id; - guint use_word_wrap_id; + GtkWidget *statusbar; + GtkWidget *searchbar; + guint generic_message_cid; + guint tip_message_cid; + guint tab_width_id; + guint spaces_instead_of_tabs_id; + guint language_changed_id; + guint use_word_wrap_id; /* Menus & Toolbars */ GtkUIManager *manager; @@ -94,28 +98,28 @@ struct _XedWindowPrivate guint recents_menu_ui_id; gulong recents_handler_id; - XedTab *active_tab; - gint num_tabs; + XedTab *active_tab; + gint num_tabs; - gint num_tabs_with_error; + gint num_tabs_with_error; gint width; gint height; GdkWindowState window_state; - gint side_panel_size; - gint bottom_panel_size; + gint side_panel_size; + gint bottom_panel_size; - XedWindowState state; + XedWindowState state; - gint bottom_panel_item_removed_handler_id; + gint bottom_panel_item_removed_handler_id; GtkWindowGroup *window_group; - GFile *default_location; + GFile *default_location; - gboolean removing_tabs : 1; - gboolean dispose_has_run : 1; + gboolean removing_tabs : 1; + gboolean dispose_has_run : 1; }; G_END_DECLS diff --git a/xed/xed-window.c b/xed/xed-window.c index 97deae0..4a10c77 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -22,7 +22,6 @@ #include "xed-commands.h" #include "xed-debug.h" #include "xed-language-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-panel.h" #include "xed-documents-panel.h" #include "xed-plugins-engine.h" @@ -30,6 +29,7 @@ #include "xed-enum-types.h" #include "xed-dirs.h" #include "xed-status-combo-box.h" +#include "xed-settings.h" #define LANGUAGE_NONE (const gchar *)"LangNone" #define XED_UIFILE "xed-ui.xml" @@ -38,6 +38,9 @@ #define FULLSCREEN_ANIMATION_SPEED 4 +#define XED_WINDOW_DEFAULT_WIDTH 650 +#define XED_WINDOW_DEFAULT_HEIGHT 500 + #define XED_WINDOW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_WINDOW, XedWindowPrivate)) /* Signals */ @@ -69,9 +72,9 @@ G_DEFINE_TYPE(XedWindow, xed_window, GTK_TYPE_WINDOW) static void recent_manager_changed (GtkRecentManager *manager, XedWindow *window); static void -xed_window_get_property (GObject *object, - guint prop_id, - GValue *value, +xed_window_get_property (GObject *object, + guint prop_id, + GValue *value, GParamSpec *pspec) { XedWindow *window = XED_WINDOW(object); @@ -90,41 +93,33 @@ xed_window_get_property (GObject *object, static void save_panes_state (XedWindow *window) { - gint pane_page; + gint panel_page; xed_debug (DEBUG_WINDOW); - if (xed_prefs_manager_window_size_can_set ()) + if (window->priv->side_panel_size > 0) { - xed_prefs_manager_set_window_size (window->priv->width, window->priv->height); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_SIZE, window->priv->side_panel_size); } - if (xed_prefs_manager_window_state_can_set ()) + panel_page = _xed_panel_get_active_item_id (XED_PANEL (window->priv->side_panel)); + if (panel_page != 0) { - xed_prefs_manager_set_window_state (window->priv->window_state); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE, panel_page); } - if ((window->priv->side_panel_size > 0) && xed_prefs_manager_side_panel_size_can_set ()) + if (window->priv->bottom_panel_size > 0) { - xed_prefs_manager_set_side_panel_size (window->priv->side_panel_size); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_SIZE, window->priv->bottom_panel_size); } - pane_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->side_panel)); - if (pane_page != 0 && xed_prefs_manager_side_panel_active_page_can_set ()) + panel_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->bottom_panel)); + if (panel_page != 0) { - xed_prefs_manager_set_side_panel_active_page (pane_page); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE, panel_page); } - if ((window->priv->bottom_panel_size > 0) && xed_prefs_manager_bottom_panel_size_can_set ()) - { - xed_prefs_manager_set_bottom_panel_size (window->priv->bottom_panel_size); - } - - pane_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->bottom_panel)); - if (pane_page != 0 && xed_prefs_manager_bottom_panel_active_page_can_set ()) - { - xed_prefs_manager_set_bottom_panel_active_page (pane_page); - } + g_settings_apply (window->priv->window_settings); } static gint @@ -141,6 +136,26 @@ on_key_pressed (GtkWidget *widget, return handled; } +static void +save_window_state (GtkWidget *widget) +{ + XedWindow *window = XED_WINDOW (widget); + + if ((window->priv->window_state & + (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0) + { + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + + window->priv->width = allocation.width; + window->priv->height = allocation.height; + + g_settings_set (window->priv->window_settings, XED_SETTINGS_WINDOW_SIZE, + "(ii)", window->priv->width, window->priv->height); + } +} + static void xed_window_dispose (GObject *object) { @@ -168,6 +183,7 @@ xed_window_dispose (GObject *object) * for this window, but only once */ if (!window->priv->dispose_has_run) { + save_window_state (GTK_WIDGET (window)); save_panes_state (window); /* Note that unreffing the extension will automatically remove @@ -204,6 +220,11 @@ xed_window_dispose (GObject *object) g_clear_object (&window->priv->window_group); g_clear_object (&window->priv->default_location); + /* We must free the settings after saving the panels */ + g_clear_object (&window->priv->editor_settings); + g_clear_object (&window->priv->ui_settings); + g_clear_object (&window->priv->window_settings); + /* Now that there have broken some reference loops, force collection again. */ peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); @@ -219,26 +240,29 @@ xed_window_finalize (GObject *object) } static gboolean -xed_window_window_state_event (GtkWidget *widget, +xed_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event) { - XedWindow *window = XED_WINDOW(widget); + XedWindow *window = XED_WINDOW (widget); + window->priv->window_state = event->new_window_state; - if (event->changed_mask & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) - { - gboolean show; - show = !(event->new_window_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)); - } + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_WINDOW_STATE, window->priv->state); + return FALSE; } static gboolean -xed_window_configure_event (GtkWidget *widget, +xed_window_configure_event (GtkWidget *widget, GdkEventConfigure *event) { - XedWindow *window = XED_WINDOW(widget); - window->priv->width = event->width; - window->priv->height = event->height; + XedWindow *window = XED_WINDOW (widget); + + if (gtk_widget_get_realized (widget) && + window->priv->state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN) == 0) + { + save_window_state (widget); + } + return GTK_WIDGET_CLASS (xed_window_parent_class)->configure_event (widget, event); } @@ -398,7 +422,7 @@ set_toolbar_style (XedWindow *window, if (origin == NULL) { - visible = xed_prefs_manager_get_toolbar_visible (); + visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_TOOLBAR_VISIBLE); } else { @@ -417,9 +441,9 @@ set_toolbar_style (XedWindow *window, action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewToolbar"); - if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(action)) != visible) + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), visible); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible); } return visible; @@ -524,7 +548,7 @@ set_paste_sensitivity_according_to_clipboard (XedWindow *window, static void set_sensitivity_according_to_tab (XedWindow *window, - XedTab *tab) + XedTab *tab) { XedDocument *doc; XedView *view; @@ -534,11 +558,14 @@ set_sensitivity_according_to_tab (XedWindow *window, gboolean editable; XedTabState state; GtkClipboard *clipboard; + gboolean enable_syntax_hl; - g_return_if_fail(XED_TAB (tab)); + g_return_if_fail (XED_TAB (tab)); xed_debug (DEBUG_WINDOW); + enable_syntax_hl = g_settings_get_boolean (window->priv->editor_settings, XED_SETTINGS_SYNTAX_HIGHLIGHTING); + state = xed_tab_get_state (tab); state_normal = (state == XED_TAB_STATE_NORMAL); @@ -631,8 +658,7 @@ set_sensitivity_according_to_tab (XedWindow *window, gtk_action_set_sensitive (action, (state_normal || state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)); action = gtk_action_group_get_action (window->priv->action_group, "ViewHighlightMode"); - gtk_action_set_sensitive (action, - (state != XED_TAB_STATE_CLOSING) && xed_prefs_manager_get_enable_syntax_highlighting ()); + gtk_action_set_sensitive (action, (state != XED_TAB_STATE_CLOSING) && enable_syntax_hl); update_next_prev_doc_sensitivity (window, tab); @@ -960,11 +986,11 @@ update_recent_files_menu (XedWindow *window) gint max_recents; GList *actions, *l, *items; GList *filtered_items = NULL; - gint i; + guint i; xed_debug (DEBUG_WINDOW); - max_recents = xed_prefs_manager_get_max_recents (); + max_recents = g_settings_get_uint (window->priv->ui_settings, XED_SETTINGS_MAX_RECENTS); g_return_if_fail(p->recents_action_group != NULL); @@ -1080,10 +1106,7 @@ toolbar_visibility_changed (GtkWidget *toolbar, visible = gtk_widget_get_visible (toolbar); - if (xed_prefs_manager_toolbar_visible_can_set ()) - { - xed_prefs_manager_set_toolbar_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_TOOLBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewToolbar"); @@ -1433,9 +1456,10 @@ set_statusbar_style (XedWindow *window, { GtkAction *action; gboolean visible; + if (origin == NULL) { - visible = xed_prefs_manager_get_statusbar_visible (); + visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_STATUSBAR_VISIBLE); } else { @@ -1470,10 +1494,7 @@ statusbar_visibility_changed (GtkWidget *statusbar, visible = gtk_widget_get_visible (statusbar); - if (xed_prefs_manager_statusbar_visible_can_set ()) - { - xed_prefs_manager_set_statusbar_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_STATUSBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewStatusbar"); @@ -1730,7 +1751,7 @@ clone_window (XedWindow *origin) if ((origin->priv->window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { gint w, h; - xed_prefs_manager_get_default_window_size (&w, &h); + _xed_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW(window), w, h); gtk_window_maximize (GTK_WINDOW(window)); } @@ -3151,10 +3172,7 @@ side_panel_visibility_changed (GtkWidget *side_panel, visible = gtk_widget_get_visible (side_panel); - if (xed_prefs_manager_side_pane_visible_can_set ()) - { - xed_prefs_manager_set_side_pane_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_SIDE_PANEL_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewSidePane"); @@ -3196,10 +3214,7 @@ bottom_panel_visibility_changed (XedPanel *bottom_panel, visible = gtk_widget_get_visible (GTK_WIDGET (bottom_panel)); - if (xed_prefs_manager_bottom_panel_visible_can_set ()) - { - xed_prefs_manager_set_bottom_panel_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_BOTTOM_PANEL_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); @@ -3269,13 +3284,19 @@ static void init_panels_visibility (XedWindow *window) { gint active_page; + gboolean side_panel_visible; + gboolean bottom_panel_visible; + xed_debug (DEBUG_WINDOW); /* side pane */ - active_page = xed_prefs_manager_get_side_panel_active_page (); + active_page = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE); _xed_panel_set_active_item_by_id (XED_PANEL (window->priv->side_panel), active_page); - if (xed_prefs_manager_get_side_pane_visible ()) + side_panel_visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_SIDE_PANEL_VISIBLE); + bottom_panel_visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_BOTTOM_PANEL_VISIBLE); + + if (side_panel_visible) { gtk_widget_show (window->priv->side_panel); } @@ -3283,10 +3304,10 @@ init_panels_visibility (XedWindow *window) /* bottom pane, it can be empty */ if (xed_panel_get_n_items (XED_PANEL (window->priv->bottom_panel)) > 0) { - active_page = xed_prefs_manager_get_bottom_panel_active_page (); + active_page = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE); _xed_panel_set_active_item_by_id (XED_PANEL(window->priv->bottom_panel), active_page); - if (xed_prefs_manager_get_bottom_panel_visible ()) + if (bottom_panel_visible) { gtk_widget_show (window->priv->bottom_panel); } @@ -3375,7 +3396,7 @@ add_notebook (XedWindow *window, gtk_paned_pack1 (GTK_PANED(window->priv->vpaned), notebook, TRUE, TRUE); gtk_widget_show (notebook); - xed_notebook_set_tab_scrolling_enabled (XED_NOTEBOOK (notebook), xed_prefs_manager_get_enable_tab_scrolling ()); + // xed_notebook_set_tab_scrolling_enabled (XED_NOTEBOOK (notebook), xed_prefs_manager_get_enable_tab_scrolling ()); connect_notebook_signals (window, notebook); } @@ -3418,6 +3439,13 @@ xed_window_init (XedWindow *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 ("org.x.editor.preferences.editor"); + window->priv->ui_settings = g_settings_new ("org.x.editor.preferences.ui"); + + /* Window settings are applied only once the window is closed. We do not want + to keep writing to disk when the window is dragged around */ + window->priv->window_settings = g_settings_new ("org.x.editor.state.window"); + g_settings_delay (window->priv->window_settings); window->priv->message_bus = xed_message_bus_new (); @@ -3467,8 +3495,8 @@ xed_window_init (XedWindow *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 = xed_prefs_manager_get_side_panel_size (); - window->priv->bottom_panel_size = xed_prefs_manager_get_bottom_panel_size (); + window->priv->side_panel_size = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_SIZE); + window->priv->bottom_panel_size = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_SIZE); g_signal_connect_after(window->priv->hpaned, "map", G_CALLBACK (hpaned_restore_position), window); g_signal_connect_after(window->priv->vpaned, "map", G_CALLBACK (vpaned_restore_position), window); @@ -4211,3 +4239,13 @@ xed_window_get_message_bus (XedWindow *window) g_return_val_if_fail(XED_IS_WINDOW (window), NULL); return window->priv->message_bus; } + +void +_xed_window_get_default_size (gint *width, + gint *height) +{ + g_return_if_fail (width != NULL && height != NULL); + + *width = XED_WINDOW_DEFAULT_WIDTH; + *height = XED_WINDOW_DEFAULT_HEIGHT; +} diff --git a/xed/xed-window.h b/xed/xed-window.h index 0364e63..99e80ab 100644 --- a/xed/xed-window.h +++ b/xed/xed-window.h @@ -106,6 +106,8 @@ gboolean _xed_window_is_fullscreen (XedWindow *window); void _xed_recent_add (XedWindow *window, GFile *location, const gchar *mime); void _xed_recent_remove (XedWindow *window, GFile *location); +void _xed_window_get_default_size (gint *width, gint *height); + G_END_DECLS #endif /* __XED_WINDOW_H__ */ diff --git a/xed/xed.c b/xed/xed.c index b2eb973..24b0108 100644 --- a/xed/xed.c +++ b/xed/xed.c @@ -52,7 +52,6 @@ #include "xed-dirs.h" #include "xed-encodings.h" #include "xed-plugins-engine.h" -#include "xed-prefs-manager-app.h" #include "xed-session.h" #include "xed-utils.h" #include "xed-window.h" @@ -597,10 +596,6 @@ main (int argc, char *argv[]) /* Set the associated .desktop file */ egg_set_desktop_file (DATADIR "/applications/xed.desktop"); - /* Load user preferences */ - xed_debug_message (DEBUG_APP, "Init prefs manager"); - xed_prefs_manager_app_init (); - /* Init plugins engine */ xed_debug_message (DEBUG_APP, "Init plugins"); engine = xed_plugins_engine_get_default (); @@ -658,7 +653,6 @@ main (int argc, char *argv[]) * finalize it properly. */ g_object_unref (engine); - xed_prefs_manager_app_shutdown (); #ifndef ENABLE_GVFS_METADATA xed_metadata_manager_shutdown ();