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 21 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
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
21 changes: 20 additions & 1 deletion src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ define(function (require, exports, module) {
}


/**
* Changes the position of the file from oldIndex to NewIndex and at the same time the file
* in newIndex to oldIndex. Returns the newIndex
* @param {!number} index - old file index
* @param {!number} index - new file index
*/
function switchFilesIndex(oldIndex, newIndex) {
var length = _workingSet.length - 1;
var aux;

if (oldIndex >= 0 && oldIndex <= length && newIndex >= 0 && newIndex <= length) {
aux = _workingSet[oldIndex];
_workingSet[oldIndex] = _workingSet[newIndex];
_workingSet[newIndex] = aux;
}
}


/**
* 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 +1139,7 @@ define(function (require, exports, module) {
exports.addListToWorkingSet = addListToWorkingSet;
exports.removeFromWorkingSet = removeFromWorkingSet;
exports.getNextPrevFile = getNextPrevFile;
exports.switchFilesIndex = switchFilesIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API call should be more descriptive to distinguish this from the project tree. Also since both indexes are specified, I think it's more of a swap than a switch. Maybe swapWorkingSetIndexes.

exports.beginDocumentNavigation = beginDocumentNavigation;
exports.finalizeDocumentNavigation = finalizeDocumentNavigation;
exports.closeFullEditor = closeFullEditor;
Expand All @@ -1130,7 +1149,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
106 changes: 104 additions & 2 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 @@ -151,6 +152,102 @@ define(function (require, exports, module) {
return (docIfOpen && docIfOpen.isDirty);
}

/**
* Starts the drag and drop working set view reorder.
* @private
* @param {!Event} event - jQuery event
*/
function _reorderListItem(event) {
var $listItem = $(event.currentTarget),
$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,
moved = false;

$listItem.css("position", "relative").css("z-index", 1);

$(window.document).on("mousemove.workingSet", function (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 (top < 0) {
// If moving up, place the previows item after the moving item
$prevListItem.insertAfter($listItem);
startPageY -= height;
top = top + height;
DocumentManager.switchFilesIndex(index, --index);
} else {
// If moving down, place the next item before the moving item
$nextListItem.insertBefore($listItem);
startPageY += height;
top = top - height;
DocumentManager.switchFilesIndex(index, ++index);
}

if (!selected) {
// Remove the shadows as it will appear and they should not
ViewUtils.removeScrollerShadow($openFilesContainer[0], null);
}

// Update the previows and next items
$prevListItem = $listItem.prev();
$nextListItem = $listItem.next();
}
} else {
// Set the top to 0 as the event probably didnt fired at the exact start/end of the list
top = 0;
}

// Once the movement is greater than 2 pixels, it is assumed that the user wantes to reorder files and not open
if (!moved && Math.abs(top) > 2) {
// Hides the selection to optimize the movement
$openFilesContainer.find(".sidebar-selection").css("display", "none");
$openFilesContainer.find(".sidebar-selection-triangle").css("display", "none");
// Hide the close icon
$listItem.find(".file-status-icon").css("display", "none");
// Close all menus
Menus.closeAll();
moved = true;
}

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

$(window.document).on("mouseup.workingSet", function (e) {
// Removes the styles, placing the item in the chocen place
$listItem.removeAttr("style");
$(window.document).off("mousemove.workingSet mouseup.workingSet");

if (!moved) {
// If file wasnt moved, open the file
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
} else {
// Restore the file selection
_fireSelectionChanged();
// Display the status icon again
$listItem.find(".file-status-icon").css("display", "block");

if (!selected) {
// Add the scroller shadow in the case they were removed
ViewUtils.addScrollerShadow($openFilesContainer[0], null, true);
}
}

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

/**
* Builds the UI for a new list item and inserts in into the end of the list
* @private
Expand All @@ -175,7 +272,12 @@ define(function (require, exports, module) {
_updateListItemSelection($newItem, curDoc);

$newItem.mousedown(function (e) {
FileViewController.openAndSelectDocument(file.fullPath, FileViewController.WORKING_SET_VIEW);
// Try to reorder only with the right click and just open the file in other cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean left click, not right click, correct?

if (e.which === 1) {
_reorderListItem(e);
} else {
FileViewController.openAndSelectDocument(file.fullPath, FileViewController.WORKING_SET_VIEW);
}
e.preventDefault();
});

Expand Down