open file by click on include line
This commit is contained in:
		
							
								
								
									
										11
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								ChangeLog
									
									
									
									
									
								
							| @@ -1,3 +1,14 @@ | |||||||
|  | 2017-01-31 23:04   | ||||||
|  |  | ||||||
|  | 	* [r99] scripts/wt-mode.el, src/editor.hxx: | ||||||
|  | 	  simple syntax highlighting | ||||||
|  |  | ||||||
|  | 2017-01-31 19:54   | ||||||
|  |  | ||||||
|  | 	* [r98] COPYING, ChangeLog, INSTALL, src/editor.hxx[ADD], | ||||||
|  | 	  src/makefile.am, src/testgui.hxx, src/testgui.ui: | ||||||
|  | 	  added CodeEditor with line numbering from Qt sample code | ||||||
|  |  | ||||||
| 2017-01-31 17:32   | 2017-01-31 17:32   | ||||||
|  |  | ||||||
| 	* [r97] src/commands.hxx, src/webrunner.cxx: | 	* [r97] src/commands.hxx, src/webrunner.cxx: | ||||||
|   | |||||||
| @@ -11,6 +11,8 @@ | |||||||
| #include <QRegularExpressionMatch> | #include <QRegularExpressionMatch> | ||||||
| #include <cassert> | #include <cassert> | ||||||
|  |  | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
| class Highlighter: public QSyntaxHighlighter { | class Highlighter: public QSyntaxHighlighter { | ||||||
|     Q_OBJECT; |     Q_OBJECT; | ||||||
|   Q_SIGNALS: |   Q_SIGNALS: | ||||||
| @@ -29,8 +31,10 @@ class Highlighter: public QSyntaxHighlighter { | |||||||
|         QTextCharFormat fmt; |         QTextCharFormat fmt; | ||||||
|         if (QFile(m.captured(1)).exists()) { |         if (QFile(m.captured(1)).exists()) { | ||||||
|           fmt.setForeground(Qt::darkGreen); |           fmt.setForeground(Qt::darkGreen); | ||||||
|  |           fmt.setFontWeight(QFont::Bold); | ||||||
|         } else { |         } else { | ||||||
|           fmt.setForeground(Qt::darkRed); |           fmt.setForeground(Qt::darkRed); | ||||||
|  |           fmt.setFontStrikeOut(true); | ||||||
|         } |         } | ||||||
|         setFormat(m.capturedStart(1), m.capturedLength(1), fmt); |         setFormat(m.capturedStart(1), m.capturedLength(1), fmt); | ||||||
|         include(m.captured(1)); |         include(m.captured(1)); | ||||||
| @@ -47,6 +51,7 @@ class Highlighter: public QSyntaxHighlighter { | |||||||
|         Expression(QString s): re(s) {} |         Expression(QString s): re(s) {} | ||||||
|         Expression(QString s, QTextCharFormat f): re(s), fmt(f) {} |         Expression(QString s, QTextCharFormat f): re(s), fmt(f) {} | ||||||
|         Expression& weight(int w) {fmt.setFontWeight(w); return *this;} |         Expression& weight(int w) {fmt.setFontWeight(w); return *this;} | ||||||
|  |         Expression& strike(bool s=true) {fmt.setFontStrikeOut(s); return *this;} | ||||||
|         Expression& fg(const QBrush& b) {fmt.setForeground(b); return *this;} |         Expression& fg(const QBrush& b) {fmt.setForeground(b); return *this;} | ||||||
|         QRegularExpression re; |         QRegularExpression re; | ||||||
|         QTextCharFormat fmt; |         QTextCharFormat fmt; | ||||||
| @@ -70,6 +75,7 @@ class CodeEditor: public QPlainTextEdit { | |||||||
|     Q_OBJECT; |     Q_OBJECT; | ||||||
|   Q_SIGNALS: |   Q_SIGNALS: | ||||||
|     void include(QString); |     void include(QString); | ||||||
|  |     void link(QString); | ||||||
|   public: |   public: | ||||||
|     CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) { |     CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) { | ||||||
|       Highlighter *highlighter(new Highlighter(document())); |       Highlighter *highlighter(new Highlighter(document())); | ||||||
| @@ -111,6 +117,23 @@ class CodeEditor: public QPlainTextEdit { | |||||||
|       int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; |       int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; | ||||||
|       return space; |       return space; | ||||||
|     } |     } | ||||||
|  |     void mousePressEvent(QMouseEvent *e) { | ||||||
|  |       clickedAnchor = (e->button() & Qt::LeftButton) | ||||||
|  |         ? document()->findBlock(cursorForPosition(e->pos()).position()).text() | ||||||
|  |         : QString(); | ||||||
|  |       QPlainTextEdit::mousePressEvent(e); | ||||||
|  |     } | ||||||
|  |     void mouseReleaseEvent(QMouseEvent *e) { | ||||||
|  |       if (e->button() & Qt::LeftButton && !clickedAnchor.isEmpty() | ||||||
|  |           && document()->findBlock(cursorForPosition(e->pos()).position()).text() == clickedAnchor) { | ||||||
|  |         static QRegularExpression inc("^ *include +([^ ].*.\\.wt)"); | ||||||
|  |         QRegularExpressionMatch m(inc.match(clickedAnchor)); | ||||||
|  |         if (m.hasMatch() && QFile(m.captured(1)).exists()) { | ||||||
|  |           link(m.captured(1)); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       QPlainTextEdit::mouseReleaseEvent(e); | ||||||
|  |     } | ||||||
|   protected: |   protected: | ||||||
|     void resizeEvent(QResizeEvent *e) override { |     void resizeEvent(QResizeEvent *e) override { | ||||||
|       QPlainTextEdit::resizeEvent(e); |       QPlainTextEdit::resizeEvent(e); | ||||||
| @@ -144,6 +167,7 @@ class CodeEditor: public QPlainTextEdit { | |||||||
|     } |     } | ||||||
|   private: |   private: | ||||||
|     QWidget *lineNumberArea; |     QWidget *lineNumberArea; | ||||||
|  |     QString clickedAnchor; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| inline LineNumberArea::LineNumberArea(CodeEditor *editor): QWidget(editor) { | inline LineNumberArea::LineNumberArea(CodeEditor *editor): QWidget(editor) { | ||||||
|   | |||||||
| @@ -7,12 +7,14 @@ | |||||||
| class ScriptFile: public QDockWidget, protected Ui::ScriptFile { | class ScriptFile: public QDockWidget, protected Ui::ScriptFile { | ||||||
|     Q_OBJECT; |     Q_OBJECT; | ||||||
|   Q_SIGNALS: |   Q_SIGNALS: | ||||||
|  |     void link(QString); | ||||||
|     void include(QString); |     void include(QString); | ||||||
|     void close(ScriptFile*); |     void close(ScriptFile*); | ||||||
|   public: |   public: | ||||||
|     ScriptFile(QWidget* p=0): QDockWidget(p) { |     ScriptFile(QWidget* p=0): QDockWidget(p) { | ||||||
|       setupUi(this); |       setupUi(this); | ||||||
|       assert(connect(_editor, SIGNAL(include(QString)), SIGNAL(include(QString)))); |       assert(connect(_editor, SIGNAL(include(QString)), SIGNAL(include(QString)))); | ||||||
|  |       assert(connect(_editor, SIGNAL(link(QString)), SIGNAL(link(QString)))); | ||||||
|       _searchBar->hide(); |       _searchBar->hide(); | ||||||
|       _replaceBar->hide(); |       _replaceBar->hide(); | ||||||
|       _pageBar->hide(); |       _pageBar->hide(); | ||||||
|   | |||||||
| @@ -69,7 +69,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { | |||||||
|                      SLOT(unsupportedContent(QNetworkReply*)))); |                      SLOT(unsupportedContent(QNetworkReply*)))); | ||||||
|       assert(connect(page, SIGNAL(downloadRequested(const QNetworkRequest&)), |       assert(connect(page, SIGNAL(downloadRequested(const QNetworkRequest&)), | ||||||
|                      SLOT(downloadRequested(const QNetworkRequest&)))); |                      SLOT(downloadRequested(const QNetworkRequest&)))); | ||||||
|       assert(connect(_testscript, SIGNAL(include(QString)), SLOT(include(QString)))); |       //assert(connect(_testscript, SIGNAL(include(QString)), SLOT(include(QString)))); | ||||||
|  |       assert(connect(_testscript, SIGNAL(link(QString)), SLOT(include(QString)))); | ||||||
|       if (setupScript.size()) loadSetup(setupScript); |       if (setupScript.size()) loadSetup(setupScript); | ||||||
|       if (scriptFile.size()) loadFile(scriptFile); |       if (scriptFile.size()) loadFile(scriptFile); | ||||||
|     } |     } | ||||||
| @@ -343,7 +344,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { | |||||||
|     void include(QString name) { |     void include(QString name) { | ||||||
|       if (_testscripts.contains(name)) return; |       if (_testscripts.contains(name)) return; | ||||||
|       _testscripts[name] = new ScriptFile(this); |       _testscripts[name] = new ScriptFile(this); | ||||||
|       assert(connect(_testscripts[name], SIGNAL(include(QString)), SLOT(include(QString)))); |       // assert(connect(_testscripts[name], SIGNAL(include(QString)), SLOT(include(QString)))); | ||||||
|  |       assert(connect(_testscripts[name], SIGNAL(link(QString)), SLOT(include(QString)))); | ||||||
|       assert(connect(_testscripts[name], SIGNAL(close(ScriptFile*)), SLOT(remove(ScriptFile*)))); |       assert(connect(_testscripts[name], SIGNAL(close(ScriptFile*)), SLOT(remove(ScriptFile*)))); | ||||||
|       QFile file(name); |       QFile file(name); | ||||||
|       try { |       try { | ||||||
| @@ -354,10 +356,11 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { | |||||||
|           throw std::runtime_error("file read failed"); |           throw std::runtime_error("file read failed"); | ||||||
|         _testscripts[name]->name(name); |         _testscripts[name]->name(name); | ||||||
|         tabifyDockWidget(_scriptDock, _testscripts[name]); |         tabifyDockWidget(_scriptDock, _testscripts[name]); | ||||||
|         QDockWidget* d(0); |         // QDockWidget* d(0); | ||||||
|         for (QWidget* w(QApplication::focusWidget()); w&&!(d=qobject_cast<QDockWidget*>(w)); |         // for (QWidget* w(QApplication::focusWidget()); w&&!(d=qobject_cast<QDockWidget*>(w)); | ||||||
|              w=qobject_cast<QWidget*>(w->parent())); |         //      w=qobject_cast<QWidget*>(w->parent())); | ||||||
|         if (d) d->raise(); |         // if (d) d->raise(); | ||||||
|  |         _testscripts[name]->raise(); | ||||||
|       } catch(const std::exception& x) { |       } catch(const std::exception& x) { | ||||||
|         remove(_testscripts[name]); |         remove(_testscripts[name]); | ||||||
|       } |       } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user