From b889b4aa5af4dcecf9e273e21c587c76f6066e8f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 29 Aug 2014 22:52:21 +0200 Subject: [PATCH] [DEV] update plugin --- sources/appl/Gui/MainWindows.cpp | 7 ----- sources/appl/Gui/TextViewer.h | 10 +++++-- sources/appl/TextPlugin.cpp | 4 +++ sources/appl/TextPlugin.h | 1 + sources/appl/TextPluginCopy.cpp | 39 ++++++++++++++++++++-------- sources/appl/TextPluginCopy.h | 6 +++++ sources/appl/TextPluginCtags.cpp | 4 ++- sources/appl/TextPluginData.h | 3 +++ sources/appl/TextPluginHistory.cpp | 25 ++++++++++++++++-- sources/appl/TextPluginHistory.h | 4 +++ sources/appl/TextPluginManager.cpp | 12 +++++++++ sources/appl/TextPluginRmLine.cpp | 2 +- sources/appl/TextPluginSelectAll.cpp | 33 +++++++++++++++++++++-- sources/appl/TextPluginSelectAll.h | 3 +++ 14 files changed, 127 insertions(+), 26 deletions(-) diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index a991d5c..1a5e9c1 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -191,15 +191,8 @@ void MainWindows::init() { myMenu->add(idMenuFile, "Save", "THEME:GUI:Save.edf", "menu:save"); myMenu->add(idMenuFile, "Save As ...", "", "menu:save-as"); myMenu->addSpacer(); - //myMenu->add(idMenuFile, "Exit", "", ednMsgGuiExit); - myMenu->addSpacer(); myMenu->add(idMenuFile, "Properties", "THEME:GUI:Parameter.edf", "menu:property"); int32_t idMenuEdit = myMenu->addTitle("Edit"); - myMenu->add(idMenuEdit, "Undo", "THEME:GUI:Undo.edf", "menu:undo"); - myMenu->add(idMenuEdit, "Redo", "THEME:GUI:Redo.edf", "menu:redo"); - myMenu->addSpacer(); - myMenu->add(idMenuEdit, "Select All","", "menu:select-all"); - myMenu->add(idMenuEdit, "Un-Select","", "menu:select-none"); myMenu->add(idMenuEdit, "Goto line ...","", "menu:goto-line"); int32_t idMenuSearch = myMenu->addTitle("Search"); myMenu->add(idMenuSearch, "Search", "THEME:GUI:Search.edf", "menu:search"); diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 65a9b54..9b5c55a 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -397,13 +397,19 @@ namespace appl { /** * @brief add a specific shortcut with his description * @param[in] _descriptiveString Description string of the shortcut - * @param[in] _generateEventId Event generic of the element - * @param[in] _data Associate data wit the event + * @param[in] _generateEventName Event generic of the element */ virtual void ext_shortCutAdd(const std::string& _descriptiveString, const std::string& _generateEventName) { shortCutAdd(_descriptiveString, _generateEventName); } + /** + * @brief Remove a specific shortcut with his event name + * @param[in] _generateEventName Event of the element shortcut + */ + virtual void ext_shortCutRm(const std::string& _generateEventName) { + shortCutRemove(_generateEventName); + } private: // callback fundtions void onCallbackIsModify(); void onCallbackShortCut(const std::string& _value); diff --git a/sources/appl/TextPlugin.cpp b/sources/appl/TextPlugin.cpp index 2b0ca26..7160c8b 100644 --- a/sources/appl/TextPlugin.cpp +++ b/sources/appl/TextPlugin.cpp @@ -34,6 +34,10 @@ void appl::TextViewerPlugin::init() { ewol::Object::init(); } +void appl::TextViewerPlugin::init(const std::string& _name) { + ewol::Object::init(_name); +} + appl::TextViewerPlugin::~TextViewerPlugin() { if (m_isEnable == false) { return; diff --git a/sources/appl/TextPlugin.h b/sources/appl/TextPlugin.h index d4bed7c..1609345 100644 --- a/sources/appl/TextPlugin.h +++ b/sources/appl/TextPlugin.h @@ -21,6 +21,7 @@ namespace appl { protected: TextViewerPlugin(); void init(); + void init(const std::string& _name); public: DECLARE_FACTORY(TextViewerPlugin); virtual ~TextViewerPlugin(); diff --git a/sources/appl/TextPluginCopy.cpp b/sources/appl/TextPluginCopy.cpp index bf88356..55b9e5f 100644 --- a/sources/appl/TextPluginCopy.cpp +++ b/sources/appl/TextPluginCopy.cpp @@ -15,7 +15,12 @@ #define __class__ "TextPluginCopy" -appl::TextPluginCopy::TextPluginCopy() { +appl::TextPluginCopy::TextPluginCopy() : + m_menuIdTitle(-1), + m_menuIdCopy(-1), + m_menuIdCut(-1), + m_menuIdPast(-1), + m_menuIdRemove(-1) { m_activateOnReceiveShortCut = true; addObjectType("appl::TextPluginCopy"); } @@ -25,18 +30,15 @@ void appl::TextPluginCopy::init() { } void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) { - APPL_ERROR("plop"); // add event : std::shared_ptr menu = m_menuInterface.lock(); if (menu != nullptr) { - APPL_ERROR("plop 1"); - int32_t idMenuEdit = menu->addTitle("Edit"); - if (idMenuEdit != -1) { - APPL_ERROR("plop 2 "); - menu->add(idMenuEdit, "Copy", "", "appl::TextPluginCopy::menu:copy"); - menu->add(idMenuEdit, "Cut", "", "appl::TextPluginCopy::menu:cut"); - menu->add(idMenuEdit, "Paste", "", "appl::TextPluginCopy::menu:past"); - menu->add(idMenuEdit, "Remove", "", "appl::TextPluginCopy::menu:remove"); + m_menuIdTitle = menu->addTitle("Edit"); + if (m_menuIdTitle != -1) { + m_menuIdCopy = menu->add(m_menuIdTitle, "Copy", "", "appl::TextPluginCopy::menu:copy"); + m_menuIdCut = menu->add(m_menuIdTitle, "Cut", "", "appl::TextPluginCopy::menu:cut"); + m_menuIdPast = menu->add(m_menuIdTitle, "Paste", "", "appl::TextPluginCopy::menu:past"); + m_menuIdRemove = menu->add(m_menuIdTitle, "Remove", "", "appl::TextPluginCopy::menu:remove"); } } _textDrawer.ext_shortCutAdd("ctrl+x", "appl::TextPluginCopy::cut"); @@ -45,7 +47,22 @@ void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) { } void appl::TextPluginCopy::onPluginDisable(appl::TextViewer& _textDrawer) { - // TODO : unknow function ... + _textDrawer.ext_shortCutRm("appl::TextPluginCopy::cut"); + _textDrawer.ext_shortCutRm("appl::TextPluginCopy::copy"); + _textDrawer.ext_shortCutRm("appl::TextPluginCopy::Paste"); + std::shared_ptr menu = m_menuInterface.lock(); + if (menu != nullptr) { + menu->remove(m_menuIdRemove); + menu->remove(m_menuIdPast); + menu->remove(m_menuIdCut); + menu->remove(m_menuIdCopy); + menu->remove(m_menuIdTitle); + } + m_menuIdTitle = -1; + m_menuIdCopy = -1; + m_menuIdCut = -1; + m_menuIdPast = -1; + m_menuIdRemove = -1; } bool appl::TextPluginCopy::onReceiveShortCut(appl::TextViewer& _textDrawer, diff --git a/sources/appl/TextPluginCopy.h b/sources/appl/TextPluginCopy.h index a8d0e3e..27b0d9b 100644 --- a/sources/appl/TextPluginCopy.h +++ b/sources/appl/TextPluginCopy.h @@ -17,6 +17,12 @@ namespace appl { class TextPluginCopy : public appl::TextViewerPlugin { + private: + int32_t m_menuIdTitle; + int32_t m_menuIdCopy; + int32_t m_menuIdCut; + int32_t m_menuIdPast; + int32_t m_menuIdRemove; protected: TextPluginCopy(); void init(); diff --git a/sources/appl/TextPluginCtags.cpp b/sources/appl/TextPluginCtags.cpp index 3e4e0b5..3a4ea11 100644 --- a/sources/appl/TextPluginCtags.cpp +++ b/sources/appl/TextPluginCtags.cpp @@ -45,7 +45,9 @@ void appl::TextPluginCtags::onPluginEnable(appl::TextViewer& _textDrawer) { } void appl::TextPluginCtags::onPluginDisable(appl::TextViewer& _textDrawer) { - // TODO : unknow function ... + _textDrawer.ext_shortCutRm("appl::TextPluginCtags::JumpDestination"); + _textDrawer.ext_shortCutRm("appl::TextPluginCtags::JumpBack"); + _textDrawer.ext_shortCutRm("appl::TextPluginCtags::OpenCtagsFile"); } void appl::TextPluginCtags::jumpTo(const std::string& _name) { diff --git a/sources/appl/TextPluginData.h b/sources/appl/TextPluginData.h index df5b623..83cff7b 100644 --- a/sources/appl/TextPluginData.h +++ b/sources/appl/TextPluginData.h @@ -25,6 +25,9 @@ namespace appl { void init() { appl::TextViewerPlugin::init(); } + void init(const std::string& _name) { + appl::TextViewerPlugin::init(_name); + } public: DECLARE_FACTORY(TextViewerPluginData); virtual ~TextViewerPluginData() { diff --git a/sources/appl/TextPluginHistory.cpp b/sources/appl/TextPluginHistory.cpp index bc04d2d..816df06 100644 --- a/sources/appl/TextPluginHistory.cpp +++ b/sources/appl/TextPluginHistory.cpp @@ -15,7 +15,10 @@ #undef __class__ #define __class__ "TextPluginHistory" -appl::TextPluginHistory::TextPluginHistory() { +appl::TextPluginHistory::TextPluginHistory() : + m_menuIdTitle(-1), + m_menuIdUndo(-1), + m_menuIdRedo(-1) { m_activateOnReceiveShortCut = true; m_activateOnWrite = true; m_activateOnReplace = true; @@ -29,13 +32,31 @@ void appl::TextPluginHistory::init() { void appl::TextPluginHistory::onPluginEnable(appl::TextViewer& _textDrawer) { + std::shared_ptr menu = m_menuInterface.lock(); + if (menu != nullptr) { + m_menuIdTitle = menu->addTitle("Edit"); + if (m_menuIdTitle != -1) { + m_menuIdUndo = menu->add(m_menuIdTitle, "Undo", "THEME:GUI:Undo.edf", "appl::TextPluginHistory::menu:undo"); + m_menuIdRedo = menu->add(m_menuIdTitle, "Redo", "THEME:GUI:Redo.edf", "appl::TextPluginHistory::menu:redo"); + } + } // add event : _textDrawer.ext_shortCutAdd("ctrl+z", "appl::TextPluginHistory::Undo"); _textDrawer.ext_shortCutAdd("ctrl+shift+z", "appl::TextPluginHistory::Redo"); } void appl::TextPluginHistory::onPluginDisable(appl::TextViewer& _textDrawer) { - // TODO : unknow function ... + _textDrawer.ext_shortCutRm("appl::TextPluginHistory::Undo"); + _textDrawer.ext_shortCutRm("appl::TextPluginHistory::Redo"); + std::shared_ptr menu = m_menuInterface.lock(); + if (menu != nullptr) { + menu->remove(m_menuIdRedo); + menu->remove(m_menuIdUndo); + menu->remove(m_menuIdTitle); + } + m_menuIdTitle = -1; + m_menuIdUndo = -1; + m_menuIdRedo = -1; } bool appl::TextPluginHistory::onDataReceiveShortCut(appl::TextViewer& _textDrawer, diff --git a/sources/appl/TextPluginHistory.h b/sources/appl/TextPluginHistory.h index be22856..0278356 100644 --- a/sources/appl/TextPluginHistory.h +++ b/sources/appl/TextPluginHistory.h @@ -36,6 +36,10 @@ namespace appl { std::vector m_redo; //!< History storing data }; class TextPluginHistory : public appl::TextViewerPluginData { + private: + int32_t m_menuIdTitle; + int32_t m_menuIdUndo; + int32_t m_menuIdRedo; protected: TextPluginHistory(); void init(); diff --git a/sources/appl/TextPluginManager.cpp b/sources/appl/TextPluginManager.cpp index f4441d8..225c997 100644 --- a/sources/appl/TextPluginManager.cpp +++ b/sources/appl/TextPluginManager.cpp @@ -52,6 +52,11 @@ static std::vector>& getListOnCursorMove return s_list; } +static std::weak_ptr& getViewerConnected() { + static std::weak_ptr s_widget; + return s_widget; +} + void appl::textPluginManager::init() { } @@ -82,6 +87,7 @@ void appl::textPluginManager::addPlugin(const std::shared_ptrgetObjectType()); getList().push_back(_plugin); if (_plugin->isAvaillableOnEventEntry() == true) { getListOnEventEntry().push_back(_plugin); @@ -104,9 +110,14 @@ void appl::textPluginManager::addPlugin(const std::shared_ptrisAvaillableOnCursorMove() == true) { getListOnCursorMove().push_back(_plugin); } + std::shared_ptr viewer = getViewerConnected().lock(); + if (viewer != nullptr) { + _plugin->onPluginEnable(*viewer); + } } void appl::textPluginManager::connect(appl::TextViewer& _widget) { + getViewerConnected() = std::dynamic_pointer_cast(_widget.shared_from_this()); for (auto &it : getList()) { if (it == nullptr) { continue; @@ -116,6 +127,7 @@ void appl::textPluginManager::connect(appl::TextViewer& _widget) { } void appl::textPluginManager::disconnect(appl::TextViewer& _widget) { + getViewerConnected().reset(); for (auto &it : getList()) { if (it == nullptr) { continue; diff --git a/sources/appl/TextPluginRmLine.cpp b/sources/appl/TextPluginRmLine.cpp index e39810d..a0504c9 100644 --- a/sources/appl/TextPluginRmLine.cpp +++ b/sources/appl/TextPluginRmLine.cpp @@ -30,7 +30,7 @@ void appl::TextPluginRmLine::onPluginEnable(appl::TextViewer& _textDrawer) { } void appl::TextPluginRmLine::onPluginDisable(appl::TextViewer& _textDrawer) { - // TODO : unknow function ... + _textDrawer.ext_shortCutRm("appl::TextPluginRmLine::Rm"); } bool appl::TextPluginRmLine::onReceiveShortCut(appl::TextViewer& _textDrawer, diff --git a/sources/appl/TextPluginSelectAll.cpp b/sources/appl/TextPluginSelectAll.cpp index dd7f534..40b1d7d 100644 --- a/sources/appl/TextPluginSelectAll.cpp +++ b/sources/appl/TextPluginSelectAll.cpp @@ -15,7 +15,10 @@ #define __class__ "TextPluginSelectAll" -appl::TextPluginSelectAll::TextPluginSelectAll() { +appl::TextPluginSelectAll::TextPluginSelectAll() : + m_menuIdTitle(-1), + m_menuIdSelectAll(-1), + m_menuIdSelectNone(-1) { m_activateOnReceiveShortCut = true; addObjectType("appl::TextPluginSelectAll"); } @@ -25,12 +28,31 @@ void appl::TextPluginSelectAll::init() { } void appl::TextPluginSelectAll::onPluginEnable(appl::TextViewer& _textDrawer) { + std::shared_ptr menu = m_menuInterface.lock(); + if (menu != nullptr) { + m_menuIdTitle = menu->addTitle("Edit"); + if (m_menuIdTitle != -1) { + m_menuIdSelectAll = menu->add(m_menuIdTitle, "Select All","", "appl::TextPluginSelectAll::menu:select-all"); + m_menuIdSelectNone = menu->add(m_menuIdTitle, "Un-Select","", "appl::TextPluginSelectAll::menu:select-none"); + } + } // add event : _textDrawer.ext_shortCutAdd("ctrl+a", "appl::TextPluginSelectAll::All"); + _textDrawer.ext_shortCutAdd("ctrl+shift+a", "appl::TextPluginSelectAll::None"); } void appl::TextPluginSelectAll::onPluginDisable(appl::TextViewer& _textDrawer) { - // TODO : unknow function ... + _textDrawer.ext_shortCutRm("appl::TextPluginSelectAll::All"); + _textDrawer.ext_shortCutRm("appl::TextPluginSelectAll::None"); + std::shared_ptr menu = m_menuInterface.lock(); + if (menu != nullptr) { + menu->remove(m_menuIdSelectNone); + menu->remove(m_menuIdSelectAll); + menu->remove(m_menuIdTitle); + } + m_menuIdTitle = -1; + m_menuIdSelectAll = -1; + m_menuIdSelectNone = -1; } bool appl::TextPluginSelectAll::onReceiveShortCut(appl::TextViewer& _textDrawer, @@ -45,5 +67,12 @@ bool appl::TextPluginSelectAll::onReceiveShortCut(appl::TextViewer& _textDrawer, _textDrawer.select(_textDrawer.begin(), _textDrawer.end()); return true; } + if (_shortCutName == "appl::TextPluginSelectAll::None") { + if (_textDrawer.hasBuffer() == false) { + return false; + } + _textDrawer.unSelect(); + return true; + } return false; } diff --git a/sources/appl/TextPluginSelectAll.h b/sources/appl/TextPluginSelectAll.h index 6fefec7..c4b3fb7 100644 --- a/sources/appl/TextPluginSelectAll.h +++ b/sources/appl/TextPluginSelectAll.h @@ -20,6 +20,9 @@ namespace appl { protected: TextPluginSelectAll(); void init(); + int32_t m_menuIdTitle; + int32_t m_menuIdSelectAll; + int32_t m_menuIdSelectNone; public: DECLARE_FACTORY(TextPluginSelectAll); virtual ~TextPluginSelectAll() {