mirror of
https://github.com/KDE/konsole.git
synced 2025-12-23 23:38:08 -05:00
Return status of loadLayout to avoid empty window
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -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)")));
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user