Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Reorder Working Set with Drag and Drop #1846

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2cfd1fd
Scroll Line functionality added
TomMalbran Oct 13, 2012
1f79b12
Changing keyboard shortcut
TomMalbran Oct 14, 2012
ef03ba1
Code clean-up
TomMalbran Oct 14, 2012
eea9b5a
Fixes after initial review
TomMalbran Oct 14, 2012
44e2e39
Minor change
TomMalbran Oct 14, 2012
ecc0627
Reorder working set functionality
TomMalbran Oct 15, 2012
563ce4a
Fixing branch
TomMalbran Oct 15, 2012
55bcc84
Minor changes
TomMalbran Oct 15, 2012
11bdc68
Minor changes
TomMalbran Oct 15, 2012
ec73084
Minor changes
TomMalbran Oct 15, 2012
4f9d31f
Code refactoring and bug fixed
TomMalbran Oct 16, 2012
a46841c
Code optimizations
TomMalbran Oct 16, 2012
6baa878
Adding the reorder on DocumentManager
TomMalbran Oct 16, 2012
83280ac
Now it saves the reorder changes
TomMalbran Oct 16, 2012
5dbe02c
Minor fixes
TomMalbran Oct 16, 2012
96b0f58
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 17, 2012
e26a21a
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 18, 2012
be9b0e9
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 20, 2012
883789f
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 20, 2012
b468ae8
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 20, 2012
bce6891
Fixing error with Context Menu
TomMalbran Oct 20, 2012
2610dbc
Added test back in that was commend out for issue #389. This test is …
Oct 21, 2012
83ef3dd
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 21, 2012
4f01dd5
Fixes after review
TomMalbran Oct 21, 2012
21569eb
Fixes after review
TomMalbran Oct 21, 2012
dc0a7a3
Adding dragging from close icon
TomMalbran Oct 21, 2012
fd481e8
Update dirty flag in lightning bolt icon for all dirty flag change no…
RaymondLim Oct 22, 2012
4144abe
Scroll into view and better fix for the boottom shadow
TomMalbran Oct 22, 2012
49d0b80
Fixing indentations
TomMalbran Oct 22, 2012
4d6fe5e
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 22, 2012
b462c33
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 23, 2012
e59cfa5
add settings icon
GarthDB Oct 23, 2012
7dbfe65
Merge pull request #1907 from jeffslofish/issue-389
gruehle Oct 23, 2012
a46cb10
F2 to rename
zanqi Oct 23, 2012
4a62012
make mdoe string more presentable
redmunds Oct 23, 2012
8a27cda
Merge pull request #1922 from zanqi/renaming
peterflynn Oct 23, 2012
32ffe5d
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 24, 2012
83146d2
Merge pull request #1911 from adobe/rlim/dirty-dot-issue
njx Oct 24, 2012
6c33fbd
Merge remote-tracking branch 'upstream/master' into tom/reorder
TomMalbran Oct 24, 2012
c62b99d
Adding scrolling while dragging and other fixes
TomMalbran Oct 24, 2012
c5da9b8
get more info out of mimetype modes
redmunds Oct 24, 2012
30255fc
code review fixes
redmunds Oct 24, 2012
a81b744
add special cases for: less, php
redmunds Oct 24, 2012
5d31007
Merge pull request #1936 from adobe/garthdb/url-mapping
redmunds Oct 24, 2012
25c986b
Merge pull request #1931 from adobe/glenn/extensions-folder
RaymondLim Oct 24, 2012
4b066af
Merge pull request #1923 from adobe/randy/statusbar-mode
RaymondLim Oct 24, 2012
6d44121
Working set view drag & drop to reorder files
TomMalbran Oct 25, 2012
77b0085
Fixing merge issues
TomMalbran Oct 25, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,27 +501,22 @@ define(function LiveDevelopment(require, exports, module) {

/** Triggered by a document saved from the DocumentManager */
function _onDocumentSaved(event, doc) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument) {
if (agents.network && agents.network.wasURLRequested(doc.url)) {
// Reload HTML page
Inspector.Page.reload();

// Reload unsaved changes
_onReconnect();

// Set status back to active
_setStatus(STATUS_ACTIVE);
}
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
// Reload HTML page
Inspector.Page.reload();

// Reload unsaved changes
_onReconnect();
}
}

/** Triggered by a change in dirty flag from the DocumentManager */
function _onDirtyFlagChange(event, doc) {
if (Inspector.connected() && doc && doc.isDirty && _classForDocument(doc) !== CSSDocument) {
if (agents.network && agents.network.wasURLRequested(doc.url)) {
// Set status to out of sync
_setStatus(STATUS_OUT_OF_SYNC);
}
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
// Set status to out of sync if dirty. Otherwise, set it to active status.
_setStatus(doc.isDirty ? STATUS_OUT_OF_SYNC : STATUS_ACTIVE);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ define(function (require, exports, module) {
var project_cmenu = registerContextMenu(ContextMenuIds.PROJECT_MENU);
project_cmenu.addMenuItem(Commands.FILE_NEW);
project_cmenu.addMenuItem(Commands.FILE_NEW_FOLDER);
project_cmenu.addMenuItem(Commands.FILE_RENAME);
project_cmenu.addMenuItem(Commands.FILE_RENAME, "F2");

var working_set_cmenu = registerContextMenu(ContextMenuIds.WORKING_SET_MENU);
working_set_cmenu.addMenuItem(Commands.FILE_CLOSE);
Expand Down
20 changes: 19 additions & 1 deletion src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ define(function (require, exports, module) {
}


/**
* Mutually exchanges the files at the indexes passed by parameters.
* @param {!number} index - old file index
* @param {!number} index - new file index
*/
function swapWorkingSetIndexes(index1, index2) {
var length = _workingSet.length - 1;
var temp;

if (index1 >= 0 && index2 <= length && index1 >= 0 && index2 <= length) {
temp = _workingSet[index1];
_workingSet[index1] = _workingSet[index2];
_workingSet[index2] = temp;
}
}


/**
* Indicate that changes to currentDocument are temporary for now, and should not update the MRU
* ordering of the working set. Useful for next/previous keyboard navigation (until Ctrl is released)
Expand Down Expand Up @@ -1121,6 +1138,7 @@ define(function (require, exports, module) {
exports.addListToWorkingSet = addListToWorkingSet;
exports.removeFromWorkingSet = removeFromWorkingSet;
exports.getNextPrevFile = getNextPrevFile;
exports.swapWorkingSetIndexes = swapWorkingSetIndexes;
exports.beginDocumentNavigation = beginDocumentNavigation;
exports.finalizeDocumentNavigation = finalizeDocumentNavigation;
exports.closeFullEditor = closeFullEditor;
Expand All @@ -1130,7 +1148,7 @@ define(function (require, exports, module) {

// Setup preferences
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
$(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList fileNameChange", _savePreferences);
$(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList fileNameChange workingSetReorder", _savePreferences);

// Performance measurements
PerfUtils.createPerfMeasurement("DOCUMENT_MANAGER_GET_DOCUMENT_FOR_PATH", "DocumentManager.getDocumentForPath()");
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ define(function (require, exports, module) {
}

function _updateModeInfo(editor) {
$modeInfo.text(editor.getModeForSelection());
$modeInfo.text(StatusBar.getModeDisplayString(editor.getModeForSelection()));
}

function _updateFileInfo(editor) {
Expand Down
203 changes: 195 additions & 8 deletions src/project/WorkingSetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
/*global define, $, window */

/**
* WorkingSetView generates the UI for the list of the files user is editing based on the model provided by EditorManager.
Expand All @@ -37,6 +37,7 @@ define(function (require, exports, module) {
var DocumentManager = require("document/DocumentManager"),
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
Menus = require("command/Menus"),
EditorManager = require("editor/EditorManager"),
FileViewController = require("project/FileViewController"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
Expand Down Expand Up @@ -90,6 +91,194 @@ define(function (require, exports, module) {
_fireSelectionChanged();
}

/**
* Starts the drag and drop working set view reorder.
* @private
* @param {!Event} event - jQuery event
* @paran {!HTMLLIElement} $listItem - jQuery element
* @param {?bool} fromClose - true if reorder was called from the close icon
*/
function _reorderListItem(event, $listItem, fromClose) {
var $prevListItem = $listItem.prev(),
$nextListItem = $listItem.next(),
selected = $listItem.hasClass("selected"),
prevSelected = $prevListItem.hasClass("selected"),
nextSelected = $nextListItem.hasClass("selected"),
index = DocumentManager.findInWorkingSet($listItem.data(_FILE_KEY).fullPath),
height = $listItem.height(),
startPageY = event.pageY,
listItemTop = startPageY - $listItem.offset().top,
listItemBottom = $listItem.offset().top + height - startPageY,
offsetTop = $openFilesContainer.offset().top,
scrollElement = $openFilesContainer.get(0),
containerHeight = scrollElement.clientHeight,
maxScroll = scrollElement.scrollHeight - containerHeight,
hasScroll = scrollElement.scrollHeight > containerHeight,
hasBottomShadow = scrollElement.scrollHeight > scrollElement.scrollTop + containerHeight,
addBottomShadow = false,
interval = false,
moved = false;

// Drag the List Item
function drag(e) {
var top = e.pageY - startPageY;

// Drag if the item is not the first and moving it up or
// if the item is not the last and moving down
if (($prevListItem.length && top < 0) || ($nextListItem.length && top > 0)) {
// Reorder the list once the item is halfway to the new position
if (Math.abs(top) > height / 2) {
// If moving up, place the previows item after the moving item
if (top < 0) {
$prevListItem.insertAfter($listItem);
startPageY -= height;
top = top + height;
DocumentManager.swapWorkingSetIndexes(index, --index);
// If moving down, place the next item before the moving item
} else {
$nextListItem.insertBefore($listItem);
startPageY += height;
top = top - height;
DocumentManager.swapWorkingSetIndexes(index, ++index);
}

// Update the selection when the previows or next element were selected
if (!selected && ((top > 0 && prevSelected) || (top < 0 && nextSelected))) {
_fireSelectionChanged();
}

// Update the previows and next items
$prevListItem = $listItem.prev();
$nextListItem = $listItem.next();
prevSelected = $prevListItem.hasClass("selected");
nextSelected = $nextListItem.hasClass("selected");

// If the last item of the list was selected and the previows was moved to its location, then
// the it will show a bottom shadow even if it shouldnt because of the way the scrollHeight is
// handle with relative position. This will remove that shadow and add it on drop.
if (!addBottomShadow && !hasBottomShadow && !$nextListItem.length && prevSelected) {
ViewUtils.removeScrollerShadow($openFilesContainer[0], null);
ViewUtils.addScrollerShadow($openFilesContainer[0], null, false);
addBottomShadow = true;
}
}
// Set the top to 0 as the event probably didnt fired at the exact start/end of the list
} else {
top = 0;
}

// Move the item
$listItem.css("top", top + "px");

// Update the selection position
if (selected) {
_fireSelectionChanged();
}

// Once the movement is greater than 3 pixels, it is assumed that the user wantes to reorder files and not open
if (!moved && Math.abs(top) > 3) {
Menus.closeAll();
moved = true;
}
}

function endScroll() {
window.clearInterval(interval);
interval = false;
}

// Scroll view if the mouse is over the first or last pixels of the container
function scroll(e) {
var dir = 0;
// Mouse over the first visible pixels and moving up
if (e.pageY - listItemTop < offsetTop + 7) {
dir = -1;
// Mouse over the last visible pixels and moving down
} else if (e.pageY + listItemBottom > offsetTop + containerHeight - 7) {
dir = 1;
}

if (dir && !interval) {
// Scroll and drag as long as needed
interval = window.setInterval(function () {
var scrollTop = $openFilesContainer.scrollTop();
// End scroll if there isn't more to scroll
if ((dir === -1 && scrollTop <= 0) || (dir === 1 && scrollTop >= maxScroll)) {
endScroll();
} else {
$openFilesContainer.scrollTop(scrollTop + 7 * dir);
startPageY -= 7 * dir;
drag(e);
}
}, 100);
} else if (!dir && interval) {
endScroll();
}
}

// Drop List Item
function drop() {
// Enable Mousewheel
window.onmousewheel = window.document.onmousewheel = null;

// Removes the styles, placing the item in the chosen place
$listItem.removeAttr("style");

// End the scrolling if needed
if (interval) {
window.clearInterval(interval);
}

// If file wasnt moved open or close it
if (!moved) {
if (!fromClose) {
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
} else {
CommandManager.execute(Commands.FILE_CLOSE, {file: $listItem.data(_FILE_KEY)});
}
} else if (moved) {
if (selected) {
// Update the file selection
_fireSelectionChanged();
ViewUtils.scrollElementIntoView($openFilesContainer, $listItem, false);
}
if (addBottomShadow) {
// Restore the shadows
ViewUtils.addScrollerShadow($openFilesContainer[0], null, true);
}
}

// Dispatch event
$(DocumentManager).triggerHandler("workingSetReorder");
}


// Only drag with the left mouse button, end the drop in other cases
if (event.which !== 1) {
drop();
return;
}

// Disable Mousewheel while dragging
window.onmousewheel = window.document.onmousewheel = function (e) { e.preventDefault(); };

// Style the element
$listItem.css("position", "relative").css("z-index", 1);

// Envent Handlers
$openFilesContainer.on("mousemove.workingSet", function (e) {
if (hasScroll) {
scroll(e);
}
drag(e);
});
$openFilesContainer.on("mouseup.workingSet mouseleave.workingSet", function (e) {
$openFilesContainer.off("mousemove.workingSet mouseup.workingSet mouseleave.workingSet");
drop();

});
}

/**
* Updates the appearance of the list element based on the parameters provided
* @private
Expand All @@ -112,16 +301,14 @@ define(function (require, exports, module) {
$fileStatusIcon = $("<div class='file-status-icon'></div>")
.prependTo(listElement)
.mousedown(function (e) {
// Try to drag if that is what is wanted if not it will be the equivalent to File > Close;
// it doesn't merely remove a file from the working set
_reorderListItem(e, $(this).parent(), true);

// stopPropagation of mousedown for fileStatusIcon so the parent <LI> item, which
// selects documents on mousedown, doesn't select the document in the case
// when the click is on fileStatusIcon
e.stopPropagation();
})
.click(function () {
// Clicking the "X" button is equivalent to File > Close; it doesn't merely
// remove a file from the working set
var file = listElement.data(_FILE_KEY);
CommandManager.execute(Commands.FILE_CLOSE, {file: file});
});
}

Expand Down Expand Up @@ -175,7 +362,7 @@ define(function (require, exports, module) {
_updateListItemSelection($newItem, curDoc);

$newItem.mousedown(function (e) {
FileViewController.openAndSelectDocument(file.fullPath, FileViewController.WORKING_SET_VIEW);
_reorderListItem(e, $(this));
e.preventDefault();
});

Expand Down
18 changes: 18 additions & 0 deletions src/styles/images/settings_small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading