• Command when using close button of notebook tab

    From Alexandru@21:1/5 to All on Mon Mar 14 16:59:49 2022
    How to specify a aommand when using close button of notebook tab?

    I'm using

    scrollutil::addclosetab Closable.TNotebook
    ttk::notebook .notebook -style Closable.TNotebook

    to add nice close buttons to all tabs of a notebook.

    As I could read from the source code of scrollutil, the addclosetab command onöy modifies the style of the tab. I could not find anything close to a -command option or binding.

    The reason for my question: I need control over what happens when the user clicks on that close button.

    Many thanks
    Alexandru

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexandru@21:1/5 to All on Tue Mar 15 01:47:02 2022
    How to specify a command when using close button of notebook tab?

    I'm using

    scrollutil::addclosetab Closable.TNotebook
    ttk::notebook .notebook -style Closable.TNotebook

    to add nice close buttons to all tabs of a notebook.

    As I could read from the source code of scrollutil, the addclosetab command only modifies the style of the tab. I could not find anything close to a -command option or binding.

    The reason for my question: I need control over what happens when the user clicks on that close button.

    Many thanks
    Alexandru

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Tue Mar 15 12:13:50 2022
    Am 15.03.22 um 09:47 schrieb Alexandru:
    How to specify a command when using close button of notebook tab?

    I'm using

    scrollutil::addclosetab Closable.TNotebook
    ttk::notebook .notebook -style Closable.TNotebook

    to add nice close buttons to all tabs of a notebook.

    As I could read from the source code of scrollutil, the addclosetab command only modifies the style of the tab. I could not find anything close to a -command option or binding.

    The reason for my question: I need control over what happens when the user clicks on that close button.

    Many thanks
    Alexandru

    As of Scrollutil 1.13, the reaction on pressing and later releasing the
    left mouse button over a "closetab" element is implemented by lines 1113
    - 1114 of the file scrollednotebook.tcl:

    $nb forget $tabIdx
    set closed 1

    Try replacing these lines with:

    if {$userDataSupported} {
    event generate $w <<CloseTabRequested>> -data $tabIdx
    set closed 0
    } else {
    $nb forget $tabIdx
    set closed 1
    }

    For Tk versions 8.5a2 and later, this will send a <<CloseTabRequested>
    virtual event to the notebook, which you can handle in your application
    like in the following example:

    bind .notebook <<CloseTabRequested>> { closeTab %W %d }

    proc closeTab {nb tabIdx} {
    set btn [tk_messageBox -title "Close Tab?" -icon question \
    -message "Do you really want to close the tab?" -type yesno]
    if {$btn eq "no"} {
    return ""
    }

    $nb forget $tabIdx

    #
    # Optionally:
    #
    set widget [lindex [$nb tabs] $tabIdx]
    event generate $nb <<NotebookTabClosed>> -data $widget
    }

    I am thinking about incorporating the above change into the next
    Scrollutil version.

    Notice that if you use a scrollutil::scrollednotebook instead of a ttk::notebook then you can make use of the "-forgetcommand" option to
    control whether the "closetab" element will effectively close the tab.

    --
    Csaba Nemethi https://www.nemethi.de mailto:[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexandru@21:1/5 to nemethi on Tue Mar 15 04:54:30 2022
    nemethi schrieb am Dienstag, 15. März 2022 um 12:13:54 UTC+1:
    Am 15.03.22 um 09:47 schrieb Alexandru:
    How to specify a command when using close button of notebook tab?

    I'm using

    scrollutil::addclosetab Closable.TNotebook
    ttk::notebook .notebook -style Closable.TNotebook

    to add nice close buttons to all tabs of a notebook.

    As I could read from the source code of scrollutil, the addclosetab command only modifies the style of the tab. I could not find anything close to a -command option or binding.

    The reason for my question: I need control over what happens when the user clicks on that close button.

    Many thanks
    Alexandru
    As of Scrollutil 1.13, the reaction on pressing and later releasing the
    left mouse button over a "closetab" element is implemented by lines 1113
    - 1114 of the file scrollednotebook.tcl:

    $nb forget $tabIdx
    set closed 1

    Try replacing these lines with:

    if {$userDataSupported} {
    event generate $w <<CloseTabRequested>> -data $tabIdx
    set closed 0
    } else {
    $nb forget $tabIdx
    set closed 1
    }

    For Tk versions 8.5a2 and later, this will send a <<CloseTabRequested> virtual event to the notebook, which you can handle in your application
    like in the following example:

    bind .notebook <<CloseTabRequested>> { closeTab %W %d }

    proc closeTab {nb tabIdx} {
    set btn [tk_messageBox -title "Close Tab?" -icon question \
    -message "Do you really want to close the tab?" -type yesno]
    if {$btn eq "no"} {
    return ""
    }

    $nb forget $tabIdx

    #
    # Optionally:
    #
    set widget [lindex [$nb tabs] $tabIdx]
    event generate $nb <<NotebookTabClosed>> -data $widget
    }

    I am thinking about incorporating the above change into the next
    Scrollutil version.

    Notice that if you use a scrollutil::scrollednotebook instead of a ttk::notebook then you can make use of the "-forgetcommand" option to control whether the "closetab" element will effectively close the tab.

    --
    Csaba Nemethi https://www.nemethi.de mailto:[email protected]

    Hi Csaba, perfect! The solution works just fine.

    Cheers
    Alex

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)