]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/LyXView.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / LyXView.C
index fee535079d7d5328a21d6532f56c83ccfb9d4326..1ae358e20e6d686c6bdafa238dbb2c818d534be1 100644 (file)
@@ -86,20 +86,37 @@ LyXView::LyXView(int id)
 
 LyXView::~LyXView()
 {
+       disconnectBuffer();
 }
 
 
 // FIXME, there's only one WorkArea per LyXView possible for now.
 void LyXView::setWorkArea(WorkArea * work_area)
 {
+       BOOST_ASSERT(work_area);
        work_area_ = work_area;
        work_area_ids_.clear();
        work_area_ids_.push_back(work_area_->id());
 }
 
 
+// FIXME, there's only one WorkArea per LyXView possible for now.
+WorkArea const * LyXView::currentWorkArea() const
+{
+       return work_area_;
+}
+
+
+// FIXME, there's only one WorkArea per LyXView possible for now.
+WorkArea * LyXView::currentWorkArea()
+{
+       return work_area_;
+}
+
+
 Buffer * LyXView::buffer() const
 {
+       BOOST_ASSERT(work_area_);
        return work_area_->bufferView().buffer();
 }
 
@@ -108,6 +125,7 @@ void LyXView::setBuffer(Buffer * b)
 {
        busy(true);
 
+       BOOST_ASSERT(work_area_);
        if (work_area_->bufferView().buffer())
                disconnectBuffer();
 
@@ -115,6 +133,8 @@ void LyXView::setBuffer(Buffer * b)
                getDialogs().hideBufferDependent();
 
        work_area_->bufferView().setBuffer(b);
+       // Make sure the TOC is updated before anything else.
+       updateToc();
 
        if (work_area_->bufferView().buffer()) {
                // Buffer-dependent dialogs should be updated or
@@ -142,11 +162,13 @@ bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles)
 {
        busy(true);
 
+       BOOST_ASSERT(work_area_);
        if (work_area_->bufferView().buffer())
                disconnectBuffer();
 
        bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
 
+       updateToc();
        updateMenubar();
        updateToolbars();
        updateLayoutChoice();
@@ -168,10 +190,15 @@ void LyXView::connectBuffer(Buffer & buf)
        if (errorsConnection_.connected())
                disconnectBuffer();
 
+       BOOST_ASSERT(work_area_);
        bufferChangedConnection_ =
                buf.changed.connect(
                        boost::bind(&WorkArea::redraw, work_area_));
 
+       bufferStructureChangedConnection_ =
+               buf.structureChanged.connect(
+                       boost::bind(&LyXView::updateToc, this));
+
        errorsConnection_ =
                buf.errors.connect(
                        boost::bind(&LyXView::showErrorList, this, _1));
@@ -206,6 +233,7 @@ void LyXView::disconnectBuffer()
 {
        errorsConnection_.disconnect();
        bufferChangedConnection_.disconnect();
+       bufferStructureChangedConnection_.disconnect();
        messageConnection_.disconnect();
        busyConnection_.disconnect();
        titleConnection_.disconnect();
@@ -284,12 +312,20 @@ void LyXView::showReadonly(bool)
 
 BufferView * LyXView::view() const
 {
+       BOOST_ASSERT(work_area_);
        return &work_area_->bufferView();
 }
 
 
+void LyXView::updateToc()
+{
+       updateDialog("toc", "");
+}
+
+
 void LyXView::updateToolbars()
 {
+       BOOST_ASSERT(work_area_);
        bool const math =
                work_area_->bufferView().cursor().inMathed();
        bool const table =
@@ -306,7 +342,7 @@ void LyXView::updateToolbars()
 }
 
 
-ToolbarBackend::Flags LyXView::getToolbarState(string const & name)
+ToolbarInfo::Flags LyXView::getToolbarState(string const & name)
 {
        return toolbars_->getToolbarState(name);
 }
@@ -334,7 +370,7 @@ void LyXView::updateMenubar()
 
 void LyXView::autoSave()
 {
-       lyxerr[Debug::INFO] << "Running autoSave()" << endl;
+       LYXERR(Debug::INFO) << "Running autoSave()" << endl;
 
        if (view()->buffer())
                lyx::autoSave(view());
@@ -361,6 +397,7 @@ void LyXView::updateLayoutChoice()
                current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
        }
 
+       BOOST_ASSERT(work_area_);
        if (work_area_->bufferView().cursor().inMathed())
                return;
 
@@ -394,6 +431,7 @@ void LyXView::updateWindowTitle()
        }
 
        setWindowTitle(maximize_title, minimize_title);
+       updateTab();
 }
 
 
@@ -408,10 +446,10 @@ Buffer const * const LyXView::updateInset(InsetBase const * inset) const
 {
        Buffer const * buffer_ptr = 0;
        if (inset) {
+               BOOST_ASSERT(work_area_);
+               work_area_->scheduleRedraw();
+
                buffer_ptr = work_area_->bufferView().buffer();
-               // No FitCursor:
-               work_area_->bufferView().update(Update::Force);
-               work_area_->redraw();
        }
        return buffer_ptr;
 }