diff --git a/lib/editor-prompt.pug b/lib/editor-prompt.pug index a8f58c22..373a1fac 100644 --- a/lib/editor-prompt.pug +++ b/lib/editor-prompt.pug @@ -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;") diff --git a/lib/js/directives/ng-ace-editor.js b/lib/js/directives/ng-ace-editor.js index 4bf8445e..31dccf1a 100644 --- a/lib/js/directives/ng-ace-editor.js +++ b/lib/js/directives/ng-ace-editor.js @@ -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; @@ -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) { @@ -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', { @@ -69,7 +75,7 @@ angular.module(moduleName, []) if (source) { scope.aceFileModel = source; } else { - scope.aceFileModel = '{}'; + scope.aceFileModel = ''; } }); diff --git a/lib/js/interface/left.js b/lib/js/interface/left.js index ebe5156c..7069744e 100644 --- a/lib/js/interface/left.js +++ b/lib/js/interface/left.js @@ -16,6 +16,7 @@ angular.module(moduleName, []) data.link) { $scope.$evalAsync(() => { this.editorFilePath = false; + this.editorFileName = false; this.showHistoryPrompt = false; }); } @@ -23,6 +24,7 @@ angular.module(moduleName, []) , unregisterLeftbarEditProject = $rootScope.$on('left-bar:edit-project', (eventInfo, data) => { $scope.$apply(() => { this.editorFilePath = data.dirName; + this.editorFileName = data.fileName; this.showHistoryPrompt = false; }); }) @@ -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' }); } }] @@ -654,7 +666,7 @@ angular.module(moduleName, []) })); projectsContextMenu.append(new MenuItem({ - 'label': 'Copy Path', + 'label': 'Copy Full Path', click() { clipboard.write({ 'text': item.path