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

Improvements to middle-click closing files #4576

Merged
merged 1 commit into from
Jul 31, 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
45 changes: 12 additions & 33 deletions src/project/WorkingSetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils");


/** @const @type {number} Constants for event.which values */
var LEFT_BUTTON = 1,
MIDDLE_BUTTON = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see those defined as constant. Don't we also need to define RIGHT_BUTTON?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't bother to define right button. We're not using it anywhere any way. We can always add it here when we need it.


/** Each list item in the working set stores a references to the related document in the list item's data.
* Use listItem.data(_FILE_KEY) to get the document reference
*/
Expand Down Expand Up @@ -239,21 +243,14 @@ define(function (require, exports, module) {
window.clearInterval(interval);
}

// If file wasnt moved open or close it
// If item wasn't dragged, treat as a click
if (!moved) {
if (!fromClose) {
/***/
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
/***
// Backing out for Sprint 18 due to issues described in #2394, #2411
if (selected) {
CommandManager.execute(Commands.FILE_RENAME);
} else {
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
}
***/
} else {
// Click on close icon, or middle click anywhere - close the item without selecting it first
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment and the one above really make it clear that we're handling click events in this function, especially middle clicks right here.

if (fromClose || event.which === MIDDLE_BUTTON) {
CommandManager.execute(Commands.FILE_CLOSE, {file: $listItem.data(_FILE_KEY)});
} else {
// Normal right and left click - select the item
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
}

} else {
Expand All @@ -276,7 +273,7 @@ define(function (require, exports, module) {

// Only drag with the left mouse button, and control key is not down
// on Mac, end the drop in other cases
if (event.which !== 1 || (event.ctrlKey && brackets.platform === "mac")) {
if (event.which !== LEFT_BUTTON || (event.ctrlKey && brackets.platform === "mac")) {
drop();
return;
}
Expand Down Expand Up @@ -355,20 +352,11 @@ define(function (require, exports, module) {
}

function isOpenAndDirty(file) {
// working set item might never have been opened; if so, then it's definitely not dirty
var docIfOpen = DocumentManager.getOpenDocumentForPath(file.fullPath);
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 @@ -386,8 +374,6 @@ 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 @@ -397,13 +383,6 @@ define(function (require, exports, module) {
e.preventDefault();
});

$newItem.click(function (e) {
if (e.which === 2) {
_handleMiddleMouseClick(e);
}
e.preventDefault();
});

$newItem.hover(
function () {
_updateFileStatusIcon($(this), isOpenAndDirty(file), true);
Expand Down