Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 424621 - Create Cut file/folder command and add it to sidebar con…
…text menu and actions gear menu

- Created Cut command and added it to the Actions gear menu as well as the sidebar's context menu

--Signed-off-by: Elijah El-Haddad <elijahe@ca.ibm.com>
  • Loading branch information
elijahe committed Dec 23, 2013
1 parent 2978350 commit f84a41c
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 64 deletions.
13 changes: 13 additions & 0 deletions bundles/org.eclipse.orion.client.ui/web/css/ide.css
Expand Up @@ -247,6 +247,19 @@ textarea.parameterInput {
border-spacing: 8px;
}

.disabledNavRow > .navColumn > .mainNavColumn {
outline: 1px dashed lightgray;
}

.disabledNavRow > .navColumn > .mainNavColumn > * {
color: gray;
cursor: default;
}

.disabledNavRow > .navColumn > .mainNavColumn > *:hover {
border: none;
}

.mainNavColumn {
display: inline-block;
padding: 2px;
Expand Down
28 changes: 15 additions & 13 deletions bundles/org.eclipse.orion.client.ui/web/orion/explorers/explorer.js
Expand Up @@ -659,21 +659,23 @@ exports.ExplorerRenderer = (function() {
}
var self = this;
expandImage.onclick = function(evt) {
self.tableTree.toggle(tableRow.id);
var expanded = self.tableTree.isExpanded(tableRow.id);
if (expanded) {
self._expanded.push(tableRow.id);
} else {
for (var i in self._expanded) {
if (self._expanded[i] === tableRow.id) {
self._expanded.splice(i, 1);
break;
if (!self.explorer.getNavHandler().isDisabled(tableRow)) {
self.tableTree.toggle(tableRow.id);
var expanded = self.tableTree.isExpanded(tableRow.id);
if (expanded) {
self._expanded.push(tableRow.id);
} else {
for (var i in self._expanded) {
if (self._expanded[i] === tableRow.id) {
self._expanded.splice(i, 1);
break;
}
}
}
}
var prefPath = self._getUIStatePreferencePath();
if (prefPath && window.sessionStorage) {
self._storeExpansions(prefPath);
var prefPath = self._getUIStatePreferencePath();
if (prefPath && window.sessionStorage) {
self._storeExpansions(prefPath);
}
}
};
return expandImage;
Expand Down
Expand Up @@ -558,28 +558,32 @@ exports.ExplorerNavHandler = (function() {
},

onClick: function(model, mouseEvt) {
var twistieSpan = lib.node(this.explorer.renderer.expandCollapseImageId(this.model.getId(model)));
if(mouseEvt.target === twistieSpan){
return;
}
if(this.gridClickSelectionPolicy === "none" && this._onModelGrid(model, mouseEvt)){ //$NON-NLS-0$
return;
}
this.cursorOn(model, true, false, true);
if(isPad){
this.setSelection(model, true);
} else if(this._ctrlKeyOn(mouseEvt)){
this.setSelection(model, true, true);
} else if(mouseEvt.shiftKey && this._shiftSelectionAnchor){
var scannedSel = this._modelIterator.scan(this._shiftSelectionAnchor, model);
if(scannedSel){
this._clearSelection(true);
for(var i = 0; i < scannedSel.length; i++){
this.setSelection(scannedSel[i], true);
if (this.isDisabled(this.getRowDiv(model))) {
lib.stop(mouseEvt);
} else {
var twistieSpan = lib.node(this.explorer.renderer.expandCollapseImageId(this.model.getId(model)));
if(mouseEvt.target === twistieSpan){
return;
}
if(this.gridClickSelectionPolicy === "none" && this._onModelGrid(model, mouseEvt)){ //$NON-NLS-0$
return;
}
this.cursorOn(model, true, false, true);
if(isPad){
this.setSelection(model, true);
} else if(this._ctrlKeyOn(mouseEvt)){
this.setSelection(model, true, true);
} else if(mouseEvt.shiftKey && this._shiftSelectionAnchor){
var scannedSel = this._modelIterator.scan(this._shiftSelectionAnchor, model);
if(scannedSel){
this._clearSelection(true);
for(var i = 0; i < scannedSel.length; i++){
this.setSelection(scannedSel[i], true);
}
}
} else {
this.setSelection(model, false, true);
}
} else {
this.setSelection(model, false, true);
}
},

Expand Down Expand Up @@ -721,7 +725,57 @@ exports.ExplorerNavHandler = (function() {
e.preventDefault();
return false;
}
}
},

/**
* Sets the isNotSelectable attribute on the specified model.
* @param {Object} model
* @param {Boolean} isNotSelectable true makes the this.iterate() with selectableOnly specified skip the item
*/
setIsNotSelectable: function(model, isNotSelectable) {
model.isNotSelectable = isNotSelectable;
},

/**
* Disables the specified model making it no longer respond
* to user input such as mouse click or key presses. The
* CSS style of corresponding row node is also modified to
* reflect its disabled state.
*
* @param {Object} model
*/
disableItem: function(model) {
var rowDiv = this.getRowDiv(model);
if (this.isExpandable(model) && this.isExpanded(model)) {
this._modelIterator.collapse(model);
this.explorer.myTree.toggle(rowDiv.id); // collapse tree visually
}
rowDiv.classList.remove("checkedRow"); //$NON-NLS-0$
rowDiv.classList.add("disabledNavRow"); //$NON-NLS-0$
this.setIsNotSelectable(model, true);
},

/**
* Checks if the specified html row node is disabled.
* @return true if the specified node's classList contains the
* "disabledNavRow" class, false otherwise
*/
isDisabled: function(rowDiv) {
return rowDiv.classList.contains("disabledNavRow"); //$NON-NLS-0$
},

/**
* Enables the specified model.
*
* @param {Object} model
*/
enableItem: function(model) {
var rowDiv = this.getRowDiv(model);
if (rowDiv) {
rowDiv.classList.remove("disabledNavRow"); //$NON-NLS-0$
this.setIsNotSelectable(model, false);
}
},
};
return ExplorerNavHandler;
}());
Expand Down
Expand Up @@ -183,7 +183,7 @@ define([
/**
* @param {Element} rowElement
*/
NavigatorRenderer.prototype.rowCallback = function(rowElement) {
NavigatorRenderer.prototype.rowCallback = function(rowElement, model) {
rowElement.setAttribute("role", "treeitem"); //$NON-NLS-1$ //$NON-NLS-0$
};

Expand Down
96 changes: 86 additions & 10 deletions bundles/org.eclipse.orion.client.ui/web/orion/fileCommands.js
Expand Up @@ -253,7 +253,42 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',

// Shared for the whole page
var bufferedSelection = [];

var isCutInProgress = false;

/**
* Returns the buffer containing the cut selections or null if a
* cut operation is not in progress.
* @name orion.fileCommands#getCutBuffer
* @function
* @returns {Array} bufferedSelection or null
*/
fileCommandUtils.getCutBuffer = function() {
return isCutInProgress ? bufferedSelection : null;
};

/**
* Tests whether or not the specified model is equal to
* or a child of the specified bufferedModel.
*
* @returns true if the test passes, false otherwise
*/
fileCommandUtils.isEqualToOrChildOf = function(model, bufferedModel) {
if (model.Location === bufferedModel.Location) {
return true;
} else if (-1 !== model.Location.indexOf(bufferedModel.Location)) {
// model may be a child of bufferedModel
if (model.parent === bufferedModel.parent) {
// model is not a child but rather a file in the same
// directory with a name that starts with bufferedModel's name
return false;
}
return true;
}

return false;
};

/**
* Creates the commands related to file management.
* @param {orion.serviceregistry.ServiceRegistry} serviceRegistry The service registry to use when creating commands
Expand Down Expand Up @@ -678,7 +713,8 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
});
// Remove deleted item from copy/paste buffer
bufferedSelection = bufferedSelection.filter(function(element){
return element.Location !== item.Location;
// deleted item is neither equivalent nor a parent of the array element
return !fileCommandUtils.isEqualToOrChildOf(element, item);
});
dispatchModelEvent({ type: "delete", oldValue: item, newValue: null, parent: parent, count: items.length }); //$NON-NLS-0$
}, errorHandler);
Expand Down Expand Up @@ -994,14 +1030,42 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
});
commandService.addCommand(moveCommand);

var copyToBuffer = function() {
var navHandler = explorer.getNavHandler();
// re-enable items that were previously cut and not yet pasted, if any
if (isCutInProgress) {
bufferedSelection.forEach(function(previouslyCutItem){
navHandler.enableItem(previouslyCutItem);
});
}
isCutInProgress = false; // reset the state, caller should set to true if necessary
bufferedSelection = explorer.selection.getSelections();
};

var cutCommand = new mCommands.Command({
name: messages["Cut"],
id: "eclipse.cut" + idSuffix, //$NON-NLS-0$
callback: function() {
var navHandler = explorer.getNavHandler();

copyToBuffer();

if (bufferedSelection.length) {
isCutInProgress = true;
// disable cut items in explorer
bufferedSelection.forEach(function(cutItem){
navHandler.disableItem(cutItem);
});
}
},
visibleWhen: oneOrMoreFilesOrFolders
});
commandService.addCommand(cutCommand);

var copyToBufferCommand = new mCommands.Command({
name: messages["Copy"],
id: "eclipse.copySelections" + idSuffix, //$NON-NLS-0$
callback: function() {
explorer.selection.getSelections(function(selections) {
bufferedSelection = selections;
});
},
callback: copyToBuffer,
visibleWhen: oneOrMoreFilesOrFolders
});
commandService.addCommand(copyToBufferCommand);
Expand All @@ -1024,6 +1088,7 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
errorHandler(messages["Cannot paste into the root"]);
return;
}
var fileOperation = isCutInProgress ? fileClient.moveFile : fileClient.copyFile;
var summary = [];
var deferreds = [];
bufferedSelection.forEach(function(selectedItem) {
Expand Down Expand Up @@ -1051,25 +1116,36 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
}
}
if (location) {
var deferred = fileClient.copyFile(location, itemLocation, name);
deferreds.push(progressService.showWhile(deferred, i18nUtil.formatMessage(messages["Pasting ${0}"], location)).then(
var deferred = fileOperation.apply(fileClient, [location, itemLocation, name]);
var messageKey = isCutInProgress ? "Moving ${0}": "Pasting ${0}"; //$NON-NLS-1$ //$NON-NLS-0$
var eventType = isCutInProgress ? "move": "copy"; //$NON-NLS-1$ //$NON-NLS-0$
deferreds.push(progressService.showWhile(deferred, i18nUtil.formatMessage(messages[messageKey], location)).then(
function(result) {
summary.push({
oldValue: selectedItem,
newValue: result,
parent: item
});
dispatchModelEvent({ type: "copy", oldValue: selectedItem, newValue: result, parent: item, count: bufferedSelection.length }); //$NON-NLS-0$
dispatchModelEvent({ type: eventType, oldValue: selectedItem, newValue: result, parent: item, count: bufferedSelection.length });
},
errorHandler));
}
}
});
Deferred.all(deferreds).then(function() {
dispatchModelEvent({
type: "copyMultiple", //$NON-NLS-0$
type: isCutInProgress ? "moveMultiple" : "copyMultiple", //$NON-NLS-1$ //$NON-NLS-0$
items: summary
});

if (isCutInProgress) {
var navHandler = explorer.getNavHandler();
bufferedSelection.forEach(function(pastedItem){
navHandler.enableItem(pastedItem);
});
bufferedSelection = [];
isCutInProgress = false;
}
});
}
});
Expand Down
Expand Up @@ -86,6 +86,7 @@ define({
"Creating ${0}": "Creating ${0}",
"Linking to ${0}": "Linking to ${0}",
"Move files and folders to a new location": "Move files and folders to a new location",
"Cut": "Cut",
"Copy": "Copy",
"Fetching children of ": "Fetching children of ",
"Paste": "Paste",
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.orion.client.ui/web/orion/outliner.js
Expand Up @@ -192,7 +192,7 @@ define([
}

// set node's keyboard traversal selectability
node.isNotSelectable = !nodeMatchesFilter;
navHandler.setIsNotSelectable(node, !nodeMatchesFilter);

return visible;
};
Expand Down
Expand Up @@ -136,9 +136,6 @@ define(['i18n!orion/nls/messages', 'orion/webui/littlelib'], function(messages,
for (var i=0; i<children.length; i++) {
var row = document.createElement(this._tableRowElement); //$NON-NLS-0$
row.id = this._treeModel.getId(children[i]);
if (this._renderer.rowCallback) {
this._renderer.rowCallback(row);
}
row._depth = indentLevel;
// This is a perf problem and potential leak because we're bashing a dom node with
// a javascript object. (Whereas above we are using simple numbers/strings).
Expand All @@ -148,6 +145,11 @@ define(['i18n!orion/nls/messages', 'orion/webui/littlelib'], function(messages,
// generate an indent
var indent = this._indent * indentLevel;
row.childNodes[this._labelColumnIndex].style.paddingLeft = indent +"px"; //$NON-NLS-0$

if (this._renderer.rowCallback) {
this._renderer.rowCallback(row, children[i]);
}

if (referenceNode) {
this._bodyElement.insertBefore(row, referenceNode.nextSibling);
if (referenceNode) { //$NON-NLS-0$
Expand Down

0 comments on commit f84a41c

Please sign in to comment.