Skip to content
Permalink
Browse files

Always use an empty query tab for loading an sql file. Don't load con…

…tents into a currently non-empty tab. Closes #270.
  • Loading branch information
ansgarbecker committed Nov 10, 2019
1 parent 30f54a5 commit 66ebbca8126b433a0d9c9d9d63766fac43f470c0
Showing with 9 additions and 14 deletions.
  1. +9 −14 source/main.pas
@@ -858,7 +858,7 @@ TMainForm = class(TExtForm)
function GetMainTabAt(X, Y: Integer): Integer;
procedure FixQueryTabCloseButtons;
function ActiveQueryTab: TQueryTab;
function ActiveOrEmptyQueryTab(ConsiderActiveTab: Boolean): TQueryTab;
function GetOrCreateEmptyQueryTab: TQueryTab;
function GetQueryTabByNumber(Number: Integer): TQueryTab;
function GetQueryTabByHelpers(FindTree: TBaseVirtualTree): TQueryTab;
function ActiveQueryMemo: TSynMemo;
@@ -2169,7 +2169,7 @@ procedure TMainForm.AfterFormCreate;
// Load SQL file(s) by command line
if not RunQueryFiles(FileNames, nil, false) then begin
for i:=0 to FileNames.Count-1 do begin
Tab := ActiveOrEmptyQueryTab(False);
Tab := GetOrCreateEmptyQueryTab;
Tab.LoadContents(FileNames[i], True, nil);
if i = FileNames.Count-1 then
SetMainTab(Tab.TabSheet);
@@ -2309,7 +2309,7 @@ function TMainForm.RestoreTabs: Boolean;
// Both of them may not exist.
if not BackupFilename.IsEmpty then begin
if FileExists(BackupFilename) then begin
Tab := ActiveOrEmptyQueryTab(False);
Tab := GetOrCreateEmptyQueryTab;
Tab.Uid := Section;
Tab.LoadContents(BackupFilename, True, TEncoding.UTF8);
Tab.MemoFilename := Filename;
@@ -2324,7 +2324,7 @@ function TMainForm.RestoreTabs: Boolean;
end;
end else if not Filename.IsEmpty then begin
if FileExists(Filename) then begin
Tab := ActiveOrEmptyQueryTab(False);
Tab := GetOrCreateEmptyQueryTab;
Tab.Uid := Section;
Tab.LoadContents(Filename, True, nil);
Tab.MemoFilename := Filename;
@@ -3699,7 +3699,6 @@ procedure TMainForm.actLoadSQLExecute(Sender: TObject);
Dialog: TOpenTextFileDialog;
Encoding: TEncoding;
Tab: TQueryTab;
ConsiderActiveTab: Boolean;
begin
AppSettings.ResetPath;
Dialog := TOpenTextFileDialog.Create(Self);
@@ -3711,10 +3710,8 @@ procedure TMainForm.actLoadSQLExecute(Sender: TObject);
if Dialog.Execute then begin
Encoding := GetEncodingByName(Dialog.Encodings[Dialog.EncodingIndex]);
if not RunQueryFiles(Dialog.Files, Encoding, Sender=actRunSQL) then begin
ConsiderActiveTab := True;
for i:=0 to Dialog.Files.Count-1 do begin
Tab := ActiveOrEmptyQueryTab(ConsiderActiveTab);
ConsiderActiveTab := False;
Tab := GetOrCreateEmptyQueryTab;
Tab.LoadContents(Dialog.Files[i], True, Encoding);
if i = Dialog.Files.Count-1 then
SetMainTab(Tab.TabSheet);
@@ -4728,7 +4725,7 @@ procedure TMainform.popupQueryLoadClick(Sender: TObject);
FileList := TStringList.Create;
FileList.Add(Filename);
if not RunQueryFiles(FileList, nil, false) then begin
Tab := ActiveOrEmptyQueryTab(True);
Tab := GetOrCreateEmptyQueryTab;
Tab.LoadContents(Filename, True, nil);
SetMainTab(Tab.TabSheet);
end;
@@ -6534,7 +6531,7 @@ procedure TMainForm.SynMemoQueryDropFiles(Sender: TObject; X, Y: Integer;
// query-memo - load their contents into seperate tabs
if not RunQueryFiles(AFiles, nil, False) then begin
for i:=0 to AFiles.Count-1 do begin
Tab := ActiveOrEmptyQueryTab(False);
Tab := GetOrCreateEmptyQueryTab;
Tab.LoadContents(AFiles[i], False, nil);
end;
end;
@@ -11239,7 +11236,7 @@ function TMainForm.ActiveQueryTab: TQueryTab;
end;


function TMainForm.ActiveOrEmptyQueryTab(ConsiderActiveTab: Boolean): TQueryTab;
function TMainForm.GetOrCreateEmptyQueryTab: TQueryTab;
var
i: Integer;
begin
@@ -11248,8 +11245,6 @@ function TMainForm.ActiveOrEmptyQueryTab(ConsiderActiveTab: Boolean): TQueryTab;
// or c) create a new one
// Result should never be nil, unlike in ActiveQueryTab
Result := nil;
if ConsiderActiveTab then
Result := ActiveQueryTab;
if Result = nil then begin
// Search empty tab
for i:=0 to QueryTabs.Count-1 do begin
@@ -11936,7 +11931,7 @@ procedure TMainForm.WMCopyData(var Msg: TWMCopyData);
ParseCommandLine(ParamBlobToStr(Msg.CopyDataStruct.lpData), ConnectionParams, FileNames);
if not RunQueryFiles(FileNames, nil, False) then begin
for i:=0 to FileNames.Count-1 do begin
Tab := ActiveOrEmptyQueryTab(False);
Tab := GetOrCreateEmptyQueryTab;
Tab.LoadContents(FileNames[i], True, nil);
end;
end;

0 comments on commit 66ebbca

Please sign in to comment.
You can’t perform that action at this time.