2 |
2 |
3 # Copyright (c) 2002 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2002 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing the viewmanager base class. |
7 Module implementing the view manager base class. |
8 """ |
8 """ |
9 |
9 |
10 |
10 import re |
11 import os |
11 import os |
12 |
12 |
13 from PyQt5.QtCore import ( |
13 from PyQt5.QtCore import ( |
14 pyqtSignal, pyqtSlot, QSignalMapper, QTimer, QFileInfo, QRegExp, Qt, |
14 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, |
15 QCoreApplication, QPoint |
15 QCoreApplication |
16 ) |
16 ) |
17 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap |
17 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap |
18 from PyQt5.QtWidgets import ( |
18 from PyQt5.QtWidgets import ( |
19 QLineEdit, QToolBar, QWidgetAction, QDialog, QApplication, QMenu, |
19 QLineEdit, QToolBar, QWidgetAction, QDialog, QApplication, QMenu, |
20 QComboBox, QWidget |
20 QComboBox, QWidget |
87 super(QuickSearchLineEdit, self).focusInEvent(evt) # pass it on |
87 super(QuickSearchLineEdit, self).focusInEvent(evt) # pass it on |
88 |
88 |
89 |
89 |
90 class ViewManager(QWidget): |
90 class ViewManager(QWidget): |
91 """ |
91 """ |
92 Base class inherited by all specific viewmanager classes. |
92 Base class inherited by all specific view manager classes. |
93 |
93 |
94 It defines the interface to be implemented by specific |
94 It defines the interface to be implemented by specific |
95 viewmanager classes and all common methods. |
95 view manager classes and all common methods. |
96 |
96 |
97 @signal changeCaption(str) emitted if a change of the caption is necessary |
97 @signal changeCaption(str) emitted if a change of the caption is necessary |
98 @signal editorChanged(str) emitted when the current editor has changed |
98 @signal editorChanged(str) emitted when the current editor has changed |
99 @signal editorChangedEd(Editor) emitted when the current editor has changed |
99 @signal editorChangedEd(Editor) emitted when the current editor has changed |
100 @signal lastEditorClosed() emitted after the last editor window was closed |
100 @signal lastEditorClosed() emitted after the last editor window was closed |
5923 return |
5923 return |
5924 |
5924 |
5925 line, index = aw.getCursorPosition() |
5925 line, index = aw.getCursorPosition() |
5926 text = aw.text(line) |
5926 text = aw.text(line) |
5927 |
5927 |
5928 reg = QRegExp(r'[^\w_]') |
5928 rx = re.compile(r'[^\w_]') |
5929 end = reg.indexIn(text, index) |
5929 match = rx.search(text, index) |
5930 if end > index: |
5930 if match: |
5931 ext = text[index:end] |
5931 end = match.start() |
5932 txt += ext |
5932 if end > index: |
5933 self.quickFindtextCombo.lineEdit().setText(txt) |
5933 ext = text[index:end] |
|
5934 txt += ext |
|
5935 self.quickFindtextCombo.lineEdit().setText(txt) |
5934 |
5936 |
5935 def showSearchWidget(self): |
5937 def showSearchWidget(self): |
5936 """ |
5938 """ |
5937 Public method to show the search widget. |
5939 Public method to show the search widget. |
5938 """ |
5940 """ |
7185 if ( |
7187 if ( |
7186 self.activeWindow() is not None and |
7188 self.activeWindow() is not None and |
7187 self.activeWindow().getFileName() |
7189 self.activeWindow().getFileName() |
7188 ): |
7190 ): |
7189 ext = os.path.splitext(self.activeWindow().getFileName())[1] |
7191 ext = os.path.splitext(self.activeWindow().getFileName())[1] |
7190 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:])) |
7192 rx = re.compile(r".*\*\.{0}[ )].*".format(ext[1:])) |
7191 import QScintilla.Lexers |
7193 import QScintilla.Lexers |
7192 filters = QScintilla.Lexers.getOpenFileFiltersList() |
7194 filters = QScintilla.Lexers.getOpenFileFiltersList() |
7193 index = -1 |
7195 index = -1 |
7194 for i in range(len(filters)): |
7196 for i in range(len(filters)): |
7195 if rx.exactMatch(filters[i]): |
7197 if rx.fullmatch(filters[i]): |
7196 index = i |
7198 index = i |
7197 break |
7199 break |
7198 if index == -1: |
7200 if index == -1: |
7199 return Preferences.getEditor("DefaultOpenFilter") |
7201 return Preferences.getEditor("DefaultOpenFilter") |
7200 else: |
7202 else: |