guidirectoryfilelistctrl.cc

来自「五行MMORPG引擎系统V1.0」· CC 代码 · 共 162 行

CC
162
字号

#include "core/findMatch.h"
#include "gui/controls/guiDirectoryFileListCtrl.h"
#include "console/consoleTypes.h"


IMPLEMENT_CONOBJECT( GuiDirectoryFileListCtrl );

GuiDirectoryFileListCtrl::GuiDirectoryFileListCtrl()
{
#ifdef TGE_RPG_UI ///TGE_RPG_UI
	mSelectedFileName = StringTable->insert("");
	mFilter				= StringTable->insert("*.*");
	mFilePath			= StringTable->insert("/");
#endif
}

bool GuiDirectoryFileListCtrl::onWake()
{
   if( !Parent::onWake() )
      return false;

#ifdef TGE_RPG_UI ///TGE_RPG_UI
   setCurrentPath( mFilePath, mFilter );
#else
   setCurrentPath( "/", "*.*" );
#endif
   return true;
}

#ifdef TGE_RPG_UI ///TGE_RPG_UI
void GuiDirectoryFileListCtrl::initPersistFields()
{
	Parent::initPersistFields();
   addGroup("List Mode");	
   addField("selectFileName", TypeString, Offset(mSelectedFileName, GuiDirectoryFileListCtrl));
   addField("listFilter",		TypeString, Offset(mFilter, GuiDirectoryFileListCtrl));
   addField("filePath",			TypeString, Offset(mFilePath, GuiDirectoryFileListCtrl));
   endGroup("List Mode");	
}
#endif


void GuiDirectoryFileListCtrl::onMouseDown(const GuiEvent &event)
{
   Parent::onMouseDown( event );

   if( event.mouseClickCount == 2 && getNamespace() )
      Con::executef(this, 1, "onDoubleClick");

}


void GuiDirectoryFileListCtrl::openDirectory()
{
   Vector<Platform::FileInfo> fileVector;
   Platform::dumpPath( mFilePath, fileVector, 0 );

   // Clear the current file listing
   clear();

   // Does this dir have any files?
   if( fileVector.empty() )
      return;

   // If so, iterate through and list them
   Vector<Platform::FileInfo>::iterator i = fileVector.begin();
   for( S32 j=0 ; i != fileVector.end(); i++, j++ )
   {
      if( FindMatch::isMatchMultipleExprs( mFilter, (*i).pFileName,false ) )
		{   
			addEntry( j++, (*i).pFileName );
#ifdef TGE_RPG_UI ///TGE_RPG_UI
			if(mSelectedFileName[0] && dStricmp((*i).pFileName, mSelectedFileName)==0)
			{
				cellSelected(Point2I(0,mList.size()-1));
			}
#endif
		}
   }

   //Done!
}

bool GuiDirectoryFileListCtrl::setCurrentPath( StringTableEntry path, StringTableEntry filter )
{
   // Oops, gotta give us a path to work with
   if( !path )
      return false;

   char ExpandedPath[512];
   char FullPath[512];
   dMemset( ExpandedPath, 0, 512 );
   dMemset( FullPath, 0, 512 );

   Con::expandScriptFilename( ExpandedPath, 512, path );

   if( ExpandedPath[0] != '/' )
      dSprintf( FullPath, 512, "%s/%s", Platform::getWorkingDirectory(), ExpandedPath );
   else
      dSprintf( FullPath, 512, "%s%s", Platform::getWorkingDirectory(), ExpandedPath );

   // Platform::isDirectory expects no trailing / so make sure we conform
   if( FullPath[ dStrlen( FullPath ) - 1 ] == '/' )
      FullPath[ dStrlen( FullPath ) - 1 ] = 0x00;

   if( ! filter )
      filter = StringTable->insert("*.*");

   // A bad path!?  For shame...
   if( !Platform::isDirectory( FullPath ) && !Platform::hasSubDirectory( FullPath ) )
      return false;

   // Store our new info
   mFilePath = StringTable->insert( FullPath );
   mFilter   = StringTable->insert( filter );

   // Update our view
   openDirectory();

   // Peace out!
   return true;
}

StringTableEntry GuiDirectoryFileListCtrl::getSelectedFileName()
{
   return StringTable->insert( getSelectedText() );
}


#ifdef TGE_RPG_UI ///TGE_RPG_UI
ConsoleMethod( GuiDirectoryFileListCtrl, setPath, bool, 3, 5, "setPath(path,filter,selectFileName) - directory to enumerate files from (without trailing slash)" )
{
	object->setSelectedFileName(argc > 4?argv[4] : StringTable->insert(""));
   return object->setCurrentPath( argv[2], argv[3] );
}

ConsoleMethod( GuiDirectoryFileListCtrl, setPathData, void, 2, 5, "setPathData(path,filter,selectFileName) - directory to enumerate files from (without trailing slash)" )
{
	object->setSelectedFileName(argc > 4?argv[4] : StringTable->insert(""));
	object->setCurrentFilter(argc > 3?argv[3] : StringTable->insert("*.*"));
   object->setFilePath(argc > 2?argv[2] : StringTable->insert("/"));
}

#else

ConsoleMethod( GuiDirectoryFileListCtrl, setPath, bool, 3, 4, "setPath(path,filter) - directory to enumerate files from (without trailing slash)" )
{
   return object->setCurrentPath( argv[2], argv[3] );
}



#endif


ConsoleMethod( GuiDirectoryFileListCtrl, getSelectedFile, const char*, 2, 2, "getSelectedFile () - returns the currently selected file name" )
{
   return object->getSelectedFileName();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?