Skip to content

Commit

Permalink
Added support for folder move
Browse files Browse the repository at this point in the history
  • Loading branch information
StanZGenchev committed Nov 16, 2023
1 parent 1a7f771 commit 5fef554
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -616,6 +638,7 @@ angular.module('ideMessageHub', [])
openPerspective: openPerspective,
openEditor: openEditor,
isEditorOpen: isEditorOpen,
getCurrentlyOpenedFiles: getCurrentlyOpenedFiles,
editorReloadParameters: editorReloadParameters,
onEditorReloadParameters: onEditorReloadParameters,
setEditorDirty: setEditorDirty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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, {
Expand All @@ -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 => {
Expand Down

0 comments on commit 5fef554

Please sign in to comment.