Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
stable
filelistview: Show a different context menu for subrepos and regular files
Currently the context menu for subrepos is empty (i.e. no context menu). The patch has been tested with a dummy context menu and it works (i.e. it shows the dummy context menu).
Proper subrepo context menu items will be added in a future patch. This patch requries accessing ctx.substate each time that the context menu is triggered. I assume that the cost should be negligible since ctx.substate must have been populated earlier on when the file list was generated.
# Copyright (c) 2009-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.importosfrom tortoisehg.util import hglib
from tortoisehg.hgqt.i18n import _
from tortoisehg.hgqt import qtlib
-from tortoisehg.hgqt.filedialogs import FileLogDialog, FileDiffDialog+from tortoisehg.hgqt.filedialogs import FileLogDialog, FileDiffDialog
from tortoisehg.hgqt import visdiff, wctxactions, revert
from PyQt4.QtCore import *
fromPyQt4.QtGuiimport*classHgFileListView(QTableView):""" A QTableView for displaying a HgFileListModel """ fileRevSelected = pyqtSignal(object, object, object)
clearDisplay = pyqtSignal()
-contextmenu = None
+filecontextmenu = None
+ subrepocontextmenu = None def __init__(self, parent=None):
QTableView.__init__(self, parent)
self.setShowGrid(False)self.horizontalHeader().hide()self.verticalHeader().hide()self.verticalHeader().setDefaultSectionSize(20)self.setSelectionMode(QAbstractItemView.SingleSelection)self.setSelectionBehavior(QAbstractItemView.SelectRows)self.setTextElideMode(Qt.ElideLeft)self.createActions()self.doubleClicked.connect(self.fileActivated)self._diff_dialogs={}self._nav_dialogs={}defsetModel(self,model):QTableView.setModel(self,model)model.layoutChanged.connect(self.layoutChanged)model.contextChanged.connect(self.contextChanged)self.selectionModel().currentRowChanged.connect(self.fileSelected)self.horizontalHeader().setResizeMode(1,QHeaderView.Stretch)self.actionShowAllMerge.setChecked(False)self.actionShowAllMerge.toggled.connect(model.toggleFullFileList)self.actionSecondParent.setChecked(False)self.actionSecondParent.toggled.connect(model.toggleSecondParent)ifmodel._ctxisnotNone:self.contextChanged(model._ctx)defcontextChanged(self,ctx):real=type(ctx.rev())isintwd=ctx.rev()isNoneforactin['navigate','diffnavigate','ldiff','edit']:self._actions[act].setEnabled(real)foractin['diff','revert']:self._actions[act].setEnabled(realorwd)iflen(ctx.parents())==2:self.actionShowAllMerge.setEnabled(True)self.actionSecondParent.setEnabled(True)else:self.actionShowAllMerge.setEnabled(False)self.actionSecondParent.setEnabled(False)defcurrentFile(self):index=self.currentIndex()returnself.model().fileFromIndex(index)deflayoutChanged(self):'file model has new contents'index=self.currentIndex()count=len(self.model())ifindex.row()==-1:# index is changing, fileSelected() called for usself.selectRow(0)elifindex.row()>=count:ifcount:# index is changing, fileSelected() called for usself.selectRow(count-1)else:self.clearDisplay.emit()self.actionSecondParent.setEnabled(False)else:# redisplay previous rowself.fileSelected()deffileSelected(self,index=None,*args):ifindexisNone:index=self.currentIndex()data=self.model().dataFromIndex(index)ifdata:fromRev=self.model().revFromIndex(index)self.fileRevSelected.emit(data['path'],fromRev,data['status'])self.actionSecondParent.setEnabled(data['wasmerged'])else:self.clearDisplay.emit()self.actionSecondParent.setEnabled(False)defselectFile(self,filename):'Select given file, if found, else the first file'index=self.model().indexFromFile(filename)ifindex:self.setCurrentIndex(index)self.fileSelected(index)elifself.model().count():self.selectRow(0)deffileActivated(self,index,alternate=False):selFile=self.model().fileFromIndex(index)ifalternate:self.navigate(selFile)else:self.diffNavigate(selFile)defnavigate(self,filename=None):self._navigate(filename,FileLogDialog,self._nav_dialogs)defdiffNavigate(self,filename=None):self._navigate(filename,FileDiffDialog,self._diff_dialogs)defvdiff(self):filename=self.currentFile()iffilenameisNone:returnmodel=self.model()pats=[filename]opts={'change':model._ctx.rev()}dlg=visdiff.visualdiff(model.repo.ui,model.repo,pats,opts)ifdlg:dlg.exec_()defvdifflocal(self):filename=self.currentFile()iffilenameisNone:returnmodel=self.model()pats=[filename]asserttype(model._ctx.rev())isintopts={'rev':['rev(%d)'%(model._ctx.rev())]}dlg=visdiff.visualdiff(model.repo.ui,model.repo,pats,opts)ifdlg:dlg.exec_()defeditfile(self):filename=self.currentFile()iffilenameisNone:returnmodel=self.model()repo=model.reporev=model._ctx.rev()ifrevisNone:files=[repo.wjoin(filename)]wctxactions.edit(self,repo.ui,repo,files)else:base,_=visdiff.snapshot(repo,[filename],repo[rev])files=[os.path.join(base,filename)]wctxactions.edit(self,repo.ui,repo,files)defeditlocal(self):filename=self.currentFile()iffilenameisNone:returnmodel=self.model()repo=model.repopath=repo.wjoin(filename)wctxactions.edit(self,repo.ui,repo,[path])defrevertfile(self):filename=self.currentFile()iffilenameisNone:returnmodel=self.model()repo=model.reporev=model._ctx.rev()ifrevisNone:rev=model._ctx.p1().rev()dlg=revert.RevertDialog(repo,filename,rev,self)dlg.exec_()def_navigate(self,filename,dlgclass,dlgdict):ifnotfilename:filename=self.currentFile()model=self.model()iffilenameisnotNoneandlen(model.repo.file(filename))>0:iffilenamenotindlgdict:dlg=dlgclass(model.repo,filename,repoviewer=self.window())dlgdict[filename]=dlgufname=hglib.tounicode(filename)dlg.setWindowTitle(_('Hg file log viewer - %s')%ufname)dlg.setWindowIcon(qtlib.geticon('hg-log'))dlg=dlgdict[filename]dlg.goto(model._ctx.rev())dlg.show()dlg.raise_()dlg.activateWindow()defcreateActions(self):self.actionShowAllMerge=QAction(_('Show All'),self)self.actionShowAllMerge.setToolTip(_('Toggle display of all files and the direction they were merged'))self.actionShowAllMerge.setCheckable(True)self.actionShowAllMerge.setChecked(False)self.actionSecondParent=QAction(_('Other'),self)self.actionSecondParent.setToolTip(_('Toggle display of diffs to second (other) parent'))self.actionSecondParent.setCheckable(True)self.actionSecondParent.setChecked(False)self.actionSecondParent.setEnabled(False)self._actions={}forname,desc,icon,key,tip,cbin[('navigate',_('File history'),'hg-log','Shift+Return',_('Show the history of the selected file'),self.navigate),('diffnavigate',_('Compare file revisions'),'compare-files',None,_('Compare revisions of the selected file'),self.diffNavigate),('diff',_('Visual Diff'),'visualdiff','Ctrl+D',_('View file changes in external diff tool'),self.vdiff),('ldiff',_('Visual Diff to Local'),'ldiff','Shift+Ctrl+D',_('View changes to current in external diff tool'),self.vdifflocal),('edit',_('View at Revision'),'view-at-revision','Alt+Ctrl+E',_('View file as it appeared at this revision'),self.editfile),('ledit',_('Edit Local'),'edit-file','Shift+Ctrl+E',_('Edit current file in working copy'),self.editlocal),('revert',_('Revert to Revision'),'hg-revert','Alt+Ctrl+T',_('Revert file(s) to contents at this revision'),self.revertfile),]:act=QAction(desc,self)ificon:act.setIcon(qtlib.getmenuicon(icon))ifkey:act.setShortcut(key)iftip:act.setStatusTip(tip)ifcb:act.triggered.connect(cb)self._actions[name]=act self.addAction(act)
def contextMenuEvent(self, event):
- if not self.contextmenu:- self.contextmenu = QMenu(self)
- for act in ['diff', 'ldiff', 'edit', 'ledit', 'revert',- 'navigate', 'diffnavigate']:+ itemissubrepo = self.currentFile() in self.model()._ctx.substate.keys()+ # Subrepos and regular items have different context menus+ if itemissubrepo:+ contextmenu = self.subrepocontextmenu+ actionlist = []+ else:+ contextmenu = self.filecontextmenu+ actionlist = ['diff', 'ldiff', 'edit', 'ledit', 'revert',+ 'navigate', 'diffnavigate']+ if not contextmenu:+contextmenu = QMenu(self)
+ for act in actionlist: if act:
-self.contextmenu.addAction(self._actions[act])
+ contextmenu.addAction(self._actions[act])
else:
-self.contextmenu.addSeparator()
-self.contextmenu.exec_(event.globalPos())
+ contextmenu.addSeparator()
+ contextmenu.exec_(event.globalPos())
def resizeEvent(self, event):
if self.model() is not None:
vp_width=self.viewport().width()col_widths=[self.columnWidth(i) \
foriinrange(1,self.model().columnCount())]col_width=vp_width-sum(col_widths)col_width=max(col_width,50)self.setColumnWidth(0,col_width)QTableView.resizeEvent(self,event)### Mouse drag#defselectedRows(self):returnself.selectionModel().selectedRows()defdragObject(self):ctx=self.model()._ctxiftype(ctx.rev())==str:returnpaths=[]forindexinself.selectedRows():paths.append(self.model().fileFromIndex(index))ifnotpaths:returnifctx.rev()isNone:base=ctx._repo.rootelse:base,_=visdiff.snapshot(ctx._repo,paths,ctx)urls=[]forpathinpaths:urls.append(QUrl.fromLocalFile(os.path.join(base,path)))ifurls:d=QDrag(self)m=QMimeData()m.setUrls(urls)d.setMimeData(m)d.start(Qt.CopyAction)defmousePressEvent(self,event):self.pressPos=event.pos()self.pressTime=QTime.currentTime()returnQTableView.mousePressEvent(self,event)defmouseMoveEvent(self,event):d=event.pos()-self.pressPosifd.manhattanLength()<QApplication.startDragDistance():returnQTableView.mouseMoveEvent(self,event)elapsed=self.pressTime.msecsTo(QTime.currentTime())ifelapsed<QApplication.startDragTime():returnQTableView.mouseMoveEvent(self,event)self.dragObject()returnQTableView.mouseMoveEvent(self,event)
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.