/**
 * thunar_history_set_action_group:
 * @history      : a #ThunarHistory.
 * @action_group : a #GtkActionGroup or %NULL.
 *
 * Attaches @history to the specified @action_group,
 * and thereby registers the actions "back" and
 * "forward" provided by @history on the given
 * @action_group.
 **/
void
thunar_history_set_action_group (ThunarHistory  *history,
                                 GtkActionGroup *action_group)
{
  _thunar_return_if_fail (THUNAR_IS_HISTORY (history));
  _thunar_return_if_fail (action_group == NULL || GTK_IS_ACTION_GROUP (action_group));

  /* verify that we don't already use that action group */
  if (G_UNLIKELY (history->action_group == action_group))
    return;

  /* disconnect from the previous action group */
  if (G_UNLIKELY (history->action_group != NULL))
    {
      gtk_action_group_remove_action (history->action_group, history->action_back);
      gtk_action_group_remove_action (history->action_group, history->action_forward);
      g_object_unref (G_OBJECT (history->action_group));
    }

  /* activate the new action group */
  history->action_group = action_group;

  /* connect to the new action group */
  if (G_LIKELY (action_group != NULL))
    {
      g_object_ref (G_OBJECT (action_group));
      gtk_action_group_add_action_with_accel (action_group, history->action_back, "<alt>Left");
      gtk_action_group_add_action_with_accel (action_group, history->action_forward, "<alt>Right");
    }

  /* notify listeners */
  g_object_notify (G_OBJECT (history), "action-group");
}
void 
nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
{
	GtkActionGroup *action_group;
	GtkUIManager *ui_manager;
	GtkAction *action;
	
	action_group = gtk_action_group_new ("NavigationActions");
	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
	window->details->navigation_action_group = action_group;
	gtk_action_group_add_actions (action_group, 
				      navigation_entries, G_N_ELEMENTS (navigation_entries),
				      window);
	gtk_action_group_add_toggle_actions (action_group, 
					     navigation_toggle_entries, G_N_ELEMENTS (navigation_toggle_entries),
					     window);

	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
			       "name", "Back",
			       "label", _("_Back"),
			       "stock_id", GTK_STOCK_GO_BACK,
			       "tooltip", _("Go to the previous visited location"),
			       "arrow-tooltip", _("Back history"),
			       "window", window,
			       "direction", NAUTILUS_NAVIGATION_DIRECTION_BACK,
			       "is_important", TRUE,
			       NULL);
	g_signal_connect (action, "activate",
			  G_CALLBACK (action_back_callback), window);
	gtk_action_group_add_action_with_accel (action_group,
						action,
						"<alt>Left");
	g_object_unref (action);

	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
			       "name", "Forward",
			       "label", _("_Forward"),
			       "stock_id", GTK_STOCK_GO_FORWARD,
			       "tooltip", _("Go to the next visited location"),
			       "arrow-tooltip", _("Forward history"),
			       "window", window,
			       "direction", NAUTILUS_NAVIGATION_DIRECTION_FORWARD,
			       "is_important", TRUE,
			       NULL);
	g_signal_connect (action, "activate",
			  G_CALLBACK (action_forward_callback), window);
	gtk_action_group_add_action_with_accel (action_group,
						action,
						"<alt>Right");

	g_object_unref (action);

	action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_SEARCH);
	g_object_set (action, "short_label", _("_Search"), NULL);

	ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));

	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
	g_object_unref (action_group); /* owned by ui_manager */
}
예제 #3
0
파일: main.c 프로젝트: Swetha5/gnome-games
static void
create_game_menus (GtkUIManager * ui_manager)
{
  GtkActionGroup *action_group;
  games_stock_init ();

  action_group = gtk_action_group_new ("actions");

  gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
  gtk_action_group_add_actions (action_group, action_entry,
				G_N_ELEMENTS (action_entry), app);

  gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
  gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL);

  gtk_window_add_accel_group (GTK_WINDOW (app),
			      gtk_ui_manager_get_accel_group (ui_manager));

  new_game_action = gtk_action_group_get_action (action_group, "NewGame");

  hint_action = gtk_action_group_get_action (action_group, "Hint");
  undo_action = gtk_action_group_get_action (action_group, "UndoMove");
  fullscreen_action = GTK_ACTION (games_fullscreen_action_new ("Fullscreen", GTK_WINDOW (app)));
  gtk_action_group_add_action_with_accel (action_group, fullscreen_action, NULL);
}
예제 #4
0
/**
 * create_game_menus
 * @ap: application pointer
 *
 * Description:
 * Creates the menus for application @ap
 *
 **/
void
create_game_menus (GtkUIManager * ui_manager)
{

  GtkActionGroup *action_group;
  games_stock_init ();

  action_group = gtk_action_group_new ("actions");

  gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
  gtk_action_group_add_actions (action_group, action_entry,
				G_N_ELEMENTS (action_entry), app);
  gtk_action_group_add_toggle_actions (action_group, toggle_action_entry,
				       G_N_ELEMENTS (toggle_action_entry),
				       app);

  gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
  gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL);

  scores_action = gtk_action_group_get_action (action_group, "Scores");
  teleport_action = gtk_action_group_get_action (action_group, "Teleport");
  random_action = gtk_action_group_get_action (action_group, "Random");
  wait_action = gtk_action_group_get_action (action_group, "Wait");
  toolbar_toggle_action =
    gtk_action_group_get_action (action_group, "ShowToolbar");
  fullscreen_action = GTK_ACTION (games_fullscreen_action_new ("Fullscreen", GTK_WINDOW (app)));
  gtk_action_group_add_action_with_accel (action_group, fullscreen_action, NULL);

  return;
}
예제 #5
0
파일: main.c 프로젝트: petesh/pocketcity
void
actions_toggle_add(GtkActionGroup *act_group, const struct _actionhooks *ahs,
    int count)
{
	int i;
	GtkToggleAction *action;
	char *nel = malloc(max_path);

	for (i = 0; i < count; i++) {
		char *label = gettext(ahs[i].label);
		action = gtk_toggle_action_new(ahs[i].name,
		  label, ahs[i].tooltip == NULL ? label :
		  gettext(ahs[i].tooltip),
		  ahs[i].icon == NULL ? ahs[i].name : ahs[i].icon);
		sprintf(nel, "<Actions>/actions/%s", ahs[i].name);
		gtk_action_set_accel_path(GTK_ACTION(action), nel);
		//gtk_action_connect_accelerator(action);
		g_signal_connect(G_OBJECT(action), "activate",
		    ahs[i].handler,
		    GINT_TO_POINTER(ahs[i].parameter));
		gtk_action_group_add_action_with_accel(act_group,
		    GTK_ACTION(action),
		  NULL);
	}
	free(nel);
}
예제 #6
0
파일: formhistory.c 프로젝트: sinoory/webv8
static void
formhistory_app_add_browser_cb (MidoriApp*       app,
                                MidoriBrowser*   browser,
                                MidoriExtension* extension)
{

    GtkAccelGroup* acg = gtk_accel_group_new ();
    GtkActionGroup* action_group = midori_browser_get_action_group (browser);
    GtkAction* action = gtk_action_new ("FormHistoryToggleState",
        _("Toggle form history state"),
        _("Activate or deactivate form history for the current tab."), NULL);
    gtk_window_add_accel_group (GTK_WINDOW (browser), acg);

    g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", extension);

    g_signal_connect (action, "activate",
        G_CALLBACK (formhistory_toggle_state_cb), browser);

    gtk_action_group_add_action_with_accel (action_group, action, "<Ctrl><Shift>F");
    gtk_action_set_accel_group (action, acg);
    gtk_action_connect_accelerator (action);

    if (midori_extension_get_boolean (extension, "always-load"))
    {
        GList* tabs = midori_browser_get_tabs (browser);
        for (; tabs; tabs = g_list_next (tabs))
            formhistory_add_tab_cb (browser, tabs->data, extension);
        g_list_free (tabs);
        g_signal_connect (browser, "add-tab",
            G_CALLBACK (formhistory_add_tab_cb), extension);
    }
    g_signal_connect (extension, "deactivate",
        G_CALLBACK (formhistory_deactivate_cb), browser);
}
static void
empathy_mic_menu_add_microphone (EmpathyMicMenu *self,
    const gchar *name,
    const gchar *description,
    guint source_idx,
    gboolean is_monitor)
{
  EmpathyMicMenuPrivate *priv = self->priv;
  GtkRadioAction *action;
  GSList *group;

  action = gtk_radio_action_new (name, description, NULL, NULL, source_idx);
  gtk_action_group_add_action_with_accel (priv->action_group,
      GTK_ACTION (action), NULL);

  /* Set MONITOR_KEY on the action to non-NULL if it's a monitor
   * because we don't want to show monitors if we can help it. */
  if (is_monitor)
    {
      g_object_set_data (G_OBJECT (action), MONITOR_KEY,
          GUINT_TO_POINTER (TRUE));
    }

  group = gtk_radio_action_get_group (GTK_RADIO_ACTION (priv->anchor_action));
  gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);

  g_queue_push_tail (priv->microphones, action);

  g_signal_connect (action, "activate",
      G_CALLBACK (empathy_mic_menu_activate_cb), self);
}
예제 #8
0
void
gimp_action_group_add_enum_actions (GimpActionGroup           *group,
                                    const gchar               *msg_context,
                                    const GimpEnumActionEntry *entries,
                                    guint                      n_entries,
                                    GCallback                  callback)
{
  gint i;

  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));

  for (i = 0; i < n_entries; i++)
    {
      GimpEnumAction *action;
      const gchar    *label;
      const gchar    *tooltip = NULL;

      if (! gimp_action_group_check_unique_action (group, entries[i].name))
        continue;

      if (msg_context)
        {
          label = g_dpgettext2 (NULL, msg_context, entries[i].label);

          if (entries[i].tooltip)
            tooltip = g_dpgettext2 (NULL, msg_context, entries[i].tooltip);
        }
      else
        {
          label   = gettext (entries[i].label);
          tooltip = gettext (entries[i].tooltip);
        }

      action = gimp_enum_action_new (entries[i].name, label, tooltip,
                                     entries[i].icon_name,
                                     entries[i].value,
                                     entries[i].value_variable);

      if (callback)
        g_signal_connect (action, "selected",
                          callback,
                          group->user_data);

      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
                                              GTK_ACTION (action),
                                              entries[i].accelerator);
      g_signal_emit (group, signals[ACTION_ADDED], 0, action);

      if (entries[i].help_id)
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
                                 g_strdup (entries[i].help_id),
                                 (GDestroyNotify) g_free);

      g_object_unref (action);
    }
}
예제 #9
0
파일: glide-window.c 프로젝트: racarr/Glide
static void
glide_window_add_accelerator (GlideWindow *w,
			      GtkActionGroup *group,
			      GtkAccelGroup *accels,
			      const gchar *action,
			      const gchar *accel)
{
  GtkAction *a = GTK_ACTION (GLIDE_WINDOW_UI_OBJECT (w, action));
  gtk_action_set_accel_group (a, accels);
  gtk_action_group_add_action_with_accel (group, a, accel);
  gtk_action_connect_accelerator (a);
}
예제 #10
0
static VALUE
rg_add_action(int argc, VALUE *argv, VALUE self)
{
    VALUE action, accelerator;

    rb_scan_args(argc, argv, "11", &action, &accelerator);

    gtk_action_group_add_action_with_accel(_SELF(self),
                                           RVAL2GTKACTION(action),
                                           RVAL2CSTR_ACCEPT_NIL(accelerator));
    G_CHILD_ADD(self, action);

    return self;
}
예제 #11
0
static VALUE
rg_add_action(int argc, VALUE *argv, VALUE self)
{
    VALUE action, accelerator;

    rb_scan_args(argc, argv, "11", &action, &accelerator);

    gtk_action_group_add_action_with_accel(_SELF(self),
                                           GTK_ACTION(RVAL2GOBJ(action)),
                                           NIL_P(accelerator) ? NULL : RVAL2CSTR(accelerator));
    G_CHILD_ADD(self, action);

    return self;
}
예제 #12
0
/**
 * _rb_action_group_add_source_actions:
 * @group: a #GtkActionGroup
 * @shell: the #RBShell
 * @actions: array of GtkActionEntry structures for the action group
 * @num_actions: number of actions in the @actions array
 *
 * Adds actions to an action group where the action callback is
 * called with the current selected source.  This can safely be called
 * multiple times on the same action group.
 */
void
_rb_action_group_add_source_actions (GtkActionGroup *group,
				     GObject *shell,
				     GtkActionEntry *actions,
				     int num_actions)
{
	int i;
	for (i = 0; i < num_actions; i++) {
		GtkAction *action;
		const char *label;
		const char *tooltip;
		SourceActionData *source_action_data;

		if (gtk_action_group_get_action (group, actions[i].name) != NULL) {
			/* action was already added */
			continue;
		}

		label = gtk_action_group_translate_string (group, actions[i].label);
		tooltip = gtk_action_group_translate_string (group, actions[i].tooltip);

		action = gtk_action_new (actions[i].name, label, tooltip, NULL);
		if (actions[i].stock_id != NULL) {
			g_object_set (action, "stock-id", actions[i].stock_id, NULL);
			if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
						     actions[i].stock_id)) {
				g_object_set (action, "icon-name", actions[i].stock_id, NULL);
			}
		}

		if (actions[i].callback) {
			GClosure *closure;
			source_action_data = g_slice_new0 (SourceActionData);
			source_action_data->callback = (SourceActionCallback) actions[i].callback;
			source_action_data->shell = shell;
			g_object_add_weak_pointer (shell, &source_action_data->shell);

			closure = g_cclosure_new (G_CALLBACK (source_action_cb),
						  source_action_data,
						  (GClosureNotify) source_action_data_destroy);
			g_signal_connect_closure (action, "activate", closure, FALSE);
		}

		gtk_action_group_add_action_with_accel (group, action, actions[i].accelerator);
		g_object_unref (action);
	}
}
예제 #13
0
void
gimp_action_group_add_procedure_actions (GimpActionGroup                *group,
                                         const GimpProcedureActionEntry *entries,
                                         guint                           n_entries,
                                         GCallback                       callback)
{
  gint i;

  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));

  for (i = 0; i < n_entries; i++)
    {
      GimpProcedureAction *action;

      if (! gimp_action_group_check_unique_action (group, entries[i].name))
        continue;

      action = gimp_procedure_action_new (entries[i].name,
                                          entries[i].label,
                                          entries[i].tooltip,
                                          entries[i].icon_name,
                                          entries[i].procedure);

      if (callback)
        g_signal_connect (action, "selected",
                          callback,
                          group->user_data);

      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
                                              GTK_ACTION (action),
                                              entries[i].accelerator);
      g_signal_emit (group, signals[ACTION_ADDED], 0, action);

      if (entries[i].help_id)
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
                                 g_strdup (entries[i].help_id),
                                 (GDestroyNotify) g_free);

      g_object_unref (action);
    }
}
예제 #14
0
int
clip_GTK_ACTIONGROUPADDACTIONWITHACCEL(ClipMachine * ClipMachineMemory)
{
   C_object *cagroup = _fetch_co_arg(ClipMachineMemory);

   C_object *caction = _fetch_cobject(ClipMachineMemory, _clip_spar(ClipMachineMemory, 2));

   gchar    *accel = _clip_parc(ClipMachineMemory, 3);

   CHECKARG2(1, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKCOBJ(cagroup, GTK_IS_ACTION_GROUP(cagroup->object));
   CHECKARG2(2, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKCOBJ(caction, GTK_IS_ACTION(caction->object));
   CHECKARG(3, CHARACTER_type_of_ClipVarType);

   LOCALE_TO_UTF(accel);
   gtk_action_group_add_action_with_accel(GTK_ACTION_GROUP(cagroup->object), GTK_ACTION(caction->object), accel);

   FREE_TEXT(accel);
   return 0;
 err:
   return 1;
}
예제 #15
0
static void
gimp_color_button_init (GimpColorButton      *button,
                        GimpColorButtonClass *klass)
{
  GtkActionGroup *group;
  GtkUIManager   *ui_manager;
  gint            i;

  button->title  = NULL;
  button->dialog = NULL;

  button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
                                     "drag-mask", GDK_BUTTON1_MASK,
                                     NULL);

  g_signal_connect (button->color_area, "color-changed",
                    G_CALLBACK (gimp_color_button_area_changed),
                    button);

  gtk_container_add (GTK_CONTAINER (button), button->color_area);
  gtk_widget_show (button->color_area);

  /* right-click opens a popup */
  button->popup_menu = ui_manager = gtk_ui_manager_new ();

  group = gtk_action_group_new ("color-button");

  for (i = 0; i < G_N_ELEMENTS (actions); i++)
    {
      const gchar *label   = gettext (actions[i].label);
      const gchar *tooltip = gettext (actions[i].tooltip);
      GtkAction   *action;

      action = g_object_new (klass->get_action_type (button),
                             "name",     actions[i].name,
                             "label",    label,
                             "tooltip",  tooltip,
                             "stock-id", actions[i].stock_id,
                             NULL);

      if (actions[i].callback)
        g_signal_connect (action, "activate",
                          actions[i].callback,
                          button);

      gtk_action_group_add_action_with_accel (group, action,
                                              actions[i].accelerator);

      g_object_unref (action);
    }

  gtk_ui_manager_insert_action_group (ui_manager, group, -1);
  g_object_unref (group);

  gtk_ui_manager_add_ui_from_string
    (ui_manager,
     "<ui>\n"
     "  <popup action=\"color-button-popup\">\n"
     "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
     "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BG "\" />\n"
     "    <separator />\n"
     "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BLACK "\" />\n"
     "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_WHITE "\" />\n"
     "  </popup>\n"
     "</ui>\n",
     -1, NULL);
}
예제 #16
0
static void popup_menu (tilda_window *tw, tilda_term *tt)
{
    DEBUG_FUNCTION ("popup_menu");
    DEBUG_ASSERT (tw != NULL);
    DEBUG_ASSERT (tt != NULL);

    GtkAction *action;
    GtkActionGroup *action_group;
    GtkUIManager *ui_manager;
    GError *error = NULL;
    GtkWidget *menu;

    /* Just use a static string here to initialize the GtkUIManager,
     * rather than installing and reading from a file all the time. */
    static const gchar menu_str[] =
        "<ui>"
            "<popup name=\"popup-menu\">"
                "<menuitem action=\"new-tab\" />"
                "<menuitem action=\"close-tab\" />"
                "<separator />"
                "<menuitem action=\"copy\" />"
                "<menuitem action=\"paste\" />"
                "<separator />"
                "<menuitem action=\"fullscreen\" />"
                "<separator />"
                "<menuitem action=\"preferences\" />"
                "<separator />"
                "<menuitem action=\"quit\" />"
            "</popup>"
        "</ui>";

    /* Create the action group */
    action_group = gtk_action_group_new ("popup-menu-action-group");

    /* Add Actions and connect callbacks */
    action = gtk_action_new ("new-tab", _("_New Tab"), NULL, GTK_STOCK_ADD);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("addtab_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_add_tab_cb), tw);

    action = gtk_action_new ("close-tab", _("_Close Tab"), NULL, GTK_STOCK_CLOSE);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("closetab_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_close_tab_cb), tw);

    action = gtk_action_new ("copy", NULL, NULL, GTK_STOCK_COPY);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("copy_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_copy_cb), tt);

    action = gtk_action_new ("paste", NULL, NULL, GTK_STOCK_PASTE);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("paste_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_paste_cb), tt);

    action = gtk_action_new ("fullscreen", _("Toggle fullscreen"), NULL, NULL);
    gtk_action_group_add_action (action_group, action);
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_fullscreen_cb), tw);

    action = gtk_action_new ("preferences", NULL, NULL, GTK_STOCK_PREFERENCES);
    gtk_action_group_add_action (action_group, action);
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_preferences_cb), tw);

    action = gtk_action_new ("quit", NULL, NULL, GTK_STOCK_QUIT);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("quit_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_quit_cb), tw);

    /* Create and add actions to the GtkUIManager */
    ui_manager = gtk_ui_manager_new ();
    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
    gtk_ui_manager_add_ui_from_string (ui_manager, menu_str, -1, &error);

    /* Check for an error (REALLY REALLY unlikely, unless the developers screwed up */
    if (error)
    {
        DEBUG_ERROR ("GtkUIManager problem\n");
        g_printerr ("Error message: %s\n", error->message);
        g_error_free (error);
    }

    /* Get the popup menu out of the GtkUIManager */
    menu = gtk_ui_manager_get_widget (ui_manager, "/ui/popup-menu");

    /* Disable auto hide */
    tw->disable_auto_hide = TRUE;
    g_signal_connect (G_OBJECT(menu), "unmap", G_CALLBACK(on_popup_hide), tw);

    /* Display the menu */
    gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time());
    gtk_widget_show_all(menu);
}
예제 #17
0
파일: actions1.c 프로젝트: laubstein/pw3270
 GtkAction * create_action_by_descriptor(const gchar *name, struct action_descriptor *data)
 {
	int			state		= data->attr.key_state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK);
	int			f;

//	Trace("%s: %d",name,data->ui_type);

	switch(data->ui_type)
	{
	case UI_CALLBACK_TYPE_TOGGLE:
		data->action = GTK_ACTION(gtk_toggle_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip), data->attr.stock_id));
		break;

	case UI_CALLBACK_TYPE_DEFAULT:
		data->action = gtk_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip),data->attr.stock_id);
		break;

	case UI_CALLBACK_TYPE_SCROLL:
		if(data->sub >= 0 && data->sub <= G_N_ELEMENTS(action_scroll))
			action_scroll[data->sub] = data->action = gtk_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip),data->attr.stock_id);
		break;

	case UI_CALLBACK_TYPE_SCRIPT:

		if(data->script.text)
			g_object_set_data_full(G_OBJECT(data->action),"script_text",g_strdup(data->script.text),g_free);

		if(data->callback)
			g_signal_connect(G_OBJECT(data->action),"activate",G_CALLBACK(data->callback),topwindow);
		else
			g_signal_connect(G_OBJECT(data->action),"activate",G_CALLBACK(action_script_activated),topwindow);

		data->callback = 0;
		break;

	default:
		Trace("Invalid action type %d in %s",data->ui_type,data->name);
		return NULL;
	}

//	Trace("%s(%s), callback: %p action: %p",__FUNCTION__,name,data->callback,data->action);

	if(data->callback)
		g_signal_connect(G_OBJECT(data->action),data->ui_type == UI_CALLBACK_TYPE_TOGGLE ? "toggled" : "activate",G_CALLBACK(data->callback),data->user_data);

	// Check for special keyboard action
	for(f=0;f<G_N_ELEMENTS(keyboard_action);f++)
	{
		if(data->attr.key_value == keyboard_action[f].keyval && (state == keyboard_action[f].state))
		{
			keyboard_action[f].action = data->action;
			gtk_action_group_add_action(action_group[data->group],data->action);
			return data->action;
		}
	}

	// Check for PF actions
	if(data->attr.key_value >= GDK_F1 && data->attr.key_value <= GDK_F12 && !(state & (GDK_CONTROL_MASK|GDK_ALT_MASK)))
	{
		f = data->attr.key_value - GDK_F1;

		if(state&GDK_SHIFT_MASK)
			pf_action[f].shift = data->action;
		else
			pf_action[f].normal = data->action;
		gtk_action_group_add_action(action_group[data->group],data->action);
		return data->action;
	}

	// Register action
	if(data->attr.accel)
		gtk_action_group_add_action_with_accel(action_group[data->group],data->action,data->attr.accel);
	else
		gtk_action_group_add_action(action_group[data->group],data->action);

	return data->action;
 }
예제 #18
0
int
main(int argc, char **argv)
{
	GtkWidget *menubar,
			  *pri_vbox,
			  *tabla,
			  *scroll;
	GtkAccelGroup *accel_group;
	GtkUIManager *ui_manager;
	GtkAction *action;

	LIBXML_TEST_VERSION

	karakter_betoltes("ruin.xml");
	//return 0;

	gtk_init(&argc, &argv);

	action_group = gtk_action_group_new("main_menu");

	action = gtk_action_new("uj-karakter", "Új karakter", "Új karakter létrehozása", GTK_STOCK_NEW);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>N");

	action = gtk_action_new("karakter-megnyitas", "Karakter megnyitása", "Elmentett karakter megnyitása", GTK_STOCK_OPEN);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>O");

	action = gtk_action_new("karakter-mentes", "Karakter mentése", "Karakter adatainak mentése", GTK_STOCK_SAVE);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>S");

	action = gtk_action_new("kilepes", "Kilépés", "Kilépés a programból", GTK_STOCK_QUIT);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>Q");
	g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(kilepes_func), NULL);

	action = gtk_action_new("karakter-menu", "Karakter", "Karakter", NULL);
	gtk_action_group_add_action(action_group, action);

	gtk_action_group_add_radio_actions(action_group, menu_items, nezet_menu_szama, 0, G_CALLBACK(nezet_menu), NULL);
	action = gtk_action_new("nezet-menu", "Nézet", "Nézet", NULL);
	gtk_action_group_add_action(action_group, action);

	ui_manager = gtk_ui_manager_new();
	gtk_ui_manager_set_add_tearoffs(ui_manager, FALSE);
	gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
	gtk_ui_manager_add_ui_from_file(ui_manager, "magus_kargen_res.ui", NULL);

	accel_group = gtk_accel_group_new();

	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(main_window), "destroy", G_SIGNAL_FUNC(main_window_destroy), NULL);
	gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);
	gtk_window_set_title(GTK_WINDOW(main_window), "M.A.G.U.S. - Reneszánsz karakternyilvántartó");

	menubar = gtk_ui_manager_get_widget(ui_manager, "/menu");

	book = gtk_notebook_new();
	gtk_notebook_set_scrollable(GTK_NOTEBOOK(book), TRUE);
	gtk_notebook_popup_enable(GTK_NOTEBOOK(book));
	g_signal_connect(GTK_OBJECT(book), "change-current-page", G_SIGNAL_FUNC(lapvaltas), NULL);

	/* Azonnal látható és hallható dolgok */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(18, 2, FALSE);
	azonnal_lathato_dolgok_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(EGYBOL_LATHATO_HALLHATO_DOLGOK));

	/* A játékos és a karakter adatai */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(4, 2, FALSE);
	jatekos_es_karakter_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_JATEKOS_ES_A_KARAKTER_ADATAI));

	/* Képességek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(10, 2, FALSE);
	kepessegek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(KEPESSEGEK));

	/* Főbb adatok */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(26, 4, FALSE);
	fobb_adatok_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_KARAKTER_FOBB_ADATAI));

	/* Megjelenés */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(10, 4, FALSE);
	megjelenes_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(MEGJELENES));

	/* Állandó érzelmek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(15, 2, FALSE);
	erzelmek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ALLANDO_ERZELMEK));

	/* Szimpatikus viszonyok. Ide majd egy TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SZIMPATIKUS_VISZONYOK));

	/* Kapcsolatok, ismertseg. Ide majd egy TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISMERTSEG));

	/* Kulonleges kepessegek, hatranyok. Ide is TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_KEPESSEGEK));

	/* Tapasztalati pontok, átváltás */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(3, 2, FALSE);
	tapasztalat_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(TAPASZTALATI_PONTOK));

	/* Képzettségek. Ide majd egy TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPZETTSEGEK));

	/* Nyelvek. Ide is TableView */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(NYELVEK));

	/* Harcértékek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(5, 4, FALSE);
	harcertekek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(HARCERTEKEK));

	/* Életerő */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(3, 4, FALSE);
	eletero_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ELETERO));

	/* Pszi */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(5, 2, FALSE);
	pszi_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(PSZI));

	/* Mágia */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MAGIA));

	/* Fegyverek és pajzsok. Ide két TableView kell. */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FEGYVEREK_PAJZS));

	/* Állatok, csatlósok, szolgák. Ide sok TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALLATOK_CSATLOSOK));

	/* Mesterek és tanítók. Ide két TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MESTEREK));

	/* Földbirtokok. Ide is TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BIRTOKOK_BEFEKTETESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALAKULATOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISKOLAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MUVEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ERTEKEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(RUHAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSTARGYAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FELSZERELES));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLATOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TANULAS));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SEBESULESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BETEGSEGEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLAT_KUTATAS));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_DOLGOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MEGJEGYZESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TORTENET));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPEK));

	pri_vbox = gtk_vbox_new(FALSE, 0);

	gtk_box_pack_start(GTK_BOX(pri_vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(pri_vbox), book, TRUE, TRUE, 0);

	gtk_container_add(GTK_CONTAINER(main_window), pri_vbox);

	gtk_widget_show_all(main_window);
	gtk_window_maximize(GTK_WINDOW(main_window));

	gtk_main();

	xmlCleanupParser();

	return 0;
}
예제 #19
0
static void
anjuta_docman_update_documents_menu (AnjutaDocman* docman)
{
	AnjutaDocmanPriv *priv = docman->priv;
	GtkUIManager* ui = GTK_UI_MANAGER (anjuta_shell_get_ui (ANJUTA_PLUGIN (priv->plugin)->shell,
															NULL));
	GList *actions, *l;
	gint n, i;
	guint id;
	GSList *group = NULL;

	g_return_if_fail (priv->documents_action_group != NULL);

	if (priv->documents_merge_id != 0)
		gtk_ui_manager_remove_ui (ui,
					  priv->documents_merge_id);

	actions = gtk_action_group_list_actions (priv->documents_action_group);
	for (l = actions; l != NULL; l = l->next)
	{
		g_signal_handlers_disconnect_by_func (GTK_ACTION (l->data),
						      G_CALLBACK (on_document_toggled),
						      docman);
 		gtk_action_group_remove_action (priv->documents_action_group,
						GTK_ACTION (l->data));
	}
	g_list_free (actions);

	n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (docman));

	id = (n > 0) ? gtk_ui_manager_new_merge_id (ui) : 0;

	for (i = 0; i < n; i++)
	{
		AnjutaDocmanPage* page;
		GtkRadioAction *action;
		gchar *action_name;
		const gchar *tab_name;
		gchar *accel;

		page = anjuta_docman_get_nth_page (docman, i);

		/* NOTE: the action is associated to the position of the tab in
		 * the notebook not to the tab itself! This is needed to work
		 * around the gtk+ bug #170727: gtk leaves around the accels
		 * of the action. Since the accel depends on the tab position
		 * the problem is worked around, action with the same name always
		 * get the same accel.
		 */
		action_name = g_strdup_printf ("Tab_%d", i);
		tab_name = gtk_label_get_label (GTK_LABEL (page->label));

		/* alt + 1, 2, 3... 0 to switch to the first ten tabs */
		accel = (i < 10) ? g_strdup_printf ("<alt>%d", (i + 1) % 10) : NULL;

		action = gtk_radio_action_new (action_name,
					       tab_name,
					       NULL,
					       NULL,
					       i);

		if (group != NULL)
			gtk_radio_action_set_group (action, group);

		/* note that group changes each time we add an action, so it must be updated */
		group = gtk_radio_action_get_group (action);

		gtk_action_group_add_action_with_accel (priv->documents_action_group,
							GTK_ACTION (action),
							accel);

		g_signal_connect (action,
				  "toggled",
				  G_CALLBACK (on_document_toggled),
				  docman);

		gtk_ui_manager_add_ui (ui,
				       id,
				       MENU_PLACEHOLDER,
				       action_name, action_name,
				       GTK_UI_MANAGER_MENUITEM,
				       FALSE);

		if (i == gtk_notebook_get_current_page (GTK_NOTEBOOK (docman)))
			gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);

		g_object_unref (action);

		g_free (action_name);
		g_free (accel);
	}
	anjuta_docman_update_documents_menu_status (docman);
	priv->documents_merge_id = id;
}
예제 #20
0
파일: testAction.c 프로젝트: zdia/gnocl
int main ( int argc, char **argv )
{
	int k;
	GtkWidget *window, *child, *box, *menu, *subMenu;
	GtkAction *action[2];
	GtkUIManager  *manager;

	gtk_init ( &argc, &argv );
	window = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
	box = gtk_vbox_new ( 0, 0 );
	gtk_container_add ( GTK_CONTAINER ( window ), box );
	/*
	   menuBar = gtk_menu_bar_new();
	   gtk_container_add( GTK_CONTAINER( box ), menuBar );
	   menu = gtk_menu_item_new_with_label( "Menu" );
	   gtk_container_add( GTK_CONTAINER( menuBar ), menu );
	   subMenu = gtk_menu_new();
	   gtk_menu_item_set_submenu( menu, subMenu );
	*/

	{
		/*
		   actionGroup name -entries ... -toggleEntries ... -radioEntries
		   $name addEntries
		   $name addToggleEntries
		   $name addRadioEntries
		*/
		GtkActionGroup *action_group = gtk_action_group_new ( "MenuActions" );
		gtk_action_group_add_actions ( action_group, entries,
									   G_N_ELEMENTS ( entries ), window );
		gtk_action_group_add_toggle_actions ( action_group, toggle_entries,
											  G_N_ELEMENTS ( toggle_entries ), window );
		gtk_action_group_add_radio_actions ( action_group, radio_entries,
											 G_N_ELEMENTS ( radio_entries ), 0, func1, window );
		/*
		   uiManager addUI ui_description -groups $name
		   $manager addGroup
		*/
		manager = gtk_ui_manager_new ();
		gtk_ui_manager_insert_action_group ( manager , action_group, 0 );
	}

	{
		/*
		   $manager setAccelWindow window
		*/
		GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group ( manager );
		gtk_window_add_accel_group ( GTK_WINDOW ( window ), accel_group );
	}

	{
		/*
		   $manager setUiDescription xxx
		*/
		GError *error = NULL;

		if ( !gtk_ui_manager_add_ui_from_string ( manager, ui_description, -1, &error ) )
		{
			g_message ( "building menus failed: %s", error->message );
			g_error_free ( error );
			exit ( 1 );
		}
	}

	{
		/*
		   $manager getWidget name
		*/
		GtkWidget *menuBar = gtk_ui_manager_get_widget ( manager, "/MainMenu" );
		gtk_box_pack_start ( GTK_BOX ( box ), menuBar, FALSE, FALSE, 0 );
	}

	gtk_widget_show_all ( window );

	/*
	   action[0] = GTK_ACTION( gtk_action_new( "name", "label", "tooltip", NULL ) );
	   action[1] = GTK_ACTION( gtk_action_new( "name2", "label2", "tooltip2", "gtk-quit" ) );

	   g_signal_connect( action[0], "activate", G_CALLBACK( func1 ), NULL);
	   g_signal_connect( action[1], "activate", G_CALLBACK( func2 ), NULL);
	*/
	/* accelGroup =  gtk_accel_group_new(); */


#if 0
	group = gtk_action_group_new ( "global" );
	gtk_action_group_add_actions ( group, entries, 1, window );
	manager = gtk_ui_manager_new ();
	gtk_ui_manager_insert_action_group ( manager, group, 0 );
	accelGroup = gtk_ui_manager_get_accel_group ( manager );

	gtk_window_add_accel_group ( GTK_WINDOW ( window ), accelGroup );

	for ( k = 0; k < 2; ++k )
	{
		child = gtk_action_create_menu_item ( action[k] );
		gtk_container_add ( GTK_CONTAINER ( subMenu ), child );
		child = gtk_action_create_tool_item ( action[k] );
		gtk_container_add ( GTK_CONTAINER ( box ), child );
	}

	gtk_action_group_add_action_with_accel ( group, action[0], "<control>w" );

	gtk_action_group_add_action_with_accel ( group, action[1], NULL );
#endif

	gtk_widget_show_all ( window );

	gtk_main();
	return 0;
}
예제 #21
0
GSList *
gimp_action_group_add_radio_actions (GimpActionGroup            *group,
                                     const gchar                *msg_context,
                                     const GimpRadioActionEntry *entries,
                                     guint                       n_entries,
                                     GSList                     *radio_group,
                                     gint                        value,
                                     GCallback                   callback)
{
  GtkRadioAction *first_action = NULL;
  gint            i;

  g_return_val_if_fail (GIMP_IS_ACTION_GROUP (group), NULL);

  for (i = 0; i < n_entries; i++)
    {
      GtkRadioAction *action;
      const gchar    *label;
      const gchar    *tooltip = NULL;

      if (! gimp_action_group_check_unique_action (group, entries[i].name))
        continue;

      if (msg_context)
        {
          label = g_dpgettext2 (NULL, msg_context, entries[i].label);

          if (entries[i].tooltip)
            tooltip = g_dpgettext2 (NULL, msg_context, entries[i].tooltip);
        }
      else
        {
          label   = gettext (entries[i].label);
          tooltip = gettext (entries[i].tooltip);
        }

      action = gimp_radio_action_new (entries[i].name, label, tooltip,
                                      entries[i].icon_name,
                                      entries[i].value);

      if (i == 0)
        first_action = action;

      gtk_radio_action_set_group (action, radio_group);
      radio_group = gtk_radio_action_get_group (action);

      if (value == entries[i].value)
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);

      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
                                              GTK_ACTION (action),
                                              entries[i].accelerator);
      g_signal_emit (group, signals[ACTION_ADDED], 0, action);

      if (entries[i].help_id)
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
                                 g_strdup (entries[i].help_id),
                                 (GDestroyNotify) g_free);

      g_object_unref (action);
    }

  if (callback && first_action)
    g_signal_connect (first_action, "changed",
                      callback,
                      group->user_data);

  return radio_group;
}
예제 #22
0
static void
set_up_tree_view (TotemYouTubePlugin *self, GtkBuilder *builder, guint key)
{
	GtkUIManager *ui_manager;
	GtkActionGroup *action_group;
	GtkAction *action, *menu_item;
	GtkWidget *vscroll, *tree_view;
	GtkTreeViewColumn *column;
	GtkCellRenderer *renderer;

	/* Add the cell renderer. This can't be done with GtkBuilder, because it unavoidably sets the expand parameter to FALSE */
	/* TODO: Depends on bug #453692 */
	renderer = GTK_CELL_RENDERER (totem_cell_renderer_video_new (TRUE));
	column = GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder,
							       (key == SEARCH_TREE_VIEW) ? "yt_treeview_search_column" : "yt_treeview_related_column"));
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_set_attributes (column, renderer, "thumbnail", 0, "title", 1, NULL);

	/* Give the video lists a handle to Totem and connect their scrollbar signals */
	if (key == SEARCH_TREE_VIEW) {
		tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "yt_treeview_search"));
		vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "yt_scrolled_window_search")));
		self->list_store[key] = GTK_LIST_STORE (gtk_builder_get_object (builder, "yt_list_store_search"));
		self->tree_view[key] = GTK_TREE_VIEW (tree_view);
		self->progress_bar[key] = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "yt_progress_bar_search"));
	} else {
		tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "yt_treeview_related"));
		vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "yt_scrolled_window_related")));
		self->list_store[key] = GTK_LIST_STORE (gtk_builder_get_object (builder, "yt_list_store_related"));
		self->tree_view[key] = GTK_TREE_VIEW (tree_view);
		self->progress_bar[key] = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "yt_progress_bar_related"));
	}
	g_object_set (tree_view, "totem", self->totem, NULL);
	g_signal_connect (vscroll, "button-press-event", G_CALLBACK (button_press_event_cb), self);
	g_signal_connect (vscroll, "button-release-event", G_CALLBACK (button_release_event_cb), self);

	/* Add the extra popup menu options. This is done here rather than in the UI file, because it's done for multiple treeviews;
	 * if it were done in the UI file, the same action group would be used multiple times, which GTK+ doesn't like. */
	ui_manager = totem_video_list_get_ui_manager (TOTEM_VIDEO_LIST (tree_view));
	action_group = gtk_action_group_new ("youtube-action-group");
	action = gtk_action_new ("open-in-web-browser", _("_Open in Web Browser"), _("Open the video in your web browser"), "gtk-jump-to");
	gtk_action_group_add_action_with_accel (action_group, action, NULL);

	gtk_ui_manager_insert_action_group (ui_manager, action_group, 1);
	gtk_ui_manager_add_ui (ui_manager, gtk_ui_manager_new_merge_id (ui_manager),
			       "/ui/totem-video-list-popup/",
			       "open-in-web-browser",
			       "open-in-web-browser",
			       GTK_UI_MANAGER_MENUITEM,
			       FALSE);

	menu_item = gtk_ui_manager_get_action (ui_manager, "/ui/totem-video-list-popup/open-in-web-browser");
	g_signal_connect (menu_item, "activate", G_CALLBACK (open_in_web_browser_activate_cb), self);

	/* Connect to more scroll events */
	#if GTK_CHECK_VERSION(3, 0, 0)
		self->vadjust[key] = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(tree_view));
	#else
		self->vadjust[key] = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(tree_view));
	#endif

	g_signal_connect (self->vadjust[key], "value-changed", G_CALLBACK (value_changed_cb), self);

	self->cancel_button = GTK_WIDGET (gtk_builder_get_object (builder, "yt_cancel_button"));
}
예제 #23
0
파일: ghid-main-menu.c 프로젝트: rlutz/pcb
/*! \brief Translate a resource tree into a menu structure
 *
 *  \param [in] menu    The GHidMainMenu widget to be acted on
 *  \param [in] shall   The base menu shell (a menu bar or popup menu)
 *  \param [in] res     The base of the resource tree
 * */
void
ghid_main_menu_real_add_resource (GHidMainMenu *menu, GtkMenuShell *shell,
                                  const Resource *res)
{
    int i, j;
    const Resource *tmp_res;
    gchar mnemonic = 0;

    for (i = 0; i < res->c; ++i)
    {
        const gchar *accel = NULL;
        char *menu_label;
        const char *res_val;
        const Resource *sub_res = res->v[i].subres;
        GtkAction *action = NULL;

        switch (resource_type (res->v[i]))
        {
        case 101:   /* name, subres: passthrough */
            ghid_main_menu_real_add_resource (menu, shell, sub_res);
            break;
        case   1:   /* no name, subres */
            tmp_res = resource_subres (sub_res, "a");  /* accelerator */
            res_val = resource_value (sub_res, "m");   /* mnemonic */
            if (res_val)
                mnemonic = res_val[0];
            /* The accelerator resource will have two values, like
             *   a={"Ctrl-Q" "Ctrl<Key>q"}
             * The first Gtk ignores. The second needs to be translated. */
            if (tmp_res)
                accel = check_unique_accel
                        (translate_accelerator (tmp_res->v[1].value));

            /* Now look for the first unnamed value (not a subresource) to
             * figure out the name of the menu or the menuitem. */
            res_val = "button";
            for (j = 0; j < sub_res->c; ++j)
                if (resource_type (sub_res->v[j]) == 10)
                {
                    res_val = _(sub_res->v[j].value);
                    break;
                }
            /* Hack '_' in based on mnemonic value */
            if (!mnemonic)
                menu_label = g_strdup (res_val);
            else
            {
                char *post_ = strchr (res_val, mnemonic);
                if (post_ == NULL)
                    menu_label = g_strdup (res_val);
                else
                {
                    GString *tmp = g_string_new ("");
                    g_string_append_len (tmp, res_val, post_ - res_val);
                    g_string_append_c (tmp, '_');
                    g_string_append (tmp, post_);
                    menu_label = g_string_free (tmp, FALSE);
                }
            }
            /* If the subresource we're processing also has unnamed
             * subresources, it's a submenu, not a regular menuitem. */
            if (sub_res->flags & FLAG_S)
            {
                /* SUBMENU */
                GtkWidget *submenu = gtk_menu_new ();
                GtkWidget *item = gtk_menu_item_new_with_mnemonic (menu_label);
                GtkWidget *tearoff = gtk_tearoff_menu_item_new ();

                gtk_menu_shell_append (shell, item);
                gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);

                /* add tearoff to menu */
                gtk_menu_shell_append (GTK_MENU_SHELL (submenu), tearoff);
                /* recurse on the newly-added submenu */
                ghid_main_menu_real_add_resource (menu,
                                                  GTK_MENU_SHELL (submenu),
                                                  sub_res);
            }
            else
            {
                /* NON-SUBMENU: MENU ITEM */
                const char *checked = resource_value (sub_res, "checked");
                const char *label = resource_value (sub_res, "sensitive");
                const char *tip = resource_value (sub_res, "tip");
                if (checked)
                {
                    /* TOGGLE ITEM */
                    gchar *name = g_strdup_printf ("MainMenuAction%d",
                                                   action_counter++);

                    action = GTK_ACTION (gtk_toggle_action_new (name, menu_label,
                                         tip, NULL));
                    /* checked=foo       is a binary flag (checkbox)
                     * checked=foo,bar   is a flag compared to a value (radio) */
                    gtk_toggle_action_set_draw_as_radio
                    (GTK_TOGGLE_ACTION (action), !!strchr (checked, ','));
                }
                else if (label && strcmp (label, "false") == 0)
                {
                    /* INSENSITIVE ITEM */
                    GtkWidget *item = gtk_menu_item_new_with_label (menu_label);
                    gtk_widget_set_sensitive (item, FALSE);
                    gtk_menu_shell_append (shell, item);
                }
                else
                {
                    /* NORMAL ITEM */
                    gchar *name = g_strdup_printf ("MainMenuAction%d", action_counter++);
                    action = gtk_action_new (name, menu_label, tip, NULL);
                }
            }
            /* Connect accelerator, if there is one */
            if (action)
            {
                GtkWidget *item;
                gtk_action_set_accel_group (action, menu->accel_group);
                gtk_action_group_add_action_with_accel (menu->action_group,
                                                        action, accel);
                gtk_action_connect_accelerator (action);
                g_signal_connect (G_OBJECT (action), "activate", menu->action_cb,
                                  (gpointer) sub_res);
                g_object_set_data (G_OBJECT (action), "resource",
                                   (gpointer) sub_res);
                item = gtk_action_create_menu_item (action);
                gtk_menu_shell_append (shell, item);
                menu->actions = g_list_append (menu->actions, action);
                menu->special_key_cb (accel, action, sub_res);
            }
            /* Scan rest of resource in case there is more work */
            for (j = 0; j < sub_res->c; j++)
            {
                const char *res_name;
                /* named value = X resource */
                if (resource_type (sub_res->v[j]) == 110)
                {
                    res_name = sub_res->v[j].name;

                    /* translate bg, fg to background, foreground */
                    if (strcmp (res_name, "fg") == 0)   res_name = "foreground";
                    if (strcmp (res_name, "bg") == 0)   res_name = "background";

                    /* ignore special named values (m, a, sensitive) */
                    if (strcmp (res_name, "m") == 0
                            || strcmp (res_name, "a") == 0
                            || strcmp (res_name, "sensitive") == 0
                            || strcmp (res_name, "tip") == 0)
                        break;

                    /* log checked and active special values */
                    if (action && strcmp (res_name, "checked") == 0)
                        g_object_set_data (G_OBJECT (action), "checked-flag",
                                           sub_res->v[j].value);
                    else if (action && strcmp (res_name, "active") == 0)
                        g_object_set_data (G_OBJECT (action), "active-flag",
                                           sub_res->v[j].value);
                    else
                        /* if we got this far it is supposed to be an X
                         * resource.  For now ignore it and warn the user */
                        Message (_("The gtk gui currently ignores \"%s\""
                                   "as part of a menuitem resource.\n"
                                   "Feel free to provide patches\n"),
                                 sub_res->v[j].value);
                }
            }
            break;
        case  10:   /* no name, value */
            /* If we get here, the resource is "-" or "@foo" for some foo */
            if (res->v[i].value[0] == '@')
            {
                GList *children;
                int pos;

                children = gtk_container_get_children (GTK_CONTAINER (shell));
                pos = g_list_length (children);
                g_list_free (children);

                if (strcmp (res->v[i].value, "@layerview") == 0)
                {
                    menu->layer_view_shell = shell;
                    menu->layer_view_pos = pos;
                }
                else if (strcmp (res->v[i].value, "@layerpick") == 0)
                {
                    menu->layer_pick_shell = shell;
                    menu->layer_pick_pos = pos;
                }
                else if (strcmp (res->v[i].value, "@routestyles") == 0)
                {
                    menu->route_style_shell = shell;
                    menu->route_style_pos = pos;
                }
                else
                    Message (_("GTK GUI currently ignores \"%s\" in the menu\n"
                               "resource file.\n"), res->v[i].value);
            }
            else if (strcmp (res->v[i].value, "-") == 0)
            {
                GtkWidget *item = gtk_separator_menu_item_new ();
                gtk_menu_shell_append (shell, item);
            }
            else if (i > 0)
            {
                /* This is an action-less menuitem. It is really only useful
                 * when you're starting to build a new menu and you're looking
                 * to get the layout right. */
                GtkWidget *item
                    = gtk_menu_item_new_with_label (_(res->v[i].value));
                gtk_menu_shell_append (shell, item);
            }
            break;
        }
    }
}
예제 #24
0
/**
 * nemo_window_initialize_menus
 * 
 * Create and install the set of menus for this window.
 * @window: A recently-created NemoWindow.
 */
void 
nemo_window_initialize_menus (NemoWindow *window)
{
	GtkActionGroup *action_group;
	GtkUIManager *ui_manager;
	GtkAction *action;
	gint i;

	if (window->details->ui_manager == NULL){
        window->details->ui_manager = gtk_ui_manager_new ();
    }
	ui_manager = window->details->ui_manager;

	/* shell actions */
	action_group = gtk_action_group_new ("ShellActions");
	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
	window->details->main_action_group = action_group;
	gtk_action_group_add_actions (action_group, 
				      main_entries, G_N_ELEMENTS (main_entries),
				      window);
	gtk_action_group_add_toggle_actions (action_group, 
					     main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
					     window);
	gtk_action_group_add_radio_actions (action_group,
					    main_radio_entries, G_N_ELEMENTS (main_radio_entries),
					    0, G_CALLBACK (sidebar_radio_entry_changed_cb),
					    window);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_UP);
	g_object_set (action, "short_label", _("_Up"), NULL);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_HOME);
	g_object_set (action, "short_label", _("_Home"), NULL);

  	action = gtk_action_group_get_action (action_group, NEMO_ACTION_EDIT_LOCATION);
  	g_object_set (action, "short_label", _("_Location"), NULL);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_SHOW_HIDDEN_FILES);
	g_signal_handlers_block_by_func (action, action_show_hidden_files_callback, window);
	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
				      g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_SHOW_HIDDEN_FILES));
	g_signal_handlers_unblock_by_func (action, action_show_hidden_files_callback, window);


	g_signal_connect_swapped (nemo_preferences, "changed::" NEMO_PREFERENCES_SHOW_HIDDEN_FILES,
				  G_CALLBACK(show_hidden_files_preference_callback),
				  window);

	/* Alt+N for the first 10 tabs */
	for (i = 0; i < 10; ++i) {
		gchar action_name[80];
		gchar accelerator[80];

		snprintf(action_name, sizeof (action_name), "Tab%d", i);
		action = gtk_action_new (action_name, NULL, NULL, NULL);
		g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
		g_signal_connect (action, "activate",
				G_CALLBACK (action_tab_change_action_activate_callback), window);
		snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
		gtk_action_group_add_action_with_accel (action_group, action, accelerator);
		g_object_unref (action);
		gtk_ui_manager_add_ui (ui_manager,
				gtk_ui_manager_new_merge_id (ui_manager),
				"/",
				action_name,
				action_name,
				GTK_UI_MANAGER_ACCELERATOR,
				FALSE);

	}

	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
	g_object_unref (action_group); /* owned by ui_manager */

	gtk_window_add_accel_group (GTK_WINDOW (window),
				    gtk_ui_manager_get_accel_group (ui_manager));
	
	g_signal_connect (ui_manager, "connect_proxy",
			  G_CALLBACK (connect_proxy_cb), window);
	g_signal_connect (ui_manager, "disconnect_proxy",
			  G_CALLBACK (disconnect_proxy_cb), window);

	/* add the UI */
	gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/nemo/nemo-shell-ui.xml", NULL);

	nemo_window_initialize_trash_icon_monitor (window);
	nemo_window_initialize_go_menu (window);
}
예제 #25
0
static void
add_extension_menu_items (CajaWindow *window,
                          guint merge_id,
                          GtkActionGroup *action_group,
                          GList *menu_items,
                          const char *subdirectory)
{
    GtkUIManager *ui_manager;
    GList *l;

    ui_manager = window->details->ui_manager;

    for (l = menu_items; l; l = l->next)
    {
        CajaMenuItem *item;
        CajaMenu *menu;
        GtkAction *action;
        char *path;

        item = CAJA_MENU_ITEM (l->data);

        g_object_get (item, "menu", &menu, NULL);

        action = caja_action_from_menu_item (item);
        gtk_action_group_add_action_with_accel (action_group, action, NULL);

        path = g_build_path ("/", POPUP_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
        gtk_ui_manager_add_ui (ui_manager,
                               merge_id,
                               path,
                               gtk_action_get_name (action),
                               gtk_action_get_name (action),
                               (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
                               FALSE);
        g_free (path);

        path = g_build_path ("/", MENU_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
        gtk_ui_manager_add_ui (ui_manager,
                               merge_id,
                               path,
                               gtk_action_get_name (action),
                               gtk_action_get_name (action),
                               (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
                               FALSE);
        g_free (path);

        /* recursively fill the menu */
        if (menu != NULL)
        {
            char *subdir;
            GList *children;

            children = caja_menu_get_items (menu);

            subdir = g_build_path ("/", subdirectory, "/", gtk_action_get_name (action), NULL);
            add_extension_menu_items (window,
                                      merge_id,
                                      action_group,
                                      children,
                                      subdir);

            caja_menu_item_list_free (children);
            g_free (subdir);
        }
    }
}
/**
 * nautilus_window_initialize_menus
 *
 * Create and install the set of menus for this window.
 * @window: A recently-created NautilusWindow.
 */
void
nautilus_window_initialize_menus (NautilusWindow *window)
{
    GtkActionGroup *action_group;
    GtkUIManager *ui_manager;
    GtkAction *action;
    gint i;

    window->details->ui_manager = gtk_ui_manager_new ();
    ui_manager = window->details->ui_manager;

    /* shell actions */
    action_group = gtk_action_group_new ("ShellActions");
    gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
    window->details->main_action_group = action_group;
    gtk_action_group_add_actions (action_group,
                                  main_entries, G_N_ELEMENTS (main_entries),
                                  window);
    gtk_action_group_add_toggle_actions (action_group,
                                         main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
                                         window);
    gtk_action_group_add_radio_actions (action_group,
                                        view_radio_entries, G_N_ELEMENTS (view_radio_entries),
                                        -1, G_CALLBACK (action_view_radio_changed),
                                        window);

    action = nautilus_option_menu_action_new ("Zoom Options",
             _("Zoom"), _("Zoom Options"), NULL);
    gtk_action_group_add_action (action_group, action);
    g_object_unref (action);

    nautilus_window_menus_set_visibility_for_app_menu (window);
    window->details->app_menu_visibility_id =
        g_signal_connect_swapped (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
                                  "notify::gtk-shell-shows-app-menu",
                                  G_CALLBACK (nautilus_window_menus_set_visibility_for_app_menu), window);

    action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_UP);
    g_object_set (action, "short_label", _("_Up"), NULL);

    action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_HOME);
    g_object_set (action, "short_label", _("_Home"), NULL);

    /* Alt+N for the first 10 tabs */
    for (i = 0; i < 10; ++i) {
        gchar action_name[80];
        gchar accelerator[80];

        snprintf(action_name, sizeof (action_name), "Tab%d", i);
        action = gtk_action_new (action_name, NULL, NULL, NULL);
        g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
        g_signal_connect (action, "activate",
                          G_CALLBACK (action_tab_change_action_activate_callback), window);
        snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
        gtk_action_group_add_action_with_accel (action_group, action, accelerator);
        g_object_unref (action);
        gtk_ui_manager_add_ui (ui_manager,
                               gtk_ui_manager_new_merge_id (ui_manager),
                               "/",
                               action_name,
                               action_name,
                               GTK_UI_MANAGER_ACCELERATOR,
                               FALSE);

    }

    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
    g_object_unref (action_group); /* owned by ui_manager */

    gtk_window_add_accel_group (GTK_WINDOW (window),
                                gtk_ui_manager_get_accel_group (ui_manager));

    g_signal_connect (ui_manager, "connect-proxy",
                      G_CALLBACK (connect_proxy_cb), window);

    /* add the UI */
    gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/gnome/nautilus/nautilus-shell-ui.xml", NULL);

    /* set actions for option menu items */
    populate_option_menu_items (window);
}