diff --git a/Lib/D7/UnitSwitcherD7.bpl b/Lib/D7/UnitSwitcherD7.bpl index f38bd9e..bfa8040 100644 Binary files a/Lib/D7/UnitSwitcherD7.bpl and b/Lib/D7/UnitSwitcherD7.bpl differ diff --git a/Source/BaseSwDialog.pas b/Source/BaseSwDialog.pas index 7493684..5b14098 100644 --- a/Source/BaseSwDialog.pas +++ b/Source/BaseSwDialog.pas @@ -101,6 +101,7 @@ type function CreateStyleVisitor(): TBaseSwStyleVisitor; virtual; function AllowEmptyResult(): Boolean; virtual; abstract; + function Wildchars(): Boolean; virtual; abstract; function ColorsEnabled(): Boolean; virtual; function GetBaseItemList(): TBaseSwItemList; virtual; @@ -116,6 +117,7 @@ type procedure LoadSettings(); virtual; procedure SaveSettings(); virtual; + procedure SettingsChanged(); virtual; procedure DrawItemText(ACanvas: TCanvas; AItem: TBaseSwItem; ARect: TRect; AState: TOwnerDrawState); virtual; protected @@ -241,6 +243,7 @@ end; procedure TfrmBaseSwDialog.LoadSettings(); begin cmbSearch.Items.Assign(MRUList); + SettingsChanged(); end; @@ -249,6 +252,13 @@ begin end; +procedure TfrmBaseSwDialog.SettingsChanged(); +begin + FInputFilter.Wildchars := Wildchars; + FSubFilter.Wildchars := Wildchars; +end; + + procedure TfrmBaseSwDialog.UpdateItemActions(); begin end; diff --git a/Source/BaseSwFilters.pas b/Source/BaseSwFilters.pas index ca9529a..58a8685 100644 --- a/Source/BaseSwFilters.pas +++ b/Source/BaseSwFilters.pas @@ -9,6 +9,7 @@ unit BaseSwFilters; interface uses Classes, + Masks, BaseSwObjects; @@ -29,10 +30,16 @@ type TBaseSwItemSimpleFilter = class(TBaseSwItemFilter) private FFilter: String; + FFilterMask: TMask; + FWildchars: Boolean; + function GetFilterMask(): TMask; procedure SetFilter(const Value: String); + protected + property FilterMask: TMask read GetFilterMask; public - property Filter: String read FFilter write SetFilter; + property Filter: String read FFilter write SetFilter; + property Wildchars: Boolean read FWildchars write FWildchars; end; @@ -71,18 +78,48 @@ end; { TBaseSwItemSimpleFilter } -procedure TBaseSwItemSimpleFilter.SetFilter(const Value: String); +function TBaseSwItemSimpleFilter.GetFilterMask(): TMask; begin - FFilter := LowerCase(Value); + if not Assigned(FFilterMask) then + FFilterMask := TMask.Create('*' + FFilter + '*'); + + Result := FFilterMask; +end; + + +procedure TBaseSwItemSimpleFilter.SetFilter(const Value: String); +var + newValue: string; + +begin + newValue := LowerCase(Value); + if newValue <> FFilter then + begin + FFilter := newValue; + FreeAndNil(FFilterMask); + end; end; { TBaseSwItemSimpleNameFilter } procedure TBaseSwItemSimpleNameFilter.VisitItem(const AItem: TBaseSwItem); +var + matches: Boolean; + itemName: string; + begin - if (Length(Filter) > 0) and - (AnsiPos(Filter, LowerCase(AItem.Name)) = 0) then - FilterItem(AItem); + if Length(Filter) > 0 then + begin + itemName := LowerCase(AItem.Name); + + if Wildchars then + matches := FilterMask.Matches(itemName) + else + matches := (AnsiPos(Filter, itemName) > 0); + + if not matches then + FilterItem(AItem); + end; end; end. diff --git a/Source/CmpSwConfiguration.dfm b/Source/CmpSwConfiguration.dfm index 8d8883b..1dbf24a 100644 --- a/Source/CmpSwConfiguration.dfm +++ b/Source/CmpSwConfiguration.dfm @@ -35,7 +35,7 @@ object frmCmpSwConfiguration: TfrmCmpSwConfiguration 338) object chkAllowEmptyResults: TCheckBox Left = 0 - Top = 320 + Top = 300 Width = 273 Height = 17 Anchors = [akLeft, akBottom] @@ -46,7 +46,7 @@ object frmCmpSwConfiguration: TfrmCmpSwConfiguration Left = 0 Top = 29 Width = 296 - Height = 280 + Height = 264 Style = lbVirtual Align = alTop ItemHeight = 16 @@ -85,6 +85,15 @@ object frmCmpSwConfiguration: TfrmCmpSwConfiguration Action = actRemove end end + object chkWildchars: TCheckBox + Left = 0 + Top = 320 + Width = 273 + Height = 17 + Anchors = [akLeft, akBottom] + Caption = 'Allow &wildchars in search criteria' + TabOrder = 3 + end end object tsAbout: TTabSheet Caption = 'About...' diff --git a/Source/CmpSwConfiguration.pas b/Source/CmpSwConfiguration.pas index 83da239..37a71e3 100644 --- a/Source/CmpSwConfiguration.pas +++ b/Source/CmpSwConfiguration.pas @@ -33,6 +33,7 @@ type btnDefault: TButton; btnOk: TButton; chkAllowEmptyResults: TCheckBox; + chkWildchars: TCheckBox; dlgColor: TColorDialog; ilsFilters: TImageList; imgAbout: TImage; @@ -116,13 +117,15 @@ end; procedure TfrmCmpSwConfiguration.LoadSettings(); begin - chkAllowEmptyResults.Checked := Settings.AllowEmptyResult; + chkAllowEmptyResults.Checked := Settings.Filter.AllowEmptyResult; + chkWildchars.Checked := Settings.Filter.Wildchars; end; procedure TfrmCmpSwConfiguration.SaveSettings(); begin - Settings.AllowEmptyResult := chkAllowEmptyResults.Checked; + Settings.Filter.AllowEmptyResult := chkAllowEmptyResults.Checked; + Settings.Filter.Wildchars := chkWildchars.Checked; Settings.Save(); end; @@ -157,7 +160,7 @@ begin try if TfrmCmpSwFilterConfiguration.Execute(newGroup) then begin - newGroup.Collection := Settings.Filter; + newGroup.Collection := Settings.FilterGroups; RefreshFilters(); end; finally @@ -219,21 +222,21 @@ end; procedure TfrmCmpSwConfiguration.RefreshFilters(); begin - lbFilters.Count := Settings.Filter.Count; + lbFilters.Count := Settings.FilterGroups.Count; end; procedure TfrmCmpSwConfiguration.lbFiltersData(Control: TWinControl; Index: Integer; var Data: String); begin - if (Index >= 0) and (Index < Settings.Filter.Count) then - Data := Settings.Filter[Index].Name; + if (Index >= 0) and (Index < Settings.FilterGroups.Count) then + Data := Settings.FilterGroups[Index].Name; end; procedure TfrmCmpSwConfiguration.lbFiltersDataObject(Control: TWinControl; Index: Integer; var DataObject: TObject); begin - if (Index >= 0) and (Index < Settings.Filter.Count) then - DataObject := Settings.Filter[Index]; + if (Index >= 0) and (Index < Settings.FilterGroups.Count) then + DataObject := Settings.FilterGroups[Index]; end; diff --git a/Source/CmpSwDialog.pas b/Source/CmpSwDialog.pas index b815ab0..f5dff9d 100644 --- a/Source/CmpSwDialog.pas +++ b/Source/CmpSwDialog.pas @@ -71,9 +71,11 @@ type function AllowEmptyResult(): Boolean; override; function ColorsEnabled(): Boolean; override; + function Wildchars(): Boolean; override; procedure LoadSettings(); override; procedure SaveSettings(); override; + procedure SettingsChanged(); override; procedure DrawItemText(ACanvas: TCanvas; AItem: TBaseSwItem; ARect: TRect; AState: TOwnerDrawState); override; procedure UpdateClassFilter(); @@ -252,7 +254,7 @@ begin FFilterCheckBoxes := TObjectList.Create(); FOtherGroup := TCmpSwFilterGroup.Create(nil); try - ClassFilter.Groups := Settings.Filter; + ClassFilter.Groups := Settings.FilterGroups; FOtherGroup.Name := 'Other'; FOtherGroup.Enabled := False; @@ -503,7 +505,7 @@ end; function TfrmCmpSwDialog.AllowEmptyResult(): Boolean; begin - Result := Settings.AllowEmptyResult; + Result := Settings.Filter.AllowEmptyResult; end; @@ -513,6 +515,12 @@ begin end; +function TfrmCmpSwDialog.Wildchars(): Boolean; +begin + Result := Settings.Filter.Wildchars; +end; + + procedure TfrmCmpSwDialog.SortExecute(Sender: TObject); begin (Sender as TAction).Checked := True; @@ -546,9 +554,16 @@ procedure TfrmCmpSwDialog.btnConfigurationClick(Sender: TObject); begin if TfrmCmpSwConfiguration.Execute() then begin + SettingsChanged(); UpdateClassFilter(); UpdateSubFilters(); end; end; +procedure TfrmCmpSwDialog.SettingsChanged; +begin + inherited; + +end; + end. diff --git a/Source/CmpSwSettings.pas b/Source/CmpSwSettings.pas index bbc5b05..5cbb6b5 100644 --- a/Source/CmpSwSettings.pas +++ b/Source/CmpSwSettings.pas @@ -34,11 +34,24 @@ type end; - TCmpSwSettings = class(TObject) + TCmpSwFilterSettings = class(TBaseSwSettings) private FAllowEmptyResult: Boolean; + FWildchars: Boolean; + protected + procedure Load(const ARegistry: TRegistry); override; + procedure Save(const ARegistry: TRegistry); override; + public + property AllowEmptyResult: Boolean read FAllowEmptyResult write FAllowEmptyResult; + property Wildchars: Boolean read FWildchars write FWildchars; + end; + + + TCmpSwSettings = class(TObject) + private FDialog: TCmpSwDialogSettings; - FFilter: TCmpSwFilterGroups; + FFilter: TCmpSwFilterSettings; + FFilterGroups: TCmpSwFilterGroups; FRegistryKey: String; protected @@ -56,9 +69,9 @@ type procedure ResetDefaults(); procedure Save(); - property AllowEmptyResult: Boolean read FAllowEmptyResult write FAllowEmptyResult; property Dialog: TCmpSwDialogSettings read FDialog write FDialog; - property Filter: TCmpSwFilterGroups read FFilter; + property Filter: TCmpSwFilterSettings read FFilter; + property FilterGroups: TCmpSwFilterGroups read FFilterGroups; end; function Settings(): TCmpSwSettings; @@ -105,7 +118,7 @@ end; procedure TCmpSwDialogSettings.Load(const ARegistry: TRegistry); var sMRU: String; - + begin ReadIntegerDef(ARegistry, FWidth, 'Width'); ReadIntegerDef(ARegistry, FHeight, 'Height'); @@ -139,6 +152,21 @@ begin end; +{ TCmpSwFilterSettings } +procedure TCmpSwFilterSettings.Load(const ARegistry: TRegistry); +begin + ReadBoolDef(ARegistry, FAllowEmptyResult, 'AllowEmptyResult'); + ReadBoolDef(ARegistry, FWildchars, 'Wildchars'); +end; + + +procedure TCmpSwFilterSettings.Save(const ARegistry: TRegistry); +begin + WriteBool(ARegistry, FAllowEmptyResult, 'AllowEmptyResult'); + WriteBool(ARegistry, FWildchars, 'Wildchars'); +end; + + { TCmpSwSettings } constructor TCmpSwSettings.Create(); begin @@ -148,7 +176,8 @@ begin '\ComponentSwitcher'; FDialog := TCmpSwDialogSettings.Create(); - FFilter := TCmpSwFilterGroups.Create(); + FFilter := TCmpSwFilterSettings.Create(); + FFilterGroups := TCmpSwFilterGroups.Create(); ResetDefaults(); Load(); @@ -157,6 +186,7 @@ end; destructor TCmpSwSettings.Destroy(); begin + FreeAndNil(FFilterGroups); FreeAndNil(FFilter); FreeAndNil(FDialog); @@ -177,7 +207,8 @@ begin if OpenKey(FRegistryKey, False) then begin FDialog.Load(ideRegistry); - LoadFilter('\Filter', Filter); + FFilter.Load(ideRegistry); + LoadFilter('\Filter', FilterGroups); CloseKey(); end; @@ -189,14 +220,15 @@ end; procedure TCmpSwSettings.ResetDefaults(); begin - AllowEmptyResult := True; + Filter.AllowEmptyResult := True; + Filter.Wildchars := True; Dialog.Width := 350; Dialog.Height := 530; { Fill default groups } - Filter.Clear(); - with Filter.Add() do + FilterGroups.Clear(); + with FilterGroups.Add() do begin Name := 'Actions'; @@ -205,7 +237,7 @@ begin Visible := True; end; - with Filter.Add() do + with FilterGroups.Add() do begin Name := 'Menu items'; @@ -213,7 +245,7 @@ begin Visible := True; end; - with Filter.Add() do + with FilterGroups.Add() do begin Name := 'Dataset fields'; @@ -222,7 +254,7 @@ begin Visible := True; end; - with Filter.Add() do + with FilterGroups.Add() do begin Name := 'DevEx Grid columns'; @@ -245,7 +277,8 @@ begin if OpenKey(FRegistryKey, True) then begin FDialog.Save(ideRegistry); - SaveFilter('\Filter', Filter); + FFilter.Save(ideRegistry); + SaveFilter('\Filter', FilterGroups); CloseKey(); end; diff --git a/Source/UnSwConfiguration.dfm b/Source/UnSwConfiguration.dfm index db0f315..d63ce8c 100644 --- a/Source/UnSwConfiguration.dfm +++ b/Source/UnSwConfiguration.dfm @@ -4,7 +4,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration BorderIcons = [biSystemMenu] BorderStyle = bsDialog Caption = 'UnitSwitcher Configuration' - ClientHeight = 272 + ClientHeight = 286 ClientWidth = 303 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -16,15 +16,15 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration Position = poScreenCenter DesignSize = ( 303 - 272) + 286) PixelsPerInch = 96 TextHeight = 13 object pcConfiguration: TPageControl Left = 4 Top = 4 Width = 295 - Height = 231 - ActivePage = tsAbout + Height = 245 + ActivePage = tsGeneral Anchors = [akLeft, akTop, akRight, akBottom] TabOrder = 0 object tsGeneral: TTabSheet @@ -204,11 +204,11 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object btnDefault: TButton Left = 8 - Top = 167 + Top = 183 Width = 109 Height = 25 Caption = 'Reset to &default' - TabOrder = 2 + TabOrder = 4 OnClick = btnDefaultClick end object chkAllowEmptyResults: TCheckBox @@ -217,6 +217,14 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration Width = 273 Height = 17 Caption = 'Allow &empty results' + TabOrder = 2 + end + object chkWildchars: TCheckBox + Left = 8 + Top = 156 + Width = 273 + Height = 17 + Caption = 'Allow &wildchars in search criteria' TabOrder = 3 end end @@ -225,7 +233,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration ImageIndex = 1 DesignSize = ( 287 - 203) + 217) object imgAbout: TImage Left = 8 Top = 8 @@ -311,7 +319,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object lblBugReport: TLabel Left = 56 - Top = 177 + Top = 191 Width = 75 Height = 13 Cursor = crHandPoint @@ -327,7 +335,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object lblShortcutKeys: TLabel Left = 56 - Top = 162 + Top = 176 Width = 127 Height = 13 Cursor = crHandPoint @@ -345,7 +353,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object btnCancel: TButton Left = 224 - Top = 241 + Top = 255 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -356,7 +364,7 @@ object frmUnSwConfiguration: TfrmUnSwConfiguration end object btnOk: TButton Left = 143 - Top = 241 + Top = 255 Width = 75 Height = 25 Anchors = [akRight, akBottom] diff --git a/Source/UnSwConfiguration.pas b/Source/UnSwConfiguration.pas index 80ac698..8585254 100644 --- a/Source/UnSwConfiguration.pas +++ b/Source/UnSwConfiguration.pas @@ -28,6 +28,7 @@ type btnUnitColor: TButton; chkAllowEmptyResults: TCheckBox; chkCustomColor: TCheckBox; + chkWildchars: TCheckBox; dlgColor: TColorDialog; imgAbout: TImage; lblBugReport: TLabel; @@ -122,6 +123,7 @@ begin lblProjectColor.Font.Color := Settings.Colors.ProjectSource; lblUnitColor.Font.Color := Settings.Colors.Units; chkAllowEmptyResults.Checked := Settings.Filter.AllowEmptyResult; + chkWildchars.Checked := Settings.Filter.Wildchars; end; @@ -133,6 +135,7 @@ begin Settings.Colors.ProjectSource := lblProjectColor.Font.Color; Settings.Colors.Units := lblUnitColor.Font.Color; Settings.Filter.AllowEmptyResult := chkAllowEmptyResults.Checked; + Settings.Filter.Wildchars := chkWildchars.Checked; Settings.Save(); end; diff --git a/Source/UnSwDialog.pas b/Source/UnSwDialog.pas index 1bb4424..c20fc2a 100644 --- a/Source/UnSwDialog.pas +++ b/Source/UnSwDialog.pas @@ -93,6 +93,7 @@ type function AllowEmptyResult(): Boolean; override; function ColorsEnabled(): Boolean; override; + function Wildchars(): Boolean; override; function GetBaseItemList(): TBaseSwItemList; override; function GetItemDisplayName(const AItem: TBaseSwItem): String; override; @@ -103,6 +104,7 @@ type procedure LoadSettings(); override; procedure SaveSettings(); override; + procedure SettingsChanged(); override; public class function Execute(const AUnits: TUnSwUnitList; const AFormsOnly: Boolean; @@ -653,6 +655,14 @@ begin end; +procedure TfrmUnSwDialog.SettingsChanged(); +begin + inherited; + + lstItems.Invalidate(); +end; + + procedure TfrmUnSwDialog.SortExecute(Sender: TObject); begin (Sender as TAction).Checked := True; @@ -708,7 +718,7 @@ end; procedure TfrmUnSwDialog.btnConfigurationClick(Sender: TObject); begin if TfrmUnSwConfiguration.Execute() then - lstItems.Invalidate(); + SettingsChanged(); end; @@ -724,6 +734,12 @@ begin end; +function TfrmUnSwDialog.Wildchars(): Boolean; +begin + Result := Settings.Filter.Wildchars; +end; + + function TfrmUnSwDialog.CreateStyleVisitor(): TBaseSwStyleVisitor; begin Result := TUnSwStyleVisitor.Create(); diff --git a/Source/UnSwSettings.pas b/Source/UnSwSettings.pas index 644cd07..3011c93 100644 --- a/Source/UnSwSettings.pas +++ b/Source/UnSwSettings.pas @@ -70,11 +70,13 @@ type TUnSwFilterSettings = class(TBaseSwSettings) private FAllowEmptyResults: Boolean; + FWildchars: Boolean; protected procedure Load(const ARegistry: TRegistry); override; procedure Save(const ARegistry: TRegistry); override; public property AllowEmptyResult: Boolean read FAllowEmptyResults write FAllowEmptyResults; + property Wildchars: Boolean read FWildchars write FWildchars; end; TUnSwResetSetting = (rsColors, rsFilter, rsForms, rsUnits); @@ -94,7 +96,7 @@ type constructor Create(); destructor Destroy(); override; - procedure ResetDefaults(const ASettings: TUnSwResetSettings = [rsColors, rsFilter]); + procedure ResetDefaults(const ASettings: TUnSwResetSettings = [rsColors, rsFilter, rsForms, rsUnits]); procedure Save(); property Colors: TUnSwColorSettings read FColors write FColors; @@ -244,12 +246,14 @@ end; procedure TUnSwFilterSettings.Load(const ARegistry: TRegistry); begin ReadBoolDef(ARegistry, FAllowEmptyResults, 'AllowEmptyResults'); + ReadBoolDef(ARegistry, FWildchars, 'Wildchars'); end; procedure TUnSwFilterSettings.Save(const ARegistry: TRegistry); begin WriteBool(ARegistry, FAllowEmptyResults, 'AllowEmptyResults'); + WriteBool(ARegistry, FWildchars, 'Wildchars'); end; @@ -313,7 +317,10 @@ begin end; if rsFilter in ASettings then + begin FFilter.AllowEmptyResult := False; + FFilter.Wildchars := True; + end; end; procedure TUnSwSettings.Load();