+void Dialog::apply()
+{
+ if (isBufferDependent()) {
+ if (!isBufferAvailable() ||
+ (isBufferReadonly() && !canApplyToReadOnly()))
+ return;
+ }
+
+ applyView();
+ dispatchParams();
+
+ if (disconnectOnApply() && !isClosing()) {
+ disconnect();
+ initialiseParams(string());
+ updateView();
+ }
+}
+
+
+void Dialog::prepareView()
+{
+ // Make sure the dialog controls are correctly enabled/disabled with
+ // readonly status.
+ checkStatus();
+
+ QWidget * w = asQWidget();
+ w->setWindowTitle(title_);
+
+ 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();
+
+ if (wantInitialFocus())
+ w->setFocus();
+ else {
+ lyxview_->raise();
+ lyxview_->activateWindow();
+ lyxview_->setFocus();
+ }
+}
+
+
+void Dialog::hideView()
+{
+ QWidget * w = asQWidget();
+ if (!w->isVisible())
+ return;
+ clearParams();
+ disconnect();
+ w->hide();
+}
+
+
+bool Dialog::isVisibleView() const
+{
+ return asQWidget()->isVisible();
+}
+
+
+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 independent dialogs are always active.
+ // This check allows us leave canApply unimplemented for some dialogs.
+ if (!isBufferDependent()) {
+ updateView();
+ return;
+ }
+
+ // deactivate the dialog if we have no buffer
+ if (!isBufferAvailable()) {
+ enableView(false);
+ return;
+ }
+
+ // check whether this dialog may be active
+ if (canApply()) {
+ bool const readonly = isBufferReadonly();
+ enableView(!readonly || canApplyToReadOnly());
+ // refreshReadOnly() is too generous in _enabling_ widgets
+ // update dialog to disable disabled widgets again
+
+ updateView();
+ } else
+ enableView(false);
+}
+
+
+QString Dialog::sessionKey() const
+{
+ return "views/" + QString::number(lyxview_->id())
+ + "/" + name();
+}
+
+
+void Dialog::saveSession() const
+{
+ QSettings settings;
+ settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
+}
+
+
+void Dialog::restoreSession()