home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / INFO / DI9806FN.ZIP / source / ProjId.pas < prev   
Pascal/Delphi Source File  |  1998-04-09  |  30KB  |  823 lines

  1. unit ProjId;
  2.  
  3. { This file is based on the standard CodeRush plug-in template.  It allows
  4.   you to add Project/Unit specific Identifiers to a string list and easily
  5.   paste them into your program at the current caret location }
  6.  
  7. interface
  8.  
  9. uses
  10.   Windows,
  11.   Classes,
  12.   RushIntf,
  13.   Controls,
  14.   Forms,
  15.   Dialogs,
  16.   Graphics,
  17.   Menus,
  18.   StdCtrls,
  19.   Extctrls,
  20.   ToolIntf,
  21.   PrjID_LB,
  22.   PIAbout,
  23.   PrIDCnfg;
  24.  
  25. type
  26.  
  27. ConfigInfo = record
  28. cfgMenuSettings : BoolArray;
  29. cfgProjID_Preference : ProjID_Preferences;
  30. end;
  31.  
  32. // Special ComboBox with popup menu added to toolbar
  33. TToolbarComboBox = class(TComboBox)
  34.   private
  35.     { Private declarations }
  36.     FEmbeddedMenu: TPopupMenu;
  37.     ItmProperties: TMenuItem;
  38.     ItmShowAbout: TMenuItem;
  39.   protected
  40.     { Protected declarations }
  41.     FPopupMenuTag: integer;
  42.     procedure SetupMenuItem(AMenuItem: TMenuItem; ACaption: string; AChecked,
  43.               ARadioItem: boolean; AGroupIndex, AShortCut: integer;
  44.               AHandler: TNotifyEvent); dynamic;
  45.     procedure CreatePopupMenuItems; dynamic;
  46.     procedure InitializePopupMenuItems; dynamic;
  47.     procedure AddMenuItemsToPopupMenu; dynamic;
  48.     { Event handlers and transfer methods for FEmbeddedMenu. }
  49.     procedure PopupEmbeddedMenuHandler(Sender: TObject); dynamic;
  50.     procedure ItmPropertiesClickHandler(Sender: TObject); dynamic;
  51.     procedure ItmShowAboutClickHandler(Sender: TObject); dynamic;
  52.   public
  53.     { Public declarations }
  54.     procedure EnableAllMenuSettings(TheMenuSettings : BoolArray);
  55.     constructor Create(AOwner: TComponent); override;
  56.     destructor Destroy; override;
  57.   published
  58.     { Published properties and events }
  59.   end;  { TToolbarComboBox }
  60.  
  61.   TProjectIdentifiersPlugIn = class(TAbstractRushInterface)
  62.     JustSelectedNewFile,
  63.     UseGlobalFile,
  64.     IdentifiersLoaded : boolean;
  65.     ListOfIdentifiers : TStringList;
  66.     CurrentProjectName : string;  // stores current project
  67.     CurrentFileName : string;  // stores current unit
  68.     // General Code Rush methods
  69.     function GetName: string; override;
  70.     function GetRequestedString(functionName, parameters: string;
  71.                                 var requestedStr: string): boolean; override;
  72.     procedure HandleCommand(command, parameters: string); override;
  73.     // Methods to Implement Functionality of PlugIn
  74.     procedure AddWordToIDList;
  75.     procedure FocusToProjIDComboBox;
  76.     procedure ProjIdentifiersComboBoxDropDown(Sender : TObject);
  77.     procedure ProjIdentifiersComboBoxKeyDown(Sender : TObject;
  78.                              var Key: Word; Shift: TShiftState);
  79.     procedure ProjIdentifiersComboBoxDoubleClick(Sender : TObject);
  80.     procedure ToggleProjIDFile;
  81.     procedure SaveProjID(AFileName : string);
  82.     procedure SaveProjIDToFile;
  83.     procedure OpenProjID(AFileName : string);
  84.     procedure OpenProjIDFromFile;
  85.     procedure RemoveWordFromIDList(StringToDelete : String);
  86.     // Method to add support info to CodeRush About Box
  87.     function GetRequestedStringList(strListName, parameters: string;
  88.               requestedStrList: TStringList): boolean; override;
  89.     // Event Enablers
  90.     procedure Event_NewFileSelected(newFileName: string); override;
  91.     procedure Event_ToolbarCreated(parentToolbar: TCustomPanel); override;
  92.     procedure Event_FileNotification  (notifyCode: TRushFileNotification;
  93.                 const fileName: string; var cancel: Boolean); override;
  94.     // Menu configuration
  95.     procedure GetCurrentMenuSettings(var CurrentMenuSettings : BoolArray);
  96.     // Creation/Destruction methods
  97.     constructor Create;
  98.     destructor Destroy; override;
  99.   end;    { TProjectIdentifiersPlugIn }
  100.  
  101. procedure Register;
  102.  
  103. implementation
  104.  
  105. uses
  106.   SysUtils;
  107.  
  108. var
  109.   MenuSettings : BoolArray;
  110.   ProjID_Preference : ProjID_Preferences;
  111. const
  112.   // plug-in commands added to the CodeRush
  113.   CMD_CopyIdentifier = 'Identifier_Add';
  114.   CMD_DeleteIdentifier = 'Identifier_Delete';
  115.   CMD_FocusToIdentifierCB = 'Focus_Identifier_List';
  116.   CMD_LoadIdentifierFromFile = 'Load_Identifiers';
  117.   CMD_SaveIdentifierToFile = 'Save_Identifiers';
  118.   CMD_ToggleProjUnit = 'Toggle_Global_Identifiers';
  119.   // string functions to get paste Identifier at current caret location
  120.   FNC_PasteProjIDString = 'PasteProjIDStr';
  121.   FNC_SelectProjIDString = 'SelectProjIDStr';
  122.   // Editor Popup menu items
  123.   STR_FocusIDMenuItem = 'mnuFocusProjIDPlugIn';
  124.   STR_AddProjIDMenuItem = 'mnuAddProjIDPlugIn';
  125.   STR_DeleteProjIDMenuItem = 'mnuDeleteProjIDPlugIn';
  126.   STR_ProjIdentifiersComboBox = 'Proj_ID_ComboBox';
  127.   STR_LoadIdentifierFromFile = 'mnuProjectIDLoadFromFile';
  128.   STR_SaveIdentifierFromFile = 'mnuProjectIDSaveToFile';
  129.   STR_ProjIdAboutID = 'Proj ID Plugin';
  130.  
  131. ResourceString
  132.   sAddProjIDMenuItem = 'Add Project Identifier to List';
  133.   sFocusProjIDMenuItem = 'Focus to Project Identifiers ComboBox';
  134.   sDeleteProjIDMenuItem = 'Delete Project Identifier from List';
  135.   sLoadProjIDFromFileMenuItem = 'Load Project Identifiers from File';
  136.   sSaveProjIDToFileMenuItem = 'Save Project Identifiers to File';
  137.  
  138.  
  139. function TProjectIdentifiersPlugIn.GetName: string;
  140. begin
  141.   result := 'Alan_C._Moore_ProjectIdentifiersPlugIn';
  142. end;    { GetName }
  143.  
  144. function TProjectIdentifiersPlugIn.GetRequestedString(
  145.          functionName, parameters: string; var requestedStr: string): boolean;
  146. var
  147.   localComboBox : TToolbarComboBox;
  148.     localDialog : TSelectIdentifierDlg;
  149. begin
  150.   result := True;
  151.   if CompareText(functionName, FNC_PasteProjIDString) = 0 then
  152.     begin
  153.     localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl(
  154.                                STR_ProjIdentifiersComboBox));
  155.     if assigned(localComboBox) then
  156.       begin
  157.         CodeRush.PutUpTransientMessage
  158.                 ('Current Project Identifier will be inserted', 1);
  159.         localComboBox.SetFocus;
  160.         requestedStr := localComboBox.SelText;
  161.     exit;
  162.       end;
  163.     end
  164.     else
  165.     if CompareText(functionName, FNC_SelectProjIDString) = 0 then
  166.    begin
  167.     localDialog := TSelectIdentifierDlg.Create(CodeRush);
  168.     try
  169.       CodeRush.PutUpTransientMessage
  170.         ('Select Identifier to Paste into code', 1);
  171.       if NOT localDialog.Execute
  172.         (requestedStr, ListOfIdentifiers) then requestedStr := '';
  173.     finally
  174.     localDialog.Free;
  175.     end;  // try/finally
  176.     if requestedStr<>'' then exit;
  177.         end  // outer begin/end
  178.     else
  179.   result := False;
  180. end;    { GetRequestedString }
  181.  
  182. procedure TProjectIdentifiersPlugIn.HandleCommand(command, parameters: string);
  183. begin
  184.   if CompareText(command, CMD_CopyIdentifier) = 0 then
  185.     AddWordToIDList
  186.   else if CompareText(command, CMD_FocusToIdentifierCB) = 0 then
  187.     FocusToProjIDComboBox
  188.   else if CompareText(command, CMD_DeleteIdentifier) = 0 then
  189.     RemoveWordFromIDList(CodeRush.GetCurrentWord)
  190.   else if CompareText(command,  CMD_LoadIdentifierFromFile) = 0 then
  191.     OpenProjIDFromFile
  192.   else if CompareText(command, CMD_SaveIdentifierToFile) = 0 then
  193.     SaveProjIDToFile
  194.   else if CompareText(command, CMD_ToggleProjUnit) = 0 then
  195.      ToggleProjIDFile;
  196. end;    { HandleCommand }
  197.  
  198. // Configuration Methods
  199.  
  200. procedure UpdateProjIDSettings(NewMenuSettings, OldMenuSettings : BoolArray;
  201.            NewPreferences : ProjID_Preferences);
  202. var
  203.   MenuFileName : string;
  204.   MenuFile : File of ConfigInfo;
  205.   LocalCfgInfo : ConfigInfo;
  206.   j: integer;
  207. begin
  208.   LocalCfgInfo.cfgMenuSettings := NewMenuSettings;
  209.   LocalCfgInfo.cfgProjID_Preference := ProjID_Preference;
  210.   for j := 0 to 4 do    //Iterate to find which menu settings have changed
  211.   begin
  212.     if NewMenuSettings[j]<>OldMenuSettings[j] then
  213.        with CodeRush do
  214.        case j of    //
  215.          0:  if NewMenuSettings[0] then
  216.              AddMenuItemToEditor(STR_FocusIDMenuItem, '', 'N2',
  217.                 sFocusProjIDMenuItem, CMD_FocusToIdentifierCB, 0,
  218.                 True, True, False)
  219.               else RemoveMenuItemFromEditor(STR_FocusIDMenuItem);
  220.          1:  if MenuSettings[1] then
  221.              AddMenuItemToEditor(STR_AddProjIDMenuItem, '', 'N2',
  222.                 sAddProjIDMenuItem, CMD_CopyIdentifier, 0, True, True, False)
  223.              else RemoveMenuItemFromEditor(STR_AddProjIDMenuItem);
  224.          2:  if MenuSettings[2] then
  225.              AddMenuItemToEditor(STR_DeleteProjIDMenuItem, '', 'N2',
  226.                 sDeleteProjIDMenuItem, CMD_DeleteIdentifier, 0, True, True,
  227.                 False)
  228.              else RemoveMenuItemFromEditor(STR_DeleteProjIDMenuItem);
  229.          3:  if MenuSettings[3] then
  230.              AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
  231.                 'N2', sLoadProjIDFromFileMenuItem,
  232.                 CMD_LoadIdentifierFromFile, 0, True, True, False)
  233.              else RemoveMenuItemFromEditor(STR_LoadIdentifierFromFile);
  234.          4:  if MenuSettings[4] then
  235.              AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
  236.                 'N2', sSaveProjIDToFileMenuItem,
  237.                 CMD_SaveIdentifierToFile, 0, True, True, False)
  238.              else RemoveMenuItemFromEditor(STR_SaveIdentifierFromFile);
  239.        end;    //case
  240.   end;    //for
  241.   CodeRush.PutUpTransientMessage
  242.     ('Saving Project Identifier Configuration Information...', 1);
  243.   MenuFileName := CodeRush.DelphiInstallDirectory + 'bin\ProjID.cfg';
  244.   AssignFile(MenuFile, MenuFileName);
  245.   Rewrite(MenuFile);
  246.   Write(MenuFile, LocalCfgInfo);
  247.   CloseFile(MenuFile);
  248.   CodeRush.DropTransientMessage;
  249. end;
  250.  
  251.  
  252. // Menu configuration
  253. // following procedure no longer used
  254. procedure TProjectIdentifiersPlugIn.GetCurrentMenuSettings
  255.            (var CurrentMenuSettings : BoolArray);
  256. var
  257.   j : integer;
  258.   MenuPath : TMenuItem;
  259. begin
  260. try
  261. MenuPath := nil;
  262. for j := 0 to 4 do    { Iterate }
  263. begin
  264.     case j of    {  }
  265.       0 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
  266.           +STR_FocusIDMenuItem);
  267.       1 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
  268.           +STR_AddProjIDMenuItem);
  269.       2 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
  270.           +STR_DeleteProjIDMenuItem);
  271.       3 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
  272.           +STR_LoadIdentifierFromFile);
  273.       4 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
  274.           +STR_SaveIdentifierFromFile);
  275.     end;    { case }
  276.     if (MenuPath<>Nil) then CurrentMenuSettings[j] := true else
  277.       CurrentMenuSettings[j] := false;
  278. end;    { for }
  279. except
  280. end;
  281. end;
  282.  
  283. // Basic Functionality of Plug-in
  284.  
  285. procedure TProjectIdentifiersPlugIn.AddWordToIDList;
  286. var
  287.   localComboBox : TToolbarComboBox;
  288.   localCurrentWord : string;
  289. begin
  290.   if ExtractFileName(CodeRush.CurrentDelphiFileName)='Unit1' then
  291.     raise Exception.Create('First save Unit1 with unique Name');
  292.   localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  293.                              (STR_ProjIdentifiersComboBox));
  294.   if assigned(localComboBox) then
  295.     begin
  296.     CodeRush.PutUpTransientMessage('Adding Project Identifier to list', 1);
  297.     if ((localComboBox.Items.Count=1) and (localComboBox.Items[0]=
  298.                     '<None Entered>'))
  299.                     then
  300.                     begin
  301.                             localComboBox.Items.Clear;
  302.                             ListOfIdentifiers.Clear;
  303.                     end;
  304.      localCurrentWord := CodeRush.GetCurrentWord;
  305.      if localComboBox.Items.IndexOf(localCurrentWord)>=0 then Exit;
  306.      localComboBox.Items.Add(localCurrentWord);
  307.      ListOfIdentifiers.Add(localCurrentWord);
  308.      localComboBox.Text := localCurrentWord;
  309.      IdentifiersLoaded := True;
  310.     end;
  311. end;
  312.  
  313. procedure TProjectIdentifiersPlugIn.FocusToProjIDComboBox;
  314. var
  315.   localComboBox : TToolbarComboBox;
  316. begin
  317.   If NOT IdentifiersLoaded then exit;
  318.      CodeRush.PutUpTransientMessage
  319.          ('Double Click to paste identifier to code', 1);
  320.      localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  321.      (STR_ProjIdentifiersComboBox));
  322.      if assigned(localComboBox) then localComboBox.SetFocus;
  323. end;
  324.  
  325. procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxDropDown
  326.                                                   (Sender : TObject);
  327. var
  328.   localComboBox: TToolbarComboBox;
  329. begin
  330.   localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  331.                             (STR_ProjIdentifiersComboBox));
  332.   if assigned(localComboBox) then
  333.       localComboBox.Items.Assign(ListOfIdentifiers);
  334. end;        { ProjIdentifiersComboBoxDropDown }
  335.  
  336. procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxKeyDown
  337.                (Sender : TObject; var Key: Word; Shift: TShiftState);
  338. begin
  339.   case Key of    { Key Code }
  340.     VK_Return : ProjIdentifiersComboBoxDoubleClick(Sender);
  341.     VK_Escape : CodeRush.FocusCodeEditor;
  342.     VK_Delete : RemoveWordFromIDList(CodeRush.GetCurrentWord);
  343.   end;    { case }
  344. end;
  345.  
  346. procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxDoubleClick
  347.                                                 (Sender : TObject);
  348. var
  349.   localStringList : TStringList;
  350. begin
  351.   If NOT IdentifiersLoaded then exit;
  352.   if NOT (Sender IS TToolbarComboBox) then exit;
  353.   CodeRush.PutUpTransientMessage('Pasting Project Identifier into code', 1);
  354.   localStringList := TStringList.Create;
  355.   localStringList.Add(TToolbarComboBox(Sender).SelText);
  356.   CodeRush.FocusCodeEditor;
  357.   CodeRush.InsertTextAtCursor(localStringList);
  358.   localStringList.Free;
  359. end;
  360.  
  361.  
  362. procedure TProjectIdentifiersPlugIn.RemoveWordFromIDList
  363.                                (StringToDelete : String);
  364.  
  365. var
  366.   localComboBox: TToolbarComboBox;
  367.   localNdx: Integer;
  368. begin
  369.   localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  370.                             (STR_ProjIdentifiersComboBox));
  371.   if assigned(localComboBox) then
  372.     begin
  373.       if StringToDelete <> '' then
  374.          localNdx := localComboBox.Items.IndexOf(localComboBox.Text) else
  375.          localNdx := localComboBox.ItemIndex;
  376.       if localNdx >= 0 then
  377.          begin
  378.          localComboBox.Items.Delete(localNdx);
  379.          ListOfIdentifiers.Delete(localNdx);
  380.          end
  381.       else exit;
  382.       localComboBox.Text := '';  // change only if successful delete
  383.     end;
  384. end;
  385.  
  386. // File Routines
  387.  
  388. procedure TProjectIdentifiersPlugIn.ToggleProjIDFile;
  389. begin
  390.   if NOT (ProjID_Preference=idProjAndUnits) then exit;
  391.   if UseGlobalFile then
  392.     begin
  393.       UseGlobalFile := False;
  394.       OpenProjID(CodeRush.CurrentDelphiFileName);
  395.     end
  396.   else
  397.     begin
  398.       UseGlobalFile := True;
  399.       OpenProjID(CurrentProjectName);
  400.     end;
  401. end;
  402.  
  403.  
  404. procedure TProjectIdentifiersPlugIn.SaveProjID(AFileName : string);
  405. var
  406.     TempFilePath,
  407.     TempFileName : string;
  408.     localComboBox: TToolbarComboBox;
  409. begin
  410.    if ExtractFileName(AFileName)='Unit1' then exit;
  411.    localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  412.                     (STR_ProjIdentifiersComboBox));
  413.    if assigned(localComboBox) then
  414.    begin
  415.      if ((localComboBox.Items.Count=1) and
  416.         (localComboBox.Items[0]='<None Entered>')) then exit;
  417.      CodeRush.PutUpTransientMessage('Saving Project Identifiers...', 1);
  418.      TempFilePath := ExtractFilePath(AFileName);
  419.      TempFileName := ExtractFileName(ChangeFileExt(AFileName, '.pji'));
  420.      CurrentFileName := TempFilePath+TempFileName;
  421.      localComboBox.Items.SaveToFile(CurrentFileName);
  422.      CodeRush.DropTransientMessage;
  423.    end;
  424. end;
  425.  
  426.  
  427. procedure TProjectIdentifiersPlugIn.SaveProjIDToFile;
  428. var
  429.   SaveFileDlg : TSaveDialog;
  430. begin
  431.   if JustSelectedNewFile then
  432.   CodeRush.PutUpTransientMessage('Select File for Project Identifiers', 1);
  433.   SaveFileDlg := TSaveDialog.Create(Nil);
  434.   try
  435.     SaveFileDlg.Filter := 'Proj ID files (*.pji)|*.PJI)';
  436.     if SaveFileDlg.Execute then SaveProjID(SaveFileDlg.FileName);
  437.   finally { wrap up }
  438.     SaveFileDlg.Free;
  439.   end;    { try/finally }
  440.   JustSelectedNewFile := False;
  441. end;
  442.  
  443. procedure TProjectIdentifiersPlugIn.OpenProjID(AFileName : string);
  444. var
  445.    TempFilePath,
  446.    TempFileName : string;
  447.    localComboBox: TToolbarComboBox;
  448. begin
  449.  // if ExtractFileName(AFileName)='Unit1' then exit;
  450.   TempFilePath := ExtractFilePath(AFileName);
  451.   TempFileName := ExtractFileName
  452.           (ChangeFileExt(AFileName, '.pji'));
  453.   CurrentFileName := TempFilePath + TempFileName;
  454.   localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
  455.                    (STR_ProjIdentifiersComboBox));
  456.   if assigned(localComboBox) then
  457.      begin
  458.      if FileExists(CurrentFileName) then
  459.         begin
  460.           localComboBox.Items.Clear;
  461.           localComboBox.Items.LoadFromFile(CurrentFileName);
  462.           ListOfIdentifiers.Clear;
  463.           ListOfIdentifiers.LoadFromFile(CurrentFileName);
  464.           IdentifiersLoaded := True;
  465.         end else
  466.         begin
  467.           localComboBox.Items.Clear;
  468.           ListOfIdentifiers.Clear;
  469.           localComboBox.Items.Add('<None Entered>');
  470.           IdentifiersLoaded := False;
  471.         end;
  472.      localComboBox.Text := localComboBox.Items[0];
  473.   end;  { if assigned }
  474.   JustSelectedNewFile := False;
  475. end;
  476.  
  477. procedure TProjectIdentifiersPlugIn.OpenProjIDFromFile;
  478. var
  479.   OpenFileDlg : TOpenDialog;
  480. begin
  481.   CodeRush.PutUpTransientMessage('Select Project Identifiers File to open', 1);
  482.   OpenFileDlg := TOpenDialog.Create(Nil);
  483.   try
  484.     OpenFileDlg.Filter := 'Proj ID files (*.pji)|*.PJI';
  485.     if OpenFileDlg.Execute then OpenProjID(OpenFileDlg.FileName);
  486.   finally { wrap up }
  487.    OpenFileDlg.Free;
  488.   end;    { try/finally }
  489.   CodeRush.DropTransientMessage;
  490. end;
  491.  
  492. procedure TProjectIdentifiersPlugIn.Event_FileNotification
  493.                      (notifyCode: TRushFileNotification;
  494.                       const fileName: string; var cancel: Boolean);
  495. begin
  496.   case notifyCode of    { notifyCode  }
  497.     rfnFileOpening :
  498.       if ((ProjID_Preference=idProjOnly) or ((ProjID_Preference=idProjAndUnits)
  499.          and (UseGlobalFile))) then exit
  500.       else OpenProjID(fileName);
  501.     rfnFileClosing :
  502.       if ((ProjID_Preference=idProjOnly) or((ProjID_Preference=idProjAndUnits)
  503.          and (UseGlobalFile))) then
  504.         { SaveProjID(CurrentProjectName) } exit
  505.       else SaveProjID(fileName);
  506.     rfnProjectOpening : CurrentProjectName := fileName;
  507.     rfnProjectOpened :
  508.       if ((ProjID_Preference=idProjOnly) or((ProjID_Preference=idProjAndUnits)
  509.          and (UseGlobalFile))) then
  510.            OpenProjID(CurrentProjectName) else
  511.            OpenProjID(CodeRush.CurrentDelphiFileName);
  512.     rfnProjectClosing :
  513.       if ((ProjID_Preference=idProjOnly) or ((ProjID_Preference=idProjAndUnits)
  514.          and (UseGlobalFile)))  then
  515.          SaveProjID(CurrentProjectName)
  516.       else
  517.          SaveProjID(CodeRush.CurrentDelphiFileName);
  518.   end;    { notifyCode case }
  519. end;
  520.  
  521. // Method to add support info to CodeRush About Box
  522. function TProjectIdentifiersPlugIn.GetRequestedStringList(strListName, parameters: string;
  523. requestedStrList: TStringList): boolean;
  524. begin
  525.   result := False;
  526.   if not assigned(requestedStrList) then
  527.     exit;
  528.   requestedStrList.Clear;               // We should clear the list first.
  529.   if CompareText(strListName, STR_ProjIdAboutID) = 0 then
  530.     begin
  531.       requestedStrList.Add
  532.             ('Project Identifiers Plug In, written by Alan C. Moore');
  533.       requestedStrList.Add('');
  534.       requestedStrList.Add('Copyright (c) 1998, Alan C. Moore');
  535.       requestedStrList.Add('');
  536.       requestedStrList.Add('Send feedback to:' +
  537.                            '|Alan C. Moore|acmdoc@aol.com');
  538.       result := True;
  539.       exit;
  540.     end;
  541. end;
  542.  
  543.  
  544.  
  545.  
  546. // Event Implementations
  547.  
  548. procedure TProjectIdentifiersPlugIn.Event_ToolbarCreated(parentToolbar:
  549.                                                          TCustomPanel);
  550. var
  551.   localComboBox: TToolbarComboBox;
  552. begin
  553.   IdentifiersLoaded := False;
  554.   localComboBox := TToolbarComboBox.Create(parentToolbar);
  555.   CodeRush.AddResizeBarToCustomToolbarControl(localComboBox); 
  556.   with localComboBox do
  557.     begin
  558.       Width := 180;
  559.       Height := 24;
  560.       Name := STR_ProjIdentifiersComboBox;
  561.       Items.Add('<None Entered>');
  562.       Text := '<None Entered>';
  563.       Hint := 'Project Identifiers';
  564.       OnDblClick := ProjIdentifiersComboBoxDoubleClick;
  565.       OnKeyDown  := ProjIdentifiersComboBoxKeyDown;
  566.       IdentifiersLoaded := False;
  567.       UseGlobalFile := False;    // added with CodeRush 3.01V
  568.     end;
  569. end;    { Event_ToolbarCreated }
  570.  
  571.  
  572. procedure TProjectIdentifiersPlugIn.Event_NewFileSelected(newFileName: string);
  573. begin
  574.   JustSelectedNewFile := True;
  575.   if (ProjID_Preference=idProjOnly) or ((ProjID_Preference= idProjAndUnits)
  576.          and (UseGlobalFile)) then
  577.     begin
  578.      // SaveProjID(CurrentFileName);
  579.       OpenProjID(CurrentProjectName);
  580.     end
  581.   else
  582.     begin
  583.      SaveProjID(CurrentFileName);
  584.      OpenProjID(newFileName);
  585.     end;
  586.   JustSelectedNewFile := False;
  587. end;
  588.  
  589.  
  590. constructor TProjectIdentifiersPlugIn.Create;
  591. begin
  592.   inherited Create;
  593.   ListOfIdentifiers := TStringList.Create;
  594.   ListOfIdentifiers.Add('<None Entered>');
  595.   IdentifiersLoaded := False;
  596.   UseGlobalFile := False; // Added in CodeRush version 3.01V
  597. end;    { Create }
  598.  
  599.  
  600. destructor TProjectIdentifiersPlugIn.Destroy;
  601. begin
  602.   if assigned(CodeRush) then
  603.     with CodeRush do
  604.       begin
  605.         RemoveMenuItemFromEditor(STR_FocusIDMenuItem);
  606.         RemoveMenuItemFromEditor(STR_AddProjIDMenuItem);
  607.         RemoveMenuItemFromEditor(STR_DeleteProjIDMenuItem);
  608.         RemoveMenuItemFromEditor(STR_LoadIdentifierFromFile);
  609.         RemoveMenuItemFromEditor(STR_SaveIdentifierFromFile);
  610.         UnRegisterEventHandler(Self, EVC_NewFileSelected);
  611.         UnRegisterEventHandler(Self, EVC_ToolbarCreated);
  612.         UnRegisterEventHandler(Self, EVC_FileNotification);
  613.         ListOfIdentifiers.Free;
  614.       end;    { with }
  615.   inherited Destroy;
  616. end;    { Destroy }
  617.  
  618. procedure Register;
  619.  
  620. var
  621.   ProjectIdentifiersPlugIn : TProjectIdentifiersPlugIn;
  622.   MenuFileName : string;
  623.   MenuFile : File of ConfigInfo;
  624.   ConfigRecord : ConfigInfo;
  625.   ProjIDConfigExists : boolean;
  626. begin
  627.   ProjID_Preference := idProjOnly;
  628.   ProjectIdentifiersPlugIn := TProjectIdentifiersPlugIn.Create;
  629.   MenuFileName := CodeRush.DelphiInstallDirectory + 'bin\ProjID.cfg';
  630.   if NOT FileExists(MenuFileName) then
  631.      ProjIDConfigExists := False else
  632.      begin
  633.        ProjIDConfigExists := True;
  634.        AssignFile(MenuFile, MenuFileName);
  635.        try
  636.        Reset(MenuFile);
  637.        read(MenuFile, ConfigRecord);
  638.        except
  639.            ProjIDConfigExists := False;
  640.            if Application.MessageBox
  641.              ('Configuration File is old or currupted; Erase?',
  642.               'Corrupt Configuration File', MB_OK)=mrOK then
  643.               begin
  644.                 CloseFile(MenuFile);
  645.                 Erase(MenuFile);
  646.               end;
  647.        end;
  648.        MenuSettings := AssignBoolArray(ConfigRecord.cfgMenuSettings);
  649.        ProjID_Preference := ConfigRecord.cfgProjID_Preference;
  650.        CloseFile(MenuFile);
  651.      end;
  652.   with CodeRush do
  653.     begin
  654.       RegisterInterface(ProjectIdentifiersPlugIn);
  655.       RegisterCustomToolbarControl(ProjectIdentifiersPlugIn,
  656.           STR_ProjIdentifiersComboBox);
  657.       RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_NewFileSelected);
  658.       RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_ToolbarCreated);
  659.       RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_FileNotification);
  660.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_CopyIdentifier);
  661.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_DeleteIdentifier);
  662.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_FocusToIdentifierCB);
  663.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_LoadIdentifierFromFile);
  664.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_SaveIdentifierToFile);
  665.       RegisterCommand(ProjectIdentifiersPlugIn, CMD_ToggleProjUnit);
  666.         // above Added with CodeRush 3.01V
  667.       RegisterStringFunction(ProjectIdentifiersPlugIn, FNC_PasteProjIDString);
  668.       RegisterStringFunction(ProjectIdentifiersPlugIn, FNC_SelectProjIDString);
  669.       RegisterStringListFunction(ProjectIdentifiersPlugIn,
  670.                                  STR_ProjIdAboutID, INT_SupportURLs);
  671.       if NOT ProjIDConfigExists then
  672.       begin
  673.         ProjID_Preference  := idProjOnly;
  674.         AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
  675.           'N2', sLoadProjIDFromFileMenuItem,
  676.           CMD_LoadIdentifierFromFile, 0, True, True, False);
  677.         AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
  678.           STR_LoadIdentifierFromFile, sSaveProjIDToFileMenuItem,
  679.           CMD_SaveIdentifierToFile, 0, True, True, False);
  680.         MenuSettings[0] := false;
  681.         MenuSettings[1] := false;
  682.         MenuSettings[2] := false;
  683.         MenuSettings[3] := true;
  684.         MenuSettings[4] := true;
  685.       end
  686.         else
  687.         begin
  688.           if MenuSettings[0] then
  689.              AddMenuItemToEditor(STR_FocusIDMenuItem, '', 'N2',
  690.                 sFocusProjIDMenuItem, CMD_FocusToIdentifierCB, 0,
  691.                 True, True, False);
  692.           if MenuSettings[1] then
  693.              AddMenuItemToEditor(STR_AddProjIDMenuItem, '', 'N2',
  694.                 sAddProjIDMenuItem, CMD_CopyIdentifier, 0, True, True, False);
  695.           if MenuSettings[2] then
  696.              AddMenuItemToEditor(STR_DeleteProjIDMenuItem, '', 'N2',
  697.                 sDeleteProjIDMenuItem, CMD_DeleteIdentifier, 0, True, True,
  698.                 False);
  699.           if MenuSettings[3] then
  700.              AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
  701.                 'N2', sLoadProjIDFromFileMenuItem,
  702.                 CMD_LoadIdentifierFromFile, 0, True, True, False);
  703.           if MenuSettings[4] then
  704.              AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
  705.                 'N2', sSaveProjIDToFileMenuItem,
  706.                 CMD_SaveIdentifierToFile, 0, True, True, False);
  707.         end;
  708.     end;    { with }
  709. end;    { Register }
  710.  
  711. // ToolBox ComboBox Methods
  712. procedure TToolbarComboBox.SetupMenuItem(AMenuItem: TMenuItem;
  713.           ACaption: string; AChecked, ARadioItem: boolean;
  714.           AGroupIndex, AShortCut: integer; AHandler: TNotifyEvent);
  715. begin
  716.   with AMenuItem do
  717.   begin
  718.     Caption := ACaption;
  719.     Checked := AChecked;
  720.     RadioItem := ARadioItem;
  721.     GroupIndex := AGroupIndex;
  722.     ShortCut := AShortCut;
  723.     OnClick := AHandler;
  724.     Tag := FPopupMenuTag;
  725.     inc(FPopupMenuTag);
  726.   end;
  727. end;  { SetupMenuItem }
  728.  
  729. procedure TToolbarComboBox.CreatePopupMenuItems;
  730. begin
  731.   FEmbeddedMenu := TPopupMenu.Create(Self);
  732.   PopupMenu := FEmbeddedMenu;
  733.   { CDK: If you want to attach this popup menu to a subcomponent owned by TToolbarComboBox, specify it here (e.g., replace the line above with "MySubComp1.PopupMenu := PopFile;"). }
  734.   ItmProperties := TMenuItem.Create(FEmbeddedMenu);
  735.   ItmShowAbout := TMenuItem.Create(FEmbeddedMenu);
  736.   {  ItmRemoveItemfromList := TMenuItem.Create(FEmbeddedMenu); }
  737. end;  { CreatePopupMenuItems }
  738.  
  739. procedure TToolbarComboBox.InitializePopupMenuItems;
  740. begin
  741.   FPopupMenuTag := 0;
  742.   SetupMenuItem(ItmProperties, '&Properties', false, false, 0, 0,
  743.                                        ItmPropertiesClickHandler);
  744.   SetupMenuItem(ItmShowAbout, '&Show About', false, false, 0, 0,
  745.                                        ItmShowAboutClickHandler);
  746. {  SetupMenuItem(ItmRemoveItemfromList, '&Remove Item from List', false, false, 0, 0, ItmRemoveItemfromListClickHandler); }
  747. end;  { InitializePopupMenuItems }
  748.  
  749. procedure TToolbarComboBox.AddMenuItemsToPopupMenu;
  750. begin
  751.   with FEmbeddedMenu do
  752.   begin
  753.     OnPopup := PopupEmbeddedMenuHandler;
  754.     { Add menu items in the order they should appear in the popup menu: }
  755.     Items.Add(ItmProperties);
  756.     Items.Add(ItmShowAbout);
  757.   end;
  758. end;  { AddMenuItemsToPopupMenu }
  759.  
  760. procedure TToolbarComboBox.PopupEmbeddedMenuHandler(Sender: TObject);
  761. { Handles the FEmbeddedMenu OnPopup event. }
  762. begin
  763.   { CDK: Place your event handler code here. }
  764. end;  { PopupEmbeddedMenuHandler }
  765.  
  766. procedure TToolbarComboBox.EnableAllMenuSettings(TheMenuSettings : BoolArray);
  767. var
  768.   j : integer;
  769. begin
  770.   for j := 0 to 4 do    { Iterate }
  771.     TheMenuSettings[j] := true;
  772. end;
  773.  
  774. procedure TToolbarComboBox.ItmPropertiesClickHandler(Sender: TObject);
  775. var
  776.   ProjIDPropDlg: TProjectIdentifiersProperties;
  777.   CurrentMenuSettings : BoolArray;
  778. begin
  779.   CurrentMenuSettings := MenuSettings;
  780.   ProjIDPropDlg := TProjectIdentifiersProperties.Create(Nil);
  781.   try
  782.     if ProjIDPropDlg.Execute(MenuSettings, ProjID_Preference) then
  783.        UpdateProjIDSettings(MenuSettings, CurrentMenuSettings,
  784.           ProjID_Preference);
  785.   finally { wrap up }
  786.     ProjIDPropDlg.Free;
  787.   end;    { try/finally }
  788. end;  { ItmPropertiesClickHandler }
  789.  
  790. procedure TToolbarComboBox.ItmShowAboutClickHandler(Sender: TObject);
  791. begin
  792.    AboutBox := TAboutBox.Create(Self);
  793.    try
  794.    AboutBox.ShowModal;
  795.    finally
  796.    AboutBox.Free;
  797.    end;
  798. end;
  799.  
  800. destructor TToolbarComboBox.Destroy;
  801. begin
  802.   { CDK: Free allocated memory and created objects here. }
  803.   inherited Destroy;
  804. end;  { Destroy }
  805.  
  806. constructor TToolbarComboBox.Create(AOwner: TComponent);
  807. { Creates an object of type TToolbarComboBox, and initializes properties. }
  808. begin
  809.   inherited Create(AOwner);
  810.   CreatePopupMenuItems;
  811.   InitializePopupMenuItems;
  812.   AddMenuItemsToPopupMenu;
  813.   { CDK: Add your initialization code here. }
  814. end;  { Create }
  815.  
  816.  
  817. initialization
  818.  
  819. finalization
  820.   if assigned(CodeRush) then
  821.      CodeRush.DestroyInterfaces(TProjectIdentifiersPlugIn);
  822. end.
  823.