2007-12-07 15:33:00 +00:00
|
|
|
{: Connects ComponentSwitcher to the IDE.
|
|
|
|
|
|
|
|
Last changed: $Date$
|
|
|
|
Revision: $Rev$
|
|
|
|
Author: $Author$
|
|
|
|
}
|
|
|
|
unit CmpSwClient;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
// #ToDo2 (MvR) 9-12-2007: Ctrl activates the designer guidelines in BDS 2006
|
|
|
|
// and up, which get drawn over our dialog. messy.
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
interface
|
|
|
|
uses
|
|
|
|
ActnList,
|
|
|
|
Classes,
|
|
|
|
Dialogs,
|
|
|
|
SysUtils,
|
|
|
|
ToolsAPI,
|
|
|
|
|
|
|
|
BaseSwClient;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
type
|
|
|
|
TComponentSwitcherHook = class(TBaseSwitcherHook)
|
|
|
|
protected
|
|
|
|
function ActiveModule(): IOTAModule;
|
|
|
|
function ActiveEditor(): IOTAEditor;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure NewExecute(Sender: TObject);
|
2007-12-07 15:33:00 +00:00
|
|
|
public
|
|
|
|
constructor Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
2007-12-09 12:02:11 +00:00
|
|
|
uses
|
|
|
|
BaseSwObjects,
|
|
|
|
CmpSwDialog,
|
|
|
|
CmpSwObjects, Windows;
|
2007-12-07 15:33:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ TComponentSwitcherHook}
|
|
|
|
constructor TComponentSwitcherHook.Create();
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
try
|
|
|
|
HookIDEAction('SearchFindCommand', NewExecute);
|
|
|
|
except
|
|
|
|
on E:EAssertionFailed do
|
|
|
|
ShowMessage('Error while loading ComponentSwitcher: ' + E.Message);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TComponentSwitcherHook.ActiveModule(): IOTAModule;
|
|
|
|
begin
|
|
|
|
Result := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TComponentSwitcherHook.ActiveEditor(): IOTAEditor;
|
|
|
|
var
|
|
|
|
module: IOTAModule;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
module := ActiveModule();
|
|
|
|
|
|
|
|
if Assigned(module) then
|
|
|
|
Result := activeModule.CurrentEditor;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
function SortByName(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
Result := CompareText(TCmpSwComponent(Item1).Name, TCmpSwComponent(Item2).Name)
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
procedure TComponentSwitcherHook.NewExecute(Sender: TObject);
|
|
|
|
var
|
2007-12-09 12:02:11 +00:00
|
|
|
editor: IOTAEditor;
|
|
|
|
formEditor: IOTAFormEditor;
|
|
|
|
formComponent: IOTAComponent;
|
|
|
|
componentIndex: Integer;
|
|
|
|
component: IOTAComponent;
|
|
|
|
itemList: TBaseSwItemList;
|
|
|
|
item: TCmpSwComponent;
|
|
|
|
selectedItems: TBaseSwItemList;
|
2007-12-07 15:33:00 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
editor := ActiveEditor();
|
2007-12-09 12:02:11 +00:00
|
|
|
if Assigned(editor) and Supports(editor, IOTAFormEditor, formEditor) then
|
2007-12-07 15:33:00 +00:00
|
|
|
begin
|
2007-12-09 12:02:11 +00:00
|
|
|
formComponent := formEditor.GetRootComponent;
|
|
|
|
itemList := TBaseSwItemList.Create();
|
|
|
|
|
|
|
|
for componentIndex := Pred(formComponent.GetComponentCount) downto 0 do
|
|
|
|
begin
|
|
|
|
component := formComponent.GetComponent(componentIndex);
|
|
|
|
item := TCmpSwComponent.TryCreate(component);
|
|
|
|
|
|
|
|
if Assigned(item) then
|
|
|
|
itemList.Add(item);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if itemList.Count > 0 then
|
|
|
|
begin
|
|
|
|
itemList.Sort(SortByName);
|
|
|
|
|
|
|
|
(*
|
|
|
|
ps := (borlandideservices as IOTAPackageServices);
|
|
|
|
for pi := 0 to Pred(ps.PackageCount) do
|
|
|
|
begin
|
|
|
|
for ci := 0 to Pred(ps.ComponentCount[pi]) do
|
|
|
|
begin
|
|
|
|
itemList.Add(TTestItem.Create(ps.PackageNames[pi] + ' - ' + ps.ComponentNames[pi, ci]));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
*)
|
|
|
|
|
|
|
|
selectedItems := TfrmCmpSwDialog.Execute(itemList);
|
|
|
|
|
|
|
|
if Assigned(selectedItems) then
|
|
|
|
begin
|
|
|
|
for componentIndex := 0 to Pred(selectedItems.Count) do
|
|
|
|
begin
|
|
|
|
item := TCmpSwComponent(selectedItems[componentIndex]);
|
|
|
|
item.Activate(componentIndex = 0);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2007-12-07 15:33:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|