mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
161 lines
5 KiB
ObjectPascal
161 lines
5 KiB
ObjectPascal
{
|
|
Double Commander
|
|
-------------------------------------------------------------------------
|
|
Content plugins search frame
|
|
|
|
Copyright (C) 2014-2016 Alexander Koblov (alexx2000@mail.ru)
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
}
|
|
|
|
unit fSearchPlugin;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, FileUtil, Forms, Controls, ExtCtrls, StdCtrls,
|
|
ComCtrls, Buttons, uFindFiles;
|
|
|
|
type
|
|
|
|
{ TfrmSearchPlugin }
|
|
|
|
TfrmSearchPlugin = class(TFrame)
|
|
btnDelete: TBitBtn;
|
|
btnAdd: TButton;
|
|
chkUsePlugins: TCheckBox;
|
|
lblPlugin: TLabel;
|
|
lblField: TLabel;
|
|
lblOperator: TLabel;
|
|
lblValue: TLabel;
|
|
pnlHeaders: TPanel;
|
|
pnlOptions: TPanel;
|
|
pnlButtons: TPanel;
|
|
pnlTable: TScrollBox;
|
|
rbAnd: TRadioButton;
|
|
rbOr: TRadioButton;
|
|
procedure btnAddClick(Sender: TObject);
|
|
procedure btnDeleteClick(Sender: TObject);
|
|
procedure chkUsePluginsChange(Sender: TObject);
|
|
procedure pnlTableResize(Sender: TObject);
|
|
private
|
|
{ private declarations }
|
|
public
|
|
procedure Save(var SearchTemplate: TSearchTemplateRec);
|
|
procedure Load(const SearchTemplate: TSearchTemplateRec);
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.lfm}
|
|
|
|
uses
|
|
uSearchContent;
|
|
|
|
{ TfrmSearchPlugin }
|
|
|
|
procedure TfrmSearchPlugin.Save(var SearchTemplate: TSearchTemplateRec);
|
|
var
|
|
I: Integer;
|
|
Plugin: TPluginPanel;
|
|
begin
|
|
SearchTemplate.ContentPlugin:= chkUsePlugins.Checked;
|
|
if not SearchTemplate.ContentPlugin then Exit;
|
|
SearchTemplate.ContentPluginCombine:= rbAnd.Checked;
|
|
SetLength(SearchTemplate.ContentPlugins, pnlTable.ControlCount);
|
|
for I:= 0 to pnlTable.ControlCount - 1 do
|
|
begin
|
|
Plugin:= TPluginPanel(pnlTable.Controls[I]);
|
|
SearchTemplate.ContentPlugins[I].Plugin:= Plugin.Plugin;
|
|
SearchTemplate.ContentPlugins[I].FieldType:= Plugin.FieldType;
|
|
SearchTemplate.ContentPlugins[I].Field:= Plugin.Field;
|
|
SearchTemplate.ContentPlugins[I].Compare:= Plugin.Compare;
|
|
SearchTemplate.ContentPlugins[I].Value:= Plugin.Value;
|
|
SearchTemplate.ContentPlugins[I].UnitName:= Plugin.UnitName; //Set the unit *after* the field has been set so if we have error setting the unit, the error message gives the "field" has a hint.
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmSearchPlugin.Load(const SearchTemplate: TSearchTemplateRec);
|
|
var
|
|
I: Integer;
|
|
Panel: TPluginPanel;
|
|
begin
|
|
if SearchTemplate.ContentPluginCombine then
|
|
rbAnd.Checked:= True
|
|
else begin
|
|
rbOr.Checked:= True;
|
|
end;
|
|
for I:= pnlTable.ControlCount - 1 downto 0 do pnlTable.Controls[I].Free;
|
|
for I:= Low(SearchTemplate.ContentPlugins) to High(SearchTemplate.ContentPlugins) do
|
|
begin
|
|
Panel:= TPluginPanel.Create(pnlTable);
|
|
Panel.Parent:= pnlTable;
|
|
Panel.Plugin:= SearchTemplate.ContentPlugins[I].Plugin;
|
|
Panel.Field:= SearchTemplate.ContentPlugins[I].Field;
|
|
Panel.Compare:= SearchTemplate.ContentPlugins[I].Compare;
|
|
Panel.Value:= SearchTemplate.ContentPlugins[I].Value;
|
|
Panel.UnitName:= SearchTemplate.ContentPlugins[I].UnitName;
|
|
end;
|
|
chkUsePlugins.Checked:= SearchTemplate.ContentPlugin;
|
|
end;
|
|
|
|
procedure TfrmSearchPlugin.btnAddClick(Sender: TObject);
|
|
var
|
|
Panel: TPluginPanel;
|
|
begin
|
|
Panel:= TPluginPanel.Create(pnlTable);
|
|
Panel.Parent:= pnlTable;
|
|
end;
|
|
|
|
procedure TfrmSearchPlugin.btnDeleteClick(Sender: TObject);
|
|
var
|
|
Index: Integer;
|
|
begin
|
|
Index:= pnlTable.ControlCount - 1;
|
|
if Index >= 0 then pnlTable.Controls[Index].Free;
|
|
end;
|
|
|
|
procedure TfrmSearchPlugin.chkUsePluginsChange(Sender: TObject);
|
|
begin
|
|
rbAnd.Enabled:= chkUsePlugins.Checked;
|
|
rbOr.Enabled:= chkUsePlugins.Checked;
|
|
pnlHeaders.Enabled:= chkUsePlugins.Checked;
|
|
pnlTable.Enabled:= chkUsePlugins.Checked;
|
|
pnlButtons.Enabled:= chkUsePlugins.Checked;
|
|
if chkUsePlugins.Checked and (pnlTable.ControlCount = 0) then
|
|
btnAddClick(Sender);
|
|
end;
|
|
|
|
procedure TfrmSearchPlugin.pnlTableResize(Sender: TObject);
|
|
var
|
|
I, ColumnWidth: Integer;
|
|
begin
|
|
ColumnWidth:= pnlTable.ClientWidth div 5;
|
|
lblPlugin.Constraints.MinWidth:= ColumnWidth;
|
|
lblPlugin.Constraints.MaxWidth:= ColumnWidth;
|
|
lblField.Constraints.MinWidth:= ColumnWidth;
|
|
lblField.Constraints.MaxWidth:= ColumnWidth;
|
|
lblOperator.Constraints.MinWidth:= ColumnWidth;
|
|
lblOperator.Constraints.MaxWidth:= ColumnWidth;
|
|
lblValue.Constraints.MinWidth:= ColumnWidth * 2;
|
|
lblValue.Constraints.MaxWidth:= ColumnWidth * 2;
|
|
for I:= 0 to pnlTable.ControlCount - 1 do
|
|
TPluginPanel(pnlTable.Controls[I]).UpdateSizes(ColumnWidth)
|
|
end;
|
|
|
|
end.
|
|
|