Advertisement
Guest User

Gio Pet

a guest
Jan 25th, 2010
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.63 KB | None | 0 0
  1. PROCEDURE Smart_Paste;
  2.  
  3.  
  4.  
  5. VAR
  6.    
  7.     ClassNames      :DYNARRAY[] of STRING;
  8.     NewClassNames   :DYNARRAY[] of STRING;
  9.     ExtraClassNames :DYNARRAY[] of STRING;
  10.    
  11.     countClasses, NewcountClasses   :INTEGER;
  12.     diff, StartClass                :INTEGER;
  13.    
  14.     DidCancel   :BOOLEAN;
  15.    
  16.     OldClass            :STRING;
  17.     NewClass            :STRING;
  18.    
  19.     PROCEDURE Populate_Array1;
  20.     VAR
  21.         x   :INTEGER;
  22.         y   :INTEGER;
  23.         w   :INTEGER;
  24.        
  25.         BEGIN
  26.             countClasses:=CLASSNUM;
  27.             ALLOCATE ClassNames [1..countClasses];
  28.  
  29.                 FOR x:= 1 TO countClasses DO BEGIN
  30.                     y:=x;
  31.                     CLassnames[y] := ClassList(x);                  
  32.                 END;
  33.         END;
  34.        
  35.     PROCEDURE Populate_Array2; 
  36.     VAR
  37.                 x   :INTEGER;
  38.                 y   :INTEGER;
  39.                 w   :INTEGER;
  40.     BEGIN
  41.                     ALLOCATE NewClassNames [1..NewcountClasses];
  42.                    
  43.                         FOR x:= 1 TO NewcountClasses DO BEGIN
  44.                             y:=x;
  45.                             NewClassNames[y] := ClassList(x);  
  46.                         END;       
  47.     END;
  48.        
  49.    
  50.     PROCEDURE Populate_Array_Extra;
  51.     VAR
  52.         x   :INTEGER;
  53.         y   :INTEGER;
  54.         w   :INTEGER;
  55.        
  56.         BEGIN
  57.            
  58.             diff:=(NewcountClasses - countClasses);
  59.             StartClass:=(NewcountClasses - diff)+1;
  60.            
  61.             ALLOCATE ExtraClassNames [1..diff];    
  62.                        
  63.                    
  64.             y:=1;          
  65.                 FOR x:=(StartClass) TO (NewcountClasses) DO BEGIN
  66.                     IF  y<=diff THEN BEGIN
  67.                     ExtraClassNames[y] := NewClassNames[x];                    
  68.                     y:=y+1;
  69.                 END;
  70.                 END;
  71.                    
  72.            
  73.     END;
  74.  
  75.     PROCEDURE AutomaticDlog;
  76.        
  77.     CONST
  78.     { note: the constants are of this format: kItem[1,2,3...n][b,f,c,g]Name    }
  79.     {      [1,2,3...n] is a number from 1 up to the maximum # of items allowed }
  80.     {      [b, f, c, g] indicates if it is a button (b), field (f), choice     }
  81.     {       item (c), or group box (g).                                        )
  82.     {      For example, a button with an ID of 3 would be kItem3bName, whereas }
  83.     {       a field with an ID of 13 would be kItem13fName.                    }
  84.         kDlgID=1;
  85.         kItem1bName='Ok';
  86.         kItem2bName='Cancel';
  87.         kItem3fName='Assign this Class:';
  88.         kItem5fName='To this:';
  89.         kItem4cName='OldClassPop';
  90.         kItem6cName='NewClassPop';
  91.    
  92.         Procedure SetupDialog;
  93.         Var
  94.             i:INTEGER;
  95.             major, minor, maint, platform:INTEGER;
  96.         Begin
  97.             GetVersion(major, minor, maint, platform);
  98.             BeginDialog(kDlgID, 1, 0, 0,300,320);
  99.                 if (platform = 1) then
  100.                 begin { macintosh }
  101.                     AddButton(kItem1bName,1,1,200,280,285,320);
  102.                     AddButton(kItem2bName,2,1,105,280,185,320);
  103.                 end
  104.                 else { windows }
  105.                 begin
  106.                     AddButton(kItem1bName,1,1,200,280,285,320);
  107.                     AddButton(kItem2bName,2,1,105,280,185,320);
  108.                 end;
  109.                 AddField(kItem3fName,3,1,12,12,188,28);
  110.                 AddField(kItem5fName,5,1,12,67,188,83);
  111.                 AddChoiceItem(kItem4cName,4,1,12,37,283,57);
  112.                 AddChoiceItem(kItem6cName,6,1,12,92,283,112);
  113.            EndDialog;
  114.         End; {of SetupDialog}
  115.    
  116.     Procedure HandleDialog;
  117.         Var
  118.             item, Count     :INTEGER;
  119.             done, canceled  :BOOLEAN;
  120.             error           :BOOLEAN;
  121.         Begin
  122.             GetDialog(kDlgID);
  123.            
  124.             FOR Count := 1 TO diff
  125.             DO BEGIN
  126.                 InsertChoice(4,Count, ExtraClassNames[Count]);
  127.             END;
  128.  
  129.             FOR Count := 1 TO countClasses
  130.             DO BEGIN
  131.                 InsertChoice(6,Count, ClassNames[Count]);
  132.             END;
  133.            
  134.             SetTitle('Class Reassign-Delete');
  135.             error := false;
  136.             canceled := false;
  137.             done := false;
  138.             while (not canceled) and (not done) do
  139.             begin
  140.                 DialogEvent(item);
  141.                 Case item OF
  142.                     1: if (not error) then
  143.                             done:= true
  144.                        else Sysbeep;
  145.                     2: canceled:= true;
  146.                 end; {of case}
  147.  
  148.             end;
  149.             if (done) then
  150.             begin
  151.                 { this would be a good place to retrieve the data     }
  152.                 DidCancel := canceled;
  153.                 GetSelChoice(4, 0, NewcountClasses, NewClass);
  154.                 GetSelChoice(6, 0, countClasses, OldClass);
  155.             end;
  156.             ClrDialog;
  157.            
  158.             if (canceled) Then
  159.             Begin
  160.                 DidCancel := canceled;
  161.                 DoMenuTextByName('Undo',0);
  162.             End;
  163.        
  164.         End; {of HandleDialog}
  165.     BEGIN    {of AutomaticDlog}
  166.         SetupDialog;
  167.         HandleDialog;
  168.     END;
  169.  
  170.  
  171.     PROCEDURE reassignclass(h:handle);
  172.         BEGIN
  173.         IF GetClass(h) = Newclass THEN SetClass(h, Oldclass);
  174.     END;  
  175.  
  176.  
  177. BEGIN  {of Paste_Reassign}
  178.        
  179.         Populate_Array1;
  180.         DoMenuTextByName('Paste',0);
  181.         NewcountClasses:=CLASSNUM;
  182.         IF (NewcountClasses=countClasses) THEN BEGIN
  183.        
  184.             Message('No New Classes Pasted');
  185.             END ELSE BEGIN
  186.            
  187.             Populate_Array2;
  188.             Populate_Array_Extra;
  189.                                
  190.             AutomaticDlog;
  191.                
  192.                        
  193.             IF NOT DidCancel
  194.             THEN BEGIN
  195.                 foreachobject(reassignclass,InSymbol);
  196.                 DelClass(NewClass);
  197.             END;
  198.         END;
  199.  
  200. END;   
  201. RUN(Smart_Paste);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement