Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

qscilib: move fileEditor to qscilib

It drops dependency to Qsci from qtlib.

Changeset ece8364b55a6

Parent a6f5f51aca61

by Yuya Nishihara

Changes to 4 files · Browse files at ece8364b55a6 Showing diff from parent a6f5f51aca61 Diff from another changeset...

 
16
17
18
19
 
20
21
22
 
194
195
196
197
 
198
199
200
 
16
17
18
 
19
20
21
22
 
194
195
196
 
197
198
199
200
@@ -16,7 +16,7 @@
 from tortoisehg.hgqt.i18n import _  from tortoisehg.util import shlib, hglib, paths   -from tortoisehg.hgqt import qtlib, thgrepo +from tortoisehg.hgqt import qtlib, qscilib, thgrepo    class HgignoreDialog(QDialog):   'Edit a repository .hgignore file' @@ -194,7 +194,7 @@
  self.refresh()     def editClicked(self): - if qtlib.fileEditor(self.ignorefile) == QDialog.Accepted: + if qscilib.fileEditor(self.ignorefile) == QDialog.Accepted:   self.refresh()     def addEntry(self):
 
1
2
 
3
4
5
 
9
10
11
 
12
13
14
15
16
17
 
18
19
20
 
403
404
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
 
10
11
12
13
14
15
16
17
18
 
19
20
21
22
 
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
@@ -1,5 +1,6 @@
 # qscilib.py - Utility codes for QsciScintilla  # +# Copyright 2010 Steve Borho <steve@borho.org>  # Copyright 2010 Yuya Nishihara <yuya@tcha.org>  #  # This software may be used and distributed according to the terms of the @@ -9,12 +10,13 @@
   from mercurial import util   +from tortoisehg.util import hglib  from tortoisehg.hgqt import qtlib  from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import *  from PyQt4.QtGui import * -from PyQt4.Qsci import QsciScintilla +from PyQt4.Qsci import *    class _SciImSupport(object):   """Patch for QsciScintilla to implement improved input method support @@ -403,3 +405,44 @@
  if util.any(event.matches(e) for e in self._keyseqs):   return True   return False + +def fileEditor(filename, **opts): + 'Open a simple modal file editing dialog' + dialog = QDialog() + dialog.setWindowFlags(dialog.windowFlags() & ~Qt.WindowContextHelpButtonHint) + vbox = QVBoxLayout() + dialog.setLayout(vbox) + editor = QsciScintilla() + editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) + editor.setMarginLineNumbers(1, True) + editor.setMarginWidth(1, '000') + if opts.get('foldable'): + editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) + vbox.addWidget(editor) + BB = QDialogButtonBox + bb = QDialogButtonBox(BB.Save|BB.Cancel) + bb.accepted.connect(dialog.accept) + bb.rejected.connect(dialog.reject) + vbox.addWidget(bb) + lexer = QsciLexerProperties() + editor.setLexer(lexer) + s = QSettings() + ret = QDialog.Rejected + try: + contents = open(filename, 'rb').read() + dialog.setWindowTitle(filename) + geomname = 'editor-geom' + editor.setText(contents) + editor.setUtf8(True) + editor.setModified(False) + dialog.restoreGeometry(s.value(geomname).toByteArray()) + ret = dialog.exec_() + if ret == QDialog.Accepted: + f = util.atomictempfile(filename, 'wb', createmode=None) + f.write(hglib.fromunicode(editor.text())) + f.rename() + s.setValue(geomname, dialog.saveGeometry()) + except EnvironmentError, e: + qtlib.WarningMsgBox(_('Unable to read/write config file'), + hglib.tounicode(e), parent=dialog) + return ret
 
12
13
14
15
16
 
17
18
19
20
21
22
 
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
 
12
13
14
 
 
15
16
17
 
18
19
20
 
461
462
463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
465
466
@@ -12,11 +12,9 @@
   from PyQt4.QtCore import *  from PyQt4.QtGui import * -from PyQt4.Qsci import * -from mercurial import extensions, util +from mercurial import extensions    from tortoisehg.util import hglib, paths -from tortoisehg.hgqt.i18n import _  from hgext.color import _styles    tmproot = None @@ -463,47 +461,6 @@
  def set_enable(self, *args, **kargs):   self.set_prop('setEnabled', *args, **kargs)   -def fileEditor(filename, **opts): - 'Open a simple modal file editing dialog' - dialog = QDialog() - dialog.setWindowFlags(dialog.windowFlags() & ~Qt.WindowContextHelpButtonHint) - vbox = QVBoxLayout() - dialog.setLayout(vbox) - editor = QsciScintilla() - editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) - editor.setMarginLineNumbers(1, True) - editor.setMarginWidth(1, '000') - if opts.get('foldable'): - editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) - vbox.addWidget(editor) - BB = QDialogButtonBox - bb = QDialogButtonBox(BB.Save|BB.Cancel) - bb.accepted.connect(dialog.accept) - bb.rejected.connect(dialog.reject) - vbox.addWidget(bb) - lexer = QsciLexerProperties() - editor.setLexer(lexer) - s = QSettings() - ret = QDialog.Rejected - try: - contents = open(filename, 'rb').read() - dialog.setWindowTitle(filename) - geomname = 'editor-geom' - editor.setText(contents) - editor.setUtf8(True) - editor.setModified(False) - dialog.restoreGeometry(s.value(geomname).toByteArray()) - ret = dialog.exec_() - if ret == QDialog.Accepted: - f = util.atomictempfile(filename, 'wb', createmode=None) - f.write(hglib.fromunicode(editor.text())) - f.rename() - s.setValue(geomname, dialog.saveGeometry()) - except EnvironmentError, e: - WarningMsgBox(_('Unable to read/write config file'), - hglib.tounicode(e), parent=dialog) - return ret -  class SharedWidget(QWidget):   """Share a single widget by many parents  
 
11
12
13
14
 
15
16
17
 
716
717
718
719
 
720
721
722
 
11
12
13
 
14
15
16
17
 
716
717
718
 
719
720
721
722
@@ -11,7 +11,7 @@
   from tortoisehg.util import hglib, settings, paths, wconfig  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, thgrepo +from tortoisehg.hgqt import qtlib, qscilib, thgrepo    from PyQt4.QtCore import *  from PyQt4.QtGui import * @@ -716,7 +716,7 @@
  self.applyChanges()   elif ret == 2:   return - if qtlib.fileEditor(self.fn, foldable=True) == QDialog.Accepted: + if qscilib.fileEditor(self.fn, foldable=True) == QDialog.Accepted:   self.refresh()     def refresh(self, *args):