-
Notifications
You must be signed in to change notification settings - Fork 58
/
blameViewController.js
53 lines (45 loc) · 1.55 KB
/
blameViewController.js
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
const $ = require('atom-space-pen-views').$;
const React = require('react-atom-fork');
const BlameListView = require('../views/blame-list-view');
const RemoteRevision = require('../util/RemoteRevision');
const errorController = require('./errorController');
/**
* Display or hide a BlameListView for the active editor.
*
* If the active editor does not have an existing BlameListView, one will be
* mounted.
*
* @param {Blamer} projectBlamer - a Blamer for the current project
*/
function toggleBlame(projectBlamer) {
var editor = atom.workspace.getActiveTextEditor();
if (!editor) return;
// An unsaved file has no filePath
var filePath = editor.getPath();
if (!filePath) return;
var editorView = atom.views.getView(editor);
if (!editorView.blameView) {
var remoteUrl = projectBlamer.repo.getOriginURL(filePath);
var remoteRevision;
try {
remoteRevision = RemoteRevision.create(remoteUrl);
} catch (e) {
// the only exception possible occurs when the template string is invalid
// TODO refactor this to not throw an exception
}
// insert the BlameListView after the gutter div
var mountPoint = $('<div>', {'class': 'git-blame-mount'});
$(editorView.rootElement).find('.gutter').after(mountPoint);
editorView.blameView = React.renderComponent(new BlameListView({
projectBlamer: projectBlamer,
remoteRevision: remoteRevision,
editorView: editorView
}), mountPoint[0]);
} else {
editorView.blameView.toggle();
}
}
// EXPORTS
module.exports = {
toggleBlame: toggleBlame
};