Torque3D Documentation / _generateds / guiDirectoryFileListCtrl.cpp

guiDirectoryFileListCtrl.cpp

Engine/source/gui/controls/guiDirectoryFileListCtrl.cpp

More...

Public Functions

ConsoleDocClass(GuiDirectoryFileListCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> list of files from within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single directory " "in the game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguidirectoryfilelistctrl/">GuiDirectoryFileListCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   filePath = \"art/shapes\";\n" "   fileFilter = \"*.dts\" TAB \"*.dae\";\n" "   //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControls\n</a>" )
DefineEngineMethod(GuiDirectoryFileListCtrl , getSelectedFile , const char * , () , "Get the currently selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filename.\n\n</a>" "@return The filename of the currently selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" )
DefineEngineMethod(GuiDirectoryFileListCtrl , getSelectedFiles , const char * , () , "Get the list of selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n\n</a>" "@return A space separated list of selected files" )
DefineEngineMethod(GuiDirectoryFileListCtrl , reload , void , () , "Update the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> list." )
DefineEngineMethod(GuiDirectoryFileListCtrl , setFilter , void , (const char *filter) , "Set the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filter.\n\n</a>" "@param filter Tab-delimited list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name patterns. Only matched files will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">displayed.\n</a>" )
DefineEngineMethod(GuiDirectoryFileListCtrl , setPath , bool , (const char *path, const char *filter) , "Set the search path and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filter.\n\n</a>" "@param path Path in game directory from which <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> list <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n</a>" "@param filter Tab-delimited list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name patterns. Only matched files will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">displayed.\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(GuiDirectoryFileListCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> list of files from within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single directory " "in the game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguidirectoryfilelistctrl/">GuiDirectoryFileListCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "   filePath = \"art/shapes\";\n" "   fileFilter = \"*.dts\" TAB \"*.dae\";\n" "   //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControls\n</a>" )

DefineEngineMethod(GuiDirectoryFileListCtrl , getSelectedFile , const char * , () , "Get the currently selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filename.\n\n</a>" "@return The filename of the currently selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" )

DefineEngineMethod(GuiDirectoryFileListCtrl , getSelectedFiles , const char * , () , "Get the list of selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n\n</a>" "@return A space separated list of selected files" )

DefineEngineMethod(GuiDirectoryFileListCtrl , reload , void , () , "Update the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> list." )

DefineEngineMethod(GuiDirectoryFileListCtrl , setFilter , void , (const char *filter) , "Set the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filter.\n\n</a>" "@param filter Tab-delimited list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name patterns. Only matched files will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">displayed.\n</a>" )

DefineEngineMethod(GuiDirectoryFileListCtrl , setPath , bool , (const char *path, const char *filter) , "Set the search path and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">filter.\n\n</a>" "@param path Path in game directory from which <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> list <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">files.\n</a>" "@param filter Tab-delimited list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> name patterns. Only matched files will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">displayed.\n</a>" )

IMPLEMENT_CONOBJECT(GuiDirectoryFileListCtrl )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "console/engineAPI.h"
 25#include "core/strings/findMatch.h"
 26#include "gui/controls/guiDirectoryFileListCtrl.h"
 27
 28
 29IMPLEMENT_CONOBJECT( GuiDirectoryFileListCtrl );
 30
 31ConsoleDocClass( GuiDirectoryFileListCtrl,
 32   "@brief A control that displays a list of files from within a single directory "
 33   "in the game file system.\n\n"
 34
 35   "@tsexample\n\n"
 36   "new GuiDirectoryFileListCtrl()\n"
 37   "{\n"
 38   "   filePath = \"art/shapes\";\n"
 39   "   fileFilter = \"*.dts\" TAB \"*.dae\";\n"
 40   "   //Properties not specific to this control have been omitted from this example.\n"
 41   "};\n"
 42   "@endtsexample\n\n"
 43
 44   "@ingroup GuiControls\n"
 45);
 46
 47GuiDirectoryFileListCtrl::GuiDirectoryFileListCtrl()
 48{
 49   mFilePath = StringTable->insert( "" );
 50   mFilter = StringTable->insert( "*.*" );
 51}
 52
 53void GuiDirectoryFileListCtrl::initPersistFields()
 54{
 55   addProtectedField( "filePath", TypeString, Offset( mFilePath, GuiDirectoryFileListCtrl ),
 56                      &_setFilePath, &defaultProtectedGetFn, "Path in game directory from which to list files." );
 57   addProtectedField( "fileFilter", TypeString, Offset( mFilter, GuiDirectoryFileListCtrl ),
 58                      &_setFilter, &defaultProtectedGetFn, "Tab-delimited list of file name patterns. Only matched files will be displayed." );
 59                      
 60   Parent::initPersistFields();
 61}
 62
 63bool GuiDirectoryFileListCtrl::onWake()
 64{
 65   if( !Parent::onWake() )
 66      return false;
 67      
 68   update();
 69   
 70   return true;
 71}
 72
 73void GuiDirectoryFileListCtrl::onMouseDown(const GuiEvent &event)
 74{
 75   Parent::onMouseDown( event );
 76
 77   if( event.mouseClickCount == 2 )
 78      onDoubleClick_callback();
 79}
 80
 81
 82void GuiDirectoryFileListCtrl::openDirectory()
 83{
 84   String path;
 85   if( mFilePath && mFilePath[ 0 ] )
 86      path = String::ToString( "%s/%s", Platform::getMainDotCsDir(), mFilePath );
 87   else
 88      path = Platform::getMainDotCsDir();
 89   
 90   Vector<Platform::FileInfo> fileVector;
 91   Platform::dumpPath( path, fileVector, 0 );
 92
 93   // Clear the current file listing
 94   clearItems();
 95
 96   // Does this dir have any files?
 97   if( fileVector.empty() )
 98      return;
 99
100   // If so, iterate through and list them
101   Vector<Platform::FileInfo>::iterator i = fileVector.begin();
102   for( S32 j=0 ; i != fileVector.end(); i++, j++ )
103   {
104      if( !mFilter[ 0 ] || FindMatch::isMatchMultipleExprs( mFilter, (*i).pFileName,false ) )
105         addItem( (*i).pFileName );
106   }
107}
108
109
110void GuiDirectoryFileListCtrl::setCurrentFilter( const char* filter )
111{
112   if( !filter )
113      filter = "";
114
115   mFilter = StringTable->insert( filter );
116
117   // Update our view
118   openDirectory();
119}
120
121DefineEngineMethod( GuiDirectoryFileListCtrl, setFilter, void, ( const char* filter ),,
122   "Set the file filter.\n\n"
123   "@param filter Tab-delimited list of file name patterns. Only matched files will be displayed.\n" )
124{
125   object->setCurrentFilter( filter );
126}
127
128bool GuiDirectoryFileListCtrl::setCurrentPath( const char* path, const char* filter )
129{
130   if( !path )
131      return false;
132
133   const U32 pathLen = dStrlen( path );
134   if( pathLen > 0 && path[ pathLen - 1 ] == '/' )
135      mFilePath = StringTable->insertn( path, pathLen - 1 );
136   else
137      mFilePath = StringTable->insert( path );
138
139   if( filter )
140      mFilter  = StringTable->insert( filter );
141
142   // Update our view
143   openDirectory();
144
145   return true;
146}
147
148DefineEngineMethod( GuiDirectoryFileListCtrl, reload, void, (),,
149   "Update the file list." )
150{
151   object->update();
152}
153
154DefineEngineMethod( GuiDirectoryFileListCtrl, setPath, bool, ( const char* path, const char* filter ),,
155   "Set the search path and file filter.\n\n"
156   "@param path   Path in game directory from which to list files.\n"
157   "@param filter Tab-delimited list of file name patterns. Only matched files will be displayed.\n" )
158{
159   return object->setCurrentPath( path, filter );
160}
161
162DefineEngineMethod( GuiDirectoryFileListCtrl, getSelectedFiles, const char*, (),,
163   "Get the list of selected files.\n\n"
164   "@return A space separated list of selected files" )
165{
166   Vector<S32> ItemVector;
167   object->getSelectedItems( ItemVector );
168
169   if( ItemVector.empty() )
170      return StringTable->insert( "" );
171
172   // Get an adequate buffer
173   static const U32 itemBufSize = 256;
174   char itemBuffer[itemBufSize];
175
176   static const U32 bufSize = ItemVector.size() * 64;
177   char* returnBuffer = Con::getReturnBuffer( bufSize );
178   dMemset( returnBuffer, 0, bufSize );
179
180   // Fetch the first entry
181   StringTableEntry itemText = object->getItemText( ItemVector[0] );
182   if( !itemText )
183      return StringTable->lookup("");
184   dSprintf( returnBuffer, bufSize, "%s", itemText );
185
186   // If only one entry, return it.
187   if( ItemVector.size() == 1 )
188      return returnBuffer;
189
190   // Fetch the remaining entries
191   for( S32 i = 1; i < ItemVector.size(); i++ )
192   {
193      itemText = object->getItemText( ItemVector[i] );
194      if( !itemText )
195         continue;
196
197      dMemset( itemBuffer, 0, itemBufSize );
198      dSprintf( itemBuffer, itemBufSize, " %s", itemText );
199      dStrcat( returnBuffer, itemBuffer, itemBufSize );
200   }
201
202   return returnBuffer;
203
204}
205
206StringTableEntry GuiDirectoryFileListCtrl::getSelectedFileName()
207{
208   S32 item = getSelectedItem();
209   if( item == -1 )
210      return StringTable->lookup("");
211
212   StringTableEntry itemText = getItemText( item );
213   if( !itemText )
214      return StringTable->lookup("");
215
216   return itemText;
217}
218
219DefineEngineMethod( GuiDirectoryFileListCtrl, getSelectedFile, const char*, (),,
220   "Get the currently selected filename.\n\n"
221   "@return The filename of the currently selected file\n" )
222{
223   return object->getSelectedFileName();
224}
225