1
0
mirror of synced 2024-11-22 11:23:50 +00:00

Fixed: edit box didn't resize properly

Fixed: Issue #122
Fixed: Issue #123 (yet to test on Delphi 7)
Fixed: Issue #124
Fixed: Issue #125
This commit is contained in:
Mark van Renswoude 2006-01-06 20:39:08 +00:00
parent 8637a2f146
commit 985c45ca96
7 changed files with 208 additions and 69 deletions

View File

@ -121,7 +121,7 @@
<Directories> <Directories>
<Directories Name="OutputDir"></Directories> <Directories Name="OutputDir"></Directories>
<Directories Name="UnitOutputDir"></Directories> <Directories Name="UnitOutputDir"></Directories>
<Directories Name="PackageDLLOutputDir"></Directories> <Directories Name="PackageDLLOutputDir">..\..\Lib\D2006</Directories>
<Directories Name="PackageDCPOutputDir"></Directories> <Directories Name="PackageDCPOutputDir"></Directories>
<Directories Name="SearchPath"></Directories> <Directories Name="SearchPath"></Directories>
<Directories Name="Packages"></Directories> <Directories Name="Packages"></Directories>

View File

@ -31,7 +31,7 @@
-M -M
-$M16384,1048576 -$M16384,1048576
-K$00400000 -K$00400000
-LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" -LE"..\..\Lib\D2006"
-LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" -LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl"
-Z -Z
-w-UNSAFE_TYPE -w-UNSAFE_TYPE

View File

@ -1,12 +1,7 @@
{$ASSERTIONS ON} {$ASSERTIONS ON}
unit UnSwClient; unit UnSwClient;
// Since Delphi 7 is the lowest supported version at this point, assume {$I UnSwDefines.inc}
// all other versions support the IOTAModuleServices.GetActiveProject method...
{$UNDEF PROJWORKAROUND}
{$IFDEF VER150}
{$DEFINE PROJWORKAROUND}
{$ENDIF}
interface interface
implementation implementation
@ -29,7 +24,9 @@ type
FViewFormAction: TContainedAction; FViewFormAction: TContainedAction;
protected protected
function ActiveFileName(): String; function ActiveFileName(): String;
{$IFDEF DELPHI7}
function ActiveGroup(): IOTAProjectGroup; function ActiveGroup(): IOTAProjectGroup;
{$ENDIF}
function ActiveProject(): IOTAProject; function ActiveProject(): IOTAProject;
procedure NewExecute(Sender: TObject); virtual; procedure NewExecute(Sender: TObject); virtual;
@ -55,9 +52,11 @@ begin
Assert(Supports(BorlandIDEServices, IOTAModuleServices), Assert(Supports(BorlandIDEServices, IOTAModuleServices),
'BorlandIDEServices does not support the ' + 'BorlandIDEServices does not support the ' +
'IOTAModuleServices interface.'); 'IOTAModuleServices interface.');
{$IFDEF DELPHI7}
Assert(Supports(BorlandIDEServices, IOTAActionServices), Assert(Supports(BorlandIDEServices, IOTAActionServices),
'BorlandIDEServices does not support the ' + 'BorlandIDEServices does not support the ' +
'IOTAActionServices interface.'); 'IOTAActionServices interface.');
{$ENDIF}
for iAction := 0 to Pred(ifNTA.ActionList.ActionCount) do for iAction := 0 to Pred(ifNTA.ActionList.ActionCount) do
begin begin
@ -111,6 +110,7 @@ begin
end; end;
end; end;
{$IFDEF DELPHI7}
function TUnitSwitcherHook.ActiveGroup(): IOTAProjectGroup; function TUnitSwitcherHook.ActiveGroup(): IOTAProjectGroup;
var var
ifModule: IOTAModule; ifModule: IOTAModule;
@ -127,9 +127,10 @@ begin
break; break;
end; end;
end; end;
{$ENDIF}
function TUnitSwitcherHook.ActiveProject(): IOTAProject; function TUnitSwitcherHook.ActiveProject(): IOTAProject;
{$IFDEF PROJWORKAROUND} {$IFDEF DELPHI7}
var var
ifGroup: IOTAProjectGroup; ifGroup: IOTAProjectGroup;
ifModule: IOTAModule; ifModule: IOTAModule;
@ -138,7 +139,7 @@ var
{$ENDIF} {$ENDIF}
begin begin
{$IFDEF PROJWORKAROUND} {$IFDEF DELPHI7}
Result := nil; Result := nil;
ifGroup := ActiveGroup(); ifGroup := ActiveGroup();
if not Assigned(ifGroup) then if not Assigned(ifGroup) then

7
Source/UnSwDefines.inc Normal file
View File

@ -0,0 +1,7 @@
// Lowest supported version is Delphi 7. It lacks some OTA functionality
// in comparison to Delphi 2006. Note that UnitSwitcher has not been tested
// on any other Delphi version!
{$UNDEF DELPHI7}
{$IFDEF VER150}
{$DEFINE DELPHI7}
{$ENDIF}

View File

@ -1,11 +1,13 @@
object frmUnSwDialog: TfrmUnSwDialog object frmUnSwDialog: TfrmUnSwDialog
Left = 187 Left = 187
Top = 83 Top = 83
Width = 307
Height = 454
BorderIcons = [biSystemMenu] BorderIcons = [biSystemMenu]
Caption = 'UnitSwitcher - it almosts makes coffee.' Caption = 'UnitSwitcher'
ClientHeight = 400
ClientWidth = 320
Color = clBtnFace Color = clBtnFace
Constraints.MinHeight = 240
Constraints.MinWidth = 172
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText Font.Color = clWindowText
Font.Height = -11 Font.Height = -11
@ -17,67 +19,81 @@ object frmUnSwDialog: TfrmUnSwDialog
TextHeight = 13 TextHeight = 13
object sbStatus: TStatusBar object sbStatus: TStatusBar
Left = 0 Left = 0
Top = 408 Top = 381
Width = 299 Width = 320
Height = 19 Height = 19
Panels = < Panels = <
item item
Width = 50 Width = 50
end> end>
ExplicitTop = 408
ExplicitWidth = 299
end end
object pnlMain: TPanel object pnlMain: TPanel
Left = 0 Left = 0
Top = 0 Top = 0
Width = 299 Width = 320
Height = 317 Height = 290
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
BorderWidth = 4 BorderWidth = 4
TabOrder = 0 TabOrder = 0
ExplicitWidth = 299
ExplicitHeight = 317
object pnlSearch: TPanel object pnlSearch: TPanel
Left = 4 Left = 4
Top = 4 Top = 4
Width = 291 Width = 312
Height = 25 Height = 25
Align = alTop Align = alTop
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 0 TabOrder = 0
ExplicitWidth = 291
DesignSize = (
312
25)
object edtSearch: TEdit object edtSearch: TEdit
Left = 0 Left = 0
Top = 0 Top = 0
Width = 291 Width = 312
Height = 21 Height = 21
Anchors = [akLeft, akTop, akRight]
TabOrder = 0 TabOrder = 0
OnChange = edtSearchChange OnChange = edtSearchChange
OnKeyDown = edtSearchKeyDown OnKeyDown = edtSearchKeyDown
ExplicitWidth = 291
end end
end end
object lstUnits: TListBox object lstUnits: TListBox
Left = 4 Left = 4
Top = 29 Top = 29
Width = 291 Width = 312
Height = 284 Height = 257
Style = lbVirtualOwnerDraw Style = lbVirtualOwnerDraw
Align = alClient Align = alClient
ItemHeight = 20 ItemHeight = 20
TabOrder = 1 TabOrder = 1
OnData = lstUnitsData OnData = lstUnitsData
OnDrawItem = lstUnitsDrawItem OnDrawItem = lstUnitsDrawItem
ExplicitWidth = 291
ExplicitHeight = 284
end end
end end
object pnlButtons: TPanel object pnlButtons: TPanel
Left = 0 Left = 0
Top = 372 Top = 345
Width = 299 Width = 320
Height = 36 Height = 36
Align = alBottom Align = alBottom
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 2 TabOrder = 2
ExplicitTop = 372
ExplicitWidth = 299
DesignSize = ( DesignSize = (
299 320
36) 36)
object btnCancel: TButton object btnCancel: TButton
Left = 220 Left = 241
Top = 5 Top = 5
Width = 75 Width = 75
Height = 25 Height = 25
@ -86,9 +102,10 @@ object frmUnSwDialog: TfrmUnSwDialog
Caption = 'Cancel' Caption = 'Cancel'
ModalResult = 2 ModalResult = 2
TabOrder = 1 TabOrder = 1
ExplicitLeft = 220
end end
object btnOK: TButton object btnOK: TButton
Left = 139 Left = 160
Top = 5 Top = 5
Width = 75 Width = 75
Height = 25 Height = 25
@ -97,16 +114,19 @@ object frmUnSwDialog: TfrmUnSwDialog
Default = True Default = True
ModalResult = 1 ModalResult = 1
TabOrder = 0 TabOrder = 0
ExplicitLeft = 139
end end
end end
object pnlIncludeTypes: TPanel object pnlIncludeTypes: TPanel
Left = 0 Left = 0
Top = 317 Top = 290
Width = 299 Width = 320
Height = 55 Height = 55
Align = alBottom Align = alBottom
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 1 TabOrder = 1
ExplicitTop = 317
ExplicitWidth = 299
object chkDataModules: TCheckBox object chkDataModules: TCheckBox
Left = 4 Left = 4
Top = 19 Top = 19

View File

@ -1,7 +1,5 @@
unit UnSwDialog; unit UnSwDialog;
// #ToDo1 Store dialog settings
interface interface
uses uses
Classes, Classes,
@ -66,6 +64,9 @@ type
procedure UpdateList(); procedure UpdateList();
function GetActiveUnit(): TUnSwUnit; function GetActiveUnit(): TUnSwUnit;
procedure LoadSettings();
procedure SaveSettings();
public public
class function Execute(const AUnits: TUnSwUnitList; class function Execute(const AUnits: TUnSwUnitList;
const AFormsOnly: Boolean; const AFormsOnly: Boolean;
@ -74,9 +75,9 @@ type
implementation implementation
uses uses
DIalogs, Graphics,
SysUtils, Messages,
Graphics; SysUtils;
{$R *.dfm} {$R *.dfm}
@ -124,7 +125,6 @@ end;
function TfrmUnSwDialog.InternalExecute(): TUnSwUnit; function TfrmUnSwDialog.InternalExecute(): TUnSwUnit;
begin begin
Result := nil; Result := nil;
FTypeFilteredList := TUnSwUnitList.Create(); FTypeFilteredList := TUnSwUnitList.Create();
FInputFilteredList := TUnSwUnitList.Create(); FInputFilteredList := TUnSwUnitList.Create();
FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList); FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList);
@ -134,17 +134,9 @@ begin
else else
FInputFilter := TUnSwUnitSimpleNameFilter.Create(FInputFilteredList); FInputFilter := TUnSwUnitSimpleNameFilter.Create(FInputFilteredList);
try try
if not FFormsOnly then LoadSettings();
begin
FLoading := True; if FFormsOnly then
try
chkForms.Checked := FTypeFilter.IncludeForms;
chkDataModules.Checked := FTypeFilter.IncludeDataModules;
chkProjectSource.Checked := FTypeFilter.IncludeProjectSource;
finally
FLoading := False;
end;
end else
pnlIncludeTypes.Visible := False; pnlIncludeTypes.Visible := False;
UpdateTypeFilter(); UpdateTypeFilter();
@ -153,6 +145,8 @@ begin
try try
if Self.ShowModal() = mrOk then if Self.ShowModal() = mrOk then
Result := GetActiveUnit(); Result := GetActiveUnit();
SaveSettings();
finally finally
FreeAndNil(FIconVisitor); FreeAndNil(FIconVisitor);
end; end;
@ -209,6 +203,94 @@ begin
FActiveUnit := nil; FActiveUnit := nil;
end; end;
procedure TfrmUnSwDialog.LoadSettings();
var
pSettings: TUnSwRegistry;
function ReadBoolDef(const AName: String; const ADefault: Boolean): Boolean;
begin
if pSettings.ValueExists(AName) then
Result := pSettings.ReadBool(AName)
else
Result := ADefault;
end;
function ReadIntegerDef(const AName: String; const ADefault: Integer): Integer;
begin
if pSettings.ValueExists(AName) then
Result := pSettings.ReadInteger(AName)
else
Result := ADefault;
end;
var
sKey: String;
begin
pSettings := TUnSwRegistry.Create();
with pSettings do
try
FLoading := True;
RootKey := HKEY_CURRENT_USER;
if OpenIDEKey() then
begin
chkForms.Checked := ReadBoolDef('IncludeForms', FTypeFilter.IncludeForms);
chkDataModules.Checked := ReadBoolDef('IncludeDataModules', FTypeFilter.IncludeDataModules);
chkProjectSource.Checked := ReadBoolDef('IncludeProjectSource', FTypeFilter.IncludeProjectSource);
if FFormsOnly then
sKey := 'Forms'
else
sKey := 'Units';
Self.ClientWidth := ReadIntegerDef(sKey + 'DialogWidth', Self.ClientWidth);
Self.ClientHeight := ReadIntegerDef(sKey + 'DialogHeight', Self.ClientHeight);
Self.Caption := 'UnitSwitcher - View ' + sKey;
CloseKey();
end;
finally
FLoading := False;
FreeAndNil(pSettings);
end;
end;
procedure TfrmUnSwDialog.SaveSettings();
var
sKey: String;
begin
with TUnSwRegistry.Create() do
try
FLoading := True;
RootKey := HKEY_CURRENT_USER;
if OpenIDEKey() then
begin
WriteBool('IncludeForms', chkForms.Checked);
WriteBool('IncludeDataModules', chkDataModules.Checked);
WriteBool('IncludeProjectSource', chkProjectSource.Checked);
if FFormsOnly then
sKey := 'Forms'
else
sKey := 'Units';
WriteInteger(sKey + 'DialogWidth', Self.ClientWidth);
WriteInteger(sKey + 'DialogHeight', Self.ClientHeight);
CloseKey();
end;
finally
FLoading := False;
Free();
end;
end;
procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject); procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject);
begin begin
FInputFilter.Filter := edtSearch.Text; FInputFilter.Filter := edtSearch.Text;
@ -218,23 +300,8 @@ end;
procedure TfrmUnSwDialog.edtSearchKeyDown(Sender: TObject; var Key: Word; procedure TfrmUnSwDialog.edtSearchKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
begin begin
if Shift = [] then if (Shift = []) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT]) then
case Key of lstUnits.Perform(WM_KEYDOWN, Key, 0);
VK_UP:
begin
if lstUnits.ItemIndex > 0 then
lstUnits.ItemIndex := Pred(lstUnits.ItemIndex);
Key := 0;
end;
VK_DOWN:
begin
if lstUnits.ItemIndex < Pred(lstUnits.Items.Count) then
lstUnits.ItemIndex := Succ(lstUnits.ItemIndex);
Key := 0;
end;
end;
end; end;
procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject); procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject);

View File

@ -1,9 +1,12 @@
unit UnSwObjects; unit UnSwObjects;
{$I UnSwDefines.inc}
interface interface
uses uses
Classes, Classes,
Contnrs, Contnrs,
Registry,
ToolsAPI; ToolsAPI;
type type
@ -39,7 +42,7 @@ type
function GetName(): String; virtual; function GetName(): String; virtual;
function GetFileName(): String; virtual; function GetFileName(): String; virtual;
procedure OpenFile(const AFileName: String; const ASource: Boolean); virtual; procedure OpenModule(const AModule: IOTAModule; const ASource: Boolean); virtual;
public public
// IUnSwVisited // IUnSwVisited
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); virtual; abstract; procedure AcceptVisitor(const AVisitor: IUnSwVisitor); virtual; abstract;
@ -130,6 +133,11 @@ type
write SetItem; default; write SetItem; default;
end; end;
TUnSwRegistry = class(TRegistry)
public
function OpenIDEKey(): Boolean;
end;
implementation implementation
uses uses
SysUtils; SysUtils;
@ -167,10 +175,36 @@ begin
end; end;
procedure TUnSwUnit.OpenFile(const AFileName: String; const ASource: Boolean); procedure TUnSwUnit.OpenModule(const AModule: IOTAModule; const ASource: Boolean);
{$IFDEF DELPHI7}
var
ifEditor: IOTAEditor;
iModule: Integer;
{$ENDIF}
begin begin
(BorlandIDEServices as IOTAActionServices).OpenFile(AFileName); {$IFDEF DELPHI7}
// #ToDo1 (MvR) 6-1-2006: show source for forms for iModule := 0 to Pred(AModule.ModuleFileCount) do
if Supports(AModule.ModuleFileEditors[iModule], IOTAFormEditor,
ifEditor) then
begin
if not ASource then
begin
ifEditor.Show();
break;
end;
end else
if ASource then
begin
ifEditor.Show();
break;
end;
{$ELSE}
if ASource then
AModule.ShowFilename(AModule.FileName)
else
AModule.Show();
{$ENDIF}
end; end;
@ -189,7 +223,7 @@ var
begin begin
ifModule := FModule.OpenModule(); ifModule := FModule.OpenModule();
if Assigned(ifModule) then if Assigned(ifModule) then
OpenFile(ifModule.FileName, ASource); OpenModule(ifModule, ASource);
end; end;
procedure TUnSwModuleUnit.AcceptVisitor(const AVisitor: IUnSwVisitor); procedure TUnSwModuleUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
@ -217,7 +251,9 @@ begin
Result := TUnSwUnitType(FModule.ModuleType); Result := TUnSwUnitType(FModule.ModuleType);
if Result = swutForm then if Result = swutForm then
if Length(FModule.FormName) = 0 then if SameText(FModule.DesignClass, 'TDataModule') then
Result := swutDataModule
else if Length(FModule.FormName) = 0 then
if Length(FModule.FileName) = 0 then if Length(FModule.FileName) = 0 then
Result := swutProjUnit Result := swutProjUnit
else else
@ -235,7 +271,7 @@ end;
procedure TUnSwProjectUnit.Activate(const ASource: Boolean); procedure TUnSwProjectUnit.Activate(const ASource: Boolean);
begin begin
OpenFile(FProject.FileName, ASource); OpenModule(FProject, False);
end; end;
procedure TUnSwProjectUnit.AcceptVisitor(const AVisitor: IUnSwVisitor); procedure TUnSwProjectUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
@ -350,4 +386,12 @@ begin
FItems[Index] := Value; FItems[Index] := Value;
end; end;
{ TUnSwRegistry }
function TUnSwRegistry.OpenIDEKey(): Boolean;
begin
Result := OpenKey((BorlandIDEServices as IOTAServices).GetBaseRegistryKey() +
'\UnitSwitcher', True);
end;
end. end.