atom-nuclide
Version:
A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.
186 lines (147 loc) • 6.37 kB
JavaScript
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
exports.activate = activate;
exports.deactivate = deactivate;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, 'next'); var callThrow = step.bind(null, 'throw'); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
var _atom2;
function _atom() {
return _atom2 = require('atom');
}
var _commonsNodeNuclideUri2;
function _commonsNodeNuclideUri() {
return _commonsNodeNuclideUri2 = _interopRequireDefault(require('../../commons-node/nuclideUri'));
}
var _commonsAtomProjects2;
function _commonsAtomProjects() {
return _commonsAtomProjects2 = require('../../commons-atom/projects');
}
var _nuclideAnalytics2;
function _nuclideAnalytics() {
return _nuclideAnalytics2 = require('../../nuclide-analytics');
}
var _nuclideRemoteConnection2;
function _nuclideRemoteConnection() {
return _nuclideRemoteConnection2 = require('../../nuclide-remote-connection');
}
function copyAbsolutePath() {
trackOperation('copyAbsolutePath', function () {
var uri = getCurrentNuclideUri();
if (!uri) {
return;
}
copyToClipboard('Copied absolute path', (_commonsNodeNuclideUri2 || _commonsNodeNuclideUri()).default.getPath(uri));
});
}
function copyProjectRelativePath() {
trackOperation('copyProjectRelativePath', function () {
var uri = getCurrentNuclideUri();
if (!uri) {
return;
}
var projectRelativePath = (0, (_commonsAtomProjects2 || _commonsAtomProjects()).getAtomProjectRelativePath)(uri);
if (projectRelativePath) {
copyToClipboard('Copied project relative path', projectRelativePath);
} else {
copyToClipboard('Path not contained in any open project.\nCopied absolute path', (_commonsNodeNuclideUri2 || _commonsNodeNuclideUri()).default.getPath(uri));
}
});
}
function copyRepositoryRelativePath() {
trackOperation('copyRepositoryRelativePath', _asyncToGenerator(function* () {
var uri = getCurrentNuclideUri();
if (!uri) {
return;
}
// First source control relative.
var repoRelativePath = getRepositoryRelativePath(uri);
if (repoRelativePath) {
copyToClipboard('Copied repository relative path', repoRelativePath);
return;
}
// Next try arcanist relative.
var arcRelativePath = yield getArcanistRelativePath(uri);
if (arcRelativePath) {
copyToClipboard('Copied arc project relative path', arcRelativePath);
return;
}
// Lastly, project and absolute.
var projectRelativePath = (0, (_commonsAtomProjects2 || _commonsAtomProjects()).getAtomProjectRelativePath)(uri);
if (projectRelativePath) {
copyToClipboard('Copied project relative path', projectRelativePath);
} else {
copyToClipboard('Path not contained in any repository.\nCopied absolute path', (_commonsNodeNuclideUri2 || _commonsNodeNuclideUri()).default.getPath(uri));
}
}));
}
function getRepositoryRelativePath(path) {
// TODO(peterhal): repositoryForPath is the same as projectRelativePath
// only less robust. We'll need a version of findHgRepository which is
// aware of remote paths.
return null;
}
function getArcanistRelativePath(path) {
var arcService = (0, (_nuclideRemoteConnection2 || _nuclideRemoteConnection()).getArcanistServiceByNuclideUri)(path);
return arcService.getProjectRelativePath(path);
}
function copyToClipboard(messagePrefix, value) {
atom.clipboard.write(value);
notify(messagePrefix + ': ```' + value + '```');
}
function getCurrentNuclideUri() {
var editor = atom.workspace.getActiveTextEditor();
if (!editor) {
notify('Nothing copied. No active text editor.');
return null;
}
var path = editor.getPath();
if (!path) {
notify('Nothing copied. Current text editor is unnamed.');
return null;
}
return path;
}
function trackOperation(eventName, operation) {
(0, (_nuclideAnalytics2 || _nuclideAnalytics()).trackOperationTiming)('nuclide-clipboard-path:' + eventName, operation);
}
function notify(message) {
atom.notifications.addInfo(message);
}
var Activation = (function () {
function Activation(state) {
_classCallCheck(this, Activation);
this._subscriptions = new (_atom2 || _atom()).CompositeDisposable();
this._subscriptions.add(atom.commands.add('atom-workspace', 'nuclide-clipboard-path:copy-absolute-path', copyAbsolutePath));
this._subscriptions.add(atom.commands.add('atom-workspace', 'nuclide-clipboard-path:copy-repository-relative-path', copyRepositoryRelativePath));
this._subscriptions.add(atom.commands.add('atom-workspace', 'nuclide-clipboard-path:copy-project-relative-path', copyProjectRelativePath));
}
_createClass(Activation, [{
key: 'dispose',
value: function dispose() {
this._subscriptions.dispose();
}
}]);
return Activation;
})();
var activation = null;
function activate(state) {
if (!activation) {
activation = new Activation();
}
}
function deactivate() {
if (activation) {
activation.dispose();
activation = null;
}
}