gui/main_win.cc
changeset 1861 5f204c7a1318
parent 1849 a4d1362397fe
child 1862 d47ebd34e581
equal deleted inserted replaced
26:564980477ffc 27:0f7c30af45b4
    72   ag=Gtk::ActionGroup::create();
    72   ag=Gtk::ActionGroup::create();
    73 
    73 
    74   ag->add( Gtk::Action::create("FileMenu", "_File") );
    74   ag->add( Gtk::Action::create("FileMenu", "_File") );
    75   ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
    75   ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
    76       sigc::mem_fun(*this, &MainWin::newTab));
    76       sigc::mem_fun(*this, &MainWin::newTab));
       
    77   ag->add( Gtk::Action::create("FileCloseTab", "_Close Tab"),
       
    78       sigc::mem_fun(*this, &MainWin::closeTab));
    77   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    79   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    78       sigc::mem_fun(*this, &MainWin::newFile));
    80       sigc::mem_fun(*this, &MainWin::newFile));
    79   ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    81   ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    80       sigc::mem_fun(*this, &MainWin::openFile));
    82       sigc::mem_fun(*this, &MainWin::openFile));
    81   ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
    83   ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
   129     Glib::ustring ui_info =
   131     Glib::ustring ui_info =
   130       "<ui>"
   132       "<ui>"
   131       "  <menubar name='MenuBar'>"
   133       "  <menubar name='MenuBar'>"
   132       "    <menu action='FileMenu'>"
   134       "    <menu action='FileMenu'>"
   133       "      <menuitem action='FileNewTab'/>"
   135       "      <menuitem action='FileNewTab'/>"
       
   136       "      <menuitem action='FileCloseTab'/>"
   134       "      <menuitem action='FileNew'/>"
   137       "      <menuitem action='FileNew'/>"
   135       "      <menuitem action='FileOpen'/>"
   138       "      <menuitem action='FileOpen'/>"
   136       "      <menuitem action='FileSave'/>"
   139       "      <menuitem action='FileSave'/>"
   137       "      <menuitem action='FileSaveAs'/>"
   140       "      <menuitem action='FileSaveAs'/>"
   138       "      <menuitem action='Close'/>"
   141       "      <menuitem action='Close'/>"
   228   notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   231   notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   229   notebook.set_current_page(size);
   232   notebook.set_current_page(size);
   230   set_tabtitle(tabnames[active_tab]);
   233   set_tabtitle(tabnames[active_tab]);
   231 }
   234 }
   232 
   235 
       
   236 void MainWin::closeTab()
       
   237 {
       
   238   if(active_tab!=-1)
       
   239     {
       
   240       //tabs vector will be decreased with the deleted value
       
   241       int size=tabs.size();
       
   242       if(size>1)
       
   243 	{
       
   244 	  for(int i=active_tab+1;i<size;i++)
       
   245 	    {
       
   246 	      tabs[i-1]=tabs[i];
       
   247 	    }
       
   248 	}
       
   249 
       
   250       //if size==1 resize will delete the only element
       
   251       tabs.resize(size-1);
       
   252 
       
   253       int old_active_tab=active_tab;
       
   254       notebook.remove_page(active_tab);
       
   255 
       
   256       //If the first tab was active, upon delete notebook
       
   257       //will first switch one tab upper and not lower like
       
   258       //in the case, when not the first tab was active.
       
   259       //But after deletion it will become the first tab,
       
   260       //and this should be registrated in tabs vector,
       
   261       //as well.
       
   262       if(old_active_tab==0)
       
   263 	{
       
   264 	  onChangeTab(NULL,0);
       
   265 	}
       
   266 
       
   267       //if this was the last page in notebook, there is
       
   268       //no active_tab now
       
   269       if(size==1)
       
   270 	{
       
   271 	  active_tab=-1;
       
   272 	}
       
   273     }
       
   274 }
       
   275 
   233 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
   276 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
   234 {
   277 {
   235   page=page;
   278   page=page;
   236   active_tab=page_num;
   279   active_tab=page_num;
   237   tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   280   tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);