comparison src/bar_keywords.c @ 1421:130054d9dd8a

added a dialog for editing keyword tree
author nadvornik
date Thu, 12 Mar 2009 21:27:13 +0000
parents 6ce1f7171d48
children 80462be81410
comparison
equal deleted inserted replaced
1420:3a9fb1b52559 1421:130054d9dd8a
118 118
119 FileData *fd; 119 FileData *fd;
120 gchar *key; 120 gchar *key;
121 }; 121 };
122 122
123 typedef struct _ConfDialogData ConfDialogData;
124 struct _ConfDialogData
125 {
126 PaneKeywordsData *pkd;
127 GtkTreePath *click_tpath;
128
129 /* dialog parts */
130 GenericDialog *gd;
131 GtkWidget *edit_widget;
132 gboolean is_keyword;
133
134 gboolean edit_existing;
135 };
123 136
124 static GList *bar_list = NULL; 137 static GList *bar_list = NULL;
125 138
126 139
127 static void bar_pane_keywords_write(PaneKeywordsData *pkd) 140 static void bar_pane_keywords_write(PaneKeywordsData *pkd)
444 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); 457 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW);
445 bar_pane_keywords_update(pkd); 458 bar_pane_keywords_update(pkd);
446 */ 459 */
447 } 460 }
448 461
462 /*
463 *-------------------------------------------------------------------
464 * dnd
465 *-------------------------------------------------------------------
466 */
467
449 468
450 static GtkTargetEntry bar_pane_keywords_drag_types[] = { 469 static GtkTargetEntry bar_pane_keywords_drag_types[] = {
451 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH }, 470 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH },
452 { "text/plain", 0, TARGET_TEXT_PLAIN } 471 { "text/plain", 0, TARGET_TEXT_PLAIN }
453 }; 472 };
662 gdk_drag_status(context, GDK_ACTION_COPY, time); 681 gdk_drag_status(context, GDK_ACTION_COPY, time);
663 682
664 return TRUE; 683 return TRUE;
665 } 684 }
666 685
667 static void bar_pane_keywords_conf_dialog_cb(GtkWidget *menu_widget, gpointer data) 686 /*
668 { 687 *-------------------------------------------------------------------
688 * edit dialog
689 *-------------------------------------------------------------------
690 */
691
692 static void bar_pane_keywords_edit_destroy_cb(GtkWidget *widget, gpointer data)
693 {
694 ConfDialogData *cdd = data;
695 gtk_tree_path_free(cdd->click_tpath);
696 g_free(cdd);
697 }
698
699
700 static void bar_pane_keywords_edit_cancel_cb(GenericDialog *gd, gpointer data)
701 {
702 }
703
704
705 static void bar_pane_keywords_edit_ok_cb(GenericDialog *gd, gpointer data)
706 {
707 ConfDialogData *cdd = data;
708 PaneKeywordsData *pkd = cdd->pkd;
709 GtkTreeModel *model;
710
711 GtkTreeModel *keyword_tree;
712 GtkTreeIter kw_iter;
713
714 gboolean have_dest = FALSE;
715
716 GList *keywords;
717
718 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
719 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));
720
721 if (cdd->click_tpath)
722 {
723 GtkTreeIter iter;
724 if (gtk_tree_model_get_iter(model, &iter, cdd->click_tpath))
725 {
726 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter);
727 have_dest = TRUE;
728 }
729 }
730
731 if (cdd->edit_existing && !have_dest) return;
732
733 keywords = keyword_list_pull(cdd->edit_widget);
734
735 if (cdd->edit_existing)
736 {
737 if (keywords && keywords->data) /* there should be one keyword */
738 {
739 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, keywords->data, cdd->is_keyword);
740 }
741 }
742 else
743 {
744 GList *work = keywords;
745
746 while (work)
747 {
748 GtkTreeIter add;
749 if (have_dest)
750 {
751 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &kw_iter);
752 }
753 else
754 {
755 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, NULL);
756 have_dest = TRUE;
757 }
758 kw_iter = add;
759 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, work->data, cdd->is_keyword);
760 work = work->next;
761 }
762 }
763 string_list_free(keywords);
764 }
765
766 static void bar_pane_keywords_conf_set_helper(GtkWidget *widget, gpointer data)
767 {
768 ConfDialogData *cdd = data;
769 cdd->is_keyword = FALSE;
770 }
771
772 static void bar_pane_keywords_conf_set_kw(GtkWidget *widget, gpointer data)
773 {
774 ConfDialogData *cdd = data;
775 cdd->is_keyword = TRUE;
776 }
777
778
779
780 static void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_existing)
781 {
782 ConfDialogData *cdd;
783 GenericDialog *gd;
784 GtkWidget *table;
785 GtkWidget *group;
786 GtkWidget *button;
787
788 gchar *name = NULL;
789 gboolean is_keyword = TRUE;
790
791
792 if (edit_existing && pkd->click_tpath)
793 {
794 GtkTreeModel *model;
795 GtkTreeIter iter;
796 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
797
798 if (gtk_tree_model_get_iter(model, &iter, pkd->click_tpath))
799 {
800 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name,
801 FILTER_KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1);
802 }
803 else
804 {
805 return;
806 }
807 }
808
809 if (edit_existing && !name) return;
810
811
812 cdd = g_new0(ConfDialogData, 1);
813 cdd->pkd =pkd;
814 cdd->click_tpath = pkd->click_tpath;
815 pkd->click_tpath = NULL;
816 cdd->is_keyword = is_keyword;
817 cdd->edit_existing = edit_existing;
818
819 cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("Add keywords"), "keyword_edit",
820 pkd->widget, TRUE,
821 bar_pane_keywords_edit_cancel_cb, cdd);
822 g_signal_connect(G_OBJECT(gd->dialog), "destroy",
823 G_CALLBACK(bar_pane_keywords_edit_destroy_cb), cdd);
824
825
826 generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("Add keyword"), NULL);
827
828 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
829 bar_pane_keywords_edit_ok_cb, TRUE);
830
831 table = pref_table_new(gd->vbox, 3, 1, FALSE, TRUE);
832 pref_table_label(table, 0, 0, _("Keyword:"), 1.0);
833 cdd->edit_widget = gtk_entry_new();
834 gtk_widget_set_size_request(cdd->edit_widget, 300, -1);
835 if (name) gtk_entry_set_text(GTK_ENTRY(cdd->edit_widget), name);
836 gtk_table_attach_defaults(GTK_TABLE(table), cdd->edit_widget, 1, 2, 0, 1);
837 /* here could eventually be a text view instead of entry */
838 generic_dialog_attach_default(gd, cdd->edit_widget);
839 gtk_widget_show(cdd->edit_widget);
840
841 group = pref_group_new(gd->vbox, FALSE, _("Keyword type:"), GTK_ORIENTATION_VERTICAL);
842
843 button = pref_radiobutton_new(group, NULL, _("Active keyword"),
844 (cdd->is_keyword),
845 G_CALLBACK(bar_pane_keywords_conf_set_kw), cdd);
846 button = pref_radiobutton_new(group, button, _("Helper"),
847 (!cdd->is_keyword),
848 G_CALLBACK(bar_pane_keywords_conf_set_helper), cdd);
849 g_free(name);
850
851 gtk_widget_show(gd->dialog);
852 }
853
854
855
856
857 /*
858 *-------------------------------------------------------------------
859 * popup menu
860 *-------------------------------------------------------------------
861 */
862
863 static void bar_pane_keywords_edit_dialog_cb(GtkWidget *menu_widget, gpointer data)
864 {
865 PaneKeywordsData *pkd = data;
866 bar_pane_keywords_edit_dialog(pkd, TRUE);
867 }
868
869 static void bar_pane_keywords_add_dialog_cb(GtkWidget *menu_widget, gpointer data)
870 {
871 PaneKeywordsData *pkd = data;
872 bar_pane_keywords_edit_dialog(pkd, FALSE);
669 } 873 }
670 874
671 static void bar_pane_keywords_delete_cb(GtkWidget *menu_widget, gpointer data) 875 static void bar_pane_keywords_delete_cb(GtkWidget *menu_widget, gpointer data)
672 { 876 {
673 PaneKeywordsData *pkd = data; 877 PaneKeywordsData *pkd = data;
708 gtk_tree_model_get_iter(model, &iter, pkd->click_tpath); 912 gtk_tree_model_get_iter(model, &iter, pkd->click_tpath);
709 gchar *name; 913 gchar *name;
710 914
711 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, -1); 915 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, -1);
712 916
713 gchar *conf = g_strdup_printf(_("Configure \"%s\""), name); 917 gchar *conf = g_strdup_printf(_("Edit \"%s\""), name);
714 gchar *del = g_strdup_printf(_("Delete \"%s\""), name); 918 gchar *del = g_strdup_printf(_("Delete \"%s\""), name);
715 menu_item_add_stock(menu, conf, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_conf_dialog_cb), pkd); 919 menu_item_add_stock(menu, conf, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd);
716 menu_item_add_stock(menu, del, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd); 920 menu_item_add_stock(menu, del, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd);
717 menu_item_add_divider(menu); 921 menu_item_add_divider(menu);
718 g_free(conf); 922 g_free(conf);
719 g_free(del); 923 g_free(del);
720 g_free(name); 924 g_free(name);
721 } 925 }
722 /* for the pane */ 926 /* for the pane */
723 // menu_item_add_stock(menu, _("Add entry"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_conf_dialog_cb), pkd); 927 menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);
724 // menu_item_add_check(menu, _("Show hidden entries"), pkd->show_all, G_CALLBACK(bar_pane_keywords_toggle_show_all_cb), pkd);
725 928
726 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME); 929 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
727 } 930 }
728 931
729 932
736 return TRUE; 939 return TRUE;
737 } 940 }
738 return FALSE; 941 return FALSE;
739 } 942 }
740 943
944 /*
945 *-------------------------------------------------------------------
946 * init
947 *-------------------------------------------------------------------
948 */
741 949
742 void bar_pane_keywords_close(GtkWidget *bar) 950 void bar_pane_keywords_close(GtkWidget *bar)
743 { 951 {
744 PaneKeywordsData *pkd; 952 PaneKeywordsData *pkd;
745 953