Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dorota Czaplejewicz
gtk
Commits
510d65ba
Commit
510d65ba
authored
Dec 01, 2010
by
Cosimo Cecchi
Browse files
app-chooser-button: add gtk_app_chooser_button_set_active_custom_item()
This allows to pre-select a custom item.
parent
9ffd1f7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
gtk/gtkappchooserbutton.c
View file @
510d65ba
...
...
@@ -556,6 +556,37 @@ gtk_app_chooser_button_init (GtkAppChooserButton *self)
g_free
,
NULL
);
}
static
gboolean
app_chooser_button_iter_from_custom_name
(
GtkAppChooserButton
*
self
,
const
gchar
*
name
,
GtkTreeIter
*
set_me
)
{
GtkTreeIter
iter
;
gchar
*
custom_name
=
NULL
;
if
(
!
gtk_tree_model_get_iter_first
(
GTK_TREE_MODEL
(
self
->
priv
->
store
),
&
iter
))
return
FALSE
;
do
{
gtk_tree_model_get
(
GTK_TREE_MODEL
(
self
->
priv
->
store
),
&
iter
,
COLUMN_NAME
,
&
custom_name
,
-
1
);
if
(
g_strcmp0
(
custom_name
,
name
)
==
0
)
{
g_free
(
custom_name
);
*
set_me
=
iter
;
return
TRUE
;
}
g_free
(
custom_name
);
}
while
(
gtk_tree_model_iter_next
(
GTK_TREE_MODEL
(
self
->
priv
->
store
),
&
iter
));
return
FALSE
;
}
static
void
real_insert_custom_item
(
GtkAppChooserButton
*
self
,
const
gchar
*
name
,
...
...
@@ -670,6 +701,36 @@ gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self,
real_insert_custom_item
(
self
,
name
,
label
,
icon
,
TRUE
,
&
iter
);
}
/**
* gtk_app_chooser_button_select_custom_item:
* @self: a #GtkAppChooserButton
* @name: the name of the custom item
*
* Selects a custom item previously added with
* gtk_app_chooser_button_append_custom_item().
*
* Since: 3.0
*/
void
gtk_app_chooser_button_set_active_custom_item
(
GtkAppChooserButton
*
self
,
const
gchar
*
name
)
{
GtkTreeIter
iter
;
g_return_if_fail
(
GTK_IS_APP_CHOOSER_BUTTON
(
self
));
g_return_if_fail
(
name
!=
NULL
);
if
(
g_hash_table_lookup
(
self
->
priv
->
custom_item_names
,
name
)
==
NULL
||
!
app_chooser_button_iter_from_custom_name
(
self
,
name
,
&
iter
))
{
g_warning
(
"Can't find the item named %s in the app chooser."
,
name
);
return
;
}
gtk_combo_box_set_active_iter
(
GTK_COMBO_BOX
(
self
),
&
iter
);
}
/**
* gtk_app_chooser_button_get_show_dialog_item:
* @self: a #GtkAppChooserButton
...
...
gtk/gtkappchooserbutton.h
View file @
510d65ba
...
...
@@ -68,6 +68,8 @@ void gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self
const
gchar
*
name
,
const
gchar
*
label
,
GIcon
*
icon
);
void
gtk_app_chooser_button_set_active_custom_item
(
GtkAppChooserButton
*
self
,
const
gchar
*
name
);
void
gtk_app_chooser_button_set_show_dialog_item
(
GtkAppChooserButton
*
self
,
gboolean
setting
);
...
...
tests/testappchooserbutton.c
View file @
510d65ba
...
...
@@ -122,6 +122,9 @@ main (int argc,
/* test refresh on a combo */
gtk_app_chooser_refresh
(
GTK_APP_CHOOSER
(
combobox
));
gtk_app_chooser_button_set_active_custom_item
(
GTK_APP_CHOOSER_BUTTON
(
combobox
),
CUSTOM_ITEM
);
gtk_widget_show_all
(
toplevel
);
g_signal_connect
(
toplevel
,
"delete-event"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment