| 1 | """ |
|---|
| 2 | TO DO: |
|---|
| 3 | * window menu |
|---|
| 4 | * help menu |
|---|
| 5 | * expand guessLexer function to include more languages |
|---|
| 6 | * implement file change autosensing |
|---|
| 7 | * list of recent files |
|---|
| 8 | * proper command line handling |
|---|
| 9 | * replace lock files with named mutex on windows and pid search in unix |
|---|
| 10 | * write keyboard shortcut editor widget |
|---|
| 11 | * write lexers for additional languages - extend CustomLexer class |
|---|
| 12 | * handle undo better |
|---|
| 13 | * deal with write protected, hidden, or non-standard files |
|---|
| 14 | * have to find better way to check if a given file is open |
|---|
| 15 | * saveAs dialog should automatically pick extension based on current extension of edited file |
|---|
| 16 | * add printing capabilities |
|---|
| 17 | * add EOL conversion |
|---|
| 18 | * add text encodings |
|---|
| 19 | * add auto completion |
|---|
| 20 | * website |
|---|
| 21 | * help menu |
|---|
| 22 | * find in files should display message - "assembling file list", "searching files" |
|---|
| 23 | * margin click to bookmark/unbookmark |
|---|
| 24 | * easy map from/to tab to/from document name |
|---|
| 25 | * remove dbgMsg(statements ) |
|---|
| 26 | * lexer in find in files has to scan entire text before displaying it - otherwise gui may become unresponsive on fold text |
|---|
| 27 | * change name to twedit++ |
|---|
| 28 | * cursor change on ? click # done using QtDrawer and setWindowFlags |
|---|
| 29 | * add context menu |
|---|
| 30 | * check what happens if there is python error during binary file execution - perhaps use try /except in the main script to catch any errors in the |
|---|
| 31 | * for new documents save as dialog should open up in directory of the previous widget - if this is not available then default path |
|---|
| 32 | * recent file list may be storing too many elements when destroying tabs before exiting |
|---|
| 33 | * add new function add new document (it inintializes fileDict. ) and avoid maniulating file dict directly |
|---|
| 34 | * figure out how to display binary files including control characters |
|---|
| 35 | * add context menu to clear find in files dialog |
|---|
| 36 | * add fold all/unfoldall - have to change existing toggle fold all |
|---|
| 37 | * python indentation does not work correctly after enter - sohuld assume indent of the previous line - maybe have to do it with API |
|---|
| 38 | * NOTICE findNext() |
|---|
| 39 | replace() does not work you have to use findFirst with arguments |
|---|
| 40 | |
|---|
| 41 | * add context menus to tabs (close, delete, rename etc...) |
|---|
| 42 | * context menu to for editor |
|---|
| 43 | * Default editor should be removed anyway the moment we open any new file |
|---|
| 44 | * groups brackets ( ) in regex string have to be escaped - e.g. \(.*\) - have to fix it to make sure you can put regular brackets |
|---|
| 45 | |
|---|
| 46 | """ |
|---|
| 47 | |
|---|
| 48 | from PyQt4.QtCore import * |
|---|
| 49 | from PyQt4.QtGui import * |
|---|
| 50 | from PyQt4.QtNetwork import * |
|---|
| 51 | from PyQt4.Qsci import * |
|---|
| 52 | |
|---|
| 53 | from PyQt4 import QtCore, QtGui |
|---|
| 54 | import os |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | import twedit_rc |
|---|
| 58 | import os |
|---|
| 59 | |
|---|
| 60 | from findandreplacedlg import FindAndReplaceDlg |
|---|
| 61 | from findandreplacedlg import FindAndReplaceHistory |
|---|
| 62 | from findandreplacedlg import FindInFilesResults |
|---|
| 63 | from findandreplacedlg import FindDisplayWidget |
|---|
| 64 | from gotolinedlg import GoToLineDlg |
|---|
| 65 | from Configuration import Configuration |
|---|
| 66 | from configurationdlg import ConfigurationDlg |
|---|
| 67 | from LanguageManager import LanguageManager |
|---|
| 68 | from CycleTabsPopup import CycleTabsPopup |
|---|
| 69 | from CycleTabsPopup import CycleTabFileList |
|---|
| 70 | from QsciScintillaCustom import QsciScintillaCustom |
|---|
| 71 | from PrinterTwedit import PrinterTwedit |
|---|
| 72 | |
|---|
| 73 | from DataSocketCommunicators import FileNameReceiver |
|---|
| 74 | import Encoding |
|---|
| 75 | |
|---|
| 76 | import re |
|---|
| 77 | from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32 |
|---|
| 78 | coding_regexps = [ |
|---|
| 79 | (2, re.compile(r'''coding[:=]\s*([-\w_.]+)''')), |
|---|
| 80 | (1, re.compile(r'''<\?xml.*\bencoding\s*=\s*['"]([-\w_.]+)['"]\?>''')), |
|---|
| 81 | ] |
|---|
| 82 | |
|---|
| 83 | from findandreplacedlg import ALL_IN_FILES , ALL_IN_ALL_OPEN_DOCS , ALL_IN_CURRENT_DOC |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | from Messaging import stdMsg, dbgMsg, errMsg, setDebugging |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | class ChangedTextHandler: |
|---|
| 91 | def __init__(self,_editor,_editorWindow): |
|---|
| 92 | self.editor=_editor |
|---|
| 93 | self.editorWindow=_editorWindow |
|---|
| 94 | |
|---|
| 95 | def handleChangedText(self): |
|---|
| 96 | |
|---|
| 97 | self.editorWindow.updateTextSizeLabel() |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | def handleModificationChanged(self,m): |
|---|
| 106 | self.editorWindow.setWindowModified(m) |
|---|
| 107 | if m: |
|---|
| 108 | index=self.editorWindow.editTab.indexOf(self.editor) |
|---|
| 109 | self.editorWindow.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-edited.png')) |
|---|
| 110 | |
|---|
| 111 | else: |
|---|
| 112 | index=self.editorWindow.editTab.indexOf(self.editor) |
|---|
| 113 | self.editorWindow.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 114 | self.editorWindow.checkActions() |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | class EditorWindow(QMainWindow): |
|---|
| 118 | |
|---|
| 119 | def __init__(self): |
|---|
| 120 | super(EditorWindow, self).__init__() |
|---|
| 121 | self.setWindowIcon(QtGui.QIcon(":/icons/twedit-icon.png")) |
|---|
| 122 | self.extensionLanguageMap={".py":"Python", |
|---|
| 123 | ".pyw":"Python", |
|---|
| 124 | ".xml":"XML", |
|---|
| 125 | ".c":"C", |
|---|
| 126 | ".cpp":"C", |
|---|
| 127 | ".cc":"C", |
|---|
| 128 | ".cxx":"C", |
|---|
| 129 | ".h":"C", |
|---|
| 130 | ".hxx":"C", |
|---|
| 131 | ".hpp":"C", |
|---|
| 132 | ".cmake":"CMake", |
|---|
| 133 | ".cs":"C#", |
|---|
| 134 | ".css":"CSS", |
|---|
| 135 | ".d":"D", |
|---|
| 136 | ".diff":"Diff", |
|---|
| 137 | ".patch":"Diff", |
|---|
| 138 | ".pas":"Pascal", |
|---|
| 139 | ".inc":"Pascal", |
|---|
| 140 | ".pl":"Perl", |
|---|
| 141 | ".rb":"Ruby", |
|---|
| 142 | ".rbw":"Ruby", |
|---|
| 143 | ".f":"Fortran77", |
|---|
| 144 | ".F":"Fortran77", |
|---|
| 145 | ".f90":"Fortran", |
|---|
| 146 | ".F90":"Fortran", |
|---|
| 147 | ".java":"Java", |
|---|
| 148 | ".js":"JavaScript", |
|---|
| 149 | ".lua":"Lua", |
|---|
| 150 | ".ps":"PostScript", |
|---|
| 151 | ".properties":"Properties", |
|---|
| 152 | ".pov":"POV", |
|---|
| 153 | ".cir":"Spice", |
|---|
| 154 | ".sql":"SQL", |
|---|
| 155 | ".tcl":"TCL", |
|---|
| 156 | ".v":"Verilog", |
|---|
| 157 | ".vhd":"VHDL", |
|---|
| 158 | ".vhdl":"VHDL", |
|---|
| 159 | ".yml":"YML", |
|---|
| 160 | ".bat":"Batch", |
|---|
| 161 | ".sh":"Bash", |
|---|
| 162 | ".html":"HTML", |
|---|
| 163 | ".tex":"TeX" |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | self.fileDialogFilters,self.filterExtensionsDict = self.prepareFileDialogFilters(self.extensionLanguageMap) |
|---|
| 167 | |
|---|
| 168 | self.findDialogForm=None |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | self.fileNameReceiver=FileNameReceiver(self) |
|---|
| 179 | |
|---|
| 180 | self.fileNameReceiver.newlyReadFileName.connect(self.processNewlyReadFileName) |
|---|
| 181 | |
|---|
| 182 | self.textSizeLabel=QLabel("SIZE LABEL") |
|---|
| 183 | self.currentPositionLabel=QLabel("CURRENT POSITION") |
|---|
| 184 | self.encodingLabel=QLabel("Encoding") |
|---|
| 185 | |
|---|
| 186 | self.statusBar().addPermanentWidget(self.textSizeLabel) |
|---|
| 187 | self.statusBar().addPermanentWidget(self.currentPositionLabel) |
|---|
| 188 | self.statusBar().addPermanentWidget(self.encodingLabel) |
|---|
| 189 | |
|---|
| 190 | self.deactivateChangeSensing=False |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | self.curFile = '' |
|---|
| 195 | self.configuration=Configuration() |
|---|
| 196 | |
|---|
| 197 | self.zoomRange=self.configuration.setting("ZoomRange") |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | self.resize(self.configuration.setting("InitialSize")) |
|---|
| 201 | self.move(self.configuration.setting("InitialPosition")) |
|---|
| 202 | self.editTab=QTabWidget() |
|---|
| 203 | self.editTab.setTabsClosable(True) |
|---|
| 204 | self.editTab.setMovable(True) |
|---|
| 205 | self.setCentralWidget(self.editTab) |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | textEditLocal=QsciScintillaCustom() |
|---|
| 209 | self.defaultEditor=textEditLocal |
|---|
| 210 | self.textChangedHandlers={} |
|---|
| 211 | |
|---|
| 212 | self.editTab.addTab(textEditLocal,QtGui.QIcon(':/icons/document-clean.png'),"New Document "+str(self.editTab.count()+1)) |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | textEditLocal.setFocus(True) |
|---|
| 219 | |
|---|
| 220 | self.textToFind="" |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | self.setEditorProperties(textEditLocal) |
|---|
| 224 | |
|---|
| 225 | textEditLocal.markerAdd(0,self.lineBookmark) |
|---|
| 226 | self.bookmarkMask=textEditLocal.markersAtLine(0) |
|---|
| 227 | textEditLocal.markerDelete(0) |
|---|
| 228 | self.indendationGuidesColor=QColor("silver") |
|---|
| 229 | |
|---|
| 230 | self.findAndReplaceHistory=FindAndReplaceHistory() |
|---|
| 231 | self.restoreFindAndReplaceHistory(self.findAndReplaceHistory) |
|---|
| 232 | |
|---|
| 233 | self.commentStyleDict={self.editTab.currentWidget():['','']} |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | dbgMsg("textEditLocal.braceMatching()=",textEditLocal.braceMatching()) |
|---|
| 241 | |
|---|
| 242 | self.createActions() |
|---|
| 243 | self.createMenus() |
|---|
| 244 | self.createToolBars() |
|---|
| 245 | self.createStatusBar() |
|---|
| 246 | |
|---|
| 247 | self.languageManager=LanguageManager(self) |
|---|
| 248 | self.languageManager.createActions() |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | self.findDock=self.__createDockWindow("Find Results") |
|---|
| 253 | self.findDisplayWidget=FindDisplayWidget(self) |
|---|
| 254 | |
|---|
| 255 | self.__setupDockWindow(self.findDock, Qt.BottomDockWidgetArea, self.findDisplayWidget, self.trUtf8("Find In Files Results")) |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | self.setCurrentFile('') |
|---|
| 264 | self.setUnifiedTitleAndToolBarOnMac(True) |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | self.fileDict={} |
|---|
| 268 | |
|---|
| 269 | self.setPropertiesInEditorList(self.editTab.currentWidget(),'',0) |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | self.textChangedHandlers[textEditLocal]=ChangedTextHandler(textEditLocal,self) |
|---|
| 273 | |
|---|
| 274 | self.editTab.widget(0).modificationChanged.connect(self.textChangedHandlers[textEditLocal].handleModificationChanged) |
|---|
| 275 | self.editTab.widget(0).textChanged.connect(self.textChangedHandlers[textEditLocal].handleChangedText) |
|---|
| 276 | self.editTab.widget(0).cursorPositionChanged.connect(self.handleCursorPositionChanged) |
|---|
| 277 | |
|---|
| 278 | if self.configuration.setting("RestoreTabsOnStartup"): |
|---|
| 279 | self.restoreTabs() |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | self.lastFileOpenPath="" |
|---|
| 286 | self.ctrlTabShortcut=QShortcut(QKeySequence("Ctrl+Tab") ,self) |
|---|
| 287 | self.connect( self.ctrlTabShortcut, SIGNAL("activated()"), self.cycleTabs ) |
|---|
| 288 | self.ctrlPressed=False |
|---|
| 289 | self.cycleTabsFlag=False |
|---|
| 290 | self.cycleTabsPopup=None |
|---|
| 291 | self.cycleTabFilesList=CycleTabFileList(self) |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | def getEditorList(self): |
|---|
| 295 | return self.fileDict.keys() |
|---|
| 296 | |
|---|
| 297 | def getCurrentDocumentName(self): |
|---|
| 298 | |
|---|
| 299 | return self.getEditorFileName(self.editTab.currentWidget()) |
|---|
| 300 | |
|---|
| 301 | def checkIfEditorExists(self,_editor): |
|---|
| 302 | try: |
|---|
| 303 | self.fileDict[_editor] |
|---|
| 304 | return True |
|---|
| 305 | except KeyError: |
|---|
| 306 | return False |
|---|
| 307 | |
|---|
| 308 | def getEditorFileName(self,_editor): |
|---|
| 309 | try: |
|---|
| 310 | return self.fileDict[_editor][0] |
|---|
| 311 | except (KeyError,IndexError): |
|---|
| 312 | return '' |
|---|
| 313 | |
|---|
| 314 | def getEditorFileModificationTime(self,_editor): |
|---|
| 315 | try: |
|---|
| 316 | return self.fileDict[_editor][1] |
|---|
| 317 | except (KeyError,IndexError): |
|---|
| 318 | return 0 |
|---|
| 319 | |
|---|
| 320 | def getEditorFileEncoding(self,_editor): |
|---|
| 321 | try: |
|---|
| 322 | return self.fileDict[_editor][2] |
|---|
| 323 | except (KeyError,IndexError): |
|---|
| 324 | return '' |
|---|
| 325 | |
|---|
| 326 | def removeEditor(self,_editor): |
|---|
| 327 | try: |
|---|
| 328 | del self.fileDict[_editor] |
|---|
| 329 | except KeyError: |
|---|
| 330 | pass |
|---|
| 331 | |
|---|
| 332 | def setEditorFileName(self,_editor,_name): |
|---|
| 333 | try: |
|---|
| 334 | self.fileDict[_editor][0]=_name |
|---|
| 335 | except (KeyError,IndexError): |
|---|
| 336 | pass |
|---|
| 337 | |
|---|
| 338 | def setEditorFileModificationTime(self,_editor,_time): |
|---|
| 339 | try: |
|---|
| 340 | self.fileDict[_editor][1]=_time |
|---|
| 341 | except (KeyError,IndexError): |
|---|
| 342 | pass |
|---|
| 343 | |
|---|
| 344 | def setEditorFileEncoding(self,_editor,_encoding): |
|---|
| 345 | try: |
|---|
| 346 | self.fileDict[_editor][2]=_encoding |
|---|
| 347 | except (KeyError,IndexError): |
|---|
| 348 | pass |
|---|
| 349 | |
|---|
| 350 | def setPropertiesInEditorList(self,_editor,_fileName='',_modificationTime=0,_encoding=''): |
|---|
| 351 | try: |
|---|
| 352 | self.fileDict[_editor][0]=_fileName |
|---|
| 353 | self.fileDict[_editor][1]=_modificationTime |
|---|
| 354 | self.fileDict[_editor][2]=_encoding |
|---|
| 355 | except KeyError: |
|---|
| 356 | self.fileDict[_editor]=[_fileName,_modificationTime,_encoding] |
|---|
| 357 | except IndexError: |
|---|
| 358 | pass |
|---|
| 359 | |
|---|
| 360 | def getPropertiesFromEditorList(self,_editor): |
|---|
| 361 | try: |
|---|
| 362 | return self.fileDict[_editor] |
|---|
| 363 | except KeyError: |
|---|
| 364 | return ('',0,'') |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | def handleCursorPositionChanged(self,_line,_index): |
|---|
| 368 | self.currentPositionLabel.setText("Ln : %s Col : %s"%(_line,_index)) |
|---|
| 369 | |
|---|
| 370 | def updateTextSizeLabel(self): |
|---|
| 371 | editor=self.editTab.currentWidget() |
|---|
| 372 | try: |
|---|
| 373 | self.textSizeLabel.setText("Length : %s lines : %s"%(editor.length(),editor.lines())) |
|---|
| 374 | except: |
|---|
| 375 | pass |
|---|
| 376 | def updateEncodingLabel(self): |
|---|
| 377 | editor=self.editTab.currentWidget() |
|---|
| 378 | try: |
|---|
| 379 | self.encodingLabel.setText(Encoding.normalizeEncodingName(self.getEditorFileEncoding(editor))) |
|---|
| 380 | |
|---|
| 381 | except KeyError: |
|---|
| 382 | self.encodingLabel.setText("Unknown encoding") |
|---|
| 383 | |
|---|
| 384 | def prepareFileDialogFilters(self,_extensionLanguageMap): |
|---|
| 385 | filterList=QString() |
|---|
| 386 | filterDict={} |
|---|
| 387 | for extension, language in _extensionLanguageMap.iteritems(): |
|---|
| 388 | dbgMsg("extension=",extension," language=",language) |
|---|
| 389 | try: |
|---|
| 390 | filterDict[language]=filterDict[language]+" *"+extension |
|---|
| 391 | except KeyError: |
|---|
| 392 | filterDict[language]="*"+extension |
|---|
| 393 | |
|---|
| 394 | keysSorted=filterDict.keys() |
|---|
| 395 | keysSorted.sort() |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | for language in keysSorted: |
|---|
| 400 | if language=="C": |
|---|
| 401 | filterList.append("C/C++"+" file ("+filterDict[language]+")\n") |
|---|
| 402 | continue |
|---|
| 403 | if language=="CMake": |
|---|
| 404 | filterList.append(language+" file ("+filterDict[language]+" CMakeLists.*)\n") |
|---|
| 405 | continue |
|---|
| 406 | |
|---|
| 407 | filterList.append(language+" file ("+filterDict[language]+")\n") |
|---|
| 408 | |
|---|
| 409 | filterList.insert(0,"Text file (*.txt)\n") |
|---|
| 410 | filterList.insert(0,"All files (*.*)\n") |
|---|
| 411 | return filterList,filterDict |
|---|
| 412 | |
|---|
| 413 | def getCurrentFilterString(self,_extension): |
|---|
| 414 | currentFilter="" |
|---|
| 415 | language="" |
|---|
| 416 | if _extension==".txt": |
|---|
| 417 | return "Text file (*.txt)" |
|---|
| 418 | try: |
|---|
| 419 | language=self.extensionLanguageMap[_extension] |
|---|
| 420 | |
|---|
| 421 | except KeyError: |
|---|
| 422 | return currentFilter |
|---|
| 423 | |
|---|
| 424 | try: |
|---|
| 425 | if language=="C": |
|---|
| 426 | currentFilter="C/C++"+" file ("+self.filterExtensionsDict[language]+")" |
|---|
| 427 | else: |
|---|
| 428 | currentFilter=language+" file ("+self.filterExtensionsDict[language]+")" |
|---|
| 429 | return currentFilter |
|---|
| 430 | except KeyError: |
|---|
| 431 | return currentFilter |
|---|
| 432 | |
|---|
| 433 | def getFileNameToEditorWidgetMap(self): |
|---|
| 434 | openFileDict={} |
|---|
| 435 | |
|---|
| 436 | for key in self.fileDict.keys(): |
|---|
| 437 | if self.fileDict[key][0]!='': |
|---|
| 438 | openFileDict[self.fileDict[key][0]]=key |
|---|
| 439 | else: |
|---|
| 440 | documentName=self.editTab.tabText(self.editTab.indexOf(key)) |
|---|
| 441 | if documentName!='': |
|---|
| 442 | openFileDict[documentName]=key |
|---|
| 443 | return openFileDict |
|---|
| 444 | |
|---|
| 445 | def cycleTabs(self): |
|---|
| 446 | dbgMsg("CYCLE TABS") |
|---|
| 447 | if not self.cycleTabsFlag: |
|---|
| 448 | self.cycleTabsFlag=True |
|---|
| 449 | |
|---|
| 450 | dbgMsg("Preparing list of Tabs") |
|---|
| 451 | |
|---|
| 452 | self.cycleTabsPopup=CycleTabsPopup(self) |
|---|
| 453 | self.cycleTabFilesList.initializeTabFileList() |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | if self.cycleTabFilesList: |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | self.cycleTabFilesList.initializeTabFileList() |
|---|
| 462 | self.cycleTabsPopup.initializeContent(self.cycleTabFilesList) |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | self.cycleTabsPopup.move(0,0) |
|---|
| 475 | self.cycleTabsPopup.adjustSize() |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | geom=self.geometry() |
|---|
| 481 | pGeom=self.cycleTabsPopup.geometry() |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | pCentered_x=geom.x()+(geom.width()-pGeom.width())/2 |
|---|
| 485 | pCentered_y=geom.y()+(geom.height()-pGeom.height())/2 |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | self.cycleTabsPopup.move(pCentered_x,pCentered_y) |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | pGeom=self.cycleTabsPopup.geometry() |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | self.cycleTabsPopup.show() |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | dbgMsg("self.cycleTabsPopup.pos()=",str(self.cycleTabsPopup.pos())+"\n\n\n\n") |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | def keyPressEvent(self, event): |
|---|
| 514 | if event.key()==Qt.Key_Control: |
|---|
| 515 | dbgMsg("CTRL key pressed") |
|---|
| 516 | self.ctrlPressed=True |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | self.ctrlPressed=True |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | def keyReleaseEvent(self, event): |
|---|
| 524 | if event.key()==Qt.Key_Control: |
|---|
| 525 | dbgMsg("CTRL RELEASED") |
|---|
| 526 | self.ctrlPressed=False |
|---|
| 527 | if self.cycleTabsFlag: |
|---|
| 528 | self.cycleTabsFlag=False |
|---|
| 529 | |
|---|
| 530 | |
|---|
| 531 | self.cycleTabsPopup.close() |
|---|
| 532 | self.cycleTabsPopup=None |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | def onMarginClick(self,_margin,_line, _state): |
|---|
| 559 | dbgMsg("_margin:",_margin," line:",_line," _state:",_state) |
|---|
| 560 | |
|---|
| 561 | def processCommandLine(self): |
|---|
| 562 | dbgMsg("\n\n\n\n\n PROCESSING CMD LINE") |
|---|
| 563 | import os |
|---|
| 564 | for fileName in self.argv: |
|---|
| 565 | dbgMsg("THIS IS THE FILE TO BE OPEN:", os.path.abspath(fileName)) |
|---|
| 566 | self.loadFile(os.path.abspath(fileName)) |
|---|
| 567 | self.activateWindow() |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | def processNewlyReadFileName(self,_fileName): |
|---|
| 594 | dbgMsg("processNewlyReadFileName fileName=",_fileName) |
|---|
| 595 | self.loadFile(os.path.abspath(_fileName)) |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | def wheelEvent(self, event): |
|---|
| 599 | |
|---|
| 600 | dbgMsg("WHEEL EVENT") |
|---|
| 601 | if qApp.keyboardModifiers()==Qt.ControlModifier: |
|---|
| 602 | editor=self.editTab.currentWidget() |
|---|
| 603 | |
|---|
| 604 | if event.delta()>0: |
|---|
| 605 | self.zoomIn() |
|---|
| 606 | else: |
|---|
| 607 | self.zoomOut() |
|---|
| 608 | |
|---|
| 609 | dbgMsg("WHEEL EVENT WITH CTRL") |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | def restoreTabs(self): |
|---|
| 621 | fileList=self.configuration.setting("ListOfOpenFiles") |
|---|
| 622 | for i in range(fileList.count()): |
|---|
| 623 | |
|---|
| 624 | self.loadFile(fileList[i], True) |
|---|
| 625 | |
|---|
| 626 | currentTabIndex=self.configuration.setting("CurrentTabIndex") |
|---|
| 627 | self.editTab.setCurrentIndex(currentTabIndex) |
|---|
| 628 | |
|---|
| 629 | def setArgv(self,_argv): |
|---|
| 630 | dbgMsg("\n\n\n command line arguments",_argv) |
|---|
| 631 | self.argv=_argv |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | def closeEvent(self, event): |
|---|
| 636 | |
|---|
| 637 | openFilesToRestore={} |
|---|
| 638 | self.deactivateChangeSensing=True |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | self.configuration.setSetting("CurrentTabIndex",self.editTab.currentIndex()) |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | dbgMsg("\n\n\n self.getEditorList()=",self.getEditorList()) |
|---|
| 646 | |
|---|
| 647 | for editor in self.getEditorList(): |
|---|
| 648 | dbgMsg("OPEN FILE NAME=",self.getEditorFileName(editor)) |
|---|
| 649 | if not self.getEditorFileName(editor)=='': |
|---|
| 650 | openFilesToRestore[self.editTab.indexOf(editor)]=self.getEditorFileName(editor) |
|---|
| 651 | dbgMsg(" \n\n\n\n openFilesToRestore=",openFilesToRestore) |
|---|
| 652 | for editor in self.getEditorList(): |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | self.editTab.setCurrentWidget(editor) |
|---|
| 660 | |
|---|
| 661 | self.closeTab() |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | self.deactivateChangeSensing=False |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | self.saveSettingsOpenFilesToRestore(openFilesToRestore) |
|---|
| 672 | |
|---|
| 673 | self.saveSettingsFindAndReplaceHistory(self.findAndReplaceHistory) |
|---|
| 674 | |
|---|
| 675 | self.configuration.setSetting("InitialSize",self.size()) |
|---|
| 676 | |
|---|
| 677 | self.configuration.setSetting("InitialPosition",self.pos()) |
|---|
| 678 | |
|---|
| 679 | event.accept() |
|---|
| 680 | |
|---|
| 681 | def saveSettingsOpenFilesToRestore(self,openFilesToRestore): |
|---|
| 682 | |
|---|
| 683 | keys=openFilesToRestore.keys() |
|---|
| 684 | keys.sort() |
|---|
| 685 | fileNamesSorted=[openFilesToRestore[key] for key in keys] |
|---|
| 686 | fileList=QStringList() |
|---|
| 687 | dbgMsg(dir(fileList)) |
|---|
| 688 | for fileName in fileNamesSorted: |
|---|
| 689 | fileList.append(fileName) |
|---|
| 690 | dbgMsg("saving fileList.count()=",fileList.count() ) |
|---|
| 691 | self.configuration.setSetting("ListOfOpenFiles",fileList) |
|---|
| 692 | |
|---|
| 693 | dbgMsg("saveSettingsOpenFilesToRestore") |
|---|
| 694 | |
|---|
| 695 | def restoreFindAndReplaceHistory(self,_frh): |
|---|
| 696 | |
|---|
| 697 | findHistoryList=self.configuration.setting("FRFindHistory") |
|---|
| 698 | for i in range(findHistoryList.count()): |
|---|
| 699 | _frh.findHistory.append(findHistoryList[i]) |
|---|
| 700 | |
|---|
| 701 | replaceHistoryList=self.configuration.setting("FRReplaceHistory") |
|---|
| 702 | for i in range(replaceHistoryList.count()): |
|---|
| 703 | _frh.replaceHistory.append(replaceHistoryList[i]) |
|---|
| 704 | |
|---|
| 705 | filtersHistoryList=self.configuration.setting("FRFiltersHistory") |
|---|
| 706 | for i in range(filtersHistoryList.count()): |
|---|
| 707 | _frh.filtersHistoryIF.append(filtersHistoryList[i]) |
|---|
| 708 | |
|---|
| 709 | directoryHistoryList=self.configuration.setting("FRDirectoryHistory") |
|---|
| 710 | for i in range(directoryHistoryList.count()): |
|---|
| 711 | _frh.directoryHistoryIF.append(directoryHistoryList[i]) |
|---|
| 712 | |
|---|
| 713 | _frh.syntaxIndex=self.configuration.setting("FRSyntaxIndex") |
|---|
| 714 | _frh.inSelection=self.configuration.setting("FRInSelection") |
|---|
| 715 | _frh.inAllSubfolders=self.configuration.setting("FRInAllSubfolders") |
|---|
| 716 | _frh.opacity=self.configuration.setting("FROpacity") |
|---|
| 717 | _frh.transparencyEnable=self.configuration.setting("FRTransparencyEnable") |
|---|
| 718 | _frh.opacityOnLosingFocus=self.configuration.setting("FROnLosingFocus") |
|---|
| 719 | _frh.opacityAlways=self.configuration.setting("FRAlways") |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | def saveSettingsFindAndReplaceHistory(self,_frh): |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | findHistoryList=QStringList() |
|---|
| 729 | for findText in _frh.findHistory: |
|---|
| 730 | findHistoryList.append(findText) |
|---|
| 731 | self.configuration.setSetting("FRFindHistory",findHistoryList) |
|---|
| 732 | |
|---|
| 733 | replaceHistoryList=QStringList() |
|---|
| 734 | for replaceText in _frh.replaceHistory: |
|---|
| 735 | replaceHistoryList.append(replaceText) |
|---|
| 736 | self.configuration.setSetting("FRReplaceHistory",replaceHistoryList) |
|---|
| 737 | |
|---|
| 738 | filtersHistoryList=QStringList() |
|---|
| 739 | for filtersText in _frh.filtersHistoryIF: |
|---|
| 740 | filtersHistoryList.append(filtersText) |
|---|
| 741 | self.configuration.setSetting("FRFiltersHistory",filtersHistoryList) |
|---|
| 742 | |
|---|
| 743 | directoryHistoryList=QStringList() |
|---|
| 744 | for directoryText in _frh.directoryHistoryIF: |
|---|
| 745 | directoryHistoryList.append(directoryText) |
|---|
| 746 | self.configuration.setSetting("FRDirectoryHistory",directoryHistoryList) |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | self.configuration.setSetting("FRSyntaxIndex",_frh.syntaxIndex) |
|---|
| 750 | |
|---|
| 751 | self.configuration.setSetting("FRInSelection",_frh.inSelection) |
|---|
| 752 | self.configuration.setSetting("FRInAllSubfolders",_frh.inAllSubfolders) |
|---|
| 753 | self.configuration.setSetting("FROpacity",_frh.opacity) |
|---|
| 754 | self.configuration.setSetting("FRTransparencyEnable",_frh.transparencyEnable) |
|---|
| 755 | self.configuration.setSetting("FROnLosingFocus",_frh.opacityOnLosingFocus) |
|---|
| 756 | self.configuration.setSetting("FRAlways",_frh.opacityAlways) |
|---|
| 757 | |
|---|
| 758 | dbgMsg("saveSettingsFindAndReplaceHistory" ) |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | def changeEvent(self,event): |
|---|
| 764 | if self.deactivateChangeSensing: |
|---|
| 765 | return |
|---|
| 766 | dbgMsg("THIS IS CHANGE EVENT ",event.type()) |
|---|
| 767 | if event.type()==QEvent.ActivationChange: |
|---|
| 768 | dbgMsg("application focus has changed") |
|---|
| 769 | dbgMsg("isActiveWindow()=",self.isActiveWindow()) |
|---|
| 770 | if self.isActiveWindow(): |
|---|
| 771 | self.deactivateChangeSensing=True |
|---|
| 772 | self.checkIfDocumentsWereModified() |
|---|
| 773 | self.deactivateChangeSensing=False |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | def checkIfDocumentsWereModified(self): |
|---|
| 777 | for editor in self.getEditorList(): |
|---|
| 778 | fileName=self.getEditorFileName(editor) |
|---|
| 779 | if fileName!='' and os.path.getmtime(fileName)>self.getEditorFileModificationTime(editor): |
|---|
| 780 | dbgMsg("DOCUMENT ",fileName, " was modified") |
|---|
| 781 | reloadFlag=self.maybeReload(editor) |
|---|
| 782 | if not reloadFlag: |
|---|
| 783 | self.setEditorFileModificationTime(editor,os.path.getmtime(fileName)) |
|---|
| 784 | |
|---|
| 785 | dbgMsg("reloadFlag=",reloadFlag) |
|---|
| 786 | |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | def setEditorProperties(self,_editor): |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | _editor.setMarginLineNumbers(0, self.configuration.setting("DisplayLineNumbers")) |
|---|
| 826 | _editor.setMarginWidth(0,QString('0'*8)) |
|---|
| 827 | |
|---|
| 828 | useTabSpaces=self.configuration.setting("UseTabSpaces") |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | _editor.setIndentationsUseTabs(not useTabSpaces) |
|---|
| 832 | if useTabSpaces: |
|---|
| 833 | _editor.setIndentationWidth(self.configuration.setting("TabSpaces")) |
|---|
| 834 | else: |
|---|
| 835 | _editor.setIndentationWidth(0) |
|---|
| 836 | self.lineBookmark = _editor.markerDefine(QsciScintilla.SC_MARK_SHORTARROW) |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | _editor.setMarginMarkerMask(2,QsciScintilla.SC_MARK_SHORTARROW) |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | _editor.setMarginSensitivity(1,True) |
|---|
| 847 | _editor.marginClicked.connect(self.marginClickedHandler) |
|---|
| 848 | |
|---|
| 849 | _editor.setMarkerBackgroundColor(QColor("lightsteelblue"), self.lineBookmark) |
|---|
| 850 | |
|---|
| 851 | if self.configuration.setting("FoldText"): |
|---|
| 852 | _editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 853 | else: |
|---|
| 854 | _editor.setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 855 | _editor.setCaretLineVisible(True) |
|---|
| 856 | _editor.setCaretLineBackgroundColor(QtGui.QColor('#EFEFFB')) |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | displayWhitespace=self.configuration.setting("DisplayWhitespace") |
|---|
| 866 | if displayWhitespace: |
|---|
| 867 | _editor.setWhitespaceVisibility(QsciScintilla.SCWS_VISIBLEALWAYS) |
|---|
| 868 | else: |
|---|
| 869 | _editor.setWhitespaceVisibility(QsciScintilla.SCWS_INVISIBLE) |
|---|
| 870 | |
|---|
| 871 | displayEol=self.configuration.setting("DisplayEOL") |
|---|
| 872 | _editor.setEolVisibility(displayEol) |
|---|
| 873 | |
|---|
| 874 | wrapLines=self.configuration.setting("WrapLines") |
|---|
| 875 | showWrapSymbol=self.configuration.setting("ShowWrapSymbol") |
|---|
| 876 | |
|---|
| 877 | if wrapLines: |
|---|
| 878 | _editor.setWrapMode(QsciScintilla.WrapWord) |
|---|
| 879 | if showWrapSymbol: |
|---|
| 880 | _editor.setWrapVisualFlags(QsciScintilla.WrapFlagByText) |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | def modificationChangedSlot(self, _flag): |
|---|
| 911 | dbgMsg("THIS IS CHANGED DOCUMENT") |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
| 945 | |
|---|
| 946 | |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | |
|---|
| 957 | |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | def blockComment(self): |
|---|
| 969 | editor=self.editTab.currentWidget() |
|---|
| 970 | if not self.commentStyleDict[editor][0]: |
|---|
| 971 | return |
|---|
| 972 | |
|---|
| 973 | commentStringBegin=self.commentStyleDict[editor][0] |
|---|
| 974 | commentStringEnd=self.commentStyleDict[editor][1] |
|---|
| 975 | |
|---|
| 976 | |
|---|
| 977 | if editor.hasSelectedText(): |
|---|
| 978 | line_from, index_from, line_to, index_to = editor.getSelection() |
|---|
| 979 | if index_to==0: |
|---|
| 980 | line_to-=1 |
|---|
| 981 | |
|---|
| 982 | editor.endUndoAction() |
|---|
| 983 | for l in range(line_from, line_to+1): |
|---|
| 984 | |
|---|
| 985 | self.commentSingleLine(l,commentStringBegin,commentStringEnd) |
|---|
| 986 | editor.endUndoAction() |
|---|
| 987 | |
|---|
| 988 | |
|---|
| 989 | |
|---|
| 990 | |
|---|
| 991 | if index_to==0: |
|---|
| 992 | line_to+=1 |
|---|
| 993 | editor.setSelection(line_from, index_from+len(commentStringBegin), line_to, index_to) |
|---|
| 994 | else: |
|---|
| 995 | editor.setSelection(line_from, index_from+len(commentStringBegin), line_to, index_to+len(commentStringBegin)) |
|---|
| 996 | |
|---|
| 997 | |
|---|
| 998 | |
|---|
| 999 | |
|---|
| 1000 | else: |
|---|
| 1001 | currentLine,currentColumn=editor.getCursorPosition() |
|---|
| 1002 | editor.beginUndoAction() |
|---|
| 1003 | self.commentSingleLine(currentLine,commentStringBegin,commentStringEnd) |
|---|
| 1004 | editor.endUndoAction() |
|---|
| 1005 | |
|---|
| 1006 | |
|---|
| 1007 | def commentSingleLine(self,currentLine,commentStringBegin,commentStringEnd): |
|---|
| 1008 | editor=self.editTab.currentWidget() |
|---|
| 1009 | |
|---|
| 1010 | if commentStringEnd: |
|---|
| 1011 | |
|---|
| 1012 | if not editor.text(currentLine).trimmed().isEmpty(): |
|---|
| 1013 | |
|---|
| 1014 | editor.insertAt( commentStringBegin , currentLine, 0 ) |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | |
|---|
| 1018 | eolPos=editor.text(currentLine).size() |
|---|
| 1019 | lineText=editor.text(currentLine) |
|---|
| 1020 | if lineText[eolPos-2]=="\r" or lineText[eolPos-2]=="\n": |
|---|
| 1021 | editor.insertAt( commentStringEnd , currentLine, eolPos-2) |
|---|
| 1022 | else: |
|---|
| 1023 | editor.insertAt( commentStringEnd , currentLine, eolPos-1) |
|---|
| 1024 | |
|---|
| 1025 | else: |
|---|
| 1026 | if not editor.text(currentLine).trimmed().isEmpty(): |
|---|
| 1027 | |
|---|
| 1028 | editor.insertAt( commentStringBegin , currentLine, 0 ) |
|---|
| 1029 | |
|---|
| 1030 | |
|---|
| 1031 | |
|---|
| 1032 | def copy(self): |
|---|
| 1033 | editor=self.editTab.currentWidget() |
|---|
| 1034 | editor.copy() |
|---|
| 1035 | |
|---|
| 1036 | def cut(self): |
|---|
| 1037 | editor=self.editTab.currentWidget() |
|---|
| 1038 | editor.cut() |
|---|
| 1039 | |
|---|
| 1040 | |
|---|
| 1041 | def paste(self): |
|---|
| 1042 | editor=self.editTab.currentWidget() |
|---|
| 1043 | editor.paste() |
|---|
| 1044 | |
|---|
| 1045 | def increaseIndent(self): |
|---|
| 1046 | |
|---|
| 1047 | |
|---|
| 1048 | |
|---|
| 1049 | editor=self.editTab.currentWidget() |
|---|
| 1050 | line, index = editor.getCursorPosition() |
|---|
| 1051 | if editor.hasSelectedText(): |
|---|
| 1052 | line_from, index_from, line_to, index_to = editor.getSelection() |
|---|
| 1053 | if index_to == 0 : |
|---|
| 1054 | line_to -= 1 |
|---|
| 1055 | editor.beginUndoAction() |
|---|
| 1056 | for line in range(line_from, line_to+1): |
|---|
| 1057 | |
|---|
| 1058 | editor.indent(line) |
|---|
| 1059 | editor.endUndoAction() |
|---|
| 1060 | else: |
|---|
| 1061 | tabString="" |
|---|
| 1062 | indentationWidth=1 |
|---|
| 1063 | if editor.indentationsUseTabs(): |
|---|
| 1064 | tabString="\t" |
|---|
| 1065 | else: |
|---|
| 1066 | indentationWidth=editor.indentationWidth() |
|---|
| 1067 | tabString=" "*indentationWidth |
|---|
| 1068 | |
|---|
| 1069 | editor.insertAt(tabString,line, index) |
|---|
| 1070 | editor.setCursorPosition(line,index+indentationWidth) |
|---|
| 1071 | |
|---|
| 1072 | |
|---|
| 1073 | |
|---|
| 1074 | def decreaseIndent(self): |
|---|
| 1075 | editor=self.editTab.currentWidget() |
|---|
| 1076 | line, index = editor.getCursorPosition() |
|---|
| 1077 | if editor.hasSelectedText(): |
|---|
| 1078 | line_from, index_from, line_to, index_to = editor.getSelection() |
|---|
| 1079 | if index_to == 0 : |
|---|
| 1080 | line_to -= 1 |
|---|
| 1081 | editor.beginUndoAction() |
|---|
| 1082 | for line in range(line_from, line_to+1): |
|---|
| 1083 | |
|---|
| 1084 | editor.unindent(line) |
|---|
| 1085 | editor.endUndoAction() |
|---|
| 1086 | else: |
|---|
| 1087 | editor.unindent(line) |
|---|
| 1088 | |
|---|
| 1089 | def blockUncomment(self): |
|---|
| 1090 | editor=self.editTab.currentWidget() |
|---|
| 1091 | if not self.commentStyleDict[editor][0]: |
|---|
| 1092 | return |
|---|
| 1093 | |
|---|
| 1094 | commentStringBegin=QString(self.commentStyleDict[editor][0]) |
|---|
| 1095 | commentStringBeginTrunc=commentStringBegin.trimmed() |
|---|
| 1096 | |
|---|
| 1097 | |
|---|
| 1098 | if commentStringBeginTrunc=="REM": |
|---|
| 1099 | commentStringBeginTrunc=commentStringBegin |
|---|
| 1100 | |
|---|
| 1101 | commentStringEnd=QString() |
|---|
| 1102 | if self.commentStyleDict[editor][1]: |
|---|
| 1103 | commentStringEnd=QString(self.commentStyleDict[editor][1]) |
|---|
| 1104 | commentStringEndTrunc=commentStringEnd.trimmed() |
|---|
| 1105 | |
|---|
| 1106 | |
|---|
| 1107 | if editor.hasSelectedText(): |
|---|
| 1108 | line_from, index_from, line_to, index_to = editor.getSelection() |
|---|
| 1109 | if index_to == 0 : |
|---|
| 1110 | line_to -= 1 |
|---|
| 1111 | firstLineBeginCommentLength=0 |
|---|
| 1112 | lastLineBeginCommentLength=0 |
|---|
| 1113 | |
|---|
| 1114 | editor.beginUndoAction() |
|---|
| 1115 | |
|---|
| 1116 | for line in range(line_from, line_to+1): |
|---|
| 1117 | |
|---|
| 1118 | beginCommentLength,endCommentLength = self.uncommentLine(line,commentStringBegin,commentStringBeginTrunc,commentStringEnd,commentStringEndTrunc) |
|---|
| 1119 | if line==line_from: |
|---|
| 1120 | firstLineBeginCommentLength=beginCommentLength |
|---|
| 1121 | if line==line_to: |
|---|
| 1122 | lastLineBeginCommentLength=beginCommentLength |
|---|
| 1123 | editor.endUndoAction() |
|---|
| 1124 | |
|---|
| 1125 | |
|---|
| 1126 | if index_to==0: |
|---|
| 1127 | line_to+=1 |
|---|
| 1128 | editor.setSelection(line_from, index_from-firstLineBeginCommentLength, line_to, index_to) |
|---|
| 1129 | else: |
|---|
| 1130 | editor.setSelection(line_from, index_from-firstLineBeginCommentLength, line_to, index_to-lastLineBeginCommentLength) |
|---|
| 1131 | |
|---|
| 1132 | |
|---|
| 1133 | |
|---|
| 1134 | |
|---|
| 1135 | |
|---|
| 1136 | else: |
|---|
| 1137 | |
|---|
| 1138 | |
|---|
| 1139 | line, index = editor.getCursorPosition() |
|---|
| 1140 | editor.beginUndoAction() |
|---|
| 1141 | self.uncommentLine(line,commentStringBegin,commentStringBeginTrunc,commentStringEnd,commentStringEndTrunc) |
|---|
| 1142 | editor.endUndoAction() |
|---|
| 1143 | |
|---|
| 1144 | |
|---|
| 1145 | |
|---|
| 1146 | |
|---|
| 1147 | |
|---|
| 1148 | |
|---|
| 1149 | |
|---|
| 1150 | |
|---|
| 1151 | |
|---|
| 1152 | |
|---|
| 1153 | |
|---|
| 1154 | |
|---|
| 1155 | |
|---|
| 1156 | |
|---|
| 1157 | |
|---|
| 1158 | |
|---|
| 1159 | |
|---|
| 1160 | |
|---|
| 1161 | |
|---|
| 1162 | |
|---|
| 1163 | |
|---|
| 1164 | |
|---|
| 1165 | |
|---|
| 1166 | |
|---|
| 1167 | |
|---|
| 1168 | |
|---|
| 1169 | |
|---|
| 1170 | |
|---|
| 1171 | |
|---|
| 1172 | |
|---|
| 1173 | |
|---|
| 1174 | |
|---|
| 1175 | |
|---|
| 1176 | |
|---|
| 1177 | |
|---|
| 1178 | |
|---|
| 1179 | |
|---|
| 1180 | |
|---|
| 1181 | |
|---|
| 1182 | |
|---|
| 1183 | |
|---|
| 1184 | def uncommentLine(self,line,commentStringBegin,commentStringBeginTrunc,commentStringEnd,commentStringEndTrunc): |
|---|
| 1185 | |
|---|
| 1186 | editor=self.editTab.currentWidget() |
|---|
| 1187 | commentsFound=False |
|---|
| 1188 | |
|---|
| 1189 | lineText=editor.text(line) |
|---|
| 1190 | origLineTextLength=lineText.size() |
|---|
| 1191 | indexOf=lineText.indexOf(commentStringBegin) |
|---|
| 1192 | |
|---|
| 1193 | beginCommentLength=0 |
|---|
| 1194 | endCommentLength=0 |
|---|
| 1195 | |
|---|
| 1196 | |
|---|
| 1197 | if indexOf != -1: |
|---|
| 1198 | lineText.remove(indexOf,commentStringBegin.size()) |
|---|
| 1199 | beginCommentLength=commentStringBegin.size() |
|---|
| 1200 | commentsFound=True |
|---|
| 1201 | |
|---|
| 1202 | else: |
|---|
| 1203 | indexOf=lineText.indexOf(commentStringBeginTrunc) |
|---|
| 1204 | if indexOf != -1: |
|---|
| 1205 | lineText.remove(indexOf,commentStringBeginTrunc.size()) |
|---|
| 1206 | beginCommentLength=commentStringBeginTrunc.size() |
|---|
| 1207 | commentsFound=True |
|---|
| 1208 | |
|---|
| 1209 | if commentStringEnd.size() : |
|---|
| 1210 | |
|---|
| 1211 | |
|---|
| 1212 | lastIndexOf=lineText.lastIndexOf(commentStringEnd) |
|---|
| 1213 | if lastIndexOf!=-1 : |
|---|
| 1214 | lineText.remove(lastIndexOf,commentStringEnd.size()) |
|---|
| 1215 | endCommentLength=commentStringEnd.size() |
|---|
| 1216 | commentsFound=True |
|---|
| 1217 | else: |
|---|
| 1218 | lastIndexOf=lineText.lastIndexOf(commentStringEndTrunc) |
|---|
| 1219 | if lastIndexOf!=-1 : |
|---|
| 1220 | lineText.remove(lastIndexOf,commentStringEndTrunc.size()) |
|---|
| 1221 | endCommentLength=commentStringEndTrunc.size() |
|---|
| 1222 | commentsFound=True |
|---|
| 1223 | |
|---|
| 1224 | if commentsFound: |
|---|
| 1225 | eolPos=lineText.size() |
|---|
| 1226 | if lineText[eolPos-2]=="\r" or lineText[eolPos-2]=="\n": |
|---|
| 1227 | editor.setSelection(line,0,line,origLineTextLength-1) |
|---|
| 1228 | else: |
|---|
| 1229 | editor.setSelection(line,0,line,origLineTextLength) |
|---|
| 1230 | |
|---|
| 1231 | editor.removeSelectedText() |
|---|
| 1232 | |
|---|
| 1233 | editor.insertAt(lineText,line,0) |
|---|
| 1234 | |
|---|
| 1235 | return beginCommentLength,endCommentLength |
|---|
| 1236 | |
|---|
| 1237 | def find(self): |
|---|
| 1238 | |
|---|
| 1239 | if self.findDialogForm: |
|---|
| 1240 | self.findDialogForm.show() |
|---|
| 1241 | return |
|---|
| 1242 | |
|---|
| 1243 | self.findDialogForm = FindAndReplaceDlg("",self) |
|---|
| 1244 | self.findDialogForm.setFindAndReaplceHistory(self.findAndReplaceHistory) |
|---|
| 1245 | |
|---|
| 1246 | |
|---|
| 1247 | editor=self.editTab.currentWidget() |
|---|
| 1248 | |
|---|
| 1249 | |
|---|
| 1250 | |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | |
|---|
| 1254 | |
|---|
| 1255 | |
|---|
| 1256 | self.findDialogForm.searchingSignal.connect(self.findNext) |
|---|
| 1257 | self.findDialogForm.replacingSignal.connect(self.replaceNext) |
|---|
| 1258 | self.findDialogForm.replacingAllSignal.connect(self.replaceAll) |
|---|
| 1259 | self.findDialogForm.initializeDialog(self.findAndReplaceHistory) |
|---|
| 1260 | |
|---|
| 1261 | if editor.hasSelectedText(): |
|---|
| 1262 | self.findDialogForm.findLineEdit.setText(editor.selectedText()) |
|---|
| 1263 | |
|---|
| 1264 | |
|---|
| 1265 | self.findDialogForm.searchingSignalIF.connect(self.findInFiles) |
|---|
| 1266 | self.findDialogForm.replacingSignalIF.connect(self.replaceInFiles) |
|---|
| 1267 | |
|---|
| 1268 | self.findDialogForm.searchingAllInAllOpenDocsSignal.connect(self.findInFiles) |
|---|
| 1269 | |
|---|
| 1270 | |
|---|
| 1271 | self.findDialogForm.replacingAllInOpenDocsSignal.connect(self.replaceInFiles) |
|---|
| 1272 | |
|---|
| 1273 | |
|---|
| 1274 | |
|---|
| 1275 | self.findDialogForm.show() |
|---|
| 1276 | |
|---|
| 1277 | def findInFiles(self,_text,_filters,_directory,_mode=ALL_IN_FILES): |
|---|
| 1278 | dbgMsg("findInFiles") |
|---|
| 1279 | |
|---|
| 1280 | |
|---|
| 1281 | |
|---|
| 1282 | |
|---|
| 1283 | dbgMsg("search parameters",_text," ", _filters," ",_directory) |
|---|
| 1284 | |
|---|
| 1285 | reFlag=False |
|---|
| 1286 | |
|---|
| 1287 | if str(self.findDialogForm.syntaxComboBoxIF.currentText())=="Regular expression": |
|---|
| 1288 | reFlag=True |
|---|
| 1289 | |
|---|
| 1290 | newSearchFlag=self.findAndReplaceHistory.newSearchParametersIF(_text,_filters,_directory) |
|---|
| 1291 | |
|---|
| 1292 | self.findDialogForm.initializeAllSearchLists(self.findAndReplaceHistory) |
|---|
| 1293 | |
|---|
| 1294 | |
|---|
| 1295 | |
|---|
| 1296 | |
|---|
| 1297 | |
|---|
| 1298 | |
|---|
| 1299 | |
|---|
| 1300 | |
|---|
| 1301 | |
|---|
| 1302 | |
|---|
| 1303 | import fnmatch |
|---|
| 1304 | import os |
|---|
| 1305 | filters=str(_filters).split() |
|---|
| 1306 | dbgMsg(filters) |
|---|
| 1307 | |
|---|
| 1308 | matches = [] |
|---|
| 1309 | if _mode==ALL_IN_FILES: |
|---|
| 1310 | for filter in filters: |
|---|
| 1311 | if self.findDialogForm.inAllSubFoldersCheckBoxIF.isChecked(): |
|---|
| 1312 | for root, dirnames, filenames in os.walk(str(_directory)): |
|---|
| 1313 | for filename in fnmatch.filter(filenames, filter): |
|---|
| 1314 | matches.append(os.path.join(root, filename)) |
|---|
| 1315 | else: |
|---|
| 1316 | root=str(_directory) |
|---|
| 1317 | for filename in os.listdir(root): |
|---|
| 1318 | if fnmatch.fnmatch(filename, filter): |
|---|
| 1319 | matches.append(os.path.join(root, filename)) |
|---|
| 1320 | |
|---|
| 1321 | |
|---|
| 1322 | |
|---|
| 1323 | |
|---|
| 1324 | |
|---|
| 1325 | |
|---|
| 1326 | foundFiles=[] |
|---|
| 1327 | |
|---|
| 1328 | if _mode==ALL_IN_FILES: |
|---|
| 1329 | foundFiles=self.findFiles(matches,_text,reFlag) |
|---|
| 1330 | elif _mode==ALL_IN_ALL_OPEN_DOCS: |
|---|
| 1331 | foundFiles=self.findAllInOpenDocs(_text,reFlag) |
|---|
| 1332 | elif _mode==ALL_IN_CURRENT_DOC: |
|---|
| 1333 | foundFiles=self.findAllInOpenDocs(_text,reFlag,True) |
|---|
| 1334 | else: |
|---|
| 1335 | return |
|---|
| 1336 | |
|---|
| 1337 | |
|---|
| 1338 | |
|---|
| 1339 | |
|---|
| 1340 | |
|---|
| 1341 | |
|---|
| 1342 | findInFilesFormatter=FindInFilesResults() |
|---|
| 1343 | self.findDisplayWidget.addNewFindInFilesResults(findInFilesFormatter.produceSummaryRepr(foundFiles,_text)) |
|---|
| 1344 | if not self.showFindInFilesDockAct.isChecked(): |
|---|
| 1345 | self.showFindInFilesDockAct.trigger() |
|---|
| 1346 | |
|---|
| 1347 | |
|---|
| 1348 | |
|---|
| 1349 | |
|---|
| 1350 | |
|---|
| 1351 | |
|---|
| 1352 | |
|---|
| 1353 | |
|---|
| 1354 | |
|---|
| 1355 | |
|---|
| 1356 | |
|---|
| 1357 | |
|---|
| 1358 | |
|---|
| 1359 | |
|---|
| 1360 | |
|---|
| 1361 | |
|---|
| 1362 | |
|---|
| 1363 | |
|---|
| 1364 | |
|---|
| 1365 | |
|---|
| 1366 | |
|---|
| 1367 | |
|---|
| 1368 | def findAllInOpenDocs(self,_text,_reFlag=False, _inCurrentDoc=False): |
|---|
| 1369 | |
|---|
| 1370 | foundFiles = [] |
|---|
| 1371 | editorList=[] |
|---|
| 1372 | if _inCurrentDoc: |
|---|
| 1373 | editorList.append(self.editTab.currentWidget()) |
|---|
| 1374 | else: |
|---|
| 1375 | editorList=self.getEditorList() |
|---|
| 1376 | |
|---|
| 1377 | for editor in editorList: |
|---|
| 1378 | currentLine,currentIndex = editor.getCursorPosition() |
|---|
| 1379 | filename=self.getEditorFileName(editor) |
|---|
| 1380 | if filename=='': |
|---|
| 1381 | continue |
|---|
| 1382 | |
|---|
| 1383 | foundFlag=editor.findFirst(_text,_reFlag,\ |
|---|
| 1384 | self.findDialogForm.caseCheckBox.isChecked(),\ |
|---|
| 1385 | self.findDialogForm.wholeCheckBox.isChecked(),\ |
|---|
| 1386 | False,\ |
|---|
| 1387 | True,0,0,False) |
|---|
| 1388 | |
|---|
| 1389 | findResults=None |
|---|
| 1390 | if foundFlag: |
|---|
| 1391 | foundFiles.append(FindInFilesResults(filename,_text)) |
|---|
| 1392 | findResults=foundFiles[-1] |
|---|
| 1393 | |
|---|
| 1394 | while foundFlag: |
|---|
| 1395 | line,index=editor.getCursorPosition() |
|---|
| 1396 | |
|---|
| 1397 | findResults.addLineWithText(line,editor.text(line)) |
|---|
| 1398 | foundFlag=editor.findNext() |
|---|
| 1399 | |
|---|
| 1400 | editor.setCursorPosition(currentLine,currentIndex) |
|---|
| 1401 | |
|---|
| 1402 | return foundFiles |
|---|
| 1403 | |
|---|
| 1404 | def findFiles(self, _files, _text,_reFlag=False): |
|---|
| 1405 | progressDialog = QtGui.QProgressDialog(self) |
|---|
| 1406 | |
|---|
| 1407 | progressDialog.setCancelButtonText("&Cancel") |
|---|
| 1408 | numberOfFiles=len(_files) |
|---|
| 1409 | progressDialog.setRange(0, numberOfFiles) |
|---|
| 1410 | progressDialog.setWindowTitle("Find Text in Files") |
|---|
| 1411 | |
|---|
| 1412 | foundFiles = [] |
|---|
| 1413 | i=1 |
|---|
| 1414 | for filename in _files: |
|---|
| 1415 | |
|---|
| 1416 | progressDialog.setValue(i) |
|---|
| 1417 | progressDialog.setLabelText("Searching file number %d of %d..." % (i, numberOfFiles)) |
|---|
| 1418 | QtGui.qApp.processEvents() |
|---|
| 1419 | |
|---|
| 1420 | if progressDialog.wasCanceled(): |
|---|
| 1421 | break |
|---|
| 1422 | |
|---|
| 1423 | inFile = QtCore.QFile(filename) |
|---|
| 1424 | |
|---|
| 1425 | if inFile.open(QtCore.QIODevice.ReadOnly): |
|---|
| 1426 | stream = QtCore.QTextStream(inFile) |
|---|
| 1427 | |
|---|
| 1428 | textEditLocal=QsciScintillaCustom() |
|---|
| 1429 | |
|---|
| 1430 | textEditLocal.setText(stream.readAll()) |
|---|
| 1431 | |
|---|
| 1432 | foundFlag=textEditLocal.findFirst(_text,_reFlag,\ |
|---|
| 1433 | self.findDialogForm.caseCheckBoxIF.isChecked(),\ |
|---|
| 1434 | self.findDialogForm.wholeCheckBoxIF.isChecked(),\ |
|---|
| 1435 | False,\ |
|---|
| 1436 | True,0,0,False) |
|---|
| 1437 | findResults=None |
|---|
| 1438 | if foundFlag: |
|---|
| 1439 | foundFiles.append(FindInFilesResults(filename,_text)) |
|---|
| 1440 | findResults=foundFiles[-1] |
|---|
| 1441 | |
|---|
| 1442 | while foundFlag: |
|---|
| 1443 | line,index=textEditLocal.getCursorPosition() |
|---|
| 1444 | |
|---|
| 1445 | findResults.addLineWithText(line,textEditLocal.text(line)) |
|---|
| 1446 | foundFlag=textEditLocal.findNext() |
|---|
| 1447 | |
|---|
| 1448 | |
|---|
| 1449 | |
|---|
| 1450 | |
|---|
| 1451 | |
|---|
| 1452 | |
|---|
| 1453 | |
|---|
| 1454 | |
|---|
| 1455 | i+=1 |
|---|
| 1456 | progressDialog.close() |
|---|
| 1457 | |
|---|
| 1458 | return foundFiles |
|---|
| 1459 | |
|---|
| 1460 | |
|---|
| 1461 | |
|---|
| 1462 | |
|---|
| 1463 | |
|---|
| 1464 | |
|---|
| 1465 | |
|---|
| 1466 | |
|---|
| 1467 | |
|---|
| 1468 | |
|---|
| 1469 | |
|---|
| 1470 | |
|---|
| 1471 | |
|---|
| 1472 | |
|---|
| 1473 | |
|---|
| 1474 | |
|---|
| 1475 | |
|---|
| 1476 | |
|---|
| 1477 | |
|---|
| 1478 | |
|---|
| 1479 | |
|---|
| 1480 | |
|---|
| 1481 | |
|---|
| 1482 | |
|---|
| 1483 | |
|---|
| 1484 | |
|---|
| 1485 | def replaceInFiles(self,_text,_replaceText,_filters,_directory,_mode=ALL_IN_FILES): |
|---|
| 1486 | |
|---|
| 1487 | message="About to replace all occurences of <b>\"%s\"</b> <br> in ALL <b>\"%s\"</b> files inside directory:<br> %s <br> Proceed?"%(_text,_filters,_directory) |
|---|
| 1488 | ret = QtGui.QMessageBox.warning(self, "Replace in Files", |
|---|
| 1489 | message, |
|---|
| 1490 | QtGui.QMessageBox.Ok |QtGui.QMessageBox.Cancel) |
|---|
| 1491 | if ret == QtGui.QMessageBox.Cancel: |
|---|
| 1492 | return |
|---|
| 1493 | |
|---|
| 1494 | |
|---|
| 1495 | reFlag=False |
|---|
| 1496 | |
|---|
| 1497 | if str(self.findDialogForm.syntaxComboBoxIF.currentText())=="Regular expression": |
|---|
| 1498 | reFlag=True |
|---|
| 1499 | |
|---|
| 1500 | newSearchFlag=self.findAndReplaceHistory.newReplaceParametersIF(_text,_replaceText,_filters,_directory) |
|---|
| 1501 | self.findDialogForm.initializeAllSearchLists(self.findAndReplaceHistory) |
|---|
| 1502 | |
|---|
| 1503 | |
|---|
| 1504 | |
|---|
| 1505 | |
|---|
| 1506 | |
|---|
| 1507 | |
|---|
| 1508 | |
|---|
| 1509 | |
|---|
| 1510 | |
|---|
| 1511 | |
|---|
| 1512 | |
|---|
| 1513 | |
|---|
| 1514 | |
|---|
| 1515 | |
|---|
| 1516 | |
|---|
| 1517 | import fnmatch |
|---|
| 1518 | import os |
|---|
| 1519 | filters=str(_filters).split() |
|---|
| 1520 | dbgMsg(filters) |
|---|
| 1521 | |
|---|
| 1522 | matches = [] |
|---|
| 1523 | if _mode==ALL_IN_FILES: |
|---|
| 1524 | for filter in filters: |
|---|
| 1525 | if self.findDialogForm.inAllSubFoldersCheckBoxIF.isChecked(): |
|---|
| 1526 | for root, dirnames, filenames in os.walk(str(_directory)): |
|---|
| 1527 | for filename in fnmatch.filter(filenames, filter): |
|---|
| 1528 | matches.append(os.path.join(root, filename)) |
|---|
| 1529 | else: |
|---|
| 1530 | root=str(_directory) |
|---|
| 1531 | for filename in os.listdir(root): |
|---|
| 1532 | if fnmatch.fnmatch(filename, filter): |
|---|
| 1533 | matches.append(os.path.join(root, filename)) |
|---|
| 1534 | |
|---|
| 1535 | |
|---|
| 1536 | |
|---|
| 1537 | |
|---|
| 1538 | |
|---|
| 1539 | replaceInFilesData=[] |
|---|
| 1540 | |
|---|
| 1541 | if _mode==ALL_IN_FILES: |
|---|
| 1542 | replaceInFilesData=self.processReplaceInFiles(matches,_text,_replaceText,reFlag) |
|---|
| 1543 | elif _mode==ALL_IN_ALL_OPEN_DOCS: |
|---|
| 1544 | replaceInFilesData=self.processReplaceInAllOpenDocs(_text,_replaceText,reFlag) |
|---|
| 1545 | else: |
|---|
| 1546 | return |
|---|
| 1547 | |
|---|
| 1548 | try: |
|---|
| 1549 | message="Replaced %s occurences of \"<b>%s</b>\" in %s files"%(str(replaceInFilesData[0]),_text,str(replaceInFilesData[1])) |
|---|
| 1550 | ret = QtGui.QMessageBox.information(self, "Replace in Files", |
|---|
| 1551 | message, |
|---|
| 1552 | QtGui.QMessageBox.Ok ) |
|---|
| 1553 | |
|---|
| 1554 | except IndexError: |
|---|
| 1555 | pass |
|---|
| 1556 | |
|---|
| 1557 | |
|---|
| 1558 | |
|---|
| 1559 | |
|---|
| 1560 | |
|---|
| 1561 | |
|---|
| 1562 | |
|---|
| 1563 | |
|---|
| 1564 | |
|---|
| 1565 | |
|---|
| 1566 | def processReplaceInAllOpenDocs(self,_text,_replaceText,_reFlag): |
|---|
| 1567 | |
|---|
| 1568 | replaceInFilesData = [] |
|---|
| 1569 | |
|---|
| 1570 | fileCounter=0 |
|---|
| 1571 | substitutionCounter=0 |
|---|
| 1572 | |
|---|
| 1573 | |
|---|
| 1574 | editorList=self.getEditorList() |
|---|
| 1575 | |
|---|
| 1576 | for editor in editorList: |
|---|
| 1577 | currentLine,currentIndex = editor.getCursorPosition() |
|---|
| 1578 | filename=self.getEditorFileName(editor) |
|---|
| 1579 | if filename=='': |
|---|
| 1580 | continue |
|---|
| 1581 | |
|---|
| 1582 | foundFlag=editor.findFirst(_text,_reFlag,\ |
|---|
| 1583 | self.findDialogForm.caseCheckBox.isChecked(),\ |
|---|
| 1584 | self.findDialogForm.wholeCheckBox.isChecked(),\ |
|---|
| 1585 | False,\ |
|---|
| 1586 | True,0,0,False) |
|---|
| 1587 | |
|---|
| 1588 | newFileCountedFlag=False |
|---|
| 1589 | |
|---|
| 1590 | editor.beginUndoAction() |
|---|
| 1591 | |
|---|
| 1592 | |
|---|
| 1593 | while foundFlag: |
|---|
| 1594 | line,index=editor.getCursorPosition() |
|---|
| 1595 | |
|---|
| 1596 | |
|---|
| 1597 | editor.replace(_replaceText) |
|---|
| 1598 | |
|---|
| 1599 | if not newFileCountedFlag: |
|---|
| 1600 | fileCounter+=1 |
|---|
| 1601 | newFileCountedFlag=True |
|---|
| 1602 | substitutionCounter+=1 |
|---|
| 1603 | foundFlag=editor.findFirst(_text,_reFlag,\ |
|---|
| 1604 | self.findDialogForm.caseCheckBox.isChecked(),\ |
|---|
| 1605 | self.findDialogForm.wholeCheckBox.isChecked(),\ |
|---|
| 1606 | False) |
|---|
| 1607 | |
|---|
| 1608 | editor.endUndoAction() |
|---|
| 1609 | editor.setCursorPosition(currentLine,currentIndex) |
|---|
| 1610 | |
|---|
| 1611 | replaceInFilesData=[substitutionCounter,fileCounter] |
|---|
| 1612 | return replaceInFilesData |
|---|
| 1613 | |
|---|
| 1614 | |
|---|
| 1615 | def processReplaceInFiles(self, _files, _text,_replaceText,_reFlag=False): |
|---|
| 1616 | |
|---|
| 1617 | |
|---|
| 1618 | progressDialog = QtGui.QProgressDialog(self) |
|---|
| 1619 | |
|---|
| 1620 | progressDialog.setCancelButtonText("&Cancel") |
|---|
| 1621 | numberOfFiles=len(_files) |
|---|
| 1622 | progressDialog.setRange(0, numberOfFiles) |
|---|
| 1623 | progressDialog.setWindowTitle("Replacing Text in Files") |
|---|
| 1624 | |
|---|
| 1625 | replaceInFilesData = [] |
|---|
| 1626 | i=1 |
|---|
| 1627 | |
|---|
| 1628 | openFileDict=self.getFileNameToEditorWidgetMap() |
|---|
| 1629 | |
|---|
| 1630 | |
|---|
| 1631 | |
|---|
| 1632 | |
|---|
| 1633 | |
|---|
| 1634 | |
|---|
| 1635 | fileCounter=0 |
|---|
| 1636 | substitutionCounter=0 |
|---|
| 1637 | |
|---|
| 1638 | for filename in _files: |
|---|
| 1639 | |
|---|
| 1640 | progressDialog.setValue(i) |
|---|
| 1641 | progressDialog.setLabelText("Searching file number %d of %d..." % (i, numberOfFiles)) |
|---|
| 1642 | QtGui.qApp.processEvents() |
|---|
| 1643 | |
|---|
| 1644 | if progressDialog.wasCanceled(): |
|---|
| 1645 | break |
|---|
| 1646 | |
|---|
| 1647 | textEditLocal=None |
|---|
| 1648 | |
|---|
| 1649 | usingOpenEditor=False |
|---|
| 1650 | openFileForReplaceFlag=False |
|---|
| 1651 | |
|---|
| 1652 | fileNameNormalized=os.path.abspath(filename) |
|---|
| 1653 | |
|---|
| 1654 | if fileNameNormalized in openFileDict.keys(): |
|---|
| 1655 | |
|---|
| 1656 | textEditLocal=openFileDict[fileNameNormalized] |
|---|
| 1657 | textEditLocal.setCursorPosition(0,0) |
|---|
| 1658 | |
|---|
| 1659 | |
|---|
| 1660 | |
|---|
| 1661 | usingOpenEditor=True |
|---|
| 1662 | else: |
|---|
| 1663 | |
|---|
| 1664 | |
|---|
| 1665 | inFile = QtCore.QFile(filename) |
|---|
| 1666 | if not inFile.open(QtCore.QIODevice.ReadWrite): |
|---|
| 1667 | continue |
|---|
| 1668 | stream = QtCore.QTextStream(inFile) |
|---|
| 1669 | textEditLocal=QsciScintillaCustom() |
|---|
| 1670 | textEditLocal.setText(stream.readAll()) |
|---|
| 1671 | |
|---|
| 1672 | |
|---|
| 1673 | |
|---|
| 1674 | |
|---|
| 1675 | |
|---|
| 1676 | |
|---|
| 1677 | |
|---|
| 1678 | |
|---|
| 1679 | |
|---|
| 1680 | |
|---|
| 1681 | |
|---|
| 1682 | |
|---|
| 1683 | |
|---|
| 1684 | foundFlag=textEditLocal.findFirst(_text,_reFlag,\ |
|---|
| 1685 | self.findDialogForm.caseCheckBoxIF.isChecked(),\ |
|---|
| 1686 | self.findDialogForm.wholeCheckBoxIF.isChecked(),\ |
|---|
| 1687 | False,\ |
|---|
| 1688 | True,0,0,False) |
|---|
| 1689 | findResults=None |
|---|
| 1690 | |
|---|
| 1691 | |
|---|
| 1692 | |
|---|
| 1693 | |
|---|
| 1694 | newFileCountedFlag=False |
|---|
| 1695 | if usingOpenEditor: |
|---|
| 1696 | textEditLocal.beginUndoAction() |
|---|
| 1697 | |
|---|
| 1698 | |
|---|
| 1699 | while foundFlag: |
|---|
| 1700 | line,index=textEditLocal.getCursorPosition() |
|---|
| 1701 | |
|---|
| 1702 | |
|---|
| 1703 | textEditLocal.replace(_replaceText) |
|---|
| 1704 | |
|---|
| 1705 | if not newFileCountedFlag: |
|---|
| 1706 | fileCounter+=1 |
|---|
| 1707 | newFileCountedFlag=True |
|---|
| 1708 | substitutionCounter+=1 |
|---|
| 1709 | foundFlag=textEditLocal.findFirst(_text,_reFlag,\ |
|---|
| 1710 | self.findDialogForm.caseCheckBoxIF.isChecked(),\ |
|---|
| 1711 | self.findDialogForm.wholeCheckBoxIF.isChecked(),\ |
|---|
| 1712 | False) |
|---|
| 1713 | |
|---|
| 1714 | |
|---|
| 1715 | |
|---|
| 1716 | |
|---|
| 1717 | |
|---|
| 1718 | if usingOpenEditor: |
|---|
| 1719 | textEditLocal.endUndoAction() |
|---|
| 1720 | |
|---|
| 1721 | if newFileCountedFlag: |
|---|
| 1722 | self.saveFile(filename,textEditLocal) |
|---|
| 1723 | |
|---|
| 1724 | textEditLocal.modificationChanged.disconnect(self.textChangedHandlers[textEditLocal].handleModificationChanged) |
|---|
| 1725 | |
|---|
| 1726 | self.setEditorFileModificationTime(textEditLocal,os.path.getmtime(filename)) |
|---|
| 1727 | |
|---|
| 1728 | |
|---|
| 1729 | textEditLocal.modificationChanged.connect(self.textChangedHandlers[textEditLocal].handleModificationChanged) |
|---|
| 1730 | |
|---|
| 1731 | |
|---|
| 1732 | else: |
|---|
| 1733 | |
|---|
| 1734 | inFile.close() |
|---|
| 1735 | |
|---|
| 1736 | if newFileCountedFlag and inFile.open(QtCore.QIODevice.WriteOnly): |
|---|
| 1737 | outf = QtCore.QTextStream(inFile) |
|---|
| 1738 | outf << textEditLocal.text() |
|---|
| 1739 | |
|---|
| 1740 | i+=1 |
|---|
| 1741 | |
|---|
| 1742 | progressDialog.close() |
|---|
| 1743 | |
|---|
| 1744 | replaceInFilesData=[substitutionCounter,fileCounter] |
|---|
| 1745 | return replaceInFilesData |
|---|
| 1746 | |
|---|
| 1747 | def findNext(self,_text): |
|---|
| 1748 | |
|---|
| 1749 | editor=self.editTab.currentWidget() |
|---|
| 1750 | |
|---|
| 1751 | reFlag=False |
|---|
| 1752 | |
|---|
| 1753 | if str(self.findDialogForm.syntaxComboBox.currentText())=="Regular expression": |
|---|
| 1754 | reFlag=True |
|---|
| 1755 | |
|---|
| 1756 | dbgMsg("RE FLAG:=",reFlag) |
|---|
| 1757 | |
|---|
| 1758 | |
|---|
| 1759 | |
|---|
| 1760 | newSearchFlag=self.findAndReplaceHistory.newSearchParameters(_text,reFlag,self.findDialogForm.caseCheckBox.isChecked(),self.findDialogForm.wholeCheckBox.isChecked(),True,self.findDialogForm.inSelectionBox.isChecked()) |
|---|
| 1761 | dbgMsg("self.findDialogForm.wholeCheckBox.isChecked()=",self.findDialogForm.wholeCheckBox.isChecked()) |
|---|
| 1762 | self.findDialogForm.initializeSearchLists(self.findAndReplaceHistory) |
|---|
| 1763 | |
|---|
| 1764 | |
|---|
| 1765 | |
|---|
| 1766 | |
|---|
| 1767 | |
|---|
| 1768 | dbgMsg("self.findAndReplaceHistory.re:=",self.findAndReplaceHistory.re) |
|---|
| 1769 | |
|---|
| 1770 | if newSearchFlag: |
|---|
| 1771 | foundFlag=editor.findFirst(self.findAndReplaceHistory.textToFind,self.findAndReplaceHistory.re,self.findAndReplaceHistory.cs,self.findAndReplaceHistory.wo,self.findAndReplaceHistory.wrap) |
|---|
| 1772 | dbgMsg("foundFlag=",foundFlag) |
|---|
| 1773 | |
|---|
| 1774 | else: |
|---|
| 1775 | |
|---|
| 1776 | editor.findNext() |
|---|
| 1777 | |
|---|
| 1778 | |
|---|
| 1779 | |
|---|
| 1780 | |
|---|
| 1781 | |
|---|
| 1782 | |
|---|
| 1783 | def findNextSimple(self): |
|---|
| 1784 | editor=self.editTab.currentWidget() |
|---|
| 1785 | editor.findNext() |
|---|
| 1786 | |
|---|
| 1787 | def replaceNext(self,_text,_replaceText): |
|---|
| 1788 | |
|---|
| 1789 | editor=self.editTab.currentWidget() |
|---|
| 1790 | |
|---|
| 1791 | |
|---|
| 1792 | |
|---|
| 1793 | reFlag=False |
|---|
| 1794 | inSelectionFlag=self.findDialogForm.inSelectionBox.isChecked() |
|---|
| 1795 | |
|---|
| 1796 | if str(self.findDialogForm.syntaxComboBox.currentText())=="Regular expression": |
|---|
| 1797 | reFlag=True |
|---|
| 1798 | |
|---|
| 1799 | |
|---|
| 1800 | |
|---|
| 1801 | newReplaceFlag=self.findAndReplaceHistory.newReplaceParameters(_text,_replaceText,reFlag,self.findDialogForm.caseCheckBox.isChecked(),self.findDialogForm.wholeCheckBox.isChecked(),True,inSelectionFlag) |
|---|
| 1802 | |
|---|
| 1803 | self.findDialogForm.initializeSearchLists(self.findAndReplaceHistory) |
|---|
| 1804 | |
|---|
| 1805 | |
|---|
| 1806 | |
|---|
| 1807 | |
|---|
| 1808 | if newReplaceFlag: |
|---|
| 1809 | editor.findFirst(self.findAndReplaceHistory.textToFind,self.findAndReplaceHistory.re,self.findAndReplaceHistory.cs,self.findAndReplaceHistory.wo,False) |
|---|
| 1810 | |
|---|
| 1811 | |
|---|
| 1812 | editor.replace(self.findAndReplaceHistory.replaceText) |
|---|
| 1813 | |
|---|
| 1814 | |
|---|
| 1815 | else: |
|---|
| 1816 | |
|---|
| 1817 | |
|---|
| 1818 | |
|---|
| 1819 | |
|---|
| 1820 | editor.findFirst(self.findAndReplaceHistory.textToFind,self.findAndReplaceHistory.re,self.findAndReplaceHistory.cs,self.findAndReplaceHistory.wo,False) |
|---|
| 1821 | |
|---|
| 1822 | |
|---|
| 1823 | |
|---|
| 1824 | editor.replace(self.findAndReplaceHistory.replaceText) |
|---|
| 1825 | |
|---|
| 1826 | |
|---|
| 1827 | |
|---|
| 1828 | def replaceAll(self,_text,_replaceText,_inSelectionFlag): |
|---|
| 1829 | |
|---|
| 1830 | editor=self.editTab.currentWidget() |
|---|
| 1831 | |
|---|
| 1832 | reFlag=False |
|---|
| 1833 | inSelectionFlag=_inSelectionFlag |
|---|
| 1834 | |
|---|
| 1835 | if str(self.findDialogForm.syntaxComboBox.currentText())=="Regular expression": |
|---|
| 1836 | reFlag=True |
|---|
| 1837 | |
|---|
| 1838 | newReplaceFlag=self.findAndReplaceHistory.newReplaceParameters(_text,_replaceText,reFlag,self.findDialogForm.caseCheckBox.isChecked(),self.findDialogForm.wholeCheckBox.isChecked(),True,inSelectionFlag) |
|---|
| 1839 | |
|---|
| 1840 | self.findDialogForm.initializeSearchLists(self.findAndReplaceHistory) |
|---|
| 1841 | |
|---|
| 1842 | substitutionCounter=0 |
|---|
| 1843 | |
|---|
| 1844 | if inSelectionFlag and editor.hasSelectedText(): |
|---|
| 1845 | |
|---|
| 1846 | line_before, index_before = editor.getCursorPosition() |
|---|
| 1847 | line_from, index_from, line_to, index_to = editor.getSelection() |
|---|
| 1848 | |
|---|
| 1849 | |
|---|
| 1850 | |
|---|
| 1851 | foundFlag=editor.findFirst(self.findAndReplaceHistory.textToFind,\ |
|---|
| 1852 | self.findAndReplaceHistory.re,\ |
|---|
| 1853 | self.findAndReplaceHistory.cs,\ |
|---|
| 1854 | self.findAndReplaceHistory.wo,\ |
|---|
| 1855 | False,\ |
|---|
| 1856 | True,line_from,index_from,False) |
|---|
| 1857 | |
|---|
| 1858 | line, index = editor.getCursorPosition() |
|---|
| 1859 | |
|---|
| 1860 | editor.beginUndoAction() |
|---|
| 1861 | while foundFlag and (line<line_to or (line==line_to and index<=index_to)) : |
|---|
| 1862 | |
|---|
| 1863 | editor.replace(self.findAndReplaceHistory.replaceText) |
|---|
| 1864 | substitutionCounter+=1 |
|---|
| 1865 | |
|---|
| 1866 | foundFlag=editor.findFirst(self.findAndReplaceHistory.textToFind,\ |
|---|
| 1867 | self.findAndReplaceHistory.re,\ |
|---|
| 1868 | self.findAndReplaceHistory.cs,\ |
|---|
| 1869 | self.findAndReplaceHistory.wo,\ |
|---|
| 1870 | False) |
|---|
| 1871 | |
|---|
| 1872 | line, index = editor.getCursorPosition() |
|---|
| 1873 | editor.endUndoAction() |
|---|
| 1874 | |
|---|
| 1875 | editor.setCursorPosition(line_before, index_before) |
|---|
| 1876 | elif not inSelectionFlag: |
|---|
| 1877 | |
|---|
| 1878 | line_from=0 |
|---|
| 1879 | index_from=0 |
|---|
| 1880 | line_before, index_before = editor.getCursorPosition() |
|---|
| 1881 | foundFlag=editor.findFirst(self.findAndReplaceHistory.textToFind,\ |
|---|
| 1882 | self.findAndReplaceHistory.re,\ |
|---|
| 1883 | self.findAndReplaceHistory.cs,\ |
|---|
| 1884 | self.findAndReplaceHistory.wo,\ |
|---|
| 1885 | False,\ |
|---|
| 1886 | True,line_from,index_from,False) |
|---|
| 1887 | editor.beginUndoAction() |
|---|
| 1888 | |
|---|
| 1889 | |
|---|
| 1890 | while foundFlag: |
|---|
| 1891 | |
|---|
| 1892 | editor.replace(self.findAndReplaceHistory.replaceText) |
|---|
| 1893 | substitutionCounter+=1 |
|---|
| 1894 | foundFlag=editor.findFirst(self.findAndReplaceHistory.textToFind,\ |
|---|
| 1895 | self.findAndReplaceHistory.re,\ |
|---|
| 1896 | self.findAndReplaceHistory.cs,\ |
|---|
| 1897 | self.findAndReplaceHistory.wo,\ |
|---|
| 1898 | False) |
|---|
| 1899 | |
|---|
| 1900 | |
|---|
| 1901 | |
|---|
| 1902 | |
|---|
| 1903 | |
|---|
| 1904 | |
|---|
| 1905 | |
|---|
| 1906 | |
|---|
| 1907 | |
|---|
| 1908 | editor.endUndoAction() |
|---|
| 1909 | |
|---|
| 1910 | editor.setCursorPosition(line_before, index_before) |
|---|
| 1911 | |
|---|
| 1912 | |
|---|
| 1913 | message="Replaced %s occurences of \"<b>%s</b>\""%(str(substitutionCounter),_text) |
|---|
| 1914 | ret = QtGui.QMessageBox.information(self, "Replace in Files", |
|---|
| 1915 | message, |
|---|
| 1916 | QtGui.QMessageBox.Ok ) |
|---|
| 1917 | |
|---|
| 1918 | |
|---|
| 1919 | |
|---|
| 1920 | def marginClickedHandler(self,_margin,_line,_keyboardState): |
|---|
| 1921 | editor=self.editTab.currentWidget() |
|---|
| 1922 | if _margin==1: |
|---|
| 1923 | if editor.markersAtLine(_line)!=self.bookmarkMask: |
|---|
| 1924 | marker=editor.markerAdd(_line,self.lineBookmark) |
|---|
| 1925 | else: |
|---|
| 1926 | editor.markerDelete(_line) |
|---|
| 1927 | |
|---|
| 1928 | |
|---|
| 1929 | def toggleBookmark(self): |
|---|
| 1930 | |
|---|
| 1931 | editor=self.editTab.currentWidget() |
|---|
| 1932 | line, index = editor.getCursorPosition() |
|---|
| 1933 | |
|---|
| 1934 | |
|---|
| 1935 | |
|---|
| 1936 | if editor.markersAtLine(line)!=self.bookmarkMask: |
|---|
| 1937 | |
|---|
| 1938 | |
|---|
| 1939 | marker=editor.markerAdd(line,self.lineBookmark) |
|---|
| 1940 | |
|---|
| 1941 | |
|---|
| 1942 | |
|---|
| 1943 | |
|---|
| 1944 | |
|---|
| 1945 | else: |
|---|
| 1946 | |
|---|
| 1947 | editor.markerDelete(line) |
|---|
| 1948 | |
|---|
| 1949 | |
|---|
| 1950 | |
|---|
| 1951 | def goToNextBookmark(self): |
|---|
| 1952 | |
|---|
| 1953 | editor=self.editTab.currentWidget() |
|---|
| 1954 | line, index = editor.getCursorPosition() |
|---|
| 1955 | |
|---|
| 1956 | lineNext=editor.markerFindNext(line,self.bookmarkMask) |
|---|
| 1957 | |
|---|
| 1958 | |
|---|
| 1959 | if lineNext==line: |
|---|
| 1960 | lineNext=editor.markerFindNext(line+1,self.bookmarkMask) |
|---|
| 1961 | |
|---|
| 1962 | if lineNext==-1: |
|---|
| 1963 | lineNext=editor.markerFindNext(0,self.bookmarkMask) |
|---|
| 1964 | if lineNext==-1: |
|---|
| 1965 | return |
|---|
| 1966 | |
|---|
| 1967 | if lineNext!=line and lineNext!=-1: |
|---|
| 1968 | editor.setCursorPosition(lineNext,0) |
|---|
| 1969 | return |
|---|
| 1970 | |
|---|
| 1971 | |
|---|
| 1972 | def goToPreviousBookmark(self): |
|---|
| 1973 | |
|---|
| 1974 | editor=self.editTab.currentWidget() |
|---|
| 1975 | line, index = editor.getCursorPosition() |
|---|
| 1976 | |
|---|
| 1977 | linePrevious=editor.markerFindPrevious(line,self.bookmarkMask) |
|---|
| 1978 | |
|---|
| 1979 | |
|---|
| 1980 | if linePrevious==line: |
|---|
| 1981 | linePrevious=editor.markerFindPrevious(line-1,self.bookmarkMask) |
|---|
| 1982 | |
|---|
| 1983 | if linePrevious==-1: |
|---|
| 1984 | linePrevious=editor.markerFindPrevious(editor.lines(),self.bookmarkMask) |
|---|
| 1985 | if linePrevious==-1: |
|---|
| 1986 | return |
|---|
| 1987 | |
|---|
| 1988 | if linePrevious!=line and linePrevious!=-1: |
|---|
| 1989 | editor.setCursorPosition(linePrevious,0) |
|---|
| 1990 | return |
|---|
| 1991 | |
|---|
| 1992 | def deleteAllBookmarks(self): |
|---|
| 1993 | editor=self.editTab.currentWidget() |
|---|
| 1994 | editor.markerDeleteAll(self.lineBookmark) |
|---|
| 1995 | |
|---|
| 1996 | def goToLineShow(self,_line): |
|---|
| 1997 | editor=self.editTab.currentWidget() |
|---|
| 1998 | self.goToLineDlg=GoToLineDlg(editor,self) |
|---|
| 1999 | self.goToLineDlg.show() |
|---|
| 2000 | |
|---|
| 2001 | def goToLine(self,_line): |
|---|
| 2002 | dbgMsg("GO TO LINE SLOT = ",_line) |
|---|
| 2003 | editor=self.editTab.currentWidget() |
|---|
| 2004 | editor.setCursorPosition(_line-1,0) |
|---|
| 2005 | |
|---|
| 2006 | |
|---|
| 2007 | |
|---|
| 2008 | def goToMatchingBrace(self): |
|---|
| 2009 | editor=self.editTab.currentWidget() |
|---|
| 2010 | editor.moveToMatchingBrace() |
|---|
| 2011 | |
|---|
| 2012 | def selectToMatchingBrace(self): |
|---|
| 2013 | |
|---|
| 2014 | editor=self.editTab.currentWidget() |
|---|
| 2015 | editor.selectToMatchingBrace() |
|---|
| 2016 | |
|---|
| 2017 | def configurationUpdate(self): |
|---|
| 2018 | |
|---|
| 2019 | editor=self.editTab.currentWidget() |
|---|
| 2020 | configurationDlg= ConfigurationDlg(editor,self) |
|---|
| 2021 | if configurationDlg.exec_(): |
|---|
| 2022 | for key in self.configuration.updatedConfigs.keys(): |
|---|
| 2023 | dbgMsg("NEW SETTING = ",key,":",self.configuration.updatedConfigs[key]) |
|---|
| 2024 | configureFcn=getattr(self,"configure"+key) |
|---|
| 2025 | configureFcn(self.configuration.updatedConfigs[key]) |
|---|
| 2026 | |
|---|
| 2027 | |
|---|
| 2028 | |
|---|
| 2029 | |
|---|
| 2030 | |
|---|
| 2031 | |
|---|
| 2032 | |
|---|
| 2033 | def configureUseTabSpaces(self,_flag): |
|---|
| 2034 | numberOfDocuments=self.editTab.count() |
|---|
| 2035 | for i in range(numberOfDocuments): |
|---|
| 2036 | self.editTab.widget(i).setIndentationsUseTabs( not _flag) |
|---|
| 2037 | if _flag: |
|---|
| 2038 | self.editTab.widget(i).setIndentationWidth(self.configuration.setting("TabSpaces")) |
|---|
| 2039 | else: |
|---|
| 2040 | self.editTab.widget(i).setIndentationWidth(0) |
|---|
| 2041 | |
|---|
| 2042 | |
|---|
| 2043 | |
|---|
| 2044 | def configureFoldText(self,_flag): |
|---|
| 2045 | numberOfDocuments=self.editTab.count() |
|---|
| 2046 | for i in range(numberOfDocuments): |
|---|
| 2047 | if _flag: |
|---|
| 2048 | self.editTab.widget(i).setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 2049 | else: |
|---|
| 2050 | self.editTab.widget(i).setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 2051 | |
|---|
| 2052 | def configureDisplayWhitespace(self,_flag): |
|---|
| 2053 | numberOfDocuments=self.editTab.count() |
|---|
| 2054 | for i in range(numberOfDocuments): |
|---|
| 2055 | if _flag: |
|---|
| 2056 | self.editTab.widget(i).setWhitespaceVisibility(QsciScintilla.SCWS_VISIBLEALWAYS) |
|---|
| 2057 | else: |
|---|
| 2058 | self.editTab.widget(i).setWhitespaceVisibility(QsciScintilla.SCWS_INVISIBLE) |
|---|
| 2059 | |
|---|
| 2060 | def configureDisplayEOL(self,_flag): |
|---|
| 2061 | numberOfDocuments=self.editTab.count() |
|---|
| 2062 | for i in range(numberOfDocuments): |
|---|
| 2063 | self.editTab.widget(i).setEolVisibility(_flag) |
|---|
| 2064 | |
|---|
| 2065 | def configureWrapLines(self,_flag): |
|---|
| 2066 | numberOfDocuments=self.editTab.count() |
|---|
| 2067 | for i in range(numberOfDocuments): |
|---|
| 2068 | if _flag: |
|---|
| 2069 | self.editTab.widget(i).setWrapMode(QsciScintilla.WrapWord) |
|---|
| 2070 | else: |
|---|
| 2071 | self.editTab.widget(i).setWrapMode(QsciScintilla.WrapNone) |
|---|
| 2072 | |
|---|
| 2073 | def configureShowWrapSymbol(self,_flag): |
|---|
| 2074 | numberOfDocuments=self.editTab.count() |
|---|
| 2075 | for i in range(numberOfDocuments): |
|---|
| 2076 | if _flag: |
|---|
| 2077 | self.editTab.widget(i).setWrapVisualFlags(QsciScintilla.WrapFlagByText) |
|---|
| 2078 | else: |
|---|
| 2079 | self.editTab.widget(i).setWrapVisualFlags(QsciScintilla.WrapFlagNone) |
|---|
| 2080 | |
|---|
| 2081 | |
|---|
| 2082 | |
|---|
| 2083 | def configureTabGuidelines(self,_flag): |
|---|
| 2084 | numberOfDocuments=self.editTab.count() |
|---|
| 2085 | for i in range(numberOfDocuments): |
|---|
| 2086 | self.editTab.widget(i).setIndentationGuides(_flag) |
|---|
| 2087 | |
|---|
| 2088 | def configureDisplayLineNumbers(self,_flag): |
|---|
| 2089 | numberOfDocuments=self.editTab.count() |
|---|
| 2090 | for i in range(numberOfDocuments): |
|---|
| 2091 | self.editTab.widget(i).setMarginLineNumbers(1,_flag) |
|---|
| 2092 | |
|---|
| 2093 | |
|---|
| 2094 | def newFile(self): |
|---|
| 2095 | |
|---|
| 2096 | textEditLocal = QsciScintillaCustom() |
|---|
| 2097 | textEditLocal.clear() |
|---|
| 2098 | self.editTab.addTab(textEditLocal,QtGui.QIcon(':/icons/document-clean.png'),"New Document "+str(self.editTab.count()+1)) |
|---|
| 2099 | self.editTab.setCurrentWidget(textEditLocal) |
|---|
| 2100 | |
|---|
| 2101 | self.setCurrentFile('') |
|---|
| 2102 | self.setEditorProperties(textEditLocal) |
|---|
| 2103 | self.commentStyleDict[self.editTab.currentWidget()]=['',''] |
|---|
| 2104 | |
|---|
| 2105 | self.setPropertiesInEditorList(self.editTab.currentWidget(),'',0,'utf-8') |
|---|
| 2106 | |
|---|
| 2107 | |
|---|
| 2108 | |
|---|
| 2109 | self.textChangedHandlers[textEditLocal]=ChangedTextHandler(textEditLocal,self) |
|---|
| 2110 | editorIndex=self.editTab.indexOf(textEditLocal) |
|---|
| 2111 | |
|---|
| 2112 | |
|---|
| 2113 | self.editTab.widget(editorIndex).modificationChanged.connect(self.textChangedHandlers[textEditLocal].handleModificationChanged) |
|---|
| 2114 | self.editTab.widget(editorIndex).textChanged.connect(self.textChangedHandlers[textEditLocal].handleChangedText) |
|---|
| 2115 | self.editTab.widget(editorIndex).cursorPositionChanged.connect(self.handleCursorPositionChanged) |
|---|
| 2116 | |
|---|
| 2117 | |
|---|
| 2118 | |
|---|
| 2119 | |
|---|
| 2120 | def open(self): |
|---|
| 2121 | |
|---|
| 2122 | |
|---|
| 2123 | dbgMsg("INSIDE OPEN") |
|---|
| 2124 | currentFilePath=None |
|---|
| 2125 | try: |
|---|
| 2126 | |
|---|
| 2127 | currentFilePath=self.getEditorFileName(self.editTab.currentWidget()) |
|---|
| 2128 | except KeyError: |
|---|
| 2129 | |
|---|
| 2130 | pass |
|---|
| 2131 | |
|---|
| 2132 | if currentFilePath: |
|---|
| 2133 | currentFilePath=os.path.dirname(str(currentFilePath)) |
|---|
| 2134 | self.lastFileOpenPath=currentFilePath |
|---|
| 2135 | else: |
|---|
| 2136 | currentFilePath=self.lastFileOpenPath |
|---|
| 2137 | |
|---|
| 2138 | dbgMsg("THIS IS CURRENT PATH=",currentFilePath) |
|---|
| 2139 | fileNames = QtGui.QFileDialog.getOpenFileNames(self,"Open new file...",currentFilePath,self.fileDialogFilters) |
|---|
| 2140 | if fileNames.count(): |
|---|
| 2141 | self.loadFiles(fileNames) |
|---|
| 2142 | |
|---|
| 2143 | def closeTabIndex(self, index): |
|---|
| 2144 | self.closeTab(index) |
|---|
| 2145 | |
|---|
| 2146 | def closeTab(self, index=None): |
|---|
| 2147 | dbgMsg("closing tab ",index) |
|---|
| 2148 | textEditLocal=None |
|---|
| 2149 | if index is not None and not isinstance(index, bool) : |
|---|
| 2150 | textEditLocal=self.editTab.widget(index) |
|---|
| 2151 | else: |
|---|
| 2152 | textEditLocal= self.editTab.currentWidget() |
|---|
| 2153 | |
|---|
| 2154 | |
|---|
| 2155 | |
|---|
| 2156 | |
|---|
| 2157 | self.maybeSave() |
|---|
| 2158 | |
|---|
| 2159 | if self.editTab.count()==1: |
|---|
| 2160 | self.editTab.currentWidget().clear() |
|---|
| 2161 | self.editTab.currentWidget().setModified(False) |
|---|
| 2162 | self.editTab.setTabText(0,'Empty Document') |
|---|
| 2163 | self.setCurrentFile('') |
|---|
| 2164 | self.commentStyleDict[self.editTab.currentWidget()]=['',''] |
|---|
| 2165 | if self.editTab.currentWidget() in self.getEditorList(): |
|---|
| 2166 | |
|---|
| 2167 | self.removeEditor(self.editTab.currentWidget()) |
|---|
| 2168 | |
|---|
| 2169 | self.editTab.setTabIcon(0,QtGui.QIcon(':/icons/document-clean.png') ) |
|---|
| 2170 | else: |
|---|
| 2171 | self.editTab.removeTab( self.editTab.indexOf(textEditLocal)) |
|---|
| 2172 | del self.commentStyleDict[textEditLocal] |
|---|
| 2173 | self.removeEditor(textEditLocal) |
|---|
| 2174 | |
|---|
| 2175 | |
|---|
| 2176 | if self.editTab.currentWidget() in self.textChangedHandlers: |
|---|
| 2177 | del self.textChangedHandlers[textEditLocal] |
|---|
| 2178 | |
|---|
| 2179 | def foldAll(self): |
|---|
| 2180 | editor= self.editTab.currentWidget() |
|---|
| 2181 | editor.foldAll(True) |
|---|
| 2182 | |
|---|
| 2183 | |
|---|
| 2184 | def zoomIn(self): |
|---|
| 2185 | |
|---|
| 2186 | self.zoomRange+=1 |
|---|
| 2187 | self.configuration.setSetting("ZoomRange",self.zoomRange) |
|---|
| 2188 | for editor in self.getEditorList(): |
|---|
| 2189 | editor.zoomIn() |
|---|
| 2190 | |
|---|
| 2191 | |
|---|
| 2192 | |
|---|
| 2193 | |
|---|
| 2194 | |
|---|
| 2195 | |
|---|
| 2196 | def zoomOut(self): |
|---|
| 2197 | self.zoomRange-=1 |
|---|
| 2198 | self.configuration.setSetting("ZoomRange",self.zoomRange) |
|---|
| 2199 | for editor in self.getEditorList(): |
|---|
| 2200 | editor.zoomOut() |
|---|
| 2201 | |
|---|
| 2202 | |
|---|
| 2203 | |
|---|
| 2204 | |
|---|
| 2205 | |
|---|
| 2206 | |
|---|
| 2207 | |
|---|
| 2208 | |
|---|
| 2209 | |
|---|
| 2210 | |
|---|
| 2211 | def save(self): |
|---|
| 2212 | |
|---|
| 2213 | editor=self.editTab.currentWidget() |
|---|
| 2214 | fileName='' |
|---|
| 2215 | if editor in self.getEditorList(): |
|---|
| 2216 | fileName=self.getEditorFileName(editor) |
|---|
| 2217 | |
|---|
| 2218 | if fileName: |
|---|
| 2219 | return self.saveFile(fileName) |
|---|
| 2220 | |
|---|
| 2221 | return self.saveAs() |
|---|
| 2222 | |
|---|
| 2223 | def saveAs(self,suggestedName=None): |
|---|
| 2224 | |
|---|
| 2225 | currentFilePath=None |
|---|
| 2226 | currentExtension="" |
|---|
| 2227 | try: |
|---|
| 2228 | |
|---|
| 2229 | currentFilePath=self.getEditorFileName(self.editTab.currentWidget()) |
|---|
| 2230 | except KeyError: |
|---|
| 2231 | pass |
|---|
| 2232 | |
|---|
| 2233 | if currentFilePath: |
|---|
| 2234 | fileSplit=os.path.splitext(str(currentFilePath)) |
|---|
| 2235 | currentExtension=fileSplit[1] |
|---|
| 2236 | |
|---|
| 2237 | |
|---|
| 2238 | self.lastFileOpenPath=currentFilePath |
|---|
| 2239 | else: |
|---|
| 2240 | currentFilePath=self.lastFileOpenPath |
|---|
| 2241 | |
|---|
| 2242 | dbgMsg("suggestedName=",suggestedName) |
|---|
| 2243 | fileName="" |
|---|
| 2244 | if suggestedName is None or isinstance(suggestedName, bool) : |
|---|
| 2245 | |
|---|
| 2246 | |
|---|
| 2247 | |
|---|
| 2248 | |
|---|
| 2249 | |
|---|
| 2250 | |
|---|
| 2251 | |
|---|
| 2252 | |
|---|
| 2253 | |
|---|
| 2254 | currentFilterString=self.getCurrentFilterString(currentExtension) |
|---|
| 2255 | dbgMsg("currentFilterString=",currentFilterString) |
|---|
| 2256 | |
|---|
| 2257 | |
|---|
| 2258 | fileName=QtGui.QFileDialog.getSaveFileName(self,"Save File",currentFilePath,currentFilterString+"\n"+self.fileDialogFilters) |
|---|
| 2259 | dbgMsg("SAVE FILE NAME is:",fileName) |
|---|
| 2260 | if fileName=="": |
|---|
| 2261 | return False |
|---|
| 2262 | |
|---|
| 2263 | |
|---|
| 2264 | else: |
|---|
| 2265 | dbgMsg("") |
|---|
| 2266 | fileName = QtGui.QFileDialog.getSaveFileName(self,"Save File",suggestedName) |
|---|
| 2267 | if fileName=="": |
|---|
| 2268 | return False |
|---|
| 2269 | |
|---|
| 2270 | fileName=os.path.abspath(fileName) |
|---|
| 2271 | |
|---|
| 2272 | if fileName: |
|---|
| 2273 | returnCode = self.saveFile(fileName) |
|---|
| 2274 | if returnCode: |
|---|
| 2275 | lexer=self.guessLexer(fileName) |
|---|
| 2276 | if lexer[0]: |
|---|
| 2277 | self.editTab.currentWidget().setLexer(lexer[0]) |
|---|
| 2278 | self.editTab.currentWidget().setBraceMatching(lexer[3]) |
|---|
| 2279 | if self.configuration.setting("FoldText"): |
|---|
| 2280 | self.editTab.currentWidget().setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 2281 | else: |
|---|
| 2282 | self.editTab.currentWidget().setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 2283 | self.editTab.currentWidget().setWhitespaceVisibility(self.configuration.setting("DisplayWhitespace")) |
|---|
| 2284 | self.editTab.currentWidget().setIndentationGuidesForegroundColor(self.indendationGuidesColor) |
|---|
| 2285 | self.editTab.currentWidget().setIndentationGuides(self.configuration.setting("TabGuidelines")) |
|---|
| 2286 | |
|---|
| 2287 | else: |
|---|
| 2288 | self.editTab.currentWidget().setLexer(None) |
|---|
| 2289 | |
|---|
| 2290 | tabIndex=self.editTab.indexOf(self.editTab.currentWidget()) |
|---|
| 2291 | self.editTab.setTabText(tabIndex,self.strippedName(fileName)) |
|---|
| 2292 | self.commentStyleDict[self.editTab.currentWidget()]=[lexer[1],lexer[2]] |
|---|
| 2293 | |
|---|
| 2294 | currentEncoding=self.getEditorFileEncoding(self.editTab.currentWidget()) |
|---|
| 2295 | self.setPropertiesInEditorList(self.editTab.currentWidget(),fileName,os.path.getmtime(fileName),currentEncoding) |
|---|
| 2296 | |
|---|
| 2297 | |
|---|
| 2298 | return returnCode |
|---|
| 2299 | |
|---|
| 2300 | |
|---|
| 2301 | return False |
|---|
| 2302 | |
|---|
| 2303 | def saveAll(self): |
|---|
| 2304 | |
|---|
| 2305 | unnamedFiles={} |
|---|
| 2306 | |
|---|
| 2307 | for editor in self.getEditorList(): |
|---|
| 2308 | if not self.getEditorFileName(editor)=='': |
|---|
| 2309 | index=self.editTab.indexOf(editor) |
|---|
| 2310 | self.editTab.setCurrentIndex(index) |
|---|
| 2311 | if self.editTab.currentWidget().isModified(): |
|---|
| 2312 | self.save() |
|---|
| 2313 | else: |
|---|
| 2314 | self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 2315 | else: |
|---|
| 2316 | index=self.editTab.indexOf(editor) |
|---|
| 2317 | unnamedFiles[editor]=self.editTab.tabText(index) |
|---|
| 2318 | |
|---|
| 2319 | |
|---|
| 2320 | |
|---|
| 2321 | for editor in unnamedFiles.keys(): |
|---|
| 2322 | if editor==self.defaultEditor: |
|---|
| 2323 | continue |
|---|
| 2324 | index=self.editTab.indexOf(editor) |
|---|
| 2325 | self.editTab.setCurrentIndex(index) |
|---|
| 2326 | self.saveAs(unnamedFiles[editor]) |
|---|
| 2327 | |
|---|
| 2328 | |
|---|
| 2329 | |
|---|
| 2330 | |
|---|
| 2331 | |
|---|
| 2332 | def about(self): |
|---|
| 2333 | QtGui.QMessageBox.about(self, "About Twedit", |
|---|
| 2334 | "The <b>Twedit</b> editor is a free Open-Source programmers editor\n" |
|---|
| 2335 | "Originally it was meant to be editor for Twitter and we limitted number of characters to 144\n" |
|---|
| 2336 | "However, after feedback from our users we were surprised to learn that people need more 144 characters to\n" |
|---|
| 2337 | "write software. We have since removed the limitation on number of characters... \n" |
|---|
| 2338 | "As a courtesy to our users no code written in this editor is catalogued by Google or any other data-mining company.\n" |
|---|
| 2339 | "\n" |
|---|
| 2340 | "Copyright Maciej Swat <b>Swat International Productions, LLC</b>" |
|---|
| 2341 | ) |
|---|
| 2342 | |
|---|
| 2343 | def documentWasModified(self): |
|---|
| 2344 | self.setWindowModified(self.textEdit.document().isModified()) |
|---|
| 2345 | |
|---|
| 2346 | def createActions(self): |
|---|
| 2347 | self.newAct = QtGui.QAction(QtGui.QIcon(':/icons/document-new.png'), "&New", |
|---|
| 2348 | self, shortcut=QtGui.QKeySequence.New, |
|---|
| 2349 | statusTip="Create a new file", triggered=self.newFile) |
|---|
| 2350 | |
|---|
| 2351 | self.openAct = QtGui.QAction(QtGui.QIcon(':/icons/document-open.png'), |
|---|
| 2352 | "&Open...", self, shortcut=QtGui.QKeySequence.Open, |
|---|
| 2353 | statusTip="Open an existing file", triggered=self.open) |
|---|
| 2354 | |
|---|
| 2355 | self.saveAct = QtGui.QAction(QtGui.QIcon(':/icons/document-save.png'), |
|---|
| 2356 | "&Save", self, shortcut=QtGui.QKeySequence.Save, |
|---|
| 2357 | statusTip="Save the document to disk", triggered=self.save) |
|---|
| 2358 | |
|---|
| 2359 | self.saveAsAct = QtGui.QAction(QtGui.QIcon(':/icons/document-save-as.png'),"Save &As...", self, |
|---|
| 2360 | shortcut=QtGui.QKeySequence.SaveAs, |
|---|
| 2361 | statusTip="Save the document under a new name", |
|---|
| 2362 | triggered=self.saveAs) |
|---|
| 2363 | |
|---|
| 2364 | |
|---|
| 2365 | self.saveAllAct = QtGui.QAction(QtGui.QIcon(':/icons/document-save-all.png'),"Save All", self, |
|---|
| 2366 | shortcut="Ctrl+Shift+S", |
|---|
| 2367 | statusTip="Save all documents", |
|---|
| 2368 | triggered=self.saveAll) |
|---|
| 2369 | |
|---|
| 2370 | |
|---|
| 2371 | self.printAct = QtGui.QAction(QtGui.QIcon(':/icons/document-print.png'),"print...", self,shortcut="Ctrl+P",statusTip="Print current document",triggered=self.printCurrentDocument) |
|---|
| 2372 | |
|---|
| 2373 | self.exitAct = QtGui.QAction(QtGui.QIcon(':/icons/application-exit.png'),"E&xit", self, shortcut="Ctrl+Q", |
|---|
| 2374 | statusTip="Exit the application", triggered=self.close) |
|---|
| 2375 | |
|---|
| 2376 | |
|---|
| 2377 | self.closeTabAct = QtGui.QAction(QtGui.QIcon(':/icons/tab-close.png'),"CloseTab", self, shortcut="Ctrl+W", |
|---|
| 2378 | statusTip="Close Current Tab", triggered=self.closeTab) |
|---|
| 2379 | |
|---|
| 2380 | self.zoomInAct = QtGui.QAction(QtGui.QIcon(':/icons/zoom-in.png'),"ZoomIn", self, shortcut="Ctrl+Shift+=", |
|---|
| 2381 | statusTip="Zoom In", triggered=self.zoomIn) |
|---|
| 2382 | |
|---|
| 2383 | self.zoomOutAct = QtGui.QAction(QtGui.QIcon(':/icons/zoom-out.png'),"ZoomOut", self, shortcut="Ctrl+-", |
|---|
| 2384 | statusTip="Zoom Out", triggered=self.zoomOut) |
|---|
| 2385 | |
|---|
| 2386 | self.foldAllAct = QtGui.QAction("Toggle Fold All", self, statusTip="Fold document at all folding points", triggered=self.foldAll) |
|---|
| 2387 | |
|---|
| 2388 | self.showFindInFilesDockAct=QtGui.QAction("Show Find in Files Results", self, statusTip="Show Find in Files Results", triggered=self.toggleFindInFilesDock) |
|---|
| 2389 | self.showFindInFilesDockAct.setCheckable(True) |
|---|
| 2390 | |
|---|
| 2391 | self.blockCommentAct = QtGui.QAction("BlockComment", self, shortcut="Ctrl+D", |
|---|
| 2392 | statusTip="Block Comment", triggered=self.blockComment) |
|---|
| 2393 | |
|---|
| 2394 | self.blockUncommentAct = QtGui.QAction("BlockUncomment", self, shortcut="Ctrl+Shift+D", |
|---|
| 2395 | statusTip="Block Uncomment", triggered=self.blockUncomment) |
|---|
| 2396 | |
|---|
| 2397 | |
|---|
| 2398 | |
|---|
| 2399 | |
|---|
| 2400 | self.findAct = QtGui.QAction(QtGui.QIcon(':/icons/edit-find.png'),"Find...", self, shortcut="Ctrl+F", |
|---|
| 2401 | statusTip="Find...", triggered=self.find) |
|---|
| 2402 | |
|---|
| 2403 | self.findNextAct = QtGui.QAction("Find Next", self, shortcut="F3", |
|---|
| 2404 | statusTip="Find Next", triggered=self.findNextSimple) |
|---|
| 2405 | |
|---|
| 2406 | |
|---|
| 2407 | self.toggleBookmarkAct = QtGui.QAction(QtGui.QIcon(':/icons/flag.png'),"Toogle Bookmark", self, shortcut="Ctrl+F2", |
|---|
| 2408 | statusTip="Toggle Text Bookmark", triggered=self.toggleBookmark) |
|---|
| 2409 | |
|---|
| 2410 | self.goToNextBookmarkAct = QtGui.QAction("Go To Next Bookmark", self, shortcut="F2", |
|---|
| 2411 | statusTip="Go to Next Bookmark", triggered=self.goToNextBookmark) |
|---|
| 2412 | |
|---|
| 2413 | self.goToPreviousBookmarkAct = QtGui.QAction("Go To Previous Bookmark", self, shortcut="Shift+F2", |
|---|
| 2414 | statusTip="Go to Previous Bookmark", triggered=self.goToPreviousBookmark) |
|---|
| 2415 | |
|---|
| 2416 | self.deleteAllBookmarksAct = QtGui.QAction("Delete All Bookmarks", self, shortcut="", |
|---|
| 2417 | statusTip="Delete All Bookmarks", triggered=self.deleteAllBookmarks) |
|---|
| 2418 | |
|---|
| 2419 | self.goToLineAct = QtGui.QAction("Go To Line...", self, shortcut="Ctrl+G", |
|---|
| 2420 | statusTip="Go To Line", triggered=self.goToLineShow) |
|---|
| 2421 | |
|---|
| 2422 | self.goToMatchingBraceAct = QtGui.QAction("Go To Matching Brace", self, shortcut="Ctrl+]", |
|---|
| 2423 | statusTip="Go To Matching Brace", triggered=self.goToMatchingBrace) |
|---|
| 2424 | |
|---|
| 2425 | self.selectToMatchingBraceAct = QtGui.QAction("Select To Matching Brace", self, shortcut="Ctrl+Shift+]", |
|---|
| 2426 | statusTip="Select To Matching Brace", triggered=self.selectToMatchingBrace) |
|---|
| 2427 | |
|---|
| 2428 | self.cutAct = QtGui.QAction(QtGui.QIcon(':/icons/edit-cut.png'), "Cu&t", |
|---|
| 2429 | self, shortcut=QtGui.QKeySequence.Cut, |
|---|
| 2430 | statusTip="Cut the current selection's contents to the clipboard", |
|---|
| 2431 | triggered=self.cut) |
|---|
| 2432 | |
|---|
| 2433 | self.copyAct = QtGui.QAction(QtGui.QIcon(':/icons/edit-copy.png'), |
|---|
| 2434 | "&Copy", self, shortcut=QtGui.QKeySequence.Copy, |
|---|
| 2435 | statusTip="Copy the current selection's contents to the clipboard", |
|---|
| 2436 | triggered=self.copy) |
|---|
| 2437 | |
|---|
| 2438 | self.pasteAct = QtGui.QAction(QtGui.QIcon(':/icons/edit-paste.png'), |
|---|
| 2439 | "&Paste", self, shortcut=QtGui.QKeySequence.Paste, |
|---|
| 2440 | statusTip="Paste the clipboard's contents into the current selection", |
|---|
| 2441 | triggered=self.paste) |
|---|
| 2442 | |
|---|
| 2443 | self.increaseIndentAct = QtGui.QAction(QtGui.QIcon(':/icons/format-indent-more.png'),"IncreaseIndent", self, shortcut="Tab", |
|---|
| 2444 | statusTip="Increase Indent", triggered=self.increaseIndent) |
|---|
| 2445 | |
|---|
| 2446 | self.decreaseIndentAct = QtGui.QAction(QtGui.QIcon(':/icons/format-indent-less.png'),"DecreaseIndent", self, shortcut="Shift+Tab", |
|---|
| 2447 | statusTip="Decrease Indent", triggered=self.decreaseIndent) |
|---|
| 2448 | |
|---|
| 2449 | self.upperCaseAct=QtGui.QAction("CONVERT TO UPPER CASE", self, shortcut="Ctrl+Shift+U", |
|---|
| 2450 | statusTip="Convert To Upper Case", triggered=self.convertToUpperCase) |
|---|
| 2451 | |
|---|
| 2452 | self.lowerCaseAct=QtGui.QAction("convert to lower case", self, shortcut="Ctrl+U", |
|---|
| 2453 | statusTip="Convert To Upper Case", triggered=self.convertToLowerCase) |
|---|
| 2454 | |
|---|
| 2455 | self.convertEOLAct=QtGui.QAction("Convert EOL", self,statusTip="Convert End of Line Character") |
|---|
| 2456 | self.convertEOLWinAct=QtGui.QAction("Windows EOL", self,statusTip="Convert End of Line Character to Windows Style",triggered=self.convertEolWindows) |
|---|
| 2457 | self.convertEOLUnixAct=QtGui.QAction("Unix EOL", self,statusTip="Convert End of Line Character to Unix Style",triggered=self.convertEolUnix) |
|---|
| 2458 | self.convertEOLMacAct=QtGui.QAction("Mac EOL", self,statusTip="Convert End of Line Character to Mac Style",triggered=self.convertEolMac) |
|---|
| 2459 | |
|---|
| 2460 | self.undoAct= QtGui.QAction(QtGui.QIcon(':/icons/edit-undo.png'),"Undo", self, shortcut="Ctrl+Z", |
|---|
| 2461 | statusTip="Undo", triggered=self.__undo) |
|---|
| 2462 | |
|---|
| 2463 | self.redoAct= QtGui.QAction(QtGui.QIcon(':/icons/edit-redo.png'),"Redo", self, shortcut="Ctrl+Y", |
|---|
| 2464 | statusTip="Redo", triggered=self.__redo) |
|---|
| 2465 | |
|---|
| 2466 | self.configurationAct = QtGui.QAction(QtGui.QIcon(':/icons/configure.png'),"Configuration", self, shortcut="", |
|---|
| 2467 | statusTip="Configuration...", triggered=self.configurationUpdate) |
|---|
| 2468 | |
|---|
| 2469 | |
|---|
| 2470 | self.aboutAct = QtGui.QAction("&About", self, |
|---|
| 2471 | statusTip="Show the application's About box", |
|---|
| 2472 | triggered=self.about) |
|---|
| 2473 | |
|---|
| 2474 | self.aboutQtAct = QtGui.QAction("About &Qt", self, |
|---|
| 2475 | statusTip="Show the Qt library's About box", |
|---|
| 2476 | triggered=QtGui.qApp.aboutQt) |
|---|
| 2477 | |
|---|
| 2478 | self.editTab.currentChanged.connect(self.tabIndexChanged) |
|---|
| 2479 | self.editTab.tabCloseRequested.connect(self.closeTabIndex) |
|---|
| 2480 | |
|---|
| 2481 | |
|---|
| 2482 | |
|---|
| 2483 | |
|---|
| 2484 | |
|---|
| 2485 | |
|---|
| 2486 | |
|---|
| 2487 | |
|---|
| 2488 | |
|---|
| 2489 | def createMenus(self): |
|---|
| 2490 | self.fileMenu = self.menuBar().addMenu("&File") |
|---|
| 2491 | self.fileMenu.addAction(self.newAct) |
|---|
| 2492 | self.fileMenu.addAction(self.openAct) |
|---|
| 2493 | self.fileMenu.addAction(self.saveAct) |
|---|
| 2494 | self.fileMenu.addAction(self.saveAsAct) |
|---|
| 2495 | self.fileMenu.addAction(self.saveAllAct) |
|---|
| 2496 | self.fileMenu.addSeparator() |
|---|
| 2497 | |
|---|
| 2498 | self.fileMenu.addAction(self.printAct) |
|---|
| 2499 | |
|---|
| 2500 | self.fileMenu.addSeparator(); |
|---|
| 2501 | |
|---|
| 2502 | self.fileMenu.addAction(self.exitAct) |
|---|
| 2503 | |
|---|
| 2504 | self.editMenu = self.menuBar().addMenu("&Edit") |
|---|
| 2505 | self.editMenu.addAction(self.cutAct) |
|---|
| 2506 | self.editMenu.addAction(self.copyAct) |
|---|
| 2507 | self.editMenu.addAction(self.pasteAct) |
|---|
| 2508 | |
|---|
| 2509 | self.editMenu.addSeparator() |
|---|
| 2510 | self.editMenu.addAction(self.blockCommentAct) |
|---|
| 2511 | self.editMenu.addAction(self.blockUncommentAct) |
|---|
| 2512 | |
|---|
| 2513 | self.editMenu.addAction(self.increaseIndentAct) |
|---|
| 2514 | self.editMenu.addAction(self.decreaseIndentAct) |
|---|
| 2515 | self.editMenu.addSeparator() |
|---|
| 2516 | self.editMenu.addAction(self.upperCaseAct) |
|---|
| 2517 | self.editMenu.addAction(self.lowerCaseAct) |
|---|
| 2518 | |
|---|
| 2519 | self.convertEOLMenu=self.editMenu.addMenu("Convert EOL") |
|---|
| 2520 | self.convertEOLMenu.addAction(self.convertEOLWinAct) |
|---|
| 2521 | self.convertEOLMenu.addAction(self.convertEOLUnixAct) |
|---|
| 2522 | self.convertEOLMenu.addAction(self.convertEOLMacAct) |
|---|
| 2523 | |
|---|
| 2524 | self.editMenu.addSeparator() |
|---|
| 2525 | |
|---|
| 2526 | self.editMenu.addAction(self.undoAct) |
|---|
| 2527 | self.editMenu.addAction(self.redoAct) |
|---|
| 2528 | |
|---|
| 2529 | self.searchMenu = self.menuBar().addMenu("&Search") |
|---|
| 2530 | self.searchMenu.addAction(self.findAct) |
|---|
| 2531 | |
|---|
| 2532 | self.searchMenu.addAction(self.findNextAct) |
|---|
| 2533 | |
|---|
| 2534 | self.searchMenu.addSeparator() |
|---|
| 2535 | self.searchMenu.addAction(self.toggleBookmarkAct) |
|---|
| 2536 | self.searchMenu.addAction(self.goToNextBookmarkAct) |
|---|
| 2537 | self.searchMenu.addAction(self.goToPreviousBookmarkAct) |
|---|
| 2538 | self.searchMenu.addAction(self.deleteAllBookmarksAct) |
|---|
| 2539 | self.searchMenu.addSeparator() |
|---|
| 2540 | self.searchMenu.addAction(self.goToLineAct) |
|---|
| 2541 | self.searchMenu.addAction(self.goToMatchingBraceAct) |
|---|
| 2542 | self.searchMenu.addAction(self.selectToMatchingBraceAct) |
|---|
| 2543 | |
|---|
| 2544 | |
|---|
| 2545 | |
|---|
| 2546 | |
|---|
| 2547 | |
|---|
| 2548 | |
|---|
| 2549 | self.viewMenu = self.menuBar().addMenu("&View") |
|---|
| 2550 | self.viewMenu.addAction(self.closeTabAct) |
|---|
| 2551 | self.viewMenu.addAction(self.zoomInAct) |
|---|
| 2552 | self.viewMenu.addAction(self.zoomOutAct) |
|---|
| 2553 | self.viewMenu.addSeparator() |
|---|
| 2554 | |
|---|
| 2555 | self.viewMenu.addAction(self.foldAllAct) |
|---|
| 2556 | self.viewMenu.addSeparator() |
|---|
| 2557 | |
|---|
| 2558 | self.viewMenu.addAction(self.showFindInFilesDockAct) |
|---|
| 2559 | |
|---|
| 2560 | |
|---|
| 2561 | self.languageMenu=self.menuBar().addMenu("&Language") |
|---|
| 2562 | |
|---|
| 2563 | |
|---|
| 2564 | self.configurationMenu=self.menuBar().addMenu("&Configuration") |
|---|
| 2565 | self.configurationMenu.addAction(self.configurationAct) |
|---|
| 2566 | |
|---|
| 2567 | self.menuBar().addSeparator() |
|---|
| 2568 | |
|---|
| 2569 | self.helpMenu = self.menuBar().addMenu("&Help") |
|---|
| 2570 | self.helpMenu.addAction(self.aboutAct) |
|---|
| 2571 | self.helpMenu.addAction(self.aboutQtAct) |
|---|
| 2572 | |
|---|
| 2573 | def createToolBars(self): |
|---|
| 2574 | self.fileToolBar = self.addToolBar("File") |
|---|
| 2575 | self.fileToolBar.addAction(self.newAct) |
|---|
| 2576 | self.fileToolBar.addAction(self.openAct) |
|---|
| 2577 | self.fileToolBar.addAction(self.saveAct) |
|---|
| 2578 | self.fileToolBar.addAction(self.saveAsAct) |
|---|
| 2579 | self.fileToolBar.addAction(self.saveAllAct) |
|---|
| 2580 | |
|---|
| 2581 | self.editToolBar = self.addToolBar("Edit") |
|---|
| 2582 | self.editToolBar.addAction(self.cutAct) |
|---|
| 2583 | self.editToolBar.addAction(self.copyAct) |
|---|
| 2584 | self.editToolBar.addAction(self.pasteAct) |
|---|
| 2585 | self.editToolBar.addAction(self.increaseIndentAct) |
|---|
| 2586 | self.editToolBar.addAction(self.decreaseIndentAct) |
|---|
| 2587 | |
|---|
| 2588 | self.searchToolBar = self.addToolBar("Search") |
|---|
| 2589 | self.searchToolBar.addAction(self.findAct) |
|---|
| 2590 | self.searchToolBar.addAction(self.toggleBookmarkAct) |
|---|
| 2591 | |
|---|
| 2592 | def createStatusBar(self): |
|---|
| 2593 | self.statusBar().showMessage("Ready") |
|---|
| 2594 | |
|---|
| 2595 | def toggleFindInFilesDock(self, _flag=False): |
|---|
| 2596 | dbgMsg("FLAG=",_flag) |
|---|
| 2597 | dbgMsg("self.showFindInFilesDockAct.isChecked():",self.showFindInFilesDockAct.isChecked()) |
|---|
| 2598 | if self.findDock.isHidden(): |
|---|
| 2599 | self.findDock.show() |
|---|
| 2600 | else: |
|---|
| 2601 | self.findDock.hide() |
|---|
| 2602 | |
|---|
| 2603 | |
|---|
| 2604 | |
|---|
| 2605 | |
|---|
| 2606 | |
|---|
| 2607 | |
|---|
| 2608 | |
|---|
| 2609 | |
|---|
| 2610 | |
|---|
| 2611 | def maybeSave(self): |
|---|
| 2612 | dbgMsg("slot maybeSave") |
|---|
| 2613 | |
|---|
| 2614 | editor=self.editTab.currentWidget() |
|---|
| 2615 | dbgMsg("editor=",editor," isModified()=",editor.isModified()) |
|---|
| 2616 | if editor.isModified(): |
|---|
| 2617 | fileName='' |
|---|
| 2618 | if self.getEditorFileName(editor)!='': |
|---|
| 2619 | fileName = self.getEditorFileName(editor) |
|---|
| 2620 | else: |
|---|
| 2621 | index = self.editTab.indexOf(editor) |
|---|
| 2622 | fileName = self.editTab.tabText(index) |
|---|
| 2623 | |
|---|
| 2624 | message="The document "+fileName+" has been modified.\nDo you want to save changes?" |
|---|
| 2625 | |
|---|
| 2626 | ret = QtGui.QMessageBox.warning(self, "Save Modification", |
|---|
| 2627 | message, |
|---|
| 2628 | QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | |
|---|
| 2629 | QtGui.QMessageBox.Cancel) |
|---|
| 2630 | if ret == QtGui.QMessageBox.Save: |
|---|
| 2631 | return self.save() |
|---|
| 2632 | elif ret == QtGui.QMessageBox.Cancel: |
|---|
| 2633 | return False |
|---|
| 2634 | return True |
|---|
| 2635 | |
|---|
| 2636 | def __undo(self): |
|---|
| 2637 | editor=self.editTab.currentWidget() |
|---|
| 2638 | editor.undo() |
|---|
| 2639 | self.checkActions() |
|---|
| 2640 | |
|---|
| 2641 | def __redo(self): |
|---|
| 2642 | editor=self.editTab.currentWidget() |
|---|
| 2643 | |
|---|
| 2644 | editor.redo() |
|---|
| 2645 | self.checkActions() |
|---|
| 2646 | |
|---|
| 2647 | |
|---|
| 2648 | def printCurrentDocument(self): |
|---|
| 2649 | editor=self.editTab.currentWidget() |
|---|
| 2650 | printer=PrinterTwedit() |
|---|
| 2651 | printDialog=QPrintDialog(printer,self) |
|---|
| 2652 | if printDialog.exec_()==QDialog.Accepted: |
|---|
| 2653 | dbgMsg("Paper size=", printer.paperSize()) |
|---|
| 2654 | printer.setDocName(self.getCurrentDocumentName()) |
|---|
| 2655 | printer.printRange(editor) |
|---|
| 2656 | dbgMsg("THIS IS PRINT CURRENT DOCUMENT") |
|---|
| 2657 | |
|---|
| 2658 | def convertToUpperCase(self): |
|---|
| 2659 | editor=self.editTab.currentWidget() |
|---|
| 2660 | editor.SendScintilla(QsciScintilla.SCI_UPPERCASE) |
|---|
| 2661 | |
|---|
| 2662 | def convertToLowerCase(self): |
|---|
| 2663 | editor=self.editTab.currentWidget() |
|---|
| 2664 | editor.SendScintilla(QsciScintilla.SCI_LOWERCASE) |
|---|
| 2665 | |
|---|
| 2666 | def convertEolWindows(self): |
|---|
| 2667 | editor=self.editTab.currentWidget() |
|---|
| 2668 | editor.setEolMode(QsciScintilla.EolWindows) |
|---|
| 2669 | editor.convertEols(QsciScintilla.EolWindows) |
|---|
| 2670 | |
|---|
| 2671 | def convertEolUnix(self): |
|---|
| 2672 | editor=self.editTab.currentWidget() |
|---|
| 2673 | editor.setEolMode(QsciScintilla.EolUnix) |
|---|
| 2674 | editor.convertEols(QsciScintilla.EolUnix) |
|---|
| 2675 | |
|---|
| 2676 | |
|---|
| 2677 | def convertEolMac(self): |
|---|
| 2678 | editor=self.editTab.currentWidget() |
|---|
| 2679 | editor.setEolMode(QsciScintilla.EolMac) |
|---|
| 2680 | editor.convertEols(QsciScintilla.EolMac) |
|---|
| 2681 | |
|---|
| 2682 | def checkActions(self): |
|---|
| 2683 | editor=self.editTab.currentWidget() |
|---|
| 2684 | |
|---|
| 2685 | if editor: |
|---|
| 2686 | self.undoAct.setEnabled(editor.isUndoAvailable()) |
|---|
| 2687 | self.redoAct.setEnabled(editor.isRedoAvailable()) |
|---|
| 2688 | |
|---|
| 2689 | |
|---|
| 2690 | |
|---|
| 2691 | |
|---|
| 2692 | |
|---|
| 2693 | |
|---|
| 2694 | |
|---|
| 2695 | |
|---|
| 2696 | def __modificationChanged(self, m): |
|---|
| 2697 | """ |
|---|
| 2698 | Private slot to handle the modificationChanged signal. |
|---|
| 2699 | |
|---|
| 2700 | @param m modification status |
|---|
| 2701 | """ |
|---|
| 2702 | dbgMsg(" INSIDE MODIFICATIONCHANGED SLOT") |
|---|
| 2703 | self.setWindowModified(m) |
|---|
| 2704 | self.checkActions() |
|---|
| 2705 | |
|---|
| 2706 | def maybeReload(self,tab): |
|---|
| 2707 | dbgMsg("slot maybeReload") |
|---|
| 2708 | |
|---|
| 2709 | message="The document "+self.getEditorFileName(tab)+" has been modified by external program.\nDo you want to reload?" |
|---|
| 2710 | ret = QtGui.QMessageBox.warning(self, "Reload", |
|---|
| 2711 | message, |
|---|
| 2712 | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No ) |
|---|
| 2713 | |
|---|
| 2714 | if ret == QtGui.QMessageBox.Yes: |
|---|
| 2715 | |
|---|
| 2716 | return self.reloadFile(tab,self.getEditorFileName(tab)) |
|---|
| 2717 | |
|---|
| 2718 | elif ret == QtGui.QMessageBox.No: |
|---|
| 2719 | return False |
|---|
| 2720 | return False |
|---|
| 2721 | |
|---|
| 2722 | |
|---|
| 2723 | def reloadFile (self, editor,fileName): |
|---|
| 2724 | file=None |
|---|
| 2725 | |
|---|
| 2726 | try: |
|---|
| 2727 | file = open(fileName, 'rb') |
|---|
| 2728 | except: |
|---|
| 2729 | QtGui.QMessageBox.warning(self, "Twedit", |
|---|
| 2730 | "Cannot read file %s:\n%s." % (fileName, "Check if the file is accessible")) |
|---|
| 2731 | return |
|---|
| 2732 | QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
|---|
| 2733 | |
|---|
| 2734 | |
|---|
| 2735 | editor.modificationChanged.disconnect(self.textChangedHandlers[editor].handleModificationChanged) |
|---|
| 2736 | editor.textChanged.disconnect(self.textChangedHandlers[editor].handleChangedText) |
|---|
| 2737 | editor.cursorPositionChanged.disconnect(self.handleCursorPositionChanged) |
|---|
| 2738 | |
|---|
| 2739 | |
|---|
| 2740 | |
|---|
| 2741 | |
|---|
| 2742 | |
|---|
| 2743 | |
|---|
| 2744 | |
|---|
| 2745 | |
|---|
| 2746 | |
|---|
| 2747 | |
|---|
| 2748 | |
|---|
| 2749 | |
|---|
| 2750 | import codecs |
|---|
| 2751 | |
|---|
| 2752 | |
|---|
| 2753 | txt, encoding = Encoding.decode(file) |
|---|
| 2754 | dbgMsg("RELOAD FILE encoding=",encoding,"\n\n\n") |
|---|
| 2755 | file.close() |
|---|
| 2756 | |
|---|
| 2757 | |
|---|
| 2758 | fh=codecs.open(fileName,'rb',Encoding.normalizeEncodingName(encoding)) |
|---|
| 2759 | txt=fh.read() |
|---|
| 2760 | fh.close() |
|---|
| 2761 | |
|---|
| 2762 | editor.setText(txt) |
|---|
| 2763 | |
|---|
| 2764 | |
|---|
| 2765 | |
|---|
| 2766 | editor.modificationChanged.connect(self.textChangedHandlers[editor].handleModificationChanged) |
|---|
| 2767 | editor.textChanged.connect(self.textChangedHandlers[editor].handleChangedText) |
|---|
| 2768 | editor.cursorPositionChanged.connect(self.handleCursorPositionChanged) |
|---|
| 2769 | |
|---|
| 2770 | |
|---|
| 2771 | self.setPropertiesInEditorList(editor,os.path.abspath(fileName),os.path.getmtime(fileName),encoding) |
|---|
| 2772 | |
|---|
| 2773 | editor.setModified(False) |
|---|
| 2774 | |
|---|
| 2775 | self.updateTextSizeLabel() |
|---|
| 2776 | self.updateEncodingLabel() |
|---|
| 2777 | |
|---|
| 2778 | |
|---|
| 2779 | |
|---|
| 2780 | QtGui.QApplication.restoreOverrideCursor() |
|---|
| 2781 | return True |
|---|
| 2782 | |
|---|
| 2783 | def loadFiles(self, fileNames): |
|---|
| 2784 | for i in range(fileNames.count()): |
|---|
| 2785 | self.loadFile(os.path.abspath(fileNames[i])) |
|---|
| 2786 | |
|---|
| 2787 | |
|---|
| 2788 | |
|---|
| 2789 | |
|---|
| 2790 | |
|---|
| 2791 | |
|---|
| 2792 | |
|---|
| 2793 | |
|---|
| 2794 | |
|---|
| 2795 | |
|---|
| 2796 | |
|---|
| 2797 | |
|---|
| 2798 | |
|---|
| 2799 | |
|---|
| 2800 | |
|---|
| 2801 | |
|---|
| 2802 | |
|---|
| 2803 | |
|---|
| 2804 | |
|---|
| 2805 | |
|---|
| 2806 | |
|---|
| 2807 | |
|---|
| 2808 | |
|---|
| 2809 | |
|---|
| 2810 | |
|---|
| 2811 | |
|---|
| 2812 | |
|---|
| 2813 | |
|---|
| 2814 | |
|---|
| 2815 | |
|---|
| 2816 | |
|---|
| 2817 | |
|---|
| 2818 | |
|---|
| 2819 | |
|---|
| 2820 | |
|---|
| 2821 | |
|---|
| 2822 | |
|---|
| 2823 | |
|---|
| 2824 | |
|---|
| 2825 | |
|---|
| 2826 | |
|---|
| 2827 | |
|---|
| 2828 | |
|---|
| 2829 | def loadFile(self, fileName,_restoreFlag=False): |
|---|
| 2830 | |
|---|
| 2831 | |
|---|
| 2832 | |
|---|
| 2833 | |
|---|
| 2834 | |
|---|
| 2835 | |
|---|
| 2836 | openFileDict=self.getFileNameToEditorWidgetMap() |
|---|
| 2837 | |
|---|
| 2838 | if fileName in openFileDict.keys(): |
|---|
| 2839 | |
|---|
| 2840 | try: |
|---|
| 2841 | self.editTab.setCurrentWidget(openFileDict[fileName]) |
|---|
| 2842 | except KeyError,e: |
|---|
| 2843 | pass |
|---|
| 2844 | |
|---|
| 2845 | return |
|---|
| 2846 | |
|---|
| 2847 | file=None |
|---|
| 2848 | |
|---|
| 2849 | try: |
|---|
| 2850 | |
|---|
| 2851 | file = open(fileName, 'r') |
|---|
| 2852 | except: |
|---|
| 2853 | QtGui.QMessageBox.warning(self, "Twedit", |
|---|
| 2854 | "Cannot read file %s:\n%s." % (fileName, "Check if the file is accessible")) |
|---|
| 2855 | return |
|---|
| 2856 | |
|---|
| 2857 | |
|---|
| 2858 | |
|---|
| 2859 | |
|---|
| 2860 | |
|---|
| 2861 | |
|---|
| 2862 | |
|---|
| 2863 | |
|---|
| 2864 | |
|---|
| 2865 | |
|---|
| 2866 | QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
|---|
| 2867 | |
|---|
| 2868 | |
|---|
| 2869 | |
|---|
| 2870 | lexer=self.guessLexer(fileName) |
|---|
| 2871 | textEditLocal=None |
|---|
| 2872 | encoding=None |
|---|
| 2873 | |
|---|
| 2874 | |
|---|
| 2875 | if self.editTab.count()==1: |
|---|
| 2876 | |
|---|
| 2877 | |
|---|
| 2878 | textEditLocal = self.editTab.currentWidget() |
|---|
| 2879 | if not textEditLocal.isModified() and not textEditLocal.length(): |
|---|
| 2880 | |
|---|
| 2881 | |
|---|
| 2882 | self.editTab.removeTab(0) |
|---|
| 2883 | textEditLocal=QsciScintillaCustom() |
|---|
| 2884 | self.editTab.addTab(textEditLocal,QtGui.QIcon(':/icons/document-clean.png'),self.strippedName(fileName)) |
|---|
| 2885 | textEditLocal=self.editTab.currentWidget() |
|---|
| 2886 | |
|---|
| 2887 | |
|---|
| 2888 | |
|---|
| 2889 | |
|---|
| 2890 | |
|---|
| 2891 | |
|---|
| 2892 | |
|---|
| 2893 | |
|---|
| 2894 | |
|---|
| 2895 | import codecs |
|---|
| 2896 | |
|---|
| 2897 | |
|---|
| 2898 | |
|---|
| 2899 | |
|---|
| 2900 | |
|---|
| 2901 | |
|---|
| 2902 | |
|---|
| 2903 | |
|---|
| 2904 | |
|---|
| 2905 | |
|---|
| 2906 | txt, encoding = Encoding.decode(file) |
|---|
| 2907 | dbgMsg("section 1 encoding=",encoding,"\n\n\n") |
|---|
| 2908 | file.close() |
|---|
| 2909 | |
|---|
| 2910 | |
|---|
| 2911 | fh=codecs.open(fileName,'rb',Encoding.normalizeEncodingName(encoding)) |
|---|
| 2912 | txt=fh.read() |
|---|
| 2913 | fh.close() |
|---|
| 2914 | |
|---|
| 2915 | textEditLocal.SendScintilla(QsciScintilla.SCI_SETCODEPAGE, QsciScintilla.SC_CP_UTF8) |
|---|
| 2916 | textEditLocal.setText(txt) |
|---|
| 2917 | |
|---|
| 2918 | |
|---|
| 2919 | |
|---|
| 2920 | self.editTab.setTabText(0,self.strippedName(fileName)) |
|---|
| 2921 | self.setEditorProperties(textEditLocal) |
|---|
| 2922 | if lexer[0]: |
|---|
| 2923 | textEditLocal.setLexer(lexer[0]) |
|---|
| 2924 | self.editTab.currentWidget().setBraceMatching(lexer[3]) |
|---|
| 2925 | |
|---|
| 2926 | if self.configuration.setting("FoldText"): |
|---|
| 2927 | textEditLocal.setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 2928 | else: |
|---|
| 2929 | textEditLocal.setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 2930 | |
|---|
| 2931 | self.editTab.currentWidget().setWhitespaceVisibility(self.configuration.setting("DisplayWhitespace")) |
|---|
| 2932 | self.editTab.currentWidget().setIndentationGuidesForegroundColor(self.indendationGuidesColor) |
|---|
| 2933 | self.editTab.currentWidget().setIndentationGuides(self.configuration.setting("TabGuidelines")) |
|---|
| 2934 | |
|---|
| 2935 | |
|---|
| 2936 | |
|---|
| 2937 | else: |
|---|
| 2938 | textEditLocal=QsciScintillaCustom() |
|---|
| 2939 | self.editTab.addTab(textEditLocal,QtGui.QIcon(':/icons/document-clean.png'),self.strippedName(fileName)) |
|---|
| 2940 | self.setCurrentFile(fileName) |
|---|
| 2941 | |
|---|
| 2942 | |
|---|
| 2943 | |
|---|
| 2944 | |
|---|
| 2945 | |
|---|
| 2946 | |
|---|
| 2947 | |
|---|
| 2948 | |
|---|
| 2949 | |
|---|
| 2950 | import codecs |
|---|
| 2951 | |
|---|
| 2952 | |
|---|
| 2953 | |
|---|
| 2954 | |
|---|
| 2955 | |
|---|
| 2956 | |
|---|
| 2957 | |
|---|
| 2958 | txt, encoding = Encoding.decode(file) |
|---|
| 2959 | dbgMsg("section 2 encoding=",encoding,"\n\n\n" ) |
|---|
| 2960 | file.close() |
|---|
| 2961 | |
|---|
| 2962 | fh=codecs.open(fileName,'rb',Encoding.normalizeEncodingName(encoding)) |
|---|
| 2963 | txt=fh.read() |
|---|
| 2964 | fh.close() |
|---|
| 2965 | textEditLocal.SendScintilla(QsciScintilla.SCI_SETCODEPAGE, QsciScintilla.SC_CP_UTF8) |
|---|
| 2966 | textEditLocal.setText(txt) |
|---|
| 2967 | |
|---|
| 2968 | |
|---|
| 2969 | self.setEditorProperties(textEditLocal) |
|---|
| 2970 | if lexer[0]: |
|---|
| 2971 | textEditLocal.setLexer(lexer[0]) |
|---|
| 2972 | self.editTab.currentWidget().setBraceMatching(lexer[3]) |
|---|
| 2973 | if self.configuration.setting("FoldText"): |
|---|
| 2974 | textEditLocal.setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 2975 | else: |
|---|
| 2976 | textEditLocal.setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 2977 | |
|---|
| 2978 | self.editTab.currentWidget().setWhitespaceVisibility(self.configuration.setting("DisplayWhitespace")) |
|---|
| 2979 | self.editTab.currentWidget().setIndentationGuidesForegroundColor(self.indendationGuidesColor) |
|---|
| 2980 | self.editTab.currentWidget().setIndentationGuides(self.configuration.setting("TabGuidelines")) |
|---|
| 2981 | |
|---|
| 2982 | self.editTab.setTabIcon(0,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 2983 | |
|---|
| 2984 | |
|---|
| 2985 | else: |
|---|
| 2986 | textEditLocal=QsciScintillaCustom() |
|---|
| 2987 | self.editTab.addTab(textEditLocal,QtGui.QIcon(':/icons/document-clean.png'),self.strippedName(fileName)) |
|---|
| 2988 | self.setCurrentFile(fileName) |
|---|
| 2989 | |
|---|
| 2990 | |
|---|
| 2991 | |
|---|
| 2992 | |
|---|
| 2993 | |
|---|
| 2994 | |
|---|
| 2995 | |
|---|
| 2996 | import codecs |
|---|
| 2997 | |
|---|
| 2998 | |
|---|
| 2999 | txt, encoding = Encoding.decode(file) |
|---|
| 3000 | dbgMsg("section 3 encoding=",encoding,"\n\n\n") |
|---|
| 3001 | file.close() |
|---|
| 3002 | |
|---|
| 3003 | |
|---|
| 3004 | fh=codecs.open(fileName,'rb',Encoding.normalizeEncodingName(encoding)) |
|---|
| 3005 | txt=fh.read() |
|---|
| 3006 | fh.close() |
|---|
| 3007 | textEditLocal.SendScintilla(QsciScintilla.SCI_SETCODEPAGE, QsciScintilla.SC_CP_UTF8) |
|---|
| 3008 | textEditLocal.setText(txt) |
|---|
| 3009 | |
|---|
| 3010 | |
|---|
| 3011 | |
|---|
| 3012 | self.setEditorProperties(textEditLocal) |
|---|
| 3013 | if lexer[0]: |
|---|
| 3014 | textEditLocal.setLexer(lexer[0]) |
|---|
| 3015 | self.editTab.currentWidget().setBraceMatching(lexer[3]) |
|---|
| 3016 | if self.configuration.setting("FoldText"): |
|---|
| 3017 | textEditLocal.setFolding(QsciScintilla.BoxedTreeFoldStyle) |
|---|
| 3018 | else: |
|---|
| 3019 | textEditLocal.setFolding(QsciScintilla.NoFoldStyle) |
|---|
| 3020 | |
|---|
| 3021 | self.editTab.currentWidget().setWhitespaceVisibility(lexer[5]) |
|---|
| 3022 | self.editTab.currentWidget().setIndentationGuidesForegroundColor(self.indendationGuidesColor) |
|---|
| 3023 | self.editTab.currentWidget().setIndentationGuides(True) |
|---|
| 3024 | |
|---|
| 3025 | |
|---|
| 3026 | |
|---|
| 3027 | editor=textEditLocal |
|---|
| 3028 | self.editTab.setCurrentWidget(editor) |
|---|
| 3029 | editor.setModified(False) |
|---|
| 3030 | |
|---|
| 3031 | self.checkActions() |
|---|
| 3032 | |
|---|
| 3033 | |
|---|
| 3034 | |
|---|
| 3035 | zoomRange=self.configuration.setting("ZoomRange") |
|---|
| 3036 | |
|---|
| 3037 | dbgMsg("THIS IS ZOOM RANGE=",zoomRange,"\n\n\n\n\n") |
|---|
| 3038 | editor.zoomTo(zoomRange) |
|---|
| 3039 | |
|---|
| 3040 | |
|---|
| 3041 | |
|---|
| 3042 | |
|---|
| 3043 | |
|---|
| 3044 | |
|---|
| 3045 | |
|---|
| 3046 | self.commentStyleDict[editor]=[lexer[1],lexer[2]] |
|---|
| 3047 | |
|---|
| 3048 | |
|---|
| 3049 | |
|---|
| 3050 | QtGui.QApplication.restoreOverrideCursor() |
|---|
| 3051 | |
|---|
| 3052 | self.setCurrentFile(fileName) |
|---|
| 3053 | |
|---|
| 3054 | |
|---|
| 3055 | self.setPropertiesInEditorList(editor,os.path.abspath(fileName),os.path.getmtime(fileName),encoding) |
|---|
| 3056 | |
|---|
| 3057 | |
|---|
| 3058 | self.textChangedHandlers[editor]=ChangedTextHandler(editor,self) |
|---|
| 3059 | editorIndex=self.editTab.indexOf(editor) |
|---|
| 3060 | dbgMsg("CONNECTING EDITOR INDEX=",editorIndex) |
|---|
| 3061 | |
|---|
| 3062 | self.editTab.widget(editorIndex).modificationChanged.connect(self.textChangedHandlers[editor].handleModificationChanged) |
|---|
| 3063 | self.editTab.widget(editorIndex).textChanged.connect(self.textChangedHandlers[editor].handleChangedText) |
|---|
| 3064 | self.editTab.widget(editorIndex).cursorPositionChanged.connect(self.handleCursorPositionChanged) |
|---|
| 3065 | |
|---|
| 3066 | |
|---|
| 3067 | |
|---|
| 3068 | self.updateTextSizeLabel() |
|---|
| 3069 | self.updateEncodingLabel() |
|---|
| 3070 | dbgMsg(" SETTING fileName=",fileName," os.path.getmtime(fileName)=",os.path.getmtime(fileName)) |
|---|
| 3071 | self.statusBar().showMessage("File loaded", 2000) |
|---|
| 3072 | |
|---|
| 3073 | |
|---|
| 3074 | |
|---|
| 3075 | |
|---|
| 3076 | |
|---|
| 3077 | |
|---|
| 3078 | |
|---|
| 3079 | |
|---|
| 3080 | |
|---|
| 3081 | |
|---|
| 3082 | |
|---|
| 3083 | |
|---|
| 3084 | |
|---|
| 3085 | |
|---|
| 3086 | |
|---|
| 3087 | |
|---|
| 3088 | |
|---|
| 3089 | |
|---|
| 3090 | |
|---|
| 3091 | |
|---|
| 3092 | |
|---|
| 3093 | |
|---|
| 3094 | |
|---|
| 3095 | |
|---|
| 3096 | |
|---|
| 3097 | |
|---|
| 3098 | |
|---|
| 3099 | |
|---|
| 3100 | |
|---|
| 3101 | |
|---|
| 3102 | |
|---|
| 3103 | |
|---|
| 3104 | |
|---|
| 3105 | |
|---|
| 3106 | |
|---|
| 3107 | |
|---|
| 3108 | |
|---|
| 3109 | |
|---|
| 3110 | |
|---|
| 3111 | |
|---|
| 3112 | |
|---|
| 3113 | |
|---|
| 3114 | |
|---|
| 3115 | |
|---|
| 3116 | |
|---|
| 3117 | |
|---|
| 3118 | |
|---|
| 3119 | |
|---|
| 3120 | |
|---|
| 3121 | |
|---|
| 3122 | |
|---|
| 3123 | |
|---|
| 3124 | |
|---|
| 3125 | |
|---|
| 3126 | |
|---|
| 3127 | |
|---|
| 3128 | |
|---|
| 3129 | |
|---|
| 3130 | |
|---|
| 3131 | |
|---|
| 3132 | |
|---|
| 3133 | |
|---|
| 3134 | |
|---|
| 3135 | |
|---|
| 3136 | |
|---|
| 3137 | |
|---|
| 3138 | |
|---|
| 3139 | |
|---|
| 3140 | |
|---|
| 3141 | |
|---|
| 3142 | |
|---|
| 3143 | |
|---|
| 3144 | |
|---|
| 3145 | |
|---|
| 3146 | |
|---|
| 3147 | |
|---|
| 3148 | |
|---|
| 3149 | |
|---|
| 3150 | |
|---|
| 3151 | |
|---|
| 3152 | |
|---|
| 3153 | |
|---|
| 3154 | |
|---|
| 3155 | |
|---|
| 3156 | |
|---|
| 3157 | |
|---|
| 3158 | |
|---|
| 3159 | |
|---|
| 3160 | |
|---|
| 3161 | |
|---|
| 3162 | |
|---|
| 3163 | |
|---|
| 3164 | |
|---|
| 3165 | |
|---|
| 3166 | |
|---|
| 3167 | |
|---|
| 3168 | |
|---|
| 3169 | |
|---|
| 3170 | |
|---|
| 3171 | |
|---|
| 3172 | |
|---|
| 3173 | |
|---|
| 3174 | |
|---|
| 3175 | |
|---|
| 3176 | |
|---|
| 3177 | |
|---|
| 3178 | |
|---|
| 3179 | |
|---|
| 3180 | |
|---|
| 3181 | |
|---|
| 3182 | |
|---|
| 3183 | |
|---|
| 3184 | |
|---|
| 3185 | |
|---|
| 3186 | |
|---|
| 3187 | |
|---|
| 3188 | |
|---|
| 3189 | |
|---|
| 3190 | |
|---|
| 3191 | |
|---|
| 3192 | |
|---|
| 3193 | |
|---|
| 3194 | |
|---|
| 3195 | |
|---|
| 3196 | |
|---|
| 3197 | |
|---|
| 3198 | |
|---|
| 3199 | |
|---|
| 3200 | |
|---|
| 3201 | |
|---|
| 3202 | |
|---|
| 3203 | |
|---|
| 3204 | |
|---|
| 3205 | |
|---|
| 3206 | |
|---|
| 3207 | |
|---|
| 3208 | |
|---|
| 3209 | |
|---|
| 3210 | |
|---|
| 3211 | |
|---|
| 3212 | |
|---|
| 3213 | |
|---|
| 3214 | |
|---|
| 3215 | |
|---|
| 3216 | |
|---|
| 3217 | |
|---|
| 3218 | def tabIndexChanged(self,_index): |
|---|
| 3219 | editorTab=self.editTab.widget(_index) |
|---|
| 3220 | |
|---|
| 3221 | self.checkActions() |
|---|
| 3222 | self.updateTextSizeLabel() |
|---|
| 3223 | self.updateEncodingLabel() |
|---|
| 3224 | if editorTab in self.getEditorList(): |
|---|
| 3225 | self.setCurrentFile(self.getEditorFileName(editorTab)) |
|---|
| 3226 | |
|---|
| 3227 | |
|---|
| 3228 | def guessLexer(self,_fileName): |
|---|
| 3229 | |
|---|
| 3230 | fileSplit=os.path.splitext(str(_fileName)) |
|---|
| 3231 | extension=fileSplit[1] |
|---|
| 3232 | |
|---|
| 3233 | |
|---|
| 3234 | if extension in self.extensionLanguageMap.keys(): |
|---|
| 3235 | return self.languageManager.languageLexerDictionary[self.extensionLanguageMap[extension]] |
|---|
| 3236 | |
|---|
| 3237 | |
|---|
| 3238 | |
|---|
| 3239 | if os.path.basename(str(_fileName)).lower()=="cmakelists.txt": |
|---|
| 3240 | return self.languageManager.languageLexerDictionary["CMake"] |
|---|
| 3241 | |
|---|
| 3242 | |
|---|
| 3243 | if os.path.basename(str(_fileName)).lower()=="makefile": |
|---|
| 3244 | return self.languageManager.languageLexerDictionary["Makefile"] |
|---|
| 3245 | |
|---|
| 3246 | |
|---|
| 3247 | |
|---|
| 3248 | |
|---|
| 3249 | return [None,'',None,0,0,QsciScintilla.SCWS_INVISIBLE] |
|---|
| 3250 | |
|---|
| 3251 | |
|---|
| 3252 | |
|---|
| 3253 | |
|---|
| 3254 | |
|---|
| 3255 | |
|---|
| 3256 | |
|---|
| 3257 | |
|---|
| 3258 | |
|---|
| 3259 | |
|---|
| 3260 | |
|---|
| 3261 | |
|---|
| 3262 | |
|---|
| 3263 | |
|---|
| 3264 | |
|---|
| 3265 | |
|---|
| 3266 | |
|---|
| 3267 | |
|---|
| 3268 | |
|---|
| 3269 | |
|---|
| 3270 | |
|---|
| 3271 | |
|---|
| 3272 | |
|---|
| 3273 | |
|---|
| 3274 | |
|---|
| 3275 | |
|---|
| 3276 | |
|---|
| 3277 | |
|---|
| 3278 | |
|---|
| 3279 | |
|---|
| 3280 | |
|---|
| 3281 | |
|---|
| 3282 | |
|---|
| 3283 | |
|---|
| 3284 | |
|---|
| 3285 | |
|---|
| 3286 | |
|---|
| 3287 | |
|---|
| 3288 | |
|---|
| 3289 | |
|---|
| 3290 | |
|---|
| 3291 | |
|---|
| 3292 | |
|---|
| 3293 | |
|---|
| 3294 | |
|---|
| 3295 | |
|---|
| 3296 | |
|---|
| 3297 | |
|---|
| 3298 | |
|---|
| 3299 | |
|---|
| 3300 | |
|---|
| 3301 | |
|---|
| 3302 | |
|---|
| 3303 | |
|---|
| 3304 | |
|---|
| 3305 | |
|---|
| 3306 | |
|---|
| 3307 | |
|---|
| 3308 | |
|---|
| 3309 | |
|---|
| 3310 | |
|---|
| 3311 | def saveFile(self, _fileName,_editor=None): |
|---|
| 3312 | |
|---|
| 3313 | self.deactivateChangeSensing=True |
|---|
| 3314 | |
|---|
| 3315 | QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
|---|
| 3316 | textEditLocal=None |
|---|
| 3317 | if _editor: |
|---|
| 3318 | textEditLocal=_editor |
|---|
| 3319 | else: |
|---|
| 3320 | textEditLocal=self.editTab.currentWidget() |
|---|
| 3321 | |
|---|
| 3322 | encoding='utf-8' |
|---|
| 3323 | txt = unicode(textEditLocal.text()) |
|---|
| 3324 | |
|---|
| 3325 | |
|---|
| 3326 | |
|---|
| 3327 | |
|---|
| 3328 | |
|---|
| 3329 | |
|---|
| 3330 | |
|---|
| 3331 | |
|---|
| 3332 | |
|---|
| 3333 | |
|---|
| 3334 | try: |
|---|
| 3335 | fileNameToEditorMap=self.getFileNameToEditorWidgetMap() |
|---|
| 3336 | |
|---|
| 3337 | |
|---|
| 3338 | editorLocal=None |
|---|
| 3339 | try: |
|---|
| 3340 | editorLocal=fileNameToEditorMap[_fileName] |
|---|
| 3341 | except: |
|---|
| 3342 | dbgMsg("COULD NOT FIND EDITOR FOR FILE NAME=",_fileName) |
|---|
| 3343 | |
|---|
| 3344 | try: |
|---|
| 3345 | encoding=self.getEditorFileEncoding(textEditLocal) |
|---|
| 3346 | |
|---|
| 3347 | except: |
|---|
| 3348 | dbgMsg("COULD NOT FIND ENCODING") |
|---|
| 3349 | |
|---|
| 3350 | |
|---|
| 3351 | txt, encoding = Encoding.encode(txt, encoding) |
|---|
| 3352 | except Encoding.CodingError, e: |
|---|
| 3353 | QtGui.QMessageBox.warning(self, "Twedit", |
|---|
| 3354 | "Cannot write file %s:\n%s." % (_fileName, repr(e))) |
|---|
| 3355 | self.deactivateChangeSensing=False |
|---|
| 3356 | return False |
|---|
| 3357 | |
|---|
| 3358 | |
|---|
| 3359 | try: |
|---|
| 3360 | dbgMsg("SAVE - ENCODING = ",encoding,"\n\n\n\n\n") |
|---|
| 3361 | |
|---|
| 3362 | import codecs |
|---|
| 3363 | fh=codecs.open(_fileName, 'wb',Encoding.normalizeEncodingName(encoding)) |
|---|
| 3364 | |
|---|
| 3365 | |
|---|
| 3366 | Encoding.writeBOM(fh,encoding) |
|---|
| 3367 | fh.write(txt) |
|---|
| 3368 | fh.close() |
|---|
| 3369 | |
|---|
| 3370 | |
|---|
| 3371 | |
|---|
| 3372 | |
|---|
| 3373 | |
|---|
| 3374 | |
|---|
| 3375 | |
|---|
| 3376 | |
|---|
| 3377 | |
|---|
| 3378 | |
|---|
| 3379 | |
|---|
| 3380 | |
|---|
| 3381 | |
|---|
| 3382 | |
|---|
| 3383 | |
|---|
| 3384 | |
|---|
| 3385 | |
|---|
| 3386 | |
|---|
| 3387 | except IOError, why: |
|---|
| 3388 | QtGui.QMessageBox.warning(self, "Twedit", |
|---|
| 3389 | "Cannot write file %s:\n%s." % (_fileName, why)) |
|---|
| 3390 | self.deactivateChangeSensing=False |
|---|
| 3391 | return False |
|---|
| 3392 | |
|---|
| 3393 | |
|---|
| 3394 | QtGui.QApplication.restoreOverrideCursor() |
|---|
| 3395 | |
|---|
| 3396 | dbgMsg("SAVE FILE EDITOR=",_editor,"\n\n\n\n") |
|---|
| 3397 | if _editor: |
|---|
| 3398 | |
|---|
| 3399 | self.setPropertiesInEditorList(_editor,_fileName,os.path.getmtime(_fileName),encoding) |
|---|
| 3400 | else: |
|---|
| 3401 | self.setCurrentFile(_fileName) |
|---|
| 3402 | |
|---|
| 3403 | self.setPropertiesInEditorList(self.editTab.currentWidget(),_fileName,os.path.getmtime(_fileName),encoding) |
|---|
| 3404 | self.statusBar().showMessage("File saved", 2000) |
|---|
| 3405 | if _editor: |
|---|
| 3406 | textEditLocal.setModified(False) |
|---|
| 3407 | |
|---|
| 3408 | index=self.editTab.indexOf(textEditLocal) |
|---|
| 3409 | self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3410 | else : |
|---|
| 3411 | self.editTab.currentWidget().setModified(False) |
|---|
| 3412 | |
|---|
| 3413 | index=self.editTab.indexOf(self.editTab.currentWidget()) |
|---|
| 3414 | self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3415 | self.deactivateChangeSensing=False |
|---|
| 3416 | return True |
|---|
| 3417 | |
|---|
| 3418 | def setCurrentFile(self, fileName): |
|---|
| 3419 | self.curFile = fileName |
|---|
| 3420 | |
|---|
| 3421 | self.setWindowModified(False) |
|---|
| 3422 | |
|---|
| 3423 | if self.curFile: |
|---|
| 3424 | |
|---|
| 3425 | shownName = self.curFile |
|---|
| 3426 | else: |
|---|
| 3427 | shownName = 'untitled.txt' |
|---|
| 3428 | |
|---|
| 3429 | self.setWindowTitle("[*]%s - CC3D-Twedit" % shownName) |
|---|
| 3430 | |
|---|
| 3431 | def strippedName(self, fullFileName): |
|---|
| 3432 | return QtCore.QFileInfo(fullFileName).fileName() |
|---|
| 3433 | |
|---|
| 3434 | def __createDockWindow(self, name): |
|---|
| 3435 | """ |
|---|
| 3436 | Private method to create a dock window with common properties. |
|---|
| 3437 | |
|---|
| 3438 | @param name object name of the new dock window (string or QString) |
|---|
| 3439 | @return the generated dock window (QDockWindow) |
|---|
| 3440 | """ |
|---|
| 3441 | dock = QDockWidget(self) |
|---|
| 3442 | dock.setObjectName(name) |
|---|
| 3443 | |
|---|
| 3444 | return dock |
|---|
| 3445 | |
|---|
| 3446 | def __setupDockWindow(self, dock, where, widget, caption, showFlag=False): |
|---|
| 3447 | """ |
|---|
| 3448 | Private method to configure the dock window created with __createDockWindow(). |
|---|
| 3449 | |
|---|
| 3450 | @param dock the dock window (QDockWindow) |
|---|
| 3451 | @param where dock area to be docked to (Qt.DockWidgetArea) |
|---|
| 3452 | @param widget widget to be shown in the dock window (QWidget) |
|---|
| 3453 | @param caption caption of the dock window (string or QString) |
|---|
| 3454 | """ |
|---|
| 3455 | if caption is None: |
|---|
| 3456 | caption = QString() |
|---|
| 3457 | self.addDockWidget(where, dock) |
|---|
| 3458 | dock.setWidget(widget) |
|---|
| 3459 | dock.hide() |
|---|
| 3460 | dock.setWindowTitle(caption) |
|---|
| 3461 | if showFlag: |
|---|
| 3462 | dock.show() |
|---|
| 3463 | |
|---|
| 3464 | |
|---|
| 3465 | |
|---|
| 3466 | |
|---|
| 3467 | |
|---|
| 3468 | |
|---|
| 3469 | |
|---|
| 3470 | |
|---|
| 3471 | |
|---|
| 3472 | """ |
|---|
| 3473 | old implementation of the saveFile slot |
|---|
| 3474 | # def saveFile(self, fileName,_editor=None): |
|---|
| 3475 | # # self.deactivateChangeSensing=True |
|---|
| 3476 | # file = QtCore.QFile(fileName) |
|---|
| 3477 | # if not file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): |
|---|
| 3478 | # QtGui.QMessageBox.warning(self, "Application", |
|---|
| 3479 | # "Cannot write file %s:\n%s." % (fileName, file.errorString())) |
|---|
| 3480 | # # self.deactivateChangeSensing=False |
|---|
| 3481 | # return False |
|---|
| 3482 | |
|---|
| 3483 | # outf = QtCore.QTextStream(file) |
|---|
| 3484 | # QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
|---|
| 3485 | # textEditLocal=None |
|---|
| 3486 | # if _editor: |
|---|
| 3487 | # textEditLocal=_editor |
|---|
| 3488 | # else: |
|---|
| 3489 | # textEditLocal=self.editTab.currentWidget() |
|---|
| 3490 | |
|---|
| 3491 | # outf << textEditLocal.text().toUtf8() |
|---|
| 3492 | # QtGui.QApplication.restoreOverrideCursor() |
|---|
| 3493 | |
|---|
| 3494 | # dbgMsg("SAVE FILE EDITOR=",_editor,"\n\n\n\n") |
|---|
| 3495 | # if _editor: |
|---|
| 3496 | # self.fileDict[_editor]=[fileName,os.path.getmtime(fileName)] # saving new name and new modification time |
|---|
| 3497 | # else: |
|---|
| 3498 | # self.setCurrentFile(fileName) |
|---|
| 3499 | # self.fileDict[self.editTab.currentWidget()]=[fileName,os.path.getmtime(fileName)] # saving new name and new modification time |
|---|
| 3500 | # self.statusBar().showMessage("File saved", 2000) |
|---|
| 3501 | # if _editor: |
|---|
| 3502 | # textEditLocal.setModified(False) |
|---|
| 3503 | |
|---|
| 3504 | # index=self.editTab.indexOf(textEditLocal) |
|---|
| 3505 | # self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3506 | # else : |
|---|
| 3507 | # self.editTab.currentWidget().setModified(False) |
|---|
| 3508 | |
|---|
| 3509 | # index=self.editTab.indexOf(self.editTab.currentWidget()) |
|---|
| 3510 | # self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3511 | |
|---|
| 3512 | # # self.deactivateChangeSensing=False |
|---|
| 3513 | # return True |
|---|
| 3514 | |
|---|
| 3515 | def saveFile(self, _fileName,_editor=None): |
|---|
| 3516 | # self.deactivateChangeSensing=True |
|---|
| 3517 | # # # # file=None |
|---|
| 3518 | |
|---|
| 3519 | # # # # try: |
|---|
| 3520 | # # # # file = open(str(_fileName),'w') |
|---|
| 3521 | |
|---|
| 3522 | # # # # except: |
|---|
| 3523 | # # # # # self.statusBar().message('Could not write to %s' % (self._filename),2000) |
|---|
| 3524 | # # # # QtGui.QMessageBox.warning(self, "Application", |
|---|
| 3525 | # # # # "Cannot write file %s:\n%s." % (_fileName, "Please check if you have permissions to write")) |
|---|
| 3526 | # # # # # self.deactivateChangeSensing=False |
|---|
| 3527 | # # # # return False |
|---|
| 3528 | |
|---|
| 3529 | |
|---|
| 3530 | # file = QtCore.QFile(_fileName) |
|---|
| 3531 | |
|---|
| 3532 | # if not file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): |
|---|
| 3533 | # QtGui.QMessageBox.warning(self, "Application", |
|---|
| 3534 | # "Cannot write file %s:\n%s." % (_fileName, file.errorString())) |
|---|
| 3535 | # # self.deactivateChangeSensing=False |
|---|
| 3536 | # return False |
|---|
| 3537 | |
|---|
| 3538 | # outf = QtCore.QTextStream(file) |
|---|
| 3539 | QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
|---|
| 3540 | textEditLocal=None |
|---|
| 3541 | if _editor: |
|---|
| 3542 | textEditLocal=_editor |
|---|
| 3543 | else: |
|---|
| 3544 | textEditLocal=self.editTab.currentWidget() |
|---|
| 3545 | |
|---|
| 3546 | # # # # # outf << textEditLocal.text() |
|---|
| 3547 | # # # # dbgMsg("ENCODING is UTF8=",textEditLocal.isUtf8()) |
|---|
| 3548 | # # # # # txt,encoding=self.decode(textEditLocal.text()) |
|---|
| 3549 | # # # # txt=textEditLocal.text() |
|---|
| 3550 | # # # # # txt=textEditLocal.text() |
|---|
| 3551 | |
|---|
| 3552 | # # # # # # txt=unicode(txt, 'utf-8') |
|---|
| 3553 | # # # # # # it is important to do this replacement on QString as returned by text() function |
|---|
| 3554 | # # # # # # otherwise CR LF combo will end up being writte as CR CR LF introducing extra line for every CR LF character |
|---|
| 3555 | # # # # dbgMsg("FOUND cr lf=",txt.contains("\r\n")) |
|---|
| 3556 | # # # # dbgMsg("FOUND lf=",txt.contains("\n")) |
|---|
| 3557 | # # # # dbgMsg("FOUND cr=",txt.contains("\r")) |
|---|
| 3558 | # # # # txt.replace("\r\n","\n") |
|---|
| 3559 | # # # # dbgMsg("txt.toAscii()=",txt.toAscii()) |
|---|
| 3560 | # # # # byteArray=txt.toAscii() |
|---|
| 3561 | # # # # dbgMsg("BYTE ARRAY LENGTH=",byteArray.count()," content=",byteArray) |
|---|
| 3562 | # # # # # txt.replace("\n","") |
|---|
| 3563 | # # # # # dbgMsg("txt=",txt) |
|---|
| 3564 | # # # # # txt=str(txt) |
|---|
| 3565 | # # # # file.write("a\nb\nc\nd") |
|---|
| 3566 | # # # # # file.write(txt.toAscii()) |
|---|
| 3567 | # # # # # txt=unicode(textEditLocal.text()) |
|---|
| 3568 | # # # # # txt.encode('ascii') |
|---|
| 3569 | # # # # # txt=textEditLocal.text() |
|---|
| 3570 | # # # # # file.write(txt) |
|---|
| 3571 | # # # # file.close() |
|---|
| 3572 | |
|---|
| 3573 | file = QtCore.QFile(_fileName) |
|---|
| 3574 | # if not file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): |
|---|
| 3575 | if not file.open(QtCore.QFile.WriteOnly ): |
|---|
| 3576 | QtGui.QMessageBox.warning(self, "Application", |
|---|
| 3577 | "Cannot write file %s:\n%s." % (fileName, file.errorString())) |
|---|
| 3578 | # self.deactivateChangeSensing=False |
|---|
| 3579 | return False |
|---|
| 3580 | |
|---|
| 3581 | |
|---|
| 3582 | # file.open(QIODevice.WriteOnly) |
|---|
| 3583 | # byteArray=QString("\r\n").toUtf8() |
|---|
| 3584 | # byteArray=QString("\r\n").toAscii() |
|---|
| 3585 | txt=textEditLocal.text() |
|---|
| 3586 | byteArray=txt.toAscii() |
|---|
| 3587 | file.write(byteArray) |
|---|
| 3588 | file.close() |
|---|
| 3589 | |
|---|
| 3590 | QtGui.QApplication.restoreOverrideCursor() |
|---|
| 3591 | |
|---|
| 3592 | dbgMsg("SAVE FILE EDITOR=",_editor,"\n\n\n\n") |
|---|
| 3593 | if _editor: |
|---|
| 3594 | self.fileDict[_editor]=[_fileName,os.path.getmtime(_fileName)] # saving new name and new modification time |
|---|
| 3595 | else: |
|---|
| 3596 | self.setCurrentFile(_fileName) |
|---|
| 3597 | self.fileDict[self.editTab.currentWidget()]=[_fileName,os.path.getmtime(_fileName)] # saving new name and new modification time |
|---|
| 3598 | self.statusBar().showMessage("File saved", 2000) |
|---|
| 3599 | if _editor: |
|---|
| 3600 | textEditLocal.setModified(False) |
|---|
| 3601 | |
|---|
| 3602 | index=self.editTab.indexOf(textEditLocal) |
|---|
| 3603 | self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3604 | else : |
|---|
| 3605 | self.editTab.currentWidget().setModified(False) |
|---|
| 3606 | |
|---|
| 3607 | index=self.editTab.indexOf(self.editTab.currentWidget()) |
|---|
| 3608 | self.editTab.setTabIcon(index,QtGui.QIcon(':/icons/document-clean.png')) |
|---|
| 3609 | |
|---|
| 3610 | # self.deactivateChangeSensing=False |
|---|
| 3611 | return True |
|---|
| 3612 | """ |
|---|