]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Dialog.cpp
If we are in a closeEvent, we don't want to close all buffers, because these may...
[lyx.git] / src / frontends / qt4 / Dialog.cpp
index c372107246cf87e372e1a5ff3f4a392ff913fba2..8d831b91cf6d42c492de1bfe7c541159e5886d0d 100644 (file)
 #include "qt_helpers.h"
 
 #include "Buffer.h"
+#include "BufferView.h"
+#include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "LyXFunc.h"
 
+#include "insets/Inset.h"
+
 #include "support/debug.h"
+#include "support/lassert.h"
 
 #include <QSettings>
 #include <QString>
 
-#include "support/assert.h"
-
 #include <string>
 
 using namespace std;
@@ -103,25 +106,12 @@ KernelDocType Dialog::docType() const
 }
 
 
-BufferView * Dialog::bufferview()
-{
-       return lyxview_->view();
-}
-
-
 BufferView const * Dialog::bufferview() const
 {
        return lyxview_->view();
 }
 
 
-Buffer & Dialog::buffer()
-{
-       LASSERT(lyxview_->buffer(), /**/);
-       return *lyxview_->buffer();
-}
-
-
 Buffer const & Dialog::buffer() const
 {
        LASSERT(lyxview_->buffer(), /**/);
@@ -135,7 +125,7 @@ void Dialog::showData(string const & data)
                return;
 
        if (!initialiseParams(data)) {
-               LYXERR0("Dialog \"" << fromqstr(name())
+               LYXERR0("Dialog \"" << name()
                        << "\" failed to translate the data string passed to show()");
                return;
        }
@@ -163,30 +153,11 @@ void Dialog::apply()
 }
 
 
-void Dialog::updateData(string const & data)
-{
-       if (!initialiseParams(data)) {
-               LYXERR0("Dialog \"" << fromqstr(name())
-                      << "\" could not be initialized");
-               return;
-       }
-
-       if (lyxview_->buffer())
-               updateView();
-       else
-               enableView(false);
-}
-
-
-void Dialog::showView()
+void Dialog::prepareView()
 {
-       // Make sure the dialog is up-to-date.
-       updateView(); 
        // Make sure the dialog controls are correctly enabled/disabled with
        // readonly status.
        checkStatus();
-       if (exitEarly())
-               return;
 
        QWidget * w = asQWidget();
        w->setWindowTitle(title_);
@@ -194,14 +165,27 @@ void Dialog::showView()
        QSize const hint = w->sizeHint();
        if (hint.height() >= 0 && hint.width() >= 0)
                w->setMinimumSize(hint);
+}
+
 
+void Dialog::showView()
+{
+       prepareView();
+
+       QWidget * w = asQWidget();
        if (w->isVisible()) {
                w->raise();
                w->activateWindow();
        } else
                w->show();
 
-       w->setFocus();
+       if (wantInitialFocus())
+               w->setFocus();
+       else {
+               lyxview_->raise();
+               lyxview_->activateWindow();
+               lyxview_->setFocus();
+       }
 }
 
 
@@ -222,12 +206,25 @@ bool Dialog::isVisibleView() const
 }
 
 
+Inset const * Dialog::inset(InsetCode code) const
+{
+       Inset * ins = bufferview()->cursor().innerInsetOfType(code);
+       if (!ins)
+               ins = bufferview()->cursor().nextInset();
+       if (!ins || ins->lyxCode() != code)
+               return 0;
+       return ins;
+}
+
+
 void Dialog::checkStatus()
 {
        // buffer independant dialogs are always active.
        // This check allows us leave canApply unimplemented for some dialogs.
-       if (!isBufferDependent())
+       if (!isBufferDependent()) {
+               updateView();
                return;
+       }
 
        // deactivate the dialog if we have no buffer
        if (!isBufferAvailable()) {
@@ -238,7 +235,7 @@ void Dialog::checkStatus()
        // check whether this dialog may be active
        if (canApply()) {
                bool const readonly = isBufferReadonly();
-               enableView(!readonly);
+               enableView(!readonly || canApplyToReadOnly());
                // refreshReadOnly() is too generous in _enabling_ widgets
                // update dialog to disable disabled widgets again
 
@@ -252,7 +249,7 @@ void Dialog::checkStatus()
 
 QString Dialog::sessionKey() const
 {
-       return "view-" + QString::number(lyxview_->id())
+       return "views/" + QString::number(lyxview_->id())
                + "/" + name();
 }