From be20ec1c0f7bd3584f8d56939a16f390c00fd2dc Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 15 Jan 2006 00:22:09 +0000 Subject: [PATCH] Fixed: Issue #137 Fixed: Issue #142 Fixed: Issue #143 Fixed: Issue #155 --- Packages/D2006/UnitSwitcher.bdsproj | 6 +- Source/UnSwConfiguration.dfm | 17 ++- Source/UnSwConfiguration.pas | 14 +++ Source/UnSwDialog.dfm | 60 +++++++---- Source/UnSwDialog.pas | 160 ++++++++++++++++++++++------ Source/UnSwSettings.pas | 32 +++--- 6 files changed, 220 insertions(+), 69 deletions(-) diff --git a/Packages/D2006/UnitSwitcher.bdsproj b/Packages/D2006/UnitSwitcher.bdsproj index 291ec25..4176c8d 100644 --- a/Packages/D2006/UnitSwitcher.bdsproj +++ b/Packages/D2006/UnitSwitcher.bdsproj @@ -165,8 +165,10 @@ 1.0.0.0 - - + + UnitSwitcher + + diff --git a/Source/UnSwConfiguration.dfm b/Source/UnSwConfiguration.dfm index 74d2d80..aa73417 100644 --- a/Source/UnSwConfiguration.dfm +++ b/Source/UnSwConfiguration.dfm @@ -202,10 +202,23 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration OnClick = PickColor end end + object btnDefault: TButton + Left = 8 + Top = 135 + Width = 109 + Height = 25 + Caption = 'Reset to &default' + TabOrder = 2 + OnClick = btnDefaultClick + end end object tsAbout: TTabSheet Caption = 'About...' ImageIndex = 1 + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 DesignSize = ( 287 181) @@ -334,7 +347,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object dlgColor: TColorDialog Options = [cdFullOpen] - Left = 12 - Top = 176 + Left = 260 + Top = 160 end end diff --git a/Source/UnSwConfiguration.pas b/Source/UnSwConfiguration.pas index 8378c5c..fe50351 100644 --- a/Source/UnSwConfiguration.pas +++ b/Source/UnSwConfiguration.pas @@ -21,6 +21,7 @@ type TfrmUnSwConfiguration = class(TForm) btnCancel: TButton; btnDataModuleColor: TButton; + btnDefault: TButton; btnFormColor: TButton; btnOk: TButton; btnProjectColor: TButton; @@ -39,6 +40,7 @@ type tsAbout: TTabSheet; tsGeneral: TTabSheet; + procedure btnDefaultClick(Sender: TObject); procedure chkCustomColorClick(Sender: TObject); procedure lblBugReportClick(Sender: TObject); procedure PickColor(Sender: TObject); @@ -116,6 +118,18 @@ begin end; +procedure TfrmUnSwConfiguration.btnDefaultClick(Sender: TObject); +begin + if MessageBox(Self.Handle, 'Are you sure you want to revert the color ' + + 'settings? This action can not be undone.', + 'Reset to default', MB_YESNO or MB_ICONQUESTION) = ID_YES then + begin + Settings.ResetDefaults(True); + Settings.Save(); + LoadSettings(); + end; +end; + procedure TfrmUnSwConfiguration.chkCustomColorClick(Sender: TObject); const Colors: array[Boolean] of TColor = (clBtnFace, clWindow); diff --git a/Source/UnSwDialog.dfm b/Source/UnSwDialog.dfm index bbea285..455b522 100644 --- a/Source/UnSwDialog.dfm +++ b/Source/UnSwDialog.dfm @@ -51,7 +51,7 @@ object frmUnSwDialog: TfrmUnSwDialog TabOrder = 0 object pnlSearch: TPanel Left = 4 - Top = 4 + Top = 24 Width = 304 Height = 25 Align = alTop @@ -60,22 +60,24 @@ object frmUnSwDialog: TfrmUnSwDialog DesignSize = ( 304 25) - object edtSearch: TEdit + object cmbSearch: TComboBox Left = 0 Top = 0 Width = 304 Height = 21 Anchors = [akLeft, akTop, akRight] + ItemHeight = 13 TabOrder = 0 - OnChange = edtSearchChange - OnKeyDown = edtSearchKeyDown + OnChange = cmbSearchChange + OnKeyDown = cmbSearchKeyDown + OnKeyPress = cmbSearchKeyPress end end object lstUnits: TListBox Left = 4 - Top = 29 + Top = 49 Width = 304 - Height = 274 + Height = 254 Style = lbVirtualOwnerDraw Align = alClient ItemHeight = 20 @@ -86,6 +88,28 @@ object frmUnSwDialog: TfrmUnSwDialog OnDblClick = lstUnitsDblClick OnDrawItem = lstUnitsDrawItem end + object pnlSubFilters: TPanel + Left = 4 + Top = 4 + Width = 304 + Height = 20 + Align = alTop + BevelOuter = bvNone + TabOrder = 2 + Visible = False + DesignSize = ( + 304 + 20) + object lblSubFilters: TLabel + Left = 0 + Top = 1 + Width = 305 + Height = 13 + Anchors = [akLeft, akTop, akRight] + AutoSize = False + Caption = 'frm '#187' Dialog '#187 + end + end end object pnlButtons: TPanel Left = 0 @@ -176,8 +200,8 @@ object frmUnSwDialog: TfrmUnSwDialog end end object ilsTypes: TImageList - Left = 8 - Top = 32 + Left = 16 + Top = 264 Bitmap = { 494C010105000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 0000000000003600000028000000400000003000000001002000000000000030 @@ -583,8 +607,8 @@ object frmUnSwDialog: TfrmUnSwDialog 000000000000} end object alMain: TActionList - Left = 36 - Top = 32 + Left = 44 + Top = 264 object actSelectAll: TAction Caption = 'Select &All' ShortCut = 16449 @@ -617,20 +641,20 @@ object frmUnSwDialog: TfrmUnSwDialog ShortCut = 49165 OnExecute = actOpenPropertiesExecute end - object actMRUNext: TAction - Caption = 'actMRUNext' - ShortCut = 16422 - OnExecute = actMRUNextExecute - end object actMRUPrior: TAction Caption = 'actMRUPrior' - ShortCut = 16424 + ShortCut = 16422 OnExecute = actMRUPriorExecute end + object actMRUNext: TAction + Caption = 'actMRUNext' + ShortCut = 16424 + OnExecute = actMRUNextExecute + end end object pmnUnits: TPopupMenu - Left = 64 - Top = 32 + Left = 72 + Top = 264 object pmnUnitsSelectAll: TMenuItem Action = actSelectAll end diff --git a/Source/UnSwDialog.pas b/Source/UnSwDialog.pas index 47d13d7..5309242 100644 --- a/Source/UnSwDialog.pas +++ b/Source/UnSwDialog.pas @@ -53,8 +53,9 @@ type chkForms: TCheckBox; chkProjectSource: TCheckBox; chkUnits: TCheckBox; - edtSearch: TEdit; + cmbSearch: TComboBox; ilsTypes: TImageList; + lblSubFilters: TLabel; lstUnits: TListBox; pmnUnits: TPopupMenu; pmnUnitsOpenFolder: TMenuItem; @@ -69,7 +70,9 @@ type pnlIncludeTypes: TPanel; pnlMain: TPanel; pnlSearch: TPanel; + pnlSubFilters: TPanel; sbStatus: TStatusBar; + procedure cmbSearchKeyPress(Sender: TObject; var Key: Char); procedure actMRUNextExecute(Sender: TObject); procedure actMRUPriorExecute(Sender: TObject); @@ -78,8 +81,8 @@ type procedure actSelectAllExecute(Sender: TObject); procedure actSelectInvertExecute(Sender: TObject); procedure btnConfigurationClick(Sender: TObject); - procedure edtSearchChange(Sender: TObject); - procedure edtSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); + procedure cmbSearchChange(Sender: TObject); + procedure cmbSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormResize(Sender: TObject); procedure FormShow(Sender: TObject); procedure lstUnitsData(Control: TWinControl; Index: Integer; var Data: string); @@ -92,13 +95,16 @@ type FUnitList: TUnSwUnitList; FActiveUnit: TUnSwUnit; FFormsOnly: Boolean; - FMRUIndex: Integer; FMRUList: TStrings; + FMRUIndex: Integer; + FSubFilters: TStringList; FTypeFilteredList: TUnSwUnitList; + FSubFilteredList: TUnSwUnitList; FInputFilteredList: TUnSwUnitList; FTypeFilter: TUnSwUnitTypeFilter; + FSubFilter: TUnSwUnitSimpleFilter; FInputFilter: TUnSwUnitSimpleFilter; FStyleVisitor: TUnSwStyleVisitor; @@ -110,6 +116,10 @@ type function GetActiveUnits(): TUnSwUnitList; procedure SelectMRUItem(); + function PushFilter(const AFilter: String): Boolean; + procedure PopFilter(); + procedure UpdateSubFilters(); + procedure LoadSettings(); procedure SaveSettings(); public @@ -125,7 +135,7 @@ uses SysUtils, UnSwConfiguration, - UnSwSettings; + UnSwSettings, Dialogs; type TUnSwOpenVisitor = class(TInterfacedObject, IUnSwVisitor) @@ -295,19 +305,29 @@ begin end; function TfrmUnSwDialog.InternalExecute(): TUnSwUnitList; +type + TUnSwUnitSimpleFilterClass = class of TUnSwUnitSimpleFilter; + var iIndex: Integer; + pClass: TUnSwUnitSimpleFilterClass; begin Result := nil; + FSubFilters := TStringList.Create(); FTypeFilteredList := TUnSwUnitList.Create(); + FSubFilteredList := TUnSwUnitList.Create(); FInputFilteredList := TUnSwUnitList.Create(); FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList); if FFormsOnly then - FInputFilter := TUnSwUnitSimpleFormNameFilter.Create(FInputFilteredList) + pClass := TUnSwUnitSimpleFormNameFilter else - FInputFilter := TUnSwUnitSimpleNameFilter.Create(FInputFilteredList); + pClass := TUnSwUnitSimpleNameFilter; + + FSubFilter := pClass.Create(FSubFilteredList); + FInputFilter := pClass.Create(FInputFilteredList); + try LoadSettings(); @@ -323,14 +343,18 @@ begin try if Self.ShowModal() = mrOk then begin - iIndex := FMRUList.IndexOf(edtSearch.Text); - if iIndex > -1 then - FMRUList.Delete(iIndex); + if Length(Trim(cmbSearch.Text)) > 0 then + begin + iIndex := FMRUList.IndexOf(cmbSearch.Text); + if iIndex > -1 then + FMRUList.Delete(iIndex); - while FMRUList.Count >= 10 do - FMRUList.Delete(Pred(FMRUList.Count)); + while FMRUList.Count >= 10 do + FMRUList.Delete(Pred(FMRUList.Count)); - FMRUList.Insert(0, edtSearch.Text); + FMRUList.Insert(0, cmbSearch.Text); + end; + Result := GetActiveUnits(); end; @@ -340,9 +364,12 @@ begin end; finally FreeAndNil(FInputFilter); + FreeAndNil(FSubFilter); FreeAndNil(FTypeFilter); + FreeAndNil(FSubFilteredList); FreeAndNil(FInputFilteredList); FreeAndNil(FTypeFilteredList); + FreeAndNil(FSubFilters); end; end; @@ -356,7 +383,7 @@ var begin activeUnits := GetActiveUnits(); - FInputFilteredList.Clone(FTypeFilteredList); + FInputFilteredList.Clone(FSubFilteredList); FInputFilteredList.AcceptVisitor(FInputFilter); lstUnits.Count := FInputFilteredList.Count; @@ -450,9 +477,58 @@ begin else FTypeFilteredList.Sort(SortByType); + UpdateSubFilters(); +end; + +procedure TfrmUnSwDialog.PopFilter(); +begin + if FSubFilters.Count > 0 then + begin + FSubFilters.Delete(Pred(FSubFilters.Count)); + UpdateSubFilters(); + end; +end; + +procedure TfrmUnSwDialog.UpdateSubFilters(); +var + iFilter: Integer; + sFilters: String; + +begin + FSubFilteredList.Clone(FTypeFilteredList); + + if FSubFilters.Count > 0 then + begin + for iFilter := 0 to Pred(FSubFilters.Count) do + begin + sFilters := sFilters + FSubFilters[iFilter] + ' '#187' '; + FSubFilter.Filter := FSubFilters[iFilter]; + FSubFilteredList.AcceptVisitor(FSubFilter); + end; + + lblSubFilters.Caption := Trim(sFilters); + pnlSubFilters.Visible := True; + end else + pnlSubFilters.Visible := False; + UpdateList(); end; + +function TfrmUnSwDialog.PushFilter(const AFilter: String): Boolean; +var + sFilter: String; + +begin + sFilter := Trim(AFilter); + Result := (Length(sFilter) > 0) and (FSubFilters.IndexOf(AFilter) = -1); + if Result then + begin + FSubFilters.Add(AFilter); + UpdateSubFilters(); + end; +end; + function TfrmUnSwDialog.GetActiveUnits(): TUnSwUnitList; var itemIndex: Integer; @@ -500,7 +576,7 @@ begin end; FMRUList := dialogSettings.MRUList; - FMRUIndex := -1; + cmbSearch.Items.Assign(FMRUList); Self.ClientWidth := dialogSettings.Width; Self.ClientHeight := dialogSettings.Height; @@ -559,16 +635,9 @@ end; procedure TfrmUnSwDialog.SelectMRUItem(); begin - if (FMRUIndex < -1) or (FMRUIndex > Pred(FMRUList.Count)) then - exit; - - if FMRUIndex = -1 then - edtSearch.Text := '' - else - edtSearch.Text := FMRUList[FMRUIndex]; - - ActiveControl := edtSearch; - edtSearch.SelectAll(); + cmbSearch.ItemIndex := FMRUIndex; + ActiveControl := cmbSearch; + cmbSearch.SelectAll(); end; procedure TfrmUnSwDialog.actMRUNextExecute(Sender: TObject); @@ -622,19 +691,46 @@ begin lstUnits.Invalidate(); end; -procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject); +procedure TfrmUnSwDialog.cmbSearchChange(Sender: TObject); begin - FInputFilter.Filter := edtSearch.Text; + FInputFilter.Filter := cmbSearch.Text; UpdateList(); end; -procedure TfrmUnSwDialog.edtSearchKeyDown(Sender: TObject; var Key: Word; +procedure TfrmUnSwDialog.cmbSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin - if ((Shift = []) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT])) or - ((Shift = [ssCtrl]) and (Key in [VK_HOME, VK_END])) or - ((Shift = [ssShift]) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT])) then - lstUnits.Perform(WM_KEYDOWN, Key, 0); + if not cmbSearch.DroppedDown then + if ((Shift = []) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT])) or + ((Shift = [ssCtrl]) and (Key in [VK_HOME, VK_END])) or + ((Shift = [ssShift]) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT])) then + begin + lstUnits.Perform(WM_KEYDOWN, Key, 0); + Key := 0; + end else if Shift = [ssCtrl] then + case Key of + VK_TAB: + begin + if PushFilter(cmbSearch.Text) then + cmbSearch.Text := ''; + + Key := 0; + end; + VK_BACK: + begin + cmbSearch.Text := ''; + FInputFilter.Filter := ''; + PopFilter(); + Key := 0; + end; + end; +end; + +procedure TfrmUnSwDialog.cmbSearchKeyPress(Sender: TObject; var Key: Char); +begin + // Ctrl-Backspace + if Key = #127 then + Key := #0; end; procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject); diff --git a/Source/UnSwSettings.pas b/Source/UnSwSettings.pas index ea95256..cdc8ef7 100644 --- a/Source/UnSwSettings.pas +++ b/Source/UnSwSettings.pas @@ -91,7 +91,7 @@ type constructor Create(); destructor Destroy(); override; - procedure ResetDefaults(); + procedure ResetDefaults(const AColorsOnly: Boolean = False); procedure Save(); property Colors: TUnSwColorSettings read FColors write FColors; @@ -199,8 +199,7 @@ end; procedure TUnSwDialogSettings.Load(const ARegistry: TRegistry); var - eSort: TUnSwDialogSort; - iSort: Integer absolute eSort; + iSort: Integer; sMRU: String; begin @@ -226,18 +225,17 @@ begin ReadIntegerDef(ARegistry, FWidth, 'Width'); ReadIntegerDef(ARegistry, FHeight, 'Height'); - // The 'absolute' acts as an implicit typecast - eSort := FSort; + iSort := Integer(FSort); ReadIntegerDef(ARegistry, iSort, 'Sort'); - FSort := eSort; + FSort := TUnSwDialogSort(iSort); - if ARegistry.ValueExists('MRU') then + if ARegistry.ValueExists(GetKeyName('MRU')) then begin - SetLength(sMRU, ARegistry.GetDataSize('MRU')); + SetLength(sMRU, ARegistry.GetDataSize(GetKeyName('MRU'))); if Length(sMRU) > 0 then begin - ARegistry.ReadBinaryData('MRU', PChar(sMRU)^, Length(sMRU)); - FMRUList.Text := sMRU; + ARegistry.ReadBinaryData(GetKeyName('MRU'), PChar(sMRU)^, Length(sMRU)); + FMRUList.Text := Trim(sMRU); end; end; end; @@ -260,9 +258,9 @@ begin if FMRUList.Count > 0 then begin sMRU := FMRUList.Text; - ARegistry.WriteBinaryData('MRU', PChar(sMRU)^, Length(sMRU)); + ARegistry.WriteBinaryData(GetKeyName('MRU'), PChar(sMRU)^, Length(sMRU)); end else - ARegistry.DeleteValue('MRU'); + ARegistry.DeleteValue(GetKeyName('MRU')); end; @@ -298,6 +296,7 @@ begin FFormsDialog := TUnSwDialogSettings.Create('Forms'); FUnitsDialog := TUnSwDialogSettings.Create('Units'); ResetDefaults(); + Load(); end; destructor TUnSwSettings.Destroy(); @@ -310,7 +309,7 @@ begin end; -procedure TUnSwSettings.ResetDefaults(); +procedure TUnSwSettings.ResetDefaults(const AColorsOnly: Boolean); procedure ResetDialog(const ADialog: TUnSwDialogSettings); begin ADialog.IncludeDataModules := True; @@ -323,8 +322,11 @@ procedure TUnSwSettings.ResetDefaults(); end; begin - ResetDialog(FFormsDialog); - ResetDialog(FUnitsDialog); + if not AColorsOnly then + begin + ResetDialog(FFormsDialog); + ResetDialog(FUnitsDialog); + end; FColors.Enabled := True; FColors.DataModules := RGB( 35, 120, 35); // Green