Kazuhiro NISHIYAMA
zn****@mbf*****
2005年 4月 28日 (木) 19:19:27 JST
西山和広です。 >>>>> On Mon, 25 Apr 2005 09:56:55 +0900 >>>>> poinc****@ikezo*****(Hiroyuki Ikezoe) said: > これは、将来的に、いくつかのフォーマットを同時にメニューに出せるようにと > りあえづ、 > copy_tab_format1 > とかにしておいてください。 1つしか使えないとcopyurlplusの代わりにならないので、 複数対応に挑戦してみました。 copy_document_format1=%t%t%test%%t%t%t copy_document_format_title1=test copy_document_format2=((<"%t%"|URL:%u%>)) copy_document_format_title2=RD のように1から順に(99まで)使えるようにしています。 途中が抜けているとその前までになります。 copy_document_format_title%dの方がメニューに表示される文字列で copy_document_format%dが今まで通りのコピーする文字列の指定です。 -- |ZnZ(ゼット エヌ ゼット) |西山和広(Kazuhiro NISHIYAMA) -------------- next part -------------- Index: src/actions/kz-actions-popup.c =================================================================== RCS file: /cvsroot/kazehakase/kazehakase/src/actions/kz-actions-popup.c,v retrieving revision 1.50 diff -u -p -r1.50 kz-actions-popup.c --- src/actions/kz-actions-popup.c 7 Mar 2005 12:32:05 -0000 1.50 +++ src/actions/kz-actions-popup.c 28 Apr 2005 10:10:00 -0000 @@ -36,6 +36,7 @@ #define KZ_ACTIONS_POPUP_LANGUAGE_KEY "KzActionsPopup::Language" #define KZ_ACTIONS_POPUP_TAB_KEY "KzActionsPopup::Tab" +#define KZ_ACTIONS_POPUP_COPY_IN_USER_FORMAT_KEY "KzActionsPopup::CopyInUserFormat" typedef enum { LOCATION_LINK, @@ -367,6 +368,112 @@ cb_popup_menu_hide (void) } static void +cb_copy_in_user_format_menuitem_activate (GtkWidget *menuitem, KzWindow *kz) +{ + GtkWidget *widget; + gint idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), + KZ_ACTIONS_POPUP_COPY_IN_USER_FORMAT_KEY)); + gchar conf_key[] = "copy_document_format99"; + gchar *format; + gchar *text; + gchar *str; + gint i; + gint counts = 0; + + g_return_if_fail(0 < idx && idx < 100); + g_return_if_fail(KZ_IS_WINDOW (kz)); + + widget = KZ_WINDOW_CURRENT_PAGE(kz); + if (!KZ_IS_EMBED(widget)) return; + + text = kz_embed_get_selection_string(KZ_EMBED(widget)); + if (!text) text = g_strdup(""); + + g_snprintf(conf_key, sizeof(conf_key), "copy_document_format%d", idx); + format = KZ_CONF_GET_STR("Global" , conf_key); + g_return_if_fail(format); + + for(i = 0; format[i] != '\0'; i++) + if(format[i] == '%') counts++; + counts++; + + if(counts != 1) + { + gchar **temp = g_alloca(sizeof(gchar*) * (counts + 1)); + gchar **splited = g_strsplit(format , "%" , counts); + gint st = 0; + + for(i = 0; i < counts-1; i++) + { + if(st == 0) + { + /* first state */ + temp[i] = splited[i]; + st = 1; + } + else if (st == 2) + { + /* after %t% and so on */ + temp[i] = splited[i]; + st = 1; + } + else if (splited[i][0] == '\0') + { + /* "%%" */ + temp[i] = "%"; + st = 0; + } + else if (splited[i][1] != '\0') + { + /* %text% */ + temp[i] = splited[i]; + st = 1; + } + else if(splited[i][0] == 't') + { + /* %t% */ + temp[i] = (gchar*)kz_embed_get_title(KZ_EMBED(widget)); + st = 2; + } + else if(splited[i][0] == 'u') + { + /* %u% */ + temp[i] = (gchar*)kz_embed_get_location(KZ_EMBED(widget)); + st = 2; + } + else if(splited[i][0] == 's') + { + /* %s% */ + temp[i] = text; + st = 2; + } + else + { + /* '%' + other char + '%' */ + temp[i] = splited[i]; + st = 1; + } + } + temp[counts-1] = splited[counts-1]; + temp[counts] = NULL; + + str = g_strjoinv(NULL , temp); + g_strfreev(splited); + } + else + { + str = g_strdup(format); + } + + g_free(format); + + gtkutil_copy_text(str); + + if(str) g_free(str); + if(text) g_free(text); +} + +static void cb_tablist_menuitem_activate (GtkWidget *menuitem, KzWindow *kz) { gint page_num; @@ -602,6 +709,61 @@ create_lang_menu_item (KzWindow *kz, KzX } static void +kz_actions_popup_append_copy_in_user_format_menuitem (KzWindow *kz, + GtkMenuItem *copy_in_user_format_menu) +{ + GtkWidget *copy_in_user_format_submenu; + GtkWidget *menuitem; + gchar *title; + gchar conf_key[] = "copy_document_format_title99"; + gint i; + + if (!popup_menu_table) + { + popup_menu_table = g_hash_table_new(g_direct_hash, + g_direct_equal); + } + + copy_in_user_format_submenu = g_hash_table_lookup(popup_menu_table, copy_in_user_format_menu); + if (copy_in_user_format_submenu) return; + + /* append copy in user format menuitem */ + copy_in_user_format_submenu = gtk_menu_new(); + + for (i = 1; i < 100; i++) + { + g_snprintf(conf_key, sizeof(conf_key), "copy_document_format_title%d", i); + title = KZ_CONF_GET_STR("Global" , conf_key); + if(!title) break; + + menuitem = gtk_menu_item_new_with_label(title); + + g_object_set_data (G_OBJECT(menuitem), + KZ_ACTIONS_POPUP_COPY_IN_USER_FORMAT_KEY, + GINT_TO_POINTER(i)); + + g_signal_connect(menuitem, "activate", + G_CALLBACK(cb_copy_in_user_format_menuitem_activate), + kz); + + gtk_menu_shell_append(GTK_MENU_SHELL(copy_in_user_format_submenu), + menuitem); + gtk_widget_show(menuitem); + + g_free(title); + } + + gtk_menu_item_set_submenu(GTK_MENU_ITEM(copy_in_user_format_menu), + copy_in_user_format_submenu); + + /* reference */ + g_hash_table_insert(popup_menu_table, copy_in_user_format_menu, + copy_in_user_format_submenu); + g_signal_connect(copy_in_user_format_menu, "destroy", + G_CALLBACK(cb_popup_destroy), NULL); +} + +static void kz_actions_popup_append_encoding_menuitem (KzWindow *kz, GtkMenuItem *encoding_menu) { @@ -882,6 +1044,17 @@ kz_actions_popup_menu_modal (KzWindow *k gtkutil_append_im_menuitem(GTK_MENU_SHELL(popup_menu)); } + /* add copy in user format */ + g_snprintf(extra_menu_path, + sizeof(extra_menu_path), "%s/CopyInUserFormat", path); + + extra_menu = GET_MENU(kz, extra_menu_path); + if(extra_menu) + { + kz_actions_popup_append_copy_in_user_format_menuitem + (kz, GTK_MENU_ITEM(extra_menu)); + } + /* add encoding menu */ g_snprintf(extra_menu_path, sizeof(extra_menu_path), "%s/EncodingMenu", path);