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); }
void actions_radio_add(GtkActionGroup *act_group, const struct _actionhooks *ahs, int count) { int i; GtkRadioAction *action; char *nel = malloc(max_path); GSList *list = NULL; for (i = 0; i < count; i++) { char *label = gettext(ahs[i].label); action = gtk_radio_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, ahs[i].parameter); sprintf(nel, "<Actions>/actions/%s", ahs[i].name); gtk_action_set_accel_path(GTK_ACTION(action), nel); gtk_radio_action_set_group(action, list); list = gtk_radio_action_get_group(action); //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); }
static VALUE rg_initialize(VALUE self, VALUE name, VALUE label, VALUE tooltip, VALUE stock_id, VALUE value) { const gchar *gstock = NULL; if (TYPE(stock_id) == T_STRING){ gstock = RVAL2CSTR(stock_id); } else if (TYPE(stock_id) == T_SYMBOL) { gstock = rb_id2name(SYM2ID(stock_id)); } G_INITIALIZE(self, gtk_radio_action_new(RVAL2CSTR(name), RVAL2CSTR(label), NIL_P(tooltip) ? NULL : RVAL2CSTR(tooltip), gstock, NUM2INT(value))); return Qnil; }
void e_task_shell_view_update_search_filter (ETaskShellView *task_shell_view) { ETaskShellContent *task_shell_content; EShellView *shell_view; EShellWindow *shell_window; EShellSearchbar *searchbar; EActionComboBox *combo_box; GtkActionGroup *action_group; GtkRadioAction *radio_action; GList *list, *iter; GSList *group; gint ii; shell_view = E_SHELL_VIEW (task_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); action_group = ACTION_GROUP (TASKS_FILTER); e_action_group_remove_all_actions (action_group); /* Add the standard filter actions. No callback is needed * because changes in the EActionComboBox are detected and * handled by EShellSearchbar. */ gtk_action_group_add_radio_actions ( action_group, task_filter_entries, G_N_ELEMENTS (task_filter_entries), TASK_FILTER_ANY_CATEGORY, NULL, NULL); /* Retrieve the radio group from an action we just added. */ list = gtk_action_group_list_actions (action_group); radio_action = GTK_RADIO_ACTION (list->data); group = gtk_radio_action_get_group (radio_action); g_list_free (list); /* Build the category actions. */ list = e_util_dup_searchable_categories (); for (iter = list, ii = 0; iter != NULL; iter = iter->next, ii++) { const gchar *category_name = iter->data; gchar *filename; GtkAction *action; gchar *action_name; action_name = g_strdup_printf ( "task-filter-category-%d", ii); radio_action = gtk_radio_action_new ( action_name, category_name, NULL, NULL, ii); g_free (action_name); /* Convert the category icon file to a themed icon name. */ filename = e_categories_dup_icon_file_for (category_name); if (filename != NULL && *filename != '\0') { gchar *basename; gchar *cp; basename = g_path_get_basename (filename); /* Lose the file extension. */ if ((cp = strrchr (basename, '.')) != NULL) *cp = '\0'; g_object_set ( radio_action, "icon-name", basename, NULL); g_free (basename); } g_free (filename); gtk_radio_action_set_group (radio_action, group); group = gtk_radio_action_get_group (radio_action); /* The action group takes ownership of the action. */ action = GTK_ACTION (radio_action); gtk_action_group_add_action (action_group, action); g_object_unref (radio_action); } g_list_free_full (list, g_free); task_shell_content = task_shell_view->priv->task_shell_content; searchbar = e_task_shell_content_get_searchbar (task_shell_content); combo_box = e_shell_searchbar_get_filter_combo_box (searchbar); e_shell_view_block_execute_search (shell_view); /* Use any action in the group; doesn't matter which. */ e_action_combo_box_set_action (combo_box, radio_action); ii = TASK_FILTER_UNMATCHED; e_action_combo_box_add_separator_after (combo_box, ii); ii = TASK_FILTER_TASKS_WITH_ATTACHMENTS; e_action_combo_box_add_separator_after (combo_box, ii); e_shell_view_unblock_execute_search (shell_view); }
GtkWidget* create_tool_item( GtkAction* action ) { GtkWidget* item = 0; if ( IS_EGE_SELECT_ONE_ACTION(action) && EGE_SELECT_ONE_ACTION(action)->private_data->model ) { EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(action); item = GTK_WIDGET( gtk_tool_item_new() ); if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { #if GTK_CHECK_VERSION(3,0,0) GtkWidget* holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(holder), FALSE); #else GtkWidget* holder = gtk_hbox_new( FALSE, 0 ); #endif GtkRadioAction* ract = 0; GSList* group = 0; GtkTreeIter iter; gboolean valid = FALSE; gint index = 0; { gchar* sss = 0; g_object_get( G_OBJECT(action), "short_label", &sss, NULL ); // If short_label not defined, g_object_get will return label. // This hack allows a label to be used with a drop-down menu when // no label is used with a set of icons that are self-explanatory. if (sss && strcmp( sss, "NotUsed" ) != 0 ) { GtkWidget* lbl = gtk_label_new(sss); gtk_box_pack_start( GTK_BOX(holder), lbl, FALSE, FALSE, 4 ); } g_free( sss ); sss = 0; } valid = gtk_tree_model_get_iter_first( act->private_data->model, &iter ); while ( valid ) { gchar* str = 0; gchar* tip = 0; gchar* iconId = 0; gboolean sens = true; /* gint size = 0; */ gtk_tree_model_get( act->private_data->model, &iter, act->private_data->labelColumn, &str, -1 ); if ( act->private_data->iconColumn >= 0 ) { gtk_tree_model_get( act->private_data->model, &iter, act->private_data->iconColumn, &iconId, -1 ); } if ( act->private_data->tooltipColumn >= 0 ) { gtk_tree_model_get( act->private_data->model, &iter, act->private_data->tooltipColumn, &tip, -1 ); } if ( act->private_data->sensitiveColumn >= 0 ) { gtk_tree_model_get( act->private_data->model, &iter, act->private_data->sensitiveColumn, &sens, -1 ); } if ( act->private_data->radioActionType ) { void* obj = g_object_new( act->private_data->radioActionType, "name", "Name 1", "label", str, "tooltip", tip, "value", index, /* "iconId", iconId, "iconSize", size, */ NULL ); if ( iconId ) { g_object_set( G_OBJECT(obj), act->private_data->iconProperty, iconId, NULL ); } if ( act->private_data->iconProperty ) { /* TODO get this string to be set instead of hardcoded */ if ( act->private_data->iconSize >= 0 ) { g_object_set( G_OBJECT(obj), "iconSize", act->private_data->iconSize, NULL ); } } ract = GTK_RADIO_ACTION(obj); } else { ract = gtk_radio_action_new( "Name 1", str, tip, iconId, index ); } if ( act->private_data->sensitiveColumn >= 0 ) { gtk_action_set_sensitive( GTK_ACTION(ract), sens ); } gtk_radio_action_set_group( ract, group ); group = gtk_radio_action_get_group( ract ); if ( index == act->private_data->active ) { gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(ract), TRUE ); } g_signal_connect( G_OBJECT(ract), "changed", G_CALLBACK( proxy_action_chagned_cb ), act ); GtkWidget* sub = gtk_action_create_tool_item( GTK_ACTION(ract) ); gtk_activatable_set_related_action( GTK_ACTIVATABLE (sub), GTK_ACTION(ract) ); gtk_tool_item_set_tooltip_text( GTK_TOOL_ITEM(sub), tip ); gtk_box_pack_start( GTK_BOX(holder), sub, FALSE, FALSE, 0 ); g_free( str ); g_free( tip ); g_free( iconId ); index++; valid = gtk_tree_model_iter_next( act->private_data->model, &iter ); } g_object_set_data( G_OBJECT(holder), "ege-proxy_action-group", group ); gtk_container_add( GTK_CONTAINER(item), holder ); } else { #if GTK_CHECK_VERSION(3,0,0) GtkWidget* holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous(GTK_BOX(holder), FALSE); #else GtkWidget *holder = gtk_hbox_new( FALSE, 4 ); #endif GtkEntry *entry = 0; GtkWidget *normal; if (act->private_data->selectionMode == SELECTION_OPEN) { normal = gtk_combo_box_new_with_model_and_entry (act->private_data->model); gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (normal), act->private_data->labelColumn); GtkWidget *child = gtk_bin_get_child( GTK_BIN(normal) ); if (GTK_IS_ENTRY(child)) { int maxUsed = scan_max_width( act->private_data->model, act->private_data->labelColumn ); GtkEntryCompletion *complete = 0; entry = GTK_ENTRY(child); gtk_entry_set_width_chars(entry, maxUsed); /* replace with property */ complete = gtk_entry_completion_new(); gtk_entry_completion_set_model( complete, act->private_data->model ); gtk_entry_completion_set_text_column( complete, act->private_data->labelColumn ); gtk_entry_completion_set_inline_completion( complete, FALSE ); gtk_entry_completion_set_inline_selection( complete, FALSE ); gtk_entry_completion_set_popup_completion( complete, TRUE ); gtk_entry_completion_set_popup_set_width( complete, FALSE ); gtk_entry_set_completion( entry, complete ); g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(combo_entry_changed_cb), act ); g_signal_connect( G_OBJECT(child), "focus-out-event", G_CALLBACK(combo_entry_focus_lost_cb), act ); } } else { GtkCellRenderer * renderer = NULL; normal = gtk_combo_box_new_with_model( act->private_data->model ); if ( act->private_data->iconColumn >= 0 ) { renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(normal), renderer, TRUE ); /* "icon-name" */ gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT(normal), renderer, "stock-id", act->private_data->iconColumn ); } renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(normal), renderer, TRUE ); gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT(normal), renderer, "text", act->private_data->labelColumn ); } gtk_combo_box_set_active( GTK_COMBO_BOX(normal), act->private_data->active ); if ( entry && (act->private_data->active == -1) ) { gtk_entry_set_text( entry, act->private_data->activeText ); } g_signal_connect( G_OBJECT(normal), "changed", G_CALLBACK(combo_changed_cb), action ); g_object_set_data( G_OBJECT(holder), "ege-combo-box", normal ); g_object_set_data( G_OBJECT(act), "ege-combo-box", normal ); if (act->private_data->appearanceMode == APPEARANCE_COMPACT) { gchar* sss = 0; g_object_get( G_OBJECT(action), "short_label", &sss, NULL ); if (sss) { GtkWidget* lbl = gtk_label_new(sss); gtk_box_pack_start( GTK_BOX(holder), lbl, FALSE, FALSE, 4 ); g_free( sss ); sss = 0; } } gtk_box_pack_start( GTK_BOX(holder), normal, FALSE, FALSE, 0 ); { #if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(holder, GTK_ALIGN_START); gtk_container_add(GTK_CONTAINER(item), holder); #else GtkWidget *align = gtk_alignment_new(0, 0.5, 0, 0); gtk_container_add( GTK_CONTAINER(align), holder); gtk_container_add( GTK_CONTAINER(item), align ); #endif } } gtk_widget_show_all( item ); } else { item = GTK_ACTION_CLASS(ege_select_one_action_parent_class)->create_tool_item( action ); } return item; }
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; }
static GObject *constructor (GType type, guint n_properties, GObjectConstructParam * properties) { AnnumShellWindow *self; AnnumShellWindowPrivate *priv; GObject *object; GObjectClass *parent_class; GtkAction *action; GdkScreen *screen; gint monitor; GdkRectangle rect; GtkRadioAction *radio_action; GtkWidget *button_image; parent_class = G_OBJECT_CLASS (annum_shell_window_parent_class); object = parent_class->constructor (type, n_properties, properties); self = ANNUM_SHELL_WINDOW (object); priv = self->priv = GET_PRIVATE (self); gtk_widget_realize (GTK_WIDGET (self)); screen = gdk_screen_get_default (); monitor = gdk_screen_get_monitor_at_window (screen, GTK_WIDGET (self)->window); gdk_screen_get_monitor_geometry (screen, monitor, &rect); gtk_window_set_default_size (GTK_WINDOW (self), rect.width, rect.height); gtk_window_set_decorated (GTK_WINDOW (self), FALSE); /* This is a fake action, just because EShellView needs one, but we * have only one view, so an action to switch views is needless. */ radio_action = gtk_radio_action_new ("Calendar", NULL, NULL, NULL, 0); priv->shell_view = g_object_new (ANNUM_TYPE_SHELL_VIEW, "action", radio_action, "shell-window", self, NULL); g_signal_connect_swapped (priv->shell_view, "date-changed", G_CALLBACK (date_changed_cb), self); /* Main layout */ priv->vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (self), priv->vbox); priv->toolbox = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (priv->toolbox), 6); gtk_box_pack_start (GTK_BOX (priv->vbox), priv->toolbox, FALSE, FALSE, 0); /* Top toolbox */ priv->today_button = gtk_toggle_button_new (); gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->today_button, FALSE, FALSE, 0); priv->week_button = gtk_toggle_button_new (); gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->week_button, FALSE, FALSE, 0); priv->month_button = gtk_toggle_button_new (); gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->month_button, FALSE, FALSE, 0); priv->quickadd_entry = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->quickadd_entry), "This space intentionally left blank."); gtk_widget_set_sensitive (priv->quickadd_entry, FALSE); gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->quickadd_entry, TRUE, TRUE, 0); priv->quit_button = gtk_button_new (); g_signal_connect (priv->quit_button, "clicked", G_CALLBACK (close_window_cb), self); gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->quit_button, FALSE, FALSE, 0); button_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_LARGE_TOOLBAR); gtk_container_add (GTK_CONTAINER (priv->quit_button), button_image); /* Sidebar, and main content view */ priv->hpaned = gtk_hpaned_new (); /* FIXME: store the position somehow? */ gtk_paned_set_position (GTK_PANED (priv->hpaned), 250); gtk_box_pack_start (GTK_BOX (priv->vbox), priv->hpaned, TRUE, TRUE, 0); priv->sidebar = e_shell_view_get_shell_sidebar (E_SHELL_VIEW (priv->shell_view)); gtk_paned_add1 (GTK_PANED (priv->hpaned), GTK_WIDGET (priv->sidebar)); priv->content_view = e_shell_view_get_shell_content (E_SHELL_VIEW (priv->shell_view)); gtk_paned_add2 (GTK_PANED (priv->hpaned), GTK_WIDGET (priv->content_view)); /* Set up actions */ priv->action_group = gtk_action_group_new ("AnnumActions"); gtk_action_group_add_radio_actions (priv->action_group, annum_view_actions, G_N_ELEMENTS (annum_view_actions), ANNUM_VIEW_TODAY, G_CALLBACK (annum_shell_window_change_view_cb), self); /* Today */ action = gtk_action_group_get_action (priv->action_group, "ShowToday"); gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->today_button), action); /* Week */ action = gtk_action_group_get_action (priv->action_group, "ShowWeek"); gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->week_button), action); /* Month */ action = gtk_action_group_get_action (priv->action_group, "ShowMonth"); gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->month_button), action); return object; }