Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 426407 - New File/Folder commands should create a file/folder imm…
…ediately and allow user to rename it

- Modified the name of uiUtils.getUserText()'s option.shouldHideRefNode parameter to option.hideRefNode
- Added optimization in fileCommands.createUniqueNameArtifact() to get children[] from parent item if it is already loaded.

--Signed-off-by: Elijah El-Haddad <elijahe@ca.ibm.com>
  • Loading branch information
elijahe committed Jan 27, 2014
1 parent 7b02897 commit 48b7d41
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
Expand Up @@ -181,7 +181,7 @@ define([
mUIUtils.getUserText({
id: id,
refNode: target,
shouldHideRefNode: true,
hideRefNode: true,
initialText: text,
onComplete: doChange
});
Expand Down
63 changes: 37 additions & 26 deletions bundles/org.eclipse.orion.client.ui/web/orion/fileCommands.js
Expand Up @@ -174,14 +174,14 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',

function getNewItemName(explorer, item, domId, defaultName, onDone) {
var refNode, name, tempNode;
var shouldHideRefNode = true;
var hideRefNode = true;
var insertAsChild = false;

var nodes = explorer.makeNewItemPlaceHolder(item, domId, null, true);
if (nodes) {
refNode = nodes.refNode;
tempNode = nodes.tempNode;
shouldHideRefNode = false;
hideRefNode = false;
insertAsChild = true;
} else {
refNode = lib.node(domId);
Expand All @@ -206,7 +206,7 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
mUIUtils.getUserText({
id: domId+"EditBox", //$NON-NLS-0$
refNode: refNode,
shouldHideRefNode: shouldHideRefNode,
hideRefNode: hideRefNode,
initialText: defaultName,
onComplete: done,
onEditDestroy: destroy,
Expand Down Expand Up @@ -607,7 +607,7 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
mUIUtils.getUserText({
id: id,
refNode: refNode,
shouldHideRefNode: true,
hideRefNode: true,
initialText: item.Name,
onComplete: doMove.bind(null, item),
selectTo: item.Directory ? "" : "." //$NON-NLS-1$ //$NON-NLS-0$
Expand Down Expand Up @@ -784,28 +784,39 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'orion/webui/littlelib',
function createUniqueNameArtifact(parentItem, prefix, createFunction) {
// get the list of files that already exists in the selected directory and ensure
// that the new file's initial name is unique within that directory
var location = parentItem.ChildrenLocation;
progressService.progress(fileClient.fetchChildren(location), messages["Fetching children of "] + parentItem.Name).then( //$NON-NLS-0$
function(children) {
var attempt = 0;
var uniqueName = prefix;

// find a unique name for the new artifact
var possiblyCollidingNames = children.filter(function(child){
return 0 === child.Name.indexOf(prefix);
}).map(function(child){
return child.Name;
});

while (-1 !== possiblyCollidingNames.indexOf(uniqueName)){
attempt++;
uniqueName = prefix.concat(" (").concat(attempt).concat(")"); //$NON-NLS-1$ //$NON-NLS-0$
}

// create the artifact
createFunction(uniqueName);
},
errorHandler);

var findUniqueName = function(children) {
var attempt = 0;
var uniqueName = prefix;

// find a unique name for the new artifact
var possiblyCollidingNames = children.filter(function(child){
return 0 === child.Name.indexOf(prefix);
}).map(function(child){
return child.Name;
});

while (-1 !== possiblyCollidingNames.indexOf(uniqueName)){
attempt++;
uniqueName = prefix.concat(" (").concat(attempt).concat(")"); //$NON-NLS-1$ //$NON-NLS-0$
}

return uniqueName;
};

if (parentItem.children) {
var uniqueName = findUniqueName(parentItem.children);
createFunction(uniqueName); // create the artifact
} else {
// children have not already been fetched, get them
var location = parentItem.ChildrenLocation;
progressService.progress(fileClient.fetchChildren(location), messages["Fetching children of "] + parentItem.Name).then( //$NON-NLS-0$
function(children){
var uniqueName = findUniqueName(children);
createFunction(uniqueName); // create the artifact
},
errorHandler);
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions bundles/org.eclipse.orion.client.ui/web/orion/uiUtils.js
Expand Up @@ -111,7 +111,7 @@ define(['orion/webui/littlelib'], function(lib) {
* @param {Object} options The options object
* @param {String} options.id
* @param {Element} options.refNode
* @param {Boolean} options.shouldHideRefNode
* @param {Boolean} options.hideRefNode
* @param {String} options.initialText
* @param {Function} options.onComplete
* @param {Function} options.onEditDestroy
Expand All @@ -122,7 +122,7 @@ define(['orion/webui/littlelib'], function(lib) {
function getUserText(options) {
var id = options.id;
var refNode = options.refNode;
var shouldHideRefNode = options.shouldHideRefNode;
var hideRefNode = options.hideRefNode;
var initialText = options.initialText;
var onComplete = options.onComplete;
var onEditDestroy = options.onEditDestroy;
Expand All @@ -142,7 +142,7 @@ define(['orion/webui/littlelib'], function(lib) {
return;
}
if (isKeyEvent && event.keyCode === lib.KEY.ESCAPE) {
if (shouldHideRefNode) {
if (hideRefNode) {
refNode.style.display = "inline"; //$NON-NLS-0$
}
done = true;
Expand All @@ -155,13 +155,13 @@ define(['orion/webui/littlelib'], function(lib) {
if (isKeyEvent && event.keyCode !== lib.KEY.ENTER) {
return;
} else if (newValue.length === 0 || (!isInitialValid && newValue === initialText)) {
if (shouldHideRefNode) {
if (hideRefNode) {
refNode.style.display = "inline"; //$NON-NLS-0$
}
done = true;
} else {
onComplete(newValue);
if (shouldHideRefNode && refNode.parentNode) {
if (hideRefNode && refNode.parentNode) {
refNode.style.display = "inline"; //$NON-NLS-0$
}
done = true;
Expand All @@ -186,7 +186,7 @@ define(['orion/webui/littlelib'], function(lib) {
refNode.parentNode.insertBefore(editBox, refNode.nextSibling);
}
editBox.classList.add("userEditBoxPrompt"); //$NON-NLS-0$
if (shouldHideRefNode) {
if (hideRefNode) {
refNode.style.display = "none"; //$NON-NLS-0$
}
editBox.addEventListener("keydown", handler(true), false); //$NON-NLS-0$
Expand Down

0 comments on commit 48b7d41

Please sign in to comment.