]> git.lyx.org Git - features.git/commitdiff
Transfer some code from GuiView to TabWorkArea.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 7 Oct 2007 08:05:02 +0000 (08:05 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 7 Oct 2007 08:05:02 +0000 (08:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20806 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index a50889e0fe9aedd802b45dccce753e7aab9b4093..bd4872d955e2279eb2f6623e378af7cf98616df8 100644 (file)
@@ -868,13 +868,7 @@ void GuiViewBase::setCurrentWorkArea(WorkArea * work_area)
 
        GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(work_area);
        BOOST_ASSERT(wa);
-       if (wa != d.tab_widget_->currentWidget())
-               // Switch to the work area.
-               d.tab_widget_->setCurrentWidget(wa);
-       else
-               // Make sure the work area is up to date.
-               d.tab_widget_->on_currentTabChanged(d.tab_widget_->currentIndex());
-       wa->setFocus();
+       d.tab_widget_->setCurrentWorkArea(wa);
 }
 
 
@@ -891,26 +885,14 @@ void GuiViewBase::removeWorkArea(WorkArea * work_area)
        updateToc();
 
        GuiWorkArea * gwa = dynamic_cast<GuiWorkArea *>(work_area);
-       gwa->setUpdatesEnabled(false);
        BOOST_ASSERT(gwa);
-       int index = d.tab_widget_->indexOf(gwa);
-       d.tab_widget_->removeTab(index);
-
-       delete gwa;
-
-       if (d.tab_widget_->count()) {
-               // make sure the next work area is enabled.
-               d.tab_widget_->currentWidget()->setUpdatesEnabled(true);
-               // Hide tabbar if there's only one tab.
-               d.tab_widget_->showBar(d.tab_widget_->count() > 1);
-               return;
-       }
+       d.tab_widget_->removeWorkArea(gwa);
 
        getDialogs().hideBufferDependent();
-       if (d.stack_widget_) {
+
+       if (d.tab_widget_->count() == 0 && d.stack_widget_)
                // No more work area, switch to the background widget.
                d.setBackground();
-       }
 }
 
 
index c25d392531655d0338d7fb7af34a69818d00581b..0bb9100904b35e58da7ce70708cb2592a9bf8612 100644 (file)
@@ -728,6 +728,46 @@ void TabWorkArea::showBar(bool show)
 }
 
 
+bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
+{
+       BOOST_ASSERT(work_area);
+       int index = indexOf(work_area);
+       if (index == -1)
+               return false;
+
+       if (index == currentIndex())
+               // Make sure the work area is up to date.
+               on_currentTabChanged(index);
+       else
+               // Switch to the work area.
+               setCurrentIndex(index);
+       work_area->setFocus();
+
+       return true;
+}
+
+
+bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
+{
+       BOOST_ASSERT(work_area);
+       int index = indexOf(work_area);
+       if (index == -1)
+               return false;
+
+       work_area->setUpdatesEnabled(false);
+       removeTab(index);
+       delete work_area;
+
+       if (count()) {
+               // make sure the next work area is enabled.
+               currentWidget()->setUpdatesEnabled(true);
+               // Hide tabbar if there's only one tab.
+               showBar(count() > 1);
+       }
+       return true;
+}
+
+
 void TabWorkArea::on_currentTabChanged(int i)
 {
        GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
index dc9c84c2a4f8df4d5b8b17a1c878085c363d33af..2ddad927b04fe52a4a6720ae6e88f55d55b25182 100644 (file)
@@ -180,6 +180,8 @@ class TabWorkArea : public QTabWidget
 public:
        TabWorkArea(QWidget * parent = 0);
        void showBar(bool show);
+       bool setCurrentWorkArea(GuiWorkArea *);
+       bool removeWorkArea(GuiWorkArea *);
 
 Q_SIGNALS:
        ///