mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Added line copying to copy/cut/paste
This commit is contained in:
parent
9242cb0dc5
commit
d807049b9f
5 changed files with 124 additions and 65 deletions
|
@ -776,9 +776,20 @@ namespace Beefy
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool GetClipboardText(String outStr)
|
public virtual bool GetClipboardText(String outStr)
|
||||||
|
{
|
||||||
|
return GetClipboardTextData("text", outStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool GetClipboardText(String outStr, String extra)
|
||||||
|
{
|
||||||
|
GetClipboardTextData("bf_text", extra);
|
||||||
|
return GetClipboardTextData("text", outStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetClipboardTextData(String format, String outStr)
|
||||||
{
|
{
|
||||||
int32 aSize;
|
int32 aSize;
|
||||||
void* clipboardData = GetClipboardData("text", out aSize);
|
void* clipboardData = GetClipboardData(format, out aSize);
|
||||||
if (clipboardData == null)
|
if (clipboardData == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -792,10 +803,15 @@ namespace Beefy
|
||||||
BFApp_SetClipboardData(format, ptr, size, resetClipboard ? 1 : 0);
|
BFApp_SetClipboardData(format, ptr, size, resetClipboard ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetClipboardText(String text, String extra)
|
||||||
|
{
|
||||||
|
SetClipboardData("text", text.CStr(), (int32)text.Length + 1, true);
|
||||||
|
SetClipboardData("bf_text", extra.CStr(), (int32)extra.Length + 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SetClipboardText(String text)
|
public virtual void SetClipboardText(String text)
|
||||||
{
|
{
|
||||||
//IntPtr aPtr = Marshal.StringToCoTaskMemUni(text);
|
SetClipboardText(text, "");
|
||||||
SetClipboardData("text", text.CStr(), (int32)text.Length + 1, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if STUDIO_CLIENT
|
#if STUDIO_CLIENT
|
||||||
|
|
|
@ -2001,35 +2001,93 @@ namespace Beefy.widgets
|
||||||
InsertAtCursor(text);
|
InsertAtCursor(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CutText()
|
void CopyText(bool cut)
|
||||||
{
|
{
|
||||||
if (!CheckReadOnly())
|
if (!CheckReadOnly())
|
||||||
{
|
{
|
||||||
|
bool selectedLine = false;
|
||||||
|
String extra = scope .();
|
||||||
|
if (!HasSelection())
|
||||||
|
{
|
||||||
|
selectedLine = true;
|
||||||
|
GetLinePosition(CursorLineAndColumn.mLine, var lineStart, var lineEnd);
|
||||||
|
mSelection = .(lineStart, lineEnd);
|
||||||
|
extra.Append("line");
|
||||||
|
}
|
||||||
|
|
||||||
String selText = scope String();
|
String selText = scope String();
|
||||||
GetSelectionText(selText);
|
GetSelectionText(selText);
|
||||||
if (!selText.IsEmpty)
|
BFApp.sApp.SetClipboardText(selText, extra);
|
||||||
|
if (cut)
|
||||||
{
|
{
|
||||||
BFApp.sApp.SetClipboardText(selText);
|
if (selectedLine)
|
||||||
|
{
|
||||||
|
// Remove \n
|
||||||
|
if (mSelection.Value.mEndPos < mData.mTextLength)
|
||||||
|
mSelection.ValueRef.mEndPos++;
|
||||||
|
}
|
||||||
DeleteSelection();
|
DeleteSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedLine)
|
||||||
|
mSelection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CutText()
|
||||||
|
{
|
||||||
|
CopyText(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void CopyText()
|
public void CopyText()
|
||||||
{
|
{
|
||||||
String selText = scope String();
|
CopyText(false);
|
||||||
GetSelectionText(selText);
|
}
|
||||||
if (!selText.IsEmpty)
|
|
||||||
BFApp.sApp.SetClipboardText(selText);
|
public void PasteText(String text, String extra)
|
||||||
|
{
|
||||||
|
if (extra == "line")
|
||||||
|
{
|
||||||
|
UndoBatchStart undoBatchStart = new UndoBatchStart("paste");
|
||||||
|
mData.mUndoManager.Add(undoBatchStart);
|
||||||
|
var origPosition = CursorLineAndColumn;
|
||||||
|
CursorLineAndColumn = .(origPosition.mLine, 0);
|
||||||
|
var lineStartPosition = CursorLineAndColumn;
|
||||||
|
InsertAtCursor("\n");
|
||||||
|
CursorLineAndColumn = lineStartPosition;
|
||||||
|
CursorToLineStart(false);
|
||||||
|
|
||||||
|
// Adjust to requested column
|
||||||
|
if (CursorLineAndColumn.mColumn != 0)
|
||||||
|
{
|
||||||
|
for (let c in text.RawChars)
|
||||||
|
{
|
||||||
|
if (!c.IsWhiteSpace)
|
||||||
|
{
|
||||||
|
text.Remove(0, @c.Index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PasteText(text);
|
||||||
|
CursorLineAndColumn = origPosition;
|
||||||
|
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
PasteText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PasteText()
|
public void PasteText()
|
||||||
{
|
{
|
||||||
String aText = scope String();
|
String aText = scope String();
|
||||||
BFApp.sApp.GetClipboardText(aText);
|
String extra = scope .();
|
||||||
|
BFApp.sApp.GetClipboardText(aText, extra);
|
||||||
aText.Replace("\r", "");
|
aText.Replace("\r", "");
|
||||||
if ((aText != null) && (!CheckReadOnly()))
|
if ((aText != null) && (!CheckReadOnly()))
|
||||||
PasteText(aText);
|
{
|
||||||
|
PasteText(aText, extra);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SelectLeft(int lineIdx, int lineChar, bool isChunkMove, bool isWordMove)
|
protected void SelectLeft(int lineIdx, int lineChar, bool isChunkMove, bool isWordMove)
|
||||||
|
|
|
@ -1528,25 +1528,22 @@ uint32 WinBFApp::GetClipboardFormat(const StringImpl& format)
|
||||||
else if (format == "atext")
|
else if (format == "atext")
|
||||||
return CF_TEXT;
|
return CF_TEXT;
|
||||||
|
|
||||||
// StringToUIntMap::iterator itr = mClipboardFormatMap.find(format);
|
|
||||||
// if (itr != mClipboardFormatMap.end())
|
|
||||||
// return itr->second;
|
|
||||||
|
|
||||||
uint32 aFormat;
|
uint32 aFormat;
|
||||||
if (mClipboardFormatMap.TryGetValue(format, &aFormat))
|
if (mClipboardFormatMap.TryGetValue(format, &aFormat))
|
||||||
return aFormat;
|
return aFormat;
|
||||||
|
|
||||||
String sysFormatName = "BF_" + format;
|
aFormat = ::RegisterClipboardFormatA(format.c_str());
|
||||||
aFormat = ::RegisterClipboardFormatA(sysFormatName.c_str());
|
mClipboardFormatMap[format] = aFormat;
|
||||||
mClipboardFormatMap[sysFormatName] = aFormat;
|
|
||||||
return aFormat;
|
return aFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String gClipboardData;
|
||||||
|
|
||||||
void* WinBFApp::GetClipboardData(const StringImpl& format, int* size)
|
void* WinBFApp::GetClipboardData(const StringImpl& format, int* size)
|
||||||
{
|
{
|
||||||
HWND aWindow = NULL;
|
HWND aWindow = NULL;
|
||||||
if (!mWindowList.empty())
|
if (!mWindowList.empty())
|
||||||
aWindow = ((WinBFWindow*) mWindowList.front())->mHWnd;
|
aWindow = ((WinBFWindow*)mWindowList.front())->mHWnd;
|
||||||
|
|
||||||
uint32 aFormat = GetClipboardFormat(format);
|
uint32 aFormat = GetClipboardFormat(format);
|
||||||
|
|
||||||
|
@ -1555,22 +1552,14 @@ void* WinBFApp::GetClipboardData(const StringImpl& format, int* size)
|
||||||
if (OpenClipboard(aWindow))
|
if (OpenClipboard(aWindow))
|
||||||
{
|
{
|
||||||
HGLOBAL globalHandle = ::GetClipboardData(aFormat);
|
HGLOBAL globalHandle = ::GetClipboardData(aFormat);
|
||||||
|
|
||||||
if (globalHandle == NULL)
|
if (globalHandle == NULL)
|
||||||
{
|
{
|
||||||
if (format == "text")
|
if (aFormat == CF_UNICODETEXT)
|
||||||
{
|
{
|
||||||
int aSize = 0;
|
|
||||||
char* charPtr = (char*) GetClipboardData("atext", &aSize);
|
|
||||||
if (charPtr == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*size = (int)::GlobalSize(globalHandle);
|
|
||||||
void* aPtr = ::GlobalLock(globalHandle);
|
|
||||||
|
|
||||||
mLockedHGlobalMap[aPtr] = globalHandle;
|
|
||||||
|
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
return aPtr;
|
// Return ascii text
|
||||||
|
return (char*)GetClipboardData("atext", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
|
@ -1581,11 +1570,20 @@ void* WinBFApp::GetClipboardData(const StringImpl& format, int* size)
|
||||||
*size = (int)::GlobalSize(globalHandle);
|
*size = (int)::GlobalSize(globalHandle);
|
||||||
void* aPtr = ::GlobalLock(globalHandle);
|
void* aPtr = ::GlobalLock(globalHandle);
|
||||||
|
|
||||||
static String utf8String;
|
if (aFormat == CF_UNICODETEXT)
|
||||||
utf8String = UTF8Encode((WCHAR*)aPtr);
|
{
|
||||||
|
gClipboardData = UTF8Encode((WCHAR*)aPtr);
|
||||||
|
*size = (int)gClipboardData.length() + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gClipboardData.Clear();
|
||||||
|
gClipboardData.Insert(0, (char*)aPtr, *size);
|
||||||
|
}
|
||||||
|
|
||||||
::GlobalUnlock(globalHandle);
|
::GlobalUnlock(globalHandle);
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
return (void*)utf8String.c_str();
|
return (void*)gClipboardData.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1595,11 +1593,7 @@ void* WinBFApp::GetClipboardData(const StringImpl& format, int* size)
|
||||||
|
|
||||||
void WinBFApp::ReleaseClipboardData(void* ptr)
|
void WinBFApp::ReleaseClipboardData(void* ptr)
|
||||||
{
|
{
|
||||||
HGLOBAL globalHandle;
|
|
||||||
if (mLockedHGlobalMap.Remove(ptr, &globalHandle))
|
|
||||||
{
|
|
||||||
::GlobalUnlock(globalHandle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int size, bool resetClipboard)
|
void WinBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int size, bool resetClipboard)
|
||||||
|
@ -1638,25 +1632,18 @@ void WinBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int s
|
||||||
GlobalUnlock(globalHandle);
|
GlobalUnlock(globalHandle);
|
||||||
::SetClipboardData(CF_UNICODETEXT, globalHandle);
|
::SetClipboardData(CF_UNICODETEXT, globalHandle);
|
||||||
}
|
}
|
||||||
else if (format == "atext")
|
else
|
||||||
{
|
{
|
||||||
HGLOBAL globalHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
|
HGLOBAL globalHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
|
||||||
char* data = (char*)GlobalLock(globalHandle);
|
char* data = (char*)GlobalLock(globalHandle);
|
||||||
memcpy(data, ptr, size);
|
memcpy(data, ptr, size);
|
||||||
GlobalUnlock(globalHandle);
|
GlobalUnlock(globalHandle);
|
||||||
::SetClipboardData(CF_TEXT, globalHandle);
|
::SetClipboardData(aFormat, globalHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (format == "text")
|
|
||||||
{
|
|
||||||
//String aString = ToString((const WCHAR*) ptr);
|
|
||||||
String aString = (const char*)ptr;
|
|
||||||
SetClipboardData("atext", aString.c_str(), (int)aString.length() + 1, false);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BFMenu* WinBFWindow::AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* sysBitmap, bool enabled, int checkState, bool radioCheck)
|
BFMenu* WinBFWindow::AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* sysBitmap, bool enabled, int checkState, bool radioCheck)
|
||||||
|
|
|
@ -88,7 +88,6 @@ class WinBFApp : public BFApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool mInMsgProc;
|
bool mInMsgProc;
|
||||||
PtrToHGlobalMap mLockedHGlobalMap;
|
|
||||||
StringToUIntMap mClipboardFormatMap;
|
StringToUIntMap mClipboardFormatMap;
|
||||||
DSoundManager* mDSoundManager;
|
DSoundManager* mDSoundManager;
|
||||||
|
|
||||||
|
|
|
@ -2132,9 +2132,8 @@ namespace IDE.ui
|
||||||
var str = scope String();
|
var str = scope String();
|
||||||
GetLineText(lineNum, str);
|
GetLineText(lineNum, str);
|
||||||
mSelection = null;
|
mSelection = null;
|
||||||
str.Append("\n");
|
|
||||||
CursorLineAndColumn = LineAndColumn(lineNum, 0);
|
CursorLineAndColumn = LineAndColumn(lineNum, 0);
|
||||||
InsertAtCursor(str);
|
PasteText(str, "line");
|
||||||
CursorLineAndColumn = LineAndColumn(prevCursorLineAndColumn.mLine + 1, prevCursorLineAndColumn.mColumn);
|
CursorLineAndColumn = LineAndColumn(prevCursorLineAndColumn.mLine + 1, prevCursorLineAndColumn.mColumn);
|
||||||
|
|
||||||
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
|
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue