From 3ab16fdb0e7dffc8cd0d208f94b645371b9bb405 Mon Sep 17 00:00:00 2001 From: 45kb Date: Fri, 24 Feb 2017 09:32:50 +0100 Subject: [PATCH 1/3] seems to work --- lib/editor-prompt.pug | 4 ++-- lib/js/directives/ng-ace-editor.js | 37 ++++++++++++++++++------------ lib/js/interface/left.js | 14 ++++++++++- 3 files changed, 37 insertions(+), 18 deletions(-) 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..5adfd567 100644 --- a/lib/js/directives/ng-ace-editor.js +++ b/lib/js/directives/ng-ace-editor.js @@ -10,7 +10,21 @@ 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'); + } + } + , fileEmptyContent = attrs.ngAceFileName.endsWith('.json') ? '{}' : '' + , unregisterSavedFile = $rootScope.$on('ace-editor:saved-file', () => { scope.$evalAsync(() => { scope.savingFile = false; scope.savedFile = true; @@ -30,18 +44,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 +59,10 @@ angular.module(moduleName, []) if (fs.existsSync(filePath)) { scope.aceFileModel = fs.readFileSync(filePath).toString(); } else { - scope.aceFileModel = '{}'; + scope.aceFileModel = fileEmptyContent; } } catch (e) { - scope.aceFileModel = '{}'; + scope.aceFileModel = fileEmptyContent; } $rootScope.$emit('ace-editor:loaded-file', { @@ -69,7 +76,7 @@ angular.module(moduleName, []) if (source) { scope.aceFileModel = source; } else { - scope.aceFileModel = '{}'; + scope.aceFileModel = fileEmptyContent; } }); diff --git a/lib/js/interface/left.js b/lib/js/interface/left.js index ebe5156c..0d4f0852 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' }); } }] From f0ec95302f3838aef95f36b4de796d7e52e9aac6 Mon Sep 17 00:00:00 2001 From: 45kb Date: Fri, 24 Feb 2017 09:35:46 +0100 Subject: [PATCH 2/3] seems to work --- lib/js/directives/ng-ace-editor.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/js/directives/ng-ace-editor.js b/lib/js/directives/ng-ace-editor.js index 5adfd567..31dccf1a 100644 --- a/lib/js/directives/ng-ace-editor.js +++ b/lib/js/directives/ng-ace-editor.js @@ -23,7 +23,6 @@ angular.module(moduleName, []) aceSession.setMode('ace/mode/text'); } } - , fileEmptyContent = attrs.ngAceFileName.endsWith('.json') ? '{}' : '' , unregisterSavedFile = $rootScope.$on('ace-editor:saved-file', () => { scope.$evalAsync(() => { scope.savingFile = false; @@ -59,10 +58,10 @@ angular.module(moduleName, []) if (fs.existsSync(filePath)) { scope.aceFileModel = fs.readFileSync(filePath).toString(); } else { - scope.aceFileModel = fileEmptyContent; + scope.aceFileModel = ''; } } catch (e) { - scope.aceFileModel = fileEmptyContent; + scope.aceFileModel = ''; } $rootScope.$emit('ace-editor:loaded-file', { @@ -76,7 +75,7 @@ angular.module(moduleName, []) if (source) { scope.aceFileModel = source; } else { - scope.aceFileModel = fileEmptyContent; + scope.aceFileModel = ''; } }); From db73aa32672ac19e3395cf842edf4d70f4cd6c48 Mon Sep 17 00:00:00 2001 From: 45kb Date: Fri, 24 Feb 2017 09:38:37 +0100 Subject: [PATCH 3/3] finished --- lib/js/interface/left.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/js/interface/left.js b/lib/js/interface/left.js index 0d4f0852..7069744e 100644 --- a/lib/js/interface/left.js +++ b/lib/js/interface/left.js @@ -666,7 +666,7 @@ angular.module(moduleName, []) })); projectsContextMenu.append(new MenuItem({ - 'label': 'Copy Path', + 'label': 'Copy Full Path', click() { clipboard.write({ 'text': item.path