home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Project / removeFiles.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  2.8 KB  |  110 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 227 cm19981009 - add forceUpdate
  4.  
  5. /**
  6. @Tool: removeFiles~displays a list of files you can remove 
  7. from packages in a project. The list files available to 
  8. be removed depends upon "auto include files" option. 
  9. If the package is created with the "auto include files" 
  10. not marked, then the initial list of files you can remove will 
  11. include all matching source files in the source path and sub-directories. 
  12. If the package is created with the "auto include files" 
  13. marked, then the initial list of files you can remove will be empty. 
  14. @Image: Remove Files Dialog@removeFiles_Project.gif 
  15. @EndTool: 
  16. @Summary: removeFiles~displays a list of files you can remove 
  17. */
  18.  
  19. function DoUpdate(cmdUI) 
  20. {
  21.     var project = getCurrentProject();
  22.     cmdUI.enable(project != null && !project.readOnly)
  23.     return true;
  24. }
  25.  
  26. function DoCommand()
  27. {
  28.     var project = getCurrentProject();
  29.     
  30.     if (project)
  31.     {
  32.         var packageList = project.getPackageList();
  33.         if (packageList && packageList.count >= 1)
  34.         {
  35.             if (packageList.count > 1)
  36.             {
  37.                 var packageToRemoveFilesFrom = 
  38.                 chooseFromList("Choose package to remove files from",
  39.                 packageList, getPackageString, false);
  40.                 
  41.                 if (packageToRemoveFilesFrom)
  42.                 {
  43.                     RemoveFiles(packageToRemoveFilesFrom);
  44.                 }
  45.             }
  46.             else if (packageList.count == 1)
  47.             {
  48.                 RemoveFiles(packageList.removeHead());
  49.             }
  50.         }
  51.         else
  52.         {
  53.             alert("You must add a package before removing files");
  54.         }
  55.     }
  56.     else
  57.     {
  58.         alert("A project must be open before you can remove files");
  59.     }
  60. }
  61.  
  62. function RemoveFiles(fromPackage)
  63. {
  64.     if (fromPackage)
  65.     {
  66.         // Get list of files included in the package
  67.         var includedFileList = fromPackage.getFileList(false);
  68.         var filesToRemoveList = chooseFromList("Choose files to remove", 
  69.             includedFileList, getFileString, true);
  70.         
  71.         // Remove the files from the package
  72.         if (filesToRemoveList)
  73.         {
  74.             var position = filesToRemoveList.getHeadPosition();
  75.             while (position.valid)
  76.             {
  77.                 var file = filesToRemoveList.getNext(position);
  78.                 if (file)
  79.                 {
  80.                     var destFile = fromPackage.getDestinationFile(file);
  81.                     if (destFile && pathExists(destFile.path) && destFile.path != file.path)
  82.                     {
  83.                         File.deleteFile(destFile);
  84.                     }
  85.                     fromPackage.excludeFile(file);
  86.                 }
  87.             }
  88.             Application.updateWorkspaceTab("Class"); 
  89.             Application.updateWorkspaceTab("Package"); 
  90.             Application.updateWorkspaceTab("Files"); 
  91.             
  92.             fromPackage.forceUpdate(); // cm19981009
  93.         }
  94.     }
  95. }
  96.  
  97. function getPackageString(item)
  98. {
  99.     // Assumes item is a Package object
  100.     return item.name + " (" + item.sourcePath + ")";
  101. }
  102.  
  103. function getFileString(item)
  104. {
  105.     // Assumes item is a File object
  106.     return item.path;
  107. }
  108.  
  109. !!/Script
  110.