Advertisement
Guest User

Gio PEt

a guest
Jun 28th, 2010
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 29.27 KB | None | 0 0
  1. {SMART PASTE_Command to control the automatic creation of new classes when Copy/Pasting across Drawings.
  2. Copyright (C) 2010  Giovanni Petrolito}
  3.  
  4.  
  5. PROCEDURE Smart_Paste;
  6.  
  7.  
  8. VAR
  9.         ClassNames                      :DYNARRAY[] of STRING;
  10.         NewClassNames                   :DYNARRAY[] of STRING;
  11.         ExtraClassNames                 :DYNARRAY[] of STRING;
  12.        
  13.        
  14.         { Variables to Generate Undo History }      
  15.         ButtonChoice                    :ARRAY[1..100] of STRING;
  16.         ClassRecord                 :ARRAY[1..100] of STRING;
  17.         IndexRecord                 :ARRAY[1..100] of INTEGER;
  18.         AssignIndexRecord               :ARRAY[1..100] of INTEGER;
  19.         Assign_CountTOT                 :INTEGER;
  20.         Selection_Undo                  :Integer;
  21.        
  22.         Click_Count                     :INTEGER;
  23.        
  24.         { Global Variables for Assign Class and Add Class Procedures }
  25.         OldClass                        :STRING;
  26.         NewClass                        :STRING;
  27.     to_be_assigned          :STRING;
  28.         assign_to           :STRING;
  29.        
  30.         countClasses, NewcountClasses   :INTEGER;
  31.         diff, StartClass        :INTEGER;
  32.         index                           :INTEGER;
  33.         ClassOptions            :INTEGER;
  34.        
  35.        
  36.         { Variables to Create Resource Lists }
  37.         ResourceName1       :String;
  38.     ResourceName2       :String;
  39.         ResourceList1       :LongInt;
  40.     ResourceList2       :LongInt;
  41.     NumItems        :LongInt;
  42.     NumItems2       :LongInt;
  43.        
  44.        
  45.         Didcancel    :BOOLEAN;
  46.         canceled     :BOOLEAN;
  47.        
  48.  
  49.  
  50.        
  51.        
  52.                
  53. { ***************************************************************************************************************** }        
  54.                 { BEGINNING OF SUB-PROCEDURES }        
  55. { ***************************************************************************************************************** }        
  56.        
  57.  
  58.  
  59.         PROCEDURE ResourceList_Existing_Classes;
  60.     Const
  61.         ObjectType=94;   {Class Definintion}
  62.         FolderIndex=3;   {BuildResourceList Def for Plug-ins Data Folder See Func. Ref}
  63.         SubFolderName='';    {Nul subfolder get all folders and subfolders}
  64.  
  65.         VAR
  66.                 x       :INTEGER;
  67.                
  68.         BEGIN
  69.             ResourceList1:=BuildResourceList(ObjectType,FolderIndex,'',NumItems);
  70.        
  71.                 For x:=1 to NumItems Do Begin
  72.                     ResourceName1:=GetNameFromResourceList(ResourceList1,x);
  73.                 end;
  74.         END;
  75.  
  76. { ***************************************************************************************************************** }      
  77.  
  78.         PROCEDURE ResourceList_Extra_Classes;  
  79.         Const
  80.             ObjectType=94;   {Class Definintion}
  81.             FolderIndex=3;   {BuildResourceList Def for Plug-ins Data Folder See Func. Ref}
  82.             SubFolderName='';    {Nul subfolder get all folders and subfolders}
  83.         VAR
  84.                 x       :INTEGER;
  85.                 y       :INTEGER;
  86.                
  87.         BEGIN
  88.             ResourceList2:=BuildResourceList(ObjectType,FolderIndex,'',NumItems2);
  89.    
  90.                 For x:=1 to NumItems Do Begin
  91.                 ResourceName1:=GetNameFromResourceList( ResourceList1,x);
  92.        
  93.                 For y:=1 to NumItems2 Do Begin
  94.                     ResourceName2:=GetNameFromResourceList(ResourceList2,y);
  95.                
  96.                     IF ResourceName2=ResourceName1 Then DeleteResourceFromList(ResourceList2,y);
  97.                 End;   
  98.             End;
  99.             NumItems2:=ResourceListSize(ResourceList2);
  100.         END;
  101.  
  102. { ***************************************************************************************************************** }
  103.  
  104.        
  105.        
  106.         PROCEDURE dialog1_Main;
  107.        
  108.         CONST
  109.             kStartStringAt = 3000;
  110.             kOK           = 1;
  111.             kCancel       = 2;
  112.             kUndo_Btn     = 4;
  113.             kPaste_Btn    = 5;
  114.             kAssign       = 6;
  115.             kGroupBox7    = 7;
  116.             kGroupBox14   = 14;
  117.             kGroupBox15   = 15;
  118.             kGroupBox25   = 25;
  119.             kGroupBox26   = 26;
  120.             kNEWclsnm     = 40;
  121.             kEXclsnm      = 41;
  122.             kStaticText63 = 63;
  123.             kStaticText64 = 64;
  124.            
  125.  
  126.             kRight        = 1;
  127.             kBottom       = 2;
  128.             kLeft         = 3;
  129.             kResize       = 0;
  130.             kShift        = 1;
  131.  
  132.             kTextOnly     = 0;
  133.             kIconOnly     = 1;
  134.             kTextIcon     = 3;
  135.             kStatic       = 1;
  136.             kRadio        = 2;
  137.             kMulti        = 3;
  138.             kCol0         = 0;
  139.             kCol1         = 1;
  140.             kRow1         = 1;
  141.         VAR
  142.             dialog1             :INTEGER;
  143.             kImageCheckNEW      :INTEGER;
  144.             kImageBlankNEW      :INTEGER;
  145.             kImageSheetNEW      :INTEGER;
  146.             kImageViewNEW       :INTEGER;
  147.    
  148.             kImageCheckEX       :INTEGER;
  149.             kImageBlankEX       :INTEGER;
  150.             kImageSheetEX       :INTEGER;
  151.             kImageViewEX        :INTEGER;
  152.    
  153.             cnt                 :INTEGER;
  154.             int                 :INTEGER;
  155.             ndx                 :INTEGER;
  156.    
  157.             numOfClass          :INTEGER;
  158.             classname           :INTEGER;
  159.    
  160.             xmlID               :LONGINT;
  161.    
  162.             boo                 :BOOLEAN;
  163.             Select_more         :BOOLEAN;
  164.             Select_one          :BOOLEAN;
  165.             str                 :STRING;
  166.            
  167.    
  168.             {$Include _DialogBuilderUtilities.txt}
  169.  
  170.  
  171.  
  172.             FUNCTION GetPlugInString(ndx :INTEGER) :STRING;
  173.                 BEGIN
  174.                 CASE ndx OF
  175.                     {Static Text}
  176.                     3001: GetPlugInString := 'OK';
  177.                     3002: GetPlugInString := 'Cancel';
  178.                     3003: GetPlugInString := 'Smart Paste © 2010 GioPEt';
  179.                     3004: GetPlugInString := 'Undo';
  180.                     3005: GetPlugInString := 'Add';
  181.                     3006: GetPlugInString := 'Assign';
  182.                     3007: GetPlugInString := '  Controls';
  183.                     3014: GetPlugInString := 'Untitled';
  184.                     3015: GetPlugInString := 'Untitled';
  185.                     3025: GetPlugInString := '';
  186.                     3026: GetPlugInString := '';
  187.                    
  188.                     3063: GetPlugInString := 'New Incoming Classes:';
  189.                     3064: GetPlugInString := 'Existing Classes:';
  190.                    
  191.                     {Help Text}
  192.                     4001: GetPlugInString := 'Closes this dialog.';
  193.                     4002: GetPlugInString := 'Cancels the operation without changes.';
  194.                     4004: GetPlugInString := 'The selected Incoming classes will be assigned to the selected Existing Class.';
  195.                     4005: GetPlugInString := 'The selected Incoming classes will be added to the current Drawing.';
  196.                     4006: GetPlugInString := 'Undo the previous action.';
  197.                     4007: GetPlugInString := '';
  198.                     4014: GetPlugInString := '';
  199.                     4015: GetPlugInString := '';
  200.                     4025: GetPlugInString := 'A group box control.';
  201.                     4026: GetPlugInString := 'A group box control.';
  202.                     4040: GetPlugInString := 'A list box control.';
  203.                     4041: GetPlugInString := 'A list box control.';
  204.                     4063: GetPlugInString := 'Static text control.';
  205.                     4064: GetPlugInString := 'Static text control.';
  206.                 END;
  207.             END;
  208.  
  209. { ***************************************************************************************************************** }
  210.  
  211.             FUNCTION GetStr(ndx :INTEGER) :STRING;
  212.                 BEGIN
  213.                     GetStr := GetPlugInString(ndx + kStartStringAt);
  214.                 END;
  215.  
  216. { ***************************************************************************************************************** }
  217.  
  218.             PROCEDURE dialog1_Setup;
  219.                 BEGIN
  220.                     dialog1 := CreateResizableLayout(GetStr( 3), TRUE, GetStr(kOK), GetStr(kCancel), FALSE, TRUE);
  221.                    
  222.                     CreatePushButton          (dialog1, kUndo_Btn,      GetStr(kUndo_Btn));
  223.                     CreatePushButton          (dialog1, kPaste_Btn,     GetStr(kPaste_Btn));
  224.                     CreatePushButton          (dialog1, kAssign,        GetStr(kAssign));
  225.                     CreateGroupBox            (dialog1, kGroupBox7,     GetStr(kGroupBox7), TRUE);
  226.                     CreateGroupBox            (dialog1, kGroupBox14,    GetStr(kGroupBox14), FALSE);
  227.                     CreateGroupBox            (dialog1, kGroupBox15,    GetStr(kGroupBox15), FALSE);
  228.                     CreateGroupBox            (dialog1, kGroupBox25,    GetStr(kGroupBox25), TRUE);
  229.                     CreateGroupBox            (dialog1, kGroupBox26,    GetStr(kGroupBox26), TRUE);
  230.                    
  231.                     CreateLB                  (dialog1, kNEWclsnm,      32, 10);
  232.                     CreateLB                  (dialog1, kEXclsnm,       32, 10);
  233.                     EnableLBSorting(dialog1, kNEWclsnm, FALSE);
  234.                     EnableLBSorting(dialog1,  kEXclsnm, FALSE);
  235.                     CreateStaticText          (dialog1, kStaticText63,  GetStr(kStaticText63), -1);
  236.                     CreateStaticText          (dialog1, kStaticText64,  GetStr(kStaticText64), -1);
  237.                    
  238.                     SetFirstLayoutItem(dialog1, kGroupBox15);
  239.                     SetFirstGroupItem (dialog1, kGroupBox15,    kGroupBox26);
  240.                     SetFirstGroupItem (dialog1, kGroupBox26,    kStaticText63);
  241.                     SetBelowItem      (dialog1, kStaticText63,  kNEWclsnm,      0, 0);
  242.                     SetRightItem      (dialog1, kGroupBox26,    kGroupBox7,     0, 0);
  243.    
  244.                     SetFirstGroupItem (dialog1, kGroupBox7,     kAssign);
  245.                     SetBelowItem (dialog1, kGroupBox7,     kPaste_Btn, 3.25, -40 );
  246.                     SetRightItem (dialog1,kPaste_Btn,     kUndo_Btn, -11.47, 10 );
  247.    
  248.                     SetRightItem      (dialog1, kGroupBox7,     kGroupBox14,    0, 0);
  249.                     SetFirstGroupItem (dialog1, kGroupBox14,    kGroupBox25);
  250.                     SetFirstGroupItem (dialog1, kGroupBox25,    kStaticText64);
  251.                     SetBelowItem      (dialog1, kStaticText64,  kEXclsnm,       0, 0);
  252.                    
  253.  
  254.                     AlignItemEdge(dialog1, kNEWclsnm,      kLeft,    2, kResize);
  255.                     AlignItemEdge(dialog1, kEXclsnm,       kRight,   2, kResize);
  256.  
  257.                     SetEdgeBinding        (dialog1, kUndo_Btn,      FALSE, FALSE, FALSE, FALSE);
  258.                     SetEdgeBinding        (dialog1, kPaste_Btn,     FALSE, FALSE, FALSE, FALSE);
  259.                     SetEdgeBinding        (dialog1, kAssign,        FALSE, FALSE, FALSE, FALSE);
  260.                     SetEdgeBinding        (dialog1, kGroupBox14,    TRUE, TRUE, TRUE, TRUE);
  261.                     SetEdgeBinding        (dialog1, kGroupBox15,    TRUE, TRUE, TRUE, TRUE);
  262.                     SetEdgeBinding        (dialog1, kGroupBox25,    TRUE, TRUE, TRUE, TRUE);
  263.                     SetEdgeBinding        (dialog1, kGroupBox26,    TRUE, TRUE, TRUE, TRUE);
  264.                     SetEdgeBinding        (dialog1, kNEWclsnm,      TRUE, TRUE, TRUE, TRUE);
  265.                     SetEdgeBinding        (dialog1, kEXclsnm,       TRUE, TRUE, TRUE, TRUE);
  266.                     SetEdgeBinding        (dialog1, kStaticText63,  FALSE, FALSE, TRUE, FALSE);
  267.                     SetEdgeBinding        (dialog1, kStaticText64,  FALSE, FALSE, TRUE, FALSE);
  268.                    
  269.                    
  270.                     SetProportionalBinding(dialog1, kNEWclsnm,      FALSE, FALSE, FALSE, FALSE);
  271.                     SetProportionalBinding(dialog1, kEXclsnm,       FALSE, FALSE, FALSE, FALSE);
  272.    
  273.                     FOR cnt := 1 TO 15 DO SetHelpString(cnt, GetStr(cnt + 1000));
  274.                 END;
  275.  
  276.             { ***************************************************************** }
  277.                         { PROCEDURES TO DEFINE BUTTONS BEHAVIOUR }
  278.             { ***************************************************************** }
  279.  
  280.             PROCEDURE Assign_Button;
  281.        
  282.             Var
  283.                     Selection, Remove, Assign   :Boolean;
  284.                        
  285.             Sel_ndx, Sel_cls            :Integer;
  286.            
  287.             temp_ndx1, temp_ndx2        :Integer;
  288.             temp_cls1, temp_cls2        :string;
  289.             list_name                   :STRING;       
  290.             list_image                  :Integer;      
  291.             list_number                 :INTEGER;
  292.            
  293.             LOC_ClassArray              :DYNARRAY[] of STRING;
  294.             LOC_ClassIndex              :DYNARRAY[] of INTEGER;
  295.            
  296.             atChoice        :Integer;
  297.             atIndex         :Integer;
  298.             h               :handle;
  299.             x               :integer;
  300.             DisplayGrey     :Boolean;
  301.             DisplayItalic   :Boolean;
  302.             AssignedTOClass :Integer;
  303.             Assign_this     :String;
  304.             undos           :integer;
  305.            
  306.        
  307.            
  308.            
  309.             Procedure AssignThem(h :HANDLE);
  310.                 begin
  311.                     if GetClass(h) = LOC_ClassArray[x]  then SetClass(h, assign_to);
  312.                    
  313.                 end;
  314.            
  315.                
  316.                 BEGIN
  317.                     IF GetNumSelectedLBItems(dialog1, kEXclsnm)<>0 THEN BEGIN
  318.                            
  319.                         list_number := GetNumLBItems(dialog1, kEXclsnm);
  320.                                
  321.                         For atChoice:=0 to list_number Do Begin
  322.                             Selection := IsLBItemSelected(dialog1, kEXclsnm, atChoice);
  323.                                    
  324.                             If  Selection=True Then Begin
  325.                                 Assign := GetLBItemInfo(dialog1, kEXclsnm, atChoice, kCol0, assign_to, list_image);
  326.                                
  327.                                 atIndex:=atChoice;
  328.                             End;   
  329.                         End;
  330.                                
  331.                     IF GetNumLBItems(dialog1, kNEWclsnm)<>0 THEN BEGIN
  332.                            
  333.                         list_number := GetNumLBItems(dialog1, kNEWclsnm);
  334.                         Sel_cls := GetNumSelectedLBItems(dialog1, kNEWclsnm);
  335.                        
  336.                    
  337.                         if  Sel_cls=0 Then BEGIN
  338.                             AlrtDialog('No classes selected');
  339.                         End;
  340.                                
  341.                         if  Sel_cls>0 Then BEGIN
  342.                                                
  343.                             ALLOCATE LOC_ClassArray[1..Sel_cls];
  344.                             ALLOCATE LOC_ClassIndex[1..Sel_cls];
  345.                             Sel_ndx:=1;    
  346.                            
  347.                             For atChoice:=0 to list_number Do Begin
  348.                                 Selection := IsLBItemSelected(dialog1, kNEWclsnm, atChoice);
  349.                                
  350.                                 If  Selection=True Then Begin
  351.                                     Assign := GetLBItemInfo(dialog1, kNEWclsnm, atChoice, kCol0, to_be_assigned, list_image);
  352.                        
  353.                                     LOC_ClassArray[Sel_ndx] := to_be_assigned;  
  354.                                     LOC_ClassIndex[Sel_ndx] := atChoice;
  355.                                    
  356.                                    
  357.                                     Sel_ndx:=Sel_ndx+1;    
  358.                                    
  359.                                     { Send Selection to Global Variables for Undo History}
  360.                                    
  361.                                     Click_Count:=(Click_Count+1);  
  362.                                     ButtonChoice[Click_Count]:='Assign';
  363.                                     ClassRecord[Click_Count]:=to_be_assigned;
  364.                                    
  365.                                 End;
  366.                             End;
  367.                            
  368.                             {Send Value of Selected Index to Global Variable to build Undo History}
  369.                            
  370.                             if Assign_CountTOT=0 then begin
  371.                                 Assign_CountTOT:=sel_cls;
  372.                                 Selection_Undo:=Sel_cls;
  373.                                                                
  374.                                 For undos:=1 to Assign_CountTOT do begin
  375.                                     AssignIndexRecord[undos]:=(atIndex+undos);
  376.                                 End;       
  377.                                    
  378.                             end else begin
  379.                                 Selection_Undo:=Sel_cls;                               
  380.                                
  381.                                 For undos:=1 to Selection_Undo do begin
  382.                                     AssignIndexRecord[(Assign_CountTOT+undos)]:=(atIndex+undos);
  383.                                 End;
  384.                             Assign_CountTOT:=(Assign_CountTOT+Selection_Undo); 
  385.                             End;
  386.                            
  387.                             Sel_ndx:=(Sel_cls);
  388.                        
  389.                        
  390.                             {Sort the Array in Descending order to allow DeleteLBItem work in a
  391.                             Loop }
  392.                        
  393.                             For x:=1 to Sel_cls do BEGIN
  394.                        
  395.                                 if x<Sel_ndx Then Begin
  396.                            
  397.                            
  398.                                     temp_ndx1 := LOC_ClassIndex[Sel_ndx];
  399.                                     temp_cls1 := LOC_ClassArray[Sel_ndx];
  400.                            
  401.                                     temp_ndx2 := LOC_ClassIndex[x];
  402.                                     temp_cls2 := LOC_ClassArray[x];
  403.                                
  404.                                     LOC_ClassIndex[x] := temp_ndx1;
  405.                                     LOC_ClassArray[x] := temp_cls1;
  406.                            
  407.                                     LOC_ClassIndex[Sel_ndx] := temp_ndx2;
  408.                                     LOC_ClassArray[Sel_ndx] := temp_cls2;
  409.                                 End;   
  410.                                 Sel_ndx:=(Sel_ndx-1);
  411.                             End;    
  412.                            
  413.                             {Exectues the Assignments and deletes Classes}
  414.                            
  415.                             For x:=1 to Sel_cls Do BEGIN
  416.                                 ForEachObject(AssignThem, SEL);
  417.                                 DelClass(LOC_ClassArray[x]);
  418.                                
  419.                                 Assign_this:=Concat('   ',LOC_ClassArray[x]);
  420.                    
  421.                                 AssignedTOClass:=InsertLBItem(dialog1, kEXclsnm, (atIndex+1), Assign_this);
  422.                                
  423.                                
  424.                                 DisplayGrey:=SetLBItemTextColor(dialog1, kEXclsnm,(atIndex+1), kCol0, 115, 115, 115);
  425.                                 DisplayItalic:=SetLBItemTextStyle(dialog1, kEXclsnm, (atIndex+1), kCol0, 2);
  426.                            
  427.                                 Remove:=DeleteLBItem(dialog1, kNEWclsnm, LOC_ClassIndex[x]);
  428.                                
  429.                             End;
  430.                            
  431.                            
  432.                         End;
  433.                    
  434.                     END ELSE BEGIN
  435.                         AlrtDialog('No more classes need to be reassigned');
  436.                     End;   
  437.            
  438.                 END ELSE BEGIN
  439.                     AlrtDialog('SELECT ONE OF THE EXISTING CLASSES');
  440.                 End;
  441.             End;
  442.            
  443. { ***************************************************************************************************************** }                          
  444.             Procedure   Add_Button;
  445.             Var
  446.                 Selection, Remove, Assign   :Boolean;
  447.                 Add                         :Integer;
  448.            
  449.                 Sel_ndx, Sel_cls            :Integer;
  450.            
  451.                 temp_ndx1, temp_ndx2        :Integer;
  452.                 temp_cls1, temp_cls2        :string;
  453.                 list_name                   :STRING;       
  454.                 list_image                  :Integer;      
  455.                 list_number                 :INTEGER;
  456.            
  457.                 LOC_ClassArray              :DYNARRAY[] of STRING;
  458.                 LOC_ClassIndex              :DYNARRAY[] of INTEGER;
  459.                
  460.                 atChoice        :Integer;
  461.                 h               :handle;
  462.                 x               :Integer;
  463.                 beginningfile   :Integer;
  464.                 DisplayRed      :Boolean;
  465.                
  466.             BEGIN
  467.            
  468.                 IF GetNumLBItems(dialog1, kNEWclsnm)<>0 THEN BEGIN
  469.                     list_number := GetNumLBItems(dialog1, kNEWclsnm);
  470.                     Sel_cls := GetNumSelectedLBItems(dialog1, kNEWclsnm);
  471.                    
  472.                         if  Sel_cls=0 Then BEGIN
  473.                             AlrtDialog('No classes Selected');
  474.                         End;
  475.                                
  476.                     if  Sel_cls>0 Then BEGIN
  477.                         ALLOCATE LOC_ClassArray[1..Sel_cls];
  478.                         ALLOCATE LOC_ClassIndex[1..Sel_cls];
  479.                
  480.                         Sel_ndx:=1;    
  481.                         For atChoice:=0 to list_number Do Begin
  482.                             Selection := IsLBItemSelected(dialog1, kNEWclsnm, atChoice);
  483.                                
  484.                             If  Selection=True Then Begin
  485.                                 Assign := GetLBItemInfo(dialog1, kNEWclsnm, atChoice, kCol0, to_be_assigned, list_image);
  486.                        
  487.                                 LOC_ClassArray[Sel_ndx] := to_be_assigned;  
  488.                                 LOC_ClassIndex[Sel_ndx] := atChoice;
  489.                                
  490.                                 Sel_ndx:=Sel_ndx+1;
  491.                             End;
  492.                         End;
  493.                    
  494.                         Sel_ndx:=(Sel_cls);
  495.    
  496.                         {Sort the Array in Descending order to allow DeleteLBItem work in a Loop }
  497.                         For x:=1 to Sel_cls do BEGIN
  498.                        
  499.                             if x<Sel_ndx Then Begin
  500.                                                        
  501.                                 temp_ndx1 := LOC_ClassIndex[Sel_ndx];
  502.                                 temp_cls1 := LOC_ClassArray[Sel_ndx];
  503.                            
  504.                                 temp_ndx2 := LOC_ClassIndex[x];
  505.                                 temp_cls2 := LOC_ClassArray[x];
  506.                                
  507.                                 LOC_ClassIndex[x] := temp_ndx1;
  508.                                 LOC_ClassArray[x] := temp_cls1;
  509.                            
  510.                                 LOC_ClassIndex[Sel_ndx] := temp_ndx2;
  511.                                 LOC_ClassArray[Sel_ndx] := temp_cls2;
  512.                             End;   
  513.                             Sel_ndx:=(Sel_ndx-1);
  514.                         End;    
  515.                        
  516.                        
  517.                         For x:=1 to Sel_cls Do Begin
  518.                             { Send Selection to Global Variables for Undo History}
  519.                             Click_Count:=(Click_Count+1);
  520.                             ButtonChoice[Click_Count]:='Add';
  521.                             ClassRecord[Click_Count]:=LOC_ClassArray[x];
  522.                             IndexRecord[Click_Count]:=LOC_ClassIndex[x];
  523.                            
  524.                             Remove:=DeleteLBItem(dialog1, kNEWclsnm, LOC_ClassIndex[x]);
  525.                             Add:=InsertLBItem(dialog1, kEXclsnm, 0,LOC_ClassArray[x]);
  526.                             DisplayRed:=SetLBItemTextColor(dialog1, kExclsnm, 0, kCol0, 255, 0, 0);
  527.                         End;
  528.                     End;
  529.                
  530.                     END ELSE BEGIN
  531.                         IF GetNumLBItems(dialog1, kNEWclsnm)=0 THEN BEGIN
  532.                             AlrtDialog('No more classes can be added');
  533.                             END ELSE BEGIN
  534.                                 AlrtDialog('SELECT ONE OF THE EXISTING CLASSES');
  535.                         End;
  536.                     END;
  537.             END;
  538.                    
  539. { **************************************************************************************************************** }
  540.  
  541.         Procedure Undo_Button;
  542.         VAR
  543.             ArrangeChoice                   :ARRAY[1..100] of String;
  544.             ArrangeClass                    :ARRAY[1..100] of STRING;
  545.             ArrangeIndex                    :ARRAY[1..100] of Integer;
  546.             ArrangeAssignIndex              :ARRAY[1..100] of Integer;
  547.             Current_Assign_Undo             :Integer;
  548.            
  549.             Add     :Integer;
  550.             Remove  :Boolean;
  551.             x,y     :Integer;
  552.            
  553.            
  554.            
  555.             temp_ch1, temp_ch2      :String;
  556.             temp_cls1, temp_cls2    :string;
  557.             temp_ndx1, temp_ndx2    :Integer;
  558.             temp_ndx3, temp_ndx4    :Integer;
  559.             Counter                 :Integer;
  560.        
  561.         BEGIN
  562.             If Click_Count<=0 then BEGIN
  563.             AlrtDialog('NOTHING TO UNDO!');
  564.            
  565.             END ELSE BEGIN
  566.                 {Duplicate Array for sorting}
  567.                 For x:=1 to 100 do begin
  568.                     ArrangeChoice[x]:=ButtonChoice[x];
  569.                     ArrangeClass[x]:=ClassRecord[x];
  570.                     ArrangeIndex[x]:=IndexRecord[x];
  571.                     ArrangeAssignIndex[x]:=AssignIndexRecord[x];
  572.                 End;
  573.                
  574.                 Current_Assign_Undo := Assign_CountTOT;
  575.                
  576.                                
  577.                 {Sort the Array in Descending order to Build Undo History}
  578.                 Counter:=Click_Count;  
  579.            
  580.                 For x:=1 to Click_Count do BEGIN
  581.                        
  582.                     if x<=Counter Then Begin
  583.                                                        
  584.                         temp_ch1 := ArrangeChoice[Counter];
  585.                         temp_cls1 := ArrangeClass[Counter];
  586.                         temp_ndx1 := ArrangeIndex[Counter];
  587.                        
  588.                            
  589.                         temp_ch2 := ArrangeChoice[x];
  590.                         temp_cls2 := ArrangeClass[x];
  591.                         temp_ndx2 := ArrangeIndex[x];
  592.  
  593.                                
  594.                         ArrangeChoice[x]        := temp_ch1;
  595.                         ArrangeClass[x]         := temp_cls1;
  596.                         ArrangeIndex[x]         := temp_ndx1;
  597.                        
  598.                            
  599.                         ArrangeChoice[Counter]      := temp_ch2;
  600.                         ArrangeClass[Counter]       := temp_cls2;
  601.                         ArrangeIndex[Counter]       := temp_ndx2;
  602.                        
  603.                     End;   
  604.                     Counter:=(Counter-1);
  605.                 End;    
  606.                
  607.                     If ArrangeChoice[1]='Assign' Then BEGIN
  608.                        
  609.                         Counter:=Current_Assign_Undo;
  610.                         For x:=1 to Counter do BEGIN
  611.                    
  612.                             if x<=Counter then Begin
  613.                                 temp_ndx3 := ArrangeAssignIndex[Counter];
  614.                                 temp_ndx4 := ArrangeAssignIndex[x];
  615.                                 ArrangeAssignIndex[x]   := temp_ndx3;
  616.                                 ArrangeAssignIndex[Counter] := temp_ndx4;
  617.                             End;
  618.                            
  619.                             Counter:=(Counter-1);
  620.                         End;
  621.                        
  622.                        
  623.                         NameClass(ArrangeClass[1]);
  624.                         Add:=InsertLBItem(dialog1, kNewclsnm, 0,ArrangeClass[1]);
  625.                                                
  626.                        
  627.                         Remove:=DeleteLBItem(dialog1, kExclsnm, ArrangeAssignIndex[1]);
  628.                         Click_Count:=(Click_Count-1);
  629.                        
  630.                        
  631.                         For x:=1 to Current_Assign_Undo do BEGIN
  632.                                 ArrangeAssignIndex[x]:=ArrangeAssignIndex[x+1];
  633.                         end;
  634.                                                
  635.                    
  636.                         {Remove deleted Index From Local and Global Array of indexes}
  637.                        
  638.                         ArrangeAssignIndex[Current_Assign_Undo ]:=0;
  639.                         AssignIndexRecord[Current_Assign_Undo ]:=0;
  640.                        
  641.                         {Reverts Local Array of indexes}
  642.                         Current_Assign_Undo :=  (Current_Assign_Undo-1);   
  643.                         Counter:=Current_Assign_Undo;
  644.                             For x:=1 to Counter do BEGIN
  645.                    
  646.                                 if x<=Counter then Begin
  647.                                     temp_ndx3 := ArrangeAssignIndex[Counter];
  648.                                     temp_ndx4 := ArrangeAssignIndex[x];
  649.                                     ArrangeAssignIndex[x]   := temp_ndx3;
  650.                                     ArrangeAssignIndex[Counter] := temp_ndx4;
  651.                                 End;
  652.                                 Counter:=(Counter-1);
  653.                             End;
  654.                            
  655.                         {Copy Reverted Local Array to Global}
  656.                         For x:=1 to Current_Assign_Undo do begin
  657.                             AssignIndexRecord[x]:=ArrangeAssignIndex[x];
  658.                         End;
  659.                            
  660.                         Assign_CountTOT :=  (Assign_CountTOT-1);
  661.                      
  662.                     End;
  663.                        
  664.                     If ArrangeChoice[1]='Add' Then BEGIN
  665.            
  666.                         Add:=InsertLBItem(dialog1, kNewclsnm, 0,ArrangeClass[1]);
  667.                         Remove:=DeleteLBItem(dialog1, kExclsnm, 0);
  668.                    
  669.                         Click_Count:=(Click_Count-1);
  670.                     End;   
  671.             End;
  672.         END;
  673.        
  674.        
  675. { **************************************************************************************************************** }
  676.  
  677.         { ***************************************************************** }
  678.                         { END DEFINITION OF BUTTONS BEHAVIOUR }
  679.         { ***************************************************************** }
  680.        
  681.         PROCEDURE dialog1_Handler(VAR item :LONGINT; data :LONGINT);
  682.  
  683.         Var
  684.             ColNum,TempI,I : Integer;
  685.             SheetTypeIcon : Integer;
  686.             BSB : Boolean;
  687.             BSS : String;
  688.             Selection : Boolean;
  689.  
  690.             LayerName,SelectedIconString : String;
  691.             SheetIconNumber,SelectedIconNumber : Integer;
  692.            
  693.            
  694.             atChoice    :Integer;
  695.             list_number :Integer;
  696.            
  697.             list_image  :Integer;
  698.             Assign      :Boolean;
  699.             x,y         :integer;
  700.            
  701.  
  702.         BEGIN
  703.             CASE item OF
  704.                 SetupDialogC:
  705.                     BEGIN
  706.  
  707.                         {Load images into kNEWclsnm.}
  708.                
  709.                         kImageCheckNEW := AddLBImage(dialog1, kNEWclsnm, 1, 11022);
  710.                         kImageBlankNEW := AddLBImage(dialog1, kNEWclsnm, 1, 11023);
  711.                         kImageSheetNEW := AddLBImage(dialog1, kNEWclsnm, 1, 11024);
  712.                         kImageViewNEW := AddLBImage(dialog1, kNEWclsnm, 1, 11025);
  713.                
  714.  
  715.                         {Define kNEWclsnm column 0.}
  716.                         cnt := InsertLBColumn        (dialog1, kNEWclsnm, kCol0, 'Class Name', 180);
  717.                         boo := SetLBControlType      (dialog1, kNEWclsnm, kCol0, kStatic);
  718.                         boo := SetLBItemDisplayType  (dialog1, kNEWclsnm, kCol0, kTextOnly);
  719.                
  720.                         {Initialize the rows to be used in kNEWclsnm.}
  721.                         FOR cnt := 1 TO NumItems2 DO BEGIN
  722.                             ResourceName2:=GetNameFromResourceList(ResourceList2,cnt);
  723.                             int := InsertLBItem(dialog1, kNEWclsnm, cnt, ResourceName2);
  724.                         END;
  725.  
  726.                         {Insert the data into the columns and assign them to the rows.}
  727.                         LB_SetCell(dialog1, kNEWclsnm, kCol0, kRow1, 'ClassList('')');
  728.  
  729.                         EnableLBColumnLines(dialog1, kNEWclsnm, TRUE);
  730.                
  731.                         {Load images into kEXclsnm.}
  732.                         kImageCheckEX := AddLBImage(dialog1, kEXclsnm, 1, 11022);
  733.                         kImageBlankEX := AddLBImage(dialog1, kEXclsnm, 1, 11023);
  734.                         kImageSheetEX := AddLBImage(dialog1, kEXclsnm, 1, 11024);
  735.                         kImageViewEX := AddLBImage(dialog1, kEXclsnm, 1, 11025);
  736.                
  737.                         {Define kEXclsnm column 0.}
  738.                         cnt := InsertLBColumn        (dialog1, kEXclsnm, kCol0, 'Class Name', 180);
  739.                         boo := SetLBControlType      (dialog1, kEXclsnm, kCol0, kStatic);
  740.                         boo := SetLBItemDisplayType  (dialog1, kEXclsnm, kCol0, kTextOnly);
  741.                
  742.                         {Initialize the rows to be used in kEXclsnm.}
  743.                         FOR cnt := 1 TO NumItems DO BEGIN
  744.                             ResourceName1:=GetNameFromResourceList(ResourceList1,cnt);
  745.                             int := InsertLBItem(dialog1, kEXclsnm, cnt, ResourceName1);
  746.                         END;
  747.  
  748.                         {Insert the data into the columns and assign them to the rows.}
  749.                         LB_SetCell(dialog1, kEXclsnm, kCol0, kRow1, 'ClassList('')');
  750.  
  751.                         EnableLBColumnLines(dialog1, kEXclsnm, TRUE);
  752.                
  753.                     END;
  754.        
  755.                 { ***************************************************************** }
  756.                             { CALL PROCEDURES OF BUTTONS BEHAVIOUR}
  757.                 { ***************************************************************** }
  758.                 kCancel:
  759.                     BEGIN
  760.                         canceled:=TRUE;
  761.                         Didcancel:=canceled;   
  762.                     END;
  763.            
  764.                 kUndo_Btn:
  765.                     BEGIN
  766.                         Undo_Button;           
  767.                     END;
  768.            
  769.                 kPaste_Btn:
  770.                         BEGIN
  771.                             Add_Button;
  772.                         END;
  773.            
  774.                 kAssign:
  775.                         BEGIN
  776.                             Assign_Button;
  777.                         END;
  778.  
  779.                 kOK:
  780.                     BEGIN
  781.                         IF GetNumLBItems(dialog1, kNEWclsnm)<>0 THEN Begin                     
  782.                         AlrtDialog('Please, Assign or Add the Incoming Classes!');
  783.                         dialog1_Main;
  784.                         end;
  785.                     END;
  786.            
  787.                 kNEWclsnm:
  788.                     BEGIN
  789.                     {Insert the data into the columns and assign them to the rows.}
  790.            
  791.                         For cnt:= 1 to numOfClass do
  792.                         LB_SetCell(dialog1, kNEWclsnm, 0, cnt, ClassList(cnt));
  793.                         EnableLBColumnLines(dialog1, kNEWclsnm, TRUE);
  794.                         Select_more:=EnableLBSingleLineSelection(dialog1, kNEWclsnm,FALSE);
  795.                     END;
  796.            
  797.                 kEXclsnm:
  798.                     BEGIN
  799.                     {Insert the data into the columns and assign them to the rows.}
  800.            
  801.                         For cnt:= 1 to numOfClass do
  802.                         LB_SetCell(dialog1, kEXclsnm, 0, cnt, ClassList(cnt));
  803.                         EnableLBColumnLines(dialog1, kEXclsnm, TRUE);
  804.                         Select_one:=EnableLBSingleLineSelection(dialog1, kEXclsnm,TRUE);
  805.                     END;
  806.             END;
  807.         END;
  808.  
  809.     BEGIN   {of dialog1_Main}
  810.  
  811.         kImageCheckNEW  := 0;
  812.         kImageBlankNEW  := 0;
  813.         kImageSheetNEW  := 0;
  814.         kImageViewNEW   := 0;
  815.    
  816.         kImageCheckEX := 0;
  817.         kImageBlankEX := 0;
  818.         kImageSheetEX := 0;
  819.         kImageViewEX  := 0;
  820.    
  821.    
  822.         IF ResourceIsOK THEN dialog1_Setup;
  823.         IF RunLayoutDialog(dialog1, dialog1_Handler) = 1 then BEGIN
  824.         END;
  825.     END;
  826.  
  827. { **************************************************************************************************************** }
  828.                                 { END OF ALL SUB-PROCEDURES }
  829. { **************************************************************************************************************** }
  830.  
  831. BEGIN  {of Smart_Paste}
  832.  
  833.     Assign_CountTOT:=0;    
  834.     Selection_Undo:=0;
  835.     ResourceList_Existing_Classes;
  836.     DoMenuTextByName('Paste',0);
  837.     ResourceList_Extra_Classes;    
  838.    
  839.     IF (NumItems2=0) THEN BEGIN
  840.        
  841.     END ELSE BEGIN
  842.        
  843.         Click_Count:=0;
  844.         dialog1_Main;
  845.        
  846.         IF Didcancel THEN BEGIN
  847.             DoMenuTextByName('Undo',0);
  848.         END;
  849.     END;
  850. END;
  851.  
  852. { ***************************************************************************************************************** }
  853.  
  854. RUN(Smart_Paste);
  855.        
  856.    
  857.  
  858. {This program is free software: you can redistribute it and/or modify
  859.     it under the terms of the GNU General Public License as published by
  860.     the Free Software Foundation, either version 3 of the License, or
  861.     (at your option) any later version.
  862.  
  863.     This program is distributed in the hope that it will be useful,
  864.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  865.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  866.     GNU General Public License for more details.
  867.  
  868.     You should have received a copy of the GNU General Public License
  869.     along with this program.  If not, see <http://www.gnu.org/licenses/>.}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement