mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
fix(prefs): ? shortcut for "Show Keybindings" #1144
This commit is contained in:
parent
f77fc700d1
commit
7b7073e356
|
@ -1,6 +1,4 @@
|
|||
import {ipcRenderer} from 'electron';
|
||||
import {PreferencesUIStore,
|
||||
Actions,
|
||||
WorkspaceStore,
|
||||
ComponentRegistry} from 'nylas-exports';
|
||||
|
||||
|
@ -52,16 +50,6 @@ export function activate() {
|
|||
ComponentRegistry.register(PreferencesRoot, {
|
||||
location: WorkspaceStore.Location.Preferences,
|
||||
});
|
||||
|
||||
Actions.openPreferences.listen(this._openPreferences);
|
||||
ipcRenderer.on('open-preferences', () => this._openPreferences());
|
||||
}
|
||||
|
||||
export function _openPreferences() {
|
||||
ipcRenderer.send('command', 'application:show-main-window');
|
||||
if (WorkspaceStore.topSheet() !== WorkspaceStore.Sheet.Preferences) {
|
||||
Actions.pushSheet(WorkspaceStore.Sheet.Preferences);
|
||||
}
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
"core:focus-item": "enter",
|
||||
"core:remove-from-view": ["backspace", "del"],
|
||||
"core:pop-sheet": "escape",
|
||||
"core:show-keybindings": "?",
|
||||
|
||||
"core:messages-page-up": "pageup",
|
||||
"core:messages-page-down": "pagedown",
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
_ = require 'underscore'
|
||||
NylasStore = require 'nylas-store'
|
||||
FocusedPerspectiveStore = require './focused-perspective-store'
|
||||
Actions = require '../actions'
|
||||
Immutable = require 'immutable'
|
||||
|
||||
MAIN_TAB_ITEM_ID = 'General'
|
||||
|
||||
class TabItem
|
||||
constructor: (opts={}) ->
|
||||
opts.order ?= Infinity
|
||||
_.extend(@, opts)
|
||||
|
||||
class PreferencesUIStore extends NylasStore
|
||||
constructor: ->
|
||||
perspective = FocusedPerspectiveStore.current()
|
||||
|
||||
@_tabs = Immutable.List()
|
||||
@_selection = Immutable.Map({
|
||||
tabId: null
|
||||
accountId: perspective?.account?.id
|
||||
})
|
||||
|
||||
@_triggerDebounced ?= _.debounce(( => @trigger()), 20)
|
||||
|
||||
@listenTo Actions.switchPreferencesTab, (tabId, options = {}) =>
|
||||
@_selection = @_selection.set('tabId', tabId)
|
||||
if options.accountId
|
||||
@_selection = @_selection.set('accountId', options.accountId)
|
||||
@trigger()
|
||||
|
||||
tabs: =>
|
||||
@_tabs
|
||||
|
||||
selection: =>
|
||||
@_selection
|
||||
|
||||
###
|
||||
Public: Register a new top-level section to preferences
|
||||
|
||||
- `tabItem` a `PreferencesUIStore.TabItem` object
|
||||
schema definitions on the PreferencesUIStore.Section.MySectionId
|
||||
- `tabId` A unique name to access the Section by
|
||||
- `displayName` The display name. This may go through i18n.
|
||||
- `component` The Preference section's React Component.
|
||||
|
||||
Most Preference sections include an area where a {PreferencesForm} is
|
||||
rendered. This is a type of {GeneratedForm} that uses the schema passed
|
||||
into {PreferencesUIStore::registerPreferences}
|
||||
|
||||
###
|
||||
registerPreferencesTab: (tabItem) ->
|
||||
@_tabs = @_tabs.push(tabItem).sort (a, b) =>
|
||||
a.order > b.order
|
||||
if tabItem.tabId is MAIN_TAB_ITEM_ID
|
||||
@_selection = @_selection.set('tabId', tabItem.tabId)
|
||||
@_triggerDebounced()
|
||||
|
||||
unregisterPreferencesTab: (tabItemOrId) ->
|
||||
@_tabs = @_tabs.filter (s) -> s.tabId isnt tabItemOrId and s isnt tabItemOrId
|
||||
@_triggerDebounced()
|
||||
|
||||
module.exports = new PreferencesUIStore()
|
||||
module.exports.TabItem = TabItem
|
101
src/flux/stores/preferences-ui-store.es6
Normal file
101
src/flux/stores/preferences-ui-store.es6
Normal file
|
@ -0,0 +1,101 @@
|
|||
import {ipcRenderer} from 'electron';
|
||||
import _ from 'underscore'
|
||||
import NylasStore from 'nylas-store'
|
||||
import WorkspaceStore from './workspace-store'
|
||||
import FocusedPerspectiveStore from './focused-perspective-store'
|
||||
import Actions from '../actions'
|
||||
import Immutable from 'immutable'
|
||||
|
||||
const MAIN_TAB_ITEM_ID = 'General'
|
||||
|
||||
class TabItem {
|
||||
constructor(opts = {}) {
|
||||
opts.order = opts.order || Infinity;
|
||||
_.extend(this, opts);
|
||||
}
|
||||
}
|
||||
|
||||
class PreferencesUIStore extends NylasStore {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
const perspective = FocusedPerspectiveStore.current()
|
||||
|
||||
this._tabs = Immutable.List();
|
||||
this._selection = Immutable.Map({
|
||||
tabId: null,
|
||||
accountId: perspective.account ? perspective.account.id : null,
|
||||
})
|
||||
|
||||
this._triggerDebounced = _.debounce(() => this.trigger(), 20)
|
||||
this.setupListeners()
|
||||
}
|
||||
|
||||
setupListeners() {
|
||||
this.listenTo(Actions.openPreferences, this.openPreferences);
|
||||
ipcRenderer.on('open-preferences', this.openPreferences);
|
||||
|
||||
this.listenTo(Actions.switchPreferencesTab, this.switchPreferencesTab);
|
||||
|
||||
NylasEnv.commands.add(document.body, 'core:show-keybindings', () => {
|
||||
this.openPreferences();
|
||||
this.switchPreferencesTab('Shortcuts');
|
||||
});
|
||||
}
|
||||
|
||||
tabs = () => {
|
||||
return this._tabs;
|
||||
}
|
||||
|
||||
selection = () => {
|
||||
return this._selection;
|
||||
}
|
||||
|
||||
openPreferences = () => {
|
||||
ipcRenderer.send('command', 'application:show-main-window');
|
||||
if (WorkspaceStore.topSheet() !== WorkspaceStore.Sheet.Preferences) {
|
||||
Actions.pushSheet(WorkspaceStore.Sheet.Preferences);
|
||||
}
|
||||
}
|
||||
|
||||
switchPreferencesTab = (tabId, options = {}) => {
|
||||
this._selection = this._selection.set('tabId', tabId);
|
||||
if (options.accountId) {
|
||||
this._selection = this._selection.set('accountId', options.accountId);
|
||||
}
|
||||
this.trigger();
|
||||
}
|
||||
|
||||
/*
|
||||
Public: Register a new top-level section to preferences
|
||||
|
||||
- `tabItem` a `PreferencesUIStore.TabItem` object
|
||||
schema definitions on the PreferencesUIStore.Section.MySectionId
|
||||
- `tabId` A unique name to access the Section by
|
||||
- `displayName` The display name. This may go through i18n.
|
||||
- `component` The Preference section's React Component.
|
||||
|
||||
Most Preference sections include an area where a {PreferencesForm} is
|
||||
rendered. This is a type of {GeneratedForm} that uses the schema passed
|
||||
into {PreferencesUIStore::registerPreferences}
|
||||
|
||||
*/
|
||||
registerPreferencesTab = (tabItem) => {
|
||||
this._tabs = this._tabs.push(tabItem).sort((a, b) =>
|
||||
a.order > b.order
|
||||
)
|
||||
if (tabItem.tabId === MAIN_TAB_ITEM_ID) {
|
||||
this._selection = this._selection.set('tabId', tabItem.tabId);
|
||||
}
|
||||
this._triggerDebounced();
|
||||
}
|
||||
|
||||
unregisterPreferencesTab = (tabItemOrId) => {
|
||||
this._tabs = this._tabs.filter(s => (s.tabId !== tabItemOrId) && (s !== tabItemOrId));
|
||||
this._triggerDebounced();
|
||||
}
|
||||
}
|
||||
|
||||
const Store = new PreferencesUIStore();
|
||||
Store.TabItem = TabItem;
|
||||
export default Store;
|
Loading…
Reference in a new issue