Commit 6d19a449 authored by Ignacio Casal Quinteiro's avatar Ignacio Casal Quinteiro Committed by Paolo Borelli

Add app menu

Detect if we are running under gnome-shell and add items to the appmenu,
otherwise merge them in the normal uimanager menu
parent 8e291c9a
......@@ -264,6 +264,7 @@ EXTRA_DIST = \
gedit.rc \
gedit.gresource.xml \
gedit-ui.xml \
gedit-ui-fallback.xml \
gedit-encodings-dialog.ui \
gedit-preferences-dialog.ui \
gedit-replace-dialog.ui \
......
......@@ -55,6 +55,8 @@
#include "gedit-settings.h"
#include "gedit-app-activatable.h"
#include "gedit-plugins-engine.h"
#include "gedit-commands.h"
#include "gedit-preferences-dialog.h"
#ifndef ENABLE_GVFS_METADATA
#include "gedit-metadata-manager.h"
......@@ -306,6 +308,88 @@ gedit_app_set_window_title_impl (GeditApp *app,
gtk_window_set_title (GTK_WINDOW (window), title);
}
static void
new_window_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GeditApp *app;
GeditWindow *window;
app = GEDIT_APP (user_data);
window = gedit_app_create_window (app, NULL);
gedit_debug_message (DEBUG_APP, "Show window");
gtk_widget_show (GTK_WIDGET (window));
gedit_debug_message (DEBUG_APP, "Create tab");
gedit_window_create_tab (window, TRUE);
gtk_window_present (GTK_WINDOW (window));
}
static void
preferences_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkApplication *app;
GeditWindow *window;
app = GTK_APPLICATION (user_data);
window = GEDIT_WINDOW (gtk_application_get_active_window (app));
gedit_show_preferences_dialog (window);
}
static void
help_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkApplication *app;
GeditWindow *window;
app = GTK_APPLICATION (user_data);
window = GEDIT_WINDOW (gtk_application_get_active_window (app));
_gedit_cmd_help_contents (NULL, window);
}
static void
about_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkApplication *app;
GeditWindow *window;
app = GTK_APPLICATION (user_data);
window = GEDIT_WINDOW (gtk_application_get_active_window (app));
_gedit_cmd_help_about (NULL, window);
}
static void
quit_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GApplication *app;
app = G_APPLICATION (user_data);
g_application_quit (app);
}
static GActionEntry app_entries[] = {
{ "new_window", new_window_activated, NULL, NULL, NULL },
{ "preferences", preferences_activated, NULL, NULL, NULL },
{ "help", help_activated, NULL, NULL, NULL },
{ "about", about_activated, NULL, NULL, NULL },
{ "quit", quit_activated, NULL, NULL, NULL }
};
static void
extension_added (PeasExtensionSet *extensions,
PeasPluginInfo *info,
......@@ -379,6 +463,37 @@ gedit_app_startup (GApplication *application)
/* initial lockdown state */
app->priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (app->priv->settings));
/* app menu */
if (_gedit_app_has_app_menu (app))
{
GtkBuilder *builder;
GError *error = NULL;
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries,
G_N_ELEMENTS (app_entries),
app);
builder = gtk_builder_new ();
if (!gtk_builder_add_from_resource (builder,
"/org/gnome/gedit/ui/gedit-menu.ui",
&error))
{
g_warning ("loading menu builder file: %s", error->message);
g_error_free (error);
}
else
{
GMenuModel *app_menu;
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
gtk_application_set_app_menu (GTK_APPLICATION (application),
app_menu);
}
g_object_unref (builder);
}
/*
* We use the default gtksourceview style scheme manager so that plugins
* can obtain it easily without a gedit specific api, but we need to
......@@ -1420,4 +1535,21 @@ _gedit_app_get_settings (GeditApp *app)
return app->priv->settings;
}
gboolean
_gedit_app_has_app_menu (GeditApp *app)
{
GtkSettings *gtk_settings;
gboolean show_app_menu;
g_return_val_if_fail (GEDIT_IS_APP (app), FALSE);
gtk_settings = gtk_settings_get_default ();
g_object_get (G_OBJECT (gtk_settings),
"gtk-shell-shows-app-menu",
&show_app_menu,
NULL);
return show_app_menu;
}
/* ex:set ts=8 noet: */
......@@ -144,6 +144,8 @@ void _gedit_app_set_default_print_settings (GeditApp *app,
GObject *_gedit_app_get_settings (GeditApp *app);
gboolean _gedit_app_has_app_menu (GeditApp *app);
G_END_DECLS
#endif /* __GEDIT_APP_H__ */
......
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<menu id="appmenu">
<section>
<item>
<attribute name="label" translatable="yes">_New Window</attribute>
<attribute name="action">app.new_window</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">app.help</attribute>
<attribute name="accel">F1</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">app.quit</attribute>
<attribute name="accel">&lt;Primary&gt;q</attribute>
</item>
</section>
</menu>
</interface>
<!--
* gedit-ui.xml
* This file is part of gedit
*
* 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
* 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Modified by the gedit Team, 2005. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*
* $Id$
-->
<ui>
<menubar name="MenuBar">
<menu name="FileMenu" action="File">
<placeholder name="FileQuitMenuHolder">
<menuitem name="FileQuitMenu" action="FileQuit"/>
</placeholder>
</menu>
<menu name="EditMenu" action="Edit">
<placeholder name="EditPreferencesMenuHolder">
<menuitem name="EditPreferencesMenu" action="EditPreferences"/>
</placeholder>
</menu>
<menu name="HelpMenu" action="Help">
<placeholder name="HelpHolder">
<menuitem name="HelpContentsMenu" action="HelpContents"/>
<menuitem name="HelpAboutMenu" action="HelpAbout"/>
</placeholder>
</menu>
</menubar>
</ui>
......@@ -49,7 +49,7 @@
</placeholder>
<separator/>
<menuitem name="FileCloseMenu" action="FileClose"/>
<menuitem name="FileQuitMenu" action="FileQuit"/>
<placeholder name="FileQuitMenuHolder" />
</menu>
<menu name="EditMenu" action="Edit">
......@@ -72,7 +72,7 @@
<separator/>
<placeholder name="EditOps_6" />
<separator/>
<menuitem name="EditPreferencesMenu" action="EditPreferences"/>
<placeholder name="EditPreferencesMenuHolder" />
</menu>
<menu name="ViewMenu" action="View">
......@@ -150,9 +150,11 @@
</menu>
<menu name="HelpMenu" action="Help">
<menuitem name="HelpContentsMenu" action="HelpContents"/>
<menuitem name="HelpAboutMenu" action="HelpAbout"/>
<placeholder name="HelpOps_1" />
<separator/>
<placeholder name="HelpHolder" />
</menu>
</menubar>
<toolbar name="ToolBar">
......
......@@ -1576,6 +1576,19 @@ create_menu_bar_and_toolbar (GeditWindow *window,
return;
}
if (!_gedit_app_has_app_menu (GEDIT_APP (g_application_get_default ())))
{
gtk_ui_manager_add_ui_from_resource (manager,
"/org/gnome/gedit/ui/gedit-ui-fallback.xml",
&error);
if (error != NULL)
{
g_warning ("Could not add fallback ui definition: %s", error->message);
g_error_free (error);
return;
}
}
/* show tooltips in the statusbar */
g_signal_connect (manager,
"connect_proxy",
......
......@@ -2,6 +2,8 @@
<gresources>
<gresource prefix="/org/gnome/gedit/ui">
<file preprocess="xml-stripblanks">gedit-ui.xml</file>
<file preprocess="xml-stripblanks">gedit-ui-fallback.xml</file>
<file preprocess="xml-stripblanks">gedit-menu.ui</file>
<file preprocess="xml-stripblanks">gedit-encodings-dialog.ui</file>
<file preprocess="xml-stripblanks">gedit-preferences-dialog.ui</file>
<file preprocess="xml-stripblanks">gedit-replace-dialog.ui</file>
......
......@@ -20,6 +20,7 @@ gedit/gedit-encodings-dialog.c
[type: gettext/glade]gedit/gedit-encodings-dialog.ui
gedit/gedit-file-chooser-dialog.c
gedit/gedit-io-error-info-bar.c
[type: gettext/glade]gedit/gedit-menu.ui
gedit/gedit-notebook.c
gedit/gedit-notebook-popup-menu.c
gedit/gedit-open-tool-button.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment