home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / ICAppSourceKit1.0 / ICFSSpecWhats.p < prev    next >
Encoding:
Text File  |  1994-11-28  |  4.7 KB  |  184 lines  |  [TEXT/PJMM]

  1. unit ICFSSpecWhats;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ICWindowGlobals;
  7.  
  8.     function WhatOpenFSSpec (wt: WindowType; item: integer): OSErr;
  9.     function WhatFlushFSSpec (wt: WindowType; item: integer): OSErr;
  10.     function WhatClickFSSpec (wt: WindowType; item: integer; er: eventRecord): OSErr;
  11.  
  12. implementation
  13.  
  14.     uses
  15.         Folders, 
  16.  
  17.         ICDialogs, ICMiscSubs, ICSubs, ICDocUtils, ICKeys, ICGlobals, ICStandardFile;
  18.  
  19.     function GetVolumeStuff (name: str31; date: longInt; var vrn: integer): OSErr;
  20.         var
  21.             err: OSErr;
  22.             pb: HParamBlockRec;
  23.             index: integer;
  24.             s: str255;
  25.             pass, i: integer;
  26.     begin
  27.         for pass := 1 to 2 do begin
  28.             i := 1;
  29.             while true do begin
  30.                 pb.ioVolIndex := i;
  31.                 i := i + 1;
  32.                 pb.ioNamePtr := @s;
  33.                 s := '';
  34.                 err := PBGetVInfoSync(@pb);
  35.                 if err <> noErr then begin
  36.                     leave;
  37.                 end;
  38.                 if IUEqualString(name, s) = 0 then begin
  39.                     if (pass = 2) or (pb.ioVCrDate = date) then begin
  40.                         leave;
  41.                     end;
  42.                 end;
  43.             end;
  44.             if err = noErr then begin
  45.                 leave;
  46.             end;
  47.         end;
  48.         if err = noErr then begin
  49.             vrn := pb.ioVRefNum;
  50.         end;
  51.         GetVolumeStuff := err;
  52.     end;
  53.  
  54.     function WhatOpenFSSpec (wt: WindowType; item: integer): OSErr;
  55.         var
  56.             spec: handle;
  57.             valid: boolean;
  58.             loe: longInt;
  59.             changed: boolean;
  60.             attr: longint;
  61.             pb: CInfoPBRec;
  62.             dlg: DialogPtr;
  63.             junk: OSErr;
  64.             modified: boolean;
  65.             fs: FSSpec;
  66.     begin
  67.         valid := false;
  68.         spec := nil;
  69.         modified := false;
  70.         if ICGetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, attr, spec) = noErr then begin
  71.             valid := true;
  72.         end;
  73.         ProcessAttributes(wt, item, attr);
  74.         if valid & (GetHandleSize(spec) < SizeOf(ICFileSpec)) then begin
  75.             valid := false;
  76.         end;
  77.         if valid then begin
  78.             if (ICFileSpecHandle(spec)^^.alias.aliasSize = 0) or not has_aliasMgr then begin
  79.                 if GetVolumeStuff(ICFileSpecHandle(spec)^^.vol_name, ICFileSpecHandle(spec)^^.vol_creation_date, fs.vRefNum) = noErr then begin
  80.                     fs.parID := ICFileSpecHandle(spec)^^.fss.parID;
  81.                     fs.name := ICFileSpecHandle(spec)^^.fss.name;
  82.                     if FSpGetCatInfo(fs, 0, pb) <> noErr then begin
  83.                         modified := true;
  84.                         valid := false;
  85.                     end;
  86.                 end
  87.                 else begin
  88.                     valid := false;
  89.                 end;
  90.             end
  91.             else begin
  92.                 loe := Munger(spec, 0, nil, SizeOf(ICFileSpec) - SizeOf(AliasRecord), @loe, 0);
  93.                 if ResolveAlias(nil, AliasHandle(spec), fs, changed) <> noErr then begin
  94.                     modified := true;
  95.                     valid := false;
  96.                 end;
  97.             end;
  98.         end;
  99.         if not valid then begin
  100.             if (FindFolder(kOnSystemDisk, kDesktopFolderType, true, fs.vRefNum, fs.parID) = noErr) & (FSpGetCatInfo(fs, -1, pb) = noErr) then begin
  101.                 fs.vRefNum := pb.ioVRefNum;
  102.                 fs.parID := pb.ioDrParID;
  103.             end
  104.             else begin
  105.                 fs.vRefNum := 0;
  106.                 fs.parID := 0;
  107.                 fs.name := '';
  108.             end; (* if *)
  109.         end;
  110.         DisposeHandle(spec);
  111.         windowinfo[wt].items[item]^.fss := fs;
  112.         windowinfo[wt].items[item]^.modified := modified;
  113.         SetDCtlTitle(windowinfo[wt].window, item, fs.name);
  114.         SetDCtlEnable(windowinfo[wt].window, item, not IsLocked(wt, item));
  115.         WhatOpenFSSpec := noErr;
  116.     end; (* WhatOpenFSSpec *)
  117.  
  118.     function WhatClickFSSpec (wt: WindowType; item: integer; er: eventRecord): OSErr;
  119.         var
  120.             err: OSErr;
  121.             fs: FSSpec;
  122.             dirID: longInt;
  123.     begin
  124.         err := ICStandardGetFolder(fs, dirID);
  125.         if err = noErr then begin
  126.             DirtyDocument;
  127.             windowinfo[wt].items[item]^.fss.vRefNum := fs.vRefNum;
  128.             windowinfo[wt].items[item]^.fss.parID := dirID;
  129.             windowinfo[wt].items[item]^.fss.name := '';
  130.             SetDCtlTitle(windowinfo[wt].window, item, fs.name);
  131.         end; (* if *)
  132.         WhatClickFSSpec := err;
  133.     end; (* WhatClickFSSpec *)
  134.  
  135.     function WhatFlushFSSpec (wt: WindowType; item: integer): OSErr;
  136.         var
  137.             alias: AliasHandle;
  138.             ifs: ICFileSpec;
  139.             pb: HParamBlockRec;
  140.             err: OSErr;
  141.             pos:longInt;
  142.     begin
  143.         ifs.fss := windowinfo[wt].items[item]^.fss;
  144.         alias := nil;
  145.         err := -1;
  146.         if has_aliasMgr then begin
  147.             err := NewAlias(nil, ifs.fss, alias);
  148.         end;
  149.         if err <> noErr then begin
  150.             alias := AliasHandle(NewHandle(sizeof(AliasRecord)));
  151.             err := MemError;
  152.             if err = noErr then begin
  153.                 alias^^.aliasSize := 0;
  154.                 alias^^.userType := OSType(0);
  155.             end; (* if *)
  156.         end; (* if *)
  157.  
  158.         if err = noErr then begin
  159.             pb.ioVRefNum := ifs.fss.vRefNum;
  160.             pb.ioVolIndex := 0;
  161.             pb.ioNamePtr := @ifs.vol_name;
  162.             err := PBGetVInfoSync(@pb);
  163.             if err = noErr then begin
  164.                 ifs.vol_creation_date := pb.ioVCrDate;
  165.             end; (* if *)
  166.         end; (* if *)
  167.  
  168.         if err = noErr then begin
  169.             pos:= Munger(Handle(alias), 0, nil, 0, @ifs, SizeOf(ICFileSpec) - SizeOf(AliasRecord));
  170.             err := MemError;
  171.         end; (* if *)
  172.  
  173.         if err = noErr then begin
  174.             err := ICMapErr(ICSetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, ICattr_no_change, Handle(alias)));
  175.         end; (* if *)
  176.  
  177.         if alias <> nil then begin
  178.             DisposeHandle(Handle(alias));
  179.         end; (* if *)
  180.         WhatFlushFSSpec := err;
  181.     end; (* WhatFlushFSSpec *)
  182.  
  183. end. (* ICFSSpecWhats *)
  184.