@@ -15,9 +15,11 @@ interface
1515 TfrmExtFileDialog = class (TExtForm)
1616 btnCancel: TButton;
1717 btnOk: TButton;
18+ comboLineBreaks: TComboBox;
1819 comboEncoding: TComboBox;
1920 comboFileType: TComboBox;
2021 editFilename: TEdit;
22+ lblLinebreaks: TLabel;
2123 lblEncoding: TLabel;
2224 lblFilename: TLabel;
2325 pnlBottom: TPanel;
@@ -26,6 +28,8 @@ TfrmExtFileDialog = class(TExtForm)
2628 splitterMain: TSplitter;
2729 procedure comboEncodingChange (Sender: TObject);
2830 procedure comboFileTypeChange (Sender: TObject);
31+ procedure comboLineBreaksChange (Sender: TObject);
32+ procedure FormCloseQuery (Sender: TObject; var CanClose: Boolean);
2933 procedure FormCreate (Sender: TObject);
3034 procedure FormDestroy (Sender: TObject);
3135 procedure FormShow (Sender: TObject);
@@ -39,31 +43,39 @@ TfrmExtFileDialog = class(TExtForm)
3943 FFilterMasks: TStringList;
4044 FDefaultExt: String;
4145 FEncodings: TStringList;
42- FEncodingIndex: Cardinal;
46+ FEncodingIndex: Integer;
47+ FLineBreakIndex: TLineBreaks;
4348 FOptions: TOpenOptions;
4449 FFiles: TStringList;
50+ procedure SetTitle (AValue: String);
4551 function GetFileName : String;
4652 procedure SetFileName (const AValue: String);
4753 procedure SetInitialDir (const AValue: String);
4854 public
55+ property Title: String write SetTitle;
4956 function Execute : Boolean;
5057 procedure AddFileType (FileMask, DisplayName: String);
5158 property FileName: String read GetFileName write SetFileName;
5259 property InitialDir: String read FInitialDir write SetInitialDir;
5360 class var PreviousDir: String;
5461 property DefaultExt: String read FDefaultExt write FDefaultExt;
55- property Encodings: TStringList read FEncodings write FEncodings;
56- property EncodingIndex: Cardinal read FEncodingIndex write FEncodingIndex;
5762 property Options: TOpenOptions read FOptions write FOptions;
5863 property Files: TStringList read FFiles;
59-
6064 end ;
6165
6266 // File-open-dialog with encoding selector
6367 TExtFileOpenDialog = class (TfrmExtFileDialog)
6468 procedure FormCreate (Sender: TObject); overload;
69+ public
70+ property Encodings: TStringList read FEncodings write FEncodings;
71+ property EncodingIndex: Integer read FEncodingIndex write FEncodingIndex;
6572 end ;
6673
74+ TExtFileSaveDialog = class (TfrmExtFileDialog)
75+ procedure FormCreate (Sender: TObject); overload;
76+ public
77+ property LineBreakIndex: TLineBreaks read FLineBreakIndex write FLineBreakIndex;
78+ end ;
6779
6880implementation
6981
@@ -89,11 +101,19 @@ procedure TfrmExtFileDialog.FormCreate(Sender: TObject);
89101 FFilterNames := TStringList.Create;
90102 FFilterMasks := TStringList.Create;
91103 FEncodings := TStringList.Create;
104+ { $IFDEF LINUX}
105+ FLineBreakIndex := lbsUnix;
106+ { $ENDIF}
107+ { $IFDEF WINDOWS}
108+ FLineBreakIndex := lbsWindows;
109+ { $ENDIF}
110+ { $IFDEF DARWIN}
111+ FLineBreakIndex := lbsMac;
112+ { $ENDIF}
92113 FFiles := TStringList.Create;
93114 comboFileType.Items.Clear;
94115 editFilename.Text := ' ' ;
95- lblEncoding.Enabled := False;
96- comboEncoding.Enabled := False;
116+ comboLineBreaks.Items.Clear;
97117end ;
98118
99119procedure TfrmExtFileDialog.FormDestroy (Sender: TObject);
@@ -106,10 +126,12 @@ procedure TfrmExtFileDialog.FormDestroy(Sender: TObject);
106126end ;
107127
108128procedure TfrmExtFileDialog.FormShow (Sender: TObject);
129+ var
130+ LineBreakIndexInt: Integer;
109131begin
110132 ShellListView.MultiSelect := ofAllowMultiSelect in FOptions;
111133 ShellTreeView.Enabled := not (ofNoChangeDir in FOptions);
112- // Todo: support ofOverwritePrompt, ofFileMustExist
134+ // Todo: support ofFileMustExist and convert usages of TOpenDialog and TSaveDialog
113135 if FInitialDir.IsEmpty then begin
114136 if not PreviousDir.IsEmpty then
115137 SetInitialDir(PreviousDir)
@@ -123,6 +145,13 @@ procedure TfrmExtFileDialog.FormShow(Sender: TObject);
123145 comboEncoding.Items.AddStrings(FEncodings, True);
124146 if (FEncodingIndex >=0 ) and (FEncodingIndex < comboEncoding.Items.Count) then
125147 comboEncoding.ItemIndex := FEncodingIndex;
148+
149+ comboLineBreaks.Items.Add(_(' Windows linebreaks' ));
150+ comboLineBreaks.Items.Add(_(' UNIX linebreaks' ));
151+ comboLineBreaks.Items.Add(_(' Mac OS linebreaks' ));
152+ LineBreakIndexInt := Integer(FLineBreakIndex)-1 ; // we skip lbsNone
153+ if (LineBreakIndexInt >=0 ) and (LineBreakIndexInt < comboLineBreaks.Items.Count) then
154+ comboLineBreaks.ItemIndex := LineBreakIndexInt;
126155end ;
127156
128157procedure TfrmExtFileDialog.comboFileTypeChange (Sender: TObject);
@@ -136,6 +165,36 @@ procedure TfrmExtFileDialog.comboFileTypeChange(Sender: TObject);
136165 ShellListView.Mask := FileMask;
137166end ;
138167
168+ procedure TfrmExtFileDialog.comboLineBreaksChange (Sender: TObject);
169+ begin
170+ case comboLineBreaks.ItemIndex of
171+ 0 : FLineBreakIndex := lbsWindows;
172+ 1 : FLineBreakIndex := lbsUnix;
173+ 2 : FLineBreakIndex := lbsMac;
174+ end ;
175+ end ;
176+
177+ procedure TfrmExtFileDialog.FormCloseQuery (Sender: TObject;
178+ var CanClose: Boolean);
179+ begin
180+ CanClose := True;
181+ if ModalResult = mrOK then begin
182+
183+ if FileName.IsEmpty then begin
184+ CanClose := False;
185+ end ;
186+
187+ if (not FileName.IsEmpty) and (Self is TExtFileSaveDialog) and (ofOverwritePrompt in FOptions) then begin
188+ case MessageDialog(f_(' File already exists: %s' +sLineBreak+sLineBreak+' Overwrite it?' , [FileName]), mtConfirmation, [mbYes, mbNo]) of
189+ mrNo: begin
190+ CanClose := False;
191+ end ;
192+ end ;
193+ end ;
194+
195+ end ;
196+ end ;
197+
139198procedure TfrmExtFileDialog.comboEncodingChange (Sender: TObject);
140199begin
141200 FEncodingIndex := comboEncoding.ItemIndex;
@@ -168,10 +227,17 @@ procedure TfrmExtFileDialog.ShellListViewSelectItem(Sender: TObject;
168227 end ;
169228end ;
170229
230+ procedure TfrmExtFileDialog.SetTitle (AValue: String);
231+ begin
232+ Caption := AValue;
233+ end ;
234+
171235function TfrmExtFileDialog.GetFileName : String;
172236begin
173237 if ShellListView.Selected <> nil then
174238 Result := ShellListView.GetPathFromItem(ShellListView.Selected)
239+ else if (editFilename.Text <> ' ' ) and (ShellTreeView.Selected <> nil ) then
240+ Result := ShellTreeView.Path + editFilename.Text
175241 else
176242 Result := ' ' ;
177243end ;
@@ -198,10 +264,19 @@ procedure TfrmExtFileDialog.SetInitialDir(const AValue: String);
198264procedure TExtFileOpenDialog.FormCreate (Sender: TObject);
199265begin
200266 inherited ;
201- lblEncoding.Enabled := True;
202- comboEncoding.Enabled := True;
267+ lblEncoding.Visible := True;
268+ comboEncoding.Visible := True;
203269end ;
204270
205271
272+ { TExtFileSaveDialog }
273+
274+ procedure TExtFileSaveDialog.FormCreate (Sender: TObject);
275+ begin
276+ inherited ;
277+ lblLinebreaks.Visible := True;
278+ comboLineBreaks.Visible := True;
279+ end ;
280+
206281end .
207282
0 commit comments