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

Resizer preferences and data-minsize #1899

Merged
merged 6 commits into from
Oct 20, 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
21 changes: 2 additions & 19 deletions src/language/JSLintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ define(function (require, exports, module) {
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
AppInit = require("utils/AppInit"),
Resizer = require("utils/Resizer"),
StatusBar = require("widgets/StatusBar");

var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { height: 200, enabled: true };

/** @type {Number} Height of the JSLint panel header in pixels. Hardcoded to avoid race
condition when measuring it on htmlReady*/
var HEADER_HEIGHT = 27;
defaultPrefs = { enabled: true };

/**
* @private
Expand Down Expand Up @@ -229,20 +224,8 @@ define(function (require, exports, module) {

// Initialize items dependent on HTML DOM
AppInit.htmlReady(function () {
var height = Math.max(_prefs.getValue("height"), 100),
$jslintResults = $("#jslint-results"),
var $jslintResults = $("#jslint-results"),
$jslintContent = $("#jslint-results .table-container");

$jslintResults.height(height);
$jslintContent.height(height - HEADER_HEIGHT);

if (_enabled) {
EditorManager.resizeEditor();
}

$jslintResults.on("panelResizeEnd", function (event, height) {
_prefs.setValue("height", height);
});

StatusBar.addIndicator(module.id, $("#gold-star"), false);
});
Expand Down
19 changes: 1 addition & 18 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,15 @@ define(function (require, exports, module) {
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileIndexManager = require("project/FileIndexManager"),
PreferencesManager = require("preferences/PreferencesManager"),
KeyEvent = require("utils/KeyEvent"),
AppInit = require("utils/AppInit"),
Resizer = require("utils/Resizer"),
StatusBar = require("widgets/StatusBar");

var searchResults = [];

var FIND_IN_FILES_MAX = 100,
maxHitsFoundInFile = false;

var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { height: 200 };

/** @type {Number} Height of the FIF panel header in pixels. Hardcoded to avoid race
condition when measuring it on htmlReady*/
var HEADER_HEIGHT = 27;

// This dialog class was mostly copied from QuickOpen. We should have a common dialog
// class that everyone can use.

Expand Down Expand Up @@ -370,16 +361,8 @@ define(function (require, exports, module) {
// Initialize items dependent on HTML DOM
AppInit.htmlReady(function () {
var $searchResults = $("#search-results"),
$searchContent = $("#search-results .table-container"),
prefs = PreferencesManager.getPreferenceStorage(module.id, defaultPrefs),
height = prefs.getValue("height");
$searchContent = $("#search-results .table-container");

$searchResults.height(height);
$searchContent.height(height - HEADER_HEIGHT);

$searchResults.on("panelResizeEnd", function (event, height) {
prefs.setValue("height", height);
});
});

function _fileNameChangeHandler(event, oldName, newName) {
Expand Down
65 changes: 57 additions & 8 deletions src/utils/Resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ define(function (require, exports, module) {
var POSITION_BOTTOM = "bottom";
var POSITION_LEFT = "left";
var POSITION_RIGHT = "right";
// Minimum size (height or width) for autodiscovered resizable panels
var DEFAULT_MIN_SIZE = 100;

// Load dependent modules
var AppInit = require("utils/AppInit"),
PreferencesManager = require("preferences/PreferencesManager"),
EditorManager = require("editor/EditorManager");

var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { };

/**
* @private
* @type {PreferenceStorage}
*/
var _prefs = null;

var $mainView;

/**
Expand Down Expand Up @@ -132,19 +142,23 @@ define(function (require, exports, module) {
$element = $(element),
$resizableElement = $($element.find(".resizable-content:first")[0]),
$body = $(window.document.body),
elementID = $element.attr("id"),
elementPrefs = _prefs.getValue(elementID) || {},
animationRequest = null,
directionProperty = direction === DIRECTION_HORIZONTAL ? "clientX" : "clientY",
elementSizeFunction = direction === DIRECTION_HORIZONTAL ? $element.width : $element.height,
resizerCSSPosition = direction === DIRECTION_HORIZONTAL ? "left" : "top",
contentSizeFunction = null;
contentSizeFunction = direction === DIRECTION_HORIZONTAL ? $resizableElement.width : $resizableElement.height;
minSize = minSize || 0;
collapsable = collapsable || false;

$element.prepend($resizer);

$element.data("show", function () {

$element.show();
elementPrefs.visible = true;

if (collapsable) {
$element.prepend($resizer);
Expand All @@ -153,19 +167,22 @@ define(function (require, exports, module) {

EditorManager.resizeEditor();
$element.trigger("panelExpanded");
_prefs.setValue(elementID, elementPrefs);
});

$element.data("hide", function () {
var elementOffset = $element.offset(),
elementSize = elementSizeFunction.apply($element);

$element.hide();
elementPrefs.visible = false;
if (collapsable) {
$resizer.insertBefore($element).css(resizerCSSPosition, elementOffset[resizerCSSPosition] + elementSize);
}

EditorManager.resizeEditor();
$element.trigger("panelCollapsed");
_prefs.setValue(elementID, elementPrefs);
});

$resizer.on("mousedown", function (e) {
Expand All @@ -189,8 +206,6 @@ define(function (require, exports, module) {
baseSize += $(child).outerHeight();
}
});

contentSizeFunction = direction === DIRECTION_HORIZONTAL ? $resizableElement.width : $resizableElement.height;
}

animationRequest = window.webkitRequestAnimationFrame(function doRedraw() {
Expand Down Expand Up @@ -244,9 +259,18 @@ define(function (require, exports, module) {
}

function endResize(e) {
var elementSize = elementSizeFunction.apply($element);

elementPrefs.size = elementSize;

if (contentSizeFunction) {
elementPrefs.contentSize = contentSizeFunction.apply($resizableElement);
}

if (isMouseDown) {
isMouseDown = false;
$element.trigger("panelResizeEnd", [elementSizeFunction.apply($element)]);
$element.trigger("panelResizeEnd", [elementSize]);
_prefs.setValue(elementID, elementPrefs);

// We wait 100ms to remove the resizer container to capture a mousedown
// on the container that would account for double click
Expand All @@ -263,16 +287,41 @@ define(function (require, exports, module) {

e.preventDefault();
});

// Panel preferences initialization
if (elementPrefs) {

if (elementPrefs.size !== undefined) {
elementSizeFunction.apply($element, [Math.max(elementPrefs.size, minSize)]);
}

if (elementPrefs.contentSize !== undefined) {
contentSizeFunction.apply($resizableElement, [Math.max(elementPrefs.contentSize, minSize)]);
}

//if (elementPrefs.visible !== undefined) {
// hide($element);
//}
}
}

// Init PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);

// Scan DOM for horz-resizable and vert-resizable classes and make them resizable
AppInit.htmlReady(function () {
var minSize = DEFAULT_MIN_SIZE;

$mainView = $(".main-view");

$(".vert-resizable").each(function (index, element) {

if ($(element).data().minsize !== undefined) {
minSize = $(element).data().minsize;
}

if ($(element).hasClass("top-resizer")) {
makeResizable(element, DIRECTION_VERTICAL, POSITION_TOP, DEFAULT_MIN_SIZE, $(element).hasClass("collapsable"));
makeResizable(element, DIRECTION_VERTICAL, POSITION_TOP, minSize, $(element).hasClass("collapsable"));
}

//if ($(element).hasClass("bottom-resizer")) {
Expand Down