Add extension filter for file dialogs, specify filters and starting folder for loading plugins

This commit is contained in:
Berke Viktor 2012-07-21 21:42:48 +02:00
parent 2b3e1f46e3
commit bc651b0222
12 changed files with 46 additions and 20 deletions

View File

@ -105,12 +105,13 @@ void fe_set_away (server *serv);
void fe_serverlist_open (session *sess);
void fe_get_str (char *prompt, char *def, void *callback, void *ud);
void fe_get_int (char *prompt, int def, void *callback, void *ud);
#define FRF_WRITE 1 /* save file */
#define FRF_MULTIPLE 2 /* multi-select */
#define FRF_ADDFOLDER 4 /* add ~/.xchat2 to favourites */
#define FRF_CHOOSEFOLDER 8 /* choosing a folder only */
#define FRF_FILTERISINITIAL 16 /* unused */
#define FRF_WRITE 1 /* save file */
#define FRF_MULTIPLE 2 /* multi-select */
#define FRF_ADDFOLDER 4 /* add ~/.config/hexchat to favourites */
#define FRF_CHOOSEFOLDER 8 /* choosing a folder only */
#define FRF_FILTERISINITIAL 16 /* filter is initial directory */
#define FRF_NOASKOVERWRITE 32 /* don't ask to overwrite existing files */
#define FRF_EXTENSIONS 64 /* specify file extensions to be displayed */
void fe_get_file (const char *title, char *initial,
void (*callback) (void *userdata, char *file), void *userdata,
int flags);

View File

@ -530,7 +530,7 @@ chanlist_save (GtkWidget * wid, server *serv)
if (gtk_tree_model_get_iter_first (model, &iter))
gtkutil_file_req (_("Select an output filename"), chanlist_filereq_done,
serv, NULL, FRF_WRITE);
serv, NULL, NULL, FRF_WRITE);
}
static gboolean

View File

@ -165,7 +165,7 @@ fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive)
mdc->passive = passive;
snprintf (tbuf, sizeof tbuf, _("Send file to %s"), nick);
gtkutil_file_req (tbuf, dcc_send_filereq_file, mdc, NULL, FRF_MULTIPLE);
gtkutil_file_req (tbuf, dcc_send_filereq_file, mdc, NULL, NULL, FRF_MULTIPLE);
}
static void

View File

@ -893,7 +893,7 @@ fe_confirm (const char *message, void (*yesproc)(void *), void (*noproc)(void *)
struct DCC *dcc = ud;
if (dcc->file)
gtkutil_file_req (message, dcc_saveas_cb, ud, dcc->file,
gtkutil_file_req (message, dcc_saveas_cb, ud, dcc->file, NULL,
FRF_WRITE|FRF_FILTERISINITIAL|FRF_NOASKOVERWRITE);
}
@ -1144,5 +1144,5 @@ fe_get_file (const char *title, char *initial,
{
/* OK: Call callback once per file, then once more with file=NULL. */
/* CANCEL: Call callback once with file=NULL. */
gtkutil_file_req (title, callback, userdata, initial, flags | FRF_FILTERISINITIAL);
gtkutil_file_req (title, callback, userdata, initial, NULL, flags | FRF_FILTERISINITIAL);
}

View File

@ -370,12 +370,15 @@ win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq)
#endif /* native file dialogs */
void
gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter,
gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
int flags)
{
struct file_req *freq;
GtkWidget *dialog;
GtkFileFilter *filefilter;
extern char *get_xdir_fs (void);
char *token;
char *tokenbuffer;
#if 0 /* native file dialogs */
#ifdef WIN32
@ -473,6 +476,23 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
}
if (flags & FRF_EXTENSIONS && extensions != NULL)
{
filefilter = gtk_file_filter_new ();
tokenbuffer = g_strdup (extensions);
token = strtok (tokenbuffer, ";");
while (token != NULL)
{
gtk_file_filter_add_pattern (filefilter, token);
token = strtok (NULL, ";");
}
g_free (tokenbuffer);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filefilter);
g_free (filefilter);
}
freq = malloc (sizeof (struct file_req));
freq->dialog = dialog;
freq->flags = flags;

View File

@ -10,7 +10,7 @@ typedef void (*filereqcallback) (void *, char *file);
#define FRF_FILTERISINITIAL 16
#define FRF_NOASKOVERWRITE 32
void gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, int flags);
void gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions, int flags);
void gtkutil_destroy (GtkWidget * igad, GtkWidget * dgad);
GtkWidget *gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback,
void *userdata, char *labeltext);

View File

@ -1288,7 +1288,7 @@ static void
menu_savebuffer (GtkWidget * wid, gpointer none)
{
gtkutil_file_req (_("Select an output filename"), savebuffer_req_done,
current_sess, NULL, FRF_WRITE);
current_sess, NULL, NULL, FRF_WRITE);
}
static void

View File

@ -41,6 +41,7 @@ typedef struct session xchat_context;
#include "../common/outbound.h"
#include "../common/fe.h"
#include "../common/xchatc.h"
#include "../common/cfgfiles.h"
#include "gtkutil.h"
/* model for the plugin treeview */
@ -154,7 +155,11 @@ plugingui_load (void)
#else
#endif
#endif /* native file dialogs */
NULL, FRF_ADDFOLDER);
#ifdef WIN32
get_xdir_utf8 (), "*.dll;*.lua;*.pl;*.py;*.tcl", FRF_ADDFOLDER|FRF_FILTERISINITIAL|FRF_EXTENSIONS);
#else
get_xdir_utf8 (), "*.so;*.lua;*.pl;*.py;*.tcl", FRF_ADDFOLDER|FRF_FILTERISINITIAL|FRF_EXTENSIONS);
#endif
}
static void

View File

@ -81,7 +81,7 @@ rawlog_clearbutton (GtkWidget * wid, server *serv)
static int
rawlog_savebutton (GtkWidget * wid, server *serv)
{
gtkutil_file_req (_("Save As..."), rawlog_save, serv, NULL, FRF_WRITE);
gtkutil_file_req (_("Save As..."), rawlog_save, serv, NULL, NULL, FRF_WRITE);
return FALSE;
}

View File

@ -955,7 +955,7 @@ setup_filereq_cb (GtkWidget *entry, char *file)
static void
setup_browsefile_cb (GtkWidget *button, GtkWidget *entry)
{
gtkutil_file_req (_("Select an Image File"), setup_filereq_cb, entry, NULL, 0);
gtkutil_file_req (_("Select an Image File"), setup_filereq_cb, entry, NULL, NULL, 0);
}
static void
@ -990,7 +990,7 @@ setup_fontsel_cancel (GtkWidget *button, GtkFontSelectionDialog *dialog)
static void
setup_browsefolder_cb (GtkWidget *button, GtkEntry *entry)
{
gtkutil_file_req (_("Select Download Folder"), setup_filereq_cb, entry, entry->text, FRF_CHOOSEFOLDER);
gtkutil_file_req (_("Select Download Folder"), setup_filereq_cb, entry, entry->text, NULL, FRF_CHOOSEFOLDER);
}
static void
@ -1552,7 +1552,7 @@ setup_snd_filereq_cb (GtkWidget *entry, char *file)
static void
setup_snd_browse_cb (GtkWidget *button, GtkEntry *entry)
{
gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry, NULL, 0);
gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry, NULL, NULL, 0);
}
static void

View File

@ -302,7 +302,7 @@ pevent_save_cb (GtkWidget * wid, void *data)
if (data)
{
gtkutil_file_req (_("Print Texts File"), pevent_save_req_cb, NULL,
NULL, FRF_WRITE);
NULL, NULL, FRF_WRITE);
return;
}
pevent_save (NULL);
@ -324,7 +324,7 @@ pevent_load_req_cb (void *arg1, char *file)
static void
pevent_load_cb (GtkWidget * wid, void *data)
{
gtkutil_file_req (_("Print Texts File"), pevent_load_req_cb, NULL, NULL, 0);
gtkutil_file_req (_("Print Texts File"), pevent_load_req_cb, NULL, NULL, NULL, 0);
}
static void

View File

@ -145,7 +145,7 @@ static void
url_button_save (void)
{
gtkutil_file_req (_("Select an output filename"),
url_save_callback, NULL, NULL, FRF_WRITE);
url_save_callback, NULL, NULL, NULL, FRF_WRITE);
}
void