-
Notifications
You must be signed in to change notification settings - Fork 0
/
DigIt_Destination_SaveFiles_SettingsForm.pas
129 lines (99 loc) · 2.72 KB
/
DigIt_Destination_SaveFiles_SettingsForm.pas
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
unit DigIt_Destination_SaveFiles_SettingsForm;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, EditBtn, Buttons, BCPanel, BCLabel;
type
{ TDest_SaveFiles_Settings }
TDest_SaveFiles_Settings = class(TForm)
BCLabel9: TBCLabel;
BCPanel1: TBCPanel;
btCancel: TBitBtn;
btOk: TBitBtn;
cbSaveFormat: TComboBox;
dirDestination: TDirectoryEdit;
Label6: TLabel;
panelButtons: TBCPanel;
procedure cbSaveFormatChange(Sender: TObject);
procedure dirDestinationChange(Sender: TObject);
private
SaveExt,
SavePath: String;
function UI_FindSaveFormat(AExt: String):Integer;
procedure BuildSaveFormats;
public
class function Execute(var ASaveExt, ASavePath: String): Boolean;
end;
var
Dest_SaveFiles_Settings: TDest_SaveFiles_Settings = nil;
implementation
{$R *.lfm}
uses fpimage;
{ TDest_SaveFiles_Settings }
procedure TDest_SaveFiles_Settings.BuildSaveFormats;
var
i,j :Integer;
t,e:String;
begin
j:=0;
for i :=0 to ImageHandlers.Count-1 do
begin
t :=ImageHandlers.TypeNames[i];
e :=ImageHandlers.Extensions[t];
if (ImageHandlers.ImageWriter[t]<>nil) then
begin
cbSaveFormat.Items.Add(t);
if (Pos('jpg', e)>0) then j:=i;
end;
end;
cbSaveFormat.ItemIndex:=j-1;
SaveExt :='jpg';
end;
function TDest_SaveFiles_Settings.UI_FindSaveFormat(AExt: String): Integer;
var
i:Integer;
begin
Result:=-1;
if (AExt<>'') then
for i:=0 to cbSaveFormat.Items.Count-1 do
begin
if (Pos(AExt, ImageHandlers.Extensions[cbSaveFormat.Items[i]]) > 0) then
begin
Result :=i; break;
end;
end;
end;
procedure TDest_SaveFiles_Settings.cbSaveFormatChange(Sender: TObject);
var
i:Integer;
begin
SaveExt:=ImageHandlers.Extensions[cbSaveFormat.Items[cbSaveFormat.ItemIndex]];
i :=Pos(';', SaveExt);
if (i>0) then SaveExt :=Copy(SaveExt, 1, i-1);
end;
procedure TDest_SaveFiles_Settings.dirDestinationChange(Sender: TObject);
begin
SavePath :=dirDestination.Directory;
//UI_FillTaker;
end;
class function TDest_SaveFiles_Settings.Execute(var ASaveExt, ASavePath: String): Boolean;
begin
if (Dest_SaveFiles_Settings=nil)
then Dest_SaveFiles_Settings :=TDest_SaveFiles_Settings.Create(nil);
with Dest_SaveFiles_Settings do
begin
BuildSaveFormats;
dirDestination.Directory:=ASavePath;
cbSaveFormat.ItemIndex:=UI_FindSaveFormat(ASaveExt);
Result:= (ShowModal=mrOk);
if Result then
begin
ASaveExt:= SaveExt;
ASavePath:= SavePath;
//Last Char of the Path MUST be the Directory Separator
if (ASavePath[Length(ASavePath)] <> DirectorySeparator)
then ASavePath:= ASavePath+DirectorySeparator;
end;
end;
end;
end.