diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-10-26 08:20:30 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-10-26 08:20:30 +0000 |
commit | 58da77dc80f2f0660e4f8a169e60e24c5d31046c (patch) | |
tree | 521e7e6a3b600060b3e4df6423347ddf3077fc1a /src | |
parent | 48780131a32188263501c094bff8afcbc687e189 (diff) |
add a clear button to the destination combo widget
Diffstat (limited to 'src')
-rw-r--r-- | src/trg-destination-combo.c | 26 | ||||
-rw-r--r-- | src/trg-main-window.c | 41 |
2 files changed, 39 insertions, 28 deletions
diff --git a/src/trg-destination-combo.c b/src/trg-destination-combo.c index ff35325..db9fd31 100644 --- a/src/trg-destination-combo.c +++ b/src/trg-destination-combo.c @@ -41,7 +41,7 @@ enum { }; enum { - DEST_DEFAULT, DEST_LABEL, DEST_EXISTING + DEST_DEFAULT, DEST_LABEL, DEST_EXISTING, DEST_USERADD }; enum { @@ -143,6 +143,22 @@ GtkEntry *trg_destination_combo_get_entry(TrgDestinationCombo *combo) { return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo))); } +static void add_entry_cb(GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + gpointer user_data) +{ + GtkComboBox *combo = GTK_COMBO_BOX(user_data); + GtkTreeModel *model = gtk_combo_box_get_model(combo); + GtkTreeIter iter; + + gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, INT_MAX, + DEST_COLUMN_LABEL, "", + DEST_COLUMN_DIR, "", + DEST_COLUMN_TYPE, DEST_USERADD, -1); + gtk_combo_box_set_active_iter(combo, &iter); +} + static GObject *trg_destination_combo_constructor(GType type, guint n_construct_properties, GObjectConstructParam * construct_params) { GObject *object = G_OBJECT_CLASS @@ -153,6 +169,8 @@ static GObject *trg_destination_combo_constructor(GType type, TrgClient *client = priv->client; TrgPrefs *prefs = trg_client_get_prefs(client); + GtkEntry *entry = trg_destination_combo_get_entry(TRG_DESTINATION_COMBO(object)); + GSList *dirs = NULL, *sli; GList *li, *list; GtkTreeRowReference *rr; @@ -244,6 +262,12 @@ static GObject *trg_destination_combo_constructor(GType type, g_signal_connect (object, "changed", G_CALLBACK (gtk_combo_box_entry_active_changed), NULL); + gtk_entry_set_icon_from_stock(GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY, + GTK_STOCK_CLEAR); + + g_signal_connect(entry, "icon-release", + G_CALLBACK(add_entry_cb), object); + return object; } diff --git a/src/trg-main-window.c b/src/trg-main-window.c index 6ac5dcb..a12fe61 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -138,7 +138,10 @@ static void trg_main_window_set_property(GObject * object, guint property_id, static void quit_cb(GtkWidget * w, gpointer data); static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win); static void status_icon_activated(GtkStatusIcon * icon, gpointer data); -static void clear_filter_entry_cb(GtkWidget * w, gpointer data); +static void clear_filter_entry_cb(GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + gpointer user_data); static gboolean torrent_tv_key_press_event(GtkWidget * w, GdkEventKey * key, gpointer data); static GtkWidget *trg_imagemenuitem_new(GtkMenuShell * shell, const gchar *text, @@ -200,7 +203,7 @@ struct _TrgMainWindowPrivate { gint graphNotebookIndex; GtkWidget *hpaned, *vpaned; - GtkWidget *filterEntry, *filterEntryClearButton; + GtkWidget *filterEntry; gint width, height; guint timerId; @@ -1175,12 +1178,8 @@ static void entry_filter_changed_cb(GtkWidget * w, gpointer data) { gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER (priv->filteredTorrentModel)); -#if GTK_CHECK_VERSION( 2,16,0 ) - g_object_set(priv->filterEntryClearButton, "secondary-icon-sensitive", + g_object_set(priv->filterEntry, "secondary-icon-sensitive", clearSensitive, NULL); -#else - gtk_widget_set_sensitive(priv->filterEntryClearButton, clearSensitive); -#endif } static void torrent_state_selection_changed(TrgStateSelector * selector G_GNUC_UNUSED, @@ -1348,8 +1347,12 @@ static void status_icon_activated(GtkStatusIcon * icon G_GNUC_UNUSED, gpointer d } } -static void clear_filter_entry_cb(GtkWidget * w, gpointer data G_GNUC_UNUSED) { - gtk_entry_set_text(GTK_ENTRY(w), ""); +static void clear_filter_entry_cb(GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + gpointer user_data) +{ + gtk_entry_set_text(entry, ""); } static gboolean torrent_tv_key_press_event(GtkWidget * w, GdkEventKey * key, @@ -1978,30 +1981,14 @@ static GObject *trg_main_window_constructor(GType type, gtk_box_pack_start(GTK_BOX(toolbarHbox), GTK_WIDGET(priv->toolBar), TRUE, TRUE, 0); -#if GTK_CHECK_VERSION( 2,16,0 ) w = gtk_entry_new(); gtk_entry_set_icon_from_stock(GTK_ENTRY(w), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); g_signal_connect(w, "icon-release", - G_CALLBACK(clear_filter_entry_cb), w); + G_CALLBACK(clear_filter_entry_cb), NULL); gtk_box_pack_start(GTK_BOX(toolbarHbox), w, FALSE, FALSE, 0); g_object_set(w, "secondary-icon-sensitive", FALSE, NULL); - priv->filterEntryClearButton = priv->filterEntry = w; -#else - priv->filterEntry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(toolbarHbox), priv->filterEntry, FALSE, - FALSE, 0); - w = gtk_button_new(); - gtk_button_set_relief(GTK_BUTTON(w), GTK_RELIEF_NONE); - gtk_button_set_image(GTK_BUTTON(w), - gtk_image_new_from_stock(GTK_STOCK_CLEAR, - GTK_ICON_SIZE_MENU)); - gtk_box_pack_start(GTK_BOX(toolbarHbox), w, FALSE, FALSE, 0); - g_signal_connect_swapped(w, "clicked", - G_CALLBACK(clear_filter_entry_cb), - priv->filterEntry); - priv->filterEntryClearButton = w; -#endif + priv->filterEntry = w; g_signal_connect(G_OBJECT(priv->filterEntry), "changed", G_CALLBACK(entry_filter_changed_cb), self); |