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.
# browse.py - TortoiseHg's repository browser## Copyright 2009 Steve Borho <steve@borho.org>## This software may be used and distributed according to the terms of the# GNU General Public License version 2, incorporated herein by reference.importosimportgtkimportgobjectimportpangofrommercurialimporthg,ui,cmdutilfromtortoisehg.util.i18nimport_fromtortoisehg.utilimporthglib,paths,shlib,menuthgfromtortoisehg.hgtkimporthgcmd,gtklib,gdialogfolderxpm=["17 16 7 1"," c #000000",". c #808000","X c yellow","o c #808080","O c #c0c0c0","+ c white","@ c None","@@@@@@@@@@@@@@@@@","@@@@@@@@@@@@@@@@@","@@+XXXX.@@@@@@@@@","@+OOOOOO.@@@@@@@@","@+OXOXOXOXOXOXO. ","@+XOXOXOXOXOXOX. ","@+OXOXOXOXOXOXO. ","@+XOXOXOXOXOXOX. ","@+OXOXOXOXOXOXO. ","@+XOXOXOXOXOXOX. ","@+OXOXOXOXOXOXO. ","@+XOXOXOXOXOXOX. ","@+OOOOOOOOOOOOO. ","@ ","@@@@@@@@@@@@@@@@@","@@@@@@@@@@@@@@@@@"]folderpb=gtk.gdk.pixbuf_new_from_xpm_data(folderxpm)filexpm=["12 12 3 1"," c #000000",". c #ffff04","X c #b2c0dc","X XXX","X ...... XXX","X ...... X","X . ... X","X ........ X","X . .... X","X ........ X","X . .. X","X ........ X","X . .. X","X ........ X","X X"]filepb=gtk.gdk.pixbuf_new_from_xpm_data(filexpm)classdirnode(object):def__init__(self):self.subdirs={}self.files=[]self.statuses=set()defaddfile(self,filename,st):self.files.append((filename,st))self.addstatus(st)defaddsubdir(self,dirname):self.subdirs[dirname]=dirnode()defaddstatus(self,st):self.statuses.add(st)class BrowsePane(gtk.TreeView):
'Dialog for browsing repo.status() output'
- def __init__(self, entry):
+ def __init__(self, callback):
gtk.TreeView.__init__(self)
- self.entry = entry+ self.callback = callback+ self.cachedroot = None self.menu = menuthg.menuThg()
fm = gtk.ListStore(str, # canonical path
bool, # Checked
str,# basename-UTF8bool,# Mbool,# Abool,# Rbool,# !bool,# ?bool,# Ibool,# Cbool)# isfileself.set_model(fm)self.set_headers_visible(False)self.set_reorderable(True)self.connect('popup-menu',self.popupmenu)self.connect('button-release-event',self.buttonrelease)self.connect('row-activated',self.rowactivated)self.get_selection().set_mode(gtk.SELECTION_MULTIPLE)self.set_reorderable(False)self.set_enable_search(True)ifhasattr(self,'set_rubber_banding'):self.set_rubber_banding(True)col=gtk.TreeViewColumn(_('status'))self.append_column(col)iconw,iconh=gtk.icon_size_lookup(gtk.ICON_SIZE_SMALL_TOOLBAR)defpackpixmap(ico,id):iconpath=paths.get_tortoise_icon(ico)ificonpath==None:raise(_("could not open icon file '%s' (check install)")%ico)pm=gtk.gdk.pixbuf_new_from_file_at_size(iconpath,iconw,iconh)cell=gtk.CellRendererPixbuf()cell.set_property('pixbuf',pm)col.pack_start(cell,expand=False)col.add_attribute(cell,'visible',id)#packpixmap('filemodify.ico', 3) # this icon does not load for mepackpixmap('menucommit.ico',3)# Mpackpixmap('fileadd.ico',4)# Apackpixmap('filedelete.ico',5)# Rpackpixmap('detect_rename.ico',6)# missingpackpixmap('menublame.ico',7)# unknown#packpixmap('ignore.ico', 8) # ignored#packpixmap('hg.ico', 9) # cleandefcell_seticon(column,cell,model,iter):isfile=model.get_value(iter,10)pixbuf=isfileandfilepborfolderpbcell.set_property('pixbuf',pixbuf)col=gtk.TreeViewColumn(_('type'))cell=gtk.CellRendererPixbuf()col.pack_start(cell,expand=False)col.set_cell_data_func(cell,cell_seticon)self.append_column(col)col=gtk.TreeViewColumn(_('path'),gtk.CellRendererText(),text=2)self.append_column(col)defsplit(self,filename):'Split a filename into a list of directories and the basename'dirs=[]path,basename=os.path.split(filename)whilepath:path,piece=os.path.split(path)dirs.append(piece) dirs.reverse()
return dirs, basename
- def chdir(self, cwd, repo):
- 'change directories inside a repo, or out of a repo'
+ def chdir(self, cwd):
+ 'change to a new directory'
+ # disable updates while we refill the model+ model = self.get_model()+ self.set_model(None)+ model.clear()+ try:+ self._chdir(model, cwd)+ except Exception, e:+ # report to status bar+ pass+ self.set_model(model)++ def _chdir(self, model, cwd): def buildrow(name, stset, isfile):
dirs, basename = self.split(name)
row = [ name, False, hglib.toutf(basename),
'M'instset,'A'instset,'R'instset,'!'instset,'?'instset,'I'instset,'C'instset,isfile]returnrowdefadddir(node):fordname,dirnodeinnode.subdirs.iteritems():model.append(buildrow(dname,dirnode.statuses,False)) for fname, st in node.files:
model.append(buildrow(fname, st, True))
- model = self.get_model()- self.set_model(None) # disable updates while we fill the model- model.clear() drive, tail = os.path.splitdrive(cwd)
if cwd != '/' or (drive and tail):
model.append(buildrow('..', '', False))
- if repo and cwd.startswith(repo.root):
- relpath = cwd[len(repo.root)+len(os.sep):]
+ root = paths.find_root(cwd)+ if root and self.cachedroot != root:+ self.cacherepo(root)
++ if root:
+ node = self.cachedmodel+ relpath = cwd[len(root)+len(os.sep):]
dirs, basename = self.split(relpath)
- node = self.cachedmodel for dname in dirs:
node = node.subdirs[dname]
if basename:
node = node.subdirs[basename]
adddir(node)
+ self.currepo = None else:
- for name in os.listdir(cwd):
- model.append(buildrow(name, '', os.path.isfile(name)))- self.entry.set_text(cwd)- self.set_model(model)- self.cwd = cwd- self.repo = repo+ try:+ for name in os.listdir(cwd):
+ isfile = os.path.isfile(os.path.join(cwd, name))+ model.append(buildrow(name, '', isfile))+ except OSError:+ # report to status bar+ pass+ self.currepo = self.cachedrepo- def refresh(self, cwd, repo, pats=[], filetypes='CI?'):
- hglib.invalidaterepo(repo)++ def cacherepo(self, root, pats=[], filetypes='CI?'):
status = ([],)*7
try:
+ repo = hg.repository(ui.ui(), path=root) matcher = cmdutil.match(repo, pats)
st = repo.status(match=matcher,
clean='C' in filetypes,
ignored='I'infiletypes,unknown='?'infiletypes)exceptIOError:passfilelist=[]# concatenate status output into a single list, then sort on filenameforl,sin((st[0],'M'),(st[1],'A'),(st[2],'R'),(st[3],'!'),(st[4],'?'),(st[5],'I'),(st[6],'C')):forminl:filelist.append([m,s])filelist.sort()# Build tree data structuremodelroot=dirnode()forname,filestatusinfilelist:dirs,basename=self.split(name)curdir=modelrootfordirindirs:ifdirnotincurdir.subdirs:curdir.addsubdir(dir)curdir.addstatus(filestatus)curdir=curdir.subdirs[dir] curdir.addfile(name, filestatus)
self.cachedmodel = modelroot
- self.chdir(cwd, repo)+ self.cachedroot = root+ self.cachedrepo = repo
def popupmenu(self, browse):
model, tpaths = browse.get_selection().get_selected_rows()
if not tpaths:
return
files = [model[p][0] for p in tpaths if model[p][10]]
- menus = self.menu.get_commands(self.repo, self.repo.root, files)
+ if self.currepo:+ repo = self.currepo+ menus = self.menu.get_commands(repo, repo.root, files)
+ else:+ menus = self.menu.get_norepo_commands(None, files) # see nautilus extension for usage info
for menu_info in menus:
print menu_info
defbuttonrelease(self,browse,event):ifevent.button!=3:returnFalseself.popupmenu(browse)returnTruedefrowactivated(self,browse,path,column):model,tpaths=browse.get_selection().get_selected_rows() if not tpaths:
return
if len(tpaths) == 1 and not model[tpaths[0]][10]:
- newpath = os.path.join(self.cwd, model[tpaths[0]][0])- newpath = os.path.abspath(newpath)- self.chdir(newpath, self.repo)
+ self.callback(model[tpaths[0]][0])
else:
- files = [model[p][0] for p in tpaths and model[p][10]]
+ files = [model[p][0] for p in tpaths if model[p][10]]
print files, 'activated'
class BrowseDialog(gtk.Dialog):
'Wrapper application for BrowsePane'def__init__(self,command,pats):gtk.Dialog.__init__(self)gtklib.set_tortoise_icon(self,'hg.ico')gtklib.set_tortoise_keys(self) self.set_has_separator(False)
self.set_default_size(400, 500)
self.connect('response', self.dialog_response)
- repo = hg.repository(ui.ui(), path=paths.find_root())- self.set_title(_('%s - browser') % hglib.get_reponame(repo)) entry = gtk.Entry()
- entry.set_text(repo.root) self.vbox.pack_start(entry, False, True)
- browse = BrowsePane(entry)+ def newfolder_notify(newfolder):+ curpath = entry.get_text()+ newpath = os.path.join(curpath, newfolder)+ newpath = hglib.toutf(os.path.abspath(newpath))+ root = paths.find_root(newpath)+ if root:+ self.set_title(root + ' - ' + _('browser'))+ else:+ self.set_title(_('browser'))+ entry.set_text(newpath)+ browse.chdir(newpath)++ browse = BrowsePane(newfolder_notify) scroller = gtk.ScrolledWindow()
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroller.set_shadow_type(gtk.SHADOW_ETCHED_IN)
scroller.add(browse)
self.vbox.pack_start(scroller, True, True)
self.show_all()
- self.browse = browse- gobject.idle_add(self.refresh, repo.root, repo)- def refresh(self, cwd, repo):
-self.browse.refresh(cwd, repo)
+ cwd = hglib.toutf(os.getcwd())+ entry.connect('activate', self.entry_activated, browse)+ entry.set_text(cwd)+ browse.chdir(cwd)++ def entry_activated(self, entry, browse):
+ browse.chdir(entry.get_text())
def dialog_response(self, dialog, response):
return True
defrun(ui,*pats,**opts):pats=hglib.canonpaths(pats)ifopts.get('canonpats'):pats=list(pats)+opts['canonpats']returnBrowseDialog(opts.get('alias'),pats)
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.