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

Added support for closing files on middle click #3901

Merged
merged 5 commits into from
May 28, 2013
Merged
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion src/project/WorkingSetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ define(function (require, exports, module) {
return (docIfOpen && docIfOpen.isDirty);
}

/**
* @private
* @param {$.Event} event The Click Event to respond to.
*/
function _handleMiddleMouseClick(event) {
var file = $(event.target).closest("li").data(_FILE_KEY);

CommandManager.execute(Commands.FILE_CLOSE, {file: file});
}

/**
* Builds the UI for a new list item and inserts in into the end of the list
* @private
Expand All @@ -361,7 +371,7 @@ define(function (require, exports, module) {
$openFilesContainer.find("ul").append($newItem);

// working set item might never have been opened; if so, then it's definitely not dirty

// Update the listItem's apperance
_updateFileStatusIcon($newItem, isOpenAndDirty(file), false);
_updateListItemSelection($newItem, curDoc);
Expand All @@ -370,6 +380,13 @@ define(function (require, exports, module) {
_reorderListItem(e, $(this));
e.preventDefault();
});

$newItem.click(function (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lot easier to implement by just changing line 233 to if (!fromClose || event.which !== 2) since mousedown calls _reorderListItem, and inside _reorderListItem if the user isn't using the left button, it calls drop, so if in drop we check if the user pressed the middle button and close the file, it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

@TomMalbran
Thanks for your suggestion of an alternative solution which has the least changes to get this functionality. But I think @WebsiteDeveloper current solution is cleaner, and easier to understand and easier to locate the implementation due to the function name and the event being used. Your solution may not be easy for someone to locate the code since it is harder to imagine that a middle button click is implemented inside drop() function which is called from _reorderListItem. And also if someone is going to restrict the call of drop() to only left mouse button clicks in the future (since drag-n-drop is done with left mouse button), then this functionality will be broken.

Copy link
Contributor

Choose a reason for hiding this comment

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

@RaymondLim No problem. I thought it would make sense to have all the close implementations together, since closing from the "x" button is already implemented inside the drag and drop implementation to be able to drag from the close button if desired.

if (e.which === 2) {
_handleMiddleMouseClick(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This does work, but I think this should be done in mouse up events rather than right here. Try with tabs in the browsers and other editors. All of them work on mouse ups.

}
e.preventDefault();
});

$newItem.hover(
function () {
Expand Down