   # Since only the names of predefined templates are known, return a newly
   # generated key if it does not match any of their names.
   getKeyForName: (name, generate = yes) ->
-    switch name
+    log.trace()
+    key = switch name
       when '_url'      then 'PREDEFINED.00001'
       when '_short'    then 'PREDEFINED.00002'
       when '_anchor'   then 'PREDEFINED.00003'


# Update the statistical information.
updateStatistics = ->
  store.init 'stats', {}
  store.modify 'stats', (stats) =>
    # Determine which template has the greatest usage.

  # If the context menu option has been disabled by the user, just remove all
  # of the existing menu items.
  updateContextMenu: ->
    log.trace()
    # Ensure that any previously added context menu items are removed.
    chrome.contextMenus.removeAll =>
      # Called whenever a template menu item is clicked.  
      # Send a self request, passing along the available information.
      onMenuClick = (info, tab) -> onRequest data: info, type: 'menu'
      menu = store.get 'menu'
      if menu.enabled
        # Create and add the top-level Template menu.
        parentId = chrome.contextMenus.create
          contexts: ['all']
          title:    i18n.get 'name'
        # Create and add a sub-menu item for each enabled template.
        for template in @templates when template.enabled
          notEmpty = yes
          menuId   = chrome.contextMenus.create
            contexts: ['all']
            onclick:  onMenuClick
            parentId: parentId
            title:    template.title
          template.menuId = menuId
        unless notEmpty
          chrome.contextMenus.create
            contexts: ['all']
            parentId: parentId
            title:    i18n.get 'empty'
        # Add an item to open the options page if the user doesn't mind.
        if menu.options
          chrome.contextMenus.create
            contexts: ['all']
            parentId: parentId
            type:     'separator'
          chrome.contextMenus.create
            contexts: ['all']
            onclick:  (info, tab) -> onRequest type: 'options'
            parentId: parentId
            title:    i18n.get 'options'

  # Update the local list of templates to reflect those persisted.  
  # It is very important that this is called whenever templates may have been
  # changed in order to prepare the popup HTML and optimize performance.
  updateTemplates: ->
    log.trace()
    @templates = store.get 'templates'
    @templates.sort (a, b) ->
      a.index - b.index
