summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-31 22:28:45 +0800
committerruki <[email protected]>2018-01-31 08:52:30 +0800
commitb0c66bcd2f4f029706ddec16bb5c8bb4aae35774 (patch)
treeb2387db098555d386424d1b08c36c4be139b0afb
parent93d622e12e81ee28682258f302217fc8018e3ae3 (diff)
modify load configs
-rw-r--r--tests/ui/mconfdialog.lua2
-rw-r--r--xmake/actions/config/menuconf.lua41
-rw-r--r--xmake/core/ui/mconfdialog.lua8
3 files changed, 33 insertions, 18 deletions
diff --git a/tests/ui/mconfdialog.lua b/tests/ui/mconfdialog.lua
index 2f7d313c5..c56dadf4f 100644
--- a/tests/ui/mconfdialog.lua
+++ b/tests/ui/mconfdialog.lua
@@ -72,9 +72,9 @@ 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:load(configs)
mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end)
mconfdialog:action_set(action.ac_on_load, function (v)
- v:load(configs)
end)
mconfdialog:action_set(action.ac_on_save, function (v)
for _, config in ipairs(configs) do
diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua
index 659c47445..bca0f98ff 100644
--- a/xmake/actions/config/menuconf.lua
+++ b/xmake/actions/config/menuconf.lua
@@ -50,6 +50,10 @@ function app:init()
-- insert menu config dialog
self:insert(self:mconfdialog())
+
+ -- TODO
+ -- load configs
+ self:load(not option.get("clean"))
end
-- get menu config dialog
@@ -58,7 +62,7 @@ function app:mconfdialog()
local mconfdialog = mconfdialog:new("app.config.mconfdialog", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config")
mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end)
mconfdialog:action_set(action.ac_on_load, function (v)
- self:load()
+ self:load(true)
end)
mconfdialog:action_set(action.ac_on_save, function (v)
self:save()
@@ -70,7 +74,7 @@ function app:mconfdialog()
end
-- get basic configs
-function app:basic_configs()
+function app:basic_configs(cache)
-- get configs from the cache first
local configs = self._BASIC_CONFIGS
@@ -97,12 +101,18 @@ function app:basic_configs()
-- get description
local description = opt[5]
+ -- load value
+ local value = nil
+ if cache then
+ value = config.get(value)
+ end
+
-- key=value?
if kind == "kv" then
- table.insert(configs, menuconf.string {name = name, default = default, description = description})
+ table.insert(configs, menuconf.string {name = name, value = value, default = default, description = description})
-- --key?
elseif kind == "k" then
- table.insert(configs, menuconf.boolean {name = name, default = default, description = description})
+ table.insert(configs, menuconf.boolean {name = name, value = value, default = default, description = description})
end
end
end
@@ -113,7 +123,7 @@ function app:basic_configs()
end
-- get project configs
-function app:project_configs()
+function app:project_configs(cache)
-- get configs from the cache first
local configs = self._PROJECT_CONFIGS
@@ -161,11 +171,17 @@ function app:project_configs()
first = false
end
+ -- load value
+ local value = nil
+ if cache then
+ value = config.get(value)
+ end
+
-- insert config
if type(default) == "string" then
- table.insert(submenu and submenu.configs or configs, menuconf.string {name = name, default = default, description = opt:get("description")})
+ table.insert(submenu and submenu.configs or configs, menuconf.string {name = name, value = value, default = default, description = opt:get("description")})
else
- table.insert(submenu and submenu.configs or configs, menuconf.boolean {name = name, default = default, description = opt:get("description")})
+ table.insert(submenu and submenu.configs or configs, menuconf.boolean {name = name, value = value, default = default, description = opt:get("description")})
end
end
end
@@ -177,12 +193,17 @@ function app:project_configs()
end
-- load configs from options
-function app:load()
+function app:load(cache)
+
+ -- load config from cache
+ if cache then
+ cache = config.load(option.get("target") or "all")
+ end
-- load configs
local configs = {}
- table.insert(configs, menuconf.menu {description = "Basic Configuration", configs = self:basic_configs()})
- table.insert(configs, menuconf.menu {description = "Project Configuration", configs = self:project_configs()})
+ table.insert(configs, menuconf.menu {description = "Basic Configuration", configs = self:basic_configs(cache)})
+ table.insert(configs, menuconf.menu {description = "Project Configuration", configs = self:project_configs(cache)})
self:mconfdialog():load(configs)
end
diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua
index 5d0145a91..8f2f76a87 100644
--- a/xmake/core/ui/mconfdialog.lua
+++ b/xmake/core/ui/mconfdialog.lua
@@ -222,14 +222,8 @@ end
-- on event
function mconfdialog:event_on(e)
- -- load config first
- if e.type == event.ev_idle then
- if not self._LOADED then
- self:action_on(action.ac_on_load)
- self._LOADED = true
- end
-- select config
- elseif e.type == event.ev_keyboard then
+ if e.type == event.ev_keyboard then
if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " or e.key_name == "Esc" or e.key_name:lower() == "y" or e.key_name:lower() == "n" then
return self:menuconf():event_on(e)
elseif e.key_name == "?" then