home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / UGetMultipleFiles 1.4 / Exhibit.cp < prev    next >
Encoding:
Text File  |  1997-07-24  |  6.0 KB  |  201 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    Exhibit.cp     - show how the UGetMultipleFiles class works
  3. // ===========================================================================
  4. //
  5. //    This file contains the starter code for a PowerPlant application
  6.  
  7. #include "Exhibit.h"
  8.  
  9. #include <LGrowZone.h>
  10. #include <LWindow.h>
  11. #include <PP_Messages.h>
  12. #include <PP_Resources.h>
  13. #include <PPobClasses.h>
  14. #include <UDrawingState.h>
  15. #include <UMemoryMgr.h>
  16. #include <URegistrar.h>
  17. #include <LEditField.h>
  18.  
  19.  
  20. // ===========================================================================
  21. //        • Main Program
  22. // ===========================================================================
  23.  
  24. void main(void)
  25. {
  26.                                     // Set Debugging options
  27.     SetDebugThrow_(debugAction_Alert);
  28.     SetDebugSignal_(debugAction_Alert);
  29.  
  30.     InitializeHeap(3);                // Initialize Memory Manager
  31.                                     // Parameter is number of Master Pointer
  32.                                     //   blocks to allocate
  33.     
  34.                                     // Initialize standard Toolbox managers
  35.     UQDGlobals::InitializeToolbox(&qd);
  36.     
  37.     new LGrowZone(20000);            // Install a GrowZone function to catch
  38.                                     //    low memory situations.
  39.  
  40.     Exhibit    theApp;            // replace this with your App type
  41.     theApp.Run();
  42. }
  43.  
  44.  
  45. // ---------------------------------------------------------------------------
  46. //        • Exhibit             // replace this with your App type
  47. // ---------------------------------------------------------------------------
  48. //    Constructor
  49.  
  50. Exhibit::Exhibit()
  51. {
  52. }
  53.  
  54.  
  55. // ---------------------------------------------------------------------------
  56. //        • ~Exhibit            // replace this with your App type
  57. // ---------------------------------------------------------------------------
  58. //    Destructor
  59. //
  60.  
  61. Exhibit::~Exhibit()
  62. {
  63. }
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        • StartUp
  67. // ---------------------------------------------------------------------------
  68. //    This function lets you do something when the application starts up
  69. //    without a document. For example, you could issue your own new command.
  70.  
  71. void
  72. Exhibit::StartUp()
  73. {
  74.     ObeyCommand(cmd_New, nil);        // Do the add files command
  75. }
  76.  
  77. // ---------------------------------------------------------------------------
  78. //        • ObeyCommand
  79. // ---------------------------------------------------------------------------
  80. //    Respond to commands
  81. #include "UGetMultipleFiles.h"
  82. Boolean
  83. Exhibit::ObeyCommand(
  84.     CommandT    inCommand,
  85.     void        *ioParam)
  86. {
  87.     Boolean        cmdHandled = true;
  88.  
  89.     switch (inCommand) {
  90.     
  91.         // Deal with command messages (defined in PP_Messages.h).
  92.         // Any that you don't handle will be passed to LApplication
  93.              
  94.         case cmd_New:
  95.         {
  96.                 // this time through chooses files that will be excluded from the next time
  97.             UGetMultipleFiles    *selectBadFilesThing = nil;
  98.             LArray                *suppressedFSpecs = nil;
  99.             selectBadFilesThing = new UGetMultipleFiles("\pChoose Files to Exclude",
  100.                                         (short) -1,        // number of types to show (-1 means all)
  101.                                         (unsigned long *) nil,    // the list of types
  102.                                         nil,            // the list of files to exclude
  103.                                         true,            // allow MAE to convert files?
  104.                                         true,            // show folders?
  105.                                         false);            // add folders?
  106.  
  107.             if ((selectBadFilesThing->GetSFReply()).sfGood) {
  108.                 suppressedFSpecs = selectBadFilesThing->GetFSSpecs();
  109.             } else {
  110.                 // user chose cancel, or there were no files selected
  111.                 suppressedFSpecs = nil;
  112.             }
  113.             
  114.                     // copy selected files to a new LArray.  We have to do this because all the
  115.                     // data members of UGetMultipleFiles are static, so we will be overwriting
  116.                     // the old ones if we don't delete selectBadFilesThing before creating
  117.                     // theMultFilesThing
  118.             LArray suppressedFSSpecsCopy(sizeof(FSSpec));    // create the FSSpec array
  119.             if (suppressedFSpecs != nil) {
  120.                 FSSpec *thisSpecP;
  121.                 for (short i = 1; i <= suppressedFSpecs->GetCount(); i++) {
  122.                     thisSpecP = (FSSpec *)suppressedFSpecs->GetItemPtr(i);
  123.                     suppressedFSSpecsCopy.InsertItemsAt(1, suppressedFSSpecsCopy.index_Last, thisSpecP);
  124.                 }
  125.                 suppressedFSpecs->RemoveItemsAt(suppressedFSpecs->GetCount(), 1);
  126.             }
  127.             delete selectBadFilesThing;
  128.  
  129.             
  130.                 // now we demonstrate selecting multiple files and folders, and filtering out certain ones
  131.                 // since we don't want MacEasyOpen to deal with file conversion, we'll specify a fourth
  132.                 // parameter of false for the sAllowConversion to avoid trouble with MacEasyOpen
  133.             SFTypeList            typeList;
  134.             FSSpec                oneFSSpec;
  135.             UGetMultipleFiles    *theMultFilesThing;
  136.             LArray                *theFSpecs;
  137.             short                i;
  138.             
  139.             typeList[0] = 'TEXT';
  140.             typeList[1] = 'inGT';
  141.         
  142.             theMultFilesThing = new UGetMultipleFiles("\pChoose files for processing:",
  143.                                         2,        // number of types to show (-1 means all)
  144.                                         typeList,    // the list of types
  145.                                         &suppressedFSSpecsCopy,            // the list of files to exclude
  146.                                         false,            // allow MAE to convert files?
  147.                                         true,            // show folders?
  148.                                         true);            // add folders?
  149.     
  150.             if ((theMultFilesThing->GetSFReply()).sfGood) {
  151.                 theFSpecs = theMultFilesThing->GetFSSpecs();
  152.                 for (i = 1; i <= theFSpecs->GetCount(); i++) {
  153.                     theFSpecs->FetchItemAt(i, &oneFSSpec);
  154.                     ParamText(oneFSSpec.name, "\p", "\p", "\p");
  155.                     Alert(129, nil);
  156.                 }
  157.             } else {
  158.                 // user chose cancel, or there were no files selected
  159.             }
  160.             delete theMultFilesThing;
  161.         }
  162.         break;
  163.         default:
  164.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  165.             break;
  166.     }
  167.     
  168.     return cmdHandled;
  169. }
  170.  
  171. // ---------------------------------------------------------------------------
  172. //        • FindCommandStatus
  173. // ---------------------------------------------------------------------------
  174. //    This function enables menu commands.
  175. //
  176.  
  177. void
  178. Exhibit::FindCommandStatus(
  179.     CommandT    inCommand,
  180.     Boolean        &outEnabled,
  181.     Boolean        &outUsesMark,
  182.     Char16        &outMark,
  183.     Str255        outName)
  184. {
  185.  
  186.     switch (inCommand) {
  187.     
  188.         // Return menu item status according to command messages.
  189.         // Any that you don't handle will be passed to LApplication
  190.  
  191.         case cmd_New:                    // EXAMPLE
  192.             outEnabled = true;            // enable the New command
  193.             break;
  194.  
  195.         default:
  196.             LApplication::FindCommandStatus(inCommand, outEnabled,
  197.                                                 outUsesMark, outMark, outName);
  198.             break;
  199.     }
  200. }
  201.