WizMain.pas
//---------------------------------------------------------------------------
// This software is Copyright (c) 2011 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of Delphi, C++Builder or RAD Studio (Embarcadero Products).
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.
//---------------------------------------------------------------------------
unit WizMain;
interface
uses
SysUtils, ToolsApi;
type
EActionServices = class(Exception);
TActionServices = class(TNotifierObject, IOTAWizard, IOTAMenuWizard)
private
FIndex: Integer;
procedure SetIndex(const Value: Integer);
public
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
function GetMenuText: string;
property Index: Integer read FIndex write SetIndex;
end;
implementation
uses
FrmMain;
var
ActionServices: TActionServices;
resourcestring
sActionError = 'Error creating ActionServices wizard';
{ TActionServices }
procedure TActionServices.Execute;
begin
if Form2 = nil then
Form2 := TForm2.Create(nil);
Form2.Show;
end;
function TActionServices.GetIDString: string;
begin
Result := 'Borland.ActionServices.Demo.1'; { do not localize }
end;
function TActionServices.GetMenuText: string;
resourcestring
sMenuText = 'Test Action Services';
begin
Result := sMenuText;
end;
function TActionServices.GetName: string;
begin
Result := 'Borland.ActionServices.Demo'; { do not localize }
end;
function TActionServices.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
procedure InitActionServices;
begin
if (BorlandIDEServices <> nil) then
begin
ActionServices := TActionServices.Create;
ActionServices.Index := (BorlandIDEServices as IOTAWizardServices).AddWizard(ActionServices as IOTAWizard);
if ActionServices.Index < 0 then
raise EActionServices.Create(sActionError);
end;
end;
procedure DoneActionServices;
begin
if (BorlandIDEServices <> nil) then
begin
if Form2 <> nil then
Form2.Free;
(BorlandIDEServices as IOTAWizardServices).RemoveWizard(ActionServices.Index);
end;
end;
procedure TActionServices.SetIndex(const Value: Integer);
begin
FIndex := Value;
end;
initialization
InitActionServices;
finalization
DoneActionServices;
end.
FrmMain.pas
//---------------------------------------------------------------------------
// This software is Copyright (c) 2011 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of Delphi, C++Builder or RAD Studio (Embarcadero Products).
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.
//---------------------------------------------------------------------------
unit FrmMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ToolsAPI,
StdCtrls, ComCtrls, ToolWin, ImgList;
type
TForm2 = class(TForm)
ListBox1: TListBox;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ImageList1: TImageList;
ToolButton5: TToolButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
private
{ Private declarations }
procedure UpdateFileNames;
public
{ Public declarations }
end;
var
Form2: TForm2 = nil;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Form2 := nil;
end;
procedure TForm2.ToolButton1Click(Sender: TObject);
begin
with TOpenDialog.Create(nil) do
begin
Filter := 'Delphi files|*.bpg;*.dpr;*.dpk;*.pas|All files (*.*)|*.*';
if Execute then
begin
(BorlandIDEServices as IOTAActionServices).OpenFile(FileName);
UpdateFileNames;
end;
Free;
end;
end;
procedure TForm2.ToolButton2Click(Sender: TObject);
begin
(BorlandIDEServices as IOTAActionServices).CloseFile(ListBox1.Items[ListBox1.ItemIndex]);
UpdateFileNames;
end;
procedure TForm2.ToolButton3Click(Sender: TObject);
begin
(BorlandIDEServices as IOTAActionServices).SaveFile(ListBox1.Items[ListBox1.ItemIndex]);
UpdateFileNames;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
UpdateFileNames;
end;
procedure TForm2.UpdateFileNames;
var
Count: Integer;
i: Integer;
begin
ListBox1.Items.Clear;
Count := (BorlandIDEServices as IOTAModuleServices).ModuleCount;
for i := 0 to Count-1 do
ListBox1.Items.Add((BorlandIDEServices as IOTAModuleServices).Modules[i].FileName);
ListBox1.ItemIndex := 0;
end;
procedure TForm2.ToolButton4Click(Sender: TObject);
begin
(BorlandIDEServices as IOTAActionServices).ReloadFile(ListBox1.Items[ListBox1.ItemIndex]);
UpdateFileNames;
end;
procedure TForm2.ToolButton5Click(Sender: TObject);
resourcestring
sNewGroup = 'Create a new group?';
var
NewGroup: Boolean;
begin
NewGroup := False;
with TOpenDialog.Create(nil) do
begin
Filter := 'Delphi project files|*.bpg;*.dpr;*.dpk|All files (*.*)|*.*';
if Execute then
begin
if MessageDlg(sNewGroup, mtInformation, [mbYes, mbNo], 0) = mrYes then
NewGroup := True;
(BorlandIDEServices as IOTAActionServices).OpenProject(FileName, NewGroup);
UpdateFileNames;
end;
end;
end;
procedure TForm2.ListBox1DblClick(Sender: TObject);
begin
(BorlandIDEServices as IOTAActionServices).OpenFile(ListBox1.Items[ListBox1.ItemIndex]);
UpdateFileNames;
end;
end.