Mercurial > vim
comparison src/gui_gtk.c @ 3664:0e06193d4bd7 v7.3.592
updated for version 7.3.592
Problem: Vim on GTK does not support g:browsefilter.
Solution: Add a GtkFileFilter to the file chooser. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 10 Jul 2012 13:12:51 +0200 |
parents | 8d1b63e6d317 |
children | 46896c29edd7 |
comparison
equal
deleted
inserted
replaced
3663:906c91f4fae8 | 3664:0e06193d4bd7 |
---|---|
838 gui_mch_browse(int saving UNUSED, | 838 gui_mch_browse(int saving UNUSED, |
839 char_u *title, | 839 char_u *title, |
840 char_u *dflt, | 840 char_u *dflt, |
841 char_u *ext UNUSED, | 841 char_u *ext UNUSED, |
842 char_u *initdir, | 842 char_u *initdir, |
843 char_u *filter UNUSED) | 843 char_u *filter) |
844 { | 844 { |
845 #ifdef USE_FILE_CHOOSER | 845 #ifdef USE_FILE_CHOOSER |
846 GtkWidget *fc; | 846 GtkWidget *fc; |
847 #endif | 847 #endif |
848 char_u dirbuf[MAXPATHL]; | 848 char_u dirbuf[MAXPATHL]; |
849 guint log_handler; | 849 guint log_handler; |
850 const gchar *domain = "Gtk"; | 850 const gchar *domain = "Gtk"; |
851 GtkFileFilter *gfilter; | |
851 | 852 |
852 title = CONVERT_TO_UTF8(title); | 853 title = CONVERT_TO_UTF8(title); |
853 | 854 |
854 /* GTK has a bug, it only works with an absolute path. */ | 855 /* GTK has a bug, it only works with an absolute path. */ |
855 if (initdir == NULL || *initdir == NUL) | 856 if (initdir == NULL || *initdir == NUL) |
877 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 878 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
878 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 879 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
879 NULL); | 880 NULL); |
880 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), | 881 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), |
881 (const gchar *)dirbuf); | 882 (const gchar *)dirbuf); |
883 | |
884 if (filter != NULL && *filter != NUL) | |
885 { | |
886 int i = 0; | |
887 char_u *patt; | |
888 char_u *p = filter; | |
889 | |
890 gfilter = gtk_file_filter_new(); | |
891 patt = alloc(STRLEN(filter)); | |
892 while (p != NULL && *p != NUL) | |
893 { | |
894 if (*p == '\n' || *p == ';' || *p == '\t') | |
895 { | |
896 STRNCPY(patt, filter, i); | |
897 patt[i] = '\0'; | |
898 if (*p == '\t') | |
899 gtk_file_filter_set_name(gfilter, (gchar *)patt); | |
900 else | |
901 { | |
902 gtk_file_filter_add_pattern(gfilter, (gchar *)patt); | |
903 if (*p == '\n') | |
904 { | |
905 gtk_file_chooser_add_filter((GtkFileChooser *)fc, | |
906 gfilter); | |
907 if (*(p + 1) != NUL) | |
908 gfilter = gtk_file_filter_new(); | |
909 } | |
910 } | |
911 filter = ++p; | |
912 i = 0; | |
913 } | |
914 else | |
915 { | |
916 p++; | |
917 i++; | |
918 } | |
919 } | |
920 vim_free(patt); | |
921 } | |
882 if (saving && dflt != NULL && *dflt != NUL) | 922 if (saving && dflt != NULL && *dflt != NUL) |
883 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt); | 923 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt); |
884 | 924 |
885 gui.browse_fname = NULL; | 925 gui.browse_fname = NULL; |
886 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) | 926 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) |
1302 | 1342 |
1303 entry = gtk_entry_new(); | 1343 entry = gtk_entry_new(); |
1304 gtk_widget_show(entry); | 1344 gtk_widget_show(entry); |
1305 | 1345 |
1306 /* Make Enter work like pressing OK. */ | 1346 /* Make Enter work like pressing OK. */ |
1307 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); | 1347 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); |
1308 | 1348 |
1309 text = CONVERT_TO_UTF8(textfield); | 1349 text = CONVERT_TO_UTF8(textfield); |
1310 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text); | 1350 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text); |
1311 CONVERT_TO_UTF8_FREE(text); | 1351 CONVERT_TO_UTF8_FREE(text); |
1312 | 1352 |