Esempio n. 1
0
void
ide_editor_frame_actions_init (IdeEditorFrame *self)
{
  GSimpleActionGroup *group;
  GAction *action;

  g_assert (IDE_IS_EDITOR_FRAME (self));

  group = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (group), IdeEditorFrameActions,
                                   G_N_ELEMENTS (IdeEditorFrameActions), self);
  gtk_widget_insert_action_group (GTK_WIDGET (self), "frame", G_ACTION_GROUP (group));
  g_object_unref (group);

  group = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (group), IdeEditorFrameSearchActions,
                                   G_N_ELEMENTS (IdeEditorFrameSearchActions), self);

  /* Disable replace and replace-all by default; they should only be enabled
   * when the corresponding operations would make sense.
   */
  action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace");
  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
  action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace-all");
  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);

  gtk_widget_insert_action_group (GTK_WIDGET (self->search_frame), "search-entry", G_ACTION_GROUP (group));
  g_object_unref (group);
}
void
ide_editor_view_actions_init (IdeEditorView *self)
{
  g_autoptr(GSimpleActionGroup) group = NULL;

  group = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (group), IdeEditorViewActions,
                                   G_N_ELEMENTS (IdeEditorViewActions), self);
  gtk_widget_insert_action_group (GTK_WIDGET (self), "view", G_ACTION_GROUP (group));
  gtk_widget_insert_action_group (GTK_WIDGET (self->tweak_widget), "view", G_ACTION_GROUP (group));

#define WATCH_PROPERTY(name) \
  G_STMT_START { \
    g_signal_connect (self->frame1->source_view, \
                      "notify::"name, \
                      G_CALLBACK (ide_editor_view_actions_source_view_notify), \
                      group); \
    g_object_notify (G_OBJECT (self->frame1->source_view), name); \
  } G_STMT_END

  WATCH_PROPERTY ("auto-indent");
  WATCH_PROPERTY ("highlight-current-line");
  WATCH_PROPERTY ("insert-spaces-instead-of-tabs");
  WATCH_PROPERTY ("show-line-numbers");
  WATCH_PROPERTY ("show-right-margin");
  WATCH_PROPERTY ("smart-backspace");
  WATCH_PROPERTY ("tab-width");

#undef WATCH_PROPERTY
}
void
gb_project_tree_actions_init (GbProjectTree *self)
{
  g_autoptr(GSettings) settings = NULL;
  g_autoptr(GSettings) tree_settings = NULL;
  g_autoptr(GSimpleActionGroup) actions = NULL;
  g_autoptr(GAction) action = NULL;
  g_autoptr(GVariant) show_icons = NULL;

  actions = g_simple_action_group_new ();

  settings = g_settings_new ("org.gtk.Settings.FileChooser");
  action = g_settings_create_action (settings, "sort-directories-first");
  g_action_map_add_action (G_ACTION_MAP (actions), action);

  g_action_map_add_action_entries (G_ACTION_MAP (actions),
                                   GbProjectTreeActions,
                                   G_N_ELEMENTS (GbProjectTreeActions),
                                   self);
  gtk_widget_insert_action_group (GTK_WIDGET (self),
                                  "project-tree",
                                  G_ACTION_GROUP (actions));

  tree_settings = g_settings_new ("org.gnome.builder.project-tree");
  show_icons = g_settings_get_value (tree_settings, "show-icons");
  action_set (G_ACTION_GROUP (actions), "show-icons",
              "state", show_icons,
              NULL);

  gb_project_tree_actions_update (self);
}
int
main (int argc, char **argv)
{
  GApplication *app;
  int status;

  app = g_application_new ("org.gtk.TestApplication", 0);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  g_application_set_inactivity_timeout (app, 10000);

  add_actions (app);

  if (argc > 1 && strcmp (argv[1], "--simple-action") == 0)
    {
      g_application_register (app, NULL, NULL);
      g_action_group_activate_action (G_ACTION_GROUP (app), "simple-action", NULL);
      exit (0);
    }
  else if (argc > 1 && strcmp (argv[1], "--toggle-action") == 0)
    {
      g_application_register (app, NULL, NULL);
      g_action_group_activate_action (G_ACTION_GROUP (app), "toggle-action", NULL);
      exit (0);
    }

  status = g_application_run (app, argc, argv);

  g_object_unref (app);

  return status;
}
Esempio n. 5
0
static void
gtk_application_window_real_realize (GtkWidget *widget)
{
  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
  GtkApplication *application;
  GtkSettings *settings;

  application = gtk_window_get_application (GTK_WINDOW (window));
  settings = gtk_widget_get_settings (widget);

  g_signal_connect (settings, "notify::gtk-shell-shows-app-menu",
                    G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window);
  g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
                    G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);

  if (!window->priv->muxer_initialised)
    {
      g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "app", G_ACTION_GROUP (application));
      g_action_muxer_insert (G_ACTION_MUXER (window->priv->muxer), "win", G_ACTION_GROUP (window));
      window->priv->muxer_initialised = TRUE;
    }

  gtk_application_window_update_shell_shows_app_menu (window, settings);
  gtk_application_window_update_shell_shows_menubar (window, settings);
  gtk_application_window_update_menubar (window);
  gtk_application_window_update_accels (window);

  GTK_WIDGET_CLASS (gtk_application_window_parent_class)
    ->realize (widget);

#ifdef GDK_WINDOWING_X11
  {
    GdkWindow *gdkwindow;

    gdkwindow = gtk_widget_get_window (GTK_WIDGET (window));

    if (GDK_IS_X11_WINDOW (gdkwindow) && window->priv->session)
      {
        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_ID",
                                          g_application_get_application_id (G_APPLICATION (application)));

        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_UNIQUE_BUS_NAME",
                                          g_dbus_connection_get_unique_name (window->priv->session));

        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APPLICATION_OBJECT_PATH",
                                          g_application_get_dbus_object_path (G_APPLICATION (application)));

        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_WINDOW_OBJECT_PATH",
                                          window->priv->object_path);

        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_APP_MENU_OBJECT_PATH",
                                          gtk_application_get_app_menu_object_path (application));

        gdk_x11_window_set_utf8_property (gdkwindow, "_GTK_MENUBAR_OBJECT_PATH",
                                          gtk_application_get_menubar_object_path (application));
      }
  }
#endif
}
Esempio n. 6
0
static void
ide_run_manager_notify_busy (IdeRunManager *self)
{
  g_assert (IDE_IS_RUN_MANAGER (self));

  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUSY]);
  g_action_group_action_enabled_changed (G_ACTION_GROUP (self), "run", self->busy == FALSE);
  g_action_group_action_enabled_changed (G_ACTION_GROUP (self), "run-with-handler", self->busy == FALSE);
  g_action_group_action_enabled_changed (G_ACTION_GROUP (self), "stop", self->busy == TRUE);
}
static void
activate_action (GtkWidget   *widget,
                 const gchar *prefix,
                 const gchar *action_name,
                 GVariant    *parameter)
{
    GApplication *app;
    GtkWidget *toplevel;
    GActionGroup *group = NULL;

    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_return_if_fail (prefix);
    g_return_if_fail (action_name);

    g_print ("activate!\n");

    app = g_application_get_default ();
    toplevel = gtk_widget_get_toplevel (widget);

    while ((group == NULL) && (widget != NULL))
    {
        group = gtk_widget_get_action_group (widget, prefix);
        widget = gtk_widget_get_parent (widget);
    }

    if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
        group = G_ACTION_GROUP (toplevel);

    if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
        group = G_ACTION_GROUP (app);

    if (group)
    {
        if (g_action_group_has_action (group, action_name))
        {
            g_print ("Activating %s.%s\n", prefix, action_name);
            g_action_group_activate_action (group, action_name, parameter);
            return;
        }
    }

    if (parameter && g_variant_is_floating (parameter))
    {
        parameter = g_variant_ref_sink (parameter);
        g_variant_unref (parameter);
    }

    g_warning ("Failed to resolve action %s.%s", prefix, action_name);
}
static void
action_enter_location_callback (GtkAction *action,
                                gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "enter-location", NULL);
}
static void
bus_acquired (GDBusConnection *connection,
              const gchar     *name,
              gpointer         user_data)
{
  IndicatorTestService *indicator = user_data;
  GError *error = NULL;

  indicator->actions_export_id = g_dbus_connection_export_action_group (connection,
                                                                        "/com/canonical/indicator/test",
                                                                        G_ACTION_GROUP (indicator->actions),
                                                                        &error);
  if (indicator->actions_export_id == 0)
    {
      g_warning ("cannot export action group: %s", error->message);
      g_error_free (error);
      return;
    }

  indicator->menu_export_id = g_dbus_connection_export_menu_model (connection,
                                                                   "/com/canonical/indicator/test/desktop",
                                                                   G_MENU_MODEL (indicator->menu),
                                                                   &error);
  if (indicator->menu_export_id == 0)
    {
      g_warning ("cannot export menu: %s", error->message);
      g_error_free (error);
      return;
    }
}
Esempio n. 10
0
static void
gtk_application_window_init (GtkApplicationWindow *window)
{
    window->priv = gtk_application_window_get_instance_private (window);

    window->priv->actions = gtk_application_window_actions_new (window);
    window->priv->app_menu_section = g_menu_new ();
    window->priv->menubar_section = g_menu_new ();
    window->priv->accels = gtk_accel_group_new ();
    gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accels);

    gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (window->priv->actions));

    /* window->priv->actions is the one and only ref on the group, so when
     * we dispose, the action group will die, disconnecting all signals.
     */
    g_signal_connect_swapped (window->priv->actions, "action-added",
                              G_CALLBACK (g_action_group_action_added), window);
    g_signal_connect_swapped (window->priv->actions, "action-enabled-changed",
                              G_CALLBACK (g_action_group_action_enabled_changed), window);
    g_signal_connect_swapped (window->priv->actions, "action-state-changed",
                              G_CALLBACK (g_action_group_action_state_changed), window);
    g_signal_connect_swapped (window->priv->actions, "action-removed",
                              G_CALLBACK (g_action_group_action_removed), window);
}
static void
action_about_nautilus_callback (GtkAction *action,
                                gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "about", NULL);
}
Esempio n. 12
0
static void
g_dbus_action_group_describe_all_done (GObject      *source,
                                       GAsyncResult *result,
                                       gpointer      user_data)
{
  GDBusActionGroup *group= user_data;
  GVariant *reply;

  g_assert (group->actions == NULL);
  group->actions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, action_info_free);

  g_assert (group->connection == (gpointer) source);
  reply = g_dbus_connection_call_finish (group->connection, result, NULL);

  if (reply != NULL)
    {
      GVariantIter *iter;
      ActionInfo *action;

      g_variant_get (reply, "(a{s(bgav)})", &iter);
      while ((action = action_info_new_from_iter (iter)))
        {
          g_hash_table_insert (group->actions, action->name, action);

          if (group->strict)
            g_action_group_action_added (G_ACTION_GROUP (group), action->name);
        }
      g_variant_iter_free (iter);
      g_variant_unref (reply);
    }

  g_object_unref (group);
}
static void
action_bookmarks_callback (GtkAction *action,
                           gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "bookmarks", NULL);
}
static void
action_connect_to_server_callback (GtkAction *action,
                                   gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "connect-to-server", NULL);
}
Esempio n. 15
0
/**
 * gpm_applet_cb:
 * @_applet: GpmInhibitApplet instance created by the applet factory
 * @iid: Applet id
 *
 * the function called by libpanel-applet factory after creation
 **/
static gboolean
gpm_applet_cb (PanelApplet *_applet, const gchar *iid, gpointer data)
{
	GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(_applet);
	GSimpleActionGroup *action_group;
	gchar *ui_path;

	static const GActionEntry menu_actions [] = {
		{ "about", gpm_applet_dialog_about_cb, NULL, NULL, NULL },
	};

	if (strcmp (iid, GPM_INHIBIT_APPLET_ID) != 0) {
		return FALSE;
	}

	action_group = g_simple_action_group_new ();
	g_action_map_add_action_entries (G_ACTION_MAP (action_group),
					 menu_actions,
					 G_N_ELEMENTS (menu_actions),
					 applet);
	ui_path = g_build_filename (INHIBIT_MENU_UI_DIR, "inhibit-applet-menu.xml", NULL);
	panel_applet_setup_menu_from_file (PANEL_APPLET (applet), ui_path, action_group, GETTEXT_PACKAGE);
	g_free (ui_path);

	gtk_widget_insert_action_group (GTK_WIDGET (applet), "inhibit",
					G_ACTION_GROUP (action_group));

	g_object_unref (action_group);

	return TRUE;
}
static void
action_new_window_callback (GtkAction *action,
                            gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "new-window", NULL);
}
static void
action_close_all_windows_callback (GtkAction *action,
                                   gpointer user_data)
{
    g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
                                    "quit", NULL);
}
Esempio n. 18
0
static gboolean
geyes_applet_fill (PanelApplet *applet)
{
	EyesApplet *eyes_applet;
	GSimpleActionGroup *action_group;
	GAction *action;
	gchar *ui_path;

	panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
	
        eyes_applet = create_eyes (applet);

	eyes_applet->settings = panel_applet_settings_new (applet, GEYES_PREFS_SCHEMA);

        eyes_applet->timeout_id = g_timeout_add (
		UPDATE_TIMEOUT, (GSourceFunc) timer_cb, eyes_applet);

	action_group = g_simple_action_group_new ();
	g_action_map_add_action_entries (G_ACTION_MAP (action_group),
	                                 geyes_applet_menu_actions,
	                                 G_N_ELEMENTS (geyes_applet_menu_actions),
	                                 eyes_applet);
	ui_path = g_build_filename (GEYES_MENU_UI_DIR, "geyes-applet-menu.xml", NULL);
	panel_applet_setup_menu_from_file (eyes_applet->applet,
					   ui_path, action_group,
					   GETTEXT_PACKAGE);
	g_free (ui_path);

	gtk_widget_insert_action_group (GTK_WIDGET (applet), "geyes",
	                                G_ACTION_GROUP (action_group));

	action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
	g_object_bind_property (applet, "locked-down",
	                        action, "enabled",
	                        G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);

	g_object_unref (action_group);

	gtk_widget_set_tooltip_text (GTK_WIDGET (eyes_applet->applet), _("Eyes"));

	set_atk_name_description (GTK_WIDGET (eyes_applet->applet), _("Eyes"), 
			_("The eyes look in the direction of the mouse pointer"));

	g_signal_connect (eyes_applet->vbox,
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  eyes_applet);

	gtk_widget_show_all (GTK_WIDGET (eyes_applet->applet));

	/* setup here and not in create eyes so the destroy signal is set so 
	 * that when there is an error within loading the theme
	 * we can emit this signal */
        if (properties_load (eyes_applet) == FALSE)
		return FALSE;

	setup_eyes (eyes_applet);

	return TRUE;
}
static void
gb_preferences_switch_update_settings (GbPreferencesSwitch *self)
{
  g_assert (GB_IS_PREFERENCES_SWITCH (self));

  if ((self->settings != NULL) && (self->settings_schema_key != NULL))
    {
      GSimpleActionGroup *group;
      GAction *action;
      gchar *name;

      action = g_settings_create_action (self->settings, self->settings_schema_key);
      group = g_simple_action_group_new ();
      g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action));
      gtk_widget_insert_action_group (GTK_WIDGET (self), "settings", G_ACTION_GROUP (group));
      g_object_unref (action);

      name = g_strdup_printf ("settings.%s", self->settings_schema_key);

      if (self->is_radio)
        {
          gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_radio), name);
          gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_switch), NULL);
        }
      else
        {
          gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_radio), NULL);
          gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_switch), name);
        }

      g_free (name);
    }
}
Esempio n. 20
0
void
update_undo_sensitivity (void)
{
  /* Unfortunately, this does not change the state of undo button in app menu :( */
  gboolean enable = UndoVisible ();
  gboolean result = g_action_group_query_action (G_ACTION_GROUP (application), "Undo", &enable, NULL, NULL, NULL, NULL);
}
Esempio n. 21
0
static void
photos_searchbar_enable_search (PhotosSearchbar *self, gboolean enable)
{
  GVariant *state;

  state = g_variant_new ("b", enable);
  g_action_group_change_action_state (G_ACTION_GROUP (self->priv->app), "search", state);
}
Esempio n. 22
0
static gboolean
egg_empty_state_action (GtkWidget   *widget,
                        const gchar *prefix,
                        const gchar *action_name,
                        GVariant    *parameter)
{
  GtkWidget *toplevel;
  GApplication *app;
  GActionGroup *group = NULL;

  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
  g_return_val_if_fail (prefix, FALSE);
  g_return_val_if_fail (action_name, FALSE);

  app = g_application_get_default ();
  toplevel = gtk_widget_get_toplevel (widget);

  while ((group == NULL) && (widget != NULL))
    {
      group = gtk_widget_get_action_group (widget, prefix);
      widget = gtk_widget_get_parent (widget);
    }

  if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
    group = G_ACTION_GROUP (toplevel);

  if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
    group = G_ACTION_GROUP (app);

  if (group && g_action_group_has_action (group, action_name))
    {
      g_action_group_activate_action (group, action_name, parameter);
      return TRUE;
    }

  if (parameter && g_variant_is_floating (parameter))
    {
      parameter = g_variant_ref_sink (parameter);
      g_variant_unref (parameter);
    }

  g_warning ("Failed to locate action %s.%s", prefix, action_name);

  return FALSE;
}
Esempio n. 23
0
/* Hack. We iterate over the accel map instead of the actions,
 * in order to pull the parameters out of accel map entries
 */
static void
add_accel_closure (gpointer         data,
                   const gchar     *accel_path,
                   guint            accel_key,
                   GdkModifierType  accel_mods,
                   gboolean         changed)
{
    GtkApplicationWindow *window = data;
    GActionGroup *actions;
    const gchar *path;
    const gchar *p;
    gchar *action_name;
    GVariant *parameter;
    AccelClosure *closure;

    if (accel_key == 0)
        return;

    if (!g_str_has_prefix (accel_path, "<GAction>/"))
        return;

    path = accel_path + strlen ("<GAction>/");
    p = strchr (path, '/');
    if (p)
    {
        action_name = g_strndup (path, p - path);
        parameter = g_variant_parse (NULL, p + 1, NULL, NULL, NULL);
        if (!parameter)
            g_warning ("Failed to parse parameter from '%s'\n", accel_path);
    }
    else
    {
        action_name = g_strdup (path);
        parameter = NULL;
    }

    actions = G_ACTION_GROUP (_gtk_widget_get_action_muxer (GTK_WIDGET (window)));
    if (g_action_group_has_action (actions, action_name))
    {
        closure = (AccelClosure*) g_closure_new_object (sizeof (AccelClosure), g_object_ref (actions));
        g_closure_set_marshal (&closure->closure, accel_activate);

        closure->action_name = g_strdup (action_name);
        closure->parameter = parameter ? g_variant_ref_sink (parameter) : NULL;

        window->priv->accel_closures = g_slist_prepend (window->priv->accel_closures, g_closure_ref (&closure->closure));
        g_closure_sink (&closure->closure);

        gtk_accel_group_connect_by_path (window->priv->accels, accel_path, &closure->closure);
    }
    else if (parameter)
    {
        g_variant_unref (parameter);
    }

    g_free (action_name);
}
Esempio n. 24
0
static void
gtk_application_window_activate_action (GActionGroup *group,
                                        const gchar  *action_name,
                                        GVariant     *parameter)
{
  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);

  return g_action_group_activate_action (G_ACTION_GROUP (window->priv->actions), action_name, parameter);
}
Esempio n. 25
0
static void
gtk_application_window_change_action_state (GActionGroup *group,
                                            const gchar  *action_name,
                                            GVariant     *state)
{
  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);

  return g_action_group_change_action_state (G_ACTION_GROUP (window->priv->actions), action_name, state);
}
Esempio n. 26
0
void
gstyle_color_widget_actions_init (GstyleColorWidget *self)
{
  g_autoptr (GSimpleActionGroup) action_group = NULL;

  action_group = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (action_group), actions,
                                   G_N_ELEMENTS (actions), self);
  gtk_widget_insert_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu", G_ACTION_GROUP (action_group));
}
Esempio n. 27
0
void
_ide_layout_stack_actions_init (IdeLayoutStack *self)
{
  g_assert (IDE_IS_LAYOUT_STACK (self));

  self->actions = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (self->actions), gbViewStackActions,
                                   G_N_ELEMENTS (gbViewStackActions), self);
  gtk_widget_insert_action_group (GTK_WIDGET (self), "view-stack", G_ACTION_GROUP (self->actions));
}
Esempio n. 28
0
/**
 * irc_context_get_action_group:
 *
 * Returns: (transfer full): Valid actions for this context
 */
GActionGroup *
irc_context_get_action_group (void)
{
	GSimpleActionGroup *group = g_simple_action_group_new ();
	GAction *close_action = irc_context_action_new ("close", irc_context_close);
	GAction *focus_action = irc_context_action_new ("focus", irc_context_focus);
	g_action_map_add_action (G_ACTION_MAP (group), close_action);
	g_action_map_add_action (G_ACTION_MAP (group), focus_action);
	return G_ACTION_GROUP (group);
}
Esempio n. 29
0
static void
activate (GApplication *app,
          gpointer      user_data)
{
    GtkWidget *win;
    GtkWidget *button;
    GSimpleActionGroup *doc_actions;
    GtkBuilder *builder;
    GMenuModel *doc_menu;
    GMenuModel *win_menu;
    GMenu *button_menu;
    GMenuItem *section;

    if (gtk_application_get_windows (GTK_APPLICATION (app)) != NULL)
        return;

    win = gtk_application_window_new (GTK_APPLICATION (app));

    doc_actions = g_simple_action_group_new ();
    g_action_map_add_action_entries (G_ACTION_MAP (doc_actions), doc_entries, G_N_ELEMENTS (doc_entries), win);

    g_action_map_add_action_entries (G_ACTION_MAP (win), win_entries,
                                     G_N_ELEMENTS (win_entries), win);

    builder = gtk_builder_new ();
    gtk_builder_add_from_string (builder, menu_ui, -1, NULL);

    doc_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "doc-menu"));
    win_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "win-menu"));

    button_menu = g_menu_new ();

    section = g_menu_item_new_section (NULL, doc_menu);
    g_menu_item_set_attribute (section, "action-namespace", "s", "doc");
    g_menu_append_item (button_menu, section);
    g_object_unref (section);

    section = g_menu_item_new_section (NULL, win_menu);
    g_menu_item_set_attribute (section, "action-namespace", "s", "win");
    g_menu_append_item (button_menu, section);
    g_object_unref (section);

    button = gtk_menu_button_new ();
    gtk_button_set_label (GTK_BUTTON (button), "Menu");
    gtk_widget_insert_action_group (button, "doc", G_ACTION_GROUP (doc_actions));
    gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (button_menu));

    gtk_container_add (GTK_CONTAINER (win), button);
    gtk_container_set_border_width (GTK_CONTAINER (win), 12);
    gtk_widget_show_all (win);

    g_object_unref (button_menu);
    g_object_unref (doc_actions);
    g_object_unref (builder);
}
Esempio n. 30
0
static GActionGroup *
get_group (void)
{
  GSimpleActionGroup *group;

  group = g_simple_action_group_new ();

  g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), NULL);

  return G_ACTION_GROUP (group);
}