home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / ONDEFINEDOCUMENTSET.SCRIPT < prev    next >
Encoding:
Text File  |  2001-12-18  |  2.6 KB  |  132 lines

  1. !!Script
  2. // Copyright ⌐ 1997-2001 - Modelworks Software
  3. /**
  4. @Tool: Document Sets~defines the document sets toolbar. 
  5. @EndTool: 
  6. @Summary:  Document Sets~defines the document sets toolbar
  7. */
  8.  
  9. var gDocumentSetMapfile = getMapFile("DocumentSet.map");
  10. var gOutput = getOutput();
  11.  
  12. function DoCommand()
  13. {
  14.     var gDocumentSetComboBox = getGlobal("DocumentSet.DocumentSetComboBox",null);
  15.     if (gDocumentSetComboBox)
  16.     {
  17.         var key = gDocumentSetComboBox.text;
  18.         
  19.         if (key.length == 0)
  20.         {
  21.             alert("You must define a document set before you can open it.");
  22.             return;
  23.         }
  24.         
  25.         var list = GetList(key);
  26.         
  27.         var newList = editList("Document Set: " + key, 
  28.             "To delete a document set choose remove all and then OK.",
  29.             list, 
  30.             GetItemString,
  31.             Edit,
  32.             null,
  33.             false,
  34.             AddFiles,
  35.             "Add Files...");
  36.         
  37.         if (newList && newList.count > 0)
  38.         {
  39.             gDocumentSetMapfile.add("Windows."+key, newList);
  40.             var dslist = gDocumentSetMapfile.lookup("DocumentSet", null);
  41.             if (dslist)
  42.             {
  43.                 var index = -1;
  44.                 while ((index = dslist.find(key)) > -1)
  45.                 {
  46.                     var position = dslist.getPosition(index);
  47.                     dslist.removeAt(position)
  48.                 }
  49.                 dslist.addHead(key);
  50.             }
  51.         }
  52.         else if (newList)
  53.         {
  54.             gDocumentSetMapfile.remove("Windows."+key);
  55.             var dslist = gDocumentSetMapfile.lookup("DocumentSet", null);
  56.             if (dslist)
  57.             {
  58.                 var index = dslist.find(key);
  59.                 if (index > -1)
  60.                 {
  61.                     dslist.removeAt(dslist.getPosition(index));
  62.                 }
  63.             }
  64.         }
  65.     }
  66.     
  67. }
  68.  
  69. function GetList(key)
  70. {
  71.     var list = gDocumentSetMapfile.lookup("Windows." + key, null);
  72.     if (list == null)
  73.     {
  74.         list = newList();
  75.  
  76.         var index = 0;
  77.         var document = getDocument(index++);
  78.         while(document)
  79.         {
  80.             if (document.path.length > 0)
  81.             {
  82.                 list.addTail(document);
  83.             }
  84.             document = getDocument(index++);
  85.         }
  86.     }
  87.     return list;
  88. }
  89.  
  90. function GetItemString(item)
  91. {
  92.     // item is a Document object
  93.     if (item)
  94.     {
  95.         return item.path;
  96.     }
  97.     return "";
  98. }
  99.  
  100. function AddFiles(item)
  101. {
  102.     var filelist = chooseFiles("Add files", "*.*",  "*.*");
  103.     
  104.     if (filelist)
  105.     {
  106.         var list = newList();
  107.         var position = filelist.getHeadPosition();
  108.         while (position && position.valid)
  109.         {
  110.             var file = filelist.getNext(position);
  111.             list.addTail(File.newDocument(file.path));
  112.         }
  113.         return list;
  114.     }
  115.     
  116.     return null;
  117. }
  118.  
  119. function Edit(item)
  120. {
  121.     var path = "file://" + File.getToolsPath;
  122.     path += "\\Toolbars\\DocumentSet\\defineItem.dscript";
  123.     
  124.     var result = showHtmlDialog(path, new Array(Host, Application, item));
  125.     
  126.     return File.newDocument(result);
  127. }
  128.  
  129.  
  130. !!/Script
  131.  
  132.