Commit 3c8be385 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Make KateConfigDialog a normal view in kate

Should work like before except that its not a dialog anymore.

I hid the "Cancel" button as "widget" semantics are usually different
from a dialog i.e., no Cancel/Ok etc. But "Ok/Apply" are still there.
Maybe we should just have one "Save/Apply button"?
parent 223fde91
Pipeline #248483 passed with stage
in 11 minutes and 40 seconds
......@@ -81,18 +81,20 @@ KateConfigDialog::KateConfigDialog(KateMainWindow *parent)
connect(this, &KateConfigDialog::accepted, this, &KateConfigDialog::slotApply);
connect(buttonBox()->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KateConfigDialog::slotApply);
connect(buttonBox()->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &KateConfigDialog::slotHelp);
button(QDialogButtonBox::Ok)->hide();
button(QDialogButtonBox::Cancel)->setText(i18n("Close"));
button(QDialogButtonBox::Apply)->setText(i18n("Save"));
}
QSize KateConfigDialog::sizeHint() const
KateConfigDialog *KateConfigDialog::widget(KateMainWindow *mw)
{
// start with a bit enlarged default size hint to minimize changes of useless scrollbars
QSize size = KPageDialog::sizeHint() * 1.3;
// enlarge it to half of the main window size, if that is larger
size = size.expandedTo(m_mainWindow->size() * 0.5);
// return bounded size to available real screen space
return size.boundedTo(screen()->availableSize() * 0.9);
static QPointer<KateConfigDialog> dlg = nullptr;
if (!dlg) {
dlg = new KateConfigDialog(mw);
return dlg;
}
return dlg;
}
void KateConfigDialog::addBehaviorPage()
......@@ -583,6 +585,8 @@ void KateConfigDialog::slotApply()
m_dataChanged = false;
buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
Q_EMIT saved();
}
void KateConfigDialog::slotChanged()
......
......@@ -39,7 +39,9 @@ class KateConfigDialog : public KPageDialog
{
Q_OBJECT
public:
private:
// No manual construction. We will always have one
// dialog around
KateConfigDialog(KateMainWindow *parent);
public: // static
......@@ -49,11 +51,18 @@ public: // static
*/
static int recentFilesMaxCount();
/**
* Overwrite size hint for better default window sizes
* @return size hint
*/
QSize sizeHint() const override;
// Returns the dialog
static KateConfigDialog *widget(KateMainWindow *mw);
KateMainWindow *mainwWindow()
{
return m_mainWindow;
}
Q_INVOKABLE bool shouldClose()
{
return true;
}
public:
void addPluginPage(KTextEditor::Plugin *plugin);
......@@ -80,7 +89,7 @@ private:
KPageWidgetItem *addScrollablePage(QWidget *page, const QString &itemName);
private:
KateMainWindow *const m_mainWindow;
KateMainWindow *m_mainWindow;
bool m_dataChanged = false;
......@@ -111,6 +120,9 @@ private:
#ifdef WITH_KUSERFEEDBACK
KUserFeedback::FeedbackConfigWidget *m_userFeedbackWidget = nullptr;
#endif
Q_SIGNALS:
void saved();
};
#endif
......@@ -918,20 +918,31 @@ void KateMainWindow::slotConfigure()
bool KateMainWindow::showPluginConfigPage(KTextEditor::Plugin *configpageinterface, int id)
{
KateConfigDialog *dlg = new KateConfigDialog(this);
KateConfigDialog *dlg = KateConfigDialog::widget(this);
if (dlg->mainwWindow() != this) {
dlg->reject();
if (dlg->mainwWindow())
dlg->mainwWindow()->removeWidget(dlg);
delete dlg;
dlg = KateConfigDialog::widget(this);
}
if (configpageinterface) {
dlg->showAppPluginPage(configpageinterface, id);
}
if (dlg->exec() == QDialog::Accepted) {
m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
}
activateWidget(dlg);
delete dlg;
connect(dlg, &QDialog::rejected, this, [this, dlg]() {
removeWidget(dlg);
});
m_viewManager->reactivateActiveView(); // gui (toolbars...) needs to be updated, because
// of possible changes that the configure dialog
// could have done on it, specially for plugins.
connect(dlg, &KateConfigDialog::saved, this, [this]() {
m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
// gui (toolbars...) needs to be updated, because
// of possible changes that the configure dialog
// could have done on it, specially for plugins.
m_viewManager->replugActiveView();
});
return true;
}
......
......@@ -758,6 +758,16 @@ void KateViewManager::activateSpace(KTextEditor::View *v)
}
}
void KateViewManager::replugActiveView()
{
if (auto view = activeView()) {
if (m_guiMergedView == view) {
mainWindow()->guiFactory()->removeClient(m_guiMergedView);
mainWindow()->guiFactory()->addClient(view);
}
}
}
void KateViewManager::reactivateActiveView()
{
KTextEditor::View *view = activeView();
......
......@@ -276,6 +276,8 @@ public Q_SLOTS:
/** hide every view but the active one */
void slotHideOtherViews(bool hideOthers);
void replugActiveView();
void reactivateActiveView();
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment