Remove Tracker's special DnD handling. Instead, BTextView/BTextControl now
honors drag messages containing entry refs and resolves the path of the first one contained. Will work on a more sophisticated solution that would allow optionally extracting the file text instead via right click drag context menu when I have more time. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35731 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f435abb00a
commit
7c0f5738b3
@ -32,9 +32,11 @@
|
||||
#include <Bitmap.h>
|
||||
#include <Clipboard.h>
|
||||
#include <Debug.h>
|
||||
#include <Entry.h>
|
||||
#include <Input.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Path.h>
|
||||
#include <PropertyInfo.h>
|
||||
#include <Region.h>
|
||||
#include <ScrollBar.h>
|
||||
@ -1481,7 +1483,8 @@ BTextView::AcceptsPaste(BClipboard *clipboard)
|
||||
bool
|
||||
BTextView::AcceptsDrop(const BMessage *inMessage)
|
||||
{
|
||||
if (fEditable && inMessage && inMessage->HasData("text/plain", B_MIME_TYPE))
|
||||
if (fEditable && inMessage && (inMessage->HasData("text/plain", B_MIME_TYPE)
|
||||
|| inMessage->HasData("refs", B_REF_TYPE)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -4808,6 +4811,7 @@ BTextView::_MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
|
||||
|
||||
ssize_t dataLen = 0;
|
||||
const char *text = NULL;
|
||||
entry_ref ref;
|
||||
if (inMessage->FindData("text/plain", B_MIME_TYPE, (const void **)&text,
|
||||
&dataLen) == B_OK) {
|
||||
text_run_array *runArray = NULL;
|
||||
@ -4829,6 +4833,9 @@ BTextView::_MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
|
||||
}
|
||||
|
||||
Insert(dropOffset, text, dataLen, runArray);
|
||||
} else if (inMessage->FindRef("refs", &ref) == B_OK) {
|
||||
BPath path(&ref);
|
||||
Insert(dropOffset, path.Path(), strlen(path.Path()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -103,7 +103,7 @@ const float kCountViewWidth = 76;
|
||||
const uint32 kAddNewPoses = 'Tanp';
|
||||
const uint32 kAddPosesCompleted = 'Tapc';
|
||||
const int32 kMaxAddPosesChunk = 50;
|
||||
const uint32 kMaxTextClippingSize = 64 * 1024;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
extern bool delete_point(void *);
|
||||
@ -6716,72 +6716,6 @@ BPoseView::DragSelectedPoses(const BPose *pose, BPoint clickPoint)
|
||||
|
||||
EachPoseAndModel(fSelectionList, &AddPoseRefToMessage, &message);
|
||||
|
||||
// do any special drag&drop handling
|
||||
if (fSelectionList->CountItems() == 1) {
|
||||
// for now just recognize text clipping files
|
||||
|
||||
BFile file(fSelectionList->ItemAt(0)->TargetModel()->EntryRef(), O_RDONLY);
|
||||
if (file.InitCheck() == B_OK) {
|
||||
BNodeInfo info(&file);
|
||||
char type[B_MIME_TYPE_LENGTH];
|
||||
type[0] = '\0';
|
||||
|
||||
info.GetType(type);
|
||||
|
||||
int32 tmp;
|
||||
if (strcasecmp(type, kPlainTextMimeType) == 0) {
|
||||
// got a text file
|
||||
|
||||
|
||||
file.Seek(0, SEEK_SET);
|
||||
off_t size = 0;
|
||||
file.GetSize(&size);
|
||||
if (size) {
|
||||
// clamp the amount of text we extract in order to avoid very unpleasant surprises if, say, the user
|
||||
// happens to have a 100MB plain text file they want to drag around.
|
||||
size = min(size, (off_t)kMaxTextClippingSize);
|
||||
char *buffer = new char[size];
|
||||
if (file.Read(buffer, (size_t)size) == size) {
|
||||
message.AddData(kPlainTextMimeType, B_MIME_TYPE, buffer, (ssize_t)size);
|
||||
// add text into drag message
|
||||
|
||||
attr_info attrInfo;
|
||||
if (file.GetAttrInfo("styles", &attrInfo) == B_OK
|
||||
&& attrInfo.size > 0) {
|
||||
char *data = new char [attrInfo.size];
|
||||
file.ReadAttr("styles", B_RAW_TYPE, 0, data, (size_t)attrInfo.size);
|
||||
int32 textRunSize;
|
||||
text_run_array *textRuns = BTextView::UnflattenRunArray(data,
|
||||
&textRunSize);
|
||||
delete [] data;
|
||||
message.AddData("application/x-vnd.Be-text_run_array",
|
||||
B_MIME_TYPE, textRuns, textRunSize);
|
||||
free(textRuns);
|
||||
}
|
||||
}
|
||||
delete [] buffer;
|
||||
}
|
||||
} else if (strcasecmp(type, kBitmapMimeType) == 0
|
||||
// got a raw bitmap clipping file
|
||||
&& file.ReadAttr(kAttrClippingFile, B_RAW_TYPE, 0,
|
||||
&tmp, sizeof(int32)) == sizeof(int32)) {
|
||||
file.Seek(0, SEEK_SET);
|
||||
off_t size = 0;
|
||||
file.GetSize(&size);
|
||||
if (size) {
|
||||
char *buffer = new char[size];
|
||||
if (file.Read(buffer, (size_t)size) == size) {
|
||||
BMessage embeddedBitmap;
|
||||
if (embeddedBitmap.Unflatten(buffer) == B_OK)
|
||||
message.AddMessage(kBitmapMimeType, &embeddedBitmap);
|
||||
// add bitmap into drag message
|
||||
}
|
||||
delete [] buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// make sure button is still down
|
||||
uint32 button;
|
||||
BPoint tempLoc;
|
||||
|
Loading…
Reference in New Issue
Block a user