1
0
mirror of synced 2024-11-15 08:53:50 +00:00
unitswitcher/Source/CmpSwConfiguration.pas

246 lines
6.3 KiB
ObjectPascal
Raw Normal View History

{: Contains the configuration dialog.
Last changed: $Date$
Revision: $Rev$
Author: $Author$
}
unit CmpSwConfiguration;
interface
uses
ActnList,
Classes,
ComCtrls,
Controls,
Dialogs,
ExtCtrls,
Forms,
Graphics,
2007-12-16 13:06:21 +00:00
ImgList,
StdCtrls,
ToolWin,
CmpSwFilters;
type
TfrmCmpSwConfiguration = class(TForm)
actAdd: TAction;
actEdit: TAction;
actRemove: TAction;
alMain: TActionList;
btnCancel: TButton;
btnDefault: TButton;
btnOk: TButton;
chkAllowEmptyResults: TCheckBox;
dlgColor: TColorDialog;
2007-12-16 13:06:21 +00:00
ilsFilters: TImageList;
imgAbout: TImage;
lbFilters: TListBox;
lblBugReport: TLabel;
lblVersion: TLabel;
pcConfiguration: TPageControl;
2007-12-16 13:06:21 +00:00
tbFilterAdd: TToolButton;
tbFilterEdit: TToolButton;
tbFilterRemove: TToolButton;
tbFilters: TToolBar;
tsAbout: TTabSheet;
tsGeneral: TTabSheet;
procedure btnDefaultClick(Sender: TObject);
procedure lblBugReportClick(Sender: TObject);
procedure actAddExecute(Sender: TObject);
procedure actEditExecute(Sender: TObject);
procedure actRemoveExecute(Sender: TObject);
procedure lbFiltersClick(Sender: TObject);
procedure lbFiltersData(Control: TWinControl; Index: Integer; var Data: String);
procedure lbFiltersDataObject(Control: TWinControl; Index: Integer; var DataObject: TObject);
2007-12-16 13:06:21 +00:00
procedure lbFiltersDblClick(Sender: TObject);
private
function InternalExecute(): Boolean;
procedure LoadSettings();
procedure SaveSettings();
procedure RefreshFilters();
2007-12-16 13:06:21 +00:00
function GetSelectedGroup(): TCmpSwFilterGroup;
property SelectedGroup: TCmpSwFilterGroup read GetSelectedGroup;
public
class function Execute(): Boolean;
end;
implementation
uses
ShellAPI,
2007-12-16 13:06:21 +00:00
SysUtils,
Windows,
2007-12-16 13:06:21 +00:00
CmpSwFilterConfiguration,
CmpSwSettings;
{$R *.dfm}
{ TfrmCmpSwConfiguration }
class function TfrmCmpSwConfiguration.Execute(): Boolean;
begin
with Self.Create(nil) do
try
pcConfiguration.ActivePage := tsGeneral;
Result := InternalExecute();
finally
Free();
end;
end;
function TfrmCmpSwConfiguration.InternalExecute(): Boolean;
begin
LoadSettings();
RefreshFilters();
2007-12-16 13:06:21 +00:00
Result := (ShowModal() = mrOk);
if Result then
SaveSettings();
end;
procedure TfrmCmpSwConfiguration.lblBugReportClick(Sender: TObject);
begin
ShellExecute(0, 'open', 'mailto:support@x2software.net', nil, nil, SW_SHOWNORMAL);
end;
procedure TfrmCmpSwConfiguration.LoadSettings();
begin
chkAllowEmptyResults.Checked := Settings.AllowEmptyResult;
end;
procedure TfrmCmpSwConfiguration.SaveSettings();
begin
Settings.AllowEmptyResult := chkAllowEmptyResults.Checked;
Settings.Save();
end;
2007-12-16 13:06:21 +00:00
function TfrmCmpSwConfiguration.GetSelectedGroup(): TCmpSwFilterGroup;
begin
Result := nil;
if lbFilters.ItemIndex > -1 then
Result := TCmpSwFilterGroup(lbFilters.Items.Objects[lbFilters.ItemIndex]);
end;
procedure TfrmCmpSwConfiguration.btnDefaultClick(Sender: TObject);
begin
if MessageBox(Self.Handle, 'Are you sure you want to revert the ' +
'settings? This action can not be undone.',
'Reset to default', MB_YESNO or MB_ICONQUESTION) = ID_YES then
begin
Settings.ResetDefaults();
Settings.Save();
LoadSettings();
end;
end;
procedure TfrmCmpSwConfiguration.actAddExecute(Sender: TObject);
2007-12-16 13:06:21 +00:00
var
newGroup: TCmpSwFilterGroup;
begin
2007-12-16 13:06:21 +00:00
newGroup := TCmpSwFilterGroup.Create(nil);
try
if TfrmCmpSwFilterConfiguration.Execute(newGroup) then
begin
newGroup.Collection := Settings.Filter;
RefreshFilters();
end;
finally
if not Assigned(newGroup.Collection) then
FreeAndNil(newGroup);
end;
end;
procedure TfrmCmpSwConfiguration.actEditExecute(Sender: TObject);
2007-12-16 13:06:21 +00:00
var
group: TCmpSwFilterGroup;
begin
2007-12-16 13:06:21 +00:00
group := SelectedGroup;
if Assigned(group) then
begin
if TfrmCmpSwFilterConfiguration.Execute(group) then
lbFilters.Invalidate();
end;
end;
procedure TfrmCmpSwConfiguration.actRemoveExecute(Sender: TObject);
2007-12-16 13:06:21 +00:00
var
group: TCmpSwFilterGroup;
begin
2007-12-16 13:06:21 +00:00
group := SelectedGroup;
if Assigned(group) then
begin
if Application.MessageBox(PChar(Format('Do you want to remove the filter "%s"?',
[group.Name])), 'Remove',
MB_YESNO or MB_ICONQUESTION) = ID_YES then
begin
lbFilters.Items.BeginUpdate();
try
FreeAndNil(group);
RefreshFilters();
finally
lbFilters.Items.EndUpdate();
end;
end;
end;
end;
procedure TfrmCmpSwConfiguration.lbFiltersClick(Sender: TObject);
var
itemSelected: Boolean;
begin
itemSelected := (lbFilters.ItemIndex > -1);
actEdit.Enabled := itemSelected;
actRemove.Enabled := itemSelected;
end;
procedure TfrmCmpSwConfiguration.RefreshFilters();
begin
lbFilters.Count := Settings.Filter.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;
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];
end;
2007-12-16 13:06:21 +00:00
procedure TfrmCmpSwConfiguration.lbFiltersDblClick(Sender: TObject);
begin
actEdit.Execute();
end;
end.