View previous topic :: View next topic |
Author |
Message |
Mengu
Joined: 21 Mar 2010 Posts: 21
|
Posted: Mon Mar 22, 2010 8:22 am Post subject: Gtk Notebook Tab Close Button Signals |
|
|
Hi,
I have successfully created a notebook and I can create pages automatically as much as I want and I have added close button to my tabs: http://omploader.org/vM3d3Nw
My question here is, how do I get the tabId when I click to button? http://paste.pocoo.org/show/eQ7oCGtRaeNmxmR6WbWe/ is how I create the button and insert it in a HBox. So when a button is clicked I can get its parent like button.getParent() which is a HBox and since Notebook has HBox as its child widget for the page I thought I could get it like notebook.pageNum(button.getParent()); however this returns -1.
Please let me know how should I do it. _________________ mengu.net - some kind of monster |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Mon Mar 22, 2010 12:44 pm Post subject: |
|
|
I think Gtk doesn't count the tab label as a child of the notebook only the contents.
I'll look into this. |
|
Back to top |
|
|
Mengu
Joined: 21 Mar 2010 Posts: 21
|
Posted: Mon Mar 22, 2010 1:16 pm Post subject: |
|
|
Mike Wey wrote: | I think Gtk doesn't count the tab label as a child of the notebook only the contents.
I'll look into this. |
Thanks Mike.
Actually I have solved this. For future reference for people, let me explain how I did it.
After creating my new tab and saving the page number as int newTabIndex, I have used "setData" method (belongs to ObjectG class) for my tab label button like this: myButton.setData("tabIndex", cast(void*) newTabIndex);
I have attached an "addOnClicked" method to the button and when it is clicked, I get the page number (tabIndex) like this: cast(int)button.getData("tabIndex"). And now I am able to close my notebook tabs.
I hope this helps.
If there is any other way for this, I'd like to hear. _________________ mengu.net - some kind of monster |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Mon Mar 22, 2010 3:58 pm Post subject: |
|
|
That seems to be the way to do it. |
|
Back to top |
|
|
Mengu
Joined: 21 Mar 2010 Posts: 21
|
Posted: Mon Mar 22, 2010 4:06 pm Post subject: |
|
|
Mike Wey wrote: | That seems to be the way to do it. |
however this is a bad practice. it is working very well if i close the tabs from the end, but if i close the tabs from the beginning, since the tabs are re-ordered and got a new page num, it is not working correctly.
i add the textview in a scrolledwindow and i add the scrolled window as the new tab, so after this operation, i saved the data as myButton.saveData("tabWidget", scrolledWindowInstance); so in the click action of myButton i get the page number like this: int pageNum = this.filesTab.pageNum(cast(Widget)btn.getData("tabWidget")); and I close the tab: this.filesTab.removePage(pageNum). this is working very well: http://omploader.org/vM3gyag/out-12.ogv _________________ mengu.net - some kind of monster |
|
Back to top |
|
|
|