1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
unit CodyMiscOptsFrame;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LazUtils
FileUtil,
// LCL
LResources, Forms, Controls, StdCtrls, ComCtrls,
// LazControls
DividerBevel,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, LazIDEIntf,
// CodeTools
FileProcs, CodyOpts, CodyIdentifiersDlg, CodyStrConsts;
type
{ TCodyMiscOptionsFrame }
TCodyMiscOptionsFrame = class(TAbstractIDEOptionsEditor)
UDDividerBevel: TDividerBevel;
UDLoadDelayLabel: TLabel;
UDLoadDelayTrackBar: TTrackBar;
UDSaveButton: TButton;
UDSaveIntervalLabel: TLabel;
UDSaveIntervalTrackBar: TTrackBar;
procedure UDLoadDelayTrackBarChange(Sender: TObject);
procedure UDSaveButtonClick(Sender: TObject);
procedure UDSaveIntervalTrackBarChange(Sender: TObject);
private
FOldOptions: TCodyMiscOptions;
FLoaded: boolean;
fSaved: boolean;
procedure GatherOptions(Options: TCodyMiscOptions);
function UDLoadDelayToTrackbarPos(Seconds: integer): integer;
function UDSaveIntervalToTrackbarPos(Seconds: integer): integer;
function SecondsToStr(Seconds: integer): string;
procedure UDUpdateLoadDelayInfo;
procedure UDUpdateSaveIntervalInfo;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function GetTitle: String; override;
procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure RestoreSettings({%H-}AOptions: TAbstractIDEOptions); override;
property OldOptions: TCodyMiscOptions read FOldOptions;
end;
const
UDLoadDelayTrackbarValues: array[0..9] of integer = (
// 0,1,2,3,4, 5, 6, 7, 8, 9
0,1,2,3,5,10,30,60,120,300
);
UDSaveIntervalTrackbarValues: array[0..7] of integer = (
// 0, 1, 2, 3, 4, 5, 6, 7
10,20,60,120,300,600,1800,3600
);
implementation
{ TCodyMiscOptionsFrame }
procedure TCodyMiscOptionsFrame.UDSaveButtonClick(Sender: TObject);
begin
// make sure the old db is loaded
CodyUnitDictionary.Load;
CodyUnitDictionary.Save;
end;
procedure TCodyMiscOptionsFrame.UDSaveIntervalTrackBarChange(Sender: TObject);
begin
if not FLoaded then exit;
CodyUnitDictionary.SaveIntervalInS:=UDSaveIntervalTrackbarValues[UDSaveIntervalTrackBar.Position];
UDUpdateSaveIntervalInfo;
end;
procedure TCodyMiscOptionsFrame.UDLoadDelayTrackBarChange(Sender: TObject);
begin
if not FLoaded then exit;
CodyUnitDictionary.LoadAfterStartInS:=UDLoadDelayTrackbarValues[UDLoadDelayTrackBar.Position];
UDUpdateLoadDelayInfo;
end;
function TCodyMiscOptionsFrame.UDLoadDelayToTrackbarPos(Seconds: integer
): integer;
begin
Result:=low(UDLoadDelayTrackbarValues);
while (Seconds>UDLoadDelayTrackbarValues[Result])
and (Result<High(UDLoadDelayTrackbarValues)) do
inc(Result);
end;
procedure TCodyMiscOptionsFrame.GatherOptions(Options: TCodyMiscOptions);
begin
Options.UDLoadDelayInS:=CodyUnitDictionary.LoadAfterStartInS;
Options.UDSaveIntervalInS:=CodyUnitDictionary.SaveIntervalInS;
end;
function TCodyMiscOptionsFrame.UDSaveIntervalToTrackbarPos(Seconds: integer
): integer;
begin
Result:=low(UDSaveIntervalTrackbarValues);
while (Seconds>UDSaveIntervalTrackbarValues[Result])
and (Result<High(UDSaveIntervalTrackbarValues)) do
inc(Result);
end;
function TCodyMiscOptionsFrame.SecondsToStr(Seconds: integer): string;
begin
if Seconds>=60 then
Result:=Format(crsMinutes, [IntToStr(Seconds div 60)])
else
Result:=Format(crsSeconds, [IntToStr(Seconds)]);
end;
procedure TCodyMiscOptionsFrame.UDUpdateLoadDelayInfo;
begin
UDLoadDelayLabel.Caption:=Format(crsLoadDictionaryAfter, [SecondsToStr(
CodyUnitDictionary.LoadAfterStartInS)]);
end;
procedure TCodyMiscOptionsFrame.UDUpdateSaveIntervalInfo;
begin
UDSaveIntervalLabel.Caption:=Format(crsSaveDictionaryEvery, [SecondsToStr(
CodyUnitDictionary.SaveIntervalInS)]);
end;
constructor TCodyMiscOptionsFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
UDDividerBevel.Caption:=crsUnitIdentifierDictionary;
FOldOptions:=TCodyMiscOptions.Create;
end;
destructor TCodyMiscOptionsFrame.Destroy;
begin
FreeAndNil(FOldOptions);
inherited Destroy;
end;
function TCodyMiscOptionsFrame.GetTitle: String;
begin
Result:=crsIDEIntegration;
end;
procedure TCodyMiscOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions
);
begin
if not (AOptions is SupportedOptionsClass) then exit;
if FLoaded then exit;
FLoaded:=true;
GatherOptions(OldOptions);
UDLoadDelayTrackBar.Position:=UDLoadDelayToTrackbarPos(CodyUnitDictionary.LoadAfterStartInS);
UDUpdateLoadDelayInfo;
UDSaveIntervalTrackBar.Position:=UDSaveIntervalToTrackbarPos(CodyUnitDictionary.SaveIntervalInS);
UDUpdateSaveIntervalInfo;
end;
procedure TCodyMiscOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog
);
begin
UDLoadDelayTrackBar.ShowHint:=true;
UDLoadDelayTrackBar.Hint:=crsTheDictionaryIsLoadedOnDemandOrAfterThisTime;
UDLoadDelayTrackBar.Min:=Low(UDLoadDelayTrackbarValues);
UDLoadDelayTrackBar.Max:=High(UDLoadDelayTrackbarValues);
UDSaveIntervalTrackBar.ShowHint:=true;
UDSaveIntervalTrackBar.Hint:=crsTheDictionaryIsSavedInIntervals;
UDSaveIntervalTrackBar.Min:=Low(UDSaveIntervalTrackbarValues);
UDSaveIntervalTrackBar.Max:=High(UDSaveIntervalTrackbarValues);
UDSaveButton.Caption:=crsSaveDictionaryNow;
UDSaveButton.ShowHint:=true;
UDSaveButton.Hint:=Format(crsSaveToFile, [CodyUnitDictionary.GetFilename]);
end;
class function TCodyMiscOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result:=TAbstractIDEEnvironmentOptions;
end;
procedure TCodyMiscOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions
);
begin
if not (AOptions is SupportedOptionsClass) then exit;
if fSaved then exit;
fSaved:=true;
GatherOptions(CodyOptions);
CodyOptions.SaveSafe;
end;
procedure TCodyMiscOptionsFrame.RestoreSettings(
AOptions: TAbstractIDEOptions);
begin
if not (AOptions is SupportedOptionsClass) then exit;
CodyUnitDictionary.LoadAfterStartInS:=OldOptions.UDLoadDelayInS;
CodyUnitDictionary.SaveIntervalInS:=OldOptions.UDSaveIntervalInS;
end;
{$R *.lfm}
end.
|