home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 March
/
Chip_1999-03_cd.bin
/
zkuste
/
delphi
/
INFO
/
DI9806FN.ZIP
/
source
/
ProjId.pas
< prev
Wrap
Pascal/Delphi Source File
|
1998-04-09
|
30KB
|
823 lines
unit ProjId;
{ This file is based on the standard CodeRush plug-in template. It allows
you to add Project/Unit specific Identifiers to a string list and easily
paste them into your program at the current caret location }
interface
uses
Windows,
Classes,
RushIntf,
Controls,
Forms,
Dialogs,
Graphics,
Menus,
StdCtrls,
Extctrls,
ToolIntf,
PrjID_LB,
PIAbout,
PrIDCnfg;
type
ConfigInfo = record
cfgMenuSettings : BoolArray;
cfgProjID_Preference : ProjID_Preferences;
end;
// Special ComboBox with popup menu added to toolbar
TToolbarComboBox = class(TComboBox)
private
{ Private declarations }
FEmbeddedMenu: TPopupMenu;
ItmProperties: TMenuItem;
ItmShowAbout: TMenuItem;
protected
{ Protected declarations }
FPopupMenuTag: integer;
procedure SetupMenuItem(AMenuItem: TMenuItem; ACaption: string; AChecked,
ARadioItem: boolean; AGroupIndex, AShortCut: integer;
AHandler: TNotifyEvent); dynamic;
procedure CreatePopupMenuItems; dynamic;
procedure InitializePopupMenuItems; dynamic;
procedure AddMenuItemsToPopupMenu; dynamic;
{ Event handlers and transfer methods for FEmbeddedMenu. }
procedure PopupEmbeddedMenuHandler(Sender: TObject); dynamic;
procedure ItmPropertiesClickHandler(Sender: TObject); dynamic;
procedure ItmShowAboutClickHandler(Sender: TObject); dynamic;
public
{ Public declarations }
procedure EnableAllMenuSettings(TheMenuSettings : BoolArray);
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published properties and events }
end; { TToolbarComboBox }
TProjectIdentifiersPlugIn = class(TAbstractRushInterface)
JustSelectedNewFile,
UseGlobalFile,
IdentifiersLoaded : boolean;
ListOfIdentifiers : TStringList;
CurrentProjectName : string; // stores current project
CurrentFileName : string; // stores current unit
// General Code Rush methods
function GetName: string; override;
function GetRequestedString(functionName, parameters: string;
var requestedStr: string): boolean; override;
procedure HandleCommand(command, parameters: string); override;
// Methods to Implement Functionality of PlugIn
procedure AddWordToIDList;
procedure FocusToProjIDComboBox;
procedure ProjIdentifiersComboBoxDropDown(Sender : TObject);
procedure ProjIdentifiersComboBoxKeyDown(Sender : TObject;
var Key: Word; Shift: TShiftState);
procedure ProjIdentifiersComboBoxDoubleClick(Sender : TObject);
procedure ToggleProjIDFile;
procedure SaveProjID(AFileName : string);
procedure SaveProjIDToFile;
procedure OpenProjID(AFileName : string);
procedure OpenProjIDFromFile;
procedure RemoveWordFromIDList(StringToDelete : String);
// Method to add support info to CodeRush About Box
function GetRequestedStringList(strListName, parameters: string;
requestedStrList: TStringList): boolean; override;
// Event Enablers
procedure Event_NewFileSelected(newFileName: string); override;
procedure Event_ToolbarCreated(parentToolbar: TCustomPanel); override;
procedure Event_FileNotification (notifyCode: TRushFileNotification;
const fileName: string; var cancel: Boolean); override;
// Menu configuration
procedure GetCurrentMenuSettings(var CurrentMenuSettings : BoolArray);
// Creation/Destruction methods
constructor Create;
destructor Destroy; override;
end; { TProjectIdentifiersPlugIn }
procedure Register;
implementation
uses
SysUtils;
var
MenuSettings : BoolArray;
ProjID_Preference : ProjID_Preferences;
const
// plug-in commands added to the CodeRush
CMD_CopyIdentifier = 'Identifier_Add';
CMD_DeleteIdentifier = 'Identifier_Delete';
CMD_FocusToIdentifierCB = 'Focus_Identifier_List';
CMD_LoadIdentifierFromFile = 'Load_Identifiers';
CMD_SaveIdentifierToFile = 'Save_Identifiers';
CMD_ToggleProjUnit = 'Toggle_Global_Identifiers';
// string functions to get paste Identifier at current caret location
FNC_PasteProjIDString = 'PasteProjIDStr';
FNC_SelectProjIDString = 'SelectProjIDStr';
// Editor Popup menu items
STR_FocusIDMenuItem = 'mnuFocusProjIDPlugIn';
STR_AddProjIDMenuItem = 'mnuAddProjIDPlugIn';
STR_DeleteProjIDMenuItem = 'mnuDeleteProjIDPlugIn';
STR_ProjIdentifiersComboBox = 'Proj_ID_ComboBox';
STR_LoadIdentifierFromFile = 'mnuProjectIDLoadFromFile';
STR_SaveIdentifierFromFile = 'mnuProjectIDSaveToFile';
STR_ProjIdAboutID = 'Proj ID Plugin';
ResourceString
sAddProjIDMenuItem = 'Add Project Identifier to List';
sFocusProjIDMenuItem = 'Focus to Project Identifiers ComboBox';
sDeleteProjIDMenuItem = 'Delete Project Identifier from List';
sLoadProjIDFromFileMenuItem = 'Load Project Identifiers from File';
sSaveProjIDToFileMenuItem = 'Save Project Identifiers to File';
function TProjectIdentifiersPlugIn.GetName: string;
begin
result := 'Alan_C._Moore_ProjectIdentifiersPlugIn';
end; { GetName }
function TProjectIdentifiersPlugIn.GetRequestedString(
functionName, parameters: string; var requestedStr: string): boolean;
var
localComboBox : TToolbarComboBox;
localDialog : TSelectIdentifierDlg;
begin
result := True;
if CompareText(functionName, FNC_PasteProjIDString) = 0 then
begin
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl(
STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
begin
CodeRush.PutUpTransientMessage
('Current Project Identifier will be inserted', 1);
localComboBox.SetFocus;
requestedStr := localComboBox.SelText;
exit;
end;
end
else
if CompareText(functionName, FNC_SelectProjIDString) = 0 then
begin
localDialog := TSelectIdentifierDlg.Create(CodeRush);
try
CodeRush.PutUpTransientMessage
('Select Identifier to Paste into code', 1);
if NOT localDialog.Execute
(requestedStr, ListOfIdentifiers) then requestedStr := '';
finally
localDialog.Free;
end; // try/finally
if requestedStr<>'' then exit;
end // outer begin/end
else
result := False;
end; { GetRequestedString }
procedure TProjectIdentifiersPlugIn.HandleCommand(command, parameters: string);
begin
if CompareText(command, CMD_CopyIdentifier) = 0 then
AddWordToIDList
else if CompareText(command, CMD_FocusToIdentifierCB) = 0 then
FocusToProjIDComboBox
else if CompareText(command, CMD_DeleteIdentifier) = 0 then
RemoveWordFromIDList(CodeRush.GetCurrentWord)
else if CompareText(command, CMD_LoadIdentifierFromFile) = 0 then
OpenProjIDFromFile
else if CompareText(command, CMD_SaveIdentifierToFile) = 0 then
SaveProjIDToFile
else if CompareText(command, CMD_ToggleProjUnit) = 0 then
ToggleProjIDFile;
end; { HandleCommand }
// Configuration Methods
procedure UpdateProjIDSettings(NewMenuSettings, OldMenuSettings : BoolArray;
NewPreferences : ProjID_Preferences);
var
MenuFileName : string;
MenuFile : File of ConfigInfo;
LocalCfgInfo : ConfigInfo;
j: integer;
begin
LocalCfgInfo.cfgMenuSettings := NewMenuSettings;
LocalCfgInfo.cfgProjID_Preference := ProjID_Preference;
for j := 0 to 4 do //Iterate to find which menu settings have changed
begin
if NewMenuSettings[j]<>OldMenuSettings[j] then
with CodeRush do
case j of //
0: if NewMenuSettings[0] then
AddMenuItemToEditor(STR_FocusIDMenuItem, '', 'N2',
sFocusProjIDMenuItem, CMD_FocusToIdentifierCB, 0,
True, True, False)
else RemoveMenuItemFromEditor(STR_FocusIDMenuItem);
1: if MenuSettings[1] then
AddMenuItemToEditor(STR_AddProjIDMenuItem, '', 'N2',
sAddProjIDMenuItem, CMD_CopyIdentifier, 0, True, True, False)
else RemoveMenuItemFromEditor(STR_AddProjIDMenuItem);
2: if MenuSettings[2] then
AddMenuItemToEditor(STR_DeleteProjIDMenuItem, '', 'N2',
sDeleteProjIDMenuItem, CMD_DeleteIdentifier, 0, True, True,
False)
else RemoveMenuItemFromEditor(STR_DeleteProjIDMenuItem);
3: if MenuSettings[3] then
AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
'N2', sLoadProjIDFromFileMenuItem,
CMD_LoadIdentifierFromFile, 0, True, True, False)
else RemoveMenuItemFromEditor(STR_LoadIdentifierFromFile);
4: if MenuSettings[4] then
AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
'N2', sSaveProjIDToFileMenuItem,
CMD_SaveIdentifierToFile, 0, True, True, False)
else RemoveMenuItemFromEditor(STR_SaveIdentifierFromFile);
end; //case
end; //for
CodeRush.PutUpTransientMessage
('Saving Project Identifier Configuration Information...', 1);
MenuFileName := CodeRush.DelphiInstallDirectory + 'bin\ProjID.cfg';
AssignFile(MenuFile, MenuFileName);
Rewrite(MenuFile);
Write(MenuFile, LocalCfgInfo);
CloseFile(MenuFile);
CodeRush.DropTransientMessage;
end;
// Menu configuration
// following procedure no longer used
procedure TProjectIdentifiersPlugIn.GetCurrentMenuSettings
(var CurrentMenuSettings : BoolArray);
var
j : integer;
MenuPath : TMenuItem;
begin
try
MenuPath := nil;
for j := 0 to 4 do { Iterate }
begin
case j of { }
0 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
+STR_FocusIDMenuItem);
1 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
+STR_AddProjIDMenuItem);
2 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
+STR_DeleteProjIDMenuItem);
3 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
+STR_LoadIdentifierFromFile);
4 : MenuPath := CodeRush.MenuPathToMenuItem('EditorLocalMenu|'
+STR_SaveIdentifierFromFile);
end; { case }
if (MenuPath<>Nil) then CurrentMenuSettings[j] := true else
CurrentMenuSettings[j] := false;
end; { for }
except
end;
end;
// Basic Functionality of Plug-in
procedure TProjectIdentifiersPlugIn.AddWordToIDList;
var
localComboBox : TToolbarComboBox;
localCurrentWord : string;
begin
if ExtractFileName(CodeRush.CurrentDelphiFileName)='Unit1' then
raise Exception.Create('First save Unit1 with unique Name');
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
begin
CodeRush.PutUpTransientMessage('Adding Project Identifier to list', 1);
if ((localComboBox.Items.Count=1) and (localComboBox.Items[0]=
'<None Entered>'))
then
begin
localComboBox.Items.Clear;
ListOfIdentifiers.Clear;
end;
localCurrentWord := CodeRush.GetCurrentWord;
if localComboBox.Items.IndexOf(localCurrentWord)>=0 then Exit;
localComboBox.Items.Add(localCurrentWord);
ListOfIdentifiers.Add(localCurrentWord);
localComboBox.Text := localCurrentWord;
IdentifiersLoaded := True;
end;
end;
procedure TProjectIdentifiersPlugIn.FocusToProjIDComboBox;
var
localComboBox : TToolbarComboBox;
begin
If NOT IdentifiersLoaded then exit;
CodeRush.PutUpTransientMessage
('Double Click to paste identifier to code', 1);
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then localComboBox.SetFocus;
end;
procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxDropDown
(Sender : TObject);
var
localComboBox: TToolbarComboBox;
begin
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
localComboBox.Items.Assign(ListOfIdentifiers);
end; { ProjIdentifiersComboBoxDropDown }
procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxKeyDown
(Sender : TObject; var Key: Word; Shift: TShiftState);
begin
case Key of { Key Code }
VK_Return : ProjIdentifiersComboBoxDoubleClick(Sender);
VK_Escape : CodeRush.FocusCodeEditor;
VK_Delete : RemoveWordFromIDList(CodeRush.GetCurrentWord);
end; { case }
end;
procedure TProjectIdentifiersPlugIn.ProjIdentifiersComboBoxDoubleClick
(Sender : TObject);
var
localStringList : TStringList;
begin
If NOT IdentifiersLoaded then exit;
if NOT (Sender IS TToolbarComboBox) then exit;
CodeRush.PutUpTransientMessage('Pasting Project Identifier into code', 1);
localStringList := TStringList.Create;
localStringList.Add(TToolbarComboBox(Sender).SelText);
CodeRush.FocusCodeEditor;
CodeRush.InsertTextAtCursor(localStringList);
localStringList.Free;
end;
procedure TProjectIdentifiersPlugIn.RemoveWordFromIDList
(StringToDelete : String);
var
localComboBox: TToolbarComboBox;
localNdx: Integer;
begin
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
begin
if StringToDelete <> '' then
localNdx := localComboBox.Items.IndexOf(localComboBox.Text) else
localNdx := localComboBox.ItemIndex;
if localNdx >= 0 then
begin
localComboBox.Items.Delete(localNdx);
ListOfIdentifiers.Delete(localNdx);
end
else exit;
localComboBox.Text := ''; // change only if successful delete
end;
end;
// File Routines
procedure TProjectIdentifiersPlugIn.ToggleProjIDFile;
begin
if NOT (ProjID_Preference=idProjAndUnits) then exit;
if UseGlobalFile then
begin
UseGlobalFile := False;
OpenProjID(CodeRush.CurrentDelphiFileName);
end
else
begin
UseGlobalFile := True;
OpenProjID(CurrentProjectName);
end;
end;
procedure TProjectIdentifiersPlugIn.SaveProjID(AFileName : string);
var
TempFilePath,
TempFileName : string;
localComboBox: TToolbarComboBox;
begin
if ExtractFileName(AFileName)='Unit1' then exit;
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
begin
if ((localComboBox.Items.Count=1) and
(localComboBox.Items[0]='<None Entered>')) then exit;
CodeRush.PutUpTransientMessage('Saving Project Identifiers...', 1);
TempFilePath := ExtractFilePath(AFileName);
TempFileName := ExtractFileName(ChangeFileExt(AFileName, '.pji'));
CurrentFileName := TempFilePath+TempFileName;
localComboBox.Items.SaveToFile(CurrentFileName);
CodeRush.DropTransientMessage;
end;
end;
procedure TProjectIdentifiersPlugIn.SaveProjIDToFile;
var
SaveFileDlg : TSaveDialog;
begin
if JustSelectedNewFile then
CodeRush.PutUpTransientMessage('Select File for Project Identifiers', 1);
SaveFileDlg := TSaveDialog.Create(Nil);
try
SaveFileDlg.Filter := 'Proj ID files (*.pji)|*.PJI)';
if SaveFileDlg.Execute then SaveProjID(SaveFileDlg.FileName);
finally { wrap up }
SaveFileDlg.Free;
end; { try/finally }
JustSelectedNewFile := False;
end;
procedure TProjectIdentifiersPlugIn.OpenProjID(AFileName : string);
var
TempFilePath,
TempFileName : string;
localComboBox: TToolbarComboBox;
begin
// if ExtractFileName(AFileName)='Unit1' then exit;
TempFilePath := ExtractFilePath(AFileName);
TempFileName := ExtractFileName
(ChangeFileExt(AFileName, '.pji'));
CurrentFileName := TempFilePath + TempFileName;
localComboBox := TToolbarComboBox(CodeRush.GetToolbarControl
(STR_ProjIdentifiersComboBox));
if assigned(localComboBox) then
begin
if FileExists(CurrentFileName) then
begin
localComboBox.Items.Clear;
localComboBox.Items.LoadFromFile(CurrentFileName);
ListOfIdentifiers.Clear;
ListOfIdentifiers.LoadFromFile(CurrentFileName);
IdentifiersLoaded := True;
end else
begin
localComboBox.Items.Clear;
ListOfIdentifiers.Clear;
localComboBox.Items.Add('<None Entered>');
IdentifiersLoaded := False;
end;
localComboBox.Text := localComboBox.Items[0];
end; { if assigned }
JustSelectedNewFile := False;
end;
procedure TProjectIdentifiersPlugIn.OpenProjIDFromFile;
var
OpenFileDlg : TOpenDialog;
begin
CodeRush.PutUpTransientMessage('Select Project Identifiers File to open', 1);
OpenFileDlg := TOpenDialog.Create(Nil);
try
OpenFileDlg.Filter := 'Proj ID files (*.pji)|*.PJI';
if OpenFileDlg.Execute then OpenProjID(OpenFileDlg.FileName);
finally { wrap up }
OpenFileDlg.Free;
end; { try/finally }
CodeRush.DropTransientMessage;
end;
procedure TProjectIdentifiersPlugIn.Event_FileNotification
(notifyCode: TRushFileNotification;
const fileName: string; var cancel: Boolean);
begin
case notifyCode of { notifyCode }
rfnFileOpening :
if ((ProjID_Preference=idProjOnly) or ((ProjID_Preference=idProjAndUnits)
and (UseGlobalFile))) then exit
else OpenProjID(fileName);
rfnFileClosing :
if ((ProjID_Preference=idProjOnly) or((ProjID_Preference=idProjAndUnits)
and (UseGlobalFile))) then
{ SaveProjID(CurrentProjectName) } exit
else SaveProjID(fileName);
rfnProjectOpening : CurrentProjectName := fileName;
rfnProjectOpened :
if ((ProjID_Preference=idProjOnly) or((ProjID_Preference=idProjAndUnits)
and (UseGlobalFile))) then
OpenProjID(CurrentProjectName) else
OpenProjID(CodeRush.CurrentDelphiFileName);
rfnProjectClosing :
if ((ProjID_Preference=idProjOnly) or ((ProjID_Preference=idProjAndUnits)
and (UseGlobalFile))) then
SaveProjID(CurrentProjectName)
else
SaveProjID(CodeRush.CurrentDelphiFileName);
end; { notifyCode case }
end;
// Method to add support info to CodeRush About Box
function TProjectIdentifiersPlugIn.GetRequestedStringList(strListName, parameters: string;
requestedStrList: TStringList): boolean;
begin
result := False;
if not assigned(requestedStrList) then
exit;
requestedStrList.Clear; // We should clear the list first.
if CompareText(strListName, STR_ProjIdAboutID) = 0 then
begin
requestedStrList.Add
('Project Identifiers Plug In, written by Alan C. Moore');
requestedStrList.Add('');
requestedStrList.Add('Copyright (c) 1998, Alan C. Moore');
requestedStrList.Add('');
requestedStrList.Add('Send feedback to:' +
'|Alan C. Moore|acmdoc@aol.com');
result := True;
exit;
end;
end;
// Event Implementations
procedure TProjectIdentifiersPlugIn.Event_ToolbarCreated(parentToolbar:
TCustomPanel);
var
localComboBox: TToolbarComboBox;
begin
IdentifiersLoaded := False;
localComboBox := TToolbarComboBox.Create(parentToolbar);
CodeRush.AddResizeBarToCustomToolbarControl(localComboBox);
with localComboBox do
begin
Width := 180;
Height := 24;
Name := STR_ProjIdentifiersComboBox;
Items.Add('<None Entered>');
Text := '<None Entered>';
Hint := 'Project Identifiers';
OnDblClick := ProjIdentifiersComboBoxDoubleClick;
OnKeyDown := ProjIdentifiersComboBoxKeyDown;
IdentifiersLoaded := False;
UseGlobalFile := False; // added with CodeRush 3.01V
end;
end; { Event_ToolbarCreated }
procedure TProjectIdentifiersPlugIn.Event_NewFileSelected(newFileName: string);
begin
JustSelectedNewFile := True;
if (ProjID_Preference=idProjOnly) or ((ProjID_Preference= idProjAndUnits)
and (UseGlobalFile)) then
begin
// SaveProjID(CurrentFileName);
OpenProjID(CurrentProjectName);
end
else
begin
SaveProjID(CurrentFileName);
OpenProjID(newFileName);
end;
JustSelectedNewFile := False;
end;
constructor TProjectIdentifiersPlugIn.Create;
begin
inherited Create;
ListOfIdentifiers := TStringList.Create;
ListOfIdentifiers.Add('<None Entered>');
IdentifiersLoaded := False;
UseGlobalFile := False; // Added in CodeRush version 3.01V
end; { Create }
destructor TProjectIdentifiersPlugIn.Destroy;
begin
if assigned(CodeRush) then
with CodeRush do
begin
RemoveMenuItemFromEditor(STR_FocusIDMenuItem);
RemoveMenuItemFromEditor(STR_AddProjIDMenuItem);
RemoveMenuItemFromEditor(STR_DeleteProjIDMenuItem);
RemoveMenuItemFromEditor(STR_LoadIdentifierFromFile);
RemoveMenuItemFromEditor(STR_SaveIdentifierFromFile);
UnRegisterEventHandler(Self, EVC_NewFileSelected);
UnRegisterEventHandler(Self, EVC_ToolbarCreated);
UnRegisterEventHandler(Self, EVC_FileNotification);
ListOfIdentifiers.Free;
end; { with }
inherited Destroy;
end; { Destroy }
procedure Register;
var
ProjectIdentifiersPlugIn : TProjectIdentifiersPlugIn;
MenuFileName : string;
MenuFile : File of ConfigInfo;
ConfigRecord : ConfigInfo;
ProjIDConfigExists : boolean;
begin
ProjID_Preference := idProjOnly;
ProjectIdentifiersPlugIn := TProjectIdentifiersPlugIn.Create;
MenuFileName := CodeRush.DelphiInstallDirectory + 'bin\ProjID.cfg';
if NOT FileExists(MenuFileName) then
ProjIDConfigExists := False else
begin
ProjIDConfigExists := True;
AssignFile(MenuFile, MenuFileName);
try
Reset(MenuFile);
read(MenuFile, ConfigRecord);
except
ProjIDConfigExists := False;
if Application.MessageBox
('Configuration File is old or currupted; Erase?',
'Corrupt Configuration File', MB_OK)=mrOK then
begin
CloseFile(MenuFile);
Erase(MenuFile);
end;
end;
MenuSettings := AssignBoolArray(ConfigRecord.cfgMenuSettings);
ProjID_Preference := ConfigRecord.cfgProjID_Preference;
CloseFile(MenuFile);
end;
with CodeRush do
begin
RegisterInterface(ProjectIdentifiersPlugIn);
RegisterCustomToolbarControl(ProjectIdentifiersPlugIn,
STR_ProjIdentifiersComboBox);
RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_NewFileSelected);
RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_ToolbarCreated);
RegisterEventHandler(ProjectIdentifiersPlugIn, EVC_FileNotification);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_CopyIdentifier);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_DeleteIdentifier);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_FocusToIdentifierCB);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_LoadIdentifierFromFile);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_SaveIdentifierToFile);
RegisterCommand(ProjectIdentifiersPlugIn, CMD_ToggleProjUnit);
// above Added with CodeRush 3.01V
RegisterStringFunction(ProjectIdentifiersPlugIn, FNC_PasteProjIDString);
RegisterStringFunction(ProjectIdentifiersPlugIn, FNC_SelectProjIDString);
RegisterStringListFunction(ProjectIdentifiersPlugIn,
STR_ProjIdAboutID, INT_SupportURLs);
if NOT ProjIDConfigExists then
begin
ProjID_Preference := idProjOnly;
AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
'N2', sLoadProjIDFromFileMenuItem,
CMD_LoadIdentifierFromFile, 0, True, True, False);
AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
STR_LoadIdentifierFromFile, sSaveProjIDToFileMenuItem,
CMD_SaveIdentifierToFile, 0, True, True, False);
MenuSettings[0] := false;
MenuSettings[1] := false;
MenuSettings[2] := false;
MenuSettings[3] := true;
MenuSettings[4] := true;
end
else
begin
if MenuSettings[0] then
AddMenuItemToEditor(STR_FocusIDMenuItem, '', 'N2',
sFocusProjIDMenuItem, CMD_FocusToIdentifierCB, 0,
True, True, False);
if MenuSettings[1] then
AddMenuItemToEditor(STR_AddProjIDMenuItem, '', 'N2',
sAddProjIDMenuItem, CMD_CopyIdentifier, 0, True, True, False);
if MenuSettings[2] then
AddMenuItemToEditor(STR_DeleteProjIDMenuItem, '', 'N2',
sDeleteProjIDMenuItem, CMD_DeleteIdentifier, 0, True, True,
False);
if MenuSettings[3] then
AddMenuItemToEditor(STR_LoadIdentifierFromFile, '',
'N2', sLoadProjIDFromFileMenuItem,
CMD_LoadIdentifierFromFile, 0, True, True, False);
if MenuSettings[4] then
AddMenuItemToEditor(STR_SaveIdentifierFromFile, '',
'N2', sSaveProjIDToFileMenuItem,
CMD_SaveIdentifierToFile, 0, True, True, False);
end;
end; { with }
end; { Register }
// ToolBox ComboBox Methods
procedure TToolbarComboBox.SetupMenuItem(AMenuItem: TMenuItem;
ACaption: string; AChecked, ARadioItem: boolean;
AGroupIndex, AShortCut: integer; AHandler: TNotifyEvent);
begin
with AMenuItem do
begin
Caption := ACaption;
Checked := AChecked;
RadioItem := ARadioItem;
GroupIndex := AGroupIndex;
ShortCut := AShortCut;
OnClick := AHandler;
Tag := FPopupMenuTag;
inc(FPopupMenuTag);
end;
end; { SetupMenuItem }
procedure TToolbarComboBox.CreatePopupMenuItems;
begin
FEmbeddedMenu := TPopupMenu.Create(Self);
PopupMenu := FEmbeddedMenu;
{ 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;"). }
ItmProperties := TMenuItem.Create(FEmbeddedMenu);
ItmShowAbout := TMenuItem.Create(FEmbeddedMenu);
{ ItmRemoveItemfromList := TMenuItem.Create(FEmbeddedMenu); }
end; { CreatePopupMenuItems }
procedure TToolbarComboBox.InitializePopupMenuItems;
begin
FPopupMenuTag := 0;
SetupMenuItem(ItmProperties, '&Properties', false, false, 0, 0,
ItmPropertiesClickHandler);
SetupMenuItem(ItmShowAbout, '&Show About', false, false, 0, 0,
ItmShowAboutClickHandler);
{ SetupMenuItem(ItmRemoveItemfromList, '&Remove Item from List', false, false, 0, 0, ItmRemoveItemfromListClickHandler); }
end; { InitializePopupMenuItems }
procedure TToolbarComboBox.AddMenuItemsToPopupMenu;
begin
with FEmbeddedMenu do
begin
OnPopup := PopupEmbeddedMenuHandler;
{ Add menu items in the order they should appear in the popup menu: }
Items.Add(ItmProperties);
Items.Add(ItmShowAbout);
end;
end; { AddMenuItemsToPopupMenu }
procedure TToolbarComboBox.PopupEmbeddedMenuHandler(Sender: TObject);
{ Handles the FEmbeddedMenu OnPopup event. }
begin
{ CDK: Place your event handler code here. }
end; { PopupEmbeddedMenuHandler }
procedure TToolbarComboBox.EnableAllMenuSettings(TheMenuSettings : BoolArray);
var
j : integer;
begin
for j := 0 to 4 do { Iterate }
TheMenuSettings[j] := true;
end;
procedure TToolbarComboBox.ItmPropertiesClickHandler(Sender: TObject);
var
ProjIDPropDlg: TProjectIdentifiersProperties;
CurrentMenuSettings : BoolArray;
begin
CurrentMenuSettings := MenuSettings;
ProjIDPropDlg := TProjectIdentifiersProperties.Create(Nil);
try
if ProjIDPropDlg.Execute(MenuSettings, ProjID_Preference) then
UpdateProjIDSettings(MenuSettings, CurrentMenuSettings,
ProjID_Preference);
finally { wrap up }
ProjIDPropDlg.Free;
end; { try/finally }
end; { ItmPropertiesClickHandler }
procedure TToolbarComboBox.ItmShowAboutClickHandler(Sender: TObject);
begin
AboutBox := TAboutBox.Create(Self);
try
AboutBox.ShowModal;
finally
AboutBox.Free;
end;
end;
destructor TToolbarComboBox.Destroy;
begin
{ CDK: Free allocated memory and created objects here. }
inherited Destroy;
end; { Destroy }
constructor TToolbarComboBox.Create(AOwner: TComponent);
{ Creates an object of type TToolbarComboBox, and initializes properties. }
begin
inherited Create(AOwner);
CreatePopupMenuItems;
InitializePopupMenuItems;
AddMenuItemsToPopupMenu;
{ CDK: Add your initialization code here. }
end; { Create }
initialization
finalization
if assigned(CodeRush) then
CodeRush.DestroyInterfaces(TProjectIdentifiersPlugIn);
end.