* NEW: Dialog.ShowHidden is a new property to show or hide hidden files. It
  does not work on GTK+ at the moment. Is it a GTK+ bug?

[GB.QT4]
* NEW: Dialog.ShowHidden is a new property to show or hide hidden files.



git-svn-id: svn://localhost/gambas/trunk@4439 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2012-01-31 10:25:32 +00:00
parent f7690d1afd
commit 8449b0b9b3
4 changed files with 163 additions and 57 deletions

View file

@ -36,7 +36,7 @@ BEGIN_METHOD_VOID(CDIALOG_exit)
END_METHOD
BEGIN_PROPERTY(CDIALOG_title)
BEGIN_PROPERTY(Dialog_Title)
if (READ_PROPERTY)
GB.ReturnNewZeroString(gDialog::title());
@ -46,7 +46,7 @@ BEGIN_PROPERTY(CDIALOG_title)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_filter)
BEGIN_PROPERTY(Dialog_Filter)
char **filters;
char *filter;
@ -81,7 +81,7 @@ BEGIN_PROPERTY(CDIALOG_filter)
END_PROPERTY
#if 0
BEGIN_PROPERTY(CDIALOG_filter)
BEGIN_PROPERTY(Dialog_Filter)
GB_ARRAY Array=NULL;
char **buf=NULL;
@ -153,7 +153,7 @@ BEGIN_PROPERTY(CDIALOG_filter)
END_PROPERTY
#endif
BEGIN_PROPERTY(CDIALOG_paths)
BEGIN_PROPERTY(Dialog_Paths)
GB_ARRAY Array=NULL;
char **buf=NULL;
@ -176,15 +176,28 @@ BEGIN_PROPERTY(CDIALOG_paths)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_path)
if (READ_PROPERTY) { GB.ReturnNewZeroString( gDialog::path()); return; }
gDialog::setPath(GB.ToZeroString(PROP(GB_STRING)));
BEGIN_PROPERTY(Dialog_Path)
if (READ_PROPERTY)
GB.ReturnNewZeroString( gDialog::path());
else
gDialog::setPath(GB.ToZeroString(PROP(GB_STRING)));
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_font)
BEGIN_PROPERTY(Dialog_ShowHidden)
if (READ_PROPERTY)
GB.ReturnBoolean(gDialog::showHidden());
else
gDialog::setShowHidden(VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(Dialog_Font)
CFONT *ft;
@ -207,7 +220,7 @@ BEGIN_PROPERTY(CDIALOG_font)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_color)
BEGIN_PROPERTY(Dialog_Color)
if (READ_PROPERTY) { GB.ReturnInteger( gDialog::color() ); return; }
gDialog::setColor(VPROP(GB_INTEGER));
@ -215,7 +228,7 @@ BEGIN_PROPERTY(CDIALOG_color)
END_PROPERTY
BEGIN_METHOD(CDIALOG_open_file,GB_BOOLEAN Multi;)
BEGIN_METHOD(Dialog_OpenFile,GB_BOOLEAN Multi;)
bool Multi=false;
@ -226,28 +239,28 @@ BEGIN_METHOD(CDIALOG_open_file,GB_BOOLEAN Multi;)
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_save_file)
BEGIN_METHOD_VOID(Dialog_SaveFile)
GB.ReturnBoolean( gDialog::saveFile() );
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_get_directory)
BEGIN_METHOD_VOID(Dialog_SelectDirectory)
GB.ReturnBoolean( gDialog::selectFolder() );
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_get_color)
BEGIN_METHOD_VOID(Dialog_SelectColor)
GB.ReturnBoolean ( gDialog::selectColor() );
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_select_font)
BEGIN_METHOD_VOID(Dialog_SelectFont)
GB.ReturnBoolean ( gDialog::selectFont() );
@ -260,19 +273,20 @@ GB_DESC CDialogDesc[] =
GB_STATIC_METHOD("_exit", 0, CDIALOG_exit, 0),
GB_STATIC_METHOD("OpenFile", "b", CDIALOG_open_file, "[(Multi)b]"),
GB_STATIC_METHOD("SaveFile", "b", CDIALOG_save_file, 0),
GB_STATIC_METHOD("SelectDirectory", "b", CDIALOG_get_directory, 0),
GB_STATIC_METHOD("SelectColor", "b", CDIALOG_get_color, 0),
GB_STATIC_METHOD("SelectFont", "b", CDIALOG_select_font, 0),
GB_STATIC_METHOD("OpenFile", "b", Dialog_OpenFile, "[(Multi)b]"),
GB_STATIC_METHOD("SaveFile", "b", Dialog_SaveFile, 0),
GB_STATIC_METHOD("SelectDirectory", "b", Dialog_SelectDirectory, 0),
GB_STATIC_METHOD("SelectColor", "b", Dialog_SelectColor, 0),
GB_STATIC_METHOD("SelectFont", "b", Dialog_SelectFont, 0),
GB_STATIC_PROPERTY_READ("Paths", "String[]", CDIALOG_paths),
GB_STATIC_PROPERTY_READ("Paths", "String[]", Dialog_Paths),
GB_STATIC_PROPERTY("Title", "s", CDIALOG_title),
GB_STATIC_PROPERTY("Path", "s", CDIALOG_path),
GB_STATIC_PROPERTY("Filter", "String[]", CDIALOG_filter),
GB_STATIC_PROPERTY("Color", "i", CDIALOG_color),
GB_STATIC_PROPERTY("Font", "Font", CDIALOG_font),
GB_STATIC_PROPERTY("Title", "s", Dialog_Title),
GB_STATIC_PROPERTY("Path", "s", Dialog_Path),
GB_STATIC_PROPERTY("Filter", "String[]", Dialog_Filter),
GB_STATIC_PROPERTY("Color", "i", Dialog_Color),
GB_STATIC_PROPERTY("Font", "Font", Dialog_Font),
GB_STATIC_PROPERTY("ShowHidden", "b", Dialog_ShowHidden),
GB_END_DECLARE
};

View file

@ -37,12 +37,14 @@ public:
static char* path();
static char* title();
static gFont* font();
static bool showHidden();
static void setColor(gColor col);
static void setFilter(char **filter, int nfilter);
static void setPath(char *vl);
static void setTitle(char *title);
static void setFont(gFont *ft);
static void setShowHidden(bool v);
static bool selectColor();
static bool selectFolder();

View file

@ -40,6 +40,7 @@ static char *DIALOG_path=NULL;
static char **DIALOG_paths=NULL;
static char *DIALOG_title=NULL;
static gFont *DIALOG_font=NULL;
static bool _dialog_show_hidden = false;
static int run_dialog(GtkDialog *window)
{
@ -226,7 +227,7 @@ gDialog
GPtrArray *gDialog::_filter = NULL;
static void gDialog_filters(GtkFileChooser* ch)
static void set_filters(GtkFileChooser* ch)
{
char **filters;
int nfilters;
@ -277,7 +278,7 @@ static bool run_file_dialog(GtkFileChooserDialog *msg)
char *buf;
long b=0;
gDialog_filters((GtkFileChooser*)msg);
set_filters((GtkFileChooser*)msg);
if (run_dialog(GTK_DIALOG(msg)) != GTK_RESPONSE_OK)
{
@ -404,6 +405,16 @@ void gDialog::setPath(char *vl)
strcpy(DIALOG_path,vl);
}
bool gDialog::showHidden()
{
return _dialog_show_hidden;
}
void gDialog::setShowHidden(bool v)
{
_dialog_show_hidden = v;
}
char** gDialog::filter(int *nfilter)
{
if (!_filter)
@ -451,14 +462,16 @@ bool gDialog::openFile(bool multi)
gtk_file_chooser_set_local_only((GtkFileChooser*)msg, true);
gtk_file_chooser_set_select_multiple((GtkFileChooser*)msg, multi);
gtk_file_chooser_set_show_hidden((GtkFileChooser*)msg, _dialog_show_hidden);
gtk_widget_show(GTK_WIDGET(msg));
gtk_file_chooser_unselect_all((GtkFileChooser*)msg);
if (DIALOG_path)
{
gtk_file_chooser_select_filename((GtkFileChooser*)msg, DIALOG_path);
if (g_file_test(DIALOG_path, G_FILE_TEST_IS_DIR))
gtk_file_chooser_set_current_folder((GtkFileChooser*)msg, DIALOG_path);
else
gtk_file_chooser_select_filename((GtkFileChooser*)msg, DIALOG_path);
}
return run_file_dialog(msg);
@ -475,14 +488,21 @@ bool gDialog::saveFile()
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
(void *)NULL);
gtk_file_chooser_set_do_overwrite_confirmation((GtkFileChooser*)msg, true);
gtk_file_chooser_set_local_only((GtkFileChooser*)msg, true);
gtk_file_chooser_set_select_multiple((GtkFileChooser*)msg, false);
gtk_file_chooser_set_show_hidden((GtkFileChooser*)msg, _dialog_show_hidden);
gtk_widget_show(GTK_WIDGET(msg));
gtk_file_chooser_unselect_all((GtkFileChooser*)msg);
if (DIALOG_path)
gtk_file_chooser_set_filename ((GtkFileChooser*)msg, DIALOG_path);
{
if (g_file_test(DIALOG_path, G_FILE_TEST_IS_DIR))
gtk_file_chooser_set_current_folder((GtkFileChooser*)msg, DIALOG_path);
else
gtk_file_chooser_select_filename((GtkFileChooser*)msg, DIALOG_path);
}
return run_file_dialog(msg);
}
@ -501,6 +521,7 @@ bool gDialog::selectFolder()
gtk_file_chooser_set_local_only((GtkFileChooser*)msg, true);
gtk_file_chooser_set_select_multiple((GtkFileChooser*)msg, false);
gtk_file_chooser_set_show_hidden((GtkFileChooser*)msg, _dialog_show_hidden);
gtk_widget_show(GTK_WIDGET(msg));
gtk_file_chooser_unselect_all((GtkFileChooser*)msg);
if (DIALOG_path)
@ -508,7 +529,7 @@ bool gDialog::selectFolder()
if (g_file_test(DIALOG_path, G_FILE_TEST_IS_DIR))
gtk_file_chooser_set_current_folder((GtkFileChooser*)msg, DIALOG_path);
else
gtk_file_chooser_set_filename((GtkFileChooser*)msg, DIALOG_path);
gtk_file_chooser_select_filename((GtkFileChooser*)msg, DIALOG_path);
}
return run_file_dialog(msg);

View file

@ -40,6 +40,7 @@ static GB_ARRAY dialog_filter = NULL;
static QString dialog_path;
static GB_ARRAY dialog_paths = NULL;
static CFONT *dialog_font = NULL;
static bool dialog_show_hidden = false;
static unsigned int dialog_color = 0;
@ -81,7 +82,7 @@ BEGIN_METHOD_VOID(CDIALOG_exit)
END_METHOD
BEGIN_PROPERTY(CDIALOG_title)
BEGIN_PROPERTY(Dialog_Title)
if (READ_PROPERTY)
GB.ReturnNewZeroString(TO_UTF8(dialog_title));
@ -91,7 +92,7 @@ BEGIN_PROPERTY(CDIALOG_title)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_filter)
BEGIN_PROPERTY(Dialog_Filter)
if (READ_PROPERTY)
GB.ReturnObject(dialog_filter);
@ -101,7 +102,17 @@ BEGIN_PROPERTY(CDIALOG_filter)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_path)
BEGIN_PROPERTY(Dialog_ShowHidden)
if (READ_PROPERTY)
GB.ReturnBoolean(dialog_show_hidden);
else
dialog_show_hidden = VPROP(GB_BOOLEAN);
END_PROPERTY
BEGIN_PROPERTY(Dialog_Path)
if (READ_PROPERTY)
GB.ReturnNewZeroString(TO_UTF8(dialog_path));
@ -111,14 +122,14 @@ BEGIN_PROPERTY(CDIALOG_path)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_paths)
BEGIN_PROPERTY(Dialog_Paths)
GB.ReturnObject(dialog_paths);
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_font)
BEGIN_PROPERTY(Dialog_Font)
if (READ_PROPERTY)
GB.ReturnObject(dialog_font);
@ -137,7 +148,7 @@ BEGIN_PROPERTY(CDIALOG_font)
END_PROPERTY
BEGIN_PROPERTY(CDIALOG_color)
BEGIN_PROPERTY(Dialog_Color)
if (READ_PROPERTY)
GB.ReturnInteger(dialog_color);
@ -147,13 +158,70 @@ BEGIN_PROPERTY(CDIALOG_color)
END_PROPERTY
BEGIN_METHOD(CDIALOG_open_file, GB_BOOLEAN multi)
static QString my_getOpenFileName()
{
QFileDialog dialog(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
dialog.setMode(QFileDialog::ExistingFile);
dialog.setOption(QFileDialog::DontUseNativeDialog);
dialog.setFilter(dialog_show_hidden ? (dialog.filter() | QDir::Hidden | QDir::System) : (dialog.filter() & ~(QDir::Hidden | QDir::System)));
if (dialog.exec() == QDialog::Accepted)
return dialog.selectedFiles().value(0);
else
return QString();
}
static QStringList my_getOpenFileNames()
{
QFileDialog dialog(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
dialog.setMode(QFileDialog::ExistingFiles);
dialog.setOption(QFileDialog::DontUseNativeDialog);
dialog.setFilter(dialog_show_hidden ? (dialog.filter() | QDir::Hidden | QDir::System) : (dialog.filter() & ~(QDir::Hidden | QDir::System)));
if (dialog.exec() == QDialog::Accepted)
return dialog.selectedFiles();
else
return QStringList();
}
static QString my_getSaveFileName()
{
QFileDialog dialog(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setMode(QFileDialog::AnyFile);
dialog.setOption(QFileDialog::DontUseNativeDialog);
dialog.setFilter(dialog_show_hidden ? (dialog.filter() | QDir::Hidden | QDir::System) : (dialog.filter() & ~(QDir::Hidden | QDir::System)));
if (dialog.exec() == QDialog::Accepted)
return dialog.selectedFiles().value(0);
else
return QString();
}
static QString my_getExistingDirectory()
{
QFileDialog dialog(qApp->activeWindow(), dialog_title, dialog_path);
dialog.setMode(QFileDialog::Directory);
dialog.setOption(QFileDialog::DontUseNativeDialog);
if (dialog.exec() == QDialog::Accepted)
return dialog.selectedFiles().value(0);
else
return QString();
}
BEGIN_METHOD(Dialog_OpenFile, GB_BOOLEAN multi)
if (!VARGOPT(multi, false))
{
QString file;
file = QFileDialog::getOpenFileName(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
file = my_getOpenFileName();
if (file.isNull())
GB.ReturnBoolean(true);
@ -170,7 +238,7 @@ BEGIN_METHOD(CDIALOG_open_file, GB_BOOLEAN multi)
GB_OBJECT ob;
int i;
files = QFileDialog::getOpenFileNames(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
files = my_getOpenFileNames();
if (files.isEmpty())
{
@ -195,11 +263,11 @@ BEGIN_METHOD(CDIALOG_open_file, GB_BOOLEAN multi)
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_save_file)
BEGIN_METHOD_VOID(Dialog_SaveFile)
QString file;
file = QFileDialog::getSaveFileName(qApp->activeWindow(), dialog_title, dialog_path, get_filter());
file = my_getSaveFileName();
if (file.isNull())
GB.ReturnBoolean(true);
@ -214,11 +282,11 @@ BEGIN_METHOD_VOID(CDIALOG_save_file)
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_get_directory)
BEGIN_METHOD_VOID(Dialog_SelectDirectory)
QString file;
file = QFileDialog::getExistingDirectory(qApp->activeWindow(), dialog_title, dialog_path);
file = my_getExistingDirectory();
if (file.isNull())
GB.ReturnBoolean(true);
@ -233,7 +301,7 @@ BEGIN_METHOD_VOID(CDIALOG_get_directory)
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_get_color)
BEGIN_METHOD_VOID(Dialog_SelectColor)
QColor color;
@ -250,7 +318,7 @@ BEGIN_METHOD_VOID(CDIALOG_get_color)
END_METHOD
BEGIN_METHOD_VOID(CDIALOG_select_font)
BEGIN_METHOD_VOID(Dialog_SelectFont)
QFont qfont;
bool ok;
@ -301,18 +369,19 @@ GB_DESC CDialogDesc[] =
//GB_STATIC_METHOD("_init", NULL, CDIALOG_init, NULL),
GB_STATIC_METHOD("_exit", NULL, CDIALOG_exit, NULL),
GB_STATIC_METHOD("OpenFile", "b", CDIALOG_open_file, "[(Multi)b]"),
GB_STATIC_METHOD("SaveFile", "b", CDIALOG_save_file, NULL),
GB_STATIC_METHOD("SelectDirectory", "b", CDIALOG_get_directory, NULL),
GB_STATIC_METHOD("SelectColor", "b", CDIALOG_get_color, NULL),
GB_STATIC_METHOD("SelectFont", "b", CDIALOG_select_font, NULL),
GB_STATIC_METHOD("OpenFile", "b", Dialog_OpenFile, "[(Multi)b]"),
GB_STATIC_METHOD("SaveFile", "b", Dialog_SaveFile, NULL),
GB_STATIC_METHOD("SelectDirectory", "b", Dialog_SelectDirectory, NULL),
GB_STATIC_METHOD("SelectColor", "b", Dialog_SelectColor, NULL),
GB_STATIC_METHOD("SelectFont", "b", Dialog_SelectFont, NULL),
GB_STATIC_PROPERTY("Title", "s", CDIALOG_title),
GB_STATIC_PROPERTY("Path", "s", CDIALOG_path),
GB_STATIC_PROPERTY_READ("Paths", "String[]", CDIALOG_paths),
GB_STATIC_PROPERTY("Filter", "String[]", CDIALOG_filter),
GB_STATIC_PROPERTY("Color", "i", CDIALOG_color),
GB_STATIC_PROPERTY("Font", "Font", CDIALOG_font),
GB_STATIC_PROPERTY("Title", "s", Dialog_Title),
GB_STATIC_PROPERTY("Path", "s", Dialog_Path),
GB_STATIC_PROPERTY_READ("Paths", "String[]", Dialog_Paths),
GB_STATIC_PROPERTY("Filter", "String[]", Dialog_Filter),
GB_STATIC_PROPERTY("Color", "i", Dialog_Color),
GB_STATIC_PROPERTY("Font", "Font", Dialog_Font),
GB_STATIC_PROPERTY("ShowHidden", "b", Dialog_ShowHidden),
GB_END_DECLARE
};