int main (int argc, char *argv[]) { const gchar *dir; GeditCommandLine *command_line; gboolean ret; gboolean service = FALSE; #ifdef G_OS_UNIX GeditDBus *dbus; GeditDBusResult dbusret; #endif #ifdef OS_OSX GPollFunc orig_poll_func; GPollFunc gdk_poll_func; #endif #ifndef ENABLE_GVFS_METADATA const gchar *cache_dir; gchar *metadata_filename; #endif /* Setup debugging */ gedit_debug_init (); gedit_debug_message (DEBUG_APP, "Startup"); /* Setup locale/gettext */ setlocale (LC_ALL, ""); gedit_dirs_init (); dir = gedit_dirs_get_gedit_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifndef ENABLE_GVFS_METADATA /* Setup metadata-manager */ cache_dir = gedit_dirs_get_user_cache_dir (); metadata_filename = g_build_filename (cache_dir, METADATA_FILE, NULL); gedit_metadata_manager_init (metadata_filename); g_free (metadata_filename); #endif #ifdef OS_OSX orig_poll_func = g_main_context_get_poll_func (NULL); #endif /* Parse command line arguments */ command_line = gedit_command_line_get_default (); ret = gedit_command_line_parse (command_line, &argc, &argv); if (!ret) { g_object_unref (command_line); return 1; } #ifdef G_OS_UNIX #ifdef OS_OSX /* Note: this is a bit of a hack. What happens here is that we are going to * store the poll function installed by gdk (happens in post-parse of options) * and replace it with the original main loop poll handler. We do this because * the gedit dbus stuff is going to run some main loops to run async gdbus calls. * The problem is that for OS X, the gdk poll func in the main context (which * will be run due to the fact that the main loops in our dbus code iterate the * main context) is going to process events from NSApp, INCLUDING apple events * such as OpenFiles. Since we are not setup yet, we are going to miss these * events. By swapping out the gdk poll func, and swapping it back in later, * we prevent this from happening. Note that we only do this when building * on OS X to prevent any possible future problems for other platforms. * This is a dirty hack, but it works for now. */ gdk_poll_func = g_main_context_get_poll_func (NULL); g_main_context_set_poll_func (NULL, orig_poll_func); #endif /* Run over dbus */ dbus = gedit_dbus_new (); dbusret = gedit_dbus_run (dbus); #ifdef OS_OSX g_main_context_set_poll_func (NULL, gdk_poll_func); #endif switch (dbusret) { case GEDIT_DBUS_RESULT_SUCCESS: case GEDIT_DBUS_RESULT_FAILED: /* fallthrough */ g_object_unref (command_line); g_object_unref (dbus); return dbusret == GEDIT_DBUS_RESULT_SUCCESS ? 0 : 1; break; case GEDIT_DBUS_RESULT_PROCEED_SERVICE: service = TRUE; break; case GEDIT_DBUS_RESULT_PROCEED: break; } #endif gedit_main (service); #ifdef G_OS_UNIX g_object_unref (dbus); #endif g_object_unref (command_line); return 0; }
static void gedit_app_startup (GApplication *application) { GeditAppPrivate *priv; GtkCssProvider *css_provider; GtkSourceStyleSchemeManager *manager; const gchar *dir; gchar *icon_dir; #ifndef ENABLE_GVFS_METADATA const gchar *cache_dir; gchar *metadata_filename; #endif priv = gedit_app_get_instance_private (GEDIT_APP (application)); G_APPLICATION_CLASS (gedit_app_parent_class)->startup (application); /* Setup debugging */ gedit_debug_init (); gedit_debug_message (DEBUG_APP, "Startup"); gedit_debug_message (DEBUG_APP, "Set icon"); dir = gedit_dirs_get_gedit_data_dir (); icon_dir = g_build_filename (dir, "icons", NULL); gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_dir); g_free (icon_dir); setup_theme_extensions (GEDIT_APP (application)); #ifndef ENABLE_GVFS_METADATA cache_dir = gedit_dirs_get_user_cache_dir (); metadata_filename = g_build_filename (cache_dir, "gedit-metadata.xml", NULL); gedit_metadata_manager_init (metadata_filename); g_free (metadata_filename); #endif /* Load settings */ priv->settings = gedit_settings_new (); priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui"); priv->window_settings = g_settings_new ("org.gnome.gedit.state.window"); /* initial lockdown state */ priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (priv->settings)); g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application); /* menus */ priv->window_menu = gtk_application_get_menubar (GTK_APPLICATION (application)); if (priv->window_menu == NULL) { priv->window_menu = get_menu_model (GEDIT_APP (application), "gear-menu"); } else { g_object_ref (priv->window_menu); } priv->notebook_menu = get_menu_model (GEDIT_APP (application), "notebook-menu"); priv->tab_width_menu = get_menu_model (GEDIT_APP (application), "tab-width-menu"); priv->line_col_menu = get_menu_model (GEDIT_APP (application), "line-col-menu"); /* Accelerators */ add_accelerator (GTK_APPLICATION (application), "app.new-window", "<Primary>N"); add_accelerator (GTK_APPLICATION (application), "app.quit", "<Primary>Q"); add_accelerator (GTK_APPLICATION (application), "app.help", "F1"); add_accelerator (GTK_APPLICATION (application), "win.gear-menu", "F10"); add_accelerator (GTK_APPLICATION (application), "win.open", "<Primary>O"); add_accelerator (GTK_APPLICATION (application), "win.save", "<Primary>S"); add_accelerator (GTK_APPLICATION (application), "win.save-as", "<Primary><Shift>S"); add_accelerator (GTK_APPLICATION (application), "win.save-all", "<Primary><Shift>L"); add_accelerator (GTK_APPLICATION (application), "win.new-tab", "<Primary>T"); add_accelerator (GTK_APPLICATION (application), "win.reopen-closed-tab", "<Primary><Shift>T"); add_accelerator (GTK_APPLICATION (application), "win.close", "<Primary>W"); add_accelerator (GTK_APPLICATION (application), "win.close-all", "<Primary><Shift>W"); add_accelerator (GTK_APPLICATION (application), "win.print", "<Primary>P"); add_accelerator (GTK_APPLICATION (application), "win.find", "<Primary>F"); add_accelerator (GTK_APPLICATION (application), "win.find-next", "<Primary>G"); add_accelerator (GTK_APPLICATION (application), "win.find-prev", "<Primary><Shift>G"); add_accelerator (GTK_APPLICATION (application), "win.replace", "<Primary>H"); add_accelerator (GTK_APPLICATION (application), "win.clear-highlight", "<Primary><Shift>K"); add_accelerator (GTK_APPLICATION (application), "win.goto-line", "<Primary>I"); add_accelerator (GTK_APPLICATION (application), "win.focus-active-view", "Escape"); add_accelerator (GTK_APPLICATION (application), "win.side-panel", "F9"); add_accelerator (GTK_APPLICATION (application), "win.bottom-panel", "<Primary>F9"); add_accelerator (GTK_APPLICATION (application), "win.fullscreen", "F11"); add_accelerator (GTK_APPLICATION (application), "win.new-tab-group", "<Primary><Alt>N"); add_accelerator (GTK_APPLICATION (application), "win.previous-tab-group", "<Primary><Shift><Alt>Page_Up"); add_accelerator (GTK_APPLICATION (application), "win.next-tab-group", "<Primary><Shift><Alt>Page_Down"); add_accelerator (GTK_APPLICATION (application), "win.previous-document", "<Primary><Alt>Page_Up"); add_accelerator (GTK_APPLICATION (application), "win.next-document", "<Primary><Alt>Page_Down"); load_accels (); /* Load custom css */ g_object_unref (load_css_from_resource ("gedit-style.css", TRUE)); css_provider = load_css_from_resource ("gedit-style-os.css", FALSE); g_clear_object (&css_provider); /* * We use the default gtksourceview style scheme manager so that plugins * can obtain it easily without a gedit specific api, but we need to * add our search path at startup before the manager is actually used. */ manager = gtk_source_style_scheme_manager_get_default (); gtk_source_style_scheme_manager_append_search_path (manager, gedit_dirs_get_user_styles_dir ()); priv->engine = gedit_plugins_engine_get_default (); priv->extensions = peas_extension_set_new (PEAS_ENGINE (priv->engine), GEDIT_TYPE_APP_ACTIVATABLE, "app", GEDIT_APP (application), NULL); g_signal_connect (priv->extensions, "extension-added", G_CALLBACK (extension_added), application); g_signal_connect (priv->extensions, "extension-removed", G_CALLBACK (extension_removed), application); peas_extension_set_foreach (priv->extensions, (PeasExtensionSetForeachFunc) extension_added, application); }