[rkward/frameworks] /: Remove some legacy version checks, and fix static code highlighter
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Nov 24 20:05:57 UTC 2015
Git commit 914a44d2f80890e642a769ab3b5d736e82790af6 by Thomas Friedrichsmeier.
Committed on 24/11/2015 at 20:05.
Pushed by tfry into branch 'frameworks'.
Remove some legacy version checks, and fix static code highlighter
M +1 -0 TODO
M +14 -41 rkward/windows/rkcommandeditorwindow.cpp
M +2 -4 rkward/windows/rkcommandeditorwindow.h
M +3 -8 rkward/windows/rkfilebrowser.cpp
M +1 -1 rkward/windows/rkhtmlwindow.cpp
http://commits.kde.org/rkward/914a44d2f80890e642a769ab3b5d736e82790af6
diff --git a/TODO b/TODO
index dcf48d8..554cf25 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,7 @@ Things to do:
- Remove kde4libssupport classes
- Remove obsolete version checks
- Adjust platform checks
+- Check for usages of i18n ("%1").arg(x), instead of i18n ("%1", x)
Things to test at the end:
- Everthing concerning loading / saving, from recent files, scripts, workspace, etc.
- Moved installations, moved workspaces.
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 1dbfad5..d2fea57 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -143,11 +143,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highli
}
}
-#if KDE_IS_VERSION(4,5,0)
smart_iface = qobject_cast<KTextEditor::MovingInterface*> (m_doc);
-#else
- smart_iface = qobject_cast<KTextEditor::SmartInterface*> (m_doc);
-#endif
initBlocks ();
RK_ASSERT (smart_iface);
@@ -605,7 +601,6 @@ QString RKCommandEditorWindow::currentCompletionWord () const {
return RKCommonFunctions::getCurrentSymbol (current_line, cursor_pos, false);
}
-#if KDE_IS_VERSION(4,2,0)
KTextEditor::Range RKCodeCompletionModel::completionRange (KTextEditor::View *view, const KTextEditor::Cursor &position) {
if (!position.isValid ()) return KTextEditor::Range ();
QString current_line = view->document ()->line (position.line ());
@@ -614,7 +609,6 @@ KTextEditor::Range RKCodeCompletionModel::completionRange (KTextEditor::View *vi
RKCommonFunctions::getCurrentSymbolOffset (current_line, position.column (), false, &start, &end);
return KTextEditor::Range (position.line (), start, position.line (), end);
}
-#endif
void RKCommandEditorWindow::tryCompletion () {
// TODO: merge this with RKConsole::doTabCompletion () somehow
@@ -781,11 +775,7 @@ void RKCommandEditorWindow::clearUnusedBlocks () {
for (int i = 0; i < block_records.size (); ++i) {
if (block_records[i].active) {
// TODO: do we need to check whether the range was deleted? Does the katepart do such evil things?
-#if KDE_IS_VERSION(4,5,0)
if (block_records[i].range->isEmpty ()) {
-#else
- if (!block_records[i].range->isValid () || block_records[i].range->isEmpty ()) {
-#endif
removeBlock (i, true);
}
}
@@ -800,13 +790,8 @@ void RKCommandEditorWindow::addBlock (int index, const KTextEditor::Range& range
clearUnusedBlocks ();
removeBlock (index);
-#if KDE_IS_VERSION(4,5,0)
KTextEditor::MovingRange* srange = smart_iface->newMovingRange (range);
srange->setInsertBehaviors (KTextEditor::MovingRange::ExpandRight);
-#else
- KTextEditor::SmartRange* srange = smart_iface->newSmartRange (range);
- srange->setInsertBehavior (KTextEditor::SmartRange::ExpandRight);
-#endif
QString actiontext = i18n ("%1 (Active)", index + 1);
block_records[index].range = srange;
@@ -817,10 +802,6 @@ void RKCommandEditorWindow::addBlock (int index, const KTextEditor::Range& range
block_records[index].unmark->setEnabled (true);
block_records[index].run->setText (actiontext);
block_records[index].run->setEnabled (true);
-
-#if !KDE_IS_VERSION(4,5,0)
- smart_iface->addHighlightToView (m_view, srange);
-#endif
}
void RKCommandEditorWindow::removeBlock (int index, bool was_deleted) {
@@ -829,9 +810,6 @@ void RKCommandEditorWindow::removeBlock (int index, bool was_deleted) {
RK_ASSERT ((index >= 0) && (index < block_records.size ()));
if (!was_deleted) {
-#if !KDE_IS_VERSION(4,5,0)
- smart_iface->removeHighlightFromView (m_view, block_records[index].range);
-#endif
delete (block_records[index].range);
}
@@ -1096,6 +1074,7 @@ QVariant RKCodeCompletionModel::data (const QModelIndex& index, int role) const
// static
KTextEditor::Document* RKCommandHighlighter::_doc = 0;
+KTextEditor::View* RKCommandHighlighter::_view = 0;
KTextEditor::Document* RKCommandHighlighter::getDoc () {
if (_doc) return _doc;
@@ -1104,16 +1083,19 @@ KTextEditor::Document* RKCommandHighlighter::getDoc () {
RK_ASSERT (editor);
_doc = editor->createDocument (RKWardMainWindow::getMain ());
-// NOTE: In KDE 4.4.5, a (dummy) view is needed to access highlighting attributes. According to a katepart error message, this will be fixed, eventually.
-// KF5 TODO: check whether this is fixed
- QWidget* view = _doc->createView (0);
- view->hide ();
+// NOTE: A (dummy) view is needed to access highlighting attributes.
+ _view = _doc->createView (0);
+ _view->hide ();
RK_ASSERT (_doc);
return _doc;
}
-#if KDE_IS_VERSION(4,4,0)
-# include <ktexteditor/highlightinterface.h>
+KTextEditor::View* RKCommandHighlighter::getView () {
+ if (!_view) getDoc ();
+ return _view;
+}
+
+#include <ktexteditor/highlightinterface.h>
#include <QTextDocument>
//////////
@@ -1160,17 +1142,14 @@ QString exportText(const QString& text, const KTextEditor::Attribute::Ptr& attri
QString RKCommandHighlighter::commandToHTML (const QString r_command, HighlightingMode mode) {
KTextEditor::Document* doc = getDoc ();
- KTextEditor::HighlightInterface *iface = qobject_cast<KTextEditor::HighlightInterface*> (_doc);
- RK_ASSERT (iface);
- if (!iface) return (QString ("<pre>") + r_command + "</pre>");
-
+ KTextEditor::View* view = getView ();
doc->setText (r_command);
if (r_command.endsWith ('\n')) doc->removeLine (doc->lines () - 1);
setHighlighting (doc, mode);
QString ret;
QString opening;
- KTextEditor::Attribute::Ptr m_defaultAttribute = iface->defaultStyle(KTextEditor::HighlightInterface::dsNormal);
+ KTextEditor::Attribute::Ptr m_defaultAttribute = view->defaultStyleAttribute (KTextEditor::dsNormal);
if ( !m_defaultAttribute ) {
opening = "<pre class=\"%3\">";
} else {
@@ -1192,7 +1171,7 @@ QString RKCommandHighlighter::commandToHTML (const QString r_command, Highlighti
for (int i = 0; i < doc->lines (); ++i)
{
const QString &line = doc->line(i);
- QList<KTextEditor::HighlightInterface::AttributeBlock> attribs = iface->lineAttributes(i);
+ QList<KTextEditor::AttributeBlock> attribs = view->lineAttributes(i);
int lineStart = 0;
if (mode == RInteractiveSession) {
@@ -1216,7 +1195,7 @@ QString RKCommandHighlighter::commandToHTML (const QString r_command, Highlighti
int handledUntil = lineStart;
int remainingChars = line.length();
- foreach ( const KTextEditor::HighlightInterface::AttributeBlock& block, attribs ) {
+ foreach ( const KTextEditor::AttributeBlock& block, attribs ) {
if ((block.start + block.length) <= handledUntil) continue;
int start = qMax(block.start, lineStart);
if ( start > handledUntil ) {
@@ -1239,12 +1218,6 @@ QString RKCommandHighlighter::commandToHTML (const QString r_command, Highlighti
return ret;
}
-#else // KDE < 4.4: No Highlighting Interface
-QString RKCommandHighlighter::commandToHTML (const QString r_command, HighlightingMode) {
- return (QString ("<pre class=\"code\">") + r_command + "</pre>");
-}
-#endif
-
/** set syntax highlighting-mode to R syntax. Outside of class, in order to allow use from the on demand code highlighter */
void RKCommandHighlighter::setHighlighting (KTextEditor::Document *doc, HighlightingMode mode) {
RK_TRACE (COMMANDEDITOR);
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 463a072..f9e9eea 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -235,11 +235,7 @@ private:
void initializeActions (KActionCollection* ac);
struct BlockRecord {
-#if KDE_IS_VERSION(4,5,0)
KTextEditor::MovingRange* range;
-#else
- KTextEditor::SmartRange* range;
-#endif
bool active;
KTextEditor::Attribute::Ptr attribute;
QAction* mark;
@@ -284,6 +280,8 @@ public:
private:
static KTextEditor::Document* getDoc ();
static KTextEditor::Document* _doc;
+ static KTextEditor::View* getView ();
+ static KTextEditor::View* _view;
};
#endif
diff --git a/rkward/windows/rkfilebrowser.cpp b/rkward/windows/rkfilebrowser.cpp
index f3e652f..4781fcb 100644
--- a/rkward/windows/rkfilebrowser.cpp
+++ b/rkward/windows/rkfilebrowser.cpp
@@ -26,10 +26,8 @@
#include <kconfiggroup.h>
#include <kdeversion.h>
#include <KSharedConfig>
-#if KDE_IS_VERSION(4,3,0)
-# include <kfileitemactions.h>
-# include <kfileitemlistproperties.h>
-#endif
+#include <kfileitemactions.h>
+#include <kfileitemlistproperties.h>
#include <qdir.h>
#include <qlayout.h>
@@ -119,10 +117,8 @@ RKFileBrowserWidget::RKFileBrowserWidget (QWidget *parent) : KVBox (parent) {
toolbar->addAction (dir->actionCollection ()->action ("detailed view"));
// toolbar->addAction (dir->actionCollection ()->action ("detailed tree view")); // should we have this as well? Trying to avoid crowding in the toolbar
-#if KDE_IS_VERSION(4, 3, 0)
fi_actions = new KFileItemActions (this);
connect (dir, SIGNAL (contextMenuAboutToShow(KFileItem,QMenu*)), this, SLOT (contextMenuHook(KFileItem,QMenu*)));
-#endif
connect (dir, SIGNAL (urlEntered(QUrl)), this, SLOT (urlChangedInView(QUrl)));
connect (urlbox, SIGNAL (returnPressed(QString)), this, SLOT (urlChangedInCombo(QString)));
@@ -139,7 +135,7 @@ RKFileBrowserWidget::~RKFileBrowserWidget () {
void RKFileBrowserWidget::contextMenuHook(const KFileItem& item, QMenu* menu) {
RK_TRACE (APP);
-#if KDE_IS_VERSION(4,3,0)
+
QList<KFileItem> dummy;
dummy.append (item);
fi_actions->setItemListProperties (KFileItemListProperties (dummy));
@@ -156,7 +152,6 @@ void RKFileBrowserWidget::contextMenuHook(const KFileItem& item, QMenu* menu) {
QList<QAction*> menu_actions_after = menu->actions ();
foreach (QAction* act, menu_actions_after) if (!menu_actions.contains (act)) added_service_actions.append (act);
-#endif
}
// does not work in d-tor. Apparently it's too late, then
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index d9d368d..4e6fde0 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -479,7 +479,7 @@ void RKHTMLWindow::changeURL (const QUrl &url) {
void RKHTMLWindow::updateCaption (const QUrl &url) {
RK_TRACE (APP);
- if (window_mode == HTMLOutputWindow) setCaption (i18n ("Output %1").arg (url.fileName ()));
+ if (window_mode == HTMLOutputWindow) setCaption (i18n ("Output %1", url.fileName ()));
else setCaption (url.fileName ());
}
More information about the rkward-tracker
mailing list