summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/tabs.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--devtools/client/debugger/src/actions/tabs.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/actions/tabs.js b/devtools/client/debugger/src/actions/tabs.js
new file mode 100644
index 0000000000..1b3c0d3f43
--- /dev/null
+++ b/devtools/client/debugger/src/actions/tabs.js
@@ -0,0 +1,76 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+/**
+ * Redux actions for the editor tabs
+ * @module actions/tabs
+ */
+
+import { removeDocument } from "../utils/editor";
+import { selectSource } from "./sources";
+
+import {
+ getSourceByURL,
+ getSourceTabs,
+ getNewSelectedSource,
+} from "../selectors";
+
+export function addTab(source, sourceActor) {
+ return {
+ type: "ADD_TAB",
+ source,
+ sourceActor,
+ };
+}
+
+export function moveTab(url, tabIndex) {
+ return {
+ type: "MOVE_TAB",
+ url,
+ tabIndex,
+ };
+}
+
+export function moveTabBySourceId(sourceId, tabIndex) {
+ return {
+ type: "MOVE_TAB_BY_SOURCE_ID",
+ sourceId,
+ tabIndex,
+ };
+}
+
+/**
+ * @memberof actions/tabs
+ * @static
+ */
+export function closeTab(cx, source, reason = "click") {
+ return ({ dispatch, getState, client }) => {
+ removeDocument(source.id);
+
+ const tabs = getSourceTabs(getState());
+ dispatch({ type: "CLOSE_TAB", source });
+
+ const newSource = getNewSelectedSource(getState(), tabs);
+ dispatch(selectSource(cx, newSource));
+ };
+}
+
+/**
+ * @memberof actions/tabs
+ * @static
+ */
+export function closeTabs(cx, urls) {
+ return ({ dispatch, getState, client }) => {
+ const sources = urls
+ .map(url => getSourceByURL(getState(), url))
+ .filter(Boolean);
+
+ const tabs = getSourceTabs(getState());
+ sources.map(source => removeDocument(source.id));
+ dispatch({ type: "CLOSE_TABS", sources });
+
+ const source = getNewSelectedSource(getState(), tabs);
+ dispatch(selectSource(cx, source));
+ };
+}