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

Project panel bug fixes #845

Merged
merged 14 commits into from
May 10, 2012
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
67 changes: 2 additions & 65 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ define(function (require, exports, module) {
FileUtils = require("file/FileUtils"),
Strings = require("strings"),
Dialogs = require("widgets/Dialogs"),
ExtensionLoader = require("utils/ExtensionLoader");
ExtensionLoader = require("utils/ExtensionLoader"),
SidebarView = require("project/SidebarView");

//Load modules that self-register and just need to get included in the main project
require("language/JSLintUtils");
Expand Down Expand Up @@ -249,69 +250,6 @@ define(function (require, exports, module) {
e.preventDefault();
});
}

function initSidebarListeners() {
var $sidebar = $(".sidebar");
var sidebarWidth = $sidebar.width();
var isSidebarHidden = false;
var sidebarSnappedClosed = false;
var startingSidebarPosition = sidebarWidth;

$("#sidebar-resizer").css("left", sidebarWidth - 1);
$("#sidebar-resizer").on("mousedown.sidebar", function (e) {

// check to see if we're currently in hidden mode
if (ProjectManager.getSidebarState() === ProjectManager.SIDEBAR_CLOSED) {
// when we click, start modifying the sidebar size and then
// modify the variables to set the sidebar state correctly.
CommandManager.execute(Commands.VIEW_HIDE_SIDEBAR, 1);

// this makes sure we don't snap back when we drag from a hidden position
sidebarSnappedClosed = true;

// this keeps the triangle from jumping around
$(".triangle-visible").css("display", "none");
}
$(".main-view").on("mousemove.sidebar", function (e) {
// if we've gone below 10 pixels on a mouse move, and the
// sidebar has not been snapped close, hide the sidebar
// automatically an unbind the mouse event.
if (e.clientX < 10 && !sidebarSnappedClosed) {

CommandManager.execute(Commands.VIEW_HIDE_SIDEBAR, startingSidebarPosition);

$("#sidebar-resizer").css("left", 0);
$(".main-view").off("mousemove.sidebar");
} else {
// if we've moving past 10 pixels, make the triangle visible again
// and register that the sidebar is no longer snapped closed.
if (e.clientX > 10) {
sidebarSnappedClosed = false;
$(".triangle-visible").css("display", "block");
}

$("#sidebar-resizer").css("left", e.clientX);
$sidebar.css("width", e.clientX);

// trigger the scroll events to resize shadows and the selectionTriangle
$("#project-files-container").trigger("scroll");
$("#open-files-container").trigger("scroll");

// the .sidebar-selection needs to be explicitly set
$(".sidebar-selection").width(e.clientX);
}
EditorManager.resizeEditor();
e.preventDefault();
});
e.preventDefault();
});
$("#sidebar-resizer").on("mouseup.sidebar", function (e) {
$(".main-view").off("mousemove.sidebar");
startingSidebarPosition = $sidebar.width();
console.log(startingSidebarPosition);
});

}

// Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules
$("body").addClass("platform-" + brackets.platform);
Expand All @@ -334,7 +272,6 @@ define(function (require, exports, module) {
initKeyBindings();
Menus.init(); // key bindings should be initialized first
initWindowListeners();
initSidebarListeners();

// Load extensions

Expand Down
28 changes: 14 additions & 14 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ define(function (require, exports, module) {
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar";

// Navigate
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition";
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine";
exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor";
exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch";
exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch";
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition";
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine";
exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor";
exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch";
exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch";

exports.DEBUG_REFRESH_WINDOW = "debug.refreshWindow"; // string must MATCH string in native code (brackets_extensions)
exports.DEBUG_SHOW_DEVELOPER_TOOLS = "debug.showDeveloperTools";
exports.DEBUG_RUN_UNIT_TESTS = "debug.runUnitTests";
exports.DEBUG_JSLINT = "debug.jslint";
exports.DEBUG_SHOW_PERF_DATA = "debug.showPerfData";
exports.DEBUG_NEW_BRACKETS_WINDOW = "debug.newBracketsWindow";
exports.DEBUG_CLOSE_ALL_LIVE_BROWSERS = "debug.closeAllLiveBrowsers";
exports.DEBUG_USE_TAB_CHARS = "debug.useTabChars";
exports.DEBUG_REFRESH_WINDOW = "debug.refreshWindow"; // string must MATCH string in native code (brackets_extensions)
exports.DEBUG_SHOW_DEVELOPER_TOOLS = "debug.showDeveloperTools";
exports.DEBUG_RUN_UNIT_TESTS = "debug.runUnitTests";
exports.DEBUG_JSLINT = "debug.jslint";
exports.DEBUG_SHOW_PERF_DATA = "debug.showPerfData";
exports.DEBUG_NEW_BRACKETS_WINDOW = "debug.newBracketsWindow";
exports.DEBUG_CLOSE_ALL_LIVE_BROWSERS = "debug.closeAllLiveBrowsers";
exports.DEBUG_USE_TAB_CHARS = "debug.useTabChars";

exports.HELP_ABOUT = "help.about";
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<!-- Main UI -->
<div class="main-view">
<div id="sidebar-resizer"></div>
<div class="sidebar quiet-scrollbars">
<div id="sidebar" class="sidebar quiet-scrollbars">
<!-- Left-hand 'Project panel' -->
<div id="projects" class="panel">
<div id="project-header"></div>
Expand Down
136 changes: 78 additions & 58 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils"),
FileUtils = require("file/FileUtils");

/**
* @private
* Reference to the tree control container div
* @type {jQueryObject}
*/
var $projectTreeContainer = $("#project-files-container");

/**
* @private
* Reference to the tree control
Expand All @@ -65,11 +72,19 @@ define(function (require, exports, module) {

/**
* @private
* Reference to previous selectiooon jstree node
* Reference to previous selected jstree leaf node when ProjectManager had
* selection focus from FileViewController.
* @type {DOMElement}
*/
var _lastSelected = null;

/**
* @private
* Internal flag to suppress firing of selectionChanged event.
* @type {boolean}
*/
var _suppressSelectionChange = false;

/**
* @private
* Reference to the tree control UL element
Expand Down Expand Up @@ -99,33 +114,27 @@ define(function (require, exports, module) {
fullPathToIdMap : {} /* mapping of fullPath to tree node id attr */
};

/**
* @const
* Sidebar open constant
*/
var SIDEBAR_OPEN = "open";

/**
* @const
* Sidebar closed constant
*/
var SIDEBAR_CLOSED = "closed";

/**
/**
* @private
* Current state of sidebar
*/
var _sidebarState = SIDEBAR_OPEN;


function _hasFileSelectionFocus() {
return FileViewController.getFileSelectionFocus() === FileViewController.PROJECT_MANAGER;
}

/**
* @private
*/
function _fireSelectionChanged() {
function _redraw(selectionChanged, reveal) {
reveal = (reveal === undefined) ? true : reveal;

// redraw selection
if ($projectTreeList) {
$projectTreeList.trigger("selectionChanged");
if (selectionChanged && !_suppressSelectionChange) {
$projectTreeList.triggerHandler("selectionChanged", reveal);
}

// reposition the selection triangle
$projectTreeContainer.triggerHandler("scroll");

// in-lieu of resize events, manually trigger contentChanged for every
// FileViewController focus change. This event triggers scroll shadows
Expand All @@ -137,8 +146,7 @@ define(function (require, exports, module) {

var _documentSelectionFocusChange = function () {
var curDoc = DocumentManager.getCurrentDocument();
if (curDoc
&& (FileViewController.getFileSelectionFocus() !== FileViewController.WORKING_SET_VIEW)) {
if (curDoc && _hasFileSelectionFocus()) {
$("#project-files-container li").is(function (index) {
var entry = $(this).data("entry");

Expand All @@ -156,7 +164,7 @@ define(function (require, exports, module) {
_lastSelected = null;
}

_fireSelectionChanged();
_redraw(true);
};

/**
Expand Down Expand Up @@ -238,6 +246,25 @@ define(function (require, exports, module) {

_prefs.setAllValues(storage);
}

/**
* @private
*/
function _forceSelection(current, target) {
// select_node will force the target to be revealed. Instead,
// keep the scroller position stable.
var savedScrollTop = $projectTreeContainer.get(0).scrollTop;

// suppress selectionChanged event from firing by jstree select_node
_suppressSelectionChange = true;
_projectTree.jstree("deselect_node", current);
_projectTree.jstree("select_node", target, false);
_suppressSelectionChange = false;

$projectTreeContainer.get(0).scrollTop = savedScrollTop;

_redraw(true, false);
}

/**
* @private
Expand All @@ -247,8 +274,7 @@ define(function (require, exports, module) {
* http://www.jstree.com/documentation/json_data
*/
function _renderTree(treeDataProvider) {
var $projectTreeContainer = $("#project-files-container"),
result = new $.Deferred();
var result = new $.Deferred();

// Instantiate tree widget
// (jsTree is smart enough to replace the old tree if there's already one there)
Expand Down Expand Up @@ -280,24 +306,23 @@ define(function (require, exports, module) {
function (event, data) {
var entry = data.rslt.obj.data("entry");
if (entry.isFile) {
var openResult = FileViewController.openAndSelectDocument(entry.fullPath, "ProjectManager");
var openResult = FileViewController.openAndSelectDocument(entry.fullPath, FileViewController.PROJECT_MANAGER);

openResult.done(function () {
// update when tree display state changes
_fireSelectionChanged();
_redraw(true);
_lastSelected = data.rslt.obj;
}).fail(function () {
if (_lastSelected) {
// revert this new selection and restore previous selection
_projectTree.jstree("deselect_node", data.rslt.obj);
_projectTree.jstree("select_node", _lastSelected, false);
_forceSelection(data.rslt.obj, _lastSelected);
} else {
_projectTree.jstree("deselect_all");
_lastSelected = null;
}
});
} else {
_fireSelectionChanged();
_redraw(true);
}
}
)
Expand Down Expand Up @@ -335,10 +360,27 @@ define(function (require, exports, module) {
.bind(
"loaded.jstree open_node.jstree close_node.jstree",
function (event, data) {
ViewUtils.updateChildrenToParentScrollwidth($("#project-files-container"));

// update when tree display state changes
_fireSelectionChanged();
if (event.type === "open_node") {
// select the current document if it becomes visible when this folder is opened
var curDoc = DocumentManager.getCurrentDocument();

if (_hasFileSelectionFocus() && curDoc) {
var entry = data.rslt.obj.data("entry");

if (curDoc.file.fullPath.indexOf(entry.fullPath) === 0) {
_forceSelection(data.rslt.obj, _lastSelected);
} else {
_redraw(true, false);
}
}
} else if (event.type === "close_node") {
// always update selection marker position when collapsing a node
_redraw(true, false);
} else {
_redraw(false);
}

_savePreferences();
}
);
Expand Down Expand Up @@ -545,9 +587,6 @@ define(function (require, exports, module) {
// Success!
_projectRoot = rootEntry;

// Set title
$("#project-title").html(_projectRoot.name);

// The tree will invoke our "data provider" function to populate the top-level items, then
// go idle until a node is expanded - at which time it'll call us again to fetch the node's
// immediate children, and so on.
Expand Down Expand Up @@ -807,23 +846,6 @@ define(function (require, exports, module) {
function forceFinishRename() {
$(".jstree-rename-input").blur();
}

/***** Start of Sidebar methods ******/

/**
* Gets the current state of the sidebar
*/
function getSidebarState() {
return _sidebarState;
}

/**
* Sets the sidebar state when something happens
* @param newState {string} new state for sidebar
*/
function setSidebarState(newState) {
_sidebarState = newState;
}

// Define public API
exports.getProjectRoot = getProjectRoot;
Expand All @@ -834,10 +856,6 @@ define(function (require, exports, module) {
exports.getSelectedItem = getSelectedItem;
exports.createNewItem = createNewItem;
exports.forceFinishRename = forceFinishRename;
exports.SIDEBAR_OPEN = SIDEBAR_OPEN;
exports.SIDEBAR_CLOSED = SIDEBAR_CLOSED;
exports.getSidebarState = getSidebarState;
exports.setSidebarState = setSidebarState;

// Initialize now
(function () {
Expand All @@ -851,7 +869,9 @@ define(function (require, exports, module) {

// Event Handlers
$(FileViewController).on("documentSelectionFocusChange", _documentSelectionFocusChange);
$("#open-files-container").on("contentChanged", _fireSelectionChanged); // redraw jstree when working set size changes
$("#open-files-container").on("contentChanged", function () {
_redraw(false); // redraw jstree when working set size changes
});

CommandManager.register(Commands.FILE_OPEN_FOLDER, openProject);
}());
Expand Down
Loading