Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMCO: Improved on tab click functionality #68

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/resources/emco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ function EMCO:removeTab(tabName)
if self.allTab and self.allTabName then
self:switchTab(self.allTabName)
else
self:switchTab(self.consoles[1])
self:cycleTab()
end
end
table.remove(self.consoles, table.index_of(self.consoles, tabName))
Expand Down Expand Up @@ -669,7 +669,7 @@ end
function EMCO:switchTab(tabName)
local oldTab = self.currentTab
self.currentTab = tabName
if oldTab ~= tabName and oldTab ~= "" then
if oldTab ~= tabName and oldTab ~= "" and self.mc[oldTab] then
self.mc[oldTab]:hide()
self:adjustTabBackground(oldTab)
self.tabs[oldTab]:echo(oldTab, self.inactiveTabFGColor)
Expand Down Expand Up @@ -706,6 +706,17 @@ function EMCO:cycleTab(reverse)
self:switchTab(consoles[cycleIndex])
end

--- Handles the click on a tab, by default left click changes the tab, middle click removes it
-- @param tabName string the name of the tab to show
-- @param mouseClickEvent A table passed in when called by setClickCallback
function EMCO:handleTabClick(tabName, onClickEvent)
if onClickEvent.button == "LeftButton" then
self:switchTab(tabName)
elseif onClickEvent.button == "MidButton" then
self:removeTab(tabName)
end
end

function EMCO:createComponentsForTab(tabName)
local tab = Geyser.Label:new({name = string.format("%sTab%s", self.name, tabName)}, self.tabBox)
if self.tabFont then
Expand All @@ -716,7 +727,7 @@ function EMCO:createComponentsForTab(tabName)
tab:setItalics(self.tabItalics)
tab:setBold(self.tabBold)
tab:setUnderline(self.tabUnderline)
tab:setClickCallback(self.switchTab, self, tabName)
tab:setClickCallback(self.handleTabClick, self, tabName)
self.tabs[tabName] = tab
self:adjustTabBackground(tabName)
tab:echo(tabName, self.inactiveTabFGColor)
Expand Down
Loading