ui.js (5994B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 getAllPrefs, 9 } = require("resource://devtools/client/webconsole/selectors/prefs.js"); 10 const { 11 getAllUi, 12 } = require("resource://devtools/client/webconsole/selectors/ui.js"); 13 const { 14 getMessage, 15 } = require("resource://devtools/client/webconsole/selectors/messages.js"); 16 17 const { 18 INITIALIZE, 19 PERSIST_TOGGLE, 20 PREFS, 21 REVERSE_SEARCH_INPUT_TOGGLE, 22 SELECT_NETWORK_MESSAGE_TAB, 23 SHOW_OBJECT_IN_SIDEBAR, 24 SIDEBAR_CLOSE, 25 SPLIT_CONSOLE_CLOSE_BUTTON_TOGGLE, 26 SHOW_EVALUATION_NOTIFICATION, 27 TIMESTAMPS_TOGGLE, 28 GROUP_SIMILAR_MESSAGES_TOGGLE, 29 FILTERBAR_DISPLAY_MODE_SET, 30 EDITOR_TOGGLE, 31 EDITOR_SET_WIDTH, 32 EDITOR_ONBOARDING_DISMISS, 33 EAGER_EVALUATION_TOGGLE, 34 AUTOCOMPLETE_TOGGLE, 35 ENABLE_NETWORK_MONITORING, 36 } = require("resource://devtools/client/webconsole/constants.js"); 37 38 function openLink(url, e) { 39 return ({ hud }) => { 40 return hud.openLink(url, e); 41 }; 42 } 43 44 function persistToggle() { 45 return ({ dispatch, getState, prefsService }) => { 46 dispatch({ 47 type: PERSIST_TOGGLE, 48 }); 49 const uiState = getAllUi(getState()); 50 prefsService.setBoolPref(PREFS.UI.PERSIST, uiState.persistLogs); 51 }; 52 } 53 54 function networkMonitoringToggle() { 55 return ({ dispatch, getState, prefsService, webConsoleUI }) => { 56 dispatch({ type: ENABLE_NETWORK_MONITORING }); 57 const uiState = getAllUi(getState()); 58 59 prefsService.setBoolPref( 60 PREFS.UI.ENABLE_NETWORK_MONITORING, 61 uiState.enableNetworkMonitoring 62 ); 63 64 if (uiState.enableNetworkMonitoring) { 65 webConsoleUI.startWatchingNetworkResources(); 66 } else { 67 webConsoleUI.stopWatchingNetworkResources(); 68 } 69 }; 70 } 71 72 function timestampsToggle() { 73 return ({ dispatch, getState, prefsService }) => { 74 dispatch({ 75 type: TIMESTAMPS_TOGGLE, 76 }); 77 const uiState = getAllUi(getState()); 78 prefsService.setBoolPref( 79 PREFS.UI.MESSAGE_TIMESTAMP, 80 uiState.timestampsVisible 81 ); 82 }; 83 } 84 85 function autocompleteToggle() { 86 return ({ dispatch, getState, prefsService }) => { 87 dispatch({ 88 type: AUTOCOMPLETE_TOGGLE, 89 }); 90 const prefsState = getAllPrefs(getState()); 91 prefsService.setBoolPref( 92 PREFS.FEATURES.AUTOCOMPLETE, 93 prefsState.autocomplete 94 ); 95 }; 96 } 97 98 function groupSimilarMessagesToggle() { 99 return ({ dispatch, getState, prefsService }) => { 100 dispatch({ 101 type: GROUP_SIMILAR_MESSAGES_TOGGLE, 102 }); 103 const prefsState = getAllPrefs(getState()); 104 prefsService.setBoolPref( 105 PREFS.FEATURES.GROUP_SIMILAR_MESSAGES, 106 prefsState.groupSimilar 107 ); 108 }; 109 } 110 111 function eagerEvaluationToggle() { 112 return ({ dispatch, getState, prefsService }) => { 113 dispatch({ 114 type: EAGER_EVALUATION_TOGGLE, 115 }); 116 const prefsState = getAllPrefs(getState()); 117 prefsService.setBoolPref( 118 PREFS.FEATURES.EAGER_EVALUATION, 119 prefsState.eagerEvaluation 120 ); 121 }; 122 } 123 124 function selectNetworkMessageTab(id) { 125 return { 126 type: SELECT_NETWORK_MESSAGE_TAB, 127 id, 128 }; 129 } 130 131 function initialize() { 132 return { 133 type: INITIALIZE, 134 }; 135 } 136 137 function sidebarClose() { 138 return { 139 type: SIDEBAR_CLOSE, 140 }; 141 } 142 143 function splitConsoleCloseButtonToggle(shouldDisplayButton) { 144 return { 145 type: SPLIT_CONSOLE_CLOSE_BUTTON_TOGGLE, 146 shouldDisplayButton, 147 }; 148 } 149 150 function editorToggle() { 151 return ({ dispatch, getState, prefsService }) => { 152 dispatch({ 153 type: EDITOR_TOGGLE, 154 }); 155 const uiState = getAllUi(getState()); 156 prefsService.setBoolPref(PREFS.UI.EDITOR, uiState.editor); 157 }; 158 } 159 160 function editorOnboardingDismiss() { 161 return ({ dispatch, prefsService }) => { 162 dispatch({ 163 type: EDITOR_ONBOARDING_DISMISS, 164 }); 165 prefsService.setBoolPref(PREFS.UI.EDITOR_ONBOARDING, false); 166 }; 167 } 168 169 function setEditorWidth(width) { 170 return ({ dispatch, prefsService }) => { 171 dispatch({ 172 type: EDITOR_SET_WIDTH, 173 width, 174 }); 175 prefsService.setIntPref(PREFS.UI.EDITOR_WIDTH, width); 176 }; 177 } 178 179 /** 180 * Dispatches a SHOW_OBJECT_IN_SIDEBAR action, with a grip property corresponding to the 181 * {actor} parameter in the {messageId} message. 182 * 183 * @param {string} actorID: Actor id of the object we want to place in the sidebar. 184 * @param {string} messageId: id of the message containing the {actor} parameter. 185 */ 186 function showMessageObjectInSidebar(actorID, messageId) { 187 return ({ dispatch, getState }) => { 188 const { parameters } = getMessage(getState(), messageId); 189 if (Array.isArray(parameters)) { 190 for (const parameter of parameters) { 191 if (parameter && parameter.actorID === actorID) { 192 dispatch(showObjectInSidebar(parameter)); 193 return; 194 } 195 } 196 } 197 }; 198 } 199 200 function showObjectInSidebar(front) { 201 return { 202 type: SHOW_OBJECT_IN_SIDEBAR, 203 front, 204 }; 205 } 206 207 function reverseSearchInputToggle({ initialValue, access } = {}) { 208 return { 209 type: REVERSE_SEARCH_INPUT_TOGGLE, 210 initialValue, 211 access, 212 }; 213 } 214 215 function filterBarDisplayModeSet(displayMode) { 216 return { 217 type: FILTERBAR_DISPLAY_MODE_SET, 218 displayMode, 219 }; 220 } 221 222 function openSidebar(messageId, rootActorId) { 223 return ({ dispatch }) => { 224 dispatch(showMessageObjectInSidebar(rootActorId, messageId)); 225 }; 226 } 227 228 function showEvaluationNotification(notification) { 229 return { 230 type: SHOW_EVALUATION_NOTIFICATION, 231 notification, 232 }; 233 } 234 235 module.exports = { 236 eagerEvaluationToggle, 237 editorOnboardingDismiss, 238 editorToggle, 239 filterBarDisplayModeSet, 240 initialize, 241 persistToggle, 242 reverseSearchInputToggle, 243 selectNetworkMessageTab, 244 setEditorWidth, 245 showMessageObjectInSidebar, 246 showObjectInSidebar, 247 sidebarClose, 248 splitConsoleCloseButtonToggle, 249 timestampsToggle, 250 networkMonitoringToggle, 251 groupSimilarMessagesToggle, 252 openLink, 253 openSidebar, 254 autocompleteToggle, 255 showEvaluationNotification, 256 };