[haiku-commits] r35731 - in haiku/trunk/src/kits: interface tracker

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 3 Mar 2010 01:02:02 +0100 (CET)

Author: anevilyak
Date: 2010-03-03 01:02:02 +0100 (Wed, 03 Mar 2010)
New Revision: 35731
Changeset: http://dev.haiku-os.org/changeset/35731/haiku

Modified:
   haiku/trunk/src/kits/interface/TextView.cpp
   haiku/trunk/src/kits/tracker/PoseView.cpp
Log:
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.



Modified: haiku/trunk/src/kits/interface/TextView.cpp
===================================================================
--- haiku/trunk/src/kits/interface/TextView.cpp 2010-03-02 22:30:40 UTC (rev 
35730)
+++ haiku/trunk/src/kits/interface/TextView.cpp 2010-03-03 00:02:02 UTC (rev 
35731)
@@ -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 @@
 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 @@
 
        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 @@
                }
 
                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;

Modified: haiku/trunk/src/kits/tracker/PoseView.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/PoseView.cpp   2010-03-02 22:30:40 UTC (rev 
35730)
+++ haiku/trunk/src/kits/tracker/PoseView.cpp   2010-03-03 00:02:02 UTC (rev 
35731)
@@ -103,8 +103,8 @@
 const uint32 kAddNewPoses = 'Tanp';
 const uint32 kAddPosesCompleted = 'Tapc';
 const int32 kMaxAddPosesChunk = 50;
-const uint32 kMaxTextClippingSize = 64 * 1024;
 
+
 namespace BPrivate {
 extern bool delete_point(void *);
        // TODO: exterminate this
@@ -6716,72 +6716,6 @@
 
        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;


Other related posts:

  • » [haiku-commits] r35731 - in haiku/trunk/src/kits: interface tracker - anevilyak