home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL1.toast / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / ProjectDrag 1.1b8.sea / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / ModifyReadOnly.c / ModifyReadOnly.c
Encoding:
C/C++ Source or Header  |  1995-09-07  |  3.2 KB  |  145 lines  |  [TEXT/MPS ]

  1. /* ModifyReadOnly.c: ModifyReadOnly applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21. #include "FileCancel.h"
  22.  
  23.  
  24. void ModifyReadOnlyFile(FSSpec *file);
  25.  
  26.  
  27. /* This routine is called for each file passed in the ODOC event. */
  28.  
  29. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  30. {
  31. #pragma unused ( opening )
  32. #pragma unused ( userDataHandle )
  33.  
  34.     ModifyReadOnlyFile(myFSSPtr);
  35. }
  36.  
  37.  
  38. void ModifyReadOnlyFile(FSSpec *file)
  39. {
  40.     OSErr err;
  41.     AEDesc command;
  42.     CKIDHandle theCKID;
  43.     Str63 userName;
  44.     Str15 nickname;
  45.     Str255 comment;
  46.  
  47.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  48.     
  49.     /* find the user name and initials */
  50.     err = GetUserSettings(userName, nickname, false);
  51.     if (err != noErr)
  52.     {
  53.         if (err != userCanceledErr)
  54.             ErrorAlert(kProjectDragStrings, kNoUserSettings, err);
  55.         gDone = true;
  56.         return;
  57.     }
  58.     
  59.     /* get the CKID */
  60.     err = ExtractCKID(file, &theCKID);
  61.     if (err != noErr)
  62.     {
  63.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  64.                          NULL, NULL, NULL);
  65.         return;
  66.     }
  67.     
  68.     /* make sure the file is checked in */
  69.     if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
  70.     {
  71.         DisposeHandle((Handle)theCKID);
  72.         RaiseErrorString(kProjectDragStrings, kNoMROPermission, file->name,
  73.                          NULL, NULL, NULL);
  74.         return;
  75.     }
  76.     
  77.     /* create a ModifyReadOnly command for SourceServer
  78.      * ModifyReadOnly <file>
  79.      */
  80.     err = CreateCommand(&command, "ModifyReadOnly");
  81.     if (err == noErr)
  82.         err = AddFileNameArg(&command,file);
  83.     if (err != noErr)
  84.     {
  85.         DisposeHandle((Handle)theCKID);
  86.         AEDisposeDesc(&command);
  87.         RaiseErrorNumber(err);
  88.         return;
  89.     }
  90.     
  91.     /* send the command to SourceServer */
  92.     err = SendCommand(&command);
  93.     if (err != noErr)
  94.     {
  95.         DisposeHandle((Handle)theCKID);
  96.         return;
  97.     }
  98.  
  99.     /* get the checkout comment from the user */
  100.     comment[0] = 0;
  101.     if (!GetChangeComment(false, file->name, comment))
  102.     {
  103.         DisposeHandle((Handle)theCKID);
  104.         return;
  105.     }
  106.  
  107.     /* add the checkout comment to the file */
  108.     err = AddCheckoutComment(file, userName, nickname, comment);
  109.     if (err != noErr)
  110.     {
  111.         /* pop the current task and start a new one if user confirms cancel */
  112.         if (!ResTextYesNo(kProjectDragStrings, kMROCommentFailedCancel,
  113.                          file->name, NULL, NULL, NULL))
  114.         {
  115.             RaiseErrorNumber(userCanceledErr);
  116.             return;
  117.         }
  118.         
  119.         TaskDone(); /* not really! */
  120.         
  121.         TaskStart(2001, 2, file->name, NULL, NULL, NULL); /* canceling */
  122.         err = FileCancel(file, theCKID);
  123.         DisposeHandle((Handle)theCKID);
  124.         if (err != noErr) return;
  125.     }
  126.     else
  127.     {
  128.         DisposeHandle((Handle)theCKID);
  129.     }
  130.     
  131.     /* modify the label to blue (4) */
  132.     SetFileLabel(file, 4, NULL);
  133.  
  134.     TaskDone();
  135. }
  136.  
  137.  
  138. void DoFileMenu(short itemID)
  139. {
  140.     if ( itemID == 1 )
  141.         SelectFile();        // call file selection userProc
  142.     else
  143.         SendQuitToSelf();    // send self a 'quit' event
  144. }
  145.