mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
Issue #1503: switch file-open-dialog for SQL files from TOpenTextFileDialog to newer TFileOpenDialog with better DPI support, and extend it with an encoding selector
This commit is contained in:
@@ -5,7 +5,7 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, Forms, Windows, Messages, System.Types, StdCtrls, Clipbrd,
|
||||
SizeGrip, apphelpers, Vcl.Graphics, Vcl.Dialogs, gnugettext, Vcl.ImgList, Vcl.ComCtrls,
|
||||
ShLwApi, Vcl.ExtCtrls, VirtualTrees, SynRegExpr, Vcl.Controls;
|
||||
ShLwApi, Vcl.ExtCtrls, VirtualTrees, SynRegExpr, Vcl.Controls, Winapi.ShlObj;
|
||||
|
||||
type
|
||||
// Form with a sizegrip in the lower right corner, without the need for a statusbar
|
||||
@@ -30,6 +30,20 @@ type
|
||||
class function ScaleSize(x: Extended; Control: TControl): Integer; overload;
|
||||
end;
|
||||
|
||||
// Modern file-open-dialog with high DPI support and encoding selector
|
||||
TExtFileOpenDialog = class(TFileOpenDialog)
|
||||
private
|
||||
FEncodings: TStringList;
|
||||
FEncodingIndex: Integer;
|
||||
protected
|
||||
procedure DoOnExecute; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Encodings: TStringList read FEncodings write FEncodings;
|
||||
property EncodingIndex: Integer read FEncodingIndex write FEncodingIndex default 0;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
@@ -362,4 +376,48 @@ begin
|
||||
Result := Round(x * Control.ScaleFactor);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ TExtFileOpenDialog }
|
||||
|
||||
constructor TExtFileOpenDialog.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FEncodings := TStringList.Create;
|
||||
end;
|
||||
|
||||
|
||||
destructor TExtFileOpenDialog.Destroy;
|
||||
begin
|
||||
FEncodings.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
procedure TExtFileOpenDialog.DoOnExecute;
|
||||
var
|
||||
iCustomize: IFileDialogCustomize;
|
||||
i: Integer;
|
||||
const
|
||||
idEncodingCombo = 1;
|
||||
begin
|
||||
// Add encodings selector
|
||||
if Dialog.QueryInterface(IFileDialogCustomize, iCustomize) = S_OK then
|
||||
begin
|
||||
iCustomize.StartVisualGroup(0, PChar(_('Encoding:')));
|
||||
try
|
||||
// note other controls available: AddCheckButton, AddEditBox, AddPushButton, AddRadioButtonList...
|
||||
iCustomize.AddComboBox(idEncodingCombo);
|
||||
for i:=0 to FEncodings.Count - 1 do begin
|
||||
iCustomize.AddControlItem(idEncodingCombo, i, PChar(FEncodings[i]));
|
||||
end;
|
||||
iCustomize.SetSelectedControlItem(idEncodingCombo, EncodingIndex);
|
||||
finally
|
||||
iCustomize.EndVisualGroup;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
end.
|
||||
|
||||
@@ -3881,15 +3881,21 @@ end;
|
||||
procedure TMainForm.actLoadSQLExecute(Sender: TObject);
|
||||
var
|
||||
i, ProceedResult: Integer;
|
||||
Dialog: TOpenTextFileDialog;
|
||||
Dialog: TExtFileOpenDialog;
|
||||
FileType: TFileTypeItem;
|
||||
Encoding: TEncoding;
|
||||
Tab: TQueryTab;
|
||||
begin
|
||||
AppSettings.ResetPath;
|
||||
Dialog := TOpenTextFileDialog.Create(Self);
|
||||
Dialog.Options := Dialog.Options + [ofAllowMultiSelect];
|
||||
Dialog.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*';
|
||||
Dialog.DefaultExt := 'sql';
|
||||
Dialog := TExtFileOpenDialog.Create(Self);
|
||||
Dialog.Options := Dialog.Options + [fdoAllowMultiSelect];
|
||||
FileType := Dialog.FileTypes.Add;
|
||||
FileType.DisplayName := _('SQL files');
|
||||
FileType.FileMask := '*.sql';
|
||||
FileType := Dialog.FileTypes.Add;
|
||||
FileType.DisplayName := _('All files');
|
||||
FileType.FileMask := '*.*';
|
||||
Dialog.DefaultExtension := 'sql';
|
||||
Dialog.Encodings.Assign(FileEncodings);
|
||||
Dialog.EncodingIndex := AppSettings.ReadInt(asFileDialogEncoding, Self.Name);
|
||||
if Dialog.Execute then begin
|
||||
|
||||
Reference in New Issue
Block a user