]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Dialog.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / Dialog.cpp
index c26b38f468e0498d84aae376ec5b0b3a14e7ccfe..32c47c61295333612b41f78a9048a7e8bff65a16 100644 (file)
 #include "Dialog.h"
 
 #include "GuiView.h"
+#include "qt_helpers.h"
 
 #include "Buffer.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "LyXFunc.h"
 
-#include "support/Debug.h"
+#include "support/debug.h"
+
+#include <QSettings>
+#include <QString>
+
+#include "support/assert.h"
 
 #include <string>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
 
-Dialog::Dialog(GuiView & lv, std::string const & name)
-       : name_(name), lyxview_(&lv)
+Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
+       : name_(name), title_(title), lyxview_(&lv)
 {}
 
 
@@ -38,14 +45,9 @@ Dialog::~Dialog()
 {}
 
 
-std::string const & Dialog::name() const
-{
-       return name_;
-}
-
 bool Dialog::canApply() const
 {
-       FuncRequest const fr(getLfun(), from_ascii(name_));
+       FuncRequest const fr(getLfun(), fromqstr(name_));
        FuncStatus const fs(getStatus(fr));
        return fs.enabled();
 }
@@ -60,13 +62,13 @@ void Dialog::dispatch(FuncRequest const & fr) const
 
 void Dialog::updateDialog() const
 {
-       dispatch(FuncRequest(LFUN_DIALOG_UPDATE, from_ascii(name_)));
+       dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
 }
 
 
 void Dialog::disconnect() const
 {
-       lyxview_->disconnectDialog(name_);
+       lyxview_->disconnectDialog(fromqstr(name_));
 }
 
 
@@ -84,9 +86,9 @@ bool Dialog::isBufferReadonly() const
 }
 
 
-std::string const Dialog::bufferFilepath() const
+QString Dialog::bufferFilepath() const
 {
-       return buffer().filePath();
+       return toqstr(buffer().filePath());
 }
 
 
@@ -115,14 +117,14 @@ BufferView const * Dialog::bufferview() const
 
 Buffer & Dialog::buffer()
 {
-       BOOST_ASSERT(lyxview_->buffer());
+       LASSERT(lyxview_->buffer(), /**/);
        return *lyxview_->buffer();
 }
 
 
 Buffer const & Dialog::buffer() const
 {
-       BOOST_ASSERT(lyxview_->buffer());
+       LASSERT(lyxview_->buffer(), /**/);
        return *lyxview_->buffer();
 }
 
@@ -133,7 +135,7 @@ void Dialog::showData(string const & data)
                return;
 
        if (!initialiseParams(data)) {
-               LYXERR0("Dialog \"" << name()
+               LYXERR0("Dialog \"" << fromqstr(name())
                        << "\" failed to translate the data string passed to show()");
                return;
        }
@@ -167,7 +169,7 @@ void Dialog::updateData(string const & data)
                return;
 
        if (!initialiseParams(data)) {
-               LYXERR0("Dialog \"" << name()
+               LYXERR0("Dialog \"" << fromqstr(name())
                       << "\" could not be initialized");
                return;
        }
@@ -178,11 +180,17 @@ void Dialog::updateData(string const & data)
 
 void Dialog::showView()
 {
-       updateView();  // make sure its up-to-date
+       // 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_);
+
        QSize const hint = w->sizeHint();
        if (hint.height() >= 0 && hint.width() >= 0)
                w->setMinimumSize(hint);
@@ -241,5 +249,27 @@ void Dialog::checkStatus()
                enableView(false);
 }
 
+
+QString Dialog::sessionKey() const
+{
+       return "view-" + QString::number(lyxview_->id())
+               + "/" + name();
+}
+
+
+void Dialog::saveSession() const
+{
+       QSettings settings;
+       settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
+}
+
+
+void Dialog::restoreSession()
+{
+       QSettings settings;
+       asQWidget()->restoreGeometry(
+               settings.value(sessionKey() + "/geometry").toByteArray());
+}
+
 } // namespace frontend
 } // namespace lyx