From 5fef554ebbb309e2390d9c1d9bc103049c086865 Mon Sep 17 00:00:00 2001 From: StanZGenchev Date: Thu, 16 Nov 2023 19:59:19 +0200 Subject: [PATCH] Added support for folder move --- .../dirigible/ide-projects/js/projects.js | 33 ++++++++++++++----- .../resources-core/core/ide-message-hub.js | 27 +++++++++++++-- .../dirigible/resources-core/ui/layout.js | 25 ++++++++++++-- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/components/ide/ide-ui-projects/src/main/resources/META-INF/dirigible/ide-projects/js/projects.js b/components/ide/ide-ui-projects/src/main/resources/META-INF/dirigible/ide-projects/js/projects.js index ee3cd0402d9..3c54a70e543 100644 --- a/components/ide/ide-ui-projects/src/main/resources/META-INF/dirigible/ide-projects/js/projects.js +++ b/components/ide/ide-ui-projects/src/main/resources/META-INF/dirigible/ide-projects/js/projects.js @@ -231,7 +231,7 @@ projectsView.controller('ProjectsViewController', [ moveObj.old_position, ); } - function move(parent, oldWorkspace, oldPath) { + function move(parent, oldPath) { for (let i = 0; i < parent.children.length; i++) { // Temp solution let node = $scope.jstreeWidget.jstree(true).get_node(parent.children[i]); if (node.text === moveObj.node.text && node.id !== moveObj.node.id) { @@ -258,12 +258,29 @@ projectsView.controller('ProjectsViewController', [ moveObj.node.data.path = (parent.data.path.endsWith('/') ? parent.data.path : parent.data.path + '/') + moveObj.node.text; moveObj.node.data.workspace = parent.data.workspace; $scope.jstreeWidget.jstree(true).show_node(moveObj.node); - messageHub.announceFileMoved({ - name: moveObj.node.text, - path: moveObj.node.data.path, - oldPath: oldPath, - workspace: moveObj.node.data.workspace, - }); + if (moveObj.node.type === 'file') { + messageHub.announceFileMoved({ + name: moveObj.node.text, + path: moveObj.node.data.path, + oldPath: oldPath, + workspace: moveObj.node.data.workspace, + }); + } else { + messageHub.getCurrentlyOpenedFiles(`/${moveObj.node.data.workspace}${oldPath}`).then(function (result) { + for (let i = 0; i < result.data.files.length; i++) { + messageHub.announceFileMoved({ + name: result.data.files[i].substring(result.data.files[i].lastIndexOf('/') + 1, result.data.files[i].length), + path: result.data.files[i].replace(oldPath, moveObj.node.data.path), + oldPath: result.data.files[i], + workspace: moveObj.node.data.workspace, + }); + } + }); + for (let i = 0; i < moveObj.node.children_d.length; i++) { + let child = $scope.jstreeWidget.jstree(true).get_node(moveObj.node.children_d[i]); + child.data.path = child.data.path.replace(oldPath, moveObj.node.data.path); + } + } } else { failedToMove(); } @@ -282,7 +299,7 @@ projectsView.controller('ProjectsViewController', [ messageHub.showAlertWarning('Cannot move file', 'The file you are trying to move is currently open and has unsaved changes.'); failedToMove(false); } else { - move(parent, moveObj.node.data.workspace, moveObj.node.data.path); + move(parent, moveObj.node.data.path); } }, function (error) { failedToMove(); diff --git a/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/core/ide-message-hub.js b/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/core/ide-message-hub.js index c76e7bd676d..f61267f0519 100644 --- a/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/core/ide-message-hub.js +++ b/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/core/ide-message-hub.js @@ -351,12 +351,34 @@ angular.module('ideMessageHub', []) if (isNullOrUndefinedOrEmpty(resourcePath)) reject(new Error("isEditorOpen: resourcePath must be specified")); - const callbackTopic = `ide-core.isEditorOpen.${new Date().valueOf()}`; + const callbackTopic = `core.editors.isOpen.${new Date().valueOf()}`; messageHub.post({ resourcePath: resourcePath, callbackTopic: callbackTopic - }, 'ide-core.isEditorOpen'); + }, 'core.editors.isOpen'); + + const handler = messageHub.subscribe(function (msg) { + messageHub.unsubscribe(handler); + resolve(msg); + }, callbackTopic); + }); + }; + /** + * Returnes a list of all files whose path starts with 'basePath', from the currently opened editors. + * If basePath is not specified, all files will be listed. + */ + const getCurrentlyOpenedFiles = function (basePath = '/') { + return new Promise((resolve, reject) => { + if (isNullOrUndefinedOrEmpty(basePath)) + reject(new Error("getOpenedFiles: resourcePath cannot be null, undefined or empty")); + + const callbackTopic = `core.editors.openedFiles.${new Date().valueOf()}`; + + messageHub.post({ + basePath: basePath, + callbackTopic: callbackTopic + }, 'core.editors.openedFiles'); const handler = messageHub.subscribe(function (msg) { messageHub.unsubscribe(handler); @@ -616,6 +638,7 @@ angular.module('ideMessageHub', []) openPerspective: openPerspective, openEditor: openEditor, isEditorOpen: isEditorOpen, + getCurrentlyOpenedFiles: getCurrentlyOpenedFiles, editorReloadParameters: editorReloadParameters, onEditorReloadParameters: onEditorReloadParameters, setEditorDirty: setEditorDirty, diff --git a/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/ui/layout.js b/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/ui/layout.js index c65eb9dba02..95e69a58639 100644 --- a/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/ui/layout.js +++ b/components/resources/resources-core/src/main/resources/META-INF/dirigible/resources-core/ui/layout.js @@ -11,7 +11,7 @@ angular.module('ideLayout', ['idePerspective', 'ideEditors', 'ideMessageHub', 'ideView']) .constant('perspective', perspectiveData || {}) .constant('layoutConstants', { - version: 2.0, + version: 3.0, stateKey: 'ide.layout.state' }) .directive('view', ['Views', 'perspective', function (Views, perspective) { @@ -504,6 +504,23 @@ angular.module('ideLayout', ['idePerspective', 'ideEditors', 'ideMessageHub', 'i return null; } + /** + * Returnes a list of all files whose path starts with 'basePath', from the currently opened editors. + * If basePath is not specified, all files will be listed. + */ + function getCurrentlyOpenedFiles(basePath = '/') { + let fileList = []; + for (let childIndex = 0; childIndex < $scope.centerSplittedTabViews.panes.length; childIndex++) { + let childPane = $scope.centerSplittedTabViews.panes[childIndex]; + for (let tabIndex = 0; tabIndex < childPane.tabs.length; tabIndex++) { + if (childPane.tabs[tabIndex].params && childPane.tabs[tabIndex].params.file && childPane.tabs[tabIndex].params.file.startsWith(basePath)) { + fileList.push(childPane.tabs[tabIndex].params.file); + } + } + } + return fileList; + } + function getFirstCenterSplittedTabViewPane(parent) { let pane = parent; while (pane.panes) { @@ -886,7 +903,7 @@ angular.module('ideLayout', ['idePerspective', 'ideEditors', 'ideMessageHub', 'i } ); - messageHub.onDidReceiveMessage('ide-core.isEditorOpen', function (msg) { + messageHub.onDidReceiveMessage('core.editors.isOpen', function (msg) { const result = findCenterSplittedTabViewByPath(msg.resourcePath); if (result) { messageHub.postMessage(msg.callbackTopic, { @@ -899,6 +916,10 @@ angular.module('ideLayout', ['idePerspective', 'ideEditors', 'ideMessageHub', 'i } }, true); + messageHub.onDidReceiveMessage('core.editors.openedFiles', function (msg) { + messageHub.postMessage(msg.callbackTopic, { files: getCurrentlyOpenedFiles(msg.basePath) }, true); + }, true); + function shortenCenterTabsLabels() { const getTabPath = tab => {