KPCTabsControl icon indicating copy to clipboard operation
KPCTabsControl copied to clipboard

Support for Button to Close Tabs (x) is Missing?

Open nicolas-miari opened this issue 8 years ago • 4 comments

I've successfully incorporated the framework to my project, gone through the docs, source code and sample project... However, I can't figure out how to close the tabs? The tab buttons themselves seem to only support icon and (editable) text field...

Did I miss something?


EDIT: Looks like I missed this comment in Issue #18 :

This must go along with the "close" button as in Safari, more or less in the location of the icon...

Perhaps these should be treated as separate features? The "Add" button (both in Chrome and Safari) is a floating button at the right end, not associated with any data source item. The "Close" button is part of every tab, and (in Safari) appears on hover. Looks quite independent to me...

nicolas-miari avatar Aug 17 '17 04:08 nicolas-miari

Yes, it is missing. Not much time nowadays unfortunately. PR much welcome!

onekiloparsec avatar Aug 19 '17 23:08 onekiloparsec

I would love to give it a shot. Unfortunately, my code is a personal project on top of my day job :-( If I do find the time, you'll be the first to know ;)

nicolas-miari avatar Aug 21 '17 00:08 nicolas-miari

We are many in that same boat of personal projects on top of day jobs, no worries. :-)

onekiloparsec avatar Aug 22 '17 12:08 onekiloparsec

One quick and dirty solution for me was to modify the "trackMouse" function within the "TabButtonCell.swift" file and add the lines below under the "let location = controlView.convert..." line:

let minX = controlView.subviews[0].frame.origin.x
let minY = controlView.subviews[0].frame.origin.y
let maxX = controlView.subviews[0].frame.origin.x + controlView.subviews[0].bounds.width
let maxY = controlView.subviews[0].frame.origin.y + controlView.subviews[0].bounds.height

if location.x >= minX && location.x <= maxX && location.y >= minY && location.y <= maxY {
    for (key, value) in controlView.superview!.subviews.enumerated() {
        if controlView == value {
            var notification:Notification = Notification(name:  NSNotification.Name(rawValue: "close_tab_from_x"))
            let userInfo:[String:String] = ["tab_to_close": String(key)]
            notification.userInfo = userInfo
            NotificationCenter.default.post(notification)
        }
    }
}

When the user clicks on the tab's icon the "close_tab_from_x" notification is being dispatched with the ID of the tab, then somewhere else I listed for that notification and handle the tab closing thing (remove the tab from the data source then call the reloadTabs() method)

So perhaps the only thing that needs to be done is to send a notification when clicking on the icon and let the developers handle this event themselves.

alex-techlab avatar Nov 27 '17 13:11 alex-techlab