]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/LyXView.C
fix crash on exit.
[lyx.git] / src / frontends / LyXView.C
index 0eeaacee0381cc4d5f2de6a1ea446a8c58aae38b..e700434499d257f6b6c8b94c171f1681bee7cb96 100644 (file)
@@ -42,6 +42,9 @@
 
 #include <boost/bind.hpp>
 
+
+namespace lyx {
+
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
@@ -64,8 +67,8 @@ using lyx::frontend::ControlCommandBuffer;
 string current_layout;
 
 
-LyXView::LyXView()
-       : work_area_(0),
+LyXView::LyXView(int id)
+       : id_(id), work_area_(0),
          toolbars_(new Toolbars(*this)),
          autosave_timeout_(new Timeout(5000)),
          dialogs_(new Dialogs(*this)),
@@ -85,22 +88,12 @@ LyXView::~LyXView()
 }
 
 
+// FIXME, there's only one WorkArea per LyXView possible for now.
 void LyXView::setWorkArea(WorkArea * work_area)
 {
        work_area_ = work_area;
-}
-
-
-void LyXView::redrawWorkArea()
-{
-       work_area_->redraw();
-       updateStatusBar();
-}
-
-
-WorkArea * LyXView::workArea()
-{
-       return work_area_;
+       work_area_ids_.clear();
+       work_area_ids_.push_back(work_area_->id());
 }
 
 
@@ -128,11 +121,15 @@ void LyXView::setBuffer(Buffer * b)
                connectBuffer(*work_area_->bufferView().buffer());
        }
 
+       if (quitting)
+               return;
+
        updateMenubar();
        updateToolbars();
        updateLayoutChoice();
        updateWindowTitle();
-       redrawWorkArea();
+       updateStatusBar();
+       work_area_->redraw();
 }
 
 
@@ -151,7 +148,8 @@ bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
                connectBuffer(*work_area_->bufferView().buffer());
                showErrorList("Parse");
        }
-       redrawWorkArea();
+       updateStatusBar();
+       work_area_->redraw();
        return loaded;
 }
 
@@ -161,6 +159,10 @@ void LyXView::connectBuffer(Buffer & buf)
        if (errorsConnection_.connected())
                disconnectBuffer();
 
+       bufferChangedConnection_ =
+               buf.changed.connect(
+                       boost::bind(&WorkArea::redraw, work_area_));
+
        errorsConnection_ =
                buf.errors.connect(
                        boost::bind(&LyXView::showErrorList, this, _1));
@@ -193,6 +195,8 @@ void LyXView::connectBuffer(Buffer & buf)
 
 void LyXView::disconnectBuffer()
 {
+       errorsConnection_.disconnect();
+       bufferChangedConnection_.disconnect();
        messageConnection_.disconnect();
        busyConnection_.disconnect();
        titleConnection_.disconnect();
@@ -242,15 +246,14 @@ void LyXView::showDialog(string const & name)
 }
 
 
-void LyXView::showDialogWithData(string const & name,
-                                                                string const & data)
+void LyXView::showDialogWithData(string const & name, string const & data)
 {
        getDialogs().show(name, data);
 }
 
 
 void LyXView::showInsetDialog(string const & name, string const & data,
-                                                         InsetBase * inset)
+               InsetBase * inset)
 {
        getDialogs().show(name, data, inset);
 }
@@ -280,7 +283,7 @@ void LyXView::updateToolbars()
 {
        bool const math = work_area_->bufferView().cursor().inMathed();
        bool const table =
-               getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
+               lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
        toolbars_->update(math, table);
        // update redaonly status of open dialogs. This could also be in
        // updateMenubar(), but since updateToolbars() and updateMenubar()
@@ -299,9 +302,8 @@ void LyXView::autoSave()
 {
        lyxerr[Debug::INFO] << "Running autoSave()" << endl;
 
-       if (view()->buffer()) {
-               ::autoSave(view());
-       }
+       if (view()->buffer())
+               lyx::autoSave(view());
 }
 
 
@@ -347,7 +349,7 @@ void LyXView::updateWindowTitle()
        if (view()->buffer()) {
                string const cur_title = buffer()->fileName();
                if (!cur_title.empty()) {
-                       maximize_title += lyx::from_ascii(": ") + makeDisplayPath(cur_title, 30);
+                       maximize_title += ": " + makeDisplayPath(cur_title, 30);
                        minimize_title = lyx::from_utf8(onlyFilename(cur_title));
                        if (!buffer()->isClean()) {
                                maximize_title += _(" (changed)");
@@ -367,7 +369,14 @@ void LyXView::updateWindowTitle()
 
 void LyXView::dispatch(FuncRequest const & cmd)
 {
-       getLyXFunc().dispatch(cmd);
+       if (cmd.action == LFUN_WINDOW_CLOSE) {
+               close();
+               closed(id_);
+               return;
+       }
+
+       theLyXFunc().setLyXView(this);
+       lyx::dispatch(cmd);
 }
 
 
@@ -381,3 +390,6 @@ Buffer const * const LyXView::updateInset(InsetBase const * inset) const
        }
        return buffer_ptr;
 }
+
+
+} // namespace lyx