Skip to content

Commit

Permalink
Merge pull request #53 from cybertec-postgresql/30-pop-up-editor-for-…
Browse files Browse the repository at this point in the history
…cron-values

[+] implement pop-up editor for chain Cron values, closes #30
  • Loading branch information
pashagolub authored Dec 30, 2022
2 parents 125b2e6 + 7cd4c7f commit c781561
Show file tree
Hide file tree
Showing 12 changed files with 474 additions and 150 deletions.
3 changes: 3 additions & 0 deletions forms/fmmain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object fmMain: TfmMain
Images = imglTabs
TabIndex = 0
TabOrder = 0
OnChange = pcEditorsChange
object tsOverview: TTabSheet
Caption = 'Overview'
ClientHeight = 986
Expand Down Expand Up @@ -82,6 +83,7 @@ object fmMain: TfmMain
FieldName = 'live'
end
item
ButtonStyle = cbsEllipsis
PickList.Strings = (
'* * * * *'
'@every <interval>'
Expand Down Expand Up @@ -137,6 +139,7 @@ object fmMain: TfmMain
TabAdvance = aaRight
TabOrder = 0
TitleImageList = imglGrids
OnEditButtonClick = gridChainsEditButtonClick
OnEditingDone = gridChainsEditingDone
OnTitleClick = gridChainsTitleClick
end
Expand Down
36 changes: 30 additions & 6 deletions forms/fmmain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Menus,
StdCtrls, DBGrids, DBCtrls, ExtCtrls, uObjects, DB, Grids, ActnList, Buttons,
frameTaskCommand;
frameTaskCommandEditor, frameCronEditor;

type

Expand Down Expand Up @@ -93,6 +93,7 @@ TfmMain = class(TForm)
procedure acTaskToolbarUpdate(Sender: TObject);
procedure acConnectClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure gridChainsEditButtonClick(Sender: TObject);
procedure gridChainsEditingDone(Sender: TObject);
procedure gridChainsTitleClick(Column: TColumn);
procedure gridTasksDrawColumnCell(Sender: TObject; const Rect: TRect;
Expand All @@ -102,9 +103,11 @@ TfmMain = class(TForm)
var Editor: TWinControl);
procedure miCloseClick(Sender: TObject);
procedure miLogClick(Sender: TObject);
procedure pcEditorsChange(Sender: TObject);
private
FLastColumn: TColumn; //last sorted grid column
FTaskCmd: TfrmTaskCommand;
FTaskCmd: TfrmTaskCommandEditor;
FCronEdit: TfrmCronEditor;
public
procedure UpdateSortIndication(ACol: TColumn);
end;
Expand All @@ -114,7 +117,7 @@ TfmMain = class(TForm)

implementation

uses uDataModule, SQLDB, LCLType, RegExpr;
uses uDataModule, SQLDB, LCLType;

{$R *.lfm}

Expand All @@ -126,6 +129,19 @@ procedure TfmMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
CanClose := True;
end;

procedure TfmMain.gridChainsEditButtonClick(Sender: TObject);
var
P: TPoint;
begin
if not Assigned(FCronEdit) then
begin
FCronEdit := TfrmCronEditor.Create(Self);
FCronEdit.Parent := Self;
end;
P := gridChains.ClientToParent(gridChains.SelectedFieldRect.TopLeft, Self);
FCronEdit.ShowEditor(gridChains.SelectedField, P);
end;

procedure TfmMain.gridChainsEditingDone(Sender: TObject);
var
S: string;
Expand Down Expand Up @@ -212,13 +228,16 @@ procedure TfmMain.gridTasksDrawColumnCell(Sender: TObject; const Rect: TRect;
end;

procedure TfmMain.gridTasksEditButtonClick(Sender: TObject);
var
P: TPoint;
begin
if not Assigned(FTaskCmd) then
begin
FTaskCmd := TfrmTaskCommand.Create(Self);
FTaskCmd.Parent := gridTasks;
FTaskCmd := TfrmTaskCommandEditor.Create(Self);
FTaskCmd.Parent := Self;
end;
FTaskCmd.ShowEditor(gridTasks.SelectedField, gridTasks.SelectedFieldRect.TopLeft);
P := gridTasks.ClientToParent(gridTasks.SelectedFieldRect.TopLeft, Self);
FTaskCmd.ShowEditor(gridTasks.SelectedField, P);
end;

procedure TfmMain.gridTasksSelectEditor(Sender: TObject; Column: TColumn;
Expand All @@ -245,6 +264,11 @@ procedure TfmMain.miLogClick(Sender: TObject);
if tsLog.TabVisible then tsLog.Show();
end;

procedure TfmMain.pcEditorsChange(Sender: TObject);
begin
pcEditors.SetFocus();
end;

procedure TfmMain.UpdateSortIndication(ACol: TColumn);
begin
// Remove the sort arrow from the previous column we sorted
Expand Down
43 changes: 43 additions & 0 deletions forms/framebase.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
object BaseFrame: TBaseFrame
Left = 0
Height = 360
Top = 0
Width = 480
ClientHeight = 360
ClientWidth = 480
DesignTimePPI = 144
LCLVersion = '2.2.4.0'
OnExit = FrameExit
ParentFont = False
TabOrder = 0
DesignLeft = 2785
DesignTop = 1022
object pnlButtons: TPanel
Left = 0
Height = 56
Top = 304
Width = 480
Align = alBottom
ClientHeight = 56
ClientWidth = 480
TabOrder = 0
object btnOK: TButton
Left = 344
Height = 38
Top = 8
Width = 113
Caption = 'OK'
OnClick = btnOKClick
TabOrder = 0
end
object btnCancel: TButton
Left = 16
Height = 38
Top = 8
Width = 113
Caption = 'Cancel'
OnExit = FrameExit
TabOrder = 1
end
end
end
71 changes: 71 additions & 0 deletions forms/framebase.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
unit framebase;

{$mode ObjFPC}{$H+}

interface

uses
Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls, SynEdit,
SynHighlighterSQL, ComCtrls, LCLType, Db;

type

{ TBaseFrame }

TBaseFrame = class(TFrame)
btnOK: TButton;
btnCancel: TButton;
pnlButtons: TPanel;
procedure btnOKClick(Sender: TObject);
procedure FrameExit(Sender: TObject);
protected
fldCommand: TField;
function GetEditorValue(): string; virtual; abstract;
procedure SetEditorValue(AText: string); virtual; abstract;
public
procedure ShowEditor(AField: TField; ATopLeft: TPoint);
procedure HideEditor();
procedure ApplyChanges();
end;

implementation

{$R *.lfm}

{ TBaseFrame }

procedure TBaseFrame.FrameExit(Sender: TObject);
begin
HideEditor();
end;

procedure TBaseFrame.btnOKClick(Sender: TObject);
begin
ApplyChanges();
end;

procedure TBaseFrame.ShowEditor(AField: TField; ATopLeft: TPoint);
begin
SetEditorValue(AField.AsString);
fldCommand := AField;
Left := ATopLeft.X;
Top := ATopLeft.Y;
Show();
SetFocus();
end;

procedure TBaseFrame.HideEditor;
begin
Hide();
Parent.SetFocus();
end;

procedure TBaseFrame.ApplyChanges;
begin
fldCommand.DataSet.Edit;
fldCommand.AsString := GetEditorValue();
HideEditor();
end;

end.

111 changes: 111 additions & 0 deletions forms/framecroneditor.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
inherited frmCronEditor: TfrmCronEditor
Width = 472
ClientWidth = 472
inherited pnlButtons: TPanel
Width = 472
ClientWidth = 472
inherited btnCancel: TButton
OnClick = FrameExit
OnExit = nil
end
end
object pnlEditor: TPanel[1]
Left = 0
Height = 304
Top = 0
Width = 472
Align = alClient
ClientHeight = 304
ClientWidth = 472
TabOrder = 1
object edCron: TEdit
Left = 48
Height = 35
Top = 41
Width = 375
Alignment = taCenter
Font.Height = -24
Font.Name = 'Courier New'
Font.Pitch = fpFixed
OnChange = edCronChange
ParentFont = False
TabOrder = 0
Text = '* * * * *'
end
object mmRuns: TMemo
Left = 48
Height = 180
Top = 112
Width = 375
Color = clInfoBk
Lines.Strings = (
'mmRuns'
)
TabOrder = 1
end
object lblNextRuns: TLabel
Left = 26
Height = 25
Top = 80
Width = 79
Caption = 'Next runs:'
ParentColor = False
end
object lblDayMonth: TLabel
Left = 198
Height = 25
Top = 16
Width = 75
Alignment = taCenter
AutoSize = False
Caption = 'Day'
ParentColor = False
end
object lblMonth: TLabel
Left = 273
Height = 25
Top = 16
Width = 75
Alignment = taCenter
AutoSize = False
Caption = 'Month'
ParentColor = False
end
object lblWeekday: TLabel
Left = 348
Height = 25
Top = 16
Width = 75
Alignment = taCenter
AutoSize = False
Caption = 'Week'
ParentColor = False
end
object lblHour: TLabel
Left = 123
Height = 25
Top = 16
Width = 75
Alignment = taCenter
AutoSize = False
Caption = 'Hour'
ParentColor = False
end
object lblMinute: TLabel
Left = 48
Height = 25
Top = 17
Width = 75
Alignment = taCenter
AutoSize = False
Caption = 'Minute'
ParentColor = False
end
end
object timerChange: TTimer[2]
Enabled = False
OnTimer = timerChangeTimer
Left = 416
Top = 88
end
end
Loading

0 comments on commit c781561

Please sign in to comment.