Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/project/FileViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ define(function (require, exports, module) {
* @return {$.Promise}
*/
function openAndSelectDocument(fullPath, fileSelectionFocus, paneId) {
var result;
var result,
curDocChangedDueToMe = _curDocChangedDueToMe;

if (fileSelectionFocus !== PROJECT_MANAGER && fileSelectionFocus !== WORKING_SET_VIEW) {
console.error("Bad parameter passed to FileViewController.openAndSelectDocument");
Expand Down Expand Up @@ -172,7 +173,7 @@ define(function (require, exports, module) {

// clear after notification is done
result.always(function () {
_curDocChangedDueToMe = false;
_curDocChangedDueToMe = curDocChangedDueToMe;
});

return result;
Expand All @@ -199,6 +200,9 @@ define(function (require, exports, module) {
// image file, we get a null doc here but we still want to keep _fileSelectionFocus
// as PROJECT_MANAGER. Regardless of doc is null or not, call _activatePane
// to trigger documentSelectionFocusChange event.
_fileSelectionFocus = WORKING_SET_VIEW;
_activatePane(paneId);

result.resolve(file);
}).fail(function (err) {
result.reject(err);
Expand Down
83 changes: 60 additions & 23 deletions src/project/WorkingSetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ define(function (require, exports, module) {
WorkingSetView.prototype._checkForDuplicatesInWorkingTree = function () {
var self = this,
map = {},
fileList = MainViewManager.getWorkingSet(this.paneId);
fileList = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES);

// We need to always clear current directories as files could be removed from working tree.
this.$openFilesContainer.find("ul > li > a > span.directory").remove();
Expand Down Expand Up @@ -301,14 +301,7 @@ define(function (require, exports, module) {
* @private
*/
WorkingSetView.prototype._redraw = function () {
var paneId = MainViewManager.getActivePaneId();

if (paneId === this.paneId) {
this.$el.addClass("active");
} else {
this.$el.removeClass("active");
}

this._updateViewState();
this._updateVisibility();
this._adjustForScrollbars();
this._fireSelectionChanged();
Expand Down Expand Up @@ -622,13 +615,32 @@ define(function (require, exports, module) {
}
};

/**
* Updates the pane view's selection state
* @private
*/
WorkingSetView.prototype._updateViewState = function () {
var paneId = MainViewManager.getActivePaneId();
if ((FileViewController.getFileSelectionFocus() === FileViewController.WORKING_SET_VIEW) &&
(paneId === this.paneId)) {
this.$el.addClass("active");
this.$openFilesContainer.addClass("active");
} else {
this.$el.removeClass("active");
this.$openFilesContainer.removeClass("active");
}
};

/**
* Updates the pane view's selection marker and scrolls the item into view
* @private
*/
WorkingSetView.prototype._updateListSelection = function () {
var file = MainViewManager.getCurrentlyViewedFile(this.paneId);


this._updateViewState();


// Iterate through working set list and update the selection on each
this.$openFilesContainer.find("ul").children().each(function () {
_updateListItemSelection(this, file);
Expand All @@ -650,6 +662,8 @@ define(function (require, exports, module) {
WorkingSetView.prototype._handleFileAdded = function (e, fileAdded, index, paneId) {
if (paneId === this.paneId) {
this._rebuildViewList(true);
} else {
this._checkForDuplicatesInWorkingTree();
}
};

Expand All @@ -663,6 +677,8 @@ define(function (require, exports, module) {
WorkingSetView.prototype._handleFileListAdded = function (e, files, paneId) {
if (paneId === this.paneId) {
this._rebuildViewList(true);
} else {
this._checkForDuplicatesInWorkingTree();
}
};

Expand All @@ -675,21 +691,38 @@ define(function (require, exports, module) {
* @param {!string} paneId - the id of the pane the item that was to
*/
WorkingSetView.prototype._handleFileRemoved = function (e, file, suppressRedraw, paneId) {
if (paneId === this.paneId && !suppressRedraw) {
var $listItem = this._findListItemFromFile(file);
if ($listItem) {
// Make the next file in the list show the close icon,
// without having to move the mouse, if there is a next file.
var $nextListItem = $listItem.next();
if ($nextListItem && $nextListItem.length > 0) {
var canClose = ($listItem.find(".can-close").length === 1);
var isDirty = _isOpenAndDirty($nextListItem.data(_FILE_KEY));
this._updateFileStatusIcon($nextListItem, isDirty, canClose);
/*
* The suppressRedraw flag is used in cases when we are replacing the working
* set entry with another one. There are only 2 use cases for this:
*
* 1) When an untitled document is being saved.
* 2) When a file is saved with a new name.
*/
if (paneId === this.paneId) {
if (!suppressRedraw) {
var $listItem = this._findListItemFromFile(file);
if ($listItem) {
// Make the next file in the list show the close icon,
// without having to move the mouse, if there is a next file.
var $nextListItem = $listItem.next();
if ($nextListItem && $nextListItem.length > 0) {
var canClose = ($listItem.find(".can-close").length === 1);
var isDirty = _isOpenAndDirty($nextListItem.data(_FILE_KEY));
this._updateFileStatusIcon($nextListItem, isDirty, canClose);
}
$listItem.remove();
}
$listItem.remove();

this._redraw();
}

this._redraw();
} else {
/*
* When this event is handled by a pane that is not being updated then
* the suppressRedraw flag does not need to be respected.
* _checkForDuplicatesInWorkingTree() does not remove any entries so it's
* safe to call at any time.
*/
this._checkForDuplicatesInWorkingTree();
}
};

Expand All @@ -711,6 +744,8 @@ define(function (require, exports, module) {
});

this._redraw();
} else {
this._checkForDuplicatesInWorkingTree();
}
};

Expand Down Expand Up @@ -749,6 +784,8 @@ define(function (require, exports, module) {
WorkingSetView.prototype._handleWorkingSetUpdate = function (e, paneId) {
if (this.paneId === paneId) {
this._rebuildViewList(true);
} else {
this._checkForDuplicatesInWorkingTree();
}
};

Expand Down
22 changes: 6 additions & 16 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,12 @@ a, img {
min-height: 18px;
vertical-align: baseline;

&.selected {
a,
.extension {
color: #99dbff;
}
&.selected a {
color: @open-working-file-name-highlight;
}

&.selected .extension {
color: @open-working-file-ext-highlight;
}
}

Expand Down Expand Up @@ -805,18 +806,7 @@ a, img {
}
}

.open-files-container.active {

li {
&.selected a {
color: @open-working-file-name-highlight;
}

&.selected .extension {
color: @open-working-file-ext-highlight;
}
}
}

.sidebar-selection {
background: @bc-sidebar-selection;
Expand Down
16 changes: 14 additions & 2 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils"),
Resizer = require("utils/Resizer"),
Pane = require("view/Pane").Pane;

/**
* Preference setting name for the MainView Saved State
* @const
Expand Down Expand Up @@ -949,6 +949,16 @@ define(function (require, exports, module) {
});
}

/**
* Updates the header text for all panes
*/
function _updatePaneHeaders() {
_forEachPaneOrPanes(ALL_PANES, function (pane) {
pane.updateHeaderText();
});

}

/**
* Creates a pane for paneId if one doesn't already exist
* @param {!string} paneId - id of the pane to create
Expand All @@ -969,9 +979,11 @@ define(function (require, exports, module) {
});

$(pane).on("viewListChange.mainview", function () {
_updatePaneHeaders();
$(exports).triggerHandler("workingSetUpdate", [pane.id]);
});
$(pane).on("currentViewChange.mainview", function (e, newView, oldView) {
_updatePaneHeaders();
if (_activePaneId === pane.id) {
$(exports).triggerHandler("currentFileChange",
[newView && newView.getFile(),
Expand Down Expand Up @@ -1502,7 +1514,7 @@ define(function (require, exports, module) {
return result;
}

/**
/**
* Setup a ready event to initialize ourself
*/
AppInit.htmlReady(function () {
Expand Down
34 changes: 28 additions & 6 deletions src/view/Pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ define(function (require, exports, module) {
Commands = require("command/Commands"),
Strings = require("strings"),
ViewUtils = require("utils/ViewUtils"),
ProjectManager = require("project/ProjectManager"),
paneTemplate = require("text!htmlContent/pane.html");


Expand Down Expand Up @@ -237,12 +238,17 @@ define(function (require, exports, module) {
}
});

this._updateHeaderText();
this.updateHeaderText();

// Listen to document events so we can update ourself
$(DocumentManager).on(this._makeEventName("fileNameChange"), _.bind(this._handleFileNameChange, this));
$(DocumentManager).on(this._makeEventName("pathDeleted"), _.bind(this._handleFileDeleted, this));
$(MainViewManager).on(this._makeEventName("activePaneChange"), _.bind(this._handleActivePaneChange, this));
$(MainViewManager).on(this._makeEventName("workingSetAdd"), _.bind(this.updateHeaderText, this));
$(MainViewManager).on(this._makeEventName("workingSetRemove"), _.bind(this.updateHeaderText, this));
$(MainViewManager).on(this._makeEventName("workingSetAddList"), _.bind(this.updateHeaderText, this));
$(MainViewManager).on(this._makeEventName("workingSetRemoveList"), _.bind(this.updateHeaderText, this));

}

/**
Expand Down Expand Up @@ -619,8 +625,13 @@ define(function (require, exports, module) {
return uniqueFileList;
};

/**
* Dispatches a currentViewChange event
* @param {?View} newView - the view become the current view
* @param {?View} oldView - the view being replaced
*/
Pane.prototype._notifyCurrentViewChange = function (newView, oldView) {
this._updateHeaderText();
this.updateHeaderText();

$(this).triggerHandler("currentViewChange", [newView, oldView]);
};
Expand Down Expand Up @@ -741,10 +752,21 @@ define(function (require, exports, module) {
* Updates text in pane header
* @private
*/
Pane.prototype._updateHeaderText = function () {
var file = this.getCurrentlyViewedFile();
Pane.prototype.updateHeaderText = function () {
var file = this.getCurrentlyViewedFile(),
files,
displayName;

if (file) {
this.$header.text(file.name);
files = MainViewManager.getAllOpenFiles().filter(function (item) {
return (item.name === file.name);
});
if (files.length < 2) {
this.$header.text(file.name);
} else {
displayName = ProjectManager.makeProjectRelativeIfPossible(file.fullPath);
this.$header.text(displayName);
}
} else {
this.$header.html(Strings.EMPTY_VIEW_HEADER);
}
Expand Down Expand Up @@ -773,7 +795,7 @@ define(function (require, exports, module) {
delete this._views[oldname];
}

this._updateHeaderText();
this.updateHeaderText();

// dispatch the change event
if (dispatchEvent) {
Expand Down