static void pluma_prefs_manager_auto_save_changed (GSettings *settings, gchar *key, gpointer user_data) { GList *docs; GList *l; pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_AUTO_SAVE) == 0) { gboolean auto_save; auto_save = g_settings_get_boolean (settings, key); docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { PlumaDocument *doc = PLUMA_DOCUMENT (l->data); PlumaTab *tab = pluma_tab_get_from_document (doc); pluma_tab_set_auto_save_enabled (tab, auto_save); l = l->next; } g_list_free (docs); } else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0) { gint auto_save_interval; auto_save_interval = g_settings_get_int (settings, key); if (auto_save_interval <= 0) auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { PlumaDocument *doc = PLUMA_DOCUMENT (l->data); PlumaTab *tab = pluma_tab_get_from_document (doc); pluma_tab_set_auto_save_interval (tab, auto_save_interval); l = l->next; } g_list_free (docs); } }
static void pluma_prefs_manager_tabs_size_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_TABS_SIZE) == 0) { gint tab_width; GList *views; GList *l; tab_width = g_settings_get_int (settings, key); tab_width = CLAMP (tab_width, 1, 24); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), tab_width); l = l->next; } g_list_free (views); } else if (strcmp (key, GPM_INSERT_SPACES) == 0) { gboolean enable; GList *views; GList *l; enable = g_settings_get_boolean (settings, key); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_insert_spaces_instead_of_tabs ( GTK_SOURCE_VIEW (l->data), enable); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_right_margin_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0) { gint pos; GList *views; GList *l; pos = g_settings_get_int (settings, key); pos = CLAMP (pos, 1, 160); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); l = l->next; } g_list_free (views); } else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0) { gboolean display; GList *views; GList *l; display = g_settings_get_boolean (settings, key); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_syntax_hl_enable_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) { gboolean enable; GList *docs; GList *l; const GList *windows; enable = g_settings_get_boolean (settings, key); docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); l = l->next; } g_list_free (docs); /* update the sensitivity of the Higlight Mode menu item */ windows = pluma_app_get_windows (pluma_app_get_default ()); while (windows != NULL) { GtkUIManager *ui; GtkAction *a; ui = pluma_window_get_ui_manager (PLUMA_WINDOW (windows->data)); a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); gtk_action_set_sensitive (a, enable); windows = g_list_next (windows); } } }
static void pluma_prefs_manager_wrap_mode_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_WRAP_MODE) == 0) { GtkWrapMode wrap_mode; GList *views; GList *l; wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key)); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), wrap_mode); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_hl_current_line_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0) { gboolean hl; GList *views; GList *l; hl = g_settings_get_boolean (settings, key); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_bracket_matching_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_BRACKET_MATCHING) == 0) { gboolean enable; GList *docs; GList *l; enable = g_settings_get_boolean (settings, key); docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable); l = l->next; } g_list_free (docs); } }
static void pluma_plugins_engine_deactivate_plugin_real (PlumaPluginsEngine *engine, PlumaPluginInfo *info) { const GList *wins; PlumaPluginLoader *loader; if (!pluma_plugin_info_is_active (info) || !pluma_plugin_info_is_available (info)) return; for (wins = pluma_app_get_windows (pluma_app_get_default ()); wins != NULL; wins = wins->next) { call_plugin_deactivate (info->plugin, PLUMA_WINDOW (wins->data)); } /* first unref the plugin (the loader still has one) */ g_object_unref (info->plugin); /* find the loader and tell it to gc and unload the plugin */ loader = get_plugin_loader (engine, info); pluma_plugin_loader_garbage_collect (loader); pluma_plugin_loader_unload (loader, info); info->plugin = NULL; }
static void pluma_prefs_manager_max_recents_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_MAX_RECENTS) == 0) { const GList *windows; gint max; max = g_settings_get_int (settings, key); if (max < 0) { max = GPM_DEFAULT_MAX_RECENTS; } windows = pluma_app_get_windows (pluma_app_get_default ()); while (windows != NULL) { PlumaWindow *w = windows->data; gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu), max); windows = g_list_next (windows); } /* FIXME: we have no way at the moment to trigger the * update of the inline recents in the File menu */ } }
static void pluma_prefs_manager_search_hl_enable_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0) { gboolean enable; GList *docs; GList *l; enable = g_settings_get_boolean (settings, key); docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { g_return_if_fail (PLUMA_IS_DOCUMENT (l->data)); pluma_document_set_enable_search_highlighting (PLUMA_DOCUMENT (l->data), enable); l = l->next; } g_list_free (docs); } }
static void pluma_prefs_manager_smart_home_end_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SMART_HOME_END) == 0) { GtkSourceSmartHomeEndType smart_he; GList *views; GList *l; smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key)); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_undo_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0) { gint ul; GList *docs; GList *l; ul = g_settings_get_int (settings, key); ul = CLAMP (ul, -1, 250); docs = pluma_app_get_documents (pluma_app_get_default ()); l = docs; while (l != NULL) { gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); l = l->next; } g_list_free (docs); } }
static void pluma_prefs_manager_auto_indent_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_AUTO_INDENT) == 0) { gboolean enable; GList *views; GList *l; enable = g_settings_get_boolean (settings, key); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_line_numbers_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0) { gboolean dln; GList *views; GList *l; dln = g_settings_get_boolean (settings, key); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), dln); l = l->next; } g_list_free (views); } }
static void pluma_prefs_manager_lockdown_changed (GSettings *settings, gchar *key, gpointer user_data) { PlumaApp *app; gboolean locked; pluma_debug (DEBUG_PREFS); locked = g_settings_get_boolean (settings, key); app = pluma_app_get_default (); if (strcmp (key, GPM_LOCKDOWN_COMMAND_LINE) == 0) _pluma_app_set_lockdown_bit (app, PLUMA_LOCKDOWN_COMMAND_LINE, locked); else if (strcmp (key, GPM_LOCKDOWN_PRINTING) == 0) _pluma_app_set_lockdown_bit (app, PLUMA_LOCKDOWN_PRINTING, locked); else if (strcmp (key, GPM_LOCKDOWN_PRINT_SETUP) == 0) _pluma_app_set_lockdown_bit (app, PLUMA_LOCKDOWN_PRINT_SETUP, locked); else if (strcmp (key, GPM_LOCKDOWN_SAVE_TO_DISK) == 0) _pluma_app_set_lockdown_bit (app, PLUMA_LOCKDOWN_SAVE_TO_DISK, locked); }
static void pluma_prefs_manager_source_style_scheme_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) { static gchar *old_scheme = NULL; gchar *scheme; GtkSourceStyleScheme *style; GList *docs; GList *l; scheme = g_settings_get_string (settings, key); if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) return; g_free (old_scheme); old_scheme = scheme; style = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), scheme); if (style == NULL) { g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); style = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), "classic"); if (style == NULL) { g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); return; } } docs = pluma_app_get_documents (pluma_app_get_default ()); for (l = docs; l != NULL; l = l->next) { g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); } g_list_free (docs); } }
static void draw_spaces (PlumaDrawspacesPlugin *plugin) { const GList *windows, *l; windows = pluma_app_get_windows (pluma_app_get_default ()); for (l = windows; l != NULL; l = g_list_next (l)) { draw_spaces_in_window (l->data, plugin); } }
static void pluma_prefs_manager_editor_font_changed (GSettings *settings, gchar *key, gpointer user_data) { GList *views; GList *l; gchar *font = NULL; gboolean def = TRUE; gint ts; pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) { def = g_settings_get_boolean (settings, key); if (def) font = pluma_prefs_manager_get_system_font (); else font = pluma_prefs_manager_get_editor_font (); } else if (strcmp (key, GPM_EDITOR_FONT) == 0) { font = g_settings_get_string (settings, key); def = pluma_prefs_manager_get_use_default_font (); } else return; g_return_if_fail (font != NULL); ts = pluma_prefs_manager_get_tabs_size (); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { /* Note: we use def=FALSE to avoid PlumaView to query GSettings */ pluma_view_set_font (PLUMA_VIEW (l->data), FALSE, font); gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); l = l->next; } g_list_free (views); g_free (font); }
static void pluma_plugins_engine_activate_plugin_real (PlumaPluginsEngine *engine, PlumaPluginInfo *info) { const GList *wins; if (!load_plugin (engine, info)) return; for (wins = pluma_app_get_windows (pluma_app_get_default ()); wins != NULL; wins = wins->next) { pluma_plugin_activate (info->plugin, PLUMA_WINDOW (wins->data)); } }
static void pluma_prefs_manager_system_font_changed (GSettings *settings, gchar *key, gpointer user_data) { GList *views; GList *l; gchar *font; gint ts; pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SYSTEM_FONT) != 0) return; if (!pluma_prefs_manager_get_use_default_font ()) return; font = g_settings_get_string (settings, key); ts = pluma_prefs_manager_get_tabs_size (); views = pluma_app_get_views (pluma_app_get_default ()); l = views; while (l != NULL) { /* Note: we use def=FALSE to avoid PlumaView to query GSettings */ pluma_view_set_font (PLUMA_VIEW (l->data), FALSE, font); gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); l = l->next; } g_list_free (views); g_free (font); }
int main (int argc, char *argv[]) { GOptionContext *context; PlumaPluginsEngine *engine; PlumaWindow *window; PlumaApp *app; gboolean restored = FALSE; GError *error = NULL; gchar *dir; gchar *icon_dir; /* Setup debugging */ pluma_debug_init (); pluma_debug_message (DEBUG_APP, "Startup"); setlocale (LC_ALL, ""); dir = pluma_dirs_get_pluma_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, dir); g_free (dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); startup_timestamp = get_startup_timestamp(); /* Setup command line options */ context = g_option_context_new (_("- Edit text files")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (FALSE)); g_option_context_add_group (context, egg_sm_client_get_option_group ()); gtk_init (&argc, &argv); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); pluma_debug_message (DEBUG_APP, "Create bacon connection"); connection = bacon_message_connection_new ("pluma"); if (connection != NULL) { if (!bacon_message_connection_get_is_server (connection)) { pluma_debug_message (DEBUG_APP, "I'm a client"); pluma_get_command_line_data (); send_bacon_message (); free_command_line_data (); /* we never popup a window... tell startup-notification * that we are done. */ gdk_notify_startup_complete (); bacon_message_connection_free (connection); exit (0); } else { pluma_debug_message (DEBUG_APP, "I'm a server"); bacon_message_connection_set_callback (connection, on_message_received, NULL); } } else { g_warning ("Cannot create the 'pluma' connection."); } pluma_debug_message (DEBUG_APP, "Set icon"); dir = pluma_dirs_get_pluma_data_dir (); icon_dir = g_build_filename (dir, "icons", NULL); g_free (dir); gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_dir); g_free (icon_dir); /* Set the associated .desktop file */ egg_set_desktop_file (DATADIR "/applications/pluma.desktop"); /* Load user preferences */ pluma_debug_message (DEBUG_APP, "Init prefs manager"); pluma_prefs_manager_app_init (); /* Init plugins engine */ pluma_debug_message (DEBUG_APP, "Init plugins"); engine = pluma_plugins_engine_get_default (); /* Initialize session management */ pluma_debug_message (DEBUG_APP, "Init session manager"); pluma_session_init (); if (pluma_session_is_restored ()) restored = pluma_session_load (); if (!restored) { pluma_debug_message (DEBUG_APP, "Analyze command line data"); pluma_get_command_line_data (); pluma_debug_message (DEBUG_APP, "Get default app"); app = pluma_app_get_default (); pluma_debug_message (DEBUG_APP, "Create main window"); window = pluma_app_create_window (app, NULL); if (file_list != NULL) { const PlumaEncoding *encoding = NULL; if (encoding_charset) encoding = pluma_encoding_get_from_charset (encoding_charset); pluma_debug_message (DEBUG_APP, "Load files"); _pluma_cmd_load_files_from_prompt (window, file_list, encoding, line_position); } else { pluma_debug_message (DEBUG_APP, "Create tab"); pluma_window_create_tab (window, TRUE); } pluma_debug_message (DEBUG_APP, "Show window"); gtk_widget_show (GTK_WIDGET (window)); free_command_line_data (); } pluma_debug_message (DEBUG_APP, "Start gtk-main"); gtk_main(); bacon_message_connection_free (connection); /* We kept the original engine reference here. So let's unref it to * finalize it properly. */ g_object_unref (engine); pluma_prefs_manager_app_shutdown (); #ifndef ENABLE_GVFS_METADATA pluma_metadata_manager_shutdown (); #endif return 0; }
/* serverside */ static void on_message_received (const char *message, gpointer data) { const PlumaEncoding *encoding = NULL; gchar **commands; gchar **params; gint workspace; gint viewport_x; gint viewport_y; gchar *display_name; gint screen_number; gint i; PlumaApp *app; PlumaWindow *window; GdkDisplay *display; GdkScreen *screen; g_return_if_fail (message != NULL); pluma_debug_message (DEBUG_APP, "Received message:\n%s\n", message); commands = g_strsplit (message, "\v", -1); /* header */ params = g_strsplit (commands[0], "\t", 6); startup_timestamp = atoi (params[0]); display_name = params[1]; screen_number = atoi (params[2]); workspace = atoi (params[3]); viewport_x = atoi (params[4]); viewport_y = atoi (params[5]); display = display_open_if_needed (display_name); if (display == NULL) { g_warning ("Could not open display %s\n", display_name); g_strfreev (params); goto out; } screen = gdk_display_get_screen (display, screen_number); g_strfreev (params); /* body */ for (i = 1; commands[i] != NULL; i++) { params = g_strsplit (commands[i], "\t", -1); if (strcmp (params[0], "NEW-WINDOW") == 0) { new_window_option = TRUE; } else if (strcmp (params[0], "NEW-DOCUMENT") == 0) { new_document_option = TRUE; } else if (strcmp (params[0], "OPEN-URIS") == 0) { gint n_uris, j; gchar **uris; line_position = atoi (params[1]); if (params[2] != '\0') encoding = pluma_encoding_get_from_charset (params[2]); n_uris = atoi (params[3]); uris = g_strsplit (params[4], " ", n_uris); for (j = 0; j < n_uris; j++) { GFile *file; file = g_file_new_for_uri (uris[j]); file_list = g_slist_prepend (file_list, file); } file_list = g_slist_reverse (file_list); /* the list takes ownerhip of the strings, * only free the array */ g_free (uris); } else { g_warning ("Unexpected bacon command"); } g_strfreev (params); } /* execute the commands */ app = pluma_app_get_default (); if (new_window_option) { window = pluma_app_create_window (app, screen); } else { /* get a window in the current workspace (if exists) and raise it */ window = _pluma_app_get_window_in_viewport (app, screen, workspace, viewport_x, viewport_y); } if (file_list != NULL) { _pluma_cmd_load_files_from_prompt (window, file_list, encoding, line_position); if (new_document_option) pluma_window_create_tab (window, TRUE); } else { PlumaDocument *doc; doc = pluma_window_get_active_document (window); if (doc == NULL || !pluma_document_is_untouched (doc) || new_document_option) pluma_window_create_tab (window, TRUE); } /* set the proper interaction time on the window. * Fall back to roundtripping to the X server when we * don't have the timestamp, e.g. when launched from * terminal. We also need to make sure that the window * has been realized otherwise it will not work. lame. */ if (!gtk_widget_get_realized (GTK_WIDGET (window))) gtk_widget_realize (GTK_WIDGET (window)); if (startup_timestamp <= 0) startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window))); gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), startup_timestamp); gtk_window_present (GTK_WINDOW (window)); out: g_strfreev (commands); free_command_line_data (); }