diff options
| author | ruki <[email protected]> | 2018-01-30 00:50:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-29 23:03:04 +0800 |
| commit | cac3ce526b57c4ec2be57709729d93527b8f6276 (patch) | |
| tree | 7e2d79f6001a67a4f26a233caa11eb95b6712262 | |
| parent | 01f67cdabb350364cb3e65a808fbec649e76ea51 (diff) | |
add xmake f --menu
| -rw-r--r-- | tests/ui/mconfdialog.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/config/main.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/config/menuconf.lua | 147 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/option.lua | 62 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/option.lua | 5 | ||||
| -rw-r--r-- | xmake/core/ui/mconfdialog.lua | 5 |
7 files changed, 196 insertions, 34 deletions
diff --git a/tests/ui/mconfdialog.lua b/tests/ui/mconfdialog.lua index 397848511..2f7d313c5 100644 --- a/tests/ui/mconfdialog.lua +++ b/tests/ui/mconfdialog.lua @@ -74,7 +74,7 @@ function demo:init() local mconfdialog = mconfdialog:new("mconfdialog.main", 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) - v:menuconf():load(configs) + 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/main.lua b/xmake/actions/config/main.lua index ee90d455b..aa13b767a 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -31,6 +31,7 @@ import("core.platform.platform") import("core.project.cache", {nocache = true}) import("lib.detect.cache", {alias = "detectcache"}) import("scanner") +import("menuconf", {alias = "menuconf_show"}) import("configheader", {alias = "generate_configheader"}) import("actions.require.install", {alias = "install_requires", rootdir = os.programdir()}) @@ -144,7 +145,12 @@ function main() -- avoid to run this task repeatly if _g.configured then return end - _g.configured = true + _g.configured = true + + -- enter menu config + if option.get("menu") then + menuconf_show() + end -- scan project and generate it if xmake.lua not exists if not os.isfile(project.file()) then diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua new file mode 100644 index 000000000..22c86c90a --- /dev/null +++ b/xmake/actions/config/menuconf.lua @@ -0,0 +1,147 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file menuconf.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.ui.log") +import("core.ui.rect") +import("core.ui.view") +import("core.ui.label") +import("core.ui.event") +import("core.ui.action") +import("core.ui.menuconf") +import("core.ui.mconfdialog") +import("core.ui.application") + +-- the app application +local app = application() + +-- init app +function app:init() + + -- init name + application.init(self, "app.config") + + -- init background + self:background_set("blue") + + -- insert menu config dialog + self:insert(self:mconfdialog()) +end + +-- get menu config dialog +function app:mconfdialog() + if not self._MCONFDIALOG then + 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() + end) + mconfdialog:action_set(action.ac_on_save, function (v) + self:save() + mconfdialog:quit() + end) + self._MCONFDIALOG = mconfdialog + end + return self._MCONFDIALOG +end + +-- get basic configs +function app:basic_configs() + + -- get configs from the cache first + local configs = self._BASIC_CONFIGS + if configs then + return configs + end + + -- get config menu + local menu = option.taskmenu("config") + + -- make configs from options + local configs = {} + local options = menu and menu.options or {} + for _, opt in ipairs(options) do + + -- get name + local name = opt[2] or opt[1] + + -- get kind + local kind = opt[3] + + -- get default + local default = opt[4] + + -- get description + local description = opt[5] + + -- key=value? + if kind == "kv" then + table.insert(configs, menuconf.string {name = name, default = default, description = description}) + elseif kind == "k" then + table.insert(configs, menuconf.boolean {name = name, default = default, description = description}) + end + end + + -- cache configs + self._BASIC_CONFIGS = configs + return configs +end + +-- get project configs +function app:project_configs() + + -- get configs from the cache first + local configs = self._PROJECT_CONFIGS + if configs then + return configs + end + + -- TODO + + -- cache configs + self._PROJECT_CONFIGS = configs + return configs +end + +-- load configs from options +function app:load() + + -- 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()}) + self:mconfdialog():load(configs) +end + +-- save configs to options +function app:save() +end + +-- main entry +function main(...) + app:run(...) +end diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index a60837a8b..b1e29b1f8 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -46,6 +46,7 @@ task("config") , options = { {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + , {nil, "menu", "k", nil, "Configure project with a menu-driven user interface." } , {nil, "require", "kv", nil, "Require all dependent packages?", " - y: force to enable", " - n: disable" } diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index c4c2cbbac..8d43fabe5 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -62,30 +62,6 @@ function option._translate(menu) return true end --- get the task menu -function option._taskmenu(task) - - -- check - assert(option._MENU) - - -- the current task - task = task or option.taskname() or "main" - - -- get the task menu - local taskmenu = option._MENU[task] - if type(taskmenu) == "function" then - - -- load this task menu - taskmenu = taskmenu() - - -- save this task menu - option._MENU[task] = taskmenu - end - - -- get it - return taskmenu -end - -- get the top context function option._context() @@ -201,7 +177,7 @@ function option.init(menu) end -- the main menu - local main = option._taskmenu("main") + local main = option.taskmenu("main") assert(main) -- new top context @@ -262,7 +238,7 @@ function option.init(menu) -- find this option local opt = nil local longname = nil - for _, o in ipairs(option._taskmenu().options) do + for _, o in ipairs(option.taskmenu().options) do -- check assert(o) @@ -363,7 +339,7 @@ function option.init(menu) -- find a value option with name local opt = nil - for _, o in ipairs(option._taskmenu().options) do + for _, o in ipairs(option.taskmenu().options) do -- the mode local mode = o[3] @@ -420,7 +396,7 @@ function option.init(menu) end -- init the default value - for _, o in ipairs(table.wrap(option._taskmenu().options)) do + for _, o in ipairs(table.wrap(option.taskmenu().options)) do -- the long name local longname = o[2] @@ -690,9 +666,31 @@ end -- get the current task name function option.taskname() + return option._context().taskname +end + +-- get the task menu +function option.taskmenu(task) + + -- check + assert(option._MENU) + + -- the current task + task = task or option.taskname() or "main" + + -- get the task menu + local taskmenu = option._MENU[task] + if type(taskmenu) == "function" then + + -- load this task menu + taskmenu = taskmenu() + + -- save this task menu + option._MENU[task] = taskmenu + end -- get it - return option._context().taskname + return taskmenu end -- get the given option value for the current task @@ -773,7 +771,7 @@ function option.defaults(task) end -- the task menu - local taskmenu = option._taskmenu(task) + local taskmenu = option.taskmenu(task) -- get the default options for the given task local defaults = {} @@ -820,7 +818,7 @@ function option.show_menu(task) assert(menu) -- the task menu - local taskmenu = option._taskmenu(task) + local taskmenu = option.taskmenu(task) assert(taskmenu) -- print title @@ -859,7 +857,7 @@ function option.show_main() assert(menu) -- the main menu - local main = option._taskmenu("main") + local main = option.taskmenu("main") assert(main) -- print title diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua index 4be085674..24986fd47 100644 --- a/xmake/core/sandbox/modules/import/core/base/option.lua +++ b/xmake/core/sandbox/modules/import/core/base/option.lua @@ -45,6 +45,11 @@ function sandbox_core_base_option.default(name) return option.default(name) end +-- get the given task menu +function sandbox_core_base_option.taskmenu(taskname) + return option.taskmenu(taskname) +end + -- get the options function sandbox_core_base_option.options() return assert(option.options()) diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua index 7fb70758e..5d0145a91 100644 --- a/xmake/core/ui/mconfdialog.lua +++ b/xmake/core/ui/mconfdialog.lua @@ -95,6 +95,11 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> to go back or exit, <?> for Hel end) end +-- load configs +function mconfdialog:load(configs) + return self:menuconf():load(configs) +end + -- get menu config function mconfdialog:menuconf() if not self._MENUCONF then |
