[rkward/work/split_views] rkward: Share document representation between split script windows, so they will remain in sync.
Thomas Friedrichsmeier
null at kde.org
Thu Jun 22 15:42:49 UTC 2017
Git commit da249b930e32069ec4998184c9efd8a6070fea62 by Thomas Friedrichsmeier.
Committed on 22/06/2017 at 15:41.
Pushed by tfry into branch 'work/split_views'.
Share document representation between split script windows, so they will remain in sync.
This does not work for unsaved script windows, yet.
M +1 -1 rkward/plugin/rkstandardcomponentgui.cpp
M +1 -1 rkward/windows/rkcallstackviewer.cpp
M +66 -48 rkward/windows/rkcommandeditorwindow.cpp
M +8 -8 rkward/windows/rkcommandeditorwindow.h
M +1 -9 rkward/windows/rkworkplace.cpp
https://commits.kde.org/rkward/da249b930e32069ec4998184c9efd8a6070fea62
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index f6ad9ccc..ad3440b5 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -154,7 +154,7 @@ RKStandardComponentGUI::RKStandardComponentGUI (RKStandardComponent *component,
if (!enslaved) {
// code display
RKXMLGUIPreviewArea *area = addDockedPreview (&code_display_visibility, i18n ("Code Preview"), QString (), true);
- code_display = new RKCommandEditorWindow (0, true, false);
+ code_display = new RKCommandEditorWindow (0, QUrl (), QString (), true, false);
code_display->setReadOnly (true);
code_display_visibility.setBoolValue (!enslaved && RKSettingsModulePlugins::showCodeByDefault ());
code_display->setParent (area); // hm, mysterious breakage when adding via constructor. Whatever...
diff --git a/rkward/windows/rkcallstackviewer.cpp b/rkward/windows/rkcallstackviewer.cpp
index bfe7209b..1a09c169 100644
--- a/rkward/windows/rkcallstackviewer.cpp
+++ b/rkward/windows/rkcallstackviewer.cpp
@@ -110,7 +110,7 @@ RKCallstackViewerWidget::RKCallstackViewerWidget (QWidget *parent) : QWidget (pa
frame_info->setWordWrap (true);
v_layout->addWidget (frame_info);
- frame_source = new RKCommandEditorWindow (this, true);
+ frame_source = new RKCommandEditorWindow (this, QUrl (), QString (), true);
v_layout->addWidget (frame_source);
updateState ();
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 82230635..43b450b9 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-2015 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2017 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -78,13 +78,63 @@ RKCommandEditorWindowPart::~RKCommandEditorWindowPart () {
#define GET_HELP_URL 1
#define NUM_BLOCK_RECORDS 6
-RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highlighting, bool use_codehinting) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
+RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl url, const QString& encoding, bool use_r_highlighting, bool use_codehinting, bool read_only, bool delete_on_close) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
RK_TRACE (COMMANDEDITOR);
KTextEditor::Editor* editor = KTextEditor::Editor::instance ();
RK_ASSERT (editor);
- m_doc = editor->createDocument (this);
+ m_doc = 0;
+ if (!url.isEmpty ()) { // TODO: what about delete_on_close
+ QList<KTextEditor::Document*> docs = editor->documents ();
+ for (int i = 0; i < docs.count (); ++i) {
+ if (docs[i]->url ().matches (url, QUrl::NormalizePathSegments | QUrl::StripTrailingSlash | QUrl::PreferLocalFile)) {
+ m_doc = docs[i];
+ break;
+ }
+ }
+ if (!encoding.isEmpty () && (m_doc->encoding () != encoding)) {
+ m_doc->setEncoding (encoding);
+ m_doc->documentReload ();
+ }
+ }
+ if (!m_doc) {
+ m_doc = editor->createDocument (RKWardMainWindow::getMain ()); // The document may have to outlive this window
+
+ // encoding must be set *before* loading the file
+ if (!encoding.isEmpty ()) m_doc->setEncoding (encoding);
+ if (!url.isEmpty ()) {
+ if (m_doc->openUrl (url)) {
+ // KF5 TODO: Check which parts of this are still needed in KF5, and which no longer work
+ if (!delete_on_close) { // don't litter config with temporary files
+ QString p_url = RKWorkplace::mainWorkplace ()->portableUrl (m_doc->url ());
+ KConfigGroup conf (RKWorkplace::mainWorkplace ()->workspaceConfig (), QString ("SkriptDocumentSettings %1").arg (p_url));
+ // HACK: Hmm. KTextEditor::Document's readSessionConfig() simply restores too much. Yes, I want to load bookmarks and stuff.
+ // I do not want to mess with encoding, or risk loading a different url, after the doc is already loaded!
+ if (!encoding.isEmpty () && (conf.readEntry ("Encoding", encoding) != encoding)) conf.writeEntry ("Encoding", encoding);
+ if (conf.readEntry ("URL", url) != url) conf.writeEntry ("URL", url);
+ // HACK: What the...?! Somehow, at least on longer R scripts, stored Mode="Normal" in combination with R Highlighting
+ // causes code folding to fail (KDE 4.8.4, http://sourceforge.net/p/rkward/bugs/122/).
+ // Forcing Mode == Highlighting appears to help.
+ if (use_r_highlighting) conf.writeEntry ("Mode", conf.readEntry ("Highlighting", "Normal"));
+ m_doc->readSessionConfig (conf);
+ }
+ } else {
+ KMessageBox::messageBox (this, KMessageBox::Error, i18n ("Unable to open \"%1\"", url.toDisplayString ()), i18n ("Could not open command file"));
+ }
+ }
+ }
+
+ setReadOnly (read_only);
+
+ if (delete_on_close) {
+ if (read_only) {
+ RKCommandEditorWindow::delete_on_close = url;
+ } else {
+ RK_ASSERT (false);
+ }
+ }
+
RK_ASSERT (m_doc);
// yes, we want to be notified, if the file has changed on disk.
// why, oh why is this not the default?
@@ -93,6 +143,10 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highli
if (em_iface) em_iface->setModifiedOnDiskWarning (true);
else RK_ASSERT (false);
m_view = m_doc->createView (this);
+ if (!url.isEmpty ()) {
+ KConfigGroup viewconf (RKWorkplace::mainWorkplace ()->workspaceConfig (), QString ("SkriptViewSettings %1").arg (RKWorkplace::mainWorkplace ()->portableUrl (url)));
+ m_view->readSessionConfig (viewconf);
+ }
setFocusProxy (m_view);
setFocusPolicy (Qt::StrongFocus);
@@ -112,6 +166,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highli
connect (m_doc, &KTextEditor::Document::documentUrlChanged, this, &RKCommandEditorWindow::updateCaption);
connect (m_doc, &KTextEditor::Document::modifiedChanged, this, &RKCommandEditorWindow::updateCaption); // of course most of the time this causes a redundant call to updateCaption. Not if a modification is undone, however.
+#warning remove this in favor of KTextEditor::Document::restore()
connect (m_doc, &KTextEditor::Document::modifiedChanged, this, &RKCommandEditorWindow::autoSaveHandlerModifiedChanged);
connect (m_doc, &KTextEditor::Document::textChanged, this, &RKCommandEditorWindow::autoSaveHandlerTextChanged);
connect (m_view, &KTextEditor::View::selectionChanged, this, &RKCommandEditorWindow::selectionChanged);
@@ -137,6 +192,8 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highli
}
hinter = new RKFunctionArgHinter (this, m_view);
}
+ } else {
+ RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::Automatic);
}
smart_iface = qobject_cast<KTextEditor::MovingInterface*> (m_doc);
@@ -166,8 +223,12 @@ RKCommandEditorWindow::~RKCommandEditorWindow () {
}
delete hinter;
- delete m_doc;
- if (!delete_on_close.isEmpty ()) KIO::del (delete_on_close)->start ();
+ delete m_view;
+ QList<KTextEditor::View*> views = m_doc->views ();
+ if (views.isEmpty ()) {
+ delete m_doc;
+ if (!delete_on_close.isEmpty ()) KIO::del (delete_on_close)->start ();
+ }
}
void RKCommandEditorWindow::fixupPartGUI () {
@@ -356,49 +417,6 @@ void RKCommandEditorWindow::setReadOnly (bool ro) {
m_doc->setReadWrite (!ro);
}
-bool RKCommandEditorWindow::openURL (const QUrl url, const QString& encoding, bool use_r_highlighting, bool read_only, bool delete_on_close){
- RK_TRACE (COMMANDEDITOR);
-
- // encoding must be set *before* loading the file
- if (!encoding.isEmpty ()) m_doc->setEncoding (encoding);
- if (m_doc->openUrl (url)) {
- // KF5 TODO: Check which parts of this are still needed in KF5, and which no longer work
- if (!delete_on_close) { // don't litter config with temporary files
- QString p_url = RKWorkplace::mainWorkplace ()->portableUrl (m_doc->url ());
- KConfigGroup conf (RKWorkplace::mainWorkplace ()->workspaceConfig (), QString ("SkriptDocumentSettings %1").arg (p_url));
- // HACK: Hmm. KTextEditor::Document's readSessionConfig() simply restores too much. Yes, I want to load bookmarks and stuff.
- // I do not want to mess with encoding, or risk loading a different url, after the doc is already loaded!
- if (!encoding.isEmpty () && (conf.readEntry ("Encoding", encoding) != encoding)) conf.writeEntry ("Encoding", encoding);
- if (conf.readEntry ("URL", url) != url) conf.writeEntry ("URL", url);
- // HACK: What the...?! Somehow, at least on longer R scripts, stored Mode="Normal" in combination with R Highlighting
- // causes code folding to fail (KDE 4.8.4, http://sourceforge.net/p/rkward/bugs/122/).
- // Forcing Mode == Highlighting appears to help.
- if (use_r_highlighting) conf.writeEntry ("Mode", conf.readEntry ("Highlighting", "Normal"));
- m_doc->readSessionConfig (conf);
-
- KConfigGroup viewconf (RKWorkplace::mainWorkplace ()->workspaceConfig (), QString ("SkriptViewSettings %1").arg (p_url));
- m_view->readSessionConfig (viewconf);
- }
- if (use_r_highlighting) RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::RScript);
- else RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::Automatic);
-
- setReadOnly (read_only);
-
- updateCaption ();
-
- if (delete_on_close) {
- if (!read_only) {
- RK_ASSERT (false);
- return true;
- }
- RKCommandEditorWindow::delete_on_close = url;
- }
-
- return true;
- }
- return false;
-}
-
void RKCommandEditorWindow::autoSaveHandlerModifiedChanged () {
RK_TRACE (COMMANDEDITOR);
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 2a152cfc..6f464c2c 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-2016 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2017 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -140,16 +140,13 @@ class RKCommandEditorWindow : public RKMDIWindow, public RKScriptContextProvider
Q_OBJECT
public:
/** constructor
+ at param encoding encoding to use. If QString (), the default encoding is used.
+ at param read_only Open the file in read-only mode
+ at param delete_on_close File should be deleted when closing the window. Only respected with read_only=true.
@param use_r_highlighting Initialize the view to use R syntax highlighting. Use, if you're going to edit an R syntax file */
- explicit RKCommandEditorWindow (QWidget *parent = 0, bool use_r_highlighting=true, bool use_codehinting=true);
+ explicit RKCommandEditorWindow (QWidget *parent, const QUrl url, const QString& encoding=QString (), bool use_r_highlighting=true, bool use_codehinting=true, bool read_only=false, bool delete_on_close=false);
/** destructor */
~RKCommandEditorWindow ();
-/** open given URL.
- at param use_r_highlighting Initialize the view to use R syntax highlighting. Use, if you're going to edit an R syntax file
- at param encoding encoding to use. If QString (), the default encoding is used.
- at param read_only Open the file in read-only mode
- at param delete_on_close File should be deleted when closing the window. Only respected with read_only=true. */
- bool openURL (const QUrl url, const QString& encoding=QString (), bool use_r_highlighting=true, bool read_only=false, bool delete_on_close=false);
/** returns, whether the document was modified since the last save */
bool isModified () override;
/** insert the given text into the document at the current cursor position. Additionally, focuses the view */
@@ -266,6 +263,9 @@ private:
QTimer* autosave_timer;
QUrl delete_on_close;
+
+/** open given URL. See RKCommandEditorWindow () */
+ bool openURL (const QUrl url, const QString& encoding=QString (), bool use_r_highlighting=true, bool read_only=false, bool delete_on_close=false);
};
/** Simple class to provide HTML highlighting for arbitrary R code. */
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 59092da4..733a8902 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -450,15 +450,7 @@ RKMDIWindow* RKWorkplace::openScriptEditor (const QUrl &url, const QString& enco
}
}
- RKCommandEditorWindow *editor = new RKCommandEditorWindow (view (), use_r_highlighting);
-
- if (!url.isEmpty ()) {
- if (!editor->openURL (url, encoding, use_r_highlighting, read_only, delete_on_close)) {
- delete editor;
- KMessageBox::messageBox (view (), KMessageBox::Error, i18n ("Unable to open \"%1\"", url.toDisplayString ()), i18n ("Could not open command file"));
- return 0;
- }
- }
+ RKCommandEditorWindow *editor = new RKCommandEditorWindow (view (), url, encoding, use_r_highlighting, read_only, delete_on_close);
if (!force_caption.isEmpty ()) editor->setCaption (force_caption);
addWindow (editor);
More information about the rkward-tracker
mailing list