]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
LFUN_CLOSE_TAB_GROUP: bug fixes.
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 456c3ffbed52568e6943e23507db731e5ba67595..42b96807048a8fc66e7641e82e788306be053ae0 100644 (file)
@@ -224,17 +224,14 @@ struct GuiView::GuiViewPrivate
                        // The first TabWorkArea is always the first one, if any.
                        return tabWorkArea(0);
 
-               TabWorkArea * tab_widget = 0;
                for (int i = 0; i != splitter_->count(); ++i) {
-                       QWidget * w = splitter_->widget(i);
-                       if (!w->hasFocus())
-                               continue;
-                       tab_widget = dynamic_cast<TabWorkArea *>(w);
-                       if (tab_widget)
-                               break;
+                       TabWorkArea * twa = tabWorkArea(i);
+                       if (current_work_area_ == twa->currentWorkArea())
+                               return twa;
                }
 
-               return tab_widget;
+               // None has the focus so we just take the first one.
+               return tabWorkArea(0);
        }
 
 public:
@@ -696,34 +693,29 @@ GuiToolbar * GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
 
 GuiWorkArea * GuiView::workArea(Buffer & buffer)
 {
-       for (int i = 0; i != d.splitter_->count(); ++i) {
-               GuiWorkArea * wa = d.tabWorkArea(i)->workArea(buffer);
-               if (wa)
-                       return wa;
-       }
+       if (TabWorkArea * twa = d.currentTabWorkArea())
+               return twa->workArea(buffer);
        return 0;
 }
 
 
 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
 {
-
        // Automatically create a TabWorkArea if there are none yet.
-       if (!d.splitter_->count())
-               addTabWorkArea();
-
-       TabWorkArea * tab_widget = d.currentTabWorkArea();
+       TabWorkArea * tab_widget = d.splitter_->count() 
+               ? d.currentTabWorkArea() : addTabWorkArea();
        return tab_widget->addWorkArea(buffer, *this);
 }
 
 
-void GuiView::addTabWorkArea()
+TabWorkArea * GuiView::addTabWorkArea()
 {
        TabWorkArea * twa = new TabWorkArea;
        QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
                this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
        d.splitter_->addWidget(twa);
        d.stack_widget_->setCurrentWidget(d.splitter_);
+       return twa;
 }
 
 
@@ -968,6 +960,14 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
                enable = buf;
                break;
 
+       case LFUN_SPLIT_VIEW:
+               enable = buf;
+               break;
+
+       case LFUN_CLOSE_TAB_GROUP:
+               enable = d.currentTabWorkArea();
+               break;
+
        case LFUN_TOOLBAR_TOGGLE:
                flag.setOnOff(d.toolbars_->visible(cmd.getArg(0)));
                break;
@@ -1811,6 +1811,31 @@ bool GuiView::dispatch(FuncRequest const & cmd)
 
                case LFUN_UI_TOGGLE:
                        lfunUiToggle(cmd);
+                       // Make sure the keyboard focus stays in the work area.
+                       setFocus();
+                       break;
+
+               case LFUN_SPLIT_VIEW:
+                       if (Buffer * buf = buffer()) {
+                               string const orientation = cmd.getArg(0);
+                               d.splitter_->setOrientation(orientation == "vertical"
+                                       ? Qt::Vertical : Qt::Horizontal);
+                               TabWorkArea * twa = addTabWorkArea();
+                               GuiWorkArea * wa = twa->addWorkArea(*buf, *this);
+                               setCurrentWorkArea(wa);
+                       }
+                       break;
+
+               case LFUN_CLOSE_TAB_GROUP:
+                       if (TabWorkArea * twa = d.currentTabWorkArea()) {
+                               delete twa;
+                               twa = d.currentTabWorkArea();
+                               // Switch to the next GuiWorkArea in the found TabWorkArea.
+                               d.current_work_area_ = twa? twa->currentWorkArea() : 0;
+                               if (d.splitter_->count() == 0)
+                                       // No more work area, switch to the background widget.
+                                       d.setBackground();
+                       }
                        break;
 
                default:
@@ -1868,29 +1893,23 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
                d.toolbars_->toggleFullScreen(!isFullScreen());
 
        if (isFullScreen()) {
-               showNormal();
+               for (int i = 0; i != d.splitter_->count(); ++i)
+                       d.tabWorkArea(i)->setFullScreen(false);
 #if QT_VERSION >= 0x040300
                setContentsMargins(0, 0, 0, 0);
 #endif
-               for (int i = 0; i != d.splitter_->count(); ++i)
-                       d.tabWorkArea(i)->setFullScreen(false);
+               showNormal();
                menuBar()->show();
                statusBar()->show();
-               if (lyxrc.full_screen_scrollbar && d.current_work_area_)
-                       d.current_work_area_->
-                               setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        } else {
-               if (lyxrc.full_screen_scrollbar && d.current_work_area_)
-                       d.current_work_area_->
-                               setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-               statusBar()->hide();
-               menuBar()->hide();
                for (int i = 0; i != d.splitter_->count(); ++i)
                        d.tabWorkArea(i)->setFullScreen(true);
 #if QT_VERSION >= 0x040300
                setContentsMargins(-2, -2, -2, -2);
 #endif
                showFullScreen();
+               statusBar()->hide();
+               menuBar()->hide();
        }
 }