#if($isInServletMode)## Visible only in a page
<div id="mainmenu" class="layoutsubsection actionmenu">
<strong id="xwikimenutitle" class="hidden">$msg.get('core.menu.main.title')</strong>
<div class="leftmenu">
##
## Create
##
#set ($displayCreateSubmenu = $hasCreateSpace || $hasCreatePage || $hasComment)
#if($displayCreateSubmenu)
  #xwikitopmenuentrystart('' $msg.get('core.menu.create') 'tmCreate' 'hasIcon')
  #set ($hasPreviousMenuSection = false)
  #if ($hasCreateSpace)
    #submenuitem("$doc.getURL('create', 'tocreate=space')" $msg.get('core.menu.create.space') 'tmCreateSpace', '')
    #set ($hasPreviousMenuSection = true)
  #end
  #if ($hasCreatePage)
    #if ($hasPreviousMenuSection)
      #submenuseparator()
    #end
    #submenuitem("$doc.getURL('create')" $msg.get('core.menu.create.page') 'tmCreatePage', '')
    ## Only display the Office Importer menu action if the Office Importer application is installed
    #set($officeImporterMainDocument = $xwiki.getDocument('XWiki.OfficeImporter'))
    #if("$!{officeImporterMainDocument.isNew()}" == 'false')
      #submenuitem($officeImporterMainDocument.getURL('view', "&amp;parent=$!{escapetool.url($doc.fullName)}") $msg.get('core.menu.create.pageFromOffice') 'tmCreatePageFromOffice', '')
    #end
    #set ($hasPreviousMenuSection = true)
  #end
  #if ((($hasComment && $showcomments) || ($hasEdit && $showattachments)) && $hasPreviousMenuSection)
    #submenuseparator()
  #end
  #if ($hasComment && $showcomments)
    #submenuitem("$doc.getURL('view', 'viewer=comments')" $msg.get('core.menu.create.comment') 'tmCreateComment', '')
    <script type="text/javascript">
      //<![CDATA[
        document.observe('xwiki:dom:loaded', function() {
          $('tmCreateComment').observe('click', function(event) {
            event.stop();
            XWiki.displayDocExtra('Comments', 'commentsinline.vm', true);
            return false;
          });
        });
      //]]>
    </script>
    #set ($hasPreviousMenuSection = true)
  #end
  #if ($hasEdit && $showattachments)
    #submenuitem("$doc.getURL('view', 'viewer=attachments')" $msg.get('core.menu.create.attachment') 'tmCreateAttachment', '')
    <script type="text/javascript">
      //<![CDATA[
        document.observe('xwiki:dom:loaded', function() {
          $('tmCreateAttachment').observe('click', function(event) {
            event.stop();
            XWiki.displayDocExtra('Attachments', 'attachmentsinline.vm', true);
            return false;
          });
        });
      //]]>
    </script>
    #set ($hasPreviousMenuSection = true)
  #end
  #xwikitopmenuentryend()
#end
##
## Wiki
##
#set($isAdminAppInstalled = $xwiki.exists('XWiki.AdminSheet'))
#set ($displayWikiSubmenu = $hasWatch || $hasGlobalAdmin || $xwiki.exists('Main.AllDocs'))
#set($wikiEntryText = $msg.get('core.menu.type.wiki'))
#if($xwiki.isVirtualMode() && $xwiki.wikimanager)
  #set($wikiName = $xwiki.wikimanager.getWikiDocument($xcontext.getDatabase()).getWikiPrettyName())
  #if("$!wikiName.trim()" == '')
    #set($wikiName = $xcontext.getDatabase())
  #end
  #set($wikiEntryText = "${wikiEntryText}__SEPARATOR__${wikiName}")
#end
#if(!$displayWikiSubmenu)
  #xwikitopmenuentry($xwiki.getURL('Main.WebHome', 'view') $wikiEntryText 'tmWiki' 'hasIcon')
#else
  #xwikitopmenuentrystart($xwiki.getURL('Main.WebHome', 'view') $wikiEntryText 'tmWiki' 'hasIcon')
  #set ($hasPreviousMenuSection = false)
  #if ($hasWatch)
    #set($watchClasses = '')
    #set($unwatchClasses = 'hidden')
    #if($xwiki.watchlist.isWikiWatched())
      #set($watchClasses = 'hidden')
      #set($unwatchClasses = '')
    #end
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=addwiki')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.add.wiki', [$escapetool.xml($doc.wiki)]) 'tmWatchWiki', $watchClasses)
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=removewiki')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.remove.wiki') 'tmUnwatchWiki', $unwatchClasses)
    #set ($hasPreviousMenuSection = true)
  #end
  #if($hasGlobalAdmin)
    #set ($adminwikiaction = $!xwiki.getURL('XWiki.XWikiPreferences', 'admin'))
    #set ($importaction = $!xwiki.getURL('XWiki.XWikiPreferences', 'import'))
    #if($isAdminAppInstalled)
      #submenuitem($adminwikiaction $msg.get('core.menu.admin.wiki') 'tmAdminWiki', '')
    #else
      #submenuitem($importaction $msg.get('core.menu.admin') 'tmAdminWiki' '')
    #end
    #set ($hasPreviousMenuSection = true)
  #end
  #if ($xwiki.exists('Main.AllDocs'))
    #if ($hasPreviousMenuSection)
      #submenuseparator()
    #end
    #submenuitem("$xwiki.getURL('Main.AllDocs')" $msg.get('core.menu.wiki.documentindex') 'tmWikiDocumentIndex' '')
  #end
  #xwikitopmenuentryend()
#end
##
## Space
##
#set ($displaySpaceSubmenu = $hasWatch || $hasSpaceAdmin || $xwiki.exists('Main.SpaceIndex'))
### #xwikitopmenuseparator() ### Edit: do not print separators at top menu
#if(!$displaySpaceSubmenu)
  #xwikitopmenuentry($xwiki.getURL("${doc.space}.WebHome", 'view') "$msg.get('core.menu.type.space')__SEPARATOR__$!{escapetool.xml($doc.space)}" 'tmSpace' 'hasIcon')
#else
  #xwikitopmenuentrystart($xwiki.getURL("${doc.space}.WebHome", 'view') "$msg.get('core.menu.type.space')__SEPARATOR__$!{escapetool.xml($doc.space)}" 'tmSpace' 'hasIcon')
  #set ($hasPreviousMenuSection = false)
  #if ($hasWatch)
    #set($watchClasses = '')
    #set($unwatchClasses = 'hidden')
    #if($xwiki.watchlist.isSpaceWatched())
      #set($watchClasses = 'hidden')
      #set($unwatchClasses = '')
    #end
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=addspace')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.add.space', [$escapetool.xml($doc.space)]) 'tmWatchSpace', $watchClasses)
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=removespace')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.remove.space') 'tmUnwatchSpace', $unwatchClasses)
    #set ($hasPreviousMenuSection = true)
  #end
  #if($hasSpaceAdmin)
    #set ($adminspaceaction = $!xwiki.getURL("${doc.space}.WebPreferences", 'admin'))
    #submenuitem($adminspaceaction $msg.get('core.menu.admin.space', [$escapetool.xml($doc.space)]) 'tmAdminSpace')
    #set ($hasPreviousMenuSection = true)
  #end
  #if ($xwiki.exists('Main.SpaceIndex'))
    #if ($hasPreviousMenuSection)
      #submenuseparator()
    #end
    #set ($spaceIndexUrl = $xwiki.getURL('Main.SpaceIndex', 'view',"space=${escapetool.url($doc.space)}"))
    #submenuitem($spaceIndexUrl $msg.get('core.menu.space.documentindex') 'tmSpaceDocumentIndex' '')
    #set ($hasPreviousMenuSection = true)
  #end
  #xwikitopmenuentryend()
#end
##
## Page
##
#set ($displayPageSubmenu = $hasWatch)
### #xwikitopmenuseparator() ### Edit: do not print top menu separators
#if(!$displayPageSubmenu)
  #xwikitopmenuentry($xwiki.getURL("${doc.name}", 'view') "$msg.get('core.menu.type.page')__SEPARATOR__$!{escapetool.xml($doc.name)}" 'tmPage' 'hasIcon')
#else
  #xwikitopmenuentrystart($xwiki.getURL("${doc.name}", 'view') "$msg.get('core.menu.type.page')__SEPARATOR__$!{escapetool.xml($doc.name)}" 'tmPage' 'hasIcon')
  #if ($hasWatch && !$doc.isNew())
    #set($watchClasses = 'hasIcon')
    #set($unwatchClasses = 'hasIcon hidden')
    #if($xwiki.watchlist.isDocumentWatched())
      #set($watchClasses = 'hasIcon hidden')
      #set($unwatchClasses = 'hasIcon')
    #end
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=adddocument')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.add.page') 'tmWatchDocument' $watchClasses)
    #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=removedocument')&amp;xredirect=$escapetool.url($doc.getURL())" $msg.get('core.menu.watchlist.remove.page') 'tmUnwatchDocument' $unwatchClasses)
  #end
  #if ($xwiki.exists('XWiki.SharePage') && !$isGuest)
    #submenuitem($doc.getURL('view', 'viewer=share') $msg.get('core.menu.share') 'tmActionShare', '')
    $xwiki.jsx.use('XWiki.SharePage')
    $xwiki.ssx.use('XWiki.SharePage')
  #end
  #set ($canDelete = !$doc.isNew() && $xwiki.checkAccess($doc.fullName, 'delete'))
  #if($canDelete || $xwiki.hasProgrammingRights())
    #submenuseparator()
  #end
  #if($xwiki.hasProgrammingRights())
    #submenuitem($doc.getURL('view', 'xpage=copy') $msg.get('core.menu.copy') 'tmActionCopy', '')
  #end
  #if($canDelete)
    #submenuitem($doc.getURL('view', 'xpage=rename&amp;step=1') $msg.get('core.menu.rename') 'tmActionRename', '')
    #submenuitem($doc.getURL('delete', $!languageparams) $msg.get('core.menu.delete') 'tmActionDelete', '')
  #end
  #xwikitopmenuentryend()
  #if($canDelete && $keyboardShortcutsEnabled)
    <script type="text/javascript">
      //<![CDATA[
      shortcut.add("$msg.get('core.shortcuts.view.delete')",function() { location.href=$('tmActionDelete').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
      shortcut.add("$msg.get('core.shortcuts.view.rename')",function() { location.href=$('tmActionRename').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
      //]]>
    </script>
  #end
#end
</div>
</div>
#end
