[rkward-cvs] SF.net SVN: rkward:[2481] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri May 15 13:48:58 UTC 2009
Revision: 2481
http://rkward.svn.sourceforge.net/rkward/?rev=2481&view=rev
Author: tfry
Date: 2009-05-15 13:48:58 +0000 (Fri, 15 May 2009)
Log Message:
-----------
This commit makes handling of various urls more consistent.
Also the different HTML-windows are re-unified into one class that simply uses two different ui.rc-files.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rkward.cpp
trunk/rkward/rkward/windows/rkfilebrowser.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.h
trunk/rkward/rkward/windows/rkworkplace.cpp
trunk/rkward/rkward/windows/rkworkplace.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/ChangeLog 2009-05-15 13:48:58 UTC (rev 2481)
@@ -1,3 +1,4 @@
+- Fixed: Opening most file type (e.g. PDF) from the help browser was broken TODO: backport in basic form
- Fixed: Make built-in editor work again for file.edit ()
- (Almost) all plugins now write a header to the output window TODO: work in progress; which ones should not?
- Add convenience function "makeHeaderCode()" for use inside plugins TODO: document, adjust for tests (->rk.describe.alternative())
Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/rkward.cpp 2009-05-15 13:48:58 UTC (rev 2481)
@@ -238,7 +238,7 @@
setUpdatesEnabled (true);
show ();
- RKOutputWindow::initialize ();
+ RKHTMLWindow::initializeOutputWindow ();
if (!open_url.isEmpty()) {
openWorkspace (open_url);
Modified: trunk/rkward/rkward/windows/rkfilebrowser.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkfilebrowser.cpp 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/windows/rkfilebrowser.cpp 2009-05-15 13:48:58 UTC (rev 2481)
@@ -2,7 +2,7 @@
rkfilebrowser - description
-------------------
begin : Thu Apr 26 2007
- copyright : (C) 2007, 2008 by Thomas Friedrichsmeier
+ copyright : (C) 2007, 2008, 2009 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -22,7 +22,6 @@
#include <kurlcompletion.h>
#include <kcompletionbox.h>
#include <ktoolbar.h>
-#include <krun.h>
#include <kactioncollection.h>
#include <qdir.h>
@@ -167,20 +166,7 @@
void RKFileBrowserWidget::fileActivated (const KFileItem& item) {
RK_TRACE (APP);
- QString mimetype = item.mimetype ();
- if (mimetype.startsWith ("text/")) {
- if (mimetype == "text/html") {
- RKWorkplace::mainWorkplace ()->openHelpWindow (item.url (), true);
- } else {
- RKWorkplace::mainWorkplace ()->openScriptEditor (item.url ());
- }
- } else {
- if (item.name (true).endsWith (".rdata")) {
- RKWardMainWindow::getMain ()->fileOpenAskSave (item.url ());
- } else {
- new KRun (item.url (), topLevelWidget(), item.mode (), item.isLocalFile ());
- }
- }
+ RKWorkplace::mainWorkplace ()->openAnyUrl (item.url ());
}
#include "rkfilebrowser.moc"
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2009-05-15 13:48:58 UTC (rev 2481)
@@ -22,7 +22,6 @@
#include <klocale.h>
#include <kiconloader.h>
#include <kmessagebox.h>
-#include <krun.h>
#include <kparts/partmanager.h>
#include <kactioncollection.h>
@@ -47,10 +46,16 @@
#include "../windows/rkworkplaceview.h"
#include "../debug.h"
-RKHTMLWindow::RKHTMLWindow (QWidget *parent) : RKMDIWindow (parent, RKMDIWindow::HelpWindow) {
+//static
+RKHTMLWindow* RKHTMLWindow::current_output = 0;
+QDateTime RKHTMLWindow::last_refresh_time;
+
+RKHTMLWindow::RKHTMLWindow (QWidget *parent, WindowMode mode) : RKMDIWindow (parent, RKMDIWindow::HelpWindow) {
RK_TRACE (APP);
scroll_position=-1;
-
+
+ setComponentData (KGlobal::mainComponent ());
+
khtmlpart = new KHTMLPart (this, 0, KHTMLPart::BrowserViewGUI);
setPart (khtmlpart);
initializeActivationSignals ();
@@ -62,26 +67,48 @@
pLayout->setContentsMargins (0, 0, 0, 0);
pLayout->addWidget (khtmlpart->widget ());
+ // strip down the khtmlpart's GUI. remove some stuff we definitely don't need.
+ RKCommonFunctions::removeContainers (khtmlpart, QString ("tools,security,extraToolBar,saveBackground,saveFrame,printFrame,kget_menu").split (','), true);
+
// We have to connect this in order to allow browsing.
connect (khtmlpart->browserExtension (), SIGNAL (openUrlRequestDelayed (const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)), this, SLOT (slotOpenUrl (const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)));
connect (khtmlpart, SIGNAL (completed ()), this, SLOT (loadDone ()));
- back = forward = print = run_selection = 0; // initialization done in subclasses
current_history_position = -1;
url_change_is_from_history = false;
+
+ initActions ();
+ window_mode = Undefined;
+ useMode (mode);
}
RKHTMLWindow::~RKHTMLWindow () {
RK_TRACE (APP);
+ if (this == current_output) {
+ RK_ASSERT (window_mode == HTMLOutputWindow);
+ current_output = 0;
+ }
+
delete khtmlpart;
- khtmlpart = 0; // in case we try to redelete in a parent class
}
+// static
+void RKHTMLWindow::initializeOutputWindow () {
+ RK_TRACE (APP);
+
+ last_refresh_time = QDateTime::currentDateTime ();
+}
+
QString RKHTMLWindow::getDescription () {
RK_TRACE (APP);
- return ("help:" + khtmlpart->url ().url ());
+ if (window_mode == HTMLOutputWindow) {
+ return ("output:" + current_url.url ());
+
+ } else {
+ return ("help:" + current_url.url ());
+ }
}
bool RKHTMLWindow::isModified () {
@@ -89,18 +116,35 @@
return false;
}
-void RKHTMLWindow::addCommonActions (KActionCollection *action_collection) {
+void RKHTMLWindow::initActions () {
RK_TRACE (APP);
- // enable copy
- action_collection->addAction (KStandardAction::Copy, "copy", khtmlpart->browserExtension (), SLOT (copy ()));
+ // common actions
+ actionCollection ()->addAction (KStandardAction::Copy, "copy", khtmlpart->browserExtension (), SLOT (copy ()));
- // run selection
- run_selection = RKStandardActions::runSelection (action_collection, "run_selection", this, SLOT (runSelection()));
+ print = actionCollection ()->addAction (KStandardAction::Print, "print_html", this, SLOT (slotPrint()));
- // needed to enable / disable the run selection action
+ run_selection = RKStandardActions::runSelection (actionCollection (), "run_selection", this, SLOT (runSelection()));
+
+ // needed to enable / disable the run selection action
connect (khtmlpart, SIGNAL (selectionChanged()), this, SLOT (selectionChanged()));
selectionChanged ();
+
+ // help window actions
+ back = actionCollection ()->addAction (KStandardAction::Back, "help_back", this, SLOT (slotBack()));
+ back->setEnabled (false);
+
+ forward = actionCollection ()->addAction (KStandardAction::Forward, "help_forward", this, SLOT (slotForward()));
+ forward->setEnabled (false);
+
+ // output window actions
+ outputFlush = actionCollection ()->addAction ("output_flush", this, SLOT (flushOutput()));
+ outputFlush->setText (i18n ("&Flush Output"));
+ outputFlush->setIcon (KIcon ("edit-delete"));
+
+ outputRefresh = actionCollection ()->addAction ("output_refresh", this, SLOT (refresh()));
+ outputRefresh->setText (i18n ("&Refresh Output"));
+ outputRefresh->setIcon (KIcon ("view-refresh"));
}
void RKHTMLWindow::selectionChanged () {
@@ -141,6 +185,7 @@
void RKHTMLWindow::slotForward () {
RK_TRACE (APP);
+ RK_ASSERT (window_mode == HTMLHelpWindow);
url_change_is_from_history = true;
@@ -157,6 +202,7 @@
void RKHTMLWindow::slotBack () {
RK_TRACE (APP);
+ RK_ASSERT (window_mode == HTMLHelpWindow);
url_change_is_from_history = true;
--current_history_position;
@@ -180,48 +226,62 @@
#warning TODO: error handling!
return true;
} else {
- RKWorkplace::mainWorkplace ()->openHelpWindow (url);
+ bool ok = false;
+ if (url.host () == "component") {
+ ok = renderRKHelp (url);
+ } else if (url.host () == "rhelp") {
+ // TODO: find a nice solution to render this in the current window
+ RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (url.path ().mid (1));
+ return true;
+ } else if (url.host () == "page") {
+ ok = renderRKHelp (url);
+ }
+
+ if (!ok) {
+ fileDoesNotExistMessage ();
+ }
+
+ changeURL (url);
return true;
}
}
return false;
}
+#include <kmimetype.h>
bool RKHTMLWindow::openURL (const KUrl &url) {
RK_TRACE (APP);
if (handleRKWardURL (url)) return true;
// asyncrhonously dealing with non-local files would be quite a task. We chose the simple answer instead...
- if (!url.isLocalFile ()) {
- if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file. Do you want to open the url in the default application?", url.prettyUrl ()), i18n ("Open in default application?")) != KMessageBox::Yes) {
- return false;
- }
- KRun *runner = new KRun (url, topLevelWidget()); // according to KRun-documentation, KRun will self-destruct when done.
- runner->setRunExecutables (false);
- return false;
+ if (!(url.isLocalFile () && KMimeType::findByUrl (url)->is ("text/html"))) {
+ RKWorkplace::mainWorkplace ()->openAnyUrl (url);
+ return true;
}
- khtmlpart->openUrl (url);
+ QFileInfo out_file (url.path ());
+ bool ok = out_file.exists();
+ if (ok) {
+ khtmlpart->openUrl (url);
+ last_refresh_time = out_file.lastModified ();
+ } else {
+ fileDoesNotExistMessage ();
+ }
changeURL (url);
-
- return true;
+ return ok;
}
KUrl RKHTMLWindow::url () {
- if (khtmlpart) {
- return khtmlpart->url ();
- } else {
- RK_ASSERT (false);
- return KUrl ();
- }
+ return current_url;
}
void RKHTMLWindow::changeURL (const KUrl &url) {
+ current_url = url;
updateCaption (url);
if (!url_change_is_from_history) {
- if (back && forward) {
+ if (window_mode == HTMLHelpWindow) {
int history_last = url_history.count () - 1;
for (int i = history_last; i > current_history_position; --i) {
url_history.removeLast ();
@@ -237,7 +297,9 @@
void RKHTMLWindow::updateCaption (const KUrl &url) {
RK_TRACE (APP);
- setCaption (url.fileName ());
+
+ if (window_mode == HTMLOutputWindow) setCaption (i18n ("Output %1").arg (url.fileName ()));
+ else setCaption (url.fileName ());
}
void RKHTMLWindow::slotOpenUrl (const KUrl & url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &) {
@@ -247,8 +309,15 @@
void RKHTMLWindow::refresh () {
RK_TRACE (APP);
- scroll_position = khtmlpart->view ()->contentsY ();
- openURL (khtmlpart->url ());
+
+ KParts::OpenUrlArguments args;
+ args.setReload (true); // this forces the next openURL to reload all images
+ khtmlpart->setArguments (args);
+
+ if (window_mode == HTMLOutputWindow) scroll_position = khtmlpart->view ()->contentsHeight ();
+ else scroll_position = khtmlpart->view ()->contentsY ();
+
+ openURL (current_url);
}
void RKHTMLWindow::loadDone () {
@@ -256,99 +325,22 @@
if (scroll_position >= 0) khtmlpart->view()->setContentsPos (0, scroll_position);
}
-//##################### BEGIN RKOutputWindow #####################
-//static
-RKOutputWindow* RKOutputWindow::current_output = 0;
-QDateTime RKOutputWindow::last_refresh_time;
-
-RKOutputWindow::RKOutputWindow (QWidget *parent) : RKHTMLWindow (parent), KXMLGUIClient () {
- RK_TRACE (APP);
-
- type = RKMDIWindow::OutputWindow;
- // for this window, we need to set it explicitly, as the logic in RKHTMLWindow though we are an RKHTMLWindow, only
- setWindowIcon (RKStandardIcons::getIcon (RKStandardIcons::WindowOutput));
- // strip down the khtmlpart's GUI. remove some stuff we definitely don't need.
- RKCommonFunctions::removeContainers (khtmlpart, QString ("tools,security,extraToolBar,saveBackground,saveFrame,printFrame,kget_menu").split (','), true);
-
- setComponentData (KGlobal::mainComponent ());
- setXMLFile ("rkoutputwindow.rc");
-
- khtmlpart->insertChildClient (this);
-
- setCaption (i18n ("Output"));
-
- outputFlush = actionCollection ()->addAction ("output_flush", this, SLOT (flushOutput()));
- outputFlush->setText (i18n ("&Flush Output"));
- outputFlush->setIcon (KIcon ("edit-delete"));
-
- outputRefresh = actionCollection ()->addAction ("output_refresh", this, SLOT (refreshOutput()));
- outputRefresh->setText (i18n ("&Refresh Output"));
- outputRefresh->setIcon (KIcon ("view-refresh"));
-
- print = actionCollection ()->addAction (KStandardAction::Print, "print_output", this, SLOT (slotPrint()));
- print->setText (i18n ("Print Output"));
- addCommonActions (actionCollection ());
-
- QAction *action = khtmlpart->action ("saveDocument");
- if (action) action->setText (i18n ("Save Output as HTML"));
- else RK_ASSERT (false); // we should know about this
-}
-
//static
-void RKOutputWindow::initialize () {
+RKHTMLWindow* RKHTMLWindow::getCurrentOutput () {
RK_TRACE (APP);
+
+ if (!current_output) {
+ current_output = new RKHTMLWindow (RKWorkplace::mainWorkplace ()->view (), HTMLOutputWindow);
- QFileInfo out_file (RKSettingsModuleGeneral::filesPath () + "/rk_out.html");
- last_refresh_time = out_file.lastModified ();
-}
-
-RKOutputWindow::~RKOutputWindow () {
- RK_TRACE (APP);
-
- if (this == current_output) {
- current_output = 0;
+ KUrl url (RKSettingsModuleGeneral::filesPath () + "/rk_out.html");
+ current_output->openURL (url);
}
- delete khtmlpart;
- khtmlpart = 0; // in case we try to redelete in a parent class
+ return current_output;
}
-QString RKOutputWindow::getDescription () {
- RK_TRACE (APP);
-
- return ("output:" + output_url.url ());
-}
-
-bool RKOutputWindow::openURL (const KUrl &url) {
- RK_TRACE (APP);
-
- if (handleRKWardURL (url)) return true;
-
- output_url = url;
- QFileInfo out_file (url.path ());
- bool ok = out_file.exists();
- if (ok) {
- KParts::OpenUrlArguments args;
- args.setReload (true); // this forces the next openURL to reload all images
- khtmlpart->setArguments (args);
- RKHTMLWindow::openURL (url);
- last_refresh_time = out_file.lastModified ();
- } else {
- showOutputEmptyMessage ();
- }
- return ok;
-}
-
-void RKOutputWindow::updateCaption (const KUrl &) {
-}
-
-void RKOutputWindow::refresh () {
- scroll_position = khtmlpart->view ()->contentsHeight ();
- openURL (output_url);
-}
-
//static
-RKOutputWindow* RKOutputWindow::refreshOutput (bool show, bool raise, bool only_if_modified) {
+RKHTMLWindow* RKHTMLWindow::refreshOutput (bool show, bool raise, bool only_if_modified) {
RK_TRACE (APP);
if (only_if_modified) {
@@ -367,30 +359,65 @@
getCurrentOutput ();
}
}
-
return current_output;
}
-//static
-RKOutputWindow* RKOutputWindow::getCurrentOutput () {
+void RKHTMLWindow::useMode (WindowMode new_mode) {
RK_TRACE (APP);
-
- if (!current_output) {
- current_output = new RKOutputWindow (RKWorkplace::mainWorkplace ()->view ());
- KUrl url (RKSettingsModuleGeneral::filesPath () + "/rk_out.html");
- current_output->openURL (url);
+ RK_ASSERT (new_mode != Undefined);
+ if (window_mode == new_mode) return;
+
+ if (new_mode == HTMLOutputWindow) {
+ type = RKMDIWindow::OutputWindow;
+ setWindowIcon (RKStandardIcons::getIcon (RKStandardIcons::WindowOutput));
+
+ print->setText (i18n ("Print output"));
+ QAction *action = khtmlpart->action ("saveDocument");
+ if (action) action->setText (i18n ("Export page as HTML"));
+ else RK_ASSERT (false); // we should know about this
+
+ setXMLFile ("rkoutputwindow.rc");
+ khtmlpart->removeChildClient (this);
+ khtmlpart->insertChildClient (this);
+ } else {
+ RK_ASSERT (new_mode == HTMLHelpWindow);
+
+ type = RKMDIWindow::HelpWindow;
+ setWindowIcon (RKStandardIcons::getIcon (RKStandardIcons::WindowHelp));
+
+ print->setText (i18n ("Print page"));
+ QAction *action = khtmlpart->action ("saveDocument");
+ if (action) action->setText (i18n ("Save Output as HTML"));
+ else RK_ASSERT (false); // we should know about this
+
+ setXMLFile ("rkhelpwindow.rc");
+ khtmlpart->removeChildClient (this);
+ khtmlpart->insertChildClient (this);
}
- return current_output;
+ updateCaption (current_url);
+ window_mode = new_mode;
}
-void RKOutputWindow::flushOutput () {
+void RKHTMLWindow::fileDoesNotExistMessage () {
RK_TRACE (APP);
+ khtmlpart->begin();
+ if (window_mode == HTMLOutputWindow) {
+ khtmlpart->write (i18n ("<HTML><BODY><H1>RKWard output</H1>\n<P>The output is empty.</P>\n</BODY></HTML>"));
+ } else {
+ khtmlpart->write ("<html><body><h1>" + i18n ("Page does not exist or is broken") + "</h1></body></html>");
+ }
+ khtmlpart->end();
+}
+
+void RKHTMLWindow::flushOutput () {
+ RK_TRACE (APP);
+
int res = KMessageBox::questionYesNo (this, i18n ("Do you really want to flush the output? It will not be possible to restore it."), i18n ("Flush output?"));
if (res==KMessageBox::Yes) {
- QFile out_file (RKSettingsModuleGeneral::filesPath () + "/rk_out.html");
+ QFile out_file (current_url.path ());
QDir out_dir = QFileInfo (out_file).absoluteDir ();
out_file.remove ();
@@ -401,94 +428,20 @@
QFile file (out_dir.absoluteFilePath (*it));
file.remove ();
}
- refreshOutput (false, false, false);
+ refresh ();
}
}
-void RKOutputWindow::refreshOutput () {
+bool RKHTMLWindow::renderRKHelp (const KUrl &url) {
RK_TRACE (APP);
- refreshOutput (true, true, false);
-}
-
-void RKOutputWindow::showOutputEmptyMessage () {
- khtmlpart->begin();
- khtmlpart->write (i18n ("<HTML><BODY><H1>RKWard output</H1>\n<P>The output is empty.</P>\n</BODY></HTML>"));
- khtmlpart->end();
-}
-
-//#################### END RKOutputWindow ##########################
-//#################### BEGIN RKHelpWindow ##########################
-
-RKHelpWindow::RKHelpWindow (QWidget *parent) : RKHTMLWindow (parent), KXMLGUIClient () {
- RK_TRACE (APP);
-
- setComponentData (KGlobal::mainComponent ());
-
- // strip down the khtmlpart's GUI. remove some stuff we definitely don't need.
- RKCommonFunctions::removeContainers (khtmlpart, QString ("tools,security,extraToolBar,saveBackground,saveDocument,saveFrame,printFrame,kget_menu").split (','), true);
-
- back = actionCollection ()->addAction (KStandardAction::Back, "help_back", this, SLOT (slotBack()));
- back->setEnabled (false);
-
- forward = actionCollection ()->addAction (KStandardAction::Forward, "help_forward", this, SLOT (slotForward()));
- forward->setEnabled (false);
-
- print = actionCollection ()->addAction (KStandardAction::Print, "print_help", this, SLOT (slotPrint()));
- print->setText (i18n ("Print Help"));
- addCommonActions (actionCollection ());
-
- setXMLFile ("rkhelpwindow.rc");
-
- khtmlpart->insertChildClient (this);
-
- setCaption (i18n ("R Help"));
-}
-
-RKHelpWindow::~RKHelpWindow () {
- RK_TRACE (APP);
- delete khtmlpart;
- khtmlpart = 0; // in case we try to redelete in a parent class
-}
-
-bool RKHelpWindow::handleRKWardURL (const KUrl &url) {
- RK_TRACE (APP);
-
- if (url.protocol () == "rkward") {
- bool ok;
- if (url.host () == "component") {
- ok = renderRKHelp (url);
- } else if (url.host () == "rhelp") {
- // TODO: find a nice solution to render this in the current window
- RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (url.path ().mid (1));
- return true;
- } else if (url.host () == "page") {
- ok = renderRKHelp (url);
- } else {
- return RKHTMLWindow::handleRKWardURL (url);
- }
-
- if (!ok) {
- khtmlpart->begin (url);
- khtmlpart->write ("<html><body><h1>" + i18n ("Page does not exist or is broken") + "</h1></body></html>");
- khtmlpart->end ();
- }
-
- changeURL (url);
- return true;
- } else {
- return false;
- }
-}
-
-bool RKHelpWindow::renderRKHelp (const KUrl &url) {
- RK_TRACE (APP);
-
if (url.protocol () != "rkward") {
RK_ASSERT (false);
return (false);
}
+ useMode (HTMLHelpWindow);
+
bool for_component = false; // is this a help page for a component, or a top-level help page?
if (url.host () == "component") for_component = true;
@@ -649,7 +602,7 @@
return (success);
}
-QString RKHelpWindow::renderHelpFragment (QDomElement &fragment) {
+QString RKHTMLWindow::renderHelpFragment (QDomElement &fragment) {
RK_TRACE (APP);
// prepare all internal links
@@ -676,7 +629,7 @@
return ret;
}
-void RKHelpWindow::prepareHelpLink (QDomElement *link_element) {
+void RKHTMLWindow::prepareHelpLink (QDomElement *link_element) {
RK_TRACE (APP);
link_element->setTagName ("a");
@@ -712,7 +665,7 @@
}
}
-RKComponentHandle *RKHelpWindow::componentPathToHandle (QString path) {
+RKComponentHandle *RKHTMLWindow::componentPathToHandle (QString path) {
RK_TRACE (APP);
QStringList path_segments = path.split ('/', QString::SkipEmptyParts);
@@ -723,7 +676,7 @@
return (RKComponentMap::getComponentHandle (path_segments.join ("::")));
}
-QString RKHelpWindow::startSection (const QString &name, const QString &title, const QString &shorttitle, QStringList *anchors, QStringList *anchor_names) {
+QString RKHTMLWindow::startSection (const QString &name, const QString &title, const QString &shorttitle, QStringList *anchors, QStringList *anchor_names) {
QString ret = "<a name=\"" + name + "\">";
ret.append ("<h2>" + title + "</h2>\n");
anchors->append (name);
@@ -732,5 +685,4 @@
return (ret);
}
-
#include "rkhtmlwindow.moc"
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.h 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.h 2009-05-15 13:48:58 UTC (rev 2481)
@@ -28,6 +28,8 @@
class KActionCollection;
class KRecentFilesAction;
class QAction;
+class QDomElement;
+class RKComponentHandle;
/**
\brief Show html files.
@@ -38,30 +40,41 @@
@author Pierre Ecochard
*/
-class RKHTMLWindow : public RKMDIWindow {
+class RKHTMLWindow : public RKMDIWindow, public KXMLGUIClient {
Q_OBJECT
-protected:
-/** constructor. Protected. Use derived classes instead, or derive your own class.
+public:
+ enum WindowMode {
+ Undefined,
+ HTMLHelpWindow,
+ HTMLOutputWindow
+ };
+
+/** constructor.
@param parent parent QWidget, usually RKGlobals::rkApp () or similar */
- RKHTMLWindow (QWidget *parent = 0);
+ RKHTMLWindow (QWidget *parent, WindowMode mode=HTMLHelpWindow);
/** destructor */
- virtual ~RKHTMLWindow ();
-public:
+ ~RKHTMLWindow ();
/** open given URL. Returns false, if the URL is not an existing local file. Loading a non-local URL may succeed, even if this returns false! */
- virtual bool openURL (const KUrl &url);
+ bool openURL (const KUrl &url);
/** takes care of special handling, if the url is an rkward://-url. Does nothing and returns false, otherwise. */
- virtual bool handleRKWardURL (const KUrl &url);
-/** Reload current page.*/
- virtual void refresh ();
-/** Add common actions to the given action collection (currently only "copy")
- at param action_collection A KActionCollection to insert actions in. */
- void addCommonActions (KActionCollection *action_collection);
+ bool handleRKWardURL (const KUrl &url);
+/** initialize all actions */
+ void initActions ();
QString getDescription ();
bool isModified ();
/** Return current url */
KUrl url ();
void doGotoAnchor (const QString &anchor_name);
+
+ static void initializeOutputWindow ();
+
+/** return a pointer to the current output. If there is no output window, one will be created (and shown) automatically */
+ static RKHTMLWindow* getCurrentOutput ();
+/** refresh output window.
+ at param show Show the window, if not currently shown (this actually means: it is created if not currently existant)
+ at param raise Raise the window (if currently shown, or show==true) */
+ static RKHTMLWindow* refreshOutput (bool show, bool raise, bool only_if_modified);
public slots:
/** this is used for browsing only. Use openURL instead, when calling from outside. */
void slotOpenUrl (const KUrl & url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &);
@@ -70,6 +83,10 @@
void slotBack ();
void selectionChanged ();
void runSelection ();
+/** flush current output. */
+ void flushOutput ();
+/** Reload current page.*/
+ void refresh ();
private slots:
/** This slot is called when the new page has finished loading. Sets scroll position to scroll_position */
void loadDone ();
@@ -83,98 +100,53 @@
virtual void updateCaption (const KUrl &url);
/** called from openURL. Takes care of updating caption, and updating back/forward actions, if available */
void changeURL (const KUrl &url);
-protected:
+private:
QList<KUrl> url_history;
int current_history_position;
bool url_change_is_from_history; // dirty!!!
+ // general actions
+ QAction *run_selection;
+ QAction* print;
+ // actions in output window mode
+ QAction* outputFlush;
+ QAction* outputRefresh;
+ // actions in help window mode
QAction *back;
QAction *forward;
- QAction *print;
- QAction *run_selection;
+
QString goto_anchor_name;
-};
+ KUrl current_url;
-/**
- \brief RKWard output window.
+ WindowMode window_mode;
+ void useMode (WindowMode);
-Specialized RKHTMLWindow used for RKWard output.
+ void fileDoesNotExistMessage ();
- at author Thomas Friedrichsmeier
-*/
-class RKOutputWindow : public RKHTMLWindow, public KXMLGUIClient {
- Q_OBJECT
-public:
-/** constructor.
- at param parent parent QWidget, usually RKGlobals::rkApp () or similar */
- RKOutputWindow (QWidget *parent = 0);
-/** destructor */
- ~RKOutputWindow ();
+ static RKHTMLWindow *current_output;
+ static QDateTime last_refresh_time;
-/** reimplemented to show "output is empty" message, if file could not be opened */
- bool openURL (const KUrl &url);
-/** reimplemented to scroll to the bottom of the page */
- void refresh ();
-/** refresh output window.
- at param show Show the window, if not currently shown (this actually means: it is created if not currently existant)
- at param raise Raise the window (if currently shown, or show==true) */
- static RKOutputWindow* refreshOutput (bool show, bool raise, bool only_if_modified);
+ // for dealing with rkward://[page|component]-pages
+ bool renderRKHelp (const KUrl &url);
+ QString renderHelpFragment (QDomElement &fragment);
+ void prepareHelpLink (QDomElement *link_element);
+ RKComponentHandle *componentPathToHandle (QString path);
+ QString startSection (const QString &name, const QString &title, const QString &shorttitle, QStringList *anchors, QStringList *anchor_names);
-/** return a pointer to the current output. If there is no output window, one will be created (and shown) automatically */
- static RKOutputWindow* getCurrentOutput ();
-
- static void initialize ();
-
- QString getDescription ();
-public slots:
-/** flush current output. */
- void flushOutput ();
-/** Slot wrapper around refreshOutput (bool, bool, bool). */
- void refreshOutput ();
-protected:
-/** reimplemented to never change the caption (it's always "Output") */
- void updateCaption (const KUrl &url);
-private:
-/** print a message "Output is empty" to the output window. Used internally, if loading output fails*/
- void showOutputEmptyMessage ();
-
- QAction* outputFlush;
- QAction* outputRefresh;
-
- static RKOutputWindow* current_output;
-/** In case the output is empty (i.e. output file does not exist), we need to store, where the output *would* be, if it existed, so we can properly refresh the output */
- KUrl output_url;
- static QDateTime last_refresh_time;
};
-class QDomElement;
-class RKComponentHandle;
-class XMLHelper;
-
/**
- \brief Show html help files.
+ \brief Renders RKWard help pages.
-This class wraps a khtml part.
-
-Specialized HTML window for displaying R help pages.
-
- at author Pierre Ecochard
+ at author Thomas Friedrichsmeier
*/
-class RKHelpWindow : public RKHTMLWindow, public KXMLGUIClient {
+class RKHelpRenderer {
public:
-/** constructor.
- at param parent parent QWidget, usually RKGlobals::rkApp () or similar */
- RKHelpWindow (QWidget *parent = 0);
+/** ctor */
+ RKHelpRenderer () {};
/** destructor */
- ~RKHelpWindow ();
-
- bool handleRKWardURL (const KUrl &url);
-private:
- bool renderRKHelp (const KUrl &url);
- QString renderHelpFragment (QDomElement &fragment);
- void prepareHelpLink (QDomElement *link_element);
- RKComponentHandle *componentPathToHandle (QString path);
- QString startSection (const QString &name, const QString &title, const QString &shorttitle, QStringList *anchors, QStringList *anchor_names);
+ ~RKHelpRenderer () {};
};
+
#endif
Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp 2009-05-15 13:48:58 UTC (rev 2481)
@@ -25,6 +25,8 @@
#include <kvbox.h>
#include <kglobalsettings.h>
#include <kactioncollection.h>
+#include <krun.h>
+#include <kmimetype.h>
#include "detachedwindowcontainer.h"
#include "rkcommandeditorwindow.h"
@@ -190,6 +192,33 @@
}
}
+bool RKWorkplace::openAnyUrl (const KUrl &url) {
+ RK_TRACE (APP);
+
+#warning TODO support rkward:\/\/-protocol, here, too
+ if (url.isLocalFile ()) {
+ KMimeType::Ptr mimetype = KMimeType::findByUrl (url);
+ if (mimetype->is ("text/html")) {
+ openHelpWindow (url, true);
+ return true; // TODO
+ }
+ if (url.fileName ().toLower ().endsWith (".rdata")) {
+ RKWardMainWindow::getMain ()->fileOpenAskSave (url);
+ return true; // TODO
+ }
+ if (mimetype->name ().startsWith ("text")) {
+ return (openScriptEditor (url, false));
+ }
+ }
+
+ if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file or the filetype is not supported by RKWard. Do you want to open the url in the default application?", url.prettyUrl ()), i18n ("Open in default application?")) != KMessageBox::Yes) {
+ return false;
+ }
+ KRun *runner = new KRun (url, topLevelWidget()); // according to KRun-documentation, KRun will self-destruct when done.
+ runner->setRunExecutables (false);
+ return false;
+}
+
bool RKWorkplace::openScriptEditor (const KUrl &url, bool use_r_highlighting, bool read_only, const QString &force_caption) {
RK_TRACE (APP);
@@ -232,14 +261,14 @@
if (only_once) {
RKWorkplaceObjectList help_windows = getObjectList (RKMDIWindow::HelpWindow, RKMDIWindow::AnyWindowState);
for (RKWorkplaceObjectList::const_iterator it = help_windows.constBegin (); it != help_windows.constEnd (); ++it) {
- if (static_cast<RKHelpWindow *> (*it)->url ().equals (url, KUrl::CompareWithoutTrailingSlash | KUrl::CompareWithoutFragment)) {
+ if (static_cast<RKHTMLWindow *> (*it)->url ().equals (url, KUrl::CompareWithoutTrailingSlash | KUrl::CompareWithoutFragment)) {
(*it)->activate ();
return;
}
}
}
- RKHelpWindow *hw = new RKHelpWindow (view ());
+ RKHTMLWindow *hw = new RKHTMLWindow (view (), RKHTMLWindow::HTMLHelpWindow);
hw->openURL (url);
addWindow (hw);
}
@@ -247,15 +276,15 @@
void RKWorkplace::openOutputWindow (const KUrl &url) {
RK_TRACE (APP);
- RKOutputWindow::refreshOutput (true, true, false);
- if (!windows.contains (RKOutputWindow::getCurrentOutput ())) {
- addWindow (RKOutputWindow::getCurrentOutput ());
+ RKHTMLWindow::refreshOutput (true, true, false);
+ if (!windows.contains (RKHTMLWindow::getCurrentOutput ())) {
+ addWindow (RKHTMLWindow::getCurrentOutput ());
}
}
void RKWorkplace::refreshOutputWindow () {
RK_TRACE (APP);
- RKOutputWindow *window = RKOutputWindow::refreshOutput (RKSettingsModuleOutput::autoShow (), RKSettingsModuleOutput::autoRaise (), true);
+ RKHTMLWindow *window = RKHTMLWindow::refreshOutput (RKSettingsModuleOutput::autoShow (), RKSettingsModuleOutput::autoRaise (), true);
if (window) {
if (!windows.contains (window)) {
addWindow (window);
Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h 2009-05-14 12:29:14 UTC (rev 2480)
+++ trunk/rkward/rkward/windows/rkworkplace.h 2009-05-15 13:48:58 UTC (rev 2481)
@@ -2,7 +2,7 @@
rkworkplace - description
-------------------
begin : Thu Sep 21 2006
- copyright : (C) 2006, 2007 by Thomas Friedrichsmeier
+ copyright : (C) 2006, 2007, 2009 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -90,6 +90,9 @@
/** @returns a pointer to the current window. state specifies, which windows should be considered. */
RKMDIWindow *activeWindow (RKMDIWindow::State state);
+/** Opens the given url in the appropriate way. */
+ bool openAnyUrl (const KUrl &url);
+
/** Opens a new script editor
@param url URL to load. Default option is to open an empty document
@param use_r_highlighting Set R highlighting mode (vs. no highlighting)? Default is yes
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list