Return status of loadLayout to avoid empty window

This commit is contained in:
Kurt Hindenburg
2024-08-09 15:54:03 -04:00
parent 0e216b34a4
commit 004a788916
3 changed files with 15 additions and 7 deletions

View File

@@ -195,9 +195,13 @@ int Application::newInstance()
// if layout file is enable load it and create session from definitions,
// else create new session
bool validSessions = false;
if (m_parser->isSet(QStringLiteral("layout"))) {
window->viewManager()->loadLayout(m_parser->value(QStringLiteral("layout")));
} else {
validSessions = window->viewManager()->loadLayout(m_parser->value(QStringLiteral("layout")));
}
// loadLayout() failed or not using --layout
if (!validSessions) {
Session *session = window->createSession(newProfile, QString());
const QString workingDir = m_parser->value(QStringLiteral("workdir"));

View File

@@ -47,6 +47,7 @@
#include "terminalDisplay/TerminalDisplay.h"
#include "widgets/ViewContainer.h"
#include "widgets/ViewSplitter.h"
#include "konsoledebug.h"
using namespace Konsole;
@@ -1239,27 +1240,30 @@ ViewSplitter *restoreSessionsSplitterRecurse(const QJsonObject &jsonSplitter, Vi
}
} // namespace
void ViewManager::loadLayout(QString file)
bool ViewManager::loadLayout(QString file)
{
// User pressed cancel in dialog
if (file.isEmpty()) {
return;
return false;
}
QFile jsonFile(file);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
KMessageBox::error(this->widget(), i18nc("@label:textbox", "A problem occurred when loading the Layout.\n%1", jsonFile.fileName()));
qCDebug(KonsoleDebug) << "A problem occurred when loading the Layout " << jsonFile.fileName();
return false;
}
auto json = QJsonDocument::fromJson(jsonFile.readAll());
if (!json.isEmpty()) {
auto splitter = restoreSessionsSplitterRecurse(json.object(), this, false);
_viewContainer->addSplitter(splitter, _viewContainer->count());
return true;
}
return false;
}
void ViewManager::loadLayoutFile()
{
loadLayout(QFileDialog::getOpenFileName(this->widget(),
auto result = loadLayout(QFileDialog::getOpenFileName(this->widget(),
i18nc("@title:window", "Load Tab Layout"),
QStringLiteral("~/"),
i18nc("@item:inlistbox", "Konsole View Layout (*.json)")));

View File

@@ -312,7 +312,7 @@ public Q_SLOTS:
// Creates json file with split config
Q_SCRIPTABLE void saveLayoutFile();
Q_SCRIPTABLE void loadLayoutFile();
Q_SCRIPTABLE void loadLayout(QString File);
Q_SCRIPTABLE bool loadLayout(QString File);
/** DBus slot that returns a description of the layout hierarchy
* in each tab.