edn/sources/appl/TextPluginCopy.cpp

83 lines
2.7 KiB
C++
Raw Permalink Normal View History

2016-05-02 22:01:55 +02:00
/** @file
* @author Edouard DUPIN
* @copyright 2010, Edouard DUPIN, all right reserved
* @license GPL v3 (see license file)
*/
2016-10-03 22:01:55 +02:00
#include <appl/TextPluginCopy.hpp>
#include <gale/context/clipBoard.hpp>
#include <appl/Gui/TextViewer.hpp>
2014-08-29 22:52:21 +02:00
appl::TextPluginCopy::TextPluginCopy() :
m_menuIdTitle(-1),
m_menuIdCopy(-1),
m_menuIdCut(-1),
m_menuIdPast(-1),
m_menuIdRemove(-1) {
m_activateOnReceiveShortCut = true;
addObjectType("appl::TextPluginCopy");
}
void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
2016-07-19 22:03:39 +02:00
ememory::SharedPtr<ewol::widget::Menu> menu = m_menuInterface.lock();
2018-06-19 22:31:29 +02:00
if (menu != null) {
m_menuIdTitle = menu->addTitle("_T{Edit}");
2014-08-29 22:52:21 +02:00
if (m_menuIdTitle != -1) {
m_menuIdCopy = menu->add(m_menuIdTitle, "_T{Copy}", "", "appl::TextPluginCopy::menu:copy");
m_menuIdCut = menu->add(m_menuIdTitle, "_T{Cut}", "", "appl::TextPluginCopy::menu:cut");
m_menuIdPast = menu->add(m_menuIdTitle, "_T{Paste}", "", "appl::TextPluginCopy::menu:past");
m_menuIdRemove = menu->add(m_menuIdTitle, "_T{Remove}", "", "appl::TextPluginCopy::menu:remove");
2014-08-28 22:31:00 +02:00
}
}
_textDrawer.ext_shortCutAdd("ctrl+x", "appl::TextPluginCopy::cut");
_textDrawer.ext_shortCutAdd("ctrl+c", "appl::TextPluginCopy::copy");
_textDrawer.ext_shortCutAdd("ctrl+v", "appl::TextPluginCopy::Paste");
}
void appl::TextPluginCopy::onPluginDisable(appl::TextViewer& _textDrawer) {
2014-08-29 22:52:21 +02:00
_textDrawer.ext_shortCutRm("appl::TextPluginCopy::cut");
_textDrawer.ext_shortCutRm("appl::TextPluginCopy::copy");
_textDrawer.ext_shortCutRm("appl::TextPluginCopy::Paste");
2016-07-19 22:03:39 +02:00
ememory::SharedPtr<ewol::widget::Menu> menu = m_menuInterface.lock();
2018-06-19 22:31:29 +02:00
if (menu != null) {
2014-08-29 22:52:21 +02:00
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,
2017-08-28 00:09:10 +02:00
const etk::String& _shortCutName) {
2013-10-22 21:34:13 +02:00
if (isEnable() == false) {
return false;
}
if ( _shortCutName == "appl::TextPluginCopy::copy"
|| _shortCutName == "appl::TextPluginCopy::cut") {
if (_textDrawer.hasBuffer() == true) {
2017-08-28 00:09:10 +02:00
etk::String value;
_textDrawer.copy(value);
if (value.size() != 0) {
gale::context::clipBoard::set(gale::context::clipBoard::clipboardStd, value);
}
}
if (_shortCutName == "appl::TextPluginCopy::cut") {
2013-11-21 21:56:22 +01:00
_textDrawer.remove();
}
return true;
} else if (_shortCutName == "appl::TextPluginCopy::Paste") {
if (_textDrawer.hasBuffer() == true) {
gale::context::clipBoard::request(gale::context::clipBoard::clipboardStd);
}
return true;
}
return false;
}