Skip to content

Commit

Permalink
added a popup menu in keyword tree
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Mar 11, 2009
1 parent 13b5d1f commit 53335b4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/bar_keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct _PaneKeywordsData
GtkWidget *keyword_view;
GtkWidget *keyword_treeview;

GtkTreePath *click_tpath;

FileData *fd;
gchar *key;
};
Expand Down Expand Up @@ -662,6 +664,80 @@ static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *c
return TRUE;
}

static void bar_pane_keywords_conf_dialog_cb(GtkWidget *menu_widget, gpointer data)
{
}

static void bar_pane_keywords_delete_cb(GtkWidget *menu_widget, gpointer data)
{
PaneKeywordsData *pkd = data;
GtkTreeModel *model;
GtkTreeIter iter;

GtkTreeModel *keyword_tree;
GtkTreeIter kw_iter;

if (!pkd->click_tpath) return;

model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));

if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return;
gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter);

keyword_delete(GTK_TREE_STORE(keyword_tree), &kw_iter);
}

static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pkd, gint x, gint y)
{
GtkWidget *menu;
GtkTreeViewDropPosition pos;

if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
pkd->click_tpath = NULL;
gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos);

menu = popup_menu_short_lived();

if (pkd->click_tpath)
{
/* for the entry */
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));

GtkTreeIter iter;
gtk_tree_model_get_iter(model, &iter, pkd->click_tpath);
gchar *name;

gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, -1);

gchar *conf = g_strdup_printf(_("Configure \"%s\""), name);
gchar *del = g_strdup_printf(_("Delete \"%s\""), name);
menu_item_add_stock(menu, conf, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_conf_dialog_cb), pkd);
menu_item_add_stock(menu, del, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd);
menu_item_add_divider(menu);
g_free(conf);
g_free(del);
g_free(name);
}
/* for the pane */
// menu_item_add_stock(menu, _("Add entry"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_conf_dialog_cb), pkd);
// menu_item_add_check(menu, _("Show hidden entries"), pkd->show_all, G_CALLBACK(bar_pane_keywords_toggle_show_all_cb), pkd);

gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
}


static gboolean bar_pane_keywords_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
PaneKeywordsData *pkd = data;
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
bar_pane_keywords_menu_popup(widget, pkd, bevent->x, bevent->y);
return TRUE;
}
return FALSE;
}


void bar_pane_keywords_close(GtkWidget *bar)
{
Expand All @@ -677,6 +753,8 @@ static void bar_pane_keywords_destroy(GtkWidget *widget, gpointer data)
{
PaneKeywordsData *pkd = data;

if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);

file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd);

file_data_unref(pkd->fd);
Expand Down Expand Up @@ -838,6 +916,9 @@ GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key, gboolean
g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_motion",
G_CALLBACK(bar_pane_keywords_dnd_motion), pkd);

g_signal_connect(G_OBJECT(pkd->keyword_treeview), "button_press_event",
G_CALLBACK(bar_pane_keywords_menu_cb), pkd);

gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_treeview);
gtk_widget_show(pkd->keyword_treeview);

Expand Down
6 changes: 6 additions & 0 deletions src/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,12 @@ void keyword_tree_reset(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList
}
}

void keyword_delete(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr)
{
gtk_tree_store_remove(keyword_tree, iter_ptr);
}


void keyword_tree_new(void)
{
if (keyword_tree) return;
Expand Down
2 changes: 2 additions & 0 deletions src/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ gboolean keyword_tree_is_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GLis
void keyword_tree_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list);
void keyword_tree_reset(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list);

void keyword_delete(GtkTreeStore *keyword_tree, GtkTreeIter *iter_ptr);

void keyword_tree_new_default(void);
void keyword_tree_new(void);

Expand Down

0 comments on commit 53335b4

Please sign in to comment.