edn/sources/appl/TextPluginCopy.cpp

94 lines
2.8 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginCopy.h>
2013-12-13 21:50:40 +01:00
#include <ewol/context/clipBoard.h>
#include <appl/Gui/TextViewer.h>
2013-10-22 21:34:13 +02:00
#undef __class__
#define __class__ "TextPluginCopy"
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::init() {
appl::TextViewerPlugin::init();
}
void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
2014-08-28 22:31:00 +02:00
std::shared_ptr<ewol::widget::Menu> menu = m_menuInterface.lock();
if (menu != nullptr) {
2014-08-29 22:52:21 +02:00
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");
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");
std::shared_ptr<ewol::widget::Menu> 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,
const std::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) {
2013-11-14 21:57:10 +01:00
std::string value;
_textDrawer.copy(value);
if (value.size() != 0) {
2013-12-13 21:50:40 +01:00
ewol::context::clipBoard::set(ewol::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) {
2013-12-13 21:50:40 +01:00
ewol::context::clipBoard::request(ewol::context::clipBoard::clipboardStd);
}
return true;
}
return false;
}