# File lib/foxtails/FTFileBrowser.rb, line 161
    def onPopupMenu sender, sel, event
      # based on FXFileSelector::onPopupMenu

      if event.moved then return 1 end

      index = getItemAt(event.win_x, event.win_y)
      
      filemenu = FXMenuPane.new(self)
      
      FTEnabledMenuCommand.new(filemenu, "Up one level", UPLEVEL_ICON,
        self, :can_go_up).
        connect(SEL_COMMAND) {on_cmd_up_dir}

      FXMenuCommand.new(filemenu, "Go home", HOME_ICON).
        connect(SEL_COMMAND) {on_cmd_home_dir}
      
      FTEnabledMenuCommand.new(filemenu, "New directory...", NEW_DIR_ICON,
        self, :can_write).
        connect(SEL_COMMAND) {on_cmd_new_dir}

      FXMenuSeparator.new(filemenu)

      sortmenu = FXMenuPane.new(self)
      FXMenuCascade.new(filemenu, "Sort by", nil, sortmenu)
      FXMenuCommand.new(sortmenu, "Name",    nil, self, ID_SORT_BY_NAME)
      FXMenuCommand.new(sortmenu, "Type",    nil, self, ID_SORT_BY_TYPE)
      FXMenuCommand.new(sortmenu, "Size",    nil, self, ID_SORT_BY_SIZE)
      FXMenuCommand.new(sortmenu, "Time",    nil, self, ID_SORT_BY_TIME)
      FXMenuCommand.new(sortmenu, "User",    nil, self, ID_SORT_BY_USER)
      FXMenuCommand.new(sortmenu, "Group",   nil, self, ID_SORT_BY_GROUP)
      FXMenuCommand.new(sortmenu, "Reverse", nil, self, ID_SORT_REVERSE)

      viewmenu = FXMenuPane.new(self)
      FXMenuCascade.new(filemenu, "View", nil, viewmenu)

      FTRadioMenuCommand.new(viewmenu, "Small icons", nil, self,
        :show_icons_state, :mini)
      FTRadioMenuCommand.new(viewmenu, "Big icons", nil, self,
        :show_icons_state, :big)
      FTRadioMenuCommand.new(viewmenu, "Details", nil, self,
        :show_icons_state, :details)

      FXMenuSeparator.new(viewmenu)

      FTRadioMenuCommand.new(viewmenu, "Rows", nil, self,
        :arrange_state, :by_rows)
      FTRadioMenuCommand.new(viewmenu, "Columns", nil, self,
        :arrange_state, :by_columns)

      FXMenuSeparator.new(viewmenu)

      FTCheckMenuCommand.new(viewmenu, "Hidden files", nil, self,
        :show_hidden_state)

      bm_menu = FXMenuPane.new(self)
      FXMenuCascade.new(filemenu, "Bookmarks", nil, bm_menu)
      FXMenuCommand.new(bm_menu, "Set bookmark", MARK_ICON).
        connect(SEL_COMMAND) {set_bookmark}

      if @bookmarks
        FXMenuCommand.new(bm_menu, "Clear bookmarks", CLEAR_MARKS_ICON).
          connect(SEL_COMMAND) {clear_bookmarks}

        FXMenuSeparator.new(bm_menu)
        
        @bookmarks.each do |bm|
          FXMenuCommand.new(bm_menu, bm).connect(SEL_COMMAND) {open_bookmark bm}
        end
      end

      FXMenuSeparator.new(filemenu)

      open_cmd = FXMenuCommand.new(filemenu, "Open...", FILE_OPEN_ICON)
      if index >= 0
        open_cmd.connect(SEL_COMMAND) {open_selection(index)}
      else
        open_cmd.disable
      end
      
## RENAME?
##      FXMenuCommand.new(filemenu, "Copy...", COPY_ICON, self,0)###
##      FXMenuCommand.new(filemenu, "Move...", MOVE_ICON, self,0)###
##      FXMenuCommand.new(filemenu, "Link...", LINK_ICON, self,0)###

      del_cmd = FXMenuCommand.new(filemenu, "Delete...", DELETE_ICON)
      if index >= 0 and isItemSelected(index)
        del_cmd.connect(SEL_COMMAND) {on_cmd_delete_files}
      else
        del_cmd.disable
      end

      filemenu.create()
      filemenu.popup(nil, event.root_x, event.root_y)
      filemenu.grabKeyboard
      getApp().runModalWhileShown(filemenu)
      return 1
    end