mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Add some safer logic to find out if a given tab is a query tab
This commit is contained in:
@ -699,6 +699,7 @@ type
|
|||||||
function ActiveQueryHelpers: TTntListBox;
|
function ActiveQueryHelpers: TTntListBox;
|
||||||
function ActiveQueryTabset: TTabset;
|
function ActiveQueryTabset: TTabset;
|
||||||
function QueryTabActive: Boolean;
|
function QueryTabActive: Boolean;
|
||||||
|
function IsQueryTab(PageIndex: Integer; IncludeFixed: Boolean): Boolean;
|
||||||
procedure popupMainTabsPopup(Sender: TObject);
|
procedure popupMainTabsPopup(Sender: TObject);
|
||||||
private
|
private
|
||||||
ReachedEOT : Boolean;
|
ReachedEOT : Boolean;
|
||||||
@ -3752,7 +3753,7 @@ begin
|
|||||||
viewdata(Sender);
|
viewdata(Sender);
|
||||||
if DataGrid.CanFocus then
|
if DataGrid.CanFocus then
|
||||||
DataGrid.SetFocus;
|
DataGrid.SetFocus;
|
||||||
end else if QueryTabActive then begin
|
end else if IsQueryTab(tab.PageIndex, True) then begin
|
||||||
ActiveQueryMemo.SetFocus;
|
ActiveQueryMemo.SetFocus;
|
||||||
ActiveQueryMemo.WordWrap := actQueryWordWrap.Checked;
|
ActiveQueryMemo.WordWrap := actQueryWordWrap.Checked;
|
||||||
SynMemoQueryStatusChange(ActiveQueryMemo, []);
|
SynMemoQueryStatusChange(ActiveQueryMemo, []);
|
||||||
@ -4181,7 +4182,7 @@ begin
|
|||||||
actQueryWordWrap.Enabled := QueryTabActive;
|
actQueryWordWrap.Enabled := QueryTabActive;
|
||||||
actClearQueryEditor.Enabled := QueryTabActive and NotEmpty;
|
actClearQueryEditor.Enabled := QueryTabActive and NotEmpty;
|
||||||
actSetDelimiter.Enabled := QueryTabActive;
|
actSetDelimiter.Enabled := QueryTabActive;
|
||||||
actCloseQueryTab.Enabled := PageControlMain.ActivePageIndex > tabQuery.PageIndex;
|
actCloseQueryTab.Enabled := IsQueryTab(PageControlMain.ActivePageIndex, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -9205,10 +9206,12 @@ end;
|
|||||||
procedure TMainForm.popupMainTabsPopup(Sender: TObject);
|
procedure TMainForm.popupMainTabsPopup(Sender: TObject);
|
||||||
var
|
var
|
||||||
aPoint: TPoint;
|
aPoint: TPoint;
|
||||||
|
PageIndex: Integer;
|
||||||
begin
|
begin
|
||||||
// Detect if there is a tab under mouse position
|
// Detect if there is a tab under mouse position
|
||||||
aPoint := PageControlMain.ScreenToClient(popupMainTabs.PopupPoint);
|
aPoint := PageControlMain.ScreenToClient(popupMainTabs.PopupPoint);
|
||||||
menuCloseTab.Enabled := GetMainTabAt(aPoint.X, aPoint.Y) > tabQuery.PageIndex;
|
PageIndex := GetMainTabAt(aPoint.X, aPoint.Y);
|
||||||
|
menuCloseTab.Enabled := IsQueryTab(PageIndex, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -9216,7 +9219,7 @@ procedure TMainForm.CloseQueryTab(PageIndex: Integer);
|
|||||||
var
|
var
|
||||||
NewPageIndex: Integer;
|
NewPageIndex: Integer;
|
||||||
begin
|
begin
|
||||||
if PageIndex <= tabQuery.PageIndex then
|
if not IsQueryTab(PageIndex, False) then
|
||||||
Exit;
|
Exit;
|
||||||
FGridResults.Delete(PageIndex-tabData.PageIndex);
|
FGridResults.Delete(PageIndex-tabData.PageIndex);
|
||||||
// Work around bugs in ComCtrls.TPageControl.RemovePage
|
// Work around bugs in ComCtrls.TPageControl.RemovePage
|
||||||
@ -9347,7 +9350,7 @@ function TMainForm.QueryControl(PageIndex: Integer; Base: TControl): TControl;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
begin
|
begin
|
||||||
if (PageIndex < tabQuery.PageIndex) or (PageIndex >= PageControlMain.PageCount) then
|
if not IsQueryTab(PageIndex, True) then
|
||||||
Raise Exception.Create(PageControlMain.Pages[PageIndex].Name+' is not a Query tab.');
|
Raise Exception.Create(PageControlMain.Pages[PageIndex].Name+' is not a Query tab.');
|
||||||
Result := nil;
|
Result := nil;
|
||||||
FindChild(PageControlMain.Pages[PageIndex]);
|
FindChild(PageControlMain.Pages[PageIndex]);
|
||||||
@ -9420,7 +9423,17 @@ end;
|
|||||||
function TMainForm.QueryTabActive: Boolean;
|
function TMainForm.QueryTabActive: Boolean;
|
||||||
begin
|
begin
|
||||||
// Find out if the active main tab is a query tab
|
// Find out if the active main tab is a query tab
|
||||||
Result := PageControlMain.ActivePage.PageIndex >= tabQuery.PageIndex;
|
Result := IsQueryTab(PageControlMain.ActivePageIndex, True);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMainForm.IsQueryTab(PageIndex: Integer; IncludeFixed: Boolean): Boolean;
|
||||||
|
var
|
||||||
|
Min: Integer;
|
||||||
|
begin
|
||||||
|
// Find out if the given main tab is a query tab
|
||||||
|
Min := tabQuery.PageIndex+1;
|
||||||
|
if IncludeFixed then Dec(Min);
|
||||||
|
Result := PageIndex >= Min;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Reference in New Issue
Block a user