Commit f7adcb22 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Save (but do not load yet) workplace item for opened output windows

parent 193fcae3
......@@ -65,7 +65,7 @@ QString hashDirectoryState(const QString& dir) {
QMap<QString, RKOutputDirectory*> RKOutputDirectory::outputs;
RKOutputDirectory::RKOutputDirectory() : initialized(false), window(nullptr) {
RKOutputDirectory::RKOutputDirectory() : initialized(false) {
RK_TRACE(APP);
}
......@@ -91,6 +91,19 @@ RKOutputDirectory* RKOutputDirectory::getOutputBySaveUrl(const QString& _dest) {
return nullptr;
}
RKOutputDirectory* RKOutputDirectory::getOutputByWindow(const RKMDIWindow *window) {
RK_TRACE (APP);
if (!window) return nullptr;
if (!window->isType(RKMDIWindow::OutputWindow)) return nullptr;
for (auto it = outputs.constBegin(); it != outputs.constEnd(); ++it) {
if (it.value()->workPath() == static_cast<const RKHTMLWindow*>(window)->url().toLocalFile()) {
return(it.value());
}
}
return nullptr;
}
GenericRRequestResult RKOutputDirectory::save(const QString& _dest, RKOutputDirectory::OverwriteBehavior overwrite) {
RK_TRACE (APP);
......
......@@ -56,6 +56,7 @@ public:
static GenericRRequestResult handleRCall(const QStringList& params, RCommandChain *chain);
static RKOutputDirectory* getOutputById(const QString& id);
static RKOutputDirectory* getOutputBySaveUrl(const QString& dest);
static RKOutputDirectory* getOutputByWindow(const RKMDIWindow* window);
/** Return a list of all current output directories that have been modified. Used for asking for save during shutdown. */
static QList<RKOutputDirectory*> modifiedOutputDirectories();
......@@ -79,7 +80,6 @@ private:
QString id;
bool initialized;
QPointer<RKMDIWindow> window;
/** map of outputs. */
static QMap<QString, RKOutputDirectory*> outputs;
......
......@@ -9,7 +9,11 @@
#' an instance of the \code{RK.Output} reference class, which has methods for subsequent manipulation. Two instances of this class may be pointing to the same
#' logical output file/directory (e.g. when loading the same output file, twice), in which case any operation will affect both instances the same.
#'
#' Internally, outputs are managed by the RKWard frontend. The frontend will ask to save any unsaved modified output pages on exit.
#' Internally, outputs are managed by the RKWard frontend. The frontend will ask to save any unsaved modified output pages on exit, even if those are not currently shown.
#'
#' Output references can be assigned to a symbol, which may be useful when writing to several output files in turn. However, such references should be considered
#' short-lived. Importantly, they will not currently remain valid across sessions. Where this may be a concern, code should obtain a new reference using
#' rk.output(filename="something") at relevant entry points to subsequent code.
#'
#' At the time of this writing, output is stored in directories containing an HTML index file, and, usually, several image files, and possibly more.
#' However other types of output may be supported in the future, and therefore assumptions about the details of the output storage should be avoided.
......
......@@ -593,10 +593,6 @@ bool RKHTMLWindow::openURL (const QUrl &url) {
return true;
}
QUrl RKHTMLWindow::url () {
return current_url;
}
void RKHTMLWindow::mimeTypeJobFail (KJob* job) {
RK_TRACE (APP);
......
......@@ -74,7 +74,7 @@ public:
bool isModified () override;
/** Return current url */
QUrl url ();
QUrl url () const { return current_url; };
/** Return current url in a restorable way, i.e. for help pages, abstract the session specific part of the path */
QUrl restorableUrl ();
......
......@@ -800,8 +800,15 @@ QString RKWorkplace::makeItemDescription (RKMDIWindow *win) const {
specification = static_cast<RKCommandEditorWindow*> (win)->url ().url ();
if (specification.isEmpty ()) specification = static_cast<RKCommandEditorWindow*> (win)->id ();
} else if (win->isType (RKMDIWindow::OutputWindow)) {
type = "output";
specification = static_cast<RKHTMLWindow*> (win)->url ().url ();
RKOutputDirectory *dir = RKOutputDirectory::getOutputByWindow(win);
if (dir) {
type = "rkoutput";
specification = dir->filename();
} else {
// legacy support for rk.set.html.output.file()
type = "output";
specification = static_cast<RKHTMLWindow*> (win)->url ().url ();
}
} else if (win->isType (RKMDIWindow::HelpWindow)) {
type = "help";
specification = static_cast<RKHTMLWindow*> (win)->restorableUrl ().url ();
......
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