mapCommand

mapCommand

  • audio/buttons.lua

    local Props = {
      name = "audio",
      commandClass = "audio",
      anchorName = "selectAudio",
      model = {
          {name="save",   label="Save"},
          {name="cancel", label="Cancel"}}
    }
    
    local M = require(root.."parts.baseButtons").new(Props)
    
    function M:init(UI, x, y)
      self.objs = {}
      self.x = x
      self.y = y
      local app = App.get()
      for i = 1, #self.model do
        local entry = self.model[i]
        local eventName = "editor."..self.commandClass.."." .. entry.name
        if app.context.commands[eventName] == nil then
          app.context:mapCommand(
             eventName,
            "editor.audio.controller." .. entry.name
           )
        end
      end
    end
  • editor.controller.selectAudio

    local instance = require("editor.audio.index").controller:command()
    return instance

    selctAudio is used for deleting as well by the icons. See baseTable.lua should it be modified to dispatch to contoller.delete?

  • editor.audio.index

    function M:command()
      local instance = require("commands.kwik.baseCommand").new(
      function (params)
        local UI    = params.UI
        local name =  params[params.class] or ""
        local book = params.book or UI.editor.currentBook
        local page  = params.page or UI.page
    
        for k, v in pairs(params) do print(k, v) end
        if params.hide then
          self:hide()
          return
        end
        ---
        local asset = params.asset
        if params.isUpdatingAsset then
          if self.classProps and self.classProps.objs then
            for i, v in next, self.classProps.objs do
              if v.text == self.classProps.activeProp then
                v.field.text = asset.name
                return
              end
            end
          end
        elseif params.isDelete then <=========== let's forward it delete command() or baseTable should dispatch to delete command()
        else
          -- read from models/{class}/{name}.json
          local decoded = util.decode(book, page, params.class, name, {subclass = params.subclass, isNew = params.isNew, isDelete = params.isDelete}) -- this reads models/xx.json
          --
          print("From selectors")
          self.classProps:didHide(UI)
          self.classProps:destroy(UI)
          self.classProps:init(UI)
          local model = decoded
  • baseTable

        local obj = muiIcon:create {
        icon = {name.."_over", name.."Color_over", name},
        text = "",
        name = name.."-icon",
        x = posX + i*22,
        y = posY,
        width = 22,
        height = 22,
        fontSize =16,
        fillColor = {1.0},
        listener = function(event)
          -- should we use BT with "add component"?
          -- for k, v in pairs(event.target.muiOptions) do print(k, v) end
          local name = event.target.muiOptions.name
          if self.anchorName then
            print("@@", self.anchorName, self.id, name)
            self.UI.scene.app:dispatchEvent {
              name = "editor.selector."..self.anchorName, <================= this is selectAudio
              UI = self.UI,
              class = self.id,
              icon = name,
              isNew = (name ~= "trash-icon" and name ~="Properties-icon"),
              isDelete = (name == "trash-icon")
            }
          else -- use icon.eventMap
            print(name)
            local eventName = self.eventMap[name:gsub("-icon", "")] or self.anchorName
            self.UI.scene.app:dispatchEvent {
              name = "editor.selector."..eventName,
              UI = self.UI,
              class = self.id,
              icon = name,
              isNew = (name ~= "trash-icon" and name ~="Properties-icon"),
              isDelete = (name == "trash-icon")
            }
          end
  • parts/buttons.lua for context menu mapCommnads, so dispathEvent(“editor.classEditor.delete”) should work too

    M.commands = {"create", "shape.new_rectangle", "shape.new_ellipse", "shape.new_text",
        "rename",
        "modify", "shape.move", "shape.scale", "shape.rotate",
        "openEditor",
        "copy", "paste", "delete",
        "toggle",
        "save", "cancel"}
    
    for i = 1, #self.commands do
      local eventName =  "editor.classEditor." .. self.commands[i]
      if app.context.commands[eventName] == nil then
        app.context:mapCommand(
          eventName,
          "editor.controller." .. self.commands[i]
        )
      end
    end