Kiln » TortoiseHg » TortoiseHg
Clone URL:  
manifestdialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*- # Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ Qt4 dialogs to display hg revisions of a file """ import os.path as osp from mercurial import util from mercurial.revlog import LookupError from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.Qsci import QsciScintilla from tortoisehg.util import paths, thgrepo from tortoisehg.util.hglib import tounicode from tortoisehg.hgqt.dialogmixin import HgDialogMixin from tortoisehg.hgqt.manifestmodel import ManifestModel from tortoisehg.hgqt.lexers import get_lexer from tortoisehg.hgqt.ManifestDialog_ui import Ui_ManifestDialog connect = QObject.connect disconnect = QObject.disconnect nullvariant = QVariant() class ManifestDialog(QMainWindow, Ui_ManifestDialog, HgDialogMixin): """ Qt4 dialog to display all files of a repo at a given revision """ def __init__(self, repo, noderev): self.repo = repo QMainWindow.__init__(self) HgDialogMixin.__init__(self, self.repo.ui) self.setWindowTitle('Hg manifest viewer - %s:%s' % (repo.root, noderev)) # hg repo self.repo = repo self.rev = noderev self.setupModels() self.createActions() self.setupTextview() self._readsettings() def setupModels(self): self.treemodel = ManifestModel(self.repo, self.rev) self.treeView.setModel(self.treemodel) connect(self.treeView.selectionModel(), SIGNAL('currentChanged(const QModelIndex &, const QModelIndex &)'), self.fileSelected) def createActions(self): pass def setupTextview(self): lay = QHBoxLayout(self.mainFrame) lay.setSpacing(0) lay.setContentsMargins(0,0,0,0) sci = QsciScintilla(self.mainFrame) lay.addWidget(sci) sci.setMarginLineNumbers(1, True) sci.setMarginWidth(1, '000') sci.setReadOnly(True) sci.setFont(self._font) sci.setUtf8(True) sci.SendScintilla(sci.SCI_SETSELEOLFILLED, True) self.textView = sci def fileSelected(self, index, *args): if not index.isValid(): return path = self.treemodel.pathFromIndex(index) try: fc = self.repo.changectx(self.rev).filectx(path) except LookupError: # may occur when a directory is selected self.textView.setMarginWidth(1, '00') self.textView.setText('') return if fc.size() > self.max_file_size: data = "file too big" else: # return the whole file data = fc.data() if util.binary(data): data = "binary file" else: data = tounicode(data) lexer = get_lexer(path, data, self.repo.ui) if lexer: lexer.setFont(self._font) self.textView.setLexer(lexer) self._cur_lexer = lexer nlines = data.count('\n') self.textView.setMarginWidth(1, str(nlines)+'00') self.textView.setText(data) def setCurrentFile(self, filename): index = QModelIndex() path = filename.split(osp.sep) for p in path: self.treeView.expand(index) for row in range(self.treemodel.rowCount(index)): newindex = self.treemodel.index(row, 0, index) if newindex.internalPointer().data(0) == p: index = newindex break self.treeView.setCurrentIndex(index) def closeEvent(self, event): self._writesettings() super(ManifestDialog, self).closeEvent(event) def _readsettings(self): s = QSettings() self.restoreGeometry(s.value('manifest/geom').toByteArray()) self.splitter.restoreState(s.value('manifest/splitter').toByteArray()) def _writesettings(self): s = QSettings() s.setValue('manifest/geom', self.saveGeometry()) s.setValue('manifest/splitter', self.splitter.saveState()) def run(ui, *pats, **opts): repo = opts.get('repo') or thgrepo.repository(ui, paths.find_root()) return ManifestDialog(repo, opts.get('rev'))