]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/LyXView.C
fix crash on exit.
[lyx.git] / src / frontends / LyXView.C
index 8a8274e966e0d998b92618004f6d4dbd96b5ca5c..e700434499d257f6b6c8b94c171f1681bee7cb96 100644 (file)
@@ -42,6 +42,9 @@
 
 #include <boost/bind.hpp>
 
+
+namespace lyx {
+
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
@@ -64,15 +67,19 @@ 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)),
-         lyxfunc_(new LyXFunc(this)),
          dialogs_(new Dialogs(*this)),
          controlcommand_(new ControlCommandBuffer(*this))
 {
-       lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
+       // Start autosave timer
+       if (lyxrc.autosave) {
+               autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
+               autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
+               autosave_timeout_->start();
+       }
 }
 
 
@@ -81,36 +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_;
-}
-
-
-void LyXView::init()
-{
-       updateLayoutChoice();
-       updateMenubar();
-
-       // Start autosave timer
-       if (lyxrc.autosave) {
-               autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
-               autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
-               autosave_timeout_->start();
-       }
+       work_area_ids_.clear();
+       work_area_ids_.push_back(work_area_->id());
 }
 
 
@@ -138,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();
 }
 
 
@@ -161,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;
 }
 
@@ -171,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));
@@ -203,12 +195,15 @@ void LyXView::connectBuffer(Buffer & buf)
 
 void LyXView::disconnectBuffer()
 {
+       errorsConnection_.disconnect();
+       bufferChangedConnection_.disconnect();
        messageConnection_.disconnect();
        busyConnection_.disconnect();
        titleConnection_.disconnect();
        timerConnection_.disconnect();
        readonlyConnection_.disconnect();
        closingConnection_.disconnect();
+       layout_changed_connection_.disconnect();
 }
 
 
@@ -222,6 +217,8 @@ void LyXView::connectBufferView(BufferView & bv)
                        boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3));
        update_dialog_connection_ = bv.updateDialog.connect(
                        boost::bind(&LyXView::updateDialog, this, _1, _2));
+       layout_changed_connection_ = bv.layoutChanged.connect(
+                       boost::bind(&Toolbars::setLayout, toolbars_.get(), _1));
 }
 
 
@@ -249,17 +246,16 @@ 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, 0);
+       getDialogs().show(name, data, inset);
 }
 
 
@@ -283,17 +279,11 @@ BufferView * LyXView::view() const
 }
 
 
-void LyXView::setLayout(string const & layout)
-{
-       toolbars_->setLayout(layout);
-}
-
-
 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()
@@ -312,9 +302,8 @@ void LyXView::autoSave()
 {
        lyxerr[Debug::INFO] << "Running autoSave()" << endl;
 
-       if (view()->buffer()) {
-               ::autoSave(view());
-       }
+       if (view()->buffer())
+               lyx::autoSave(view());
 }
 
 
@@ -360,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)");
@@ -380,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);
 }
 
 
@@ -394,3 +390,6 @@ Buffer const * const LyXView::updateInset(InsetBase const * inset) const
        }
        return buffer_ptr;
 }
+
+
+} // namespace lyx