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

Fix for issue #1122 #1661

Merged
merged 17 commits into from
Oct 8, 2012
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions src/htmlContent/main-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@
</div>

<div id="jslint-results" class="bottom-panel">
<div id="jslint-resizer" class="h-resizer"></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice if the resizing functionality could be added to a bottom panel simply by adding a the h-resizer class to the parent container and this DIV was dynamically added to the DOM. This would make it easier and less obtrusive to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be okay to have a module like utils/Resizer and scan for resizer classes on initialization to add the necessary elements as well as configure the behavior?

It could work also on the sidebar...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that sounds like the best solution.

<div class="toolbar simple-toolbar-layout">
<div class="title">{{JSLINT_ERRORS}}</div>
</div>
<div class="table-container"></div>
</div>

<div id="search-results" class="bottom-panel">
<div id="search-resizer" class="h-resizer"></div>
<div class="toolbar simple-toolbar-layout">
<div class="title">{{SEARCH_RESULTS}}</div>
<div class="title" id="search-result-summary"></div>
Expand Down
107 changes: 104 additions & 3 deletions src/language/JSLintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, JSLINT, PathUtils */
/*global define, $, JSLINT, PathUtils, document, window */
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like both document and window are no longer used and can be removed


/**
* Allows JSLint to run on the current document and report results in a UI panel.
Expand All @@ -44,8 +44,22 @@ define(function (require, exports, module) {
EditorManager = require("editor/EditorManager"),
PreferencesManager = require("preferences/PreferencesManager"),
PerfUtils = require("utils/PerfUtils"),
Strings = require("strings");
Strings = require("strings"),
AppInit = require("utils/AppInit");

var MIN_HEIGHT = 100;

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

// These vars are initialized by the htmlReady handler
// below since they refer to DOM elements
var $mainView,
$jslintResults,
$jslintContent,
$jslintToolbar,
$jslintResizer;

/**
* @private
* @type {PreferenceStorage}
Expand Down Expand Up @@ -200,14 +214,101 @@ define(function (require, exports, module) {
setEnabled(!getEnabled());
}

/**
* @private
* Sets jslint panel height and resizes editor.
* @param {number} height Height in pixels.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot of duplicated code here that needs to be refactored into a single resizer class. There are several other extensions (and I expect more to come) that also use the bottom panel adn would like to have this same functionality:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't thought about the other extensions... should we refactor this in a utils/Resizer module with a simple API to make an element or extension resizable and initialize its behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

function _setHeight(height) {
// There seems to be a race condition when accessing height if JSLint is
// enabled when Brackets is opening. Neither htmlReady nor appReady seem
// to work for that. Forcing 27px height for the toolbar in that case.
var toolbarHeight = $jslintToolbar.outerHeight(true);
if (!$jslintToolbar.height()) {
toolbarHeight = 27;
}

height = Math.max(height, MIN_HEIGHT);
_prefs.setValue("height", height);

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

EditorManager.resizeEditor();
}

/**
* @private
* Initialize resize handling.
*/
function _initJSLintResizer() {
var $body = $(document.body),
animationRequest = null,
isMouseDown = false;

if (_enabled) {
_setHeight(_prefs.getValue("height"));
}

$jslintResizer.on("mousedown.jslint", function (e) {
var startY = e.clientY,
startHeight = $jslintResults.height(),
newHeight = startHeight + (startY - e.clientY),
doResize = true;

isMouseDown = true;
$body.toggleClass("hor-resizing");

animationRequest = window.webkitRequestAnimationFrame(function doRedraw() {
// only run this if the mouse is down so we don't constantly loop even
// after we're done resizing.
if (!isMouseDown) {
return;
}

if (doResize) {
_setHeight(newHeight);
}

animationRequest = window.webkitRequestAnimationFrame(doRedraw);
});

$mainView.on("mousemove.jslint", function (e) {
// calculate newHeight as difference between stargint and current
// position to avoid dependencies with other panels
newHeight = startHeight + (startY - e.clientY);
e.preventDefault();
});

$mainView.one("mouseup.jslint", function (e) {
isMouseDown = false;
$mainView.off("mousemove.jslint");
$body.toggleClass("hor-resizing");
});

e.preventDefault();
});
}

// Register command handlers
CommandManager.register(Strings.CMD_JSLINT, Commands.TOGGLE_JSLINT, _handleToggleJSLint);

// Init PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(module.id, { enabled: !!brackets.config.enable_jslint });
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);
_setEnabled(_prefs.getValue("enabled"));

// Initialize items dependent on HTML DOM
AppInit.htmlReady(function () {
$mainView = $(".main-view");
$jslintResults = $("#jslint-results");
$jslintResizer = $("#jslint-resizer");
$jslintToolbar = $("#jslint-results .toolbar");
$jslintContent = $("#jslint-results .table-container");

// init
_initJSLintResizer();
});

// Define public API
exports.run = run;
exports.getEnabled = getEnabled;
Expand Down
99 changes: 96 additions & 3 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, PathUtils, window */
/*global define, $, PathUtils, window, document */
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like both document and window are no longer used and can be removed


/*
* Adds a "find in files" command to allow the user to find all occurances of a string in all files in
Expand Down Expand Up @@ -50,11 +50,25 @@ define(function (require, exports, module) {
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileIndexManager = require("project/FileIndexManager"),
AppInit = require("utils/AppInit"),
PreferencesManager = require("preferences/PreferencesManager"),
KeyEvent = require("utils/KeyEvent");


var FIND_IN_FILES_MAX = 100;

var MIN_HEIGHT = 100;

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

// These vars are initialized by the htmlReady handler
// below since they refer to DOM elements
var $mainView,
$searchResults,
$searchContent,
$searchToolbar,
$searchResizer;

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

Expand Down Expand Up @@ -332,6 +346,85 @@ define(function (require, exports, module) {
}
});
}

/**
* @private
* Sets jslint panel height and resizes editor.
* @param {number} height Height in pixels.
*/
function _setHeight(height) {
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);

height = Math.max(height, MIN_HEIGHT);

$searchResults.height(height);
$searchContent.height(height - $searchToolbar.outerHeight());

prefs.setValue("height", height);
EditorManager.resizeEditor();
}

/**
* @private
* Install resize handling.
*/
function _initSearchResizer() {
var $body = $(document.body),
prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs),
animationRequest = null,
isMouseDown = false;

$searchResizer.on("mousedown.search", function (e) {
var startY = e.clientY,
startHeight = $searchResults.height(),
newHeight = startHeight + (startY - e.clientY),
doResize = true;

isMouseDown = true;
$body.toggleClass("hor-resizing");

animationRequest = window.webkitRequestAnimationFrame(function doRedraw() {
// only run this if the mouse is down so we don't constantly loop even
// after we're done resizing.
if (!isMouseDown) {
return;
}

if (doResize) {
_setHeight(newHeight);
}

animationRequest = window.webkitRequestAnimationFrame(doRedraw);
});

$mainView.on("mousemove.search", function (e) {
// calculate newHeight as difference between stargint and current
// position to avoid dependencies with other panels
newHeight = startHeight + (startY - e.clientY);
e.preventDefault();
});

$mainView.one("mouseup.search", function (e) {
isMouseDown = false;
$mainView.off("mousemove.search");
$body.toggleClass("hor-resizing");
});

e.preventDefault();
});
}

CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.EDIT_FIND_IN_FILES, doFindInFiles);
});

// Initialize items dependent on HTML DOM
AppInit.htmlReady(function () {
$mainView = $(".main-view");
$searchResults = $("#search-results");
$searchResizer = $("#search-resizer");
$searchToolbar = $("#search-results .toolbar");
$searchContent = $("#search-results .table-container");

// init
_initSearchResizer();
});
});
15 changes: 15 additions & 0 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ body {
&.resizing a, &.resizing #projects a, &.resizing .main-view, &.resizing .CodeMirror-lines {
cursor: col-resize;
}

/* This appears to be necessary in Firefox when body is set to display: box. */
height: 100%;
&.hor-resizing a, &.hor-resizing #projects a, &.hor-resizing .main-view, &.hor-resizing .CodeMirror-lines {
cursor: row-resize;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Brackets currently doesn't support Firefox, so is this necessary? Maybe the comment is incorrect.

}


Expand Down Expand Up @@ -116,6 +122,15 @@ a, img {
border-width: 1px;
border-color: lighten(@bc-grey, @bc-color-step-size*4);

.h-resizer {
position: absolute;
height: 6px;
width: 100%;
z-index: @z-index-brackets-bottom-resizer;
opacity: 0;
cursor: row-resize;
}

.toolbar {
height: auto;
padding-top: @base-padding / 2;
Expand Down
1 change: 1 addition & 0 deletions src/styles/brackets_variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@

@z-index-brackets-sidebar-resizer: @z-index-brackets-ui + 2;
@z-index-brackets-resizer-div: @z-index-brackets-sidebar-resizer + 1;
@z-index-brackets-bottom-resizer: @z-index-brackets-ui + 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

@z-index-brackets-bottm-panel-resizer would be more accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix...


@z-index-brackets-context-menu-base: 1000;