[Gambas-user] Multiselect files

ML ml at ...973...
Wed May 11 12:46:53 CEST 2005


On 10/05/2005 11:45, Marco Gusy wrote:
> Thanks for the fast answer!
> 
> I think Dialog class should allow multiselect, if any developer would like to 
> implement this it would be great.

Well, a quick hack that works for me is in the attached patches to CDialog.cpp
files in gb.qt and gb.qt.kde that allow to select multiple files.

The new method Dialog.OpenFiles behaves like its brother Dialog.OpenFile (that
is it returns true if no files have been selected and vice versa) but, after
calling OpenFiles, Dialog.Path contains a string containing all the files
chosen, separated by spaces.

You can then easily split the string to get an array of the files you selected.

Ciao,
Piero

-------------- next part --------------
--- CDialog_orig.cpp	2005-05-10 23:59:45.000000000 +0200
+++ CDialog.cpp	2005-05-11 12:10:16.000000000 +0200
@@ -148,6 +148,25 @@
 
 END_METHOD
 
+BEGIN_METHOD_VOID(CDIALOG_open_files)
+
+  QStringList files;
+
+  files = QFileDialog::getOpenFileNames(get_filter(), dialog_path,
+  qApp->activeWindow(), 0, dialog_title);
+
+  if (files.isEmpty())
+    GB.ReturnBoolean(true);
+  else
+  {
+    dialog_path = files.join(" ");
+    GB.ReturnBoolean(false);
+  }
+
+  dialog_title = QString::null;
+
+END_METHOD
+
 
 BEGIN_METHOD_VOID(CDIALOG_save_file)
 
@@ -246,6 +265,7 @@
   GB_STATIC_METHOD("_exit", NULL, CDIALOG_exit, NULL),
 
   GB_STATIC_METHOD("OpenFile", "b", CDIALOG_open_file, NULL),
+  GB_STATIC_METHOD("OpenFiles", "b", CDIALOG_open_files, NULL),
   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),
-------------- next part --------------
--- CDialog_orig.cpp	2005-05-11 12:18:15.000000000 +0200
+++ CDialog.cpp	2005-05-11 12:01:27.000000000 +0200
@@ -69,7 +69,7 @@
   }
 
   //qDebug("%s", s.latin1());
-  
+
   return s;
 }
 
@@ -124,7 +124,7 @@
   {
     if (GB.CheckObject(VPROP(GB_OBJECT)))
       return;
-  
+
     dialog_font = *(((QT_FONT *)VPROP(GB_OBJECT))->font);
   }
 
@@ -160,6 +160,25 @@
 END_METHOD
 
 
+BEGIN_METHOD_VOID(CDIALOG_open_files)
+
+  QStringList files;
+
+  files = KFileDialog::getOpenFileNames(dialog_path, get_filter(),
+  qApp->activeWindow(), dialog_title);
+
+  if (files.isEmpty())
+    GB.ReturnBoolean(true);
+  else
+  {
+    dialog_path = files.join(" ");
+    GB.ReturnBoolean(false);
+  }
+
+  dialog_title = QString::null;
+
+END_METHOD
+
 
 BEGIN_METHOD_VOID(CDIALOG_save_file)
 
@@ -193,7 +212,7 @@
     dialog_path = file;
     GB.ReturnBoolean(false);
   }
-  
+
   dialog_title = QString::null;
 
 END_METHOD
@@ -237,6 +256,7 @@
   GB_STATIC_METHOD("_exit", NULL, CDIALOG_exit, NULL),
 
   GB_STATIC_METHOD("OpenFile", "b", CDIALOG_open_file, NULL),
+  GB_STATIC_METHOD("OpenFiles", "b", CDIALOG_open_files, NULL),
   GB_STATIC_METHOD("SaveFile", "b", CDIALOG_save_file, NULL),
   GB_STATIC_METHOD("SelectDirectory", "b", CDIALOG_get_directory, NULL),
 


More information about the User mailing list