diff --git a/Packages/D2006/UnitSwitcher.bdsproj b/Packages/D2006/UnitSwitcher.bdsproj index ad9c071..3449fc1 100644 --- a/Packages/D2006/UnitSwitcher.bdsproj +++ b/Packages/D2006/UnitSwitcher.bdsproj @@ -121,7 +121,7 @@ - + ..\..\Lib\D2006 diff --git a/Packages/D2006/UnitSwitcher.cfg b/Packages/D2006/UnitSwitcher.cfg index 12d4a5a..78d6549 100644 --- a/Packages/D2006/UnitSwitcher.cfg +++ b/Packages/D2006/UnitSwitcher.cfg @@ -31,7 +31,7 @@ -M -$M16384,1048576 -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" -Z -w-UNSAFE_TYPE diff --git a/Source/UnSwClient.pas b/Source/UnSwClient.pas index a3498dd..621d17e 100644 --- a/Source/UnSwClient.pas +++ b/Source/UnSwClient.pas @@ -1,12 +1,7 @@ {$ASSERTIONS ON} unit UnSwClient; -// Since Delphi 7 is the lowest supported version at this point, assume -// all other versions support the IOTAModuleServices.GetActiveProject method... -{$UNDEF PROJWORKAROUND} -{$IFDEF VER150} - {$DEFINE PROJWORKAROUND} -{$ENDIF} +{$I UnSwDefines.inc} interface implementation @@ -29,7 +24,9 @@ type FViewFormAction: TContainedAction; protected function ActiveFileName(): String; + {$IFDEF DELPHI7} function ActiveGroup(): IOTAProjectGroup; + {$ENDIF} function ActiveProject(): IOTAProject; procedure NewExecute(Sender: TObject); virtual; @@ -55,9 +52,11 @@ begin Assert(Supports(BorlandIDEServices, IOTAModuleServices), 'BorlandIDEServices does not support the ' + 'IOTAModuleServices interface.'); + {$IFDEF DELPHI7} Assert(Supports(BorlandIDEServices, IOTAActionServices), 'BorlandIDEServices does not support the ' + 'IOTAActionServices interface.'); + {$ENDIF} for iAction := 0 to Pred(ifNTA.ActionList.ActionCount) do begin @@ -111,6 +110,7 @@ begin end; end; +{$IFDEF DELPHI7} function TUnitSwitcherHook.ActiveGroup(): IOTAProjectGroup; var ifModule: IOTAModule; @@ -127,9 +127,10 @@ begin break; end; end; +{$ENDIF} function TUnitSwitcherHook.ActiveProject(): IOTAProject; -{$IFDEF PROJWORKAROUND} +{$IFDEF DELPHI7} var ifGroup: IOTAProjectGroup; ifModule: IOTAModule; @@ -138,7 +139,7 @@ var {$ENDIF} begin - {$IFDEF PROJWORKAROUND} + {$IFDEF DELPHI7} Result := nil; ifGroup := ActiveGroup(); if not Assigned(ifGroup) then diff --git a/Source/UnSwDefines.inc b/Source/UnSwDefines.inc new file mode 100644 index 0000000..b1ec7da --- /dev/null +++ b/Source/UnSwDefines.inc @@ -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} diff --git a/Source/UnSwDialog.dfm b/Source/UnSwDialog.dfm index 3ac9572..abc29d2 100644 --- a/Source/UnSwDialog.dfm +++ b/Source/UnSwDialog.dfm @@ -1,11 +1,13 @@ object frmUnSwDialog: TfrmUnSwDialog Left = 187 Top = 83 - Width = 307 - Height = 454 BorderIcons = [biSystemMenu] - Caption = 'UnitSwitcher - it almosts makes coffee.' + Caption = 'UnitSwitcher' + ClientHeight = 400 + ClientWidth = 320 Color = clBtnFace + Constraints.MinHeight = 240 + Constraints.MinWidth = 172 Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 @@ -17,67 +19,81 @@ object frmUnSwDialog: TfrmUnSwDialog TextHeight = 13 object sbStatus: TStatusBar Left = 0 - Top = 408 - Width = 299 + Top = 381 + Width = 320 Height = 19 Panels = < item Width = 50 end> + ExplicitTop = 408 + ExplicitWidth = 299 end object pnlMain: TPanel Left = 0 Top = 0 - Width = 299 - Height = 317 + Width = 320 + Height = 290 Align = alClient BevelOuter = bvNone BorderWidth = 4 TabOrder = 0 + ExplicitWidth = 299 + ExplicitHeight = 317 object pnlSearch: TPanel Left = 4 Top = 4 - Width = 291 + Width = 312 Height = 25 Align = alTop BevelOuter = bvNone TabOrder = 0 + ExplicitWidth = 291 + DesignSize = ( + 312 + 25) object edtSearch: TEdit Left = 0 Top = 0 - Width = 291 + Width = 312 Height = 21 + Anchors = [akLeft, akTop, akRight] TabOrder = 0 OnChange = edtSearchChange OnKeyDown = edtSearchKeyDown + ExplicitWidth = 291 end end object lstUnits: TListBox Left = 4 Top = 29 - Width = 291 - Height = 284 + Width = 312 + Height = 257 Style = lbVirtualOwnerDraw Align = alClient ItemHeight = 20 TabOrder = 1 OnData = lstUnitsData OnDrawItem = lstUnitsDrawItem + ExplicitWidth = 291 + ExplicitHeight = 284 end end object pnlButtons: TPanel Left = 0 - Top = 372 - Width = 299 + Top = 345 + Width = 320 Height = 36 Align = alBottom BevelOuter = bvNone TabOrder = 2 + ExplicitTop = 372 + ExplicitWidth = 299 DesignSize = ( - 299 + 320 36) object btnCancel: TButton - Left = 220 + Left = 241 Top = 5 Width = 75 Height = 25 @@ -86,9 +102,10 @@ object frmUnSwDialog: TfrmUnSwDialog Caption = 'Cancel' ModalResult = 2 TabOrder = 1 + ExplicitLeft = 220 end object btnOK: TButton - Left = 139 + Left = 160 Top = 5 Width = 75 Height = 25 @@ -97,16 +114,19 @@ object frmUnSwDialog: TfrmUnSwDialog Default = True ModalResult = 1 TabOrder = 0 + ExplicitLeft = 139 end end object pnlIncludeTypes: TPanel Left = 0 - Top = 317 - Width = 299 + Top = 290 + Width = 320 Height = 55 Align = alBottom BevelOuter = bvNone TabOrder = 1 + ExplicitTop = 317 + ExplicitWidth = 299 object chkDataModules: TCheckBox Left = 4 Top = 19 diff --git a/Source/UnSwDialog.pas b/Source/UnSwDialog.pas index 9767497..1a97783 100644 --- a/Source/UnSwDialog.pas +++ b/Source/UnSwDialog.pas @@ -1,7 +1,5 @@ unit UnSwDialog; -// #ToDo1 Store dialog settings - interface uses Classes, @@ -66,6 +64,9 @@ type procedure UpdateList(); function GetActiveUnit(): TUnSwUnit; + + procedure LoadSettings(); + procedure SaveSettings(); public class function Execute(const AUnits: TUnSwUnitList; const AFormsOnly: Boolean; @@ -74,9 +75,9 @@ type implementation uses - DIalogs, - SysUtils, - Graphics; + Graphics, + Messages, + SysUtils; {$R *.dfm} @@ -124,7 +125,6 @@ end; function TfrmUnSwDialog.InternalExecute(): TUnSwUnit; begin Result := nil; - FTypeFilteredList := TUnSwUnitList.Create(); FInputFilteredList := TUnSwUnitList.Create(); FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList); @@ -134,17 +134,9 @@ begin else FInputFilter := TUnSwUnitSimpleNameFilter.Create(FInputFilteredList); try - if not FFormsOnly then - begin - FLoading := True; - try - chkForms.Checked := FTypeFilter.IncludeForms; - chkDataModules.Checked := FTypeFilter.IncludeDataModules; - chkProjectSource.Checked := FTypeFilter.IncludeProjectSource; - finally - FLoading := False; - end; - end else + LoadSettings(); + + if FFormsOnly then pnlIncludeTypes.Visible := False; UpdateTypeFilter(); @@ -153,6 +145,8 @@ begin try if Self.ShowModal() = mrOk then Result := GetActiveUnit(); + + SaveSettings(); finally FreeAndNil(FIconVisitor); end; @@ -209,6 +203,94 @@ begin FActiveUnit := nil; 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); begin FInputFilter.Filter := edtSearch.Text; @@ -218,23 +300,8 @@ end; procedure TfrmUnSwDialog.edtSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin - if Shift = [] then - case Key of - 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; + if (Shift = []) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT]) then + lstUnits.Perform(WM_KEYDOWN, Key, 0); end; procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject); diff --git a/Source/UnSwObjects.pas b/Source/UnSwObjects.pas index b9631d4..95a20bb 100644 --- a/Source/UnSwObjects.pas +++ b/Source/UnSwObjects.pas @@ -1,9 +1,12 @@ unit UnSwObjects; +{$I UnSwDefines.inc} + interface uses Classes, Contnrs, + Registry, ToolsAPI; type @@ -39,7 +42,7 @@ type function GetName(): 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 // IUnSwVisited procedure AcceptVisitor(const AVisitor: IUnSwVisitor); virtual; abstract; @@ -130,6 +133,11 @@ type write SetItem; default; end; + TUnSwRegistry = class(TRegistry) + public + function OpenIDEKey(): Boolean; + end; + implementation uses SysUtils; @@ -167,10 +175,36 @@ begin 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 - (BorlandIDEServices as IOTAActionServices).OpenFile(AFileName); - // #ToDo1 (MvR) 6-1-2006: show source for forms + {$IFDEF DELPHI7} + 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; @@ -189,7 +223,7 @@ var begin ifModule := FModule.OpenModule(); if Assigned(ifModule) then - OpenFile(ifModule.FileName, ASource); + OpenModule(ifModule, ASource); end; procedure TUnSwModuleUnit.AcceptVisitor(const AVisitor: IUnSwVisitor); @@ -217,7 +251,9 @@ begin Result := TUnSwUnitType(FModule.ModuleType); 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 Result := swutProjUnit else @@ -235,7 +271,7 @@ end; procedure TUnSwProjectUnit.Activate(const ASource: Boolean); begin - OpenFile(FProject.FileName, ASource); + OpenModule(FProject, False); end; procedure TUnSwProjectUnit.AcceptVisitor(const AVisitor: IUnSwVisitor); @@ -350,4 +386,12 @@ begin FItems[Index] := Value; end; + +{ TUnSwRegistry } +function TUnSwRegistry.OpenIDEKey(): Boolean; +begin + Result := OpenKey((BorlandIDEServices as IOTAServices).GetBaseRegistryKey() + + '\UnitSwitcher', True); +end; + end.