Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/940 game tree options #942

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
)
Expand Down Expand Up @@ -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
}))
Expand Down Expand Up @@ -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'),
Expand All @@ -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'},
{
Expand Down Expand Up @@ -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'),
Expand All @@ -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'},
{
Expand Down Expand Up @@ -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
}))
Expand All @@ -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
}))
Expand All @@ -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
}))
Expand Down
25 changes: 24 additions & 1 deletion src/modules/sabaki.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -2620,13 +2622,34 @@ 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
}
]

helper.popupMenu(template, x, y)
}

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)

Expand Down Expand Up @@ -2710,7 +2733,7 @@ class Sabaki extends EventEmitter {
item.click = () => this.setComment(treePosition, item.data)
}

helper.popupMenu(template, x, y)
return template
}

openVariationMenu(
Expand Down
10 changes: 7 additions & 3 deletions src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down