diff --git a/src/menu.js b/src/menu.js index 8995180d..f49bccf0 100644 --- a/src/menu.js +++ b/src/menu.js @@ -16,7 +16,6 @@ const setting = isRenderer : nativeRequire('./setting') exports.get = function(props = {}) { - let toggleSetting = key => setting.set(key, !setting.get(key)) let selectTool = tool => ( sabaki.setMode('edit'), sabaki.setState({selectedTool: tool}) ) @@ -446,7 +445,7 @@ exports.get = function(props = {}) { type: 'checkbox', checked: !!showLeftSidebar, click: () => { - toggleSetting('view.show_leftsidebar') + setting.toggle('view.show_leftsidebar') sabaki.setState(({showLeftSidebar}) => ({ showLeftSidebar: !showLeftSidebar })) @@ -553,7 +552,7 @@ exports.get = function(props = {}) { submenu: [ { label: i18n.t('menu.view', 'Toggle Menu &Bar'), - click: () => toggleSetting('view.show_menubar') + click: () => setting.toggle('view.show_menubar') }, { label: i18n.t('menu.view', 'Toggle &Full Screen'), @@ -571,7 +570,7 @@ exports.get = function(props = {}) { accelerator: 'CmdOrCtrl+Shift+C', type: 'checkbox', checked: !showCoordinates, - click: () => toggleSetting('view.show_coordinates') + click: () => setting.toggle('view.show_coordinates') }, {type: 'separator'}, { @@ -607,25 +606,25 @@ exports.get = function(props = {}) { label: i18n.t('menu.view', 'Show Move N&umbers'), type: 'checkbox', checked: !!showMoveNumbers, - click: () => toggleSetting('view.show_move_numbers') + click: () => setting.toggle('view.show_move_numbers') }, { label: i18n.t('menu.view', 'Show Move Colori&zation'), type: 'checkbox', checked: !!showMoveColorization, - click: () => toggleSetting('view.show_move_colorization') + click: () => setting.toggle('view.show_move_colorization') }, { label: i18n.t('menu.view', 'Show &Next Moves'), type: 'checkbox', checked: !!showNextMoves, - click: () => toggleSetting('view.show_next_moves') + click: () => setting.toggle('view.show_next_moves') }, { label: i18n.t('menu.view', 'Show &Sibling Variations'), type: 'checkbox', checked: !!showSiblings, - click: () => toggleSetting('view.show_siblings') + click: () => setting.toggle('view.show_siblings') }, { label: i18n.t('menu.view', 'Show &Heatmap'), @@ -635,7 +634,7 @@ exports.get = function(props = {}) { type: 'checkbox', checked: !showAnalysis, accelerator: 'CmdOrCtrl+H', - click: () => toggleSetting('board.show_analysis') + click: () => setting.toggle('board.show_analysis') }, {type: 'separator'}, { @@ -677,7 +676,7 @@ exports.get = function(props = {}) { checked: !!showWinrateGraph, enabled: !!showGameGraph || !!showCommentBox, click: () => { - toggleSetting('view.show_winrategraph') + setting.toggle('view.show_winrategraph') sabaki.setState(({showWinrateGraph}) => ({ showWinrateGraph: !showWinrateGraph })) @@ -689,7 +688,7 @@ exports.get = function(props = {}) { checked: !!showGameGraph, accelerator: 'CmdOrCtrl+T', click: () => { - toggleSetting('view.show_graph') + setting.toggle('view.show_graph') sabaki.setState(({showGameGraph}) => ({ showGameGraph: !showGameGraph })) @@ -701,7 +700,7 @@ exports.get = function(props = {}) { checked: !!showCommentBox, accelerator: 'CmdOrCtrl+Shift+T', click: () => { - toggleSetting('view.show_comments') + setting.toggle('view.show_comments') sabaki.setState(({showCommentBox}) => ({ showCommentBox: !showCommentBox })) diff --git a/src/modules/sabaki.js b/src/modules/sabaki.js index fa034bdf..f87971fd 100644 --- a/src/modules/sabaki.js +++ b/src/modules/sabaki.js @@ -2581,6 +2581,8 @@ class Sabaki extends EventEmitter { // Menus openNodeMenu(treePosition, {x, y} = {}) { + let commentMenu = this.getCommentMenuTemplate(treePosition) + let t = i18n.context('menu.edit') let template = [ { @@ -2620,6 +2622,21 @@ class Sabaki extends EventEmitter { { label: t('Remove &Other Variations'), click: () => this.removeOtherVariations(treePosition) + }, + {type: 'separator'}, + { + label: t('Toggle Show Comments'), + click: () => { + setting.toggle('view.show_comments') + this.setState(({showCommentBox}) => ({ + showCommentBox: !showCommentBox + })) + } + }, + {type: 'separator'}, + { + label: t('Annotate'), + submenu: commentMenu } ] @@ -2627,6 +2644,12 @@ class Sabaki extends EventEmitter { } openCommentMenu(treePosition, {x, y} = {}) { + let template = this.getCommentMenuTemplate(treePosition) + + helper.popupMenu(template, x, y) + } + + getCommentMenuTemplate(treePosition) { let t = i18n.context('menu.comment') let node = this.inferredState.gameTree.get(treePosition) @@ -2710,7 +2733,7 @@ class Sabaki extends EventEmitter { item.click = () => this.setComment(treePosition, item.data) } - helper.popupMenu(template, x, y) + return template } openVariationMenu( diff --git a/src/setting.js b/src/setting.js index 282448d3..5b2f836a 100644 --- a/src/setting.js +++ b/src/setting.js @@ -325,17 +325,21 @@ exports.save = function() { return exports } -exports.get = function(key) { +let get = (exports.get = function(key) { if (key in settings) return settings[key] if (key in defaults) return defaults[key] return null -} +}) -exports.set = function(key, value) { +let set = (exports.set = function(key, value) { settings[key] = value exports.save() exports.events.emit('change', {key, value}) return exports +}) + +exports.toggle = function(key) { + set(key, !get(key)) } exports.getThemes = function() {