[education/rkward/devel/workspace_output] rkward/misc: Fix showing not-yet-intialized outputs for real, this time.
Thomas Friedrichsmeier
null at kde.org
Sat Feb 19 22:10:21 GMT 2022
Git commit 41e4ac851f5c0a095879c232978f450d61c4745c by Thomas Friedrichsmeier.
Committed on 19/02/2022 at 22:09.
Pushed by tfry into branch 'devel/workspace_output'.
Fix showing not-yet-intialized outputs for real, this time.
M +22 -15 rkward/misc/rkoutputdirectory.cpp
M +3 -2 rkward/misc/rkoutputdirectory.h
https://invent.kde.org/education/rkward/commit/41e4ac851f5c0a095879c232978f450d61c4745c
diff --git a/rkward/misc/rkoutputdirectory.cpp b/rkward/misc/rkoutputdirectory.cpp
index 047803e4..bb6364bc 100644
--- a/rkward/misc/rkoutputdirectory.cpp
+++ b/rkward/misc/rkoutputdirectory.cpp
@@ -264,23 +264,16 @@ RKOutputDirectory* RKOutputDirectory::createOutputDirectoryInternal() {
return d;
}
-RKOutputDirectory::initializeIfNeeded(RCommandChain *chain) {
- if(!initialized) {
- RK_TRACE (APP);
- // when an output directory is first initialized, we don't want that to count as a "modification". Therefore, update the "saved hash" _after_ initialization
- RCommand *command = new RCommand(QString(), RCommand::App | RCommand::Sync | RCommand::EmptyCommand);
- connect(command->notifier(), &RCommandNotifier::commandFinished, this, &RKOutputDirectory::updateSavedHash);
- RKGlobals::rInterface()->issueCommand(command, chain);
- initialized = true;
- }
-}
-
GenericRRequestResult RKOutputDirectory::activate(RCommandChain* chain) {
RK_TRACE (APP);
QString index_file = work_dir + "/index.html";
RKGlobals::rInterface()->issueCommand(QStringLiteral("rk.set.output.html.file(\"") + RKCommonFunctions::escape(index_file) + QStringLiteral("\")\n"), RCommand::App, QString(), 0, 0, chain);
- initializeIfNeeded(chain);
+ // when an output directory is first initialized, we don't want that to count as a "modification". Therefore, update the "saved hash" _after_ initialization
+ RCommand *command = new RCommand(QString(), RCommand::App | RCommand::Sync | RCommand::EmptyCommand);
+ connect(command->notifier(), &RCommandNotifier::commandFinished, this, &RKOutputDirectory::updateSavedHash);
+ RKGlobals::rInterface()->issueCommand(command, chain);
+ initialized = true;
return GenericRRequestResult(QVariant(index_file));
}
@@ -445,9 +438,24 @@ RKOutputDirectory::OverwriteBehavior parseOverwrite(const QString ¶m) {
return RKOutputDirectory::Fail;
}
-GenericRRequestResult RKOutputDirectory::view(bool raise) {
+RKOutputDirectory* RKOutputDirectory::activeOutput() {
+ for (auto it = outputs.constBegin(); it != outputs.constEnd(); ++it) {
+ if (it.value()->isActive()) {
+ return it.value();
+ }
+ }
+ return nullptr;
+}
+
+GenericRRequestResult RKOutputDirectory::view(bool raise, RCommandChain* chain) {
RK_TRACE(APP);
+ if (!initialized) {
+ // currently, activating is the only way to init. That's a bit lame, but then, viewing an uninitialzed output is rather a corner case, anyway.
+ RKOutputDirectory *active = activeOutput();
+ activate(chain);
+ if (active) active->activate();
+ }
auto list = RKOutputWindowManager::self()->existingOutputWindows(workPath());
if (!list.isEmpty()) {
auto w = list[0];
@@ -455,7 +463,6 @@ GenericRRequestResult RKOutputDirectory::view(bool raise) {
list[0]->activate();
}
} else {
- initializeIfNeeded(chain);
RKWorkplace::mainWorkplace()->openOutputWindow(QUrl::fromLocalFile(workPath()));
}
return GenericRRequestResult(id);
@@ -531,7 +538,7 @@ GenericRRequestResult RKOutputDirectory::handleRCall(const QStringList& params,
} else if (command == QStringLiteral("close")) {
return out->purge(parseOverwrite(params.value(2)), chain);
} else if (command == QStringLiteral("view")) {
- return out->view(params.value(2) == QStringLiteral("raise"));
+ return out->view(params.value(2) == QStringLiteral("raise"), chain);
} else if (command == QStringLiteral("workingDir")) {
return GenericRRequestResult(out->workDir());
} else if (command == QStringLiteral("filename")) {
diff --git a/rkward/misc/rkoutputdirectory.h b/rkward/misc/rkoutputdirectory.h
index 916c5c61..1628a60f 100644
--- a/rkward/misc/rkoutputdirectory.h
+++ b/rkward/misc/rkoutputdirectory.h
@@ -60,7 +60,7 @@ public:
bool isEmpty() const;
bool isActive() const;
bool isModified() const;
- GenericRRequestResult view(bool raise);
+ GenericRRequestResult view(bool raise, RCommandChain* chain=0);
QString filename() const { return save_filename; };
QString workDir() const { return work_dir; }
QString workPath() const;
@@ -85,7 +85,8 @@ private:
RKOutputDirectory();
~RKOutputDirectory();
void updateSavedHash();
- void initializeIfNeeded(RCommandChain *chain);
+ /** Currently active output. Could be nullptr in corner cases! */
+ RKOutputDirectory* activeOutput();
QString saved_hash;
QDateTime save_timestamp;
More information about the rkward-tracker
mailing list