home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / filemanip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-28  |  6.1 KB  |  271 lines

  1. #include "go.h"
  2. #include "display.h"
  3. #include "xfer.h"
  4.  
  5. #include "sharedtransfer.proto.h"
  6. #include "filemanip.proto.h"
  7. #include "mouse.proto.h"
  8. #include "window.proto.h"
  9. #include "dircreate.proto.h"
  10. #include "delete.proto.h"
  11. #include "initdirs.proto.h"
  12. #include "inithotband.proto.h"
  13. #include "update.proto.h"
  14. #include "misc.proto.h"
  15. #include "launch.proto.h"
  16. #include "alerts.proto.h"
  17. #include <string.h>
  18. #include "windlist.h"
  19.  
  20. /* todo: move to .h file */
  21. #define STDFILEWIDTH    304
  22.  
  23. void
  24. newfolder (void)
  25. {
  26.   Point pt;
  27.   SFReply reply;
  28.   long savecurdir;
  29.   short savesfsavedisk;
  30.   WindowPeek wp;
  31.  
  32.   wp = (WindowPeek) FrontWindow ();
  33.   savecurdir = CurDirStore;
  34.   savesfsavedisk = SFSaveDisk;
  35.   if (browser_window_p ((WindowPtr) wp))
  36.     {
  37.       CurDirStore = (*(opendirinfo **) wp->refCon)->iodirid;
  38.       SFSaveDisk = -(*(opendirinfo **) wp->refCon)->vrefnum;
  39.     }
  40. #ifdef THINK_C
  41.   SetPt (&pt, (screenBits.bounds.right - screenBits.bounds.left - STDFILEWIDTH) / 2,
  42.      100);
  43.   SFPutFile (pt, (StringPtr) "\pNew Folder Name:", (StringPtr) "\pUntitled Folder",
  44.          (ProcPtr) 0, &reply);
  45. #else
  46.   SetPt (&pt, (qd.screenBits.bounds.right - qd.screenBits.bounds.left - STDFILEWIDTH) / 2,
  47.      100);
  48.   SFPutFile (pt, (StringPtr) "\pNew Folder Name:", (StringPtr) "\pUntitled Folder",
  49.          (DlgHookUPP) 0, &reply);
  50. #endif
  51.   if (reply.good)
  52.     {
  53. #ifdef THINK_C
  54.       createdir (-SFSaveDisk, CurDirStore, reply.fName);
  55. #else
  56.       createdir (-LMGetSFSaveDisk (), LMGetCurDirStore (), reply.fName);
  57. #endif
  58. #ifdef THINK_C
  59.       changewindow (reply.fName, CurDirStore, -SFSaveDisk, updatemove);
  60. #else
  61.       changewindow (reply.fName, LMGetCurDirStore (), -LMGetSFSaveDisk (), updatemove);
  62. #endif
  63.     }
  64.   CurDirStore = savecurdir;
  65.   SFSaveDisk = savesfsavedisk;
  66. }
  67.  
  68. void
  69. openitem (void)
  70. {
  71.   if ((**g_selection)[0] != 0)
  72.     activateicon ((**g_selection)[0], FALSE, TRUE);
  73. }
  74.  
  75. void
  76. printitem (void)
  77. {
  78.   launchcreator ((**g_selection)[0], appPrint);
  79. }
  80.  
  81. int
  82. is_closable (WindowPtr wp)
  83. {
  84.   return browser_window_p (wp);
  85. }
  86.  
  87. void
  88. closeitem (void)
  89. {
  90.   WindowPtr wp;
  91.  
  92.   wp = FrontWindow ();
  93.   if (is_closable (wp))
  94.     disposedirwindow (wp);
  95. }
  96.  
  97. void
  98. saveitem (void)
  99. {
  100. /* todo */
  101. }
  102.  
  103. void
  104. undolast (void)
  105. {
  106. /* todo */
  107. }
  108.  
  109. void
  110. duplicatename (Str255 name)
  111. {
  112. /* todo: put in .h file */
  113. #define MAXNAMELEN    31
  114. #define SUFFIX    " copy"
  115.   short suffix_length;
  116.  
  117.   suffix_length = sizeof (SUFFIX) - 1;
  118.   name[0] += suffix_length;
  119.   if (name[0] > MAXNAMELEN)
  120.     name[0] = MAXNAMELEN;
  121.   memcpy(name + name[0] - suffix_length + 1, SUFFIX, suffix_length);
  122. }
  123.  
  124. void
  125. duplicate (void)
  126. {
  127.   item **ih;
  128.   ControlHandle c;
  129.   Str255 newname;
  130.   unsigned char state;
  131.   long flags;
  132.  
  133.   c = (**g_selection)[0];
  134.   mystr255copy (newname, (*c)->contrlTitle);
  135.   duplicatename (newname);
  136.   ih = (item **) (*c)->contrlData;
  137.   state = HGetState ((Handle) c);
  138.   HLock ((Handle) c);
  139.   if (!duplicate1file ((*ih)->vrefnum, (*ih)->vrefnum, (*ih)->ioparid,
  140.               (*ih)->ioparid, (*c)->contrlTitle, newname, true, &flags))
  141.     changewindow (newname, (*ih)->ioparid, (*ih)->vrefnum, updatemove);
  142.   HSetState ((Handle) c, state);
  143. }
  144.  
  145. /* todo: move to .h file */
  146. #define RENAMEDIALOGID    202
  147. #define NEWNAMEITEM        3
  148.  
  149. void
  150. renameselection (void)
  151. {
  152.   Rect r;
  153.   item **ih;
  154.   short itemnum, type;
  155.   Handle itemh;
  156.   DialogPtr dp;
  157.   HParamBlockRec pb;
  158.   ControlHandle c;
  159.   OSErr e;
  160.   Str255 s, s2;
  161.   unsigned char state;
  162.   short vrefnum;
  163.   long parid;
  164.   CInfoPBRec cpb;
  165.  
  166.   c = (**g_selection)[0];
  167.  
  168.   dp = GetNewDialog (RENAMEDIALOGID, (Ptr) 0, (WindowPtr) - 1);
  169.   
  170.   GetDItem (dp, NEWNAMEITEM, &type, &itemh, &r);
  171.   SetIText (itemh, (*c)->contrlTitle);
  172.   SelIText (dp, NEWNAMEITEM, 0, 32767);
  173.   
  174. #ifdef THINK_C
  175.   ModalDialog ((ProcPtr) 0, &itemnum);
  176. #else
  177.   ModalDialog ((ModalFilterUPP) 0, &itemnum);
  178. #endif
  179.   if (itemnum == OK)
  180.     {
  181.       GetDItem (dp, NEWNAMEITEM, &type, &itemh, &r);
  182.       GetIText (itemh, s);
  183.       ih = (item **) (*c)->contrlData;
  184.       state = HGetState ((Handle) c);
  185.       HLock ((Handle) c);
  186.       pb.ioParam.ioNamePtr = (*c)->contrlTitle;
  187.       pb.ioParam.ioMisc = (Ptr) s;
  188.       pb.ioParam.ioVRefNum = (*ih)->vrefnum;
  189.       pb.fileParam.ioDirID = (*ih)->ioparid;
  190.       e = PBHRename (&pb, false);
  191.       HSetState ((Handle) c, state);
  192.       if (e == noErr)
  193.     {
  194.       if (is_volume (c))
  195.         s[++s[0]] = ':';
  196.       mystr255copy(s2, (*c)->contrlTitle);
  197.       parid = (*ih)->ioparid;
  198.       vrefnum = (*ih)->vrefnum;
  199.       replaceselected (0);
  200.       if ((*ih)->action == OPENDIR)
  201.         {
  202.               cpb.dirInfo.ioNamePtr = s;
  203.               cpb.dirInfo.ioVRefNum = (*ih)->vrefnum;
  204.               cpb.dirInfo.ioDrDirID = (*ih)->ioparid;
  205.           cpb.dirInfo.ioFDirIndex = 0;
  206.           e = PBGetCatInfo (&cpb, false);
  207.           if (e == noErr)
  208.             {
  209.                update_title (c, s);
  210.             }
  211.         }
  212.  
  213.       if ((*c)->contrlOwner == g_hotband)
  214.         SetCTitle (c, s);
  215.       changewindow (s2, parid, vrefnum, removefromlist);
  216.       changewindow (s, parid, vrefnum, updatemove);
  217.  
  218.       /* NOTE: after the first changewindow() call is made, c is no
  219.          longer valid, so calls to SetCTitle (c, s); would really be
  220.          a bad idea */
  221.          
  222.     }
  223.       else if (e == dupFNErr)
  224.         {
  225.           ParamText ((StringPtr) "\pThat name is already in use.",
  226.         (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  227.           StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
  228.         }
  229.       else
  230.     {
  231.       doerror (e, (StringPtr) "\pPBHRename");
  232.     }
  233.     }
  234.   DisposDialog (dp);
  235. }
  236.  
  237. void
  238. deleteselection (void)
  239. {
  240.   ControlHandle c;
  241.   item **ih;
  242.   short vrefnum;
  243.   long parid;
  244.   Str255 save_ctl_title;
  245.   
  246.   abortflag = 0;
  247.  
  248. /* Don't worry about c being null because the menu choice would not have been
  249.  * hilit
  250.  */
  251.   c = (**g_selection)[0];
  252.   if ((*c)->contrlOwner == g_hotband)
  253.     removeitemfromhotband (c);
  254.   else
  255.     {
  256.       boolean_t was_folder_p;
  257.       
  258.       was_folder_p = is_folder (c);
  259.       ih = (item **) (*c)->contrlData;
  260.       vrefnum = (*ih)->vrefnum;
  261.       parid = (*ih)->ioparid;
  262.       changehot (c, 0, 0);
  263.       replaceselected((ControlHandle) 0);
  264.       mystr255copy (save_ctl_title, (*c)->contrlTitle);
  265.       if (!delete1file (vrefnum, parid, save_ctl_title))
  266.     changewindow (save_ctl_title, parid, vrefnum, removefromlist);
  267.       if (was_folder_p)
  268.         close_windows_no_longer_present ();
  269.     }
  270. }
  271.