| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- function makedirectoryHandler(%targetTree, %folderExclusionList, %searchFilter)
- {
- %newHandler = new ScriptObject()
- {
- class = "directoryHandler";
- };
-
- %newHandler.currentAddress = "";
- %newHandler.treeCtrl = %targetTree;
- %newHandler.folderExclusionList = %folderExclusionList;
- %newHandler.searchFilter = %searchFilter;
-
- %newHandler.prevHistoryList = new ArrayObject();
- %newHandler.foreHistoryList = new ArrayObject();
-
- return %newHandler;
- }
- function directoryHandler::loadFolders(%this, %path, %parentId)
- {
- %modulesList = ModuleDatabase.findModules();
-
- //utilize home dir project setting here
- %paths = getDirectoryList(%path);
- for(%i=0; %i < getFieldCount(%paths); %i++)
- {
- %childPath = getField(%paths, %i);
-
- %fullChildPath = makeFullPath(%path @ "/" @ %childPath);
-
- %folderCount = getTokenCount(%childPath, "/");
-
- for(%f=0; %f < %folderCount; %f++)
- {
- %folderName = getToken(%childPath, "/", %f);
-
- %parentName = %this.treeCtrl.getItemText(%parentId);
-
- //we don't need to display the shadercache folder
- if(%parentName $= "Data" && (%folderName $= "shaderCache" || %folderName $= "cache"))
- continue;
-
- if(%folderName $= ".git")
- continue;
-
- %iconIdx = 3;
-
- //Lets see if any modules match our current path)
- for(%m=0; %m < getWordCount(%modulesList); %m++)
- {
- %moduleDef = getWord(%modulesList, %m);
-
- if(%moduleDef.modulePath $= %fullChildPath)
- {
- %iconIdx = 1;
- break;
- }
- }
-
- //if(ModuleDatabase.findModule(%folderName) !$= "")
- // %iconIdx = 1;
-
- %searchFoldersText = %this.searchFilter;
- if(%searchFoldersText !$= "")
- {
- if(strstr(strlwr(%folderName), strlwr(%searchFoldersText)) != -1)
- {
- %folderID = %this.treeCtrl.insertItem(%parentId, %folderName, %path, "", %iconIdx, %iconIdx+1);
-
- %this.loadFolders(%path @ "/" @ %folderName, %folderID);
- }
- }
- else
- {
- %folderID = %this.treeCtrl.insertItem(%parentId, %folderName, %path, "", %iconIdx, %iconIdx);
-
- %this.loadFolders(%path @ "/" @ %folderName, %folderID);
- }
- }
- }
- }
- function directoryHandler::navigateTo(%this, %address, %historyNav, %selectionNav)
- {
- //Don't bother navigating if it's to the place we already are
- if(%this.currentAddress $= %address)
- return;
-
- //clear the breadcrumb bar
- AssetBrowser_BreadcrumbBar.clear();
-
- //break down the address
- %folderCount = getTokenCount(%address, "/");
- //find our folder tree and action on it tree
- %folderId = %this.getFolderTreeItemFromAddress(%address);
- %this.oldAddress = %this.currentAddress;
- %this.currentAddress = %address;
- %this.selectedItem = %folderId;
-
- //This lets us update the tree selection if we didn't get here because of that
- if(%selectionNav $= "")
- {
- %this.treeCtrl.clearSelection();
- %this.treeCtrl.selectItem(%folderId);
- }
-
- //remove any history records that are 'newer' than this one
- if(%historyNav $= "")
- {
- %this.foreHistoryList.empty();
-
- if(%this.oldAddress !$= "")
- %this.prevHistoryList.push_front(%this.oldAddress);
- }
-
- %this.treeCtrl.buildVisibleTree(true);
- }
- function directoryHandler::navigateHistoryForward(%this)
- {
- if(%this.foreHistoryList.count() == 0)
- return;
-
- %newAddress = %this.foreHistoryList.getKey(0);
- %prevHistory = %this.currentAddress;
-
- %this.prevHistoryList.push_front(%prevHistory);
- %this.foreHistoryList.pop_front();
-
- %this.navigateTo(%newAddress, true);
- }
- function directoryHandler::navigateHistoryBack(%this)
- {
- if(%this.prevHistoryList.count() == 0)
- return;
-
- %newAddress = %this.prevHistoryList.getKey(0);
- %foreHistory = %this.currentAddress;
-
- %this.foreHistoryList.push_front(%foreHistory);
- %this.prevHistoryList.pop_front();
-
- %this.navigateTo(%newAddress, true);
- }
- function directoryHandler::getModuleFromAddress(%this, %address)
- {
- %moduleList = ModuleDatabase.findModules();
-
- for(%i=0; %i < getWordCount(%moduleList); %i++)
- {
- %module = getWord(%moduleList, %i);
- %modulePath = makeRelativePath(%module.ModulePath);
-
- //We don't want to add stuff directly to the root core or tools modules
- //if(%modulePath $= "Core" || %modulePath $= "Tools")
- // continue;
-
- if(startsWith(%address, %modulePath))
- {
- return %module;
- }
- }
- /*//break down the address
- %folderCount = getTokenCount(%address, "/");
-
- for(%f=0; %f < %folderCount; %f++)
- {
- %folderName = getToken(%address, "/", %f);
- %module = ModuleDatabase.findModule(%folderName);
- if(%module !$= "")
- return %module;
- }*/
-
- return "";
- }
- function directoryHandler::getFolderTreeItemFromAddress(%this, %address)
- {
- //break down the address
- %folderCount = getTokenCount(%address, "/");
- if(startsWith(%address, "data/") || startsWith(%address, "tools/") || startsWith(%address, "core/"))
- {
- %curItem = %this.treeCtrl.findChildItemByName(1, "Modules");
- }
- else
- {
- %curItem = 1;
- }
-
- %rebuiltPath = "";
- for(%f=0; %f < %folderCount; %f++)
- {
- %folderName = getToken(%address, "/", %f);
- %curItem = %this.treeCtrl.findChildItemByName(%curItem, %folderName);
- }
-
- return %curItem;
- }
- function directoryHandler::expandTreeToAddress(%this, %address)
- {
- //break down the address
- %folderCount = getTokenCount(%address, "/");
- %rootId = AssetBrowser-->filterTree.findItemByName("Content");
- %this.treeCtrl.expandItem(%rootId);
- if(startsWith(%address, "data/") || startsWith(%address, "tools/") || startsWith(%address, "core/"))
- {
- %curItem = %this.treeCtrl.findChildItemByName(1, "Modules");
- }
- else
- {
- %curItem = 1;
- }
-
- %rebuiltPath = "";
- for(%f=0; %f < %folderCount; %f++)
- {
- %folderName = getToken(%address, "/", %f);
- %curItem = %this.treeCtrl.findChildItemByName(%curItem, %folderName);
- %this.treeCtrl.expandItem(%curItem);
- }
-
- %this.treeCtrl.expandItem(%rootId);
- }
- function directoryHandler::createFolder(%this, %folderPath)
- {
- //make a dummy file
- %file = new FileObject();
- %file.openForWrite(%folderPath @ "/test");
- %file.close();
-
- fileDelete(%folderPath @ "/test");
- }
- function directoryHandler::deleteFolder(%this, %folderPath)
- {
- %fullPath = makeFullPath(%folderPath);
-
- //First, wipe out any files inside the folder first
- %file = findFirstFileMultiExpr( %fullPath @ "/*", true);
- while( %file !$= "" )
- {
- if (isFile(%file))
- {
- %success = fileDelete( %file );
-
- if(!%success)
- {
- error("doDeleteFolder - unable to delete file " @ %file);
- return;
- }
- }
- %file = findNextFileMultiExpr( %fullPath @ "/*" );
- }
-
- //next, walk through and delete any subfolders that may be remaining
- %finalDeleteAttempt = false;
- while(IsDirectory(%fullPath) && fileDelete(%fullPath) == 0)
- {
- //We couldn't delete the folder, so get a directory list and recurse through it, deleteing them as we go
- %paths = getDirectoryList(%fullPath);
- // If nothing is in this directory, let the loop run once more and if that fails we're not going
- // to delete the folder. This prevents an infinite loop if for some reason the directory cannot
- // be deleted.
- %pathCount = getFieldCount(%paths);
- if (%pathCount == 0)
- {
- if (%finalDeleteattempt)
- {
- error("doDeleteFolder - unable to delete directory " @ %fullPath);
- return;
- }
- %finalDeleteAttempt = true;
- continue;
- }
- for(%i=0; %i < %pathCount; %i++)
- {
- %childPath = getField(%paths, %i);
- %this.deleteFolder(%fullPath @ "/" @ %childPath);
- }
- }
- }
- function directoryHandler::copyFolder(%this, %fromFolder, %toFolder)
- {
- if(!isDirectory(%toFolder))
- %this.createFolder(%toFolder);
-
- %file = findFirstFileMultiExpr( %fromFolder @ "/*.*", false);
- while( %file !$= "" )
- {
- %copiedFile = strreplace(%file, %fromFolder, %toFolder);
-
- %copiedPath = filePath(%copiedFile);
-
- if(!isDirectory(%copiedPath))
- createPath(%copiedPath);
-
- %success = pathCopy(%file, %copiedFile, false);
- if(!%success)
- error("copyProjectFolder() - failed to copy file: " @ %file);
-
- %file = findNextFileMultiExpr( %fromFolder @ "/*.*" );
- }
-
- //do sub directories
- %paths = getDirectoryList(%fromFolder);
- for(%i=0; %i < getFieldCount(%paths); %i++)
- {
- %childPath = getField(%paths, %i);
-
- %this.copyFolder(%fromFolder @ %childPath @ "/", %toFolder @ %childPath @ "/");
- }
-
- return true;
- }
|