[DEV] add ctags and select all plugin and correct the undo/redo plugin

This commit is contained in:
Edouard DUPIN 2013-11-25 22:18:06 +01:00
parent b79578b7e1
commit 4d999bbb67
14 changed files with 422 additions and 74 deletions

View File

@ -261,7 +261,7 @@ MainWindows::MainWindows(void) {
shortCutAdd("ctrl+f", ednMsgGuiSearch, "", true);
shortCutAdd("F12", ednMsgGuiReloadShader, "", true);
shortCutAdd("ctrl+d", ednMsgGuiCtags, "Jump", true);
//shortCutAdd("ctrl+d", ednMsgGuiCtags, "Jump", true);

View File

@ -35,16 +35,12 @@ appl::TextViewer::TextViewer(const std::string& _fontName, int32_t _fontSize) :
addObjectType("appl::TextViewer");
setCanHaveFocus(true);
registerMultiCast(ednMsgBufferId);
registerMultiCast(ednMsgGuiSelect);
registerMultiCast(ednMsgGuiFind);
registerMultiCast(ednMsgGuiReplace);
registerMultiCast(ednMsgGuiGotoLine);
registerMultiCast(appl::MsgSelectNewFile);
setLimitScrolling(0.2);
shortCutAdd("ctrl+a", ednMsgGuiSelect, "ALL");
shortCutAdd("ctrl+shift+a", ednMsgGuiSelect, "NONE");
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
m_viewerManager = appl::ViewerManager::keep();
@ -60,15 +56,6 @@ appl::TextViewer::TextViewer(const std::string& _fontName, int32_t _fontSize) :
m_colorSelection = m_paintingProperties->request("SelectedText");
m_colorNormal = m_paintingProperties->request("normal");
// by default we load an example object:
/*
m_buffer = new appl::Buffer();
if (m_buffer == NULL) {
APPL_ERROR("can not create buffer ... ");
return;
}
m_buffer->loadFile("./example.txt");
*/
appl::textPluginManager::connect(*this);
// last created has focus ...
setCurrentSelect();

View File

@ -37,8 +37,9 @@ namespace appl {
public:
TextViewer(const std::string& _fontName="", int32_t _fontSize=-1);
virtual ~TextViewer(void);
private:
public:
appl::Buffer* m_buffer; //!< pointer on the current buffer to display (can be null if the buffer is remover or in state of changing buffer)
private:
ewol::Text m_displayText; //!< Text display properties.
ewol::Drawing m_displayDrawing; //!< Other diaplay requested.
std::vector<std::pair<appl::Buffer*, vec2>> m_drawingRemenber;
@ -266,6 +267,21 @@ namespace appl {
}
return ret;
}
/**
* @brief Get the position of selection around (select word).
* @param[in] _pos Position to start the selection.
* @param[out] _beginPos Position where the element start.
* @param[out] _endPos Position where the element stop.
* @return true if we find a selection around.
*/
bool getPosAround(const appl::Buffer::Iterator& _pos,
appl::Buffer::Iterator &_beginPos,
appl::Buffer::Iterator &_endPos) {
if (m_buffer==NULL) {
return false;
}
return m_buffer->getPosAround(_pos, _beginPos, _endPos);
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator.

View File

@ -19,7 +19,7 @@ namespace appl {
friend class appl::TextViewer;
public:
TextViewerPlugin(void);
~TextViewerPlugin(void);
virtual ~TextViewerPlugin(void);
private:
bool m_isEnable; //!< The plugin is enable or not (for all viewer).
public:

View File

@ -0,0 +1,67 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginCtags.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginCtags"
appl::TextPluginCtags::TextPluginCtags(void) {
m_activateOnReceiveMessage = true;
}
const char* eventJumpDestination = "event-plugin-ctags-jump-destination";
const char* eventJumpBack = "event-plugin-ctags-jump-back";
void appl::TextPluginCtags::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(eventJumpDestination);
_textDrawer.ext_registerMultiCast(eventJumpBack);
_textDrawer.ext_shortCutAdd("ctrl+d", eventJumpDestination);
_textDrawer.ext_shortCutAdd("ctrl+shift+d", eventJumpBack);
}
void appl::TextPluginCtags::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginCtags::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == eventJumpDestination) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
std::string textToSearch;
if (_textDrawer.hasTextSelected() == true) {
_textDrawer.copy(textToSearch, _textDrawer.selectStart(), _textDrawer.selectStop() );
} else {
appl::Buffer::Iterator _beginPos;
appl::Buffer::Iterator _endPos;
if (_textDrawer.getPosAround(_textDrawer.cursor(), _beginPos, _endPos) == false) {
APPL_WARNING("Can not get data around...");
return true;
}
_textDrawer.copy(textToSearch, _beginPos, _endPos);
}
APPL_ERROR("CTAGS might search : '" << textToSearch << "'");
return true;
} else if (_msg.getMessage() == eventJumpBack) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
return true;
}
return false;
}

View File

@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_CTAGS_H__
#define __APPL_TEXT_PLUGIN_CTAGS_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginCtags : public appl::TextViewerPlugin {
public:
TextPluginCtags(void);
~TextPluginCtags(void) {
// nothing to do ...
};
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg);
};
};
#endif

View File

View File

@ -0,0 +1,149 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_DATA_H__
#define __APPL_TEXT_PLUGIN_DATA_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
template <typename TYPE> class TextViewerPluginData : public appl::TextViewerPlugin {
public:
TextViewerPluginData(void) {
// nothing to do ...
}
virtual ~TextViewerPluginData(void) {
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
if (m_specificData[iii].second != NULL) {
remove(*m_specificData[iii].second);
delete(m_specificData[iii].second);
m_specificData[iii].second = NULL;
}
}
m_specificData.clear();
}
private:
std::vector<std::pair<appl::Buffer* ,TYPE* >> m_specificData;
protected:
TYPE* getDataRef(appl::TextViewer& _textDrawer) {
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
APPL_DEBUG("compare " << (int64_t)m_specificData[iii].first << " && " << (int64_t)&_textDrawer);
if (m_specificData[iii].first == _textDrawer.m_buffer) {
APPL_DEBUG("find data : " << iii);
return m_specificData[iii].second;
}
}
TYPE* data = new TYPE();
if (data == NULL) {
return NULL;
}
m_specificData.push_back(std::make_pair(_textDrawer.m_buffer, data));
// create a new one ...
return data;
}
protected: // Wrap all element with their internal data: (do not use theses function)
void onPluginEnable(appl::TextViewer& _textDrawer) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return;
}
return onPluginEnable(_textDrawer, *data);
}
void onPluginDisable(appl::TextViewer& _textDrawer) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return;
}
return onPluginDisable(_textDrawer, *data);
}
bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onReceiveMessage(_textDrawer, _msg, *data);
}
bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onWrite(_textDrawer, _pos, _data, *data);
}
bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onReplace(_textDrawer, _pos, _data, _posEnd, *data);
}
bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onRemove(_textDrawer, _pos, _posEnd, *data);
}
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer,
TYPE& _data) {
return;
}
virtual void onPluginDisable(appl::TextViewer& _textDrawer,
TYPE& _data) {
return;
}
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg,
TYPE& _data) {
return false;
}
virtual bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
TYPE& _data) {
return false;
}
virtual bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
TYPE& _data) {
return false;
}
virtual bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd,
TYPE& _data) {
return false;
}
virtual void remove(TYPE& _data) {
return;
};
public:
virtual void onObjectRemove(ewol::EObject* _removeObject) {
// TODO : plop
};
};
};
#endif

View File

@ -22,11 +22,6 @@ appl::TextPluginHistory::TextPluginHistory(void) {
m_activateOnRemove = true;
}
appl::TextPluginHistory::~TextPluginHistory(void) {
clearUndo();
clearRedo();
};
void appl::TextPluginHistory::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(ednMsgGuiRedo);
@ -40,37 +35,38 @@ void appl::TextPluginHistory::onPluginDisable(appl::TextViewer& _textDrawer) {
}
bool appl::TextPluginHistory::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
const ewol::EMessage& _msg,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == ednMsgGuiRedo) {
if (m_redo.size() == 0) {
if (_data.m_redo.size() == 0) {
return true;
}
if (m_redo[m_redo.size()-1] == NULL) {
m_redo.pop_back();
if (_data.m_redo[_data.m_redo.size()-1] == NULL) {
_data.m_redo.pop_back();
return true;
}
appl::History *tmpElement = m_redo[m_redo.size()-1];
m_redo.pop_back();
m_undo.push_back(tmpElement);
appl::History *tmpElement = _data.m_redo[_data.m_redo.size()-1];
_data.m_redo.pop_back();
_data.m_undo.push_back(tmpElement);
_textDrawer.replaceDirect(tmpElement->m_addedText,
_textDrawer.position(tmpElement->m_posAdded),
_textDrawer.position(tmpElement->m_endPosRemoved) );
return true;
} else if (_msg.getMessage() == ednMsgGuiUndo) {
if (m_undo.size() == 0) {
if (_data.m_undo.size() == 0) {
return true;
}
if (m_undo[m_undo.size()-1] == NULL) {
m_undo.pop_back();
if (_data.m_undo[_data.m_undo.size()-1] == NULL) {
_data.m_undo.pop_back();
return true;
}
appl::History *tmpElement = m_undo[m_undo.size()-1];
m_undo.pop_back();
m_redo.push_back(tmpElement);
appl::History *tmpElement = _data.m_undo[_data.m_undo.size()-1];
_data.m_undo.pop_back();
_data.m_redo.push_back(tmpElement);
_textDrawer.replaceDirect(tmpElement->m_removedText,
_textDrawer.position(tmpElement->m_posAdded),
_textDrawer.position(tmpElement->m_endPosAdded) );
@ -80,52 +76,53 @@ bool appl::TextPluginHistory::onReceiveMessage(appl::TextViewer& _textDrawer,
return false;
}
void appl::TextPluginHistory::clearRedo(void) {
if (m_redo.size() == 0) {
void appl::TextPluginHistory::clearRedo(appl::PluginHistoryData& _data) {
if (_data.m_redo.size() == 0) {
return;
}
for (size_t iii=0; iii<m_redo.size(); ++iii) {
if (m_redo[iii] == NULL) {
for (size_t iii=0; iii<_data.m_redo.size(); ++iii) {
if (_data.m_redo[iii] == NULL) {
continue;
}
delete(m_redo[iii]);
m_redo[iii] = NULL;
delete(_data.m_redo[iii]);
_data.m_redo[iii] = NULL;
}
m_redo.clear();
_data.m_redo.clear();
}
void appl::TextPluginHistory::clearUndo(void) {
if (m_undo.size() == 0) {
void appl::TextPluginHistory::clearUndo(appl::PluginHistoryData& _data) {
if (_data.m_undo.size() == 0) {
return;
}
for (size_t iii=0; iii<m_undo.size(); ++iii) {
if (m_undo[iii] == NULL) {
for (size_t iii=0; iii<_data.m_undo.size(); ++iii) {
if (_data.m_undo[iii] == NULL) {
continue;
}
delete(m_undo[iii]);
m_undo[iii] = NULL;
delete(_data.m_undo[iii]);
_data.m_undo[iii] = NULL;
}
m_undo.clear();
_data.m_undo.clear();
}
bool appl::TextPluginHistory::onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data) {
const std::string& _strData,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
appl::History *tmpElement = new appl::History();
if (tmpElement != NULL) {
tmpElement->m_addedText = _data;
tmpElement->m_addedText = _strData;
tmpElement->m_posAdded = (int64_t)_pos;
tmpElement->m_endPosRemoved = (int64_t)_pos;
}
_textDrawer.writeDirect(_data, _pos);
_textDrawer.writeDirect(_strData, _pos);
if (tmpElement != NULL) {
tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor();
clearRedo();
m_undo.push_back(tmpElement);
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());
return true;
@ -133,23 +130,24 @@ bool appl::TextPluginHistory::onWrite(appl::TextViewer& _textDrawer,
bool appl::TextPluginHistory::onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd) {
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
appl::History *tmpElement = new appl::History();
if (tmpElement != NULL) {
tmpElement->m_posAdded = (int64_t)_pos;
tmpElement->m_addedText = _data;
tmpElement->m_addedText = _strData;
tmpElement->m_endPosRemoved = (int64_t)_posEnd;
_textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd);
}
_textDrawer.replaceDirect(_data, _pos, _posEnd);
_textDrawer.replaceDirect(_strData, _pos, _posEnd);
if (tmpElement != NULL) {
tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor();
clearRedo();
m_undo.push_back(tmpElement);
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());
return true;
@ -157,7 +155,8 @@ bool appl::TextPluginHistory::onReplace(appl::TextViewer& _textDrawer,
bool appl::TextPluginHistory::onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
@ -168,8 +167,8 @@ bool appl::TextPluginHistory::onRemove(appl::TextViewer& _textDrawer,
tmpElement->m_endPosAdded = tmpElement->m_posAdded;
tmpElement->m_endPosRemoved = (int64_t)_posEnd;
_textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd);
clearRedo();
m_undo.push_back(tmpElement);
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
_textDrawer.removeDirect();
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());

View File

@ -13,7 +13,7 @@
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
#include <appl/TextPluginData.h>
namespace appl {
class History {
@ -30,31 +30,42 @@ namespace appl {
int64_t m_endPosAdded;
int64_t m_endPosRemoved;
};
class TextPluginHistory : public appl::TextViewerPlugin {
class PluginHistoryData {
public:
TextPluginHistory(void);
~TextPluginHistory(void);
private:
std::vector<History*> m_undo; //!< History storing data
std::vector<History*> m_redo; //!< History storing data
};
class TextPluginHistory : public appl::TextViewerPluginData<appl::PluginHistoryData> {
public:
TextPluginHistory(void);
virtual ~TextPluginHistory(void) { };
private:
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg);
const ewol::EMessage& _msg,
appl::PluginHistoryData& _data);
virtual bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data);
const std::string& _strData,
appl::PluginHistoryData& _data);
virtual bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd);
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data);
virtual bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd);
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data);
virtual void remove(appl::PluginHistoryData& _data) {
clearRedo(_data);
clearUndo(_data);
}
private:
void clearRedo(void);
void clearUndo(void);
void clearRedo(appl::PluginHistoryData& _data);
void clearUndo(appl::PluginHistoryData& _data);
public:
virtual void onObjectRemove(ewol::EObject* _removeObject);
};

View File

@ -13,6 +13,8 @@
#include <appl/TextPluginAutoIndent.h>
#include <appl/TextPluginHistory.h>
#include <appl/TextPluginRmLine.h>
#include <appl/TextPluginSelectAll.h>
#include <appl/TextPluginCtags.h>
#undef __class__
#define __class__ "textPluginManager"
@ -80,6 +82,8 @@ void appl::textPluginManager::addDefaultPlugin(void) {
appl::textPluginManager::addPlugin(new appl::TextPluginAutoIndent());
appl::textPluginManager::addPlugin(new appl::TextPluginHistory());
appl::textPluginManager::addPlugin(new appl::TextPluginRmLine());
appl::textPluginManager::addPlugin(new appl::TextPluginSelectAll());
appl::textPluginManager::addPlugin(new appl::TextPluginCtags());
}
void appl::textPluginManager::addPlugin(appl::TextViewerPlugin* _plugin) {

View File

@ -0,0 +1,47 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginSelectAll.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginSelectAll"
appl::TextPluginSelectAll::TextPluginSelectAll(void) {
m_activateOnReceiveMessage = true;
}
static const char* eventSelectAll = "plugin-select-all";
void appl::TextPluginSelectAll::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(eventSelectAll);
_textDrawer.ext_shortCutAdd("ctrl+a", eventSelectAll);
}
void appl::TextPluginSelectAll::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginSelectAll::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == eventSelectAll) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
_textDrawer.select(_textDrawer.begin(), _textDrawer.end());
return true;
}
return false;
}

View File

@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_SELECT_ALL_H__
#define __APPL_TEXT_PLUGIN_SELECT_ALL_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginSelectAll : public appl::TextViewerPlugin {
public:
TextPluginSelectAll(void);
~TextPluginSelectAll(void) {
// nothing to do ...
};
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg);
};
};
#endif

View File

@ -41,6 +41,8 @@ def Create(target):
'appl/TextPluginAutoIndent.cpp',
'appl/TextPluginHistory.cpp',
'appl/TextPluginRmLine.cpp',
'appl/TextPluginSelectAll.cpp',
'appl/TextPluginCtags.cpp',
'appl/TextPluginManager.cpp'])
# Generic color management for the text editor :