Skip to content

Commit

Permalink
Merge pull request #176 from 720kb/edit-local-npmrc
Browse files Browse the repository at this point in the history
Edit/create local .npmrc
  • Loading branch information
45kb authored Feb 24, 2017
2 parents 19a4118 + db73aa3 commit 39bf70f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/editor-prompt.pug
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
div.dialog.dialog-window(ng-if="leftBar.editorFilePath", ng-ace-editor, ng-ace-editor-theme="xcode", ng-ace-editor-mode="json", ng-ace-file="{{leftBar.editorFilePath}}" ng-model="aceFileModel")
div.dialog.dialog-window(ng-if="leftBar.editorFilePath", ng-ace-editor, ng-ace-editor-theme="xcode", ng-ace-file-name="{{leftBar.editorFileName}}", ng-ace-file="{{leftBar.editorFilePath}}" ng-model="aceFileModel")
div(class="prompt-window-options")
span(class="prompt-window-infos", title="{{leftBar.rightClickedProject.path}}")
img(src="img/loading.svg", width="13", ng-show="(savingFile && !savedFile) || loadingFile")
i(class="fa fa-check color-primary", ng-show="savedFile && !savingFile")
| {{leftBar.rightClickedProject.dirName}}/package.json
| {{leftBar.rightClickedProject.dirName}}/{{leftBar.editorFileName}}
button(ng-click="saveFile()")
| Save
button(ng-click="leftBar.editorFilePath = undefined; aceFileModel = undefined;")
Expand Down
36 changes: 21 additions & 15 deletions lib/js/directives/ng-ace-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ angular.module(moduleName, [])
'require': '?ngModel',
'link': (scope, element, attrs, ngModel) => {

const unregisterSavedFile = $rootScope.$on('ace-editor:saved-file', () => {
const editorElement = element[0].querySelector('.ng-ace-editor')
, aceEditor = ace.edit(editorElement)
, aceSession = aceEditor.getSession()
, theme = attrs.ngAceEditorTheme
, readonly = scope.$eval(attrs.ngAceEditorReadonly)
, setAceMode = () => {
if (attrs.ngAceFileName.endsWith('.json')) {

aceSession.setMode('ace/mode/json');
} else if (attrs.ngAceFileName.startsWith('.')) {
aceSession.setMode('ace/mode/text');
}
}
, unregisterSavedFile = $rootScope.$on('ace-editor:saved-file', () => {
scope.$evalAsync(() => {
scope.savingFile = false;
scope.savedFile = true;
Expand All @@ -30,18 +43,11 @@ angular.module(moduleName, [])
, unregisterLoadingFile = $rootScope.$on('ace-editor:loading-file', () => {
scope.$evalAsync(() => {
scope.loadingFile = true;
scope.savedFile = false;
scope.savingFile = false;
setAceMode();
});
})
, editorElement = element[0].querySelector('.ng-ace-editor')
, aceEditor = ace.edit(editorElement)
, aceSession = aceEditor.getSession()
, mode = attrs.ngAceEditorMode
, theme = attrs.ngAceEditorTheme
, readonly = scope.$eval(attrs.ngAceEditorReadonly);

if (mode) {
aceSession.setMode(`ace/mode/${mode}`);
}
});

attrs.$observe('ngAceFile', filePath => {
if (filePath) {
Expand All @@ -52,10 +58,10 @@ angular.module(moduleName, [])
if (fs.existsSync(filePath)) {
scope.aceFileModel = fs.readFileSync(filePath).toString();
} else {
scope.aceFileModel = '{}';
scope.aceFileModel = '';
}
} catch (e) {
scope.aceFileModel = '{}';
scope.aceFileModel = '';
}

$rootScope.$emit('ace-editor:loaded-file', {
Expand All @@ -69,7 +75,7 @@ angular.module(moduleName, [])
if (source) {
scope.aceFileModel = source;
} else {
scope.aceFileModel = '{}';
scope.aceFileModel = '';
}
});

Expand Down
16 changes: 14 additions & 2 deletions lib/js/interface/left.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ angular.module(moduleName, [])
data.link) {
$scope.$evalAsync(() => {
this.editorFilePath = false;
this.editorFileName = false;
this.showHistoryPrompt = false;
});
}
})
, unregisterLeftbarEditProject = $rootScope.$on('left-bar:edit-project', (eventInfo, data) => {
$scope.$apply(() => {
this.editorFilePath = data.dirName;
this.editorFileName = data.fileName;
this.showHistoryPrompt = false;
});
})
Expand Down Expand Up @@ -627,7 +629,17 @@ angular.module(moduleName, [])
'label': 'package.json',
click() {
$rootScope.$emit('left-bar:edit-project', {
'dirName': Path.join(item.path, 'package.json')
'dirName': Path.join(item.path, 'package.json'),
'fileName': 'package.json'
});
}
},
{
'label': '.npmrc',
click() {
$rootScope.$emit('left-bar:edit-project', {
'dirName': Path.join(item.path, '.npmrc'),
'fileName': '.npmrc'
});
}
}]
Expand All @@ -654,7 +666,7 @@ angular.module(moduleName, [])
}));

projectsContextMenu.append(new MenuItem({
'label': 'Copy Path',
'label': 'Copy Full Path',
click() {
clipboard.write({
'text': item.path
Expand Down

0 comments on commit 39bf70f

Please sign in to comment.