diff --git a/src/adapter.github.js b/src/adapter.github.js index 579459c..e7c4766 100644 --- a/src/adapter.github.js +++ b/src/adapter.github.js @@ -161,17 +161,19 @@ GitHub.prototype.getRepoFromPath = function(showInNonCodePage, currentRepo, toke /** * Retrieves the code tree of a repository. - * @param {Object} repo - the repo whose code tree is to be retrieved. - * @param {String} token - the access token. + * @param {Object} opts: { repo: repository, node(optional): selected node (null for resursively loading), token (optional): user access token, apiUrl (optional): base API URL } * @param {Function} cb(err: error, tree: array (of arrays) of items) */ -GitHub.prototype.getCodeTree = function(repo, token, cb) { - var self = this - , folders = { '': [] } +GitHub.prototype.getCodeTree = function(opts, cb) { + var self = this + , folders = { '': [] } + , repo = opts.repo + , token = opts.token , encodedBranch = encodeURIComponent(decodeURIComponent(repo.branch)) - , $dummyDiv = $('
') + , $dummyDiv = $('') - getTree(encodedBranch + '?recursive=true', function(err, tree) { + var treePath = (opts.node && (opts.node.sha || encodedBranch)) || (encodedBranch + '?recursive=1') + getTree(treePath, function(err, tree) { if (err) return cb(err) fetchSubmodules(function(err, submodules) { @@ -192,6 +194,10 @@ GitHub.prototype.getCodeTree = function(repo, token, cb) { // we're done if (item === undefined) return cb(null, folders['']) + // includes parent path + if (opts.node && opts.node.path) + item.path = opts.node.path + '/' + item.path + path = item.path type = item.type index = path.lastIndexOf('/') @@ -201,10 +207,16 @@ GitHub.prototype.getCodeTree = function(repo, token, cb) { item.text = name item.icon = type // use `type` as class name for tree node - folders[path.substring(0, index)].push(item) + if (opts.node) { + // no hierarchy in lazy loading + folders[''].push(item) + } + else + folders[path.substring(0, index)].push(item) if (type === 'tree') { - folders[item.path] = item.children = [] + if (opts.node) item.children = true + else folders[item.path] = item.children = [] item.a_attr = { href: '#' } } else if (type === 'blob') { diff --git a/src/chrome/manifest.json b/src/chrome/manifest.json index a0c676a..fee00e8 100755 --- a/src/chrome/manifest.json +++ b/src/chrome/manifest.json @@ -1,6 +1,6 @@ { "name": "Octotree", - "version": "1.7.2", + "version": "2.0.0", "manifest_version": 2, "author": "Buu Nguyen", "description": "Display GitHub code in tree format", diff --git a/src/constants.js b/src/constants.js index 28ee744..b654d47 100644 --- a/src/constants.js +++ b/src/constants.js @@ -2,17 +2,18 @@ const PREFIX = 'octotree' , STORE = { - TOKEN : 'octotree.github_access_token', - COLLAPSE : 'octotree.collapse', - TABSIZE : 'octotree.tabsize', - REMEMBER : 'octotree.remember', - LAZYLOAD : 'octotree.lazyload', - HOTKEYS : 'octotree.hotkeys', - GHEURLS : 'octotree.gheurls', - WIDTH : 'octotree.sidebar_width', - POPUP : 'octotree.popup_shown', - SHOWN : 'octotree.sidebar_shown', - NONCODE : 'octotree.noncode_shown', + TOKEN : 'octotree.github_access_token', + COLLAPSE : 'octotree.collapse', + TABSIZE : 'octotree.tabsize', + REMEMBER : 'octotree.remember', + LAZYLOAD : 'octotree.lazyload', + RECURSIVE : 'octotree.recursive', + HOTKEYS : 'octotree.hotkeys', + GHEURLS : 'octotree.gheurls', + WIDTH : 'octotree.sidebar_width', + POPUP : 'octotree.popup_shown', + SHOWN : 'octotree.sidebar_shown', + NONCODE : 'octotree.noncode_shown', } , DEFAULTS = { @@ -21,6 +22,7 @@ const TABSIZE : '', REMEMBER : false, LAZYLOAD : false, + RECURSIVE: true, // @ifdef SAFARI HOTKEYS : '⌘+b, ⌃+b', // @endif @@ -43,4 +45,5 @@ const OPTS_CHANGE : 'octotree:change', VIEW_READY : 'octotree:ready', VIEW_CLOSE : 'octotree:close', + FETCH_ERROR : 'octotree:error' } \ No newline at end of file diff --git a/src/firefox/package.json b/src/firefox/package.json index 45bce9a..99664cc 100644 --- a/src/firefox/package.json +++ b/src/firefox/package.json @@ -11,7 +11,7 @@ "icon": "data/icons/icon48.png", "icon64": "data/icons/icon64.png", "license": "MIT", - "version": "1.7.2", + "version": "2.0.0", "permissions": { "cross-domain-content": ["https://api.github.com", "https://github.com"] } diff --git a/src/octotree.js b/src/octotree.js index f9ba5b6..e73a08c 100755 --- a/src/octotree.js +++ b/src/octotree.js @@ -50,6 +50,9 @@ $(document).ready(function() { showView(hasError ? errorView.$view : treeView.$view) }) .on(EVENT.OPTS_CHANGE, optionsChanged) + .on(EVENT.FETCH_ERROR, function(event, err) { + errorView.show(err) + }) }) $document @@ -81,6 +84,9 @@ $(document).ready(function() { key.unbind(value[0]) key(value[1], toggleSidebar) break + case STORE.RECURSIVE: + reload = true + break } }) if (reload) tryLoadRepo(true) @@ -108,12 +114,9 @@ $(document).ready(function() { if (repoChanged || reload === true) { $document.trigger(EVENT.REQ_START) currRepo = repo + treeView.showHeader(repo) - - adapter.getCodeTree(repo, token, function(err, tree) { - if (err) errorView.show(err) - else treeView.show(repo, tree) - }) + treeView.show(repo, token) } else treeView.syncSelection() } diff --git a/src/octotree.less b/src/octotree.less index 46bb885..dff7e21 100755 --- a/src/octotree.less +++ b/src/octotree.less @@ -202,6 +202,11 @@ label { font-weight: normal !important; } + + label.disabled { + color: gray; + } + input[type=text], textarea { width: 100%; } diff --git a/src/safari/Info.plist b/src/safari/Info.plist index 024a5d1..594863a 100755 --- a/src/safari/Info.plist +++ b/src/safari/Info.plist @@ -13,9 +13,9 @@