         }
         {
             label: 'Quit'
-            accelerator: acceleratorMap['quit'][platform]
+            accelerator: getAccelerator('quit')
             click: -> action 'quit'
         }
-    ]
-    tmpl
-
-templateEdit = (viewstate, platform) ->
-    tmpl = [
+    ].filter (n) -> n != undefined
+
+templateEdit = (viewstate) ->
+    [
         {
           label: 'Undo'
-          accelerator: acceleratorMap['undo'][platform]
-          selector: 'undo:' if platform == 'darwin'
-          role: 'undo' if platform == 'others'
+          accelerator: getAccelerator('undo')
+          selector: 'undo:' if isDarwin
+          role: 'undo' if isNotDarwin
         }
         {
           label: 'Redo'
-          accelerator: acceleratorMap['redo'][platform]
-          selector: 'redo:' if platform == 'darwin'
-          role: 'redo' if platform == 'others'
-        }
-    ]
-    if platform == 'darwin'
-        tmpl.push.apply tmpl, [
-          { type: 'separator' }
-          {
-            label: 'Cut'
-            accelerator: acceleratorMap['cut'][platform]
-            selector: 'cut:' if platform == 'darwin'
-            role: 'cut' if platform == 'others'
-          }
-          {
-            label: 'Copy'
-            accelerator: acceleratorMap['copy'][platform]
-            selector: 'copy:' if platform == 'darwin'
-            role: 'copy' if platform == 'others'
-          }
-          {
-            label: 'Paste'
-            accelerator: acceleratorMap['paste'][platform]
-            selector: 'paste:' if platform == 'darwin'
-            role: 'paste' if platform == 'others'
-          }
-          {
-            label: 'Select All'
-            accelerator: acceleratorMap['selectall'][platform]
-            selector: 'selectAll:' if platform == 'darwin'
-            role: 'selectall' if platform == 'others'
-          }
-        ]
-    tmpl
-
-templateView = (viewstate, platform) ->
-    tmpl = [
+          accelerator: getAccelerator('redo')
+          selector: 'redo:' if isDarwin
+          role: 'redo' if isNotDarwin
+        }
+        if isDarwin
+            { type: 'separator' }
+            {
+              label: 'Cut'
+              accelerator: getAccelerator('cut')
+              selector: 'cut:' if isDarwin
+              role: 'cut' if isNotDarwin
+            }
+            {
+              label: 'Copy'
+              accelerator: getAccelerator('copy')
+              selector: 'copy:' if isDarwin
+              role: 'copy' if isNotDarwin
+            }
+            {
+              label: 'Paste'
+              accelerator: getAccelerator('paste')
+              selector: 'paste:' if isDarwin
+              role: 'paste' if isNotDarwin
+            }
+            {
+              label: 'Select All'
+              accelerator: getAccelerator('selectall')
+              selector: 'selectAll:' if isDarwin
+              role: 'selectall' if isNotDarwin
+            }
+    ].filter (n) -> n != undefined
+
+templateView = (viewstate) ->
+    [
         {
             label: 'Conversation List'
             submenu: [

            submenu: [
              {
                  label: 'Conversation 1'
                  accelerator: acceleratorMap['conversation1'][platform]
                  click: -> action 'selectConvIndex', 0
              }, {
                  label: 'Conversation 2'
                  accelerator: acceleratorMap['conversation2'][platform]
                  click: -> action 'selectConvIndex', 1
              }, {
                  label: 'Conversation 3'
                  accelerator: acceleratorMap['conversation3'][platform]
                  click: -> action 'selectConvIndex', 2
              }, {
                  label: 'Conversation 4'
                  accelerator: acceleratorMap['conversation4'][platform]
                  click: -> action 'selectConvIndex', 3
              }, {
                  label: 'Conversation 5'
                  accelerator: acceleratorMap['conversation5'][platform]
                  click: -> action 'selectConvIndex', 4
              }, {
                  label: 'Conversation 6'
                  accelerator: acceleratorMap['conversation6'][platform]
                  click: -> action 'selectConvIndex', 5
              }, {
                  label: 'Conversation 7'
                  accelerator: acceleratorMap['conversation7'][platform]
                  click: -> action 'selectConvIndex', 6
              }, {
                  label: 'Conversation 8'
                  accelerator: acceleratorMap['conversation8'][platform]
                  click: -> action 'selectConvIndex', 7
              }, {
                  label: 'Conversation 9'
                  accelerator: acceleratorMap['conversation9'][platform]
                  click: -> action 'selectConvIndex', 8
              }
            ]

remote = require('electron').remote
Menu = remote.Menu

platform = require('os').platform()
# to reduce number of == comparisons
isDarwin = platform == 'darwin'
isNotDarwin = platform != 'darwin'

acceleratorMap = {
    hideyakyak: {default: 'Control+H', darwin:'Command+H'}
    hideothers: {default: '', darwin:'Command+Shift+H'}
    showall: {default: '', darwin:''}
    openinspector: {default: 'Control+Alt+I', darwin:'Command+Alt+I'}
    quit: {default: 'Control+Q', darwin:'Command+Q'}
    undo: {default: 'Control+Z', darwin:'Command+Z'}
    redo: {default: 'Control+Shift+Z', darwin:'Command+Shift+Z'}
    cut: {default: '', darwin:'Command+X'}
    copy: {default: '', darwin:'Command+C'}
    paste: {default: '', darwin:'Command+V'}
    selectall: {default: '', darwin:'Command+A'}
    togglefullscreen: {default: 'Control+Alt+F', darwin:'Command+Control+F'}
    zoomin: {default: 'Control+Plus', darwin:'Command+Plus'}
    zoomout: {default: 'Control+-', darwin:'Command+-'}
    resetzoom: {default: 'Control+0', darwin:'Command+0'}
    previousconversation: {default: 'Control+K', darwin:'Command+Shift+Tab'}
    nextconversation:  {default: 'Control+J', darwin:'Command+Tab'}
    conversation1: {default: 'Alt+1', darwin:'Command+1'}
    conversation2: {default: 'Alt+2', darwin:'Command+2'}
    conversation3: {default: 'Alt+3', darwin:'Command+3'}
    conversation4: {default: 'Alt+4', darwin:'Command+4'}
    conversation5: {default: 'Alt+5', darwin:'Command+5'}
    conversation6: {default: 'Alt+6', darwin:'Command+6'}
    conversation7: {default: 'Alt+7', darwin:'Command+7'}
    conversation8: {default: 'Alt+8', darwin:'Command+8'}
    conversation9: {default: 'Alt+9', darwin:'Command+9'}
    minimize: {default: '', darwin:'Command+M'}
    close: {default: '', darwin:'Command+W'}
}

getAccelerator = (key) ->
    if (retVal = acceleratorMap[key][platform])?
        retVal
    else
        acceleratorMap[key]['default']

templateYakYak = (viewstate) ->

    [
        { label: 'About YakYak', selector: 'orderFrontStandardAboutPanel:' } if isDarwin
        #{ type: 'separator' }
        # { label: 'Preferences...', accelerator: 'Command+,',
        # click: => delegate.openConfig() }
        { type: 'separator' } if isDarwin
        {
            label: 'Hide YakYak'
            accelerator: getAccelerator('hideyakyak')
            selector: 'hide:' if isDarwin
            role: 'minimize' if isNotDarwin
        }
        if isDarwin
            {
                label: 'Hide Others'
                accelerator: getAccelerator('hideother')
                selector: 'hideOtherApplications:' if isDarwin
            }

            {
                label: 'Show All'
                selector: 'unhideAllApplications:' if isDarwin
            }
        { type: 'separator' }
        {
            label: 'Open Inspector'
            accelerator: getAccelerator('openinspector')
            click: -> action 'devtools'
        }
        { type: 'separator' }
