Game Development Community

why OpenFileDialog does not return anything when "MultipleFiles=true;"?

by Ahsan Muzaheed · in Torque 3D Professional · 08/29/2012 (7:11 am) · 10 replies

function selectFile()
{
   %dlg = new OpenFileDialog()
	      {
			  Filters = "DSQ Files(*.dsq)|*.dsq|COLLADA Files|*.dae|Google Earth Files|*.kmz";
			  DefaultFile = makeRelativePath(getMainDotCSDir() );
			  ChangePath = false;
			  MustExist = true;
			  MultipleFiles = true;//false;//
			  title="open Animation file(dae/dsq/kmz)";
	      };
		  
   %t=%dlg.Execute();
   if ( !%t )
    error("eeeeeeeeeeeeeeeeeeeee");
   else if ( %t )
   {
     echo(%dlg.FileName);
     //%dlg.getMultipleFiles();
     //getMultipleFiles(%dlg);
   }
	 
}

you will get "" in %dlg.FileName.

now set "MultipleFiles = false;" and select a dsq file.u will get the address in %dlg.FileName.


in (EnginesourceplatformWin32nativeDialogsfileDialog.cpp) i got this lines.but i failed to understand what getMultipleFiles() is doing.

void OpenFileDialog::initPersistFields()
{
   addProtectedField("MustExist", TypeBool, Offset(mMustExist, OpenFileDialog), &setMustExist, &getMustExist, "True/False whether the file returned must exist or not" );
   addProtectedField("MultipleFiles", TypeBool, Offset(mMultipleFiles, OpenFileDialog), &setMultipleFiles, &getMultipleFiles, "True/False whether multiple files may be selected and returned or not" );
   
   Parent::initPersistFields();
}

const char* OpenFileDialog::getMultipleFiles(void* obj, const char* data)
{
   OpenFileDialog *pDlg = static_cast<OpenFileDialog*>( obj );
   if( pDlg->mData.mStyle & FileDialogData::FDS_MULTIPLEFILES )
      return StringTable->insert("true");
   else
      return StringTable->insert("false");
}

About the author

Torque 3D enthusiastic since 2010.Have been working in several T3D projects besides of Unreal Engine 4 and Unity 3D. NEED a hand with your project? SHoot me a mail. http://www.garagegames.com/community/forums /viewthread/138437/


#1
08/29/2012 (1:26 pm)
I think you have to call a function on the dialog after exit if "true" to get the list of files. Look for a console method on the dialog and there is a function to explicitly get multiple files.
#2
08/29/2012 (8:34 pm)
"I think you have to call a function on the dialog "
yeah,i thought so.and was searching for that function.but failed.no function related to OpenFileDialog exposed in console.only i have got that getMultipleFiles().

ok.i will do a search again.
#3
08/29/2012 (9:16 pm)
no.nothing.

even i have added this just after new OpenFileDialog() {}.
%dlg.dump();
%dlg.dumpMethods();

last one dump no method list!!!!!!!!!!.

even i have searched in forum and also in all templates for a example with
" MultipleFiles = true;".
nothing found.


do u know any function to return all selected files?
#4
08/30/2012 (1:37 am)
In fileDialog.cpp -
"After an Execute() call, the chosen file name and path is available in one of two areas.  "
   "If only a single file selection is permitted, the results will be stored in the @a fileName "
   "attribute.\n\n"

"If multiple file selection is permitted, the results will be stored in the "
   "@a files array.  The total number of files in the array will be stored in the "
   "@a fileCount attribute.\n\n"


so, this should work:
function selectFile()
{
   %dlg = new OpenFileDialog()
	      {
			  Filters = "DSQ Files(*.dsq)|*.dsq|COLLADA Files|*.dae|Google Earth Files|*.kmz";
			  DefaultFile = makeRelativePath(getMainDotCSDir() );
			  ChangePath = false;
			  MustExist = true;
			  MultipleFiles = true;
			  title="open Animation file(dae/dsq/kmz)";
	      };
		  
   if ( %dlg.Execute() )
   {
      echo("NumFiles:" SPC %dlg.fileCount);
      for(%i=0; %i < %dlg.fileCount; %i++)
         echo(%dlg.files[%i]);
   }	 
}
#5
08/30/2012 (6:02 am)
Guy,
u are a great saver.
thanks.

i was depending on "Torque 3D - Script Manual.chm".
u give me a lesson.
from now if anything not found that will try cpp file's quote just after forum search
#6
08/30/2012 (8:45 am)
Hah - I thought you might have already looked there. I was going to look it up this morning but Guy beat me to it. I find that generally, even if the comments in the code are not useful reading the code itself is.

Let that be a lesson! Heh. Took me a while to figure it out for myself....
#7
08/30/2012 (11:06 am)
I was using this is a totally different way. I didn't know you could do the above. I was using dialogpush an dialogpop and callback functions on the dialog buttons. However I was using a custom dialog I built in the editor and using the widget that does file selection. Maybe I am using a completely different widget. When I get home I will post a snippet as I may be making this harder than it should be.
#8
08/30/2012 (9:00 pm)
"I was using dialogpush an dialogpop and callback functions on the dialog buttons."
can u explain more.not clear.

i always having problem to find out c++ side callback.what i do is to find out TS function's console implementation then go on from that source file.

but not always there is console implementation.and in that case it is pain for me.most of the time i left it there after 10-20 minute try. just like this time.
#9
08/30/2012 (11:22 pm)
@ahsan,
I used the editor to create a dialog similar to the options menu. This is what it looks like in the gui file:
%guiContent = new GuiControl(selectFileDlg) {
   position = "0 0";
   extent = "1024 768";
   minExtent = "8 2";
   horizSizing = "right";
   vertSizing = "bottom";
   profile = "GuiOverlayProfile";
   visible = "1";
   active = "1";
   tooltipProfile = "GuiToolTipProfile";
   hovertime = "1000";
   isContainer = "1";
   canSave = "1";
   canSaveDynamicFields = "1";

   new GuiWindowCtrl() {
      text = "File Selection";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "0";
      canClose = "1";
      canMinimize = "0";
      canMaximize = "0";
      canCollapse = "0";
      closeCommand = "Canvas.popDialog(selectFileDlg);";
      edgeSnap = "1";
      margin = "0 0 0 0";
      padding = "0 0 0 0";
      anchorTop = "1";
      anchorBottom = "0";
      anchorLeft = "1";
      anchorRight = "0";
      position = "231 188";
      extent = "363 316";
      minExtent = "8 2";
      horizSizing = "right";
      vertSizing = "bottom";
      profile = "GuiWindowProfile";
      visible = "1";
      active = "1";
      tooltipProfile = "GuiToolTipProfile";
      hovertime = "1000";
      isContainer = "1";
      internalName = "dialogContainer";
      canSave = "1";
      canSaveDynamicFields = "0";

      new GuiScrollCtrl() {
         willFirstRespond = "1";
         hScrollBar = "alwaysOn";
         vScrollBar = "alwaysOn";
         lockHorizScroll = "0";
         lockVertScroll = "0";
         constantThumbHeight = "0";
         childMargin = "0 0";
         mouseWheelScrollSpeed = "-1";
         margin = "0 0 0 0";
         padding = "0 0 0 0";
         anchorTop = "1";
         anchorBottom = "0";
         anchorLeft = "1";
         anchorRight = "0";
         position = "10 30";
         extent = "343 232";
         minExtent = "8 2";
         horizSizing = "right";
         vertSizing = "bottom";
         profile = "GuiScrollProfile";
         visible = "1";
         active = "1";
         tooltipProfile = "GuiToolTipProfile";
         hovertime = "1000";
         isContainer = "1";
         canSave = "1";
         canSaveDynamicFields = "0";
#10
08/30/2012 (11:23 pm)
new GuiDirectoryFileListCtrl() {
            fileFilter = "*.*";
            allowMultipleSelections = "0";
            fitParentWidth = "1";
            colorBullet = "1";
            position = "1 1";
            extent = "325 256";
            minExtent = "8 2";
            horizSizing = "right";
            vertSizing = "bottom";
            profile = "GuiDirectoryFileListProfile";
            visible = "1";
            active = "1";
            command = "selectFileDlg-->okaybutton.active = true;";
            tooltipProfile = "GuiToolTipProfile";
            hovertime = "1000";
            isContainer = "0";
            internalName = "fileList";
            canSave = "1";
            canSaveDynamicFields = "0";
         };
      };
      new GuiButtonCtrl() {
         text = "Cancel";
         groupNum = "-1";
         buttonType = "PushButton";
         useMouseEvents = "0";
         position = "10 276";
         extent = "87 30";
         minExtent = "8 2";
         horizSizing = "right";
         vertSizing = "bottom";
         profile = "GuiButtonProfile";
         visible = "1";
         active = "1";
         command = "selectFileDlg.cancel();";
         tooltipProfile = "GuiToolTipProfile";
         hovertime = "1000";
         isContainer = "0";
         canSave = "1";
         canSaveDynamicFields = "0";
      };
      new GuiButtonCtrl() {
         text = "OK";
         groupNum = "-1";
         buttonType = "PushButton";
         useMouseEvents = "0";
         position = "266 276";
         extent = "87 30";
         minExtent = "8 2";
         horizSizing = "right";
         vertSizing = "bottom";
         profile = "GuiButtonProfile";
         visible = "1";
         active = "0";
         command = "selectFileDlg.okay();";
         tooltipProfile = "GuiToolTipProfile";
         hovertime = "1000";
         isContainer = "0";
         internalName = "okaybutton";
         canSave = "1";
         canSaveDynamicFields = "0";
      };
   };
};
It uses the GuiDirectoryFileListCtrl for the directory listing. That is why I was so confused. I did not know there a OpenFileDialog widget in existence. So I had created my own dialog control. I will have to play with that. Sorry for the confusion.