[office/kile/shift-click-forward-search] /: add Shift+Leftclick in editor to forward search

Natalie Clarius null at kde.org
Sun Mar 24 13:51:25 GMT 2024


Git commit 02cec2e0d36818b9862fd40d4d4a3c064fd99d61 by Natalie Clarius.
Committed on 24/03/2024 at 13:51.
Pushed by nclarius into branch 'shift-click-forward-search'.

add Shift+Leftclick in editor to forward search

Analogous to Shift+Leftclick in the viewer to backward search.

M  +2    -2    doc/index.docbook
M  +12   -10   src/documentinfo.cpp
M  +4    -1    src/documentinfo.h
M  +63   -2    src/eventfilter.cpp
M  +11   -1    src/eventfilter.h
M  +2    -1    src/kiledocmanager.cpp

https://invent.kde.org/office/kile/-/commit/02cec2e0d36818b9862fd40d4d4a3c064fd99d61

diff --git a/doc/index.docbook b/doc/index.docbook
index 3ba55e29..66e7b288 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -694,8 +694,8 @@
 		<guimenuitem>Tools</guimenuitem><guilabel>Build</guilabel></menuchoice>
 		and always choose the <guilabel>Modern</guilabel> configuration.</para>
 
-		<para>To execute a forward search, position the cursor on a line of source code, and click
-		<guilabel>Forward Search</guilabel> to jump to the associated position
+		<para>To execute a forward search, position the cursor on a line of source code, and click 
+		with the <mousebutton>left</mousebutton> mouse button while pressing &Shift;, or click <guilabel>Forward DVI</guilabel>/<guilabel>Forward PDF</guilabel> to jump to the associated position
 		in the &DVI; or PDF viewer window.</para>
 	</sect1>
 
diff --git a/src/documentinfo.cpp b/src/documentinfo.cpp
index c3342b6f..cf758763 100644
--- a/src/documentinfo.cpp
+++ b/src/documentinfo.cpp
@@ -831,22 +831,24 @@ void TextInfo::setDocumentContents(const QStringList& contents)
     m_documentContents = contents;
 }
 
-LaTeXInfo::LaTeXInfo(Extensions* extensions,
-                     KileAbbreviation::Manager* abbreviationManager,
-                     LatexCommands* commands,
-                     EditorExtension* editorExtension,
-                     KileConfiguration::Manager* manager,
-                     KileCodeCompletion::Manager* codeCompletionManager,
-                     KileTool::LivePreviewManager* livePreviewManager,
+LaTeXInfo::LaTeXInfo(Extensions *extensions,
+                     KileAbbreviation::Manager *abbreviationManager,
+                     LatexCommands *commands, 
+                     EditorExtension *editorExtension,
+                     KileConfiguration::Manager *manager,
+                     KileCodeCompletion::Manager *codeCompletionManager,
+                     KileTool::LivePreviewManager *livePreviewManager,
                      KileView::Manager *viewManager,
-                     KileParser::Manager* parserManager)
+                     KileParser::Manager *parserManager,
+                     KileTool::Manager *toolManager)
     : TextInfo(extensions, abbreviationManager, parserManager, "LaTeX"),
       m_commands(commands),
       m_editorExtension(editorExtension),
       m_configurationManager(manager),
       m_eventFilter(Q_NULLPTR),
       m_livePreviewManager(livePreviewManager),
-      m_viewManager(viewManager)
+      m_viewManager(viewManager),
+      m_toolManager(toolManager)
 {
     documentTypePromotionAllowed = false;
     updateStructLevelInfo();
@@ -976,7 +978,7 @@ void LaTeXInfo::updateStructLevelInfo() {
 QList<QObject*> LaTeXInfo::createEventFilters(KTextEditor::View *view)
 {
     QList<QObject*> toReturn;
-    QObject *eventFilter = new LaTeXEventFilter(view, m_editorExtension);
+    QObject *eventFilter = new LaTeXEventFilter(view, m_editorExtension, m_viewManager, m_livePreviewManager, m_toolManager);
     connect(m_configurationManager, SIGNAL(configChanged()), eventFilter, SLOT(readConfig()));
     toReturn << eventFilter;
     return toReturn;
diff --git a/src/documentinfo.h b/src/documentinfo.h
index d78e82ee..b6f40265 100644
--- a/src/documentinfo.h
+++ b/src/documentinfo.h
@@ -26,6 +26,7 @@
 
 #include "kileconstants.h"
 #include "kileextensions.h"
+#include "kiletoolmanager.h"
 #include "livepreview_utils.h"
 #include "outputinfo.h"
 
@@ -481,7 +482,8 @@ public:
               KileCodeCompletion::Manager *codeCompletionManager,
               KileTool::LivePreviewManager *livePreviewManager,
               KileView::Manager *viewManager,
-              KileParser::Manager *parserManager);
+              KileParser::Manager *parserManager,
+              KileTool::Manager *toolManager);
 
     virtual ~LaTeXInfo();
 
@@ -504,6 +506,7 @@ protected:
     KileCodeCompletion::LaTeXCompletionModel *m_latexCompletionModel;
     KileTool::LivePreviewManager *m_livePreviewManager;
     KileView::Manager *m_viewManager;
+    KileTool::Manager *m_toolManager;
 
     virtual void updateStructLevelInfo() override;
     virtual void checkChangedDeps();
diff --git a/src/eventfilter.cpp b/src/eventfilter.cpp
index 62dc724e..4c823b7d 100644
--- a/src/eventfilter.cpp
+++ b/src/eventfilter.cpp
@@ -25,12 +25,22 @@
 #include <KModifierKeyInfo>
 #include <KTextEditor/Document>
 #include <KTextEditor/View>
+#include <qfileinfo.h>
 
-#include "kiledebug.h"
 #include "editorextension.h"
 #include "kileconfig.h"
+#include "kiledebug.h"
+#include "kiletoolmanager.h"
+#include "kileviewmanager.h"
+#include "livepreview.h"
 
-LaTeXEventFilter::LaTeXEventFilter(KTextEditor::View *view, KileDocument::EditorExtension *edit) : QObject(view), m_view(view), m_edit(edit)
+LaTeXEventFilter::LaTeXEventFilter(
+    KTextEditor::View *view, KileDocument::EditorExtension *edit,
+    KileView::Manager *viewManager,
+    KileTool::LivePreviewManager *livePreviewManager,
+    KileTool::Manager *toolManager)
+    : QObject(view), m_view(view), m_edit(edit), m_viewManager(viewManager),
+      m_previewManager(livePreviewManager), m_toolManager(toolManager)
 {
     m_modifierKeyInfo = new KModifierKeyInfo(this);
     readConfig();
@@ -271,6 +281,57 @@ bool LaTeXEventFilter::eventFilter(QObject* /* o */, QEvent *e)
         }
     }
 
+    else if (e->type() == QEvent::MouseButtonPress) {
+        QMouseEvent *me = static_cast<QMouseEvent *>(e);
+        if (me->button() == Qt::LeftButton &&
+            me->modifiers() & Qt::ShiftModifier) { // forward search
+            // live preview
+            if (m_previewManager->isLivePreviewEnabledForCurrentDocument()) {
+                m_previewManager->showCursorPositionInDocumentViewer();
+                return true;
+            }
+            // generated PDF or DVI file
+            auto forwardPdfTool = m_toolManager->createTool(QLatin1String("ForwardPDF"));
+            if (!forwardPdfTool) {
+                return false;
+            }
+            forwardPdfTool->prepareToRun();
+            QFile pdfFile(forwardPdfTool->targetDir() + QLatin1Char('/') +
+                          forwardPdfTool->target());
+            auto forwardDviTool = m_toolManager->createTool(QLatin1String("ForwardDVI"));
+            if (!forwardDviTool) {
+                return false;
+            }
+            forwardDviTool->prepareToRun();
+            QFile dviFile(forwardDviTool->targetDir() + QLatin1Char('/') +
+                          forwardDviTool->target());
+            if (QFileInfo(pdfFile).exists() && QFileInfo(dviFile).exists()) {
+                if (QFileInfo(pdfFile).lastModified() > QFileInfo(dviFile).lastModified()) {
+                    m_toolManager->run(forwardPdfTool);
+                    delete forwardPdfTool;
+                    delete forwardDviTool;
+                    return true;
+                } else {
+                    m_toolManager->run(forwardDviTool);
+                    delete forwardPdfTool;
+                    delete forwardDviTool;
+                    return true;
+                }
+            } else if (QFileInfo(pdfFile).exists()) {
+                m_toolManager->run(forwardPdfTool);
+                delete forwardPdfTool;
+                delete forwardDviTool;
+                return true;
+            } else if (QFileInfo(dviFile).exists()) {
+                m_toolManager->run(forwardDviTool);
+                delete forwardPdfTool;
+                delete forwardDviTool;
+                return true;
+            }
+            return false;
+        }
+    }
+
     //pass this event on
     return false;
 }
diff --git a/src/eventfilter.h b/src/eventfilter.h
index cdc78d5e..28f46a63 100644
--- a/src/eventfilter.h
+++ b/src/eventfilter.h
@@ -15,6 +15,9 @@
 #ifndef EVENTFILTER_H
 #define EVENTFILTER_H
 
+#include "kiletoolmanager.h"
+#include "kileviewmanager.h"
+#include "livepreview.h"
 #include <QEvent>
 #include <QObject>
 
@@ -36,7 +39,11 @@ class LaTeXEventFilter : public QObject
     Q_OBJECT
 
 public:
-    LaTeXEventFilter(KTextEditor::View *view, KileDocument::EditorExtension *edit);
+    LaTeXEventFilter(KTextEditor::View *view, 
+                    KileDocument::EditorExtension *edit,
+                    KileView::Manager *viewManager,
+                    KileTool::LivePreviewManager *previewManager,
+                    KileTool::Manager *toolManager);
 
 public Q_SLOTS:
     void readConfig();
@@ -49,6 +56,9 @@ private:
     bool m_bCompleteEnvironment;
     KTextEditor::View *m_view;
     KileDocument::EditorExtension *m_edit;
+    KileView::Manager *m_viewManager;
+    KileTool::LivePreviewManager *m_previewManager;
+    KileTool::Manager *m_toolManager;
     KModifierKeyInfo *m_modifierKeyInfo;
 
 };
diff --git a/src/kiledocmanager.cpp b/src/kiledocmanager.cpp
index 002a010f..c96290b4 100644
--- a/src/kiledocmanager.cpp
+++ b/src/kiledocmanager.cpp
@@ -431,7 +431,8 @@ TextInfo* Manager::createTextDocumentInfo(KileDocument::Type type, const QUrl &u
                                     m_ki->codeCompletionManager(),
                                     m_ki->livePreviewManager(),
                                     m_ki->viewManager(),
-                                    m_ki->parserManager());
+                                    m_ki->parserManager(),
+                                    m_ki->toolManager());
             break;
         case BibTeX:
             KILE_DEBUG_MAIN << "CREATING BibInfo for " << url.url();


More information about the kde-doc-english mailing list