[education/rkward/devel/workspace_output] rkward: Bring output directory actions to the menu. Open is still missing.

Thomas Friedrichsmeier null at kde.org
Tue Mar 1 21:48:23 GMT 2022


Git commit 641ca38eef10e682c4fe9d517b0cecf07bb902ec by Thomas Friedrichsmeier.
Committed on 01/03/2022 at 21:48.
Pushed by tfry into branch 'devel/workspace_output'.

Bring output directory actions to the menu. Open is still missing.

M  +6    -5    rkward/misc/rkoutputdirectory.cpp
M  +4    -4    rkward/rkward.cpp
M  +5    -5    rkward/windows/rkcommandeditorwindow.cpp
M  +1    -6    rkward/windows/rkcommandeditorwindow.h
M  +64   -21   rkward/windows/rkhtmlwindow.cpp
M  +15   -10   rkward/windows/rkhtmlwindow.h
M  +3    -1    rkward/windows/rkmdiwindow.cpp
M  +8    -1    rkward/windows/rkmdiwindow.h
M  +5    -1    rkward/windows/rkoutputwindow.rc

https://invent.kde.org/education/rkward/commit/641ca38eef10e682c4fe9d517b0cecf07bb902ec

diff --git a/rkward/misc/rkoutputdirectory.cpp b/rkward/misc/rkoutputdirectory.cpp
index 725d4341..cd122da5 100644
--- a/rkward/misc/rkoutputdirectory.cpp
+++ b/rkward/misc/rkoutputdirectory.cpp
@@ -239,12 +239,13 @@ GenericRRequestResult RKOutputDirectory::import(const QString& _dir) {
 GenericRRequestResult RKOutputDirectory::revert(OverwriteBehavior discard) {
 	RK_TRACE (APP);
 
-	if (save_filename.isEmpty()) {
-		return GenericRRequestResult::makeError(i18n("Output has not previously been saved. Cannot revert."));
-	}
 	if (!isModifiedAccurate()) return GenericRRequestResult(id, i18n("Output had no modifications. Nothing reverted."));
 	if (discard == Ask) {
-		if (KMessageBox::warningContinueCancel(RKWardMainWindow::getMain(), i18n("Reverting will destroy any changes, since the last time you saved (%1). Are you sure you want to proceed?", save_timestamp.toString())) == KMessageBox::Continue) {
+		if (save_filename.isEmpty()) {
+			if (KMessageBox::warningContinueCancel(RKWardMainWindow::getMain(), i18n("This output has not been saved before. Reverting will clear it, entirely. Are you sure you want to proceed?")) == KMessageBox::Continue) {
+				discard = Force;
+			}
+		} else if (KMessageBox::warningContinueCancel(RKWardMainWindow::getMain(), i18n("Reverting will destroy any changes, since the last time you saved (%1). Are you sure you want to proceed?", save_timestamp.toString())) == KMessageBox::Continue) {
 			discard = Force;
 		}
 	}
@@ -333,7 +334,7 @@ bool RKOutputDirectory::isModifiedAccurate() const {
 QString RKOutputDirectory::caption() const {
 	RK_TRACE(APP);
 	if (!save_filename.isEmpty()) return QFileInfo(save_filename).fileName();
-	return i18n("[Not saved]");
+	return i18n("[Unnamed]");
 }
 
 GenericRRequestResult RKOutputDirectory::purge(RKOutputDirectory::OverwriteBehavior discard, RCommandChain* chain, bool activate_other) {
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 72e39da2..748bfdde 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -2,7 +2,7 @@
                           rkward.cpp  -  description
                              -------------------
     begin                : Tue Oct 29 20:06:08 CET 2002
-    copyright            : (C) 2002-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2002-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -677,10 +677,10 @@ void RKWardMainWindow::partChanged (KParts::Part *part) {
 	plugged_save_actions.clear ();
 
 	RKMDIWindow *w = RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::Attached);
-	if (w && (w->isType (RKMDIWindow::CommandEditorWindow))) {
-		QAction *a = static_cast<RKCommandEditorWindow*>(w)->fileSaveAction ();
+	if (w) {
+		QAction *a = w->fileSaveAction ();
 		if (a) plugged_save_actions.append (a);
-		a = static_cast<RKCommandEditorWindow*>(w)->fileSaveAsAction ();
+		a = w->fileSaveAsAction ();
 		if (a) plugged_save_actions.append (a);
 	}
 	for (int i = 0; i < plugged_save_actions.size (); ++i) {
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 950a95b3..4a872fd9 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -411,10 +411,10 @@ void RKCommandEditorWindow::initializeActions (KActionCollection* ac) {
 	actionmenu_preview->addAction (action_preview_as_you_type);
 	ac->addAction ("render_preview", actionmenu_preview);
 
-	file_save = findAction (m_view, "file_save");
-	if (file_save) file_save->setText (i18n ("Save Script..."));
-	file_save_as = findAction (m_view, "file_save_as");
-	if (file_save_as) file_save_as->setText (i18n ("Save Script As..."));
+	file_save_action = findAction (m_view, "file_save");
+	if (file_save_action) file_save_action->setText (i18n ("Save Script..."));
+	file_save_as_action = findAction (m_view, "file_save_as");
+	if (file_save_as_action) file_save_as_action->setText (i18n ("Save Script As..."));
 }
 
 void RKCommandEditorWindow::initBlocks () {
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 0a8d2969..a1891b41 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -146,9 +146,6 @@ public slots:
 
 /** apply our customizations to the katepart GUI */
 	void fixupPartGUI ();
-
-	QAction* fileSaveAction () { return file_save; };
-	QAction* fileSaveAsAction () { return file_save_as; };
 protected:
 /** reimplemented from RKMDIWindow: give the editor window a chance to object to being closed (if unsaved) */
 	void closeEvent (QCloseEvent *e) override;
@@ -194,8 +191,6 @@ private:
 	void addBlock (int index, const KTextEditor::Range& range);
 	void removeBlock (int index, bool was_deleted=false);
 
-	QAction *file_save, *file_save_as;
-
 	KActionMenu* actionmenu_mark_block;
 	KActionMenu* actionmenu_unmark_block;
 	KActionMenu* actionmenu_run_block;
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 952e7bca..0c9d4408 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -2,7 +2,7 @@
                           rkhtmlwindow  -  description
                              -------------------
     begin                : Wed Oct 12 2005
-    copyright            : (C) 2005-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -418,10 +418,28 @@ void RKHTMLWindow::slotPrint () {
 	delete dlg;
 }
 
-void RKHTMLWindow::slotSave () {
+void RKHTMLWindow::slotExport() {
+	RK_TRACE(APP);
+
+	page->downloadUrl(page->url());
+}
+
+void RKHTMLWindow::slotSave() {
+	RK_TRACE(APP);
+	RK_ASSERT(dir);
+	dir->save(dir->filename());
+}
+
+void RKHTMLWindow::slotSaveAs() {
 	RK_TRACE (APP);
+	RK_ASSERT(dir);
+	dir->save();
+}
 
-	page->downloadUrl (page->url ());
+void RKHTMLWindow::slotRevert() {
+	RK_TRACE (APP);
+	RK_ASSERT(dir);
+	dir->revert();
 }
 
 void RKHTMLWindow::openLocationFromHistory (VisitedLocation &loc) {
@@ -550,7 +568,10 @@ bool RKHTMLWindow::openURL (const QUrl &url) {
 			current_url = url;	// needs to be set before registering
 			RKOutputWindowManager::self ()->registerWindow (this);
 			dir = RKOutputDirectory::getOutputByWorkPath(url.toLocalFile());
-			connect(dir, &RKOutputDirectory::stateChange, this, &RKHTMLWindow::updateState);
+			part->setOutputDirectoryActionsEnabled(dir != nullptr);
+			if (dir) {
+				connect(dir, &RKOutputDirectory::stateChange, this, &RKHTMLWindow::updateState);
+			}
 		}
 	}
 
@@ -684,7 +705,7 @@ void RKHTMLWindow::updateCaption (const QUrl &url) {
 	if (window_mode == HTMLOutputWindow) {
 		if (dir) {
 			QString name = QFileInfo(dir->filename()).fileName();
-			if (name.isEmpty()) name = i18n("New Output");
+			if (name.isEmpty()) name = i18n("Unnamed");
 			QString mods;
 			if (dir->isActive()) mods.append(i18n("[Active]"));
 			// TODO: use icon(s), instead
@@ -787,6 +808,12 @@ void RKHTMLWindow::fileDoesNotExistMessage () {
 void RKHTMLWindow::flushOutput () {
 	RK_TRACE (APP);
 
+	if (dir) {
+		dir->clear();
+		return;
+	}
+
+	// TODO: remove legacy code below, eventually
 	int res = KMessageBox::questionYesNo (this, i18n ("Do you really want to clear the output? This will also remove all image files used in the output. It will not be possible to restore it."), i18n ("Flush output?"));
 	if (res==KMessageBox::Yes) {
 		QFile out_file (current_url.toLocalFile ());
@@ -845,8 +872,9 @@ void RKHTMLWindowPart::initActions () {
 	actionCollection ()->addAction ("view_encoding", encoding);
 	connect (encoding, static_cast<void (KCodecAction::*)(QTextCodec *)>(&KCodecAction::triggered), window, &RKHTMLWindow::setTextEncoding);
 
-	print = actionCollection ()->addAction (KStandardAction::Print, "print_html", window, SLOT (slotPrint()));
-	save_page = actionCollection ()->addAction (KStandardAction::Save, "save_html", window, SLOT (slotSave()));
+	print = actionCollection()->addAction(KStandardAction::Print, "print_html", window, SLOT (slotPrint()));
+	export_page = actionCollection()->addAction("save_html", new QAction(QIcon::fromTheme("file-save"), i18n("Export Page as HTML"), this));
+	connect(export_page, &QAction::triggered, window, &RKHTMLWindow::slotExport);
 
 	run_selection = RKStandardActions::runCurrent (window, window, SLOT (runSelection()));
 
@@ -858,11 +886,20 @@ void RKHTMLWindowPart::initActions () {
 	forward->setEnabled (false);
 
 	// output window actions
+	window->file_save_action = actionCollection()->addAction(KStandardAction::Save, window, SLOT(slotSave()));
+	window->file_save_action->setText(i18n("Save Output"));
+	window->file_save_as_action = actionCollection()->addAction(KStandardAction::SaveAs, window, SLOT(slotSaveAs()));
+	window->file_save_action->setText(i18n("Save Output As"));
+
 	outputFlush = actionCollection ()->addAction ("output_flush", window, SLOT (flushOutput()));
-	outputFlush->setText (i18n ("&Flush Output"));
+	outputFlush->setText (i18n ("&Clear Output"));
 	outputFlush->setIcon (QIcon::fromTheme("edit-delete"));
 
-	outputRefresh = actionCollection ()->addAction ("output_refresh", window->page->action (RKWebPage::Reload));
+	outputRefresh = actionCollection()->addAction("output_refresh", window->page->action(RKWebPage::Reload));
+
+	revert = actionCollection()->addAction("output_revert", window, SLOT(slotRevert()));
+	revert->setText(i18n("&Revert to last saved state"));
+	revert->setIcon (QIcon::fromTheme("edit-undo"));
 
 	actionCollection ()->addAction (KStandardAction::Find, "find", window->findbar, SLOT (activate()));
 	QAction* findAhead = actionCollection ()->addAction ("find_ahead", new QAction (i18n ("Find as you type"), this));
@@ -872,22 +909,28 @@ void RKHTMLWindowPart::initActions () {
 	actionCollection ()->addAction (KStandardAction::FindPrev, "find_previous", window->findbar, SLOT (backward()));
 }
 
-void RKHTMLWindowPart::setOutputWindowSkin () {
-	RK_TRACE (APP);
+void RKHTMLWindowPart::setOutputDirectoryActionsEnabled(bool enable) {
+	RK_TRACE(APP);
 
-	print->setText (i18n ("Print output"));
-	save_page->setText (i18n ("Save Output as HTML"));
-	setXMLFile ("rkoutputwindow.rc");
-	run_selection->setVisible (false);
+	window->file_save_action->setVisible(enable);
+	window->file_save_as_action->setVisible(enable);
+	revert->setVisible(enable);
 }
 
-void RKHTMLWindowPart::setHelpWindowSkin () {
-	RK_TRACE (APP);
+void RKHTMLWindowPart::setOutputWindowSkin() {
+	RK_TRACE(APP);
+
+	print->setText(i18n("Print output"));
+	setXMLFile("rkoutputwindow.rc");
+	run_selection->setVisible(false);
+}
+
+void RKHTMLWindowPart::setHelpWindowSkin() {
+	RK_TRACE(APP);
 
-	print->setText (i18n ("Print page"));
-	save_page->setText (i18n ("Export page as HTML"));
-	setXMLFile ("rkhelpwindow.rc");
-	run_selection->setVisible (true);
+	print->setText(i18n("Print page"));
+	setXMLFile("rkhelpwindow.rc");
+	run_selection->setVisible(true);
 }
 
 //////////////////////////////////////////
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index 98dc2331..ee78489e 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -2,7 +2,7 @@
                           rkhtmlwindow  -  description
                              -------------------
     begin                : Wed Oct 12 2005
-    copyright            : (C) 2005-2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -83,8 +83,11 @@ public:
 
 	WindowMode mode () { return window_mode; };
 public slots:
-	void slotPrint ();
-	void slotSave ();
+	void slotPrint();
+	void slotExport();
+	void slotSave();
+	void slotSaveAs();
+	void slotRevert();
 	void slotForward ();
 	void slotBack ();
 	void selectionChanged ();
@@ -149,23 +152,25 @@ public:
 	explicit RKHTMLWindowPart (RKHTMLWindow *window);
 	~RKHTMLWindowPart () {};
 
-	void setOutputWindowSkin ();
-	void setHelpWindowSkin ();
-	void initActions ();
+	void setOutputDirectoryActionsEnabled(bool enable);
+	void setOutputWindowSkin();
+	void setHelpWindowSkin();
+	void initActions();
 private:
 friend class RKHTMLWindow;
 	RKHTMLWindow *window;
 
 	// general actions
-	QAction *run_selection;
+	QAction* run_selection;
 	QAction* print;
 	// actions in output window mode
 	QAction* outputFlush;
 	QAction* outputRefresh;
 	// actions in help window mode
-	QAction *back;
-	QAction *forward;
-	QAction* save_page;
+	QAction* back;
+	QAction* forward;
+	QAction* export_page;
+	QAction* revert;
 };
 
 /**
diff --git a/rkward/windows/rkmdiwindow.cpp b/rkward/windows/rkmdiwindow.cpp
index ef1c9637..2adabdce 100644
--- a/rkward/windows/rkmdiwindow.cpp
+++ b/rkward/windows/rkmdiwindow.cpp
@@ -2,7 +2,7 @@
                           rkmdiwindow  -  description
                              -------------------
     begin                : Tue Sep 26 2006
-    copyright            : (C) 2006 - 2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2006 - 2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -73,6 +73,8 @@ RKMDIWindow::RKMDIWindow (QWidget *parent, int type, bool tool_window, const cha
 	standard_client = 0;
 	status_popup = 0;
 	status_popup_container = 0;
+	file_save_action = 0;
+	file_save_as_action = 0;
 
 	if (!(type & KatePluginWindow)) setWindowIcon (RKStandardIcons::iconForWindow (this));
 }
diff --git a/rkward/windows/rkmdiwindow.h b/rkward/windows/rkmdiwindow.h
index a50182e6..6fa648c2 100644
--- a/rkward/windows/rkmdiwindow.h
+++ b/rkward/windows/rkmdiwindow.h
@@ -2,7 +2,7 @@
                           rkmdiwindow  -  description
                              -------------------
     begin                : Tue Sep 26 2006
-    copyright            : (C) 2006 - 2020 by Thomas Friedrichsmeier
+    copyright            : (C) 2006 - 2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -130,6 +130,10 @@ is simply busy (e.g. when saving the current plot to history). */
 	KActionCollection *standardActionCollection ();
 /** plugin-accessible properties of this object in the global context. Currently used only by RKEditorDataFrame to give information on the currently active data.frame. NOTE: ATM, you cannot set arbitrary properties. Only those supported in RKStandardComponent will have an effect. */
 	QString globalContextProperty (const QString& property) { return global_context_properties.value (property); };
+/** @returns the save action applicable for this window (if any). Will be plugged into the save dropdown */
+	QAction* fileSaveAction () { return file_save_action; };
+/** @returns the save as action applicable for this window (if any). Will be plugged into the save dropdown */
+	QAction* fileSaveAsAction () { return file_save_as_action; };
 signals:
 /** This signal is emitted, whenever the window caption was changed.
 @param RKMDIWindow* a pointer to this window */
@@ -161,6 +165,9 @@ friend class RKWorkplace;
 	int type;
 private slots:
 	void slotActivateForFocusFollowsMouse ();
+protected:
+	QAction* file_save_as_action;
+	QAction* file_save_action;
 private:
 friend class RKToolWindowBar;
 /** state of this window (attached / detached). This is usually set from the RKWorkplace */
diff --git a/rkward/windows/rkoutputwindow.rc b/rkward/windows/rkoutputwindow.rc
index d0af99a7..427f2970 100644
--- a/rkward/windows/rkoutputwindow.rc
+++ b/rkward/windows/rkoutputwindow.rc
@@ -1,7 +1,9 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward_outputwindow" version="641">
+<kpartgui name="rkward_outputwindow" version="721">
 	<MenuBar>
 		<Menu name="file"><text>&File</text>
+			<Action name="file_save"/>
+			<Action name="file_save_as"/>
 			<Action name="print_html"/>
 			<Action name="save_html"/>
 		</Menu>
@@ -15,6 +17,7 @@
 			<Action name="select_all"/>
 			<Separator/>
 			<Action name="output_flush"/>
+			<Action name="output_revert"/>
 		</Menu>
 		<Menu name="view"><text>&View</text>
 			<Action name="zoom_in"/>
@@ -26,6 +29,7 @@
 	</MenuBar>
 	<ToolBar fullWidth="true" name="mainToolBar">
 		<Action name="output_flush"/>
+		<Action name="output_revert"/>
 		<Action name="output_refresh"/>
 	</ToolBar>
 </kpartgui>


More information about the rkward-tracker mailing list