[Lemon-commits] [lemon_svn] hegyi: r2424 - hugo/trunk/gui

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:52:31 CET 2006


Author: hegyi
Date: Thu Dec  8 15:16:08 2005
New Revision: 2424

Modified:
   hugo/trunk/gui/main_win.cc
   hugo/trunk/gui/main_win.h

Log:
Notebook tabs can be closed.

Modified: hugo/trunk/gui/main_win.cc
==============================================================================
--- hugo/trunk/gui/main_win.cc	(original)
+++ hugo/trunk/gui/main_win.cc	Thu Dec  8 15:16:08 2005
@@ -74,6 +74,8 @@
   ag->add( Gtk::Action::create("FileMenu", "_File") );
   ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
       sigc::mem_fun(*this, &MainWin::newTab));
+  ag->add( Gtk::Action::create("FileCloseTab", "_Close Tab"),
+      sigc::mem_fun(*this, &MainWin::closeTab));
   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
       sigc::mem_fun(*this, &MainWin::newFile));
   ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
@@ -131,6 +133,7 @@
       "  <menubar name='MenuBar'>"
       "    <menu action='FileMenu'>"
       "      <menuitem action='FileNewTab'/>"
+      "      <menuitem action='FileCloseTab'/>"
       "      <menuitem action='FileNew'/>"
       "      <menuitem action='FileOpen'/>"
       "      <menuitem action='FileSave'/>"
@@ -230,6 +233,46 @@
   set_tabtitle(tabnames[active_tab]);
 }
 
+void MainWin::closeTab()
+{
+  if(active_tab!=-1)
+    {
+      //tabs vector will be decreased with the deleted value
+      int size=tabs.size();
+      if(size>1)
+	{
+	  for(int i=active_tab+1;i<size;i++)
+	    {
+	      tabs[i-1]=tabs[i];
+	    }
+	}
+
+      //if size==1 resize will delete the only element
+      tabs.resize(size-1);
+
+      int old_active_tab=active_tab;
+      notebook.remove_page(active_tab);
+
+      //If the first tab was active, upon delete notebook
+      //will first switch one tab upper and not lower like
+      //in the case, when not the first tab was active.
+      //But after deletion it will become the first tab,
+      //and this should be registrated in tabs vector,
+      //as well.
+      if(old_active_tab==0)
+	{
+	  onChangeTab(NULL,0);
+	}
+
+      //if this was the last page in notebook, there is
+      //no active_tab now
+      if(size==1)
+	{
+	  active_tab=-1;
+	}
+    }
+}
+
 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
 {
   page=page;

Modified: hugo/trunk/gui/main_win.h
==============================================================================
--- hugo/trunk/gui/main_win.h	(original)
+++ hugo/trunk/gui/main_win.h	Thu Dec  8 15:16:08 2005
@@ -74,6 +74,7 @@
   //Notebook handlers
   ///Callback for 'FileNewTab' action.
   virtual void newTab();
+  virtual void closeTab();
   virtual void onChangeTab(GtkNotebookPage*, guint);
   virtual void onCloseTab();
 



More information about the Lemon-commits mailing list