Copy/cut/paste is back

This commit is contained in:
Edouard Dupin 2012-04-05 16:16:08 +02:00
parent c75fb80736
commit 5e86641caf
7 changed files with 98 additions and 129 deletions

View File

@ -589,6 +589,7 @@ void BufferText::MouseSelectFromCursorTo(int32_t fontId, int32_t width, int32_t
m_EdnBuf.Select(SELECTION_PRIMARY, selStart, m_cursorPos);
}
}
Copy(ewol::clipBoard::CLIPBOARD_SELECTION);
RequestPositionUpdate();
}
@ -609,6 +610,7 @@ void BufferText::MouseEventDouble(void)
m_EdnBuf.Select(SELECTION_PRIMARY, beginPos, endPos);
m_cursorPos = endPos;
}
Copy(ewol::clipBoard::CLIPBOARD_SELECTION);
// no else
}
@ -624,6 +626,7 @@ void BufferText::MouseEventTriple(void)
{
m_EdnBuf.Select(SELECTION_PRIMARY, m_EdnBuf.StartOfLine(m_cursorPos), m_EdnBuf.EndOfLine(m_cursorPos));
m_cursorPos = m_EdnBuf.EndOfLine(m_cursorPos);
Copy(ewol::clipBoard::CLIPBOARD_SELECTION);
}
void BufferText::RemoveLine(void)
@ -632,13 +635,14 @@ void BufferText::RemoveLine(void)
int32_t stop = m_EdnBuf.EndOfLine(m_cursorPos);
m_EdnBuf.Remove(start, stop+1);
SetInsertPosition(start);
SetModify(true);
SetModify(true);
}
void BufferText::SelectAll(void)
{
m_EdnBuf.Select(SELECTION_PRIMARY, 0, m_EdnBuf.Size());
m_cursorPos = m_EdnBuf.Size();
Copy(ewol::clipBoard::CLIPBOARD_SELECTION);
}
void BufferText::SelectNone(void)
@ -1161,10 +1165,8 @@ void BufferText::Replace(etk::UString &data)
bool haveSelectionActive = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, SelectionStart, SelectionEnd, SelectionIsRect, SelectionRectStart, SelectionRectEnd);
if (true == haveSelectionActive) {
// Replace Data :
etk::VectorType<uniChar_t> myData = data.GetVector();
EDN_TODO("Remove for now ...");
//m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, myData);
//SetInsertPosition(SelectionStart + myData.Size());
int32_t size = m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, data);
SetInsertPosition(SelectionStart + size);
}
SetModify(true);
}
@ -1180,16 +1182,13 @@ void BufferText::Replace(etk::UString &data)
*/
void BufferText::Copy(int8_t clipboardID)
{
//etk::VectorType<uniChar_t> mVect;
etk::UString mVect;
// get the curent selected data
if (true == m_EdnBuf.SelectHasSelection(SELECTION_PRIMARY) ) {
m_EdnBuf.GetSelectionText(SELECTION_PRIMARY, mVect);
EDN_TODO("Remove for now ...");
}
// copy data in the click board :
ewol::clipBoard::Set(clipboardID, mVect);
EDN_TODO("Remove for now ...");
}
@ -1231,10 +1230,7 @@ void BufferText::Cut(int8_t clipboardID)
*/
void BufferText::Paste(int8_t clipboardID)
{
//etk::VectorType<uniChar_t> mVect;
etk::UString mVect;
EDN_TODO("Remove for now ...");
/*
// copy data from the click board :
ewol::clipBoard::Get(clipboardID, mVect);
@ -1244,14 +1240,13 @@ void BufferText::Paste(int8_t clipboardID)
if (true == haveSelectionActive ) {
// replace data
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, mVect );
m_cursorPos = SelectionStart + mVect.Size();
int32_t size = m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, mVect );
m_cursorPos = SelectionStart + size;
} else {
// insert data
m_EdnBuf.Insert(m_cursorPos, mVect);
m_cursorPos += mVect.Size();
int32_t size = m_EdnBuf.Insert(m_cursorPos, mVect);
m_cursorPos += size;
}
*/
RequestPositionUpdate();
SetModify(true);
}

View File

@ -32,7 +32,6 @@
#include <BufferManager.h>
#include <ColorizeManager.h>
#include <HighlightManager.h>
#include <ClipBoard.h>
#include <Gui/Search.h>
#include <unistd.h>
#include <readtags.h>
@ -83,7 +82,6 @@ void APP_Init(void)
// init internal global value
globals::init();
ClipBoard::Init();
// init ALL Singleton :

View File

@ -23,79 +23,4 @@
*******************************************************************************
*/
#include <tools_globals.h>
#include <ClipBoard.h>
#undef __class__
#define __class__ "ClipBoard"
#include <etk/VectorType.h>
/*
note: la copy dans le :
0 : copy standard
[1..9] : copy interne
10 : bouton du milieux
*/
static etk::VectorType<int8_t> mesCopy[TOTAL_OF_CLICKBOARD];
void ClipBoard::Init(void)
{
EDN_INFO("Initialyse ClipBoards");
for(int32_t i=0; i<TOTAL_OF_CLICKBOARD; i++) {
mesCopy[i].Clear();
}
}
void ClipBoard::Set(uint8_t clipboardID, etk::VectorType<int8_t> &data)
{
// check if ID is correct
if(clipboardID >= TOTAL_OF_CLICKBOARD) {
EDN_WARNING("request ClickBoard id error");
} else if(0 == data.Size()) {
EDN_INFO("request a copy of nothing");
} else if (COPY_STD == clipboardID) {
//GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
//gtk_clipboard_set_text(clipboard, (const gchar*)&data[0], data.Size() );
} else if (COPY_MIDDLE_BUTTON == clipboardID) {
//GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
//gtk_clipboard_set_text(clipboard, (const gchar*)&data[0], data.Size() );
}
// Copy datas ...
mesCopy[clipboardID] = data;
}
void ClipBoard::Get(uint8_t clipboardID, etk::VectorType<int8_t> &data)
{
if(clipboardID >= TOTAL_OF_CLICKBOARD) {
EDN_WARNING("request ClickBoard id error");
} else if (COPY_STD == clipboardID) {
/*
GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD );
gchar *text = gtk_clipboard_wait_for_text(clipboard);
if (text != NULL) {
mesCopy[COPY_STD].Clear();
mesCopy[COPY_STD].PushBack((int8_t*)text, strlen(text) );
}
*/
} else if (COPY_MIDDLE_BUTTON == clipboardID) {
/*
GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY );
gchar *text = gtk_clipboard_wait_for_text(clipboard);
if (text != NULL) {
mesCopy[COPY_MIDDLE_BUTTON].Clear();
mesCopy[COPY_MIDDLE_BUTTON].PushBack((int8_t*)text, strlen(text) );
}
*/
}
// Copy datas ...
data = mesCopy[clipboardID];
}

View File

@ -26,19 +26,6 @@
#ifndef __CLIP_BOARD_H__
#define __CLIP_BOARD_H__
#include "tools_debug.h"
#include "etk/VectorType.h"
#define TOTAL_OF_CLICKBOARD (11)
#define COPY_MIDDLE_BUTTON (10)
#define COPY_STD (0)
namespace ClipBoard
{
void Init(void);
void Set(uint8_t clipboardID, etk::VectorType<int8_t> &data);
void Get(uint8_t clipboardID, etk::VectorType<int8_t> &data);
}
#endif

View File

@ -164,15 +164,23 @@ void EdnBuf::GetRange(int32_t start, int32_t end, etk::VectorType<int8_t> &outpu
//EDN_DEBUG("request start=" << start << " end="<< end << " size="<< end-start << " result size=" << output.Size() );
}
void EdnBuf::GetRange(int32_t start, int32_t end, etk::Ustring &output)
void EdnBuf::GetRange(int32_t start, int32_t end, etk::UString &output)
{
// Remove all data ...
output = "";
// import data :
etk::VectorType<int8_t> &localOutput;
etk::VectorType<int8_t> localOutput;
m_data.Get(start, end-start, localOutput);
// transcript in UNICODE ...
// TODO : ldkjqlsdjfqslkjd
if (true == m_isUtf8) {
localOutput.PushBack('\0');
output = (char*)&localOutput[0];
} else {
etk::VectorType<uniChar_t> tmpUnicodeData;
// transform in unicode :
convertIsoToUnicode(m_charsetType, localOutput, tmpUnicodeData);
output = tmpUnicodeData;
}
//EDN_DEBUG("request start=" << start << " end="<< end << " size="<< end-start << " result size=" << output.Size() );
}
@ -201,18 +209,30 @@ int8_t EdnBuf::operator[] (int32_t pos)
* @return ---
*
*/
void EdnBuf::Insert(int32_t pos, etk::VectorType<int8_t> &insertText)
int32_t EdnBuf::Insert(int32_t pos, etk::VectorType<int8_t> &insertText)
{
// if pos is not contiguous to existing text, make it
pos = edn_average(0, pos, m_data.Size() );
// insert Data
insert(pos, insertText);
int32_t sizeInsert=LocalInsert(pos, insertText);
// Call the redisplay ...
etk::VectorType<int8_t> deletedText;
eventModification(pos, insertText.Size(), deletedText);
return sizeInsert;
}
int32_t EdnBuf::Insert(int32_t pos, etk::UString &insertText)
{
// if pos is not contiguous to existing text, make it
pos = edn_average(0, pos, m_data.Size() );
// insert Data
int32_t sizeInsert=LocalInsert(pos, insertText);
// Call the redisplay ...
etk::VectorType<int8_t> deletedText;
eventModification(pos, insertText.Size(), deletedText);
return sizeInsert;
}
/**
* @brief Replace data in the buffer
@ -221,27 +241,46 @@ void EdnBuf::Insert(int32_t pos, etk::VectorType<int8_t> &insertText)
* @param[in] end Position ended in the buffer
* @param[in] insertText Test to set in the range [start..end]
*
* @return ---
* @return nb Octet inserted
*
*/
void EdnBuf::Replace(int32_t start, int32_t end, etk::VectorType<int8_t> &insertText)
int32_t EdnBuf::Replace(int32_t start, int32_t end, etk::VectorType<int8_t> &insertText)
{
etk::VectorType<int8_t> deletedText;
GetRange(start, end, deletedText);
m_data.Replace(start, end-start, insertText);
// update internal elements
eventModification(start, insertText.Size(), deletedText);
return insertText.Size();
}
void EdnBuf::Replace(int32_t start, int32_t end, etk::UString &insertText)
int32_t EdnBuf::Replace(int32_t start, int32_t end, etk::UString &insertText)
{
etk::VectorType<int8_t> deletedText;
GetRange(start, end, deletedText);
etk::VectorType<int8_t> tmpInsertText;
insertText
// TODO : Unicode to utf8 ...
if (true == m_isUtf8) {
char * tmpPointer = insertText.Utf8Data();
while (*tmpPointer != '\0') {
tmpInsertText.PushBack(*tmpPointer++);
}
} else {
etk::VectorType<unsigned int> tmppp = insertText.GetVector();
convertUnicodeToIso(m_charsetType, tmppp, tmpInsertText);
}
if (tmpInsertText.Size()>0) {
if (tmpInsertText[tmpInsertText.Size()-1] == '\0') {
tmpInsertText.PopBack();
}
}
if (tmpInsertText.Size()>0) {
if (tmpInsertText[tmpInsertText.Size()-1] == '\0') {
tmpInsertText.PopBack();
}
}
m_data.Replace(start, end-start, tmpInsertText);
// update internal elements
eventModification(start, tmpInsertText.Size(), deletedText);
return tmpInsertText.Size();
}
@ -1113,7 +1152,7 @@ bool EdnBuf::SelectAround(int32_t startPos, int32_t &beginPos, int32_t &endPos)
* @return number of element inserted.
*
*/
int32_t EdnBuf::insert(int32_t pos, etk::VectorType<int8_t> &insertText)
int32_t EdnBuf::LocalInsert(int32_t pos, etk::VectorType<int8_t> &insertText)
{
// Insert data in buffer
m_data.Insert(pos, insertText);
@ -1122,6 +1161,25 @@ int32_t EdnBuf::insert(int32_t pos, etk::VectorType<int8_t> &insertText)
// return the number of element inserted ...
return insertText.Size();
}
int32_t EdnBuf::LocalInsert(int32_t pos, etk::UString &insertText)
{
etk::VectorType<int8_t> tmpInsertText;
if (true == m_isUtf8) {
char * tmpPointer = insertText.Utf8Data();
while (*tmpPointer != '\0') {
tmpInsertText.PushBack(*tmpPointer++);
}
} else {
etk::VectorType<unsigned int> tmppp = insertText.GetVector();
convertUnicodeToIso(m_charsetType, tmppp, tmpInsertText);
}
if (tmpInsertText.Size()>0) {
if (tmpInsertText[tmpInsertText.Size()-1] == '\0') {
tmpInsertText.PopBack();
}
}
return LocalInsert(pos, tmpInsertText);
}
/**

View File

@ -90,9 +90,10 @@ class EdnBuf {
bool DumpFrom( FILE *myFile);
// replace with operator [] ...
int8_t operator[] (int32_t);
void Insert( int32_t pos, etk::VectorType<int8_t> &insertText);
void Insert( int32_t pos, etk::UString &insertText);
void Replace( int32_t start, int32_t end, etk::UString &insertText);
int32_t Insert( int32_t pos, etk::VectorType<int8_t> &insertText);
int32_t Insert( int32_t pos, etk::UString &insertText);
int32_t Replace( int32_t start, int32_t end, etk::VectorType<int8_t> &insertText);
int32_t Replace( int32_t start, int32_t end, etk::UString &insertText);
void Remove( int32_t start, int32_t end);
int32_t Indent( selectionType_te select);
int32_t UnIndent( selectionType_te select);
@ -136,8 +137,8 @@ class EdnBuf {
void GetSelectionText( selectionType_te select, etk::VectorType<int8_t> &text);
void GetSelectionText( selectionType_te select, etk::UString &text);
void RemoveSelected( selectionType_te select);
void ReplaceSelected( selectionType_te select, etk::VectorType<int8_t> &text);
void ReplaceSelected( selectionType_te select, etk::UString &text);
int32_t ReplaceSelected( selectionType_te select, etk::VectorType<int8_t> &text);
int32_t ReplaceSelected( selectionType_te select, etk::UString &text);
private:
// current selection of the buffer
selection m_selectionList[SELECTION_SIZE]; //!< Selection area of the buffer
@ -208,7 +209,8 @@ class EdnBuf {
void eventModification( int32_t pos, int32_t nInserted, etk::VectorType<int8_t> &deletedText);
int32_t insert( int32_t pos, etk::VectorType<int8_t> &insertText);
int32_t LocalInsert( int32_t pos, etk::VectorType<int8_t> &insertText);
int32_t LocalInsert( int32_t pos, etk::UString &insertText);
bool charMatch( char first, char second, bool caseSensitive = true);
};

View File

@ -220,7 +220,7 @@ void EdnBuf::RemoveSelected(selectionType_te select)
* @return ---
*
*/
void EdnBuf::ReplaceSelected(selectionType_te select, etk::VectorType<int8_t> &text)
int32_t EdnBuf::ReplaceSelected(selectionType_te select, etk::VectorType<int8_t> &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
@ -228,19 +228,21 @@ void EdnBuf::ReplaceSelected(selectionType_te select, etk::VectorType<int8_t> &t
// No data selected ...
if (false == isSelected) {
return;
return 0;
}
int32_t returnSize = 0;
// Rectangular selection
if (true == isRect) {
//ReplaceRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
Replace(start, end, text);
returnSize = Replace(start, end, text);
}
// Clean selection
m_selectionList[select].selected = false;
return returnSize;
}
void EdnBuf::ReplaceSelected(selectionType_te select, etk::UString &text)
int32_t EdnBuf::ReplaceSelected(selectionType_te select, etk::UString &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
@ -248,17 +250,19 @@ void EdnBuf::ReplaceSelected(selectionType_te select, etk::UString &text)
// No data selected ...
if (false == isSelected) {
return;
return 0;
}
int32_t returnSize = 0;
// Rectangular selection
if (true == isRect) {
//ReplaceRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
Replace(start, end, text);
returnSize = Replace(start, end, text);
}
// Clean selection
m_selectionList[select].selected = false;
return returnSize;
}