summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-23 22:35:03 +0800
committerruki <[email protected]>2018-01-23 09:30:22 +0800
commit98f8f5d64a469fd727831a24776a7a69358f5768 (patch)
tree37f6ed26087a2a43f77b12bb300492124cff959c
parentf7c0c7b89a45bf02a3ca3ffee8251d7a09654e41 (diff)
add on_action to view
-rw-r--r--xmake/core/ui/button.lua11
-rw-r--r--xmake/core/ui/dialog.lua5
-rw-r--r--xmake/core/ui/label.lua5
-rw-r--r--xmake/core/ui/mconfdialog.lua5
-rw-r--r--xmake/core/ui/view.lua16
5 files changed, 22 insertions, 20 deletions
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua
index 763dae995..14fa2a8f5 100644
--- a/xmake/core/ui/button.lua
+++ b/xmake/core/ui/button.lua
@@ -87,16 +87,7 @@ function button:event_on(e)
-- enter this button?
if e.type == event.ev_keyboard then
if e.key_name == "Enter" then
- local on_action = self:action(action.ac_on_enter)
- if on_action then
- if type(on_action) == "string" then
- -- send command
- self:application():send(on_action)
- elseif type(on_action) == "function" then
- -- do action script
- on_action(self)
- end
- end
+ self:action_on(action.ac_on_enter)
return true
end
end
diff --git a/xmake/core/ui/dialog.lua b/xmake/core/ui/dialog.lua
index fdd692f6d..90f252b10 100644
--- a/xmake/core/ui/dialog.lua
+++ b/xmake/core/ui/dialog.lua
@@ -100,10 +100,7 @@ end
function dialog:quit()
local parent = self:parent()
if parent then
- local on_action = self:action(action.ac_on_exit)
- if on_action then
- on_action(self, event.command {"cm_exit"})
- end
+ self:action_on(action.ac_on_exit)
parent:remove(self)
end
end
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua
index 0fcce66d5..d1c773bc2 100644
--- a/xmake/core/ui/label.lua
+++ b/xmake/core/ui/label.lua
@@ -76,10 +76,7 @@ function label:text_set(text)
-- do action
if changed then
- local on_action = self:action(action.ac_on_text_changed)
- if on_action then
- on_action(self)
- end
+ self:action_on(action.ac_on_text_changed)
end
self:invalidate()
return self
diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua
index 17bb96c7b..8062cbe14 100644
--- a/xmake/core/ui/mconfdialog.lua
+++ b/xmake/core/ui/mconfdialog.lua
@@ -26,6 +26,7 @@
local log = require("ui/log")
local rect = require("ui/rect")
local event = require("ui/event")
+local action = require("ui/action")
local curses = require("ui/curses")
local window = require("ui/window")
local menuconf = require("ui/menuconf")
@@ -49,8 +50,8 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> to go back or exit, <?> for Hel
self:button_add("select", "< Select >", function (v, e) end)
self:button_add("exit", "< Exit >", function (v, e) self:quit() end)
self:button_add("help", "< Help >", function (v, e) end)
- self:button_add("save", "< Save >", function (v, e) end)
- self:button_add("load", "< Load >", function (v, e) end)
+ self:button_add("save", "< Save >", function (v, e) self:action_on(action.ac_on_save) end)
+ self:button_add("load", "< Load >", function (v, e) self:action_on(action.ac_on_load) end)
self:buttons():select(self:button("select"))
-- insert menu config
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index 23a3faa87..6e73d2336 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -350,6 +350,22 @@ function view:action_set(name, on_action)
return self
end
+-- do action
+function view:action_on(name)
+ local on_action = self:action(name)
+ if on_action then
+ if type(on_action) == "string" then
+ -- send command
+ if self:application() then
+ self:application():send(on_action)
+ end
+ elseif type(on_action) == "function" then
+ -- do action script
+ on_action(self)
+ end
+ end
+end
+
-- get cursor position
function view:cursor()
return self._CURSOR