-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Toggle panels and no-Distraction mode #11732
Changes from 9 commits
03cabf9
cc58f2f
c93797e
9a7f78a
5495170
e2868de
60e273d
df9c632
a1a6573
51c0232
1968da5
d35ebb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,7 @@ | |
"platform": "mac" | ||
} | ||
], | ||
"view.hideSidebar": [ | ||
"view.toggleSidebar": [ | ||
{ | ||
"key" : "Ctrl-Alt-H" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please review if all of these params to jslint are valid for this file. |
||
/*global define, brackets */ | ||
|
||
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
var Menus = brackets.getModule("command/Menus"), | ||
CommandManager = brackets.getModule("command/CommandManager"), | ||
Commands = brackets.getModule("command/Commands"), | ||
Strings = brackets.getModule("strings"), | ||
PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | ||
ViewUtils = brackets.getModule("utils/ViewUtils"), | ||
KeyBindingManager = brackets.getModule("command/KeyBindingManager"), | ||
WorkspaceManager = brackets.getModule("view/WorkspaceManager"); | ||
|
||
// Constants | ||
var PREFS_PURE_CODE = "noDistractions", | ||
CMD_TOGGLE_PURE_CODE = "view.togglePureCode", | ||
CMD_TOGGLE_PANELS = "view.togglePanels"; | ||
|
||
//key binding keys | ||
var togglePureCodeKey = "Ctrl-Shift-2", | ||
togglePureCodeKeyMac = "Cmd-Shift-2", | ||
togglePanelsKey = "Ctrl-Shift-`", | ||
togglePanelsKeyMac = "Cmd-Shift-`"; | ||
|
||
//locals | ||
var _previouslyOpenPanelIDs = [], | ||
panelsToggled = false, | ||
layoutUpdated = false; | ||
|
||
/** | ||
* @private | ||
* | ||
* Updates the command checked status based on the preference name given. | ||
* | ||
* @param {string} name Name of preference that has changed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update the documentation as I don't see any {string} parameter. |
||
*/ | ||
function _updateCheckedState() { | ||
CommandManager.get(CMD_TOGGLE_PURE_CODE).setChecked(PreferencesManager.get(PREFS_PURE_CODE)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A null check would be better here. |
||
} | ||
|
||
function _togglePureCode() { | ||
PreferencesManager.set(PREFS_PURE_CODE, !PreferencesManager.get(PREFS_PURE_CODE)); | ||
} | ||
|
||
/** | ||
* hide all open panels | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
function _hidePanelsIfRequired() { | ||
var panelIDs = WorkspaceManager.getAllPanelIDs(), i = 0; | ||
_previouslyOpenPanelIDs = []; | ||
for (i = 0; i < panelIDs.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (WorkspaceManager.getPanelForID(panelIDs[i]).isVisible()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we just got the panel ID's from the above statement, this should never be null at this line. It would be better that a NULL access exception be raised here in that case, else will be hard to debug if things fails- which it should not 🔮 . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will never know whether we are given a null panel or an actual panel as that entirely depends on the API that is getting called. A check is surely of no harm here. |
||
WorkspaceManager.getPanelForID(panelIDs[i]).hide(); | ||
_previouslyOpenPanelIDs.push(panelIDs[i]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* show all open panels that was previously hidden by _hidePanelsIfRequired() | ||
*/ | ||
function _showPanelsIfRequired() { | ||
var panelIDs = _previouslyOpenPanelIDs, i = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need of an extra variable |
||
for (i = 0; i < panelIDs.length; i++) { | ||
if (WorkspaceManager.getPanelForID(panelIDs[i])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Store the result from |
||
WorkspaceManager.getPanelForID(panelIDs[i]).show(); | ||
} | ||
} | ||
_previouslyOpenPanelIDs = []; | ||
} | ||
|
||
function _updateLayout() { | ||
layoutUpdated = true; | ||
panelsToggled = false; | ||
} | ||
|
||
/** | ||
* We toggle panels in certain cases only : | ||
* 1. if a panel is shown, toggle can hide it, and successive toggle can show the panel and repeat. | ||
* 2. if a panel is hidden by toggle, and say the workspace changed making another panel visible by some operation; | ||
* we reset toggle states so that toggle would hide the panel already present in the workspace. | ||
* The already hidden panel should not be shown in the specific case for better UX. | ||
*/ | ||
function _togglePanels() { | ||
panelsToggled = !panelsToggled; | ||
if (panelsToggled) { | ||
_hidePanelsIfRequired(); | ||
layoutUpdated = false; | ||
panelsToggled = true; | ||
} else if (!layoutUpdated) { | ||
_showPanelsIfRequired(); | ||
} | ||
} | ||
|
||
PreferencesManager.definePreference(PREFS_PURE_CODE, "boolean", false, { | ||
description: Strings.DESCRIPTION_PURE_CODING_SURFACE | ||
}); | ||
|
||
PreferencesManager.on("change", PREFS_PURE_CODE, function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (PreferencesManager.get(PREFS_PURE_CODE)) { | ||
ViewUtils.hideMainToolBar(); | ||
CommandManager.execute(Commands.HIDE_SIDEBAR); | ||
_hidePanelsIfRequired(); | ||
} else { | ||
ViewUtils.showMainToolBar(); | ||
CommandManager.execute(Commands.SHOW_SIDEBAR); | ||
_showPanelsIfRequired(); | ||
} | ||
_updateCheckedState(); | ||
}); | ||
|
||
WorkspaceManager.on("workspaceUpdateLayout", _updateLayout); | ||
|
||
/** | ||
* Register the Commands , add the Menu Items and key bindings | ||
*/ | ||
function initializeCommands() { | ||
CommandManager.register(Strings.CMD_TOGGLE_PURE_CODE, CMD_TOGGLE_PURE_CODE, _togglePureCode); | ||
CommandManager.register(Strings.CMD_TOGGLE_PANELS, CMD_TOGGLE_PANELS, _togglePanels); | ||
|
||
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PANELS, "", Menus.AFTER, Commands.VIEW_HIDE_SIDEBAR); | ||
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PURE_CODE, "", Menus.AFTER, CMD_TOGGLE_PANELS); | ||
|
||
KeyBindingManager.addBinding(CMD_TOGGLE_PURE_CODE, [ {key: togglePureCodeKey}, {key: togglePureCodeKeyMac, platform: "mac"} ]); | ||
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey}, {key: togglePanelsKeyMac, platform: "mac"} ]); | ||
} | ||
|
||
initializeCommands(); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,9 @@ define({ | |
"VIEW_MENU" : "View", | ||
"CMD_HIDE_SIDEBAR" : "Hide Sidebar", | ||
"CMD_SHOW_SIDEBAR" : "Show Sidebar", | ||
"CMD_TOGGLE_SIDEBAR" : "Toggle Sidebar", | ||
"CMD_TOGGLE_PANELS" : "Toggle Panels", | ||
"CMD_TOGGLE_PURE_CODE" : "No Distractions", | ||
"CMD_INCREASE_FONT_SIZE" : "Increase Font Size", | ||
"CMD_DECREASE_FONT_SIZE" : "Decrease Font Size", | ||
"CMD_RESTORE_FONT_SIZE" : "Restore Font Size", | ||
|
@@ -768,5 +771,6 @@ define({ | |
"DESCRIPTION_OPEN_PREFS_IN_SPLIT_VIEW" : "false to disable opening preferences file in split view", | ||
"DESCRIPTION_OPEN_USER_PREFS_IN_SECOND_PANE" : "false to open user preferences file in left/top pane", | ||
"DEFAULT_PREFERENCES_JSON_HEADER_COMMENT" : "/*\n * This is a read-only file with the preferences supported\n * by {APP_NAME}.\n * Use this file as a reference to modify your preferences\n * file \"brackets.json\" opened in the other pane.\n * For more information on how to use preferences inside\n * {APP_NAME}, refer to the web page at https://github.com/adobe/brackets/wiki/How-to-Use-Brackets#preferences\n */", | ||
"DEFAULT_PREFERENCES_JSON_DEFAULT" : "Default" | ||
"DEFAULT_PREFERENCES_JSON_DEFAULT" : "Default", | ||
"DESCRIPTION_PURE_CODING_SURFACE" : "true to enable Code view only mode, Every other UI element in brackets will be hidden" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rephrase this to |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,19 +54,21 @@ define(function (require, exports, module) { | |
var POSITION_BOTTOM = "bottom"; | ||
var POSITION_LEFT = "left"; | ||
var POSITION_RIGHT = "right"; | ||
var PREFS_PURE_CODE = "noDistractions"; | ||
|
||
// Minimum size (height or width) for autodiscovered resizable panels | ||
var DEFAULT_MIN_SIZE = 100; | ||
|
||
// Load dependent modules | ||
var AppInit = require("utils/AppInit"), | ||
EventDispatcher = require("utils/EventDispatcher"), | ||
viewUtils = require("utils/ViewUtils"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: ViewUtils, in ProperCase |
||
PreferencesManager = require("preferences/PreferencesManager"); | ||
|
||
var $mainView; | ||
|
||
var isResizing = false; | ||
|
||
/** | ||
* Shows a resizable element. | ||
* @param {DOMNode} element Html element to show if possible | ||
|
@@ -223,6 +225,10 @@ define(function (require, exports, module) { | |
resizerCSSPosition = direction === DIRECTION_HORIZONTAL ? "left" : "top", | ||
contentSizeFunction = direction === DIRECTION_HORIZONTAL ? $resizableElement.width : $resizableElement.height; | ||
|
||
if (PreferencesManager.get(PREFS_PURE_CODE)) { | ||
elementPrefs.visible = false; | ||
} | ||
|
||
if (!elementID) { | ||
console.error("Resizable panels must have a DOM id to use as a preferences key:", element); | ||
return; | ||
|
@@ -527,6 +533,11 @@ define(function (require, exports, module) { | |
makeResizable(element, DIRECTION_HORIZONTAL, POSITION_RIGHT, minSize, $(element).hasClass("collapsible"), $(element).data().forceleft); | ||
} | ||
}); | ||
|
||
// The main toolbar is only collapsible. | ||
if ($("#main-toolbar").hasClass("collapsible") && PreferencesManager.get(PREFS_PURE_CODE)) { | ||
viewUtils.hideMainToolBar(); | ||
} | ||
}); | ||
|
||
/** | ||
|
@@ -544,9 +555,9 @@ define(function (require, exports, module) { | |
|
||
return null; | ||
} | ||
|
||
PreferencesManager.convertPreferences(module, {"panelState": "user"}, true, _isPanelPreferences); | ||
|
||
EventDispatcher.makeEventDispatcher(exports); | ||
|
||
exports.makeResizable = makeResizable; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change copyright from 2013 to 2015