changeset 23497:f45402b9dcc4

parse error messages clickable in gui console for opening the file (bug #35619) * Filter.cpp (UrlFilter::HotSpot::urlType): return new kind ParseErrorLink when found hotspot matches the related regular expression; (UrlFilter::HotSpot::activate): get file and line number from the error message and called related function for opening the file; add constants with the regular expression for the parse error; (UrlFilter::HotSpot::actions): add the open action for the parse error file; (UrlFilter::request_open_file): emit the suitable signal for opening the file * Filter.h: new signal for opening a file given by absolute path, new kind of url hotspot, new regular expressions for the filter * QUnixTerminalImpl.cpp (initialize): connect the two signal for editing function files and files with given absolute path to the related slots * main-window.cc (open_file): add new parameter for the line and emit the related signal depending on the existence of parameter line * main-window.h: open_file with new parameter line (default -1)
author Torsten <mttl@mailbox.org>
date Tue, 16 May 2017 06:55:25 +0200
parents 427c55a82f35
children 647705ffb110
files libgui/qterminal/libqterminal/unix/Filter.cpp libgui/qterminal/libqterminal/unix/Filter.h libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp libgui/src/main-window.cc libgui/src/main-window.h
diffstat 5 files changed, 74 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/unix/Filter.cpp	Mon May 15 18:05:44 2017 -0400
+++ b/libgui/qterminal/libqterminal/unix/Filter.cpp	Tue May 16 06:55:25 2017 +0200
@@ -502,6 +502,8 @@
         return Email;
     else if ( ErrorLinkRegExp.exactMatch(url) )
         return ErrorLink;
+    else if ( ParseErrorLinkRegExp.exactMatch(url) )
+        return ParseErrorLink;
     else
         return Unknown;
 }
@@ -523,39 +525,48 @@
     }
 
     if ( !object || actionName == "open-action" )
-    {
+      {
         if ( kind == StandardUrl )
-        {
+          {
             // if the URL path does not include the protocol ( eg. "www.kde.org" ) then
             // prepend http:// ( eg. "www.kde.org" --> "http://www.kde.org" )
             if (!url.contains("://"))
-            {
-                url.prepend("http://");
-            }
-        }
+              url.prepend("http://");
+            QDesktopServices::openUrl (QUrl (url));
+          }
         else if ( kind == Email )
-        {
+          {
             url.prepend("mailto:");
-        }
-
-        if (kind == ErrorLink)
+            QDesktopServices::openUrl (QUrl (url));
+          }
+        else if (kind == ErrorLink)
           {
             int pos = ErrorLinkRegExp.indexIn (url);
             if (pos > -1)
               {
                 QString file_name = ErrorLinkRegExp.cap (1);
                 QString line = ErrorLinkRegExp.cap (2);
-
                 // call the urlobject's method for opening a file; this
                 // method then signals to the filter
                 _urlObject->request_open_file (file_name, line.toInt ());
               }
           }
-        else
+        else if (kind == ParseErrorLink)
           {
-            QDesktopServices::openUrl (QUrl (url));
+            int pos = ParseErrorLinkRegExp.indexIn (url);
+            if (pos > -1)
+              {
+                QString line = ParseErrorLinkRegExp.cap (1);
+                QString file_name = ParseErrorLinkRegExp.cap (2);
+                // call the urlobject's method for opening a file; this
+                // method then signals to the filter
+                _urlObject->request_open_file (file_name, line.toInt ());
+              }
           }
-    }
+
+
+      }
+
 }
 
 // Note:  Altering these regular expressions can have a major effect on the performance of the filters
@@ -573,14 +584,21 @@
 // matches full url or email address
 const QRegExp UrlFilter::CompleteUrlRegExp('('+FullUrlRegExp.pattern()+'|'+
                                             EmailAddressRegExp.pattern()+')');
-// error link
-const QRegExp UrlFilter::ErrorLinkRegExp("(\\S+) at line (\\d+) column (?:\\d+)");
+// error link:
+//   normal error
+const QRegExp UrlFilter::ErrorLinkRegExp ("(\\S+) at line (\\d+) column (?:\\d+)");
+//   parse error
+const QRegExp UrlFilter::ParseErrorLinkRegExp ("parse error near line (\\d+) of file (\\S+)");
+//   complete regexp
+const QRegExp UrlFilter::CompleteErrorLinkRegExp ('('+ErrorLinkRegExp.pattern ()+'|'+
+                                                     ParseErrorLinkRegExp.pattern ()+')');
+
 
 UrlFilter::UrlFilter (Type t)
     : RegExpFilter (t)
 {
     if (_type == ErrorLink)
-      setRegExp (ErrorLinkRegExp);
+      setRegExp (CompleteErrorLinkRegExp);
     else
       setRegExp (CompleteUrlRegExp);
 }
@@ -601,7 +619,9 @@
     QAction* openAction = new QAction(_urlObject);
     QAction* copyAction = new QAction(_urlObject);;
 
-    Q_ASSERT (kind == StandardUrl || kind == Email || kind == ErrorLink);
+    Q_ASSERT (kind == StandardUrl || kind == Email
+                                  || kind == ErrorLink
+                                  || kind == ParseErrorLink);
 
     if ( kind == StandardUrl )
     {
@@ -625,6 +645,18 @@
                               .arg (file_name).arg (line));
         }
     }
+    else if ( kind == ParseErrorLink )
+    {
+      QString url = capturedTexts().first();
+      int pos = ParseErrorLinkRegExp.indexIn (url);
+      if (pos >= 0)
+        {
+          QString line = ParseErrorLinkRegExp.cap (1);
+          QString file_name = ParseErrorLinkRegExp.cap (2);
+          openAction->setText(tr ("Edit %1 at line %2")
+                              .arg (file_name).arg (line));
+        }
+    }
 
     // object names are set here so that the hotspot performs the
     // correct action when activated() is called with the triggered
@@ -635,7 +667,7 @@
     QObject::connect( openAction , SIGNAL(triggered()) , _urlObject , SLOT(activated()) );
     list << openAction;
 
-    if (kind != ErrorLink)
+    if (kind != ErrorLink && kind != ParseErrorLink)
       {
         QObject::connect ( copyAction , SIGNAL(triggered()) ,
                            _urlObject , SLOT(activated()) );
@@ -647,7 +679,16 @@
 void
 UrlFilter::request_open_file (const QString& file, int line)
 {
-  emit request_open_file_signal (file, line);
+  QFileInfo file_info = QFileInfo (file);
+
+  // We have to distinguish between a parse error, where we get the full
+  // path of the file or a general error in a script, where we only get
+  // the function name. depending on this we have to invoke different
+  // slots in main_window
+  if (file_info.isAbsolute () && file_info.exists ())
+    emit request_open_file_signal (file, line);
+  else
+    emit request_edit_mfile_signal (file, line);
 }
 
 //#include "moc_Filter.cpp"
--- a/libgui/qterminal/libqterminal/unix/Filter.h	Mon May 15 18:05:44 2017 -0400
+++ b/libgui/qterminal/libqterminal/unix/Filter.h	Tue May 16 06:55:25 2017 +0200
@@ -244,6 +244,7 @@
 
 signals:
 
+    void request_edit_mfile_signal (const QString&, int);
     void request_open_file_signal (const QString&, int);
 
 protected:
@@ -295,6 +296,7 @@
             StandardUrl,
             Email,
             ErrorLink,
+            ParseErrorLink,
             Unknown
         };
         UrlType urlType() const;
@@ -317,6 +319,8 @@
     static const QRegExp FullUrlRegExp;
     static const QRegExp EmailAddressRegExp;
     static const QRegExp ErrorLinkRegExp;
+    static const QRegExp ParseErrorLinkRegExp;
+    static const QRegExp CompleteErrorLinkRegExp;
 
     // combined OR of FullUrlRegExp and EmailAddressRegExp
     static const QRegExp CompleteUrlRegExp;
--- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp	Mon May 15 18:05:44 2017 -0400
+++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp	Tue May 16 06:55:25 2017 +0200
@@ -51,8 +51,10 @@
     UrlFilter *file_filter = new UrlFilter (Filter::Type::ErrorLink);
     m_terminalView->filterChain ()->addFilter (file_filter);
 
+    connect (file_filter, SIGNAL (request_edit_mfile_signal (const QString&, int)),
+             _parent, SLOT (edit_mfile (const QString&, int)));
     connect (file_filter, SIGNAL (request_open_file_signal (const QString&, int)),
-             _parent, SLOT (edit_mfile (const QString&, int)));
+             _parent, SLOT (open_file (const QString&, int)));
 
     connect(m_terminalView, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(handleCustomContextMenuRequested(QPoint)));
--- a/libgui/src/main-window.cc	Mon May 15 18:05:44 2017 -0400
+++ b/libgui/src/main-window.cc	Tue May 16 06:55:25 2017 +0200
@@ -313,9 +313,12 @@
 }
 
 void
-main_window::open_file (const QString& file_name)
+main_window::open_file (const QString& file_name, int line)
 {
-  emit open_file_signal (file_name);
+  if (line < 0)
+    emit open_file_signal (file_name);
+  else
+    emit open_file_signal (file_name, QString (), line);
 }
 
 void
--- a/libgui/src/main-window.h	Mon May 15 18:05:44 2017 -0400
+++ b/libgui/src/main-window.h	Tue May 16 06:55:25 2017 +0200
@@ -156,7 +156,7 @@
                                        const QString& new_name);
   void handle_undo_request (void);
   void new_file (const QString& commands = QString ());
-  void open_file (const QString& file_name = QString ());
+  void open_file (const QString& file_name = QString (), int line = -1);
   void edit_mfile (const QString&, int);
   void open_online_documentation_page (void);
   void display_release_notes (void);