
noreply at edgewall
Jan 4, 2006, 7:44 AM
Post #1 of 5
(4736 views)
Permalink
|
|
[The Trac Project] #2556: Easy switching between revisions while previewing a file in browser
|
|
#2556: Easy switching between revisions while previewing a file in browser ------------------------------+--------------------------------------------- Reporter: pete[at]parkmed.com | Owner: jonas Type: enhancement | Status: new Priority: normal | Milestone: 0.9.3 Component: browser | Version: 0.9.2 Severity: normal | Keywords: ------------------------------+--------------------------------------------- While previewing a file in the browser it is helpful to be able to quickly jump back and forth between revisions. Attatched is a patch to the current /trunk/versioncontrol/web/browser.py to add links to the oldest, previous, next, and most recent revisions to a file being previewed. I'm not familiar with hacking the templates, so the links simply appear in the 'alternate' file downloads area. {{{ --- browser.py 2006-01-04 10:16:03.000000000 -0500 +++ browser.py 2006-01-04 10:19:30.000000000 -0500 @@ -25,6 +25,7 @@ from trac.web.chrome import add_link, add_stylesheet, INavigationContributor from trac.wiki import wiki_to_html, wiki_to_oneliner, IWikiSyntaxProvider from trac.versioncontrol.web_ui.util import * +from trac.versioncontrol.svn_authz import SubversionAuthorizer IMG_RE = re.compile(r"\.(gif|jpg|jpeg|png)(\?.*)?$", re.IGNORECASE) @@ -211,6 +212,34 @@ mime_type = get_mime_type(content) use_rev = rev and node.rev + newestchgset = repos.get_youngest_rev() + nodehistory = repos.get_path_history(node.path, newestchgset) + allrevs = list(nodehistory) + oldest_rev_num = len(allrevs) - 1 + oldest_rev = allrevs[oldest_rev_num] + oldest_path = '%s' % oldest_rev[0] + youngest_rev = allrevs[0] + youngest_path = '%s' % youngest_rev[0] + temprev = 0 + ##find the current rev + for revision in allrevs: + if revision[1] == int(node.rev): + break + else: + temprev += 1 + continue + + current_rev = allrevs[temprev] + + if current_rev != oldest_rev: + previous_rev = allrevs[temprev + 1] + prev_path = '%s' % previous_rev[0] + if previous_rev != oldest_rev: + add_link(req, 'alternate', self.env.href.browser(oldest_path, rev=oldest_rev[1]), 'Oldest Revision') + add_link(req, 'alternate', self.env.href.browser(prev_path, rev=previous_rev[1]), 'Previous Revision') + else: + add_link(req, 'alternate', self.env.href.browser(oldest_path, rev=oldest_rev[1]), 'Previous (Oldest) Revision') + if not is_binary(content): if mime_type != 'text/plain': plain_href = self.env.href.browser(node.path, rev=use_rev, @@ -230,6 +259,16 @@ add_link(req, 'alternate', raw_href, 'Original Format', mime_type) req.hdf['file.raw_href'] = raw_href + if current_rev != youngest_rev: + next_rev = allrevs[temprev - 1] + next_path = '%s' % next_rev[0] + if temprev - 1 > 0 and next_rev != youngest_rev: + add_link(req, 'alternate', self.env.href.browser(next_path, rev=next_rev[1]), 'Next Revision') + add_link(req, 'alternate', self.env.href.browser(youngest_path, rev=youngest_rev[1]), 'Most Recent Revision') + else: + add_link(req, 'alternate', self.env.href.browser(youngest_path, rev=youngest_rev[1]), 'Next (Most Recent) Revision') + + add_stylesheet(req, 'common/css/code.css') # IWikiSyntaxProvider methods }}} -- Ticket URL: <http://projects.edgewall.com/trac/ticket/2556> The Trac Project <http://trac.edgewall.com/>
|