Follow up to rev 1169: Add a more eye catching and user friendly solution to export to a directory.

- Add a fourth radiobutton + edit + button labeled "Directory" below the "File" option
- Code just uses that new option just like the File option. Only differentiate in the InitFileStream method.
- The SelectDirectory() method expects the unit FileCtrl in the USES clause. Silence a relevant compiler warning about usage of platform specific units - we will never compile anything else than a Win32 app here.
This commit is contained in:
Ansgar Becker
2007-12-12 21:42:49 +00:00
parent 4793d275cd
commit 4e731b7fe5
4 changed files with 205 additions and 99 deletions

View File

@ -50,10 +50,10 @@
<Compiler Name="DefaultNamespace"></Compiler>
<Compiler Name="SymbolDeprecated">True</Compiler>
<Compiler Name="SymbolLibrary">True</Compiler>
<Compiler Name="SymbolPlatform">True</Compiler>
<Compiler Name="SymbolPlatform">False</Compiler>
<Compiler Name="SymbolExperimental">True</Compiler>
<Compiler Name="UnitLibrary">True</Compiler>
<Compiler Name="UnitPlatform">True</Compiler>
<Compiler Name="UnitPlatform">False</Compiler>
<Compiler Name="UnitDeprecated">True</Compiler>
<Compiler Name="UnitExperimental">True</Compiler>
<Compiler Name="HResultCompat">True</Compiler>

View File

@ -46,6 +46,8 @@
<DCC_IncludePath>$(BDS)\RaveReports\Lib;$(BDS)\lib\Debug;$(BDS)\Lib\Debug\Indy10;..\..\components\compilerdetection\include;..\..\components\heidisql\include;..\..\components\edbimage\build;..\..\components\heidisql\build;..\..\components\synedit\build;..\..\components\synedit\resources;..\..\components\zeosdbo\build;..\..\components\virtualtreeview\build;..\..\components\virtualtreeview\resources;..\..\components\tntunictrls\build</DCC_IncludePath>
<DCC_Define>DEBUG</DCC_Define>
<DCC_Description>HeidiSQL</DCC_Description>
<DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
<DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality</Borland.Personality>

View File

@ -146,16 +146,16 @@ object ExportSQLForm: TExportSQLForm
Left = 235
Top = 0
Width = 376
Height = 169
Height = 200
Anchors = [akLeft, akTop, akRight]
Caption = 'Output'
TabOrder = 0
DesignSize = (
376
169)
200)
object btnFileBrowse: TBitBtn
Left = 338
Top = 43
Left = 344
Top = 42
Width = 22
Height = 22
Anchors = [akTop, akRight]
@ -165,16 +165,16 @@ object ExportSQLForm: TExportSQLForm
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000010000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
777777777777777777777000000000007777700333333333077770B033333333
307770FB03333333330770BFB0333333333070FBFB000000000070BFBFBFBFB0
777770FBFBFBFBF0777770BFB000000077777700077777777000777777777777
7700777777777077707077777777770007777777777777777777}
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00DDDDDDDDDDDD
DDDDDDDDDDDDDDDDDDDD00000000000DDDDD003333333330DDDD0B0333333333
0DDD0FB03333333330DD0BFB03333333330D0FBFB000000000000BFBFBFBFB0D
DDDD0FBFBFBFBF0DDDDD0BFB0000000DDDDDD000DDDDDDDD000DDDDDDDDDDDDD
D00DDDDDDDDD0DDD0D0DDDDDDDDDD000DDDDDDDDDDDDDDDDDDDD}
end
object editFileName: TEdit
Left = 32
Left = 26
Top = 42
Width = 304
Width = 318
Height = 21
Anchors = [akLeft, akTop, akRight]
ParentShowHint = False
@ -183,62 +183,30 @@ object ExportSQLForm: TExportSQLForm
OnDblClick = btnFileBrowseClick
end
object radioOtherDatabase: TRadioButton
Left = 16
Top = 69
Left = 9
Top = 110
Width = 113
Height = 17
Caption = 'Another database:'
TabOrder = 3
TabOrder = 6
OnClick = radioOtherDatabaseClick
end
object radioFile: TRadioButton
Left = 16
Top = 24
Left = 9
Top = 25
Width = 49
Height = 17
Caption = 'File:'
Checked = True
TabOrder = 0
TabStop = True
OnClick = radioFileClick
OnClick = radioFileOrDirClick
OnDblClick = btnFileBrowseClick
end
object comboOtherDatabase: TComboBox
Left = 32
Top = 87
Width = 328
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
Color = clBtnFace
Enabled = False
ItemHeight = 13
TabOrder = 4
end
object radioOtherHost: TRadioButton
Left = 16
Top = 116
Width = 161
Height = 17
Caption = 'Another host and database'
TabOrder = 5
OnClick = radioOtherHostClick
end
object comboOtherHost: TComboBox
Left = 32
Top = 131
Width = 137
Height = 21
Style = csDropDownList
Color = clBtnFace
Enabled = False
ItemHeight = 13
TabOrder = 6
OnSelect = comboOtherHostSelect
end
object comboOtherHostDatabase: TComboBox
Left = 175
Top = 131
Width = 183
Left = 26
Top = 127
Width = 340
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
@ -247,12 +215,85 @@ object ExportSQLForm: TExportSQLForm
ItemHeight = 13
TabOrder = 7
end
object radioOtherHost: TRadioButton
Left = 9
Top = 152
Width = 161
Height = 17
Caption = 'Another host and database'
TabOrder = 8
OnClick = radioOtherHostClick
end
object comboOtherHost: TComboBox
Left = 26
Top = 169
Width = 137
Height = 21
Style = csDropDownList
Color = clBtnFace
Enabled = False
ItemHeight = 13
TabOrder = 9
OnSelect = comboOtherHostSelect
end
object comboOtherHostDatabase: TComboBox
Left = 168
Top = 169
Width = 198
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
Color = clBtnFace
Enabled = False
ItemHeight = 13
TabOrder = 10
end
object radioDirectory: TRadioButton
Left = 9
Top = 67
Width = 352
Height = 17
Caption = 'Directory (one .sql-file per object)'
TabOrder = 3
OnClick = radioFileOrDirClick
OnDblClick = btnDirectoryBrowseClick
end
object editDirectory: TEdit
Left = 26
Top = 85
Width = 318
Height = 21
Anchors = [akLeft, akTop, akRight]
Color = clBtnFace
Enabled = False
TabOrder = 4
OnDblClick = btnDirectoryBrowseClick
end
object btnDirectoryBrowse: TBitBtn
Left = 344
Top = 85
Width = 22
Height = 22
Anchors = [akTop, akRight]
Enabled = False
TabOrder = 5
OnClick = btnDirectoryBrowseClick
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000010000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00DDDDDDDDDDDD
DDDDDDDDDDDDDDDDDDDD00000000000DDDDD003333333330DDDD0B0333333333
0DDD0FB03333333330DD0BFB03333333330D0FBFB000000000000BFBFBFBFB0D
DDDD0FBFBFBFBF0DDDDD0BFB0000000DDDDDD000DDDDDDDD000DDDDDDDDDDDDD
D00DDDDDDDDD0DDD0D0DDDDDDDDDD000DDDDDDDDDDDDDDDDDDDD}
end
end
object groupExampleSql: TGroupBox
Left = 235
Top = 175
Top = 206
Width = 376
Height = 138
Height = 107
Anchors = [akLeft, akTop, akRight, akBottom]
Caption = 'Example SQL'
TabOrder = 1
@ -260,7 +301,7 @@ object ExportSQLForm: TExportSQLForm
Left = 2
Top = 15
Width = 372
Height = 121
Height = 90
Align = alClient
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET

View File

@ -28,7 +28,8 @@ uses
DB,
SynEdit,
SynMemo,
ZDataSet;
ZDataSet,
FileCtrl;
type
TExportSQLForm = class(TForm)
@ -67,6 +68,9 @@ type
cbxData: TCheckBox;
comboData: TComboBox;
comboTargetCompat: TComboBox;
radioDirectory: TRadioButton;
editDirectory: TEdit;
btnDirectoryBrowse: TBitBtn;
procedure comboTargetCompatChange(Sender: TObject);
procedure comboOtherHostSelect(Sender: TObject);
procedure comboDataChange(Sender: TObject);
@ -75,13 +79,14 @@ type
procedure cbxTablesClick(Sender: TObject);
procedure cbxDatabaseClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnDirectoryBrowseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure comboSelectDatabaseChange(Sender: TObject);
procedure CheckListToggle(Sender: TObject);
procedure btnFileBrowseClick(Sender: TObject);
procedure btnExportClick(Sender: TObject);
procedure radioOtherDatabaseClick(Sender: TObject);
procedure radioFileClick(Sender: TObject);
procedure radioFileOrDirClick(Sender: TObject);
procedure fillcombo_anotherdb(Sender: TObject);
procedure generateExampleSQL;
procedure validateRadioControls(Sender: TObject);
@ -132,6 +137,7 @@ const
OUTPUT_FILE = 1;
OUTPUT_DB = 2;
OUTPUT_HOST = 3;
OUTPUT_DIR = 4;
// Default output compatibility
SQL_VERSION_DEFAULT = SQL_VERSION_ANSI;
@ -246,6 +252,7 @@ begin
if Valueexists('CreateDataHow') then comboData.ItemIndex := ReadInteger('CreateDataHow');
if Valueexists('Compatibility') then comboTargetCompat.ItemIndex := ReadInteger('Compatibility');
if Valueexists('exportfilename') then editFileName.Text := ReadString('exportfilename');
if Valueexists('ExportDirectory') then editDirectory.Text := ReadString('ExportDirectory');
if Valueexists('ExportSQL_OutputTo') then
begin
OutputTo := ReadInteger('ExportSQL_OutputTo');
@ -266,11 +273,12 @@ begin
CheckForCrashedWindows;
// Fetch list of heidisql windows.
list := GetWindowList;
if Length(list) < 2 then
if (Length(list) < 2) and (OutputTo = OUTPUT_HOST) then
OutputTo := OUTPUT_FILE;
case OutputTo of
OUTPUT_FILE : radioFile.Checked := true;
OUTPUT_DIR : radioDirectory.Checked := true;
OUTPUT_DB : radioOtherDatabase.Checked := true;
OUTPUT_HOST : radioOtherHost.Checked := true;
end;
@ -440,13 +448,30 @@ end;
}
function TExportSQLForm.InitFileStream(TableName: String; OldStream: TFileStream = nil): TFileStream;
var
ParsedFileName, FileName, FilePath : String;
UnparsedFileName, ParsedFileName, FileName, FilePath : String;
begin
Result := nil;
// File or directory ?
if radioFile.Checked then
UnparsedFileName := EditFileName.Text
else if radioDirectory.Checked then begin
UnparsedFileName := EditDirectory.Text;
// Ensure directory ends with a slash.
// ExtractFilePath() expects a slash at the very end, otherwise the last segment
// will be identified as filename and therefore stripped from the return value
if UnparsedFileName[Length(UnparsedFileName)] <> '\' then
UnparsedFileName := UnparsedFileName + '\';
UnparsedFileName := ExtractFilePath(UnparsedFileName);
UnparsedFileName := UnparsedFileName + TABLENAME_PATTERN + '.sql';
end else begin
Screen.Cursor := crDefault;
Raise Exception.Create('Internal error: InitFileStream called in wrong context.');
end;
// Parse filename
FilePath := ExtractFilePath(EditFileName.Text);
FileName := ExtractFileName(EditFileName.Text);
FilePath := ExtractFilePath(UnparsedFileName);
FileName := ExtractFileName(UnparsedFileName);
FileName := StringReplace(FileName, TABLENAME_PATTERN, TableName, [rfIgnoreCase]);
ParsedFileName := FilePath + GoodFileName(FileName);
@ -533,8 +558,17 @@ begin
end;
begin
// Check for valid directory
if radioDirectory.Checked then begin
if not DirectoryExists(EditDirectory.Text) then begin
MessageDlg('The selected directory "'+EditDirectory.Text+'" does not exist.', mtError, [mbOk], 0);
EditDirectory.SetFocus;
Exit;
end;
end;
// to where?
tofile := radioFile.Checked;
tofile := radioFile.Checked or radioDirectory.Checked;
todb := radioOtherDatabase.Checked;
tohost := radioOtherHost.Checked;
@ -1239,7 +1273,7 @@ begin
generateExampleSql;
end;
procedure TExportSQLForm.radioFileClick(Sender: TObject);
procedure TExportSQLForm.radioFileOrDirClick(Sender: TObject);
begin
validateRadioControls(Sender);
validateControls(Sender);
@ -1313,48 +1347,61 @@ begin
end;
procedure TExportSQLForm.validateRadioControls(Sender: TObject);
const
EnabledColor = clWindow;
DisabledColor = clBtnFace;
var
ControlToFocus : TWinControl;
begin
// Disable all controls ...
EditFileName.Enabled := False;
EditFileName.Color := DisabledColor;
btnFileBrowse.Enabled := False;
EditDirectory.Enabled := False;
EditDirectory.Color := DisabledColor;
btnDirectoryBrowse.Enabled := False;
comboOtherDatabase.Enabled := False;
comboOtherDatabase.Color := DisabledColor;
comboOtherHost.Enabled := False;
comboOtherHost.Color := DisabledColor;
comboOtherHostDatabase.Enabled := False;
comboOtherHostDatabase.Color := DisabledColor;
// Silence compiler warning
ControlToFocus := EditFileName;
// ... and re-enable the selected controlset
if radioFile.Checked then begin
EditFileName.Enabled := true;
EditFileName.Color := clWindow;
btnFileBrowse.Enabled := true;
EditFileName.SetFocus;
end else begin
EditFileName.Enabled := false;
EditFileName.Color := clBtnFace;
btnFileBrowse.Enabled := false;
end;
if radioOtherDatabase.Checked then begin
comboOtherDatabase.Enabled := true;
comboOtherDatabase.Color := clWindow;
if comboOtherDatabase.CanFocus then comboOtherDatabase.SetFocus;
end else begin
comboOtherDatabase.Enabled := false;
comboOtherDatabase.Color := clBtnFace;
end;
if radioOtherHost.Checked then begin
comboOtherHost.Enabled := true;
comboOtherHost.Color := clWindow;
EditFileName.Enabled := True;
EditFileName.Color := EnabledColor;
btnFileBrowse.Enabled := True;
end else if radioDirectory.Checked then begin
EditDirectory.Enabled := True;
EditDirectory.Color := EnabledColor;
btnDirectoryBrowse.Enabled := True;
ControlToFocus := EditDirectory;
end else if radioOtherDatabase.Checked then begin
comboOtherDatabase.Enabled := True;
comboOtherDatabase.Color := EnabledColor;
ControlToFocus := comboOtherDatabase;
end else if radioOtherHost.Checked then begin
comboOtherHost.Enabled := True;
comboOtherHost.Color := EnabledColor;
comboOtherHostDatabase.Enabled := not (cbxStructure.Checked and cbxDatabase.Checked);
comboOtherHostDatabase.Color := clWindow;
if comboOtherHost.CanFocus then comboOtherHost.SetFocus;
end else begin
comboOtherHost.Enabled := false;
comboOtherHost.Color := clBtnFace;
comboOtherHostDatabase.Enabled := false;
comboOtherHostDatabase.Color := clBtnFace;
comboOtherHostDatabase.Color := EnabledColor;
ControlToFocus := comboOtherHost;
end;
if ControlToFocus.CanFocus then
ControlToFocus.SetFocus;
// Disable target selection if exporting to known session.
comboTargetCompat.Enabled := radioFile.Checked;
comboTargetCompat.Enabled := radioFile.Checked or radioDirectory.Checked;
end;
procedure TExportSQLForm.validateControls(Sender: TObject);
begin
cbxDatabase.Enabled := cbxStructure.Checked and ( radioFile.Checked or radioOtherHost.Checked );
comboDatabase.Enabled := cbxStructure.Checked and ( radioFile.Checked or radioOtherHost.Checked ) and cbxDatabase.Checked;
cbxDatabase.Enabled := cbxStructure.Checked and ( radioFile.Checked or radioDirectory.Checked or radioOtherHost.Checked );
comboDatabase.Enabled := cbxStructure.Checked and ( radioFile.Checked or radioDirectory.Checked or radioOtherHost.Checked ) and cbxDatabase.Checked;
comboOtherHostDatabase.Enabled := not cbxDatabase.Checked;
cbxTables.Enabled := cbxStructure.Checked;
@ -1529,8 +1576,11 @@ begin
WriteInteger('CreateDataHow', comboData.ItemIndex);
WriteInteger('Compatibility', comboTargetCompat.ItemIndex);
WriteString('exportfilename', EditFileName.Text);
WriteString('ExportDirectory', EditDirectory.Text);
OutputTo := OUTPUT_FILE;
if radioOtherDatabase.checked then
if radioDirectory.checked then
OutputTo := OUTPUT_DIR
else if radioOtherDatabase.checked then
OutputTo := OUTPUT_DB
else if radioOtherHost.checked then
OutputTo := OUTPUT_HOST;
@ -1542,6 +1592,19 @@ begin
end;
end;
{**
Browse for a directory
}
procedure TExportSQLForm.btnDirectoryBrowseClick(Sender: TObject);
var
chosenDirectory : String;
begin
if SelectDirectory('Select output directory', EditDirectory.Text, chosenDirectory) then
EditDirectory.Text := chosenDirectory;
end;
end.