From 5df22f169370e6d896bc5b4498cb9751685f3907 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:54:22 +0500 Subject: [PATCH] #393 WIP: Move plugins to ui::base --- src/netxs/apps/desk.hpp | 3 +- src/netxs/desktopio/application.hpp | 5 +- src/netxs/desktopio/baseui.hpp | 25 ++++ src/netxs/desktopio/console.hpp | 17 ++- src/netxs/desktopio/controls.hpp | 29 ++--- src/vtm.cpp | 8 +- src/vtm.hpp | 183 ++++++++++++++-------------- 7 files changed, 145 insertions(+), 125 deletions(-) diff --git a/src/netxs/apps/desk.hpp b/src/netxs/apps/desk.hpp index 2c143d0543..1f25e4c971 100644 --- a/src/netxs/apps/desk.hpp +++ b/src/netxs/apps/desk.hpp @@ -602,7 +602,8 @@ namespace netxs::app::desk { usrcfg.win = {}; usrcfg.gear_id = seed.gear_id; - boss.base::riseup(tier::release, scripting::events::invoke, usrcfg); + //todo scripting + //boss.base::riseup(tier::release, scripting::events::invoke, usrcfg); oneshot->reset(); }; }; diff --git a/src/netxs/desktopio/application.hpp b/src/netxs/desktopio/application.hpp index d6776b2b31..b62c91a8c5 100644 --- a/src/netxs/desktopio/application.hpp +++ b/src/netxs/desktopio/application.hpp @@ -10,7 +10,7 @@ #include "console.hpp" #include "system.hpp" -#include "scripting.hpp" +//#include "scripting.hpp" #include "gui.hpp" #include @@ -781,7 +781,8 @@ namespace netxs::app::shared { app::shared::splice(client, gui_config); }}; - auto domain = ui::host::ctor(server, config)->plugin(); + //todo scripting + auto domain = ui::host::ctor(server, config);// ->plugin(); auto appcfg = eccc{ .cmd = cmd }; auto applet = app::shared::builder(aclass)(appcfg, config); config_lock.unlock(); diff --git a/src/netxs/desktopio/baseui.hpp b/src/netxs/desktopio/baseui.hpp index 1887e1fced..861faa98ef 100644 --- a/src/netxs/desktopio/baseui.hpp +++ b/src/netxs/desktopio/baseui.hpp @@ -464,6 +464,12 @@ namespace netxs::ui { using e2 = netxs::events::userland::e2; + // controls: UI extensions. + namespace pro + { + struct skill; + } + //todo reimplement struct skin { @@ -578,6 +584,7 @@ namespace netxs::ui bool locked; // base: Object has fixed size. bool master; // base: Anycast root. si32 family; // base: Object type. + std::map> depo; template auto This() { return std::static_pointer_cast>(shared_from_this()); } @@ -889,6 +896,24 @@ namespace netxs::ui base::intpad = new_intpad; base::extpad = new_extpad; } + // base: Detach the specified plugin. + template + void unplug() + { + depo.erase(std::type_index(typeid(S))); + } + // base: Return a reference to a plugin of the specified type. Create an instance of the specified plugin (using the specified arguments) if it does not exist. + template + auto& plugin(Args&&... args) + { + auto it = depo.find(std::type_index(typeid(S))); + if (it == depo.end()) + { + it = depo.emplace(std::type_index(typeid(S)), std::make_unique(*this, std::forward(args)...)).first; + } + auto ptr = static_cast(it->second.get()); + return *ptr; + } // base: Render to the canvas. Trim = trim viewport to the nested object region. template void render(face& canvas, bool trim = true, bool pred = true, bool post = true) diff --git a/src/netxs/desktopio/console.hpp b/src/netxs/desktopio/console.hpp index d9afd71d1f..cc6c69405c 100644 --- a/src/netxs/desktopio/console.hpp +++ b/src/netxs/desktopio/console.hpp @@ -502,7 +502,7 @@ namespace netxs::ui public: pipe& canal; // gate: Channel to outside. - props_t props; // gate: Application properties. + props_t props; // gate: Input gate properties. diff paint; // gate: Render. link conio; // gate: Input data parser. bool direct; // gate: . @@ -557,6 +557,13 @@ namespace netxs::ui } return std::pair{ id_t{}, netxs::sptr{} }; } + id_t get_int_gear_id(id_t ext_gear_id) + { + auto int_gear_id = id_t{}; + auto gear_it = gears.find(ext_gear_id); + if (gear_it != gears.end()) int_gear_id = gear_it->second->id; + return int_gear_id; + } void draw_foreign_names(face& parent_canvas) { auto& header = *uname.lyric; @@ -660,14 +667,6 @@ namespace netxs::ui if (result) base::strike(); } - // gate: . - id_t get_int_gear_id(id_t ext_gear_id) - { - auto int_gear_id = id_t{}; - auto gear_it = gears.find(ext_gear_id); - if (gear_it != gears.end()) int_gear_id = gear_it->second->id; - return int_gear_id; - } // gate: Attach a new item. auto attach(sptr& item) { diff --git a/src/netxs/desktopio/controls.hpp b/src/netxs/desktopio/controls.hpp index 3ac7e2382e..93d3d3c5f6 100644 --- a/src/netxs/desktopio/controls.hpp +++ b/src/netxs/desktopio/controls.hpp @@ -2886,7 +2886,6 @@ namespace netxs::ui class form : public base { - std::map> depo; std::map memomap; // form: Token set for dependent subscriptions. public: @@ -2897,33 +2896,25 @@ namespace netxs::ui auto item = ui::tui_domain().template create(std::forward(args)...); return item; } - // form: Attach feature and return itself. + // form: Attach a plugin of the specified type and return self. template auto plugin(Args&&... args) { - auto backup = This(); - depo[std::type_index(typeid(S))] = std::make_unique(*backup, std::forward(args)...); - return backup; + base::plugin(std::forward(args)...); + return This(); } - // form: Detach feature and return itself. + // form: Detach the specified plugin and return self. template auto unplug() { - auto backup = This(); - depo.erase(std::type_index(typeid(S))); - return backup; + base::unplug(); + return This(); } // form: Return plugin reference of specified type. Add the specified plugin (using specified args) if it is missing. template auto& plugins(Args&&... args) { - auto it = depo.find(std::type_index(typeid(S))); - if (it == depo.end()) - { - it = depo.emplace(std::type_index(typeid(S)), std::make_unique(*this, std::forward(args)...)).first; - } - auto ptr = static_cast(it->second.get()); - return *ptr; + return base::plugin(std::forward(args)...); } // form: Fill object region using parametrized fx. template> @@ -2963,7 +2954,7 @@ namespace netxs::ui } return This(); } - // form: deprecated in favor of pro::brush. Set colors and return itself. + // form: deprecated in favor of pro::brush. Set colors and return self. template auto colors(Args&&... args) { @@ -2987,7 +2978,7 @@ namespace netxs::ui { return active(base::color()); } - // form: Invoke arbitrary functor(itself/*This/boss) in place. + // form: Invoke an arbitrary functor(self/*This/boss) in place. template auto invoke(P functor) { @@ -2995,7 +2986,7 @@ namespace netxs::ui functor(*backup); return backup; } - // form: Attach homeless branch and return itself. + // form: Attach a homeless branch and return self. template auto branch(Args&&... args) { diff --git a/src/vtm.cpp b/src/vtm.cpp index ee5d6a1359..7f3427b7c9 100644 --- a/src/vtm.cpp +++ b/src/vtm.cpp @@ -450,7 +450,8 @@ int main(int argc, char* argv[]) using e2 = ui::e2; auto config_lock = ui::tui_domain().unique_lock(); // Sync multithreaded access to config. auto domain = ui::host::ctor(server, config); - domain->plugin(); + //todo scripting + //domain->plugin(); domain->autorun(); auto settings = config.utf8(); config_lock.unlock(); @@ -474,7 +475,8 @@ int main(int argc, char* argv[]) if (active) { onecmd.cmd = cmd; - domain->bell::signal(tier::release, scripting::events::invoke, onecmd); + //todo scripting + //domain->bell::signal(tier::release, scripting::events::invoke, onecmd); } else { @@ -503,7 +505,7 @@ int main(int argc, char* argv[]) } }}; - auto execline = [&](qiew line){ domain->bell::signal(tier::release, scripting::events::invoke, { .cmd = line }); }; + auto execline = [&](qiew /*line*/) { /*domain->bell::signal(tier::release, scripting::events::invoke, {.cmd = line});*/ }; //todo scripting auto shutdown = [&]{ domain->bell::signal(tier::general, e2::shutdown, utf::concat(prompt::main, "Shutdown on signal")); }; execline(script); auto readline = os::tty::readline(execline, shutdown); diff --git a/src/vtm.hpp b/src/vtm.hpp index 3343162251..8a839cc237 100644 --- a/src/vtm.hpp +++ b/src/vtm.hpp @@ -2308,97 +2308,98 @@ namespace netxs::app::vtm gear_id = {}; } }; - LISTEN(tier::release, scripting::events::invoke, script) - { - static auto fx = std::unordered_map - { - { "vtm.selected" , &hall::vtm_selected }, - { "vtm.set" , &hall::vtm_set }, - { "vtm.del" , &hall::vtm_del }, - { "vtm.run" , &hall::vtm_run }, - { "vtm.dtvt" , &hall::vtm_dtvt }, - { "vtm.disconnect", &hall::vtm_disconnect }, - { "vtm.exit" , &hall::vtm_shutdown }, - { "vtm.close" , &hall::vtm_shutdown }, - { "vtm.shutdown" , &hall::vtm_shutdown }, - - { "vtm.window.next" , &hall::vtm_nextwindow }, - { "vtm.window.alwaysontop", &hall::vtm_alwaysontop }, - { "vtm.window.warp" , &hall::vtm_warp }, - { "vtm.window.close" , &hall::vtm_close }, - { "vtm.window.minimize" , &hall::vtm_minimize }, - { "vtm.window.maximize" , &hall::vtm_maximize }, - { "vtm.window.fullscreen" , &hall::vtm_fullscreen }, - }; - static auto delims = "\r\n\t ;.,\"\'"sv; - static auto expression = [](auto& shadow) - { - auto func = qiew{}; - auto args = qiew{}; - auto fend = shadow.find('('); - if (fend < shadow.size() - 1) - { - auto para = 1; - auto quot = '\0'; - auto head = shadow.begin() + fend + 1; - auto tail = shadow.end(); - while (head != tail) - { - auto c = *head; - if (c == '\\' && head + 1 != tail) head++; - else if (quot) - { - if (c == quot) quot = 0; - } - else if (c == '\"') quot = c; - else if (c == '\'') quot = c; - else if (c == '(') para++; - else if (c == ')' && --para == 0) break; - head++; - } - if (head != tail) - { - auto aend = std::distance(shadow.begin(), head); - func = shadow.substr(0, fend); - args = shadow.substr(fend + 1, aend - (fend + 1)); - shadow.remove_prefix(aend + 1); - } - utf::trim_front(shadow, delims); - } - return std::pair{ func, args }; - }; - utf::unescape(script.cmd); - auto backup = std::move(script.cmd); - auto shadow = qiew{ backup }; - utf::trim_front(shadow, delims); - while (shadow) - { - auto [func, args] = expression(shadow); - if (func) - { - auto expr = utf::debase(utf::concat(func, '(', args, ')')); - auto iter = fx.find(func); - if (iter != fx.end()) - { - auto result = (this->*(iter->second))(script, args); - log(ansi::clr(yellowlt, expr, ": "), result); - script.cmd += expr + ": " + result + '\n'; - } - else - { - log(prompt::repl, "Function not found: ", expr); - script.cmd += "Function not found: " + expr + '\n'; - } - } - else - { - auto expr = utf::debase(shadow); - log(prompt::repl, "Check syntax: ", ansi::clr(redlt, expr)); - script.cmd += "Check syntax: " + expr + '\n'; - break; - } - } - }; + //todo scripting + //LISTEN(tier::release, scripting::events::invoke, script) + //{ + // static auto fx = std::unordered_map + // { + // { "vtm.selected" , &hall::vtm_selected }, + // { "vtm.set" , &hall::vtm_set }, + // { "vtm.del" , &hall::vtm_del }, + // { "vtm.run" , &hall::vtm_run }, + // { "vtm.dtvt" , &hall::vtm_dtvt }, + // { "vtm.disconnect", &hall::vtm_disconnect }, + // { "vtm.exit" , &hall::vtm_shutdown }, + // { "vtm.close" , &hall::vtm_shutdown }, + // { "vtm.shutdown" , &hall::vtm_shutdown }, + // + // { "vtm.window.next" , &hall::vtm_nextwindow }, + // { "vtm.window.alwaysontop", &hall::vtm_alwaysontop }, + // { "vtm.window.warp" , &hall::vtm_warp }, + // { "vtm.window.close" , &hall::vtm_close }, + // { "vtm.window.minimize" , &hall::vtm_minimize }, + // { "vtm.window.maximize" , &hall::vtm_maximize }, + // { "vtm.window.fullscreen" , &hall::vtm_fullscreen }, + // }; + // static auto delims = "\r\n\t ;.,\"\'"sv; + // static auto expression = [](auto& shadow) + // { + // auto func = qiew{}; + // auto args = qiew{}; + // auto fend = shadow.find('('); + // if (fend < shadow.size() - 1) + // { + // auto para = 1; + // auto quot = '\0'; + // auto head = shadow.begin() + fend + 1; + // auto tail = shadow.end(); + // while (head != tail) + // { + // auto c = *head; + // if (c == '\\' && head + 1 != tail) head++; + // else if (quot) + // { + // if (c == quot) quot = 0; + // } + // else if (c == '\"') quot = c; + // else if (c == '\'') quot = c; + // else if (c == '(') para++; + // else if (c == ')' && --para == 0) break; + // head++; + // } + // if (head != tail) + // { + // auto aend = std::distance(shadow.begin(), head); + // func = shadow.substr(0, fend); + // args = shadow.substr(fend + 1, aend - (fend + 1)); + // shadow.remove_prefix(aend + 1); + // } + // utf::trim_front(shadow, delims); + // } + // return std::pair{ func, args }; + // }; + // utf::unescape(script.cmd); + // auto backup = std::move(script.cmd); + // auto shadow = qiew{ backup }; + // utf::trim_front(shadow, delims); + // while (shadow) + // { + // auto [func, args] = expression(shadow); + // if (func) + // { + // auto expr = utf::debase(utf::concat(func, '(', args, ')')); + // auto iter = fx.find(func); + // if (iter != fx.end()) + // { + // auto result = (this->*(iter->second))(script, args); + // log(ansi::clr(yellowlt, expr, ": "), result); + // script.cmd += expr + ": " + result + '\n'; + // } + // else + // { + // log(prompt::repl, "Function not found: ", expr); + // script.cmd += "Function not found: " + expr + '\n'; + // } + // } + // else + // { + // auto expr = utf::debase(shadow); + // log(prompt::repl, "Check syntax: ", ansi::clr(redlt, expr)); + // script.cmd += "Check syntax: " + expr + '\n'; + // break; + // } + // } + //}; //LISTEN(tier::preview, e2::form::proceed::action::runscript, gear) //{