Notebook tabs can be closed.
authorhegyi
Thu, 08 Dec 2005 14:16:08 +0000
changeset 18563f0558065bcd
parent 1855 c72636dcf0bd
child 1857 2e3a4481901e
Notebook tabs can be closed.
gui/main_win.cc
gui/main_win.h
     1.1 --- a/gui/main_win.cc	Wed Dec 07 15:43:44 2005 +0000
     1.2 +++ b/gui/main_win.cc	Thu Dec 08 14:16:08 2005 +0000
     1.3 @@ -74,6 +74,8 @@
     1.4    ag->add( Gtk::Action::create("FileMenu", "_File") );
     1.5    ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
     1.6        sigc::mem_fun(*this, &MainWin::newTab));
     1.7 +  ag->add( Gtk::Action::create("FileCloseTab", "_Close Tab"),
     1.8 +      sigc::mem_fun(*this, &MainWin::closeTab));
     1.9    ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    1.10        sigc::mem_fun(*this, &MainWin::newFile));
    1.11    ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    1.12 @@ -131,6 +133,7 @@
    1.13        "  <menubar name='MenuBar'>"
    1.14        "    <menu action='FileMenu'>"
    1.15        "      <menuitem action='FileNewTab'/>"
    1.16 +      "      <menuitem action='FileCloseTab'/>"
    1.17        "      <menuitem action='FileNew'/>"
    1.18        "      <menuitem action='FileOpen'/>"
    1.19        "      <menuitem action='FileSave'/>"
    1.20 @@ -230,6 +233,46 @@
    1.21    set_tabtitle(tabnames[active_tab]);
    1.22  }
    1.23  
    1.24 +void MainWin::closeTab()
    1.25 +{
    1.26 +  if(active_tab!=-1)
    1.27 +    {
    1.28 +      //tabs vector will be decreased with the deleted value
    1.29 +      int size=tabs.size();
    1.30 +      if(size>1)
    1.31 +	{
    1.32 +	  for(int i=active_tab+1;i<size;i++)
    1.33 +	    {
    1.34 +	      tabs[i-1]=tabs[i];
    1.35 +	    }
    1.36 +	}
    1.37 +
    1.38 +      //if size==1 resize will delete the only element
    1.39 +      tabs.resize(size-1);
    1.40 +
    1.41 +      int old_active_tab=active_tab;
    1.42 +      notebook.remove_page(active_tab);
    1.43 +
    1.44 +      //If the first tab was active, upon delete notebook
    1.45 +      //will first switch one tab upper and not lower like
    1.46 +      //in the case, when not the first tab was active.
    1.47 +      //But after deletion it will become the first tab,
    1.48 +      //and this should be registrated in tabs vector,
    1.49 +      //as well.
    1.50 +      if(old_active_tab==0)
    1.51 +	{
    1.52 +	  onChangeTab(NULL,0);
    1.53 +	}
    1.54 +
    1.55 +      //if this was the last page in notebook, there is
    1.56 +      //no active_tab now
    1.57 +      if(size==1)
    1.58 +	{
    1.59 +	  active_tab=-1;
    1.60 +	}
    1.61 +    }
    1.62 +}
    1.63 +
    1.64  void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
    1.65  {
    1.66    page=page;
     2.1 --- a/gui/main_win.h	Wed Dec 07 15:43:44 2005 +0000
     2.2 +++ b/gui/main_win.h	Thu Dec 08 14:16:08 2005 +0000
     2.3 @@ -74,6 +74,7 @@
     2.4    //Notebook handlers
     2.5    ///Callback for 'FileNewTab' action.
     2.6    virtual void newTab();
     2.7 +  virtual void closeTab();
     2.8    virtual void onChangeTab(GtkNotebookPage*, guint);
     2.9    virtual void onCloseTab();
    2.10