diff --git a/packages/altair-app/src/app/actions/windows-meta/windows-meta.ts b/packages/altair-app/src/app/actions/windows-meta/windows-meta.ts index bc3ca5c0ba..066654fbc5 100644 --- a/packages/altair-app/src/app/actions/windows-meta/windows-meta.ts +++ b/packages/altair-app/src/app/actions/windows-meta/windows-meta.ts @@ -1,6 +1,8 @@ import { Action as NGRXAction } from '@ngrx/store'; export const SET_ACTIVE_WINDOW_ID = 'SET_ACTIVE_WINDOW_ID'; +export const SET_NEXT_WINDOW_ACTIVE = 'SET_NEXT_WINDOW_ACTIVE'; +export const SET_PREVIOUS_WINDOW_ACTIVE = 'SET_PREVIOUS_WINDOW_ACTIVE'; export const SET_WINDOW_IDS = 'SET_WINDOW_IDS'; export const REPOSITION_WINDOW = 'REPOSITION_WINDOW'; @@ -16,6 +18,18 @@ export class SetActiveWindowIdAction implements NGRXAction { constructor(public payload: { windowId: string }) {} } +export class SetNextWindowActiveAction implements NGRXAction { + readonly type = SET_NEXT_WINDOW_ACTIVE; + + constructor(public payload?: any) {} +} + +export class SetPreviousWindowAction implements NGRXAction { + readonly type = SET_PREVIOUS_WINDOW_ACTIVE; + + constructor(public payload?: any) {} +} + export class SetWindowIdsAction implements NGRXAction { readonly type = SET_WINDOW_IDS; @@ -60,6 +74,8 @@ export class ShowPluginManagerAction implements NGRXAction { export type Action = | SetActiveWindowIdAction + | SetNextWindowActiveAction + | SetPreviousWindowAction | SetWindowIdsAction | RepositionWindowAction | ShowImportCurlDialogAction diff --git a/packages/altair-app/src/app/reducers/windows-meta/windows-meta.ts b/packages/altair-app/src/app/reducers/windows-meta/windows-meta.ts index 85834a5158..d90d7fee4e 100644 --- a/packages/altair-app/src/app/reducers/windows-meta/windows-meta.ts +++ b/packages/altair-app/src/app/reducers/windows-meta/windows-meta.ts @@ -26,6 +26,28 @@ export const getInitialState = (): State => { export function windowsMetaReducer(state = getInitialState(), action: windowsMeta.Action): State { switch (action.type) { + case windowsMeta.SET_ACTIVE_WINDOW_ID: + return { ...state, activeWindowId: action.payload.windowId }; + case windowsMeta.SET_NEXT_WINDOW_ACTIVE: { + const idx = state.windowIds.findIndex(id => id === state.activeWindowId); + let newActiveWindowId = ''; + if (idx >= state.windowIds.length - 1) { + newActiveWindowId = state.windowIds[0]; + } else { + newActiveWindowId = state.windowIds[idx + 1]; + } + return { ...state, activeWindowId: newActiveWindowId }; + } + case windowsMeta.SET_PREVIOUS_WINDOW_ACTIVE: { + const idx = state.windowIds.findIndex(id => id === state.activeWindowId); + let newActiveWindowId = ''; + if (idx <= 0) { + newActiveWindowId = state.windowIds[state.windowIds.length - 1]; + } else { + newActiveWindowId = state.windowIds[idx - 1]; + } + return { ...state, activeWindowId: newActiveWindowId }; + } case windowsMeta.SET_ACTIVE_WINDOW_ID: return { ...state, activeWindowId: action.payload.windowId }; case windowsMeta.SET_WINDOW_IDS: diff --git a/packages/altair-app/src/app/services/electron-app/electron-app.service.ts b/packages/altair-app/src/app/services/electron-app/electron-app.service.ts index 3e0171d9e8..1d2e4bc2b2 100644 --- a/packages/altair-app/src/app/services/electron-app/electron-app.service.ts +++ b/packages/altair-app/src/app/services/electron-app/electron-app.service.ts @@ -13,6 +13,7 @@ import * as fromHeader from '../../reducers/headers/headers'; import * as queryActions from '../../actions/query/query'; import * as docsActions from '../../actions/docs/docs'; import * as windowsMetaActions from '../../actions/windows-meta/windows-meta'; +import * as windowsActions from '../../actions/windows/windows'; import { debug } from 'app/utils/logger'; @Injectable() @@ -62,6 +63,18 @@ export class ElectronAppService { }); }); + this.ipc.on('next-tab', () => { + this.zone.run(() => this.store.dispatch(new windowsMetaActions.SetNextWindowActiveAction())); + }); + + this.ipc.on('previous-tab', () => { + this.zone.run(() => this.store.dispatch(new windowsMetaActions.SetPreviousWindowAction())); + }); + + this.ipc.on('reopen-closed-tab', () => { + this.zone.run(() => this.store.dispatch(new windowsActions.ReopenClosedWindowAction())); + }); + this.ipc.on('send-request', () => { this.zone.run(() => this.store.dispatch(new queryActions.SendQueryRequestAction(this.activeWindowId))); }); diff --git a/packages/altair-electron/src/menu.js b/packages/altair-electron/src/menu.js index 1f38b5d69d..fe0f406398 100644 --- a/packages/altair-electron/src/menu.js +++ b/packages/altair-electron/src/menu.js @@ -15,6 +15,11 @@ const createMenu = (actions) => { accelerator: 'CmdOrCtrl+W', click: actions.closeTab }, + { + label: 'Reopen Closed Tab', + accelerator: 'CmdOrCtrl+Shift+T', + click: actions.reopenClosedTab + }, { role: "undo" }, { role: "redo" }, { type: "separator" }, @@ -29,6 +34,16 @@ const createMenu = (actions) => { { label: "View", submenu: [ + { + label: 'Next Tab', + accelerator: 'CmdOrCtrl+Tab', + click: actions.nextTab + }, + { + label: 'Previous Tab', + accelerator: 'CmdOrCtrl+Shift+Tab', + click: actions.previousTab + }, { role: "reload" }, { role: "forcereload" }, { role: "toggledevtools" }, diff --git a/packages/altair-electron/src/window.js b/packages/altair-electron/src/window.js index f44327d738..0b8628cac4 100644 --- a/packages/altair-electron/src/window.js +++ b/packages/altair-electron/src/window.js @@ -29,13 +29,20 @@ let requestHeaders = {}; const actions = { createTab: () => { - console.log('Create tab.'); instance.webContents.send('create-tab', true); }, closeTab: () => { - console.log('Close tab.'); instance.webContents.send('close-tab', true); }, + nextTab: () => { + instance.webContents.send('next-tab', true); + }, + previousTab: () => { + instance.webContents.send('previous-tab', true); + }, + reopenClosedTab: () => { + instance.webContents.send('reopen-closed-tab', true); + }, sendRequest: () => { instance.webContents.send('send-request', true); },