| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import os |
| 9 |
import re |
| 10 |
import array |
| 11 |
|
| 12 |
from PyQt6 import QtWidgets, QtGui |
| 13 |
from PyQt6.QtWidgets import * |
| 14 |
from PyQt6.QtGui import * |
| 15 |
from PyQt6.QtCore import * |
| 16 |
|
| 17 |
try: |
| 18 |
from PyQt6.Qsci import QsciScintilla, QsciScintillaBase |
| 19 |
from PyQt6.Qsci import QsciLexerCPP, QsciLexerJava |
| 20 |
from PyQt6.Qsci import QsciLexerPython, QsciLexerRuby |
| 21 |
from PyQt6.Qsci import QsciLexerBash, QsciLexerDiff, QsciLexerMakefile |
| 22 |
from PyQt6.Qsci import QsciLexerLua, QsciLexerSQL, QsciLexerTCL, QsciLexerTeX |
| 23 |
from PyQt6.Qsci import QsciLexerHTML, QsciLexerCSS |
| 24 |
from PyQt6.Qsci import QsciLexerPerl, QsciLexerVHDL |
| 25 |
|
| 26 |
suffix_to_lexer = [ |
| 27 |
[['c', 'h', 'cpp', 'hpp', 'cc', 'hh', 'cxx', 'hxx', 'C', 'H', 'h++'], QsciLexerCPP], |
| 28 |
[['java'], QsciLexerJava], |
| 29 |
[['py', 'pyx', 'pxd', 'pxi', 'scons'], QsciLexerPython], |
| 30 |
[['rb', 'ruby'], QsciLexerRuby], |
| 31 |
[['sh', 'bash'], QsciLexerBash], |
| 32 |
[['diff', 'patch'], QsciLexerDiff], |
| 33 |
[['mak', 'mk'], QsciLexerMakefile], |
| 34 |
[['lua'], QsciLexerLua], |
| 35 |
[['sql'], QsciLexerSQL], |
| 36 |
[['tcl', 'tk', 'wish', 'itcl'], QsciLexerTCL], |
| 37 |
[['tex'], QsciLexerTeX], |
| 38 |
[['htm', 'html'], QsciLexerHTML], |
| 39 |
[['css'], QsciLexerCSS], |
| 40 |
[['pl', 'perl'], QsciLexerPerl], |
| 41 |
[['vhdl', 'vhd'], QsciLexerVHDL], |
| 42 |
] |
| 43 |
filename_to_lexer = [ |
| 44 |
[['Makefile', 'makefile', 'Makefile.am', 'makefile.am', 'Makefile.in', 'makefile.in'], QsciLexerMakefile], |
| 45 |
] |
| 46 |
|
| 47 |
seascope_editor_tab_width = None |
| 48 |
try: |
| 49 |
seascope_editor_tab_width = int(os.getenv('SEASCOPE_EDITOR_TAB_WIDTH')) |
| 50 |
except: |
| 51 |
pass |
| 52 |
|
| 53 |
except ImportError as e: |
| 54 |
print(e) |
| 55 |
print("Error: required python3-pyqt6.qsci package not found") |
| 56 |
raise ImportError |
| 57 |
|
| 58 |
import DialogManager |
| 59 |
from .FileContextView import * |
| 60 |
|
| 61 |
class EditorViewBase(QsciScintilla): |
| 62 |
def __init__(self, parent=None): |
| 63 |
QsciScintilla.__init__(self, parent) |
| 64 |
self.font = None |
| 65 |
self.lexer = None |
| 66 |
|
| 67 |
def set_font(self, font): |
| 68 |
if not font: |
| 69 |
return |
| 70 |
if not self.font: |
| 71 |
self.font = QtGui.QFont() |
| 72 |
self.font.fromString(font) |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
self.fm = QtGui.QFontMetrics(self.font) |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
self.setFont(self.font) |
| 81 |
self.setMarginsFont(self.font) |
| 82 |
|
| 83 |
if self.lexer: |
| 84 |
|
| 85 |
self.lexer.setFont(self.font,-1) |
| 86 |
self.setLexer(self.lexer) |
| 87 |
|
| 88 |
def lpropChanged(self, prop, val): |
| 89 |
print('lpropChanged', prop, val) |
| 90 |
|
| 91 |
def setProperty(self, name, val): |
| 92 |
name_buff = array.array('b', (name + "\0").encode()) |
| 93 |
val_buff = array.array("b", (str(val) + "\0").encode()) |
| 94 |
address_name_buffer = name_buff.buffer_info()[0] |
| 95 |
address_val_buffer = val_buff.buffer_info()[0] |
| 96 |
self.SendScintilla(QsciScintillaBase.SCI_SETPROPERTY, address_name_buffer, address_val_buffer) |
| 97 |
|
| 98 |
def getProperty(self, name): |
| 99 |
name_buff = array.array('b', (name + "\0").encode()) |
| 100 |
val_buff = array.array("b", (str(0) + "\0").encode()) |
| 101 |
address_name_buffer = name_buff.buffer_info()[0] |
| 102 |
address_val_buffer = val_buff.buffer_info()[0] |
| 103 |
self.SendScintilla(QsciScintillaBase.SCI_GETPROPERTY, address_name_buffer, address_val_buffer) |
| 104 |
return ''.join(val_buff) |
| 105 |
|
| 106 |
def printPropertyAll(self): |
| 107 |
sz = self.SendScintilla(QsciScintillaBase.SCI_PROPERTYNAMES, 0, 0) |
| 108 |
if not sz: |
| 109 |
return |
| 110 |
val_buff = array.array("b", ((' ' * sz) + "\0").encode()) |
| 111 |
address_val_buffer = val_buff.buffer_info()[0] |
| 112 |
self.SendScintilla(QsciScintillaBase.SCI_PROPERTYNAMES, 0, address_val_buffer) |
| 113 |
print('###>') |
| 114 |
for p in ''.join(val_buff).splitlines(): |
| 115 |
v = self.getProperty(p) |
| 116 |
print(' %s = %s' % (p, v)) |
| 117 |
|
| 118 |
def lexer_for_file(self, filename): |
| 119 |
(prefix, ext) = os.path.splitext(filename) |
| 120 |
for (el, lxr) in suffix_to_lexer: |
| 121 |
if ext in el: |
| 122 |
return lxr |
| 123 |
for (el, lxr) in filename_to_lexer: |
| 124 |
if filename in el: |
| 125 |
return lxr |
| 126 |
return QsciLexerCPP |
| 127 |
|
| 128 |
def set_lexer(self, filename): |
| 129 |
if not self.lexer: |
| 130 |
lexerClass = self.lexer_for_file(filename) |
| 131 |
self.lexer = lexerClass() |
| 132 |
|
| 133 |
self.setLexer(self.lexer) |
| 134 |
self.setProperty("lexer.cpp.track.preprocessor", "0") |
| 135 |
is_debug = os.getenv("SEASCOPE_QSCI_LEXER_DEBUG", 0) |
| 136 |
if is_debug: |
| 137 |
self.lexer.propertyChanged.connect(self.lpropChanged) |
| 138 |
self.printPropertyAll() |
| 139 |
|
| 140 |
|
| 141 |
class EditorView(EditorViewBase): |
| 142 |
ev_popup = None |
| 143 |
sig_text_selected = pyqtSignal(str) |
| 144 |
def __init__(self, parent=None): |
| 145 |
EditorViewBase.__init__(self, parent) |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
self.setCaretLineVisible(True) |
| 150 |
self.setCaretLineBackgroundColor(QtGui.QColor("#d4feff")) |
| 151 |
|
| 152 |
|
| 153 |
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) |
| 154 |
|
| 155 |
self.codemark_marker = self.markerDefine(self.MarkerSymbol.Circle) |
| 156 |
|
| 157 |
def get_filename(self): |
| 158 |
return self.filename |
| 159 |
|
| 160 |
def ed_settings_1(self): |
| 161 |
|
| 162 |
|
| 163 |
self.setMarginsBackgroundColor(QtGui.QColor("#333333")) |
| 164 |
self.setMarginsForegroundColor(QtGui.QColor("#CCCCCC")) |
| 165 |
|
| 166 |
|
| 167 |
self.setFoldMarginColors(QtGui.QColor("#888888"),QtGui.QColor("#eeeeee")) |
| 168 |
|
| 169 |
|
| 170 |
self.setEdgeMode(QsciScintilla.EdgeLine) |
| 171 |
self.setEdgeColumn(80) |
| 172 |
self.setEdgeColor(QtGui.QColor("#FF0000")) |
| 173 |
|
| 174 |
|
| 175 |
self.setCaretLineVisible(True) |
| 176 |
self.setCaretLineBackgroundColor(QtGui.QColor("#CDA869")) |
| 177 |
|
| 178 |
|
| 179 |
if seascope_editor_tab_width: |
| 180 |
self.setTabWidth(seascope_editor_tab_width) |
| 181 |
|
| 182 |
def show_line_number_cb(self, val): |
| 183 |
if (val): |
| 184 |
width = self.fm.horizontalAdvance( "00000" ) + 5 |
| 185 |
else: |
| 186 |
width = 0 |
| 187 |
|
| 188 |
self.setMarginWidth(0, width) |
| 189 |
self.setMarginLineNumbers(0, val) |
| 190 |
|
| 191 |
def show_folds_cb(self, val): |
| 192 |
if val: |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
self.setFolding(QsciScintilla.FoldStyle.CircledTreeFoldStyle) |
| 198 |
else: |
| 199 |
self.setFolding(QsciScintilla.FoldStyle.NoFoldStyle) |
| 200 |
self.clearFolds() |
| 201 |
|
| 202 |
def toggle_folds_cb(self): |
| 203 |
self.foldAll() |
| 204 |
|
| 205 |
def codemark_add(self, line): |
| 206 |
self.markerAdd(line, self.codemark_marker) |
| 207 |
|
| 208 |
def codemark_del(self, line): |
| 209 |
self.markerDelete(line, self.codemark_marker) |
| 210 |
|
| 211 |
def goto_marker(self, is_next): |
| 212 |
(eline, inx) = self.getCursorPosition() |
| 213 |
u32max = 0xFFFFFFFF |
| 214 |
if is_next: |
| 215 |
val = self.markerFindNext(eline + 1, u32max) |
| 216 |
else: |
| 217 |
val = self.markerFindPrevious(eline - 1, u32max) |
| 218 |
if val >= 0: |
| 219 |
self.setCursorPosition(val, 0) |
| 220 |
|
| 221 |
def open_file_begin(self, filename): |
| 222 |
self.filename = filename |
| 223 |
|
| 224 |
|
| 225 |
self.set_lexer(filename) |
| 226 |
|
| 227 |
|
| 228 |
self.setBraceMatching(QsciScintilla.BraceMatch.SloppyBraceMatch) |
| 229 |
|
| 230 |
|
| 231 |
self.show() |
| 232 |
|
| 233 |
def open_file_end(self): |
| 234 |
self.show() |
| 235 |
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) |
| 236 |
|
| 237 |
self.setFocus() |
| 238 |
|
| 239 |
def open_file(self, filename): |
| 240 |
self.open_file_begin(filename) |
| 241 |
|
| 242 |
|
| 243 |
self.setText(open(filename).read()) |
| 244 |
|
| 245 |
|
| 246 |
self.setReadOnly(True) |
| 247 |
|
| 248 |
self.open_file_end() |
| 249 |
|
| 250 |
def refresh_file(self, filename): |
| 251 |
assert filename == self.filename |
| 252 |
pos = self.getCursorPosition() |
| 253 |
self.open_file(filename) |
| 254 |
self.setCursorPosition(*pos) |
| 255 |
self.cursorPositionChanged.emit(*pos) |
| 256 |
|
| 257 |
def goto_line(self, line): |
| 258 |
line = line - 1 |
| 259 |
self.setCursorPosition(line, 0) |
| 260 |
|
| 261 |
self.ensureLineVisible(line) |
| 262 |
self.setFocus() |
| 263 |
|
| 264 |
def contextMenuEvent(self, ev): |
| 265 |
if not EditorView.ev_popup: |
| 266 |
return |
| 267 |
f = EditorView.ev_popup.font() |
| 268 |
EditorView.ev_popup.setFont(QFont("San Serif", 8)) |
| 269 |
EditorView.ev_popup.exec(QCursor.pos()) |
| 270 |
EditorView.ev_popup.setFont(f) |
| 271 |
|
| 272 |
def mouseReleaseEvent(self, ev): |
| 273 |
super(EditorView, self).mouseReleaseEvent(ev) |
| 274 |
if(self.hasSelectedText()): |
| 275 |
self.query_text = self.selectedText() |
| 276 |
|
| 277 |
self.sig_text_selected.emit(self.query_text) |
| 278 |
|
| 279 |
class EditorPage(QSplitter): |
| 280 |
def __init__(self, parent=None): |
| 281 |
QSplitter.__init__(self) |
| 282 |
self.fcv = FileContextView(self) |
| 283 |
self.ev = self.new_editor_view() |
| 284 |
self.addWidget(self.fcv) |
| 285 |
self.addWidget(self.ev) |
| 286 |
self.setSizes([1, 300]) |
| 287 |
|
| 288 |
self.ev.cursorPositionChanged.connect(self.fcv.sig_ed_cursor_changed) |
| 289 |
self.fcv.sig_goto_line.connect(self.ev.goto_line) |
| 290 |
|
| 291 |
def new_editor_view(self): |
| 292 |
return EditorView(self) |
| 293 |
|
| 294 |
def open_file(self, filename): |
| 295 |
self.ev.open_file(filename) |
| 296 |
self.fcv.run(filename) |
| 297 |
|
| 298 |
def refresh_file(self): |
| 299 |
filename = self.get_filename() |
| 300 |
self.fcv.rerun(filename) |
| 301 |
self.ev.refresh_file(filename) |
| 302 |
|
| 303 |
def get_filename(self): |
| 304 |
return self.ev.get_filename() |
| 305 |
|
| 306 |
class EditorBook(QTabWidget): |
| 307 |
sig_file_closed = pyqtSignal(str) |
| 308 |
sig_history_update = pyqtSignal(str, int) |
| 309 |
sig_tab_changed = pyqtSignal(str) |
| 310 |
sig_open_dir_view = pyqtSignal(str) |
| 311 |
sig_editor_text_selected = pyqtSignal(str) |
| 312 |
|
| 313 |
def __init__(self, *args): |
| 314 |
QTabWidget.__init__(*(self, ) + args) |
| 315 |
|
| 316 |
self.setMovable(True) |
| 317 |
self.setTabsClosable(True) |
| 318 |
self.tabCloseRequested.connect(self.removeTab) |
| 319 |
self.currentChanged.connect(self.tab_change_cb) |
| 320 |
|
| 321 |
self.is_show_line = False |
| 322 |
self.is_show_folds = False |
| 323 |
self.f_text = None |
| 324 |
self.ev_font = "Monospace,10,-1,5,50,0,0,0,0,0" |
| 325 |
|
| 326 |
def new_editor_page(self): |
| 327 |
return EditorPage() |
| 328 |
|
| 329 |
def addFile(self, fileName): |
| 330 |
ed = self.new_editor_page() |
| 331 |
ed.open_file(fileName) |
| 332 |
ed.ev.set_font(self.ev_font) |
| 333 |
ed.ev.show_line_number_cb(self.is_show_line) |
| 334 |
ed.ev.show_folds_cb(self.is_show_folds) |
| 335 |
self.addTab(ed, os.path.basename(fileName)) |
| 336 |
return ed |
| 337 |
|
| 338 |
def search_already_opened_files(self, filename): |
| 339 |
for i in range(self.count()): |
| 340 |
page = self.widget(i) |
| 341 |
if (page.get_filename() == filename): |
| 342 |
return page |
| 343 |
return None |
| 344 |
|
| 345 |
def removeTab(self, inx): |
| 346 |
ed = self.widget(inx) |
| 347 |
if not ed: |
| 348 |
return |
| 349 |
f = ed.ev.get_filename() |
| 350 |
QTabWidget.removeTab(self, inx) |
| 351 |
self.sig_file_closed.emit(f) |
| 352 |
|
| 353 |
def clear(self): |
| 354 |
while self.count() != 0: |
| 355 |
self.removeTab(0) |
| 356 |
|
| 357 |
def remove_tab_list(self, inx_list): |
| 358 |
for inx in sorted(inx_list, reverse=True): |
| 359 |
self.removeTab(inx) |
| 360 |
|
| 361 |
def tab_list(self, inx, type): |
| 362 |
inx_list = [] |
| 363 |
if type == 'all' or type == 'files': |
| 364 |
return list(range(self.count())) |
| 365 |
if type == 'left': |
| 366 |
return list(range(inx)) |
| 367 |
if type == 'right': |
| 368 |
return list(range(inx + 1, self.count())) |
| 369 |
if type == 'other': |
| 370 |
return self.tab_list(inx, 'left') + self.tab_list(inx, 'right') |
| 371 |
assert 0 |
| 372 |
|
| 373 |
def close_list_common(self, type): |
| 374 |
inx_list = self.tab_list(self.currentIndex(), type) |
| 375 |
if len(inx_list) == 0: |
| 376 |
return |
| 377 |
if not DialogManager.show_yes_no('Close all %s ?' % type): |
| 378 |
return |
| 379 |
self.remove_tab_list(inx_list) |
| 380 |
|
| 381 |
def close_all_left_cb(self): |
| 382 |
self.close_list_common('left') |
| 383 |
def close_all_right_cb(self): |
| 384 |
self.close_list_common('right') |
| 385 |
def close_all_other_cb(self): |
| 386 |
self.close_list_common('other') |
| 387 |
def close_all_cb(self): |
| 388 |
self.close_list_common('files') |
| 389 |
|
| 390 |
def get_current_word(self): |
| 391 |
ed = self.currentWidget() |
| 392 |
if not ed: |
| 393 |
return |
| 394 |
if ed.ev.hasSelectedText(): |
| 395 |
return ed.ev.selectedText() |
| 396 |
(line, index) = ed.ev.getCursorPosition() |
| 397 |
text = ed.ev.text(line) |
| 398 |
|
| 399 |
linx = index |
| 400 |
while linx > 0 and ed.ev.isWordCharacter(text[linx - 1]): |
| 401 |
linx = linx - 1 |
| 402 |
|
| 403 |
rinx = index |
| 404 |
while rinx < len(text) and ed.ev.isWordCharacter(text[rinx]): |
| 405 |
rinx = rinx + 1 |
| 406 |
|
| 407 |
text = text[linx:rinx] |
| 408 |
if text == '': |
| 409 |
return None |
| 410 |
return text |
| 411 |
def get_current_file_line(self): |
| 412 |
ed = self.currentWidget() |
| 413 |
if not ed: |
| 414 |
return (None, None) |
| 415 |
(line, inx) = ed.ev.getCursorPosition() |
| 416 |
return (ed.ev.filename, line + 1) |
| 417 |
def get_file_line_list(self): |
| 418 |
fl_list = [] |
| 419 |
tlist = list(range(self.count())) |
| 420 |
inx = self.currentIndex() |
| 421 |
if inx >= 0: |
| 422 |
tlist.append(inx) |
| 423 |
for inx in tlist: |
| 424 |
ed = self.widget(inx) |
| 425 |
(line, inx) = ed.ev.getCursorPosition() |
| 426 |
fl_list.append('%s:%d' % (ed.ev.filename, line + 1)) |
| 427 |
return fl_list |
| 428 |
|
| 429 |
def matching_brace_cb(self): |
| 430 |
ed = self.currentWidget() |
| 431 |
if ed: |
| 432 |
ed.ev.moveToMatchingBrace() |
| 433 |
|
| 434 |
def goto_line_cb(self): |
| 435 |
ed = self.currentWidget() |
| 436 |
if not ed: |
| 437 |
return (None, None) |
| 438 |
(line, inx) = ed.ev.getCursorPosition() |
| 439 |
|
| 440 |
line = DialogManager.show_goto_line_dialog(line + 1, ed.ev.lines()) |
| 441 |
if (line == None): |
| 442 |
return |
| 443 |
ed.ev.goto_line(line) |
| 444 |
|
| 445 |
def focus_editor(self): |
| 446 |
page = self.currentWidget() |
| 447 |
if page: |
| 448 |
page.ev.setFocus() |
| 449 |
|
| 450 |
def close_current_page(self): |
| 451 |
self.removeTab(self.currentIndex()) |
| 452 |
self.focus_editor() |
| 453 |
|
| 454 |
def focus_search_ctags(self): |
| 455 |
ed = self.currentWidget() |
| 456 |
if ed: |
| 457 |
ed.fcv.focus_search_ctags() |
| 458 |
|
| 459 |
def copy_edit_cb(self): |
| 460 |
ed = self.currentWidget() |
| 461 |
if ed: |
| 462 |
ed.ev.copy() |
| 463 |
|
| 464 |
def tab_change_cb(self, inx): |
| 465 |
if (inx == -1): |
| 466 |
fname = '' |
| 467 |
else: |
| 468 |
page = self.currentWidget() |
| 469 |
page.ev.setFocus() |
| 470 |
fname = page.get_filename() |
| 471 |
self.sig_tab_changed.emit(fname) |
| 472 |
|
| 473 |
def open_dir_cb(self): |
| 474 |
page = self.currentWidget() |
| 475 |
if page: |
| 476 |
fname = page.get_filename() |
| 477 |
self.sig_open_dir_view.emit(fname) |
| 478 |
|
| 479 |
|
| 480 |
def mousePressEvent(self, m_ev): |
| 481 |
QTabWidget.mousePressEvent(self, m_ev) |
| 482 |
if (m_ev.button() == Qt.MouseButton.RightButton): |
| 483 |
|
| 484 |
self.pmenu = QMenu() |
| 485 |
self.pmenu.addAction("Open dir", self.open_dir_cb) |
| 486 |
self.pmenu.addSeparator() |
| 487 |
self.pmenu.addAction("Close All &Left", self.close_all_left_cb) |
| 488 |
self.pmenu.addAction("Close All &Right", self.close_all_right_cb) |
| 489 |
self.pmenu.addAction("Close &Others", self.close_all_other_cb) |
| 490 |
self.pmenu.addSeparator() |
| 491 |
self.pmenu.addAction("Close &All", self.close_all_cb) |
| 492 |
self.pmenu.exec(QCursor.pos()) |
| 493 |
|
| 494 |
def show_file_line(self, filename, line, hist=True): |
| 495 |
if line: |
| 496 |
(f, l) = self.get_current_file_line() |
| 497 |
if (f): |
| 498 |
if hist: |
| 499 |
self.sig_history_update.emit(f, l) |
| 500 |
filename = str(filename) |
| 501 |
if (not os.path.exists(filename)): |
| 502 |
return |
| 503 |
page = self.search_already_opened_files(filename) |
| 504 |
if page == None: |
| 505 |
page = self.addFile(filename) |
| 506 |
self.setCurrentWidget(page) |
| 507 |
if line: |
| 508 |
page.ev.goto_line(line) |
| 509 |
if hist: |
| 510 |
self.sig_history_update.emit(filename, line) |
| 511 |
page.ev.setFocus() |
| 512 |
|
| 513 |
page.ev.sig_text_selected.connect(self.editor_text_selected) |
| 514 |
|
| 515 |
def editor_text_selected(self, text): |
| 516 |
self.sig_editor_text_selected.emit(text) |
| 517 |
|
| 518 |
def show_file(self, filename): |
| 519 |
self.show_file_line(filename, 0) |
| 520 |
|
| 521 |
def show_line(self, line): |
| 522 |
ed = self.currentWidget() |
| 523 |
if not ed: |
| 524 |
return |
| 525 |
ed.ev.goto_line(line) |
| 526 |
|
| 527 |
def refresh_file_cb(self): |
| 528 |
ed = self.currentWidget() |
| 529 |
if not ed: |
| 530 |
return |
| 531 |
ed.refresh_file() |
| 532 |
|
| 533 |
def find_cb(self): |
| 534 |
ed = self.currentWidget() |
| 535 |
if not ed: |
| 536 |
return |
| 537 |
res = DialogManager.show_find_dialog(self.get_current_word()) |
| 538 |
if (res == None): |
| 539 |
return |
| 540 |
(text, opt) = res |
| 541 |
if (text == None): |
| 542 |
return |
| 543 |
self.f_text = text |
| 544 |
self.f_opt = opt |
| 545 |
self.find_text(opt['cursor'], opt['fw']) |
| 546 |
|
| 547 |
def find_text(self, from_cursor, is_fw): |
| 548 |
if (self.f_text == None): |
| 549 |
return |
| 550 |
ed = self.currentWidget() |
| 551 |
if not ed: |
| 552 |
return |
| 553 |
text = self.f_text |
| 554 |
opt = self.f_opt |
| 555 |
if (from_cursor): |
| 556 |
if (is_fw): |
| 557 |
(line, inx) = (-1, -1) |
| 558 |
else: |
| 559 |
(line, inx) = ed.ev.getCursorPosition() |
| 560 |
if (ed.ev.hasSelectedText()): |
| 561 |
inx = inx - 1 |
| 562 |
if ed.ev.findFirst(text, opt['re'], opt['cs'], opt['wo'], False, is_fw, line, inx): |
| 563 |
return True |
| 564 |
if not DialogManager.show_yes_no('End of document reached. Continue from beginning?'): |
| 565 |
return False |
| 566 |
if (is_fw): |
| 567 |
(line, inx) = (0, 0) |
| 568 |
else: |
| 569 |
(line, inx) = (ed.ev.lines(), 0) |
| 570 |
if ed.ev.findFirst(text, opt['re'], opt['cs'], opt['wo'], False, is_fw, line, inx): |
| 571 |
return |
| 572 |
DialogManager.show_msg_dialog("Could not find " + "'" + text + "'") |
| 573 |
|
| 574 |
def find_next_cb(self): |
| 575 |
self.find_text(True, True) |
| 576 |
|
| 577 |
def find_prev_cb(self): |
| 578 |
self.find_text(True, False) |
| 579 |
|
| 580 |
def change_ev_font(self, font): |
| 581 |
if font == self.ev_font: |
| 582 |
return |
| 583 |
self.ev_font = font |
| 584 |
for inx in range(self.count()): |
| 585 |
ed = self.widget(inx) |
| 586 |
ed.ev.set_font(self.ev_font) |
| 587 |
|
| 588 |
def show_line_number_cb(self): |
| 589 |
val = self.m_show_line_num.isChecked() |
| 590 |
self.is_show_line = val |
| 591 |
for inx in range(self.count()): |
| 592 |
ed = self.widget(inx) |
| 593 |
ed.ev.show_line_number_cb(val) |
| 594 |
|
| 595 |
def show_line_number_pref(self, val): |
| 596 |
if val == self.m_show_line_num.isChecked(): |
| 597 |
return |
| 598 |
self.m_show_line_num.setChecked(val) |
| 599 |
self.show_line_number_cb() |
| 600 |
|
| 601 |
def show_folds_cb(self): |
| 602 |
val = self.m_show_folds.isChecked() |
| 603 |
self.is_show_folds = val |
| 604 |
for inx in range(self.count()): |
| 605 |
ed = self.widget(inx) |
| 606 |
ed.ev.show_folds_cb(val) |
| 607 |
|
| 608 |
def toggle_folds_cb(self): |
| 609 |
ed = self.currentWidget() |
| 610 |
if not ed: |
| 611 |
return |
| 612 |
if self.is_show_folds: |
| 613 |
ed.ev.toggle_folds_cb() |
| 614 |
|
| 615 |
def open_in_external_editor(self, cmd): |
| 616 |
if not cmd: |
| 617 |
DialogManager.show_msg_dialog('Please configure external editor') |
| 618 |
return |
| 619 |
(f, l) = self.get_current_file_line() |
| 620 |
if not f: |
| 621 |
return |
| 622 |
cmd = cmd.replace('%F', f).replace('%L', str(l)) |
| 623 |
if not QProcess.startDetached(cmd): |
| 624 |
DialogManager.show_msg_dialog('Failed to start: ' + cmd) |
| 625 |
|
| 626 |
def codemark_add(self, filename, line): |
| 627 |
ed = self.search_already_opened_files(filename) |
| 628 |
if ed: |
| 629 |
ed.ev.codemark_add(line) |
| 630 |
|
| 631 |
def codemark_del(self, filename, line): |
| 632 |
ed = self.search_already_opened_files(filename) |
| 633 |
if ed: |
| 634 |
ed.ev.codemark_del(line) |
| 635 |
|
| 636 |
def bookmark_prev_cb(self): |
| 637 |
ed = self.currentWidget() |
| 638 |
if ed: |
| 639 |
ed.ev.goto_marker(False) |
| 640 |
|
| 641 |
def bookmark_next_cb(self): |
| 642 |
ed = self.currentWidget() |
| 643 |
if ed: |
| 644 |
ed.ev.goto_marker(True) |