summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-23 00:47:20 +0800
committerruki <[email protected]>2018-01-22 22:44:03 +0800
commitac234fd5eb079d9e21485ac7d4b06c2c30d2db2a (patch)
treeb1e636c11fb9a4128f00f71a42f9c3b07a0fae64
parent6d116a4bc1b58f660a60ff206c6c57ee9c939805 (diff)
add exit command
-rw-r--r--tests/ui/mconfdialog.lua1
-rw-r--r--xmake/core/ui/dialog.lua21
-rw-r--r--xmake/core/ui/event.lua2
-rw-r--r--xmake/core/ui/mconfdialog.lua9
-rw-r--r--xmake/core/ui/program.lua5
5 files changed, 35 insertions, 3 deletions
diff --git a/tests/ui/mconfdialog.lua b/tests/ui/mconfdialog.lua
index 2eca8dc2f..9208b7099 100644
--- a/tests/ui/mconfdialog.lua
+++ b/tests/ui/mconfdialog.lua
@@ -45,6 +45,7 @@ function demo:init()
-- init menu config dialog
local mconfdialog = mconfdialog:new("mconfdialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config")
+ mconfdialog:action_set("command.exit", function (v, e) self:quit() end)
self:insert(mconfdialog)
end
diff --git a/xmake/core/ui/dialog.lua b/xmake/core/ui/dialog.lua
index b6a138e20..440f9219a 100644
--- a/xmake/core/ui/dialog.lua
+++ b/xmake/core/ui/dialog.lua
@@ -25,6 +25,7 @@
-- load modules
local log = require("ui/log")
local rect = require("ui/rect")
+local event = require("ui/event")
local label = require("ui/label")
local panel = require("ui/panel")
local button = require("ui/button")
@@ -94,5 +95,25 @@ function dialog:button_select(name)
return self
end
+-- quit dialog
+function dialog:quit()
+ local parent = self:parent()
+ if parent then
+ local action = self:action("command.exit")
+ if action then
+ action(self, event.command {"cm_exit"})
+ end
+ parent:remove(self)
+ end
+end
+
+-- on event
+function dialog:event_on(e)
+ if e.type == event.ev_keyboard and e.key_name == "Esc" then
+ self:quit()
+ return true
+ end
+end
+
-- return module
return dialog
diff --git a/xmake/core/ui/event.lua b/xmake/core/ui/event.lua
index 6c7dd7fb0..d43927705 100644
--- a/xmake/core/ui/event.lua
+++ b/xmake/core/ui/event.lua
@@ -70,7 +70,7 @@ end
event:register("ev_max", "ev_keyboard", "ev_mouse", "ev_command", "ev_text", "ev_idle")
-- register command event types (ev_command)
-event:register("cm_max", "cm_quit", "cm_ok", "cm_cancel", "cm_yes", "cm_no", "cm_help")
+event:register("cm_max", "cm_quit", "cm_exit")
-- define keyboard event
--
diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua
index 8c9e4b108..17bb96c7b 100644
--- a/xmake/core/ui/mconfdialog.lua
+++ b/xmake/core/ui/mconfdialog.lua
@@ -25,6 +25,7 @@
-- load modules
local log = require("ui/log")
local rect = require("ui/rect")
+local event = require("ui/event")
local curses = require("ui/curses")
local window = require("ui/window")
local menuconf = require("ui/menuconf")
@@ -46,7 +47,7 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> to go back or exit, <?> for Hel
-- init buttons
self:button_add("select", "< Select >", function (v, e) end)
- self:button_add("exit", "< Exit >", 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)
@@ -64,5 +65,11 @@ function mconfdialog:menuconf()
return self._MENUCONF
end
+-- on event
+function mconfdialog:event_on(e)
+ -- TODO
+ return boxdialog.event_on(self, e)
+end
+
-- return module
return mconfdialog
diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua
index ff152584f..8407d3e6b 100644
--- a/xmake/core/ui/program.lua
+++ b/xmake/core/ui/program.lua
@@ -164,7 +164,10 @@ function program:event_on(e)
end
-- quit program?
- if e.type == event.ev_keyboard and (e.key_name == "Esc" or e.key_name == "CtrlC") then
+ if e.type == event.ev_keyboard and e.key_name == "CtrlC" then
+ self:send("cm_exit")
+ return true
+ elseif event.is_command(e, "cm_exit") then
self:quit()
return true
end