[haiku-webkit-commits] r470 - webkit/trunk/WebKit/haiku/WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Sat, 01 May 2010 19:20:53 +0000

Author: stippi
Date: Sat May  1 19:20:53 2010
New Revision: 470
URL: http://mmlr.dyndns.org/changeset/470

Log:
Add a context menu to the download progress view. It allows to open the
containing folder (and selects the file in it), and to copy the download URL
to the clipboard.

Modified:
   webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.cpp
   webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.h

Modified: webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.cpp      Sat May 
 1 18:07:40 2010        (r469)
+++ webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.cpp      Sat May 
 1 19:20:53 2010        (r470)
@@ -32,12 +32,15 @@
 #include <Alert.h>
 #include <Bitmap.h>
 #include <Button.h>
+#include <Clipboard.h>
 #include <Directory.h>
 #include <Entry.h>
 #include <FindDirectory.h>
 #include <GroupLayoutBuilder.h>
+#include <MenuItem.h>
 #include <NodeInfo.h>
 #include <NodeMonitor.h>
+#include <PopUpMenu.h>
 #include <Roster.h>
 #include <SpaceLayoutItem.h>
 #include <StatusBar.h>
@@ -49,10 +52,12 @@
 
 
 enum {
-       OPEN_DOWNLOAD = 'opdn',
-       RESTART_DOWNLOAD = 'rsdn',
-       CANCEL_DOWNLOAD = 'cndn',
-       REMOVE_DOWNLOAD = 'rmdn',
+       OPEN_DOWNLOAD                   = 'opdn',
+       RESTART_DOWNLOAD                = 'rsdn',
+       CANCEL_DOWNLOAD                 = 'cndn',
+       REMOVE_DOWNLOAD                 = 'rmdn',
+       COPY_URL_TO_CLIPBOARD   = 'curl',
+       OPEN_CONTAINING_FOLDER  = 'opfd',
 };
 
 const bigtime_t kMaxUpdateInterval = 100000LL;
@@ -203,6 +208,10 @@
 bool
 DownloadProgressView::Init(BMessage* archive)
 {
+       // We need to receive mouse events even for the areas of children views,
+       // so we can pop up a context menu.
+       SetEventMask(B_POINTER_EVENTS);
+
        fCurrentSize = 0;
        fExpectedSize = 0;
        fLastUpdateTime = 0;
@@ -331,6 +340,35 @@
 
 
 void
+DownloadProgressView::MouseDown(BPoint where)
+{
+       if (!Bounds().Contains(where))
+               return;
+
+       int32 buttons;
+       if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK)
+               return;
+
+       if ((buttons & B_SECONDARY_MOUSE_BUTTON) == 0)
+               return;
+
+       where = ConvertToScreen(where) + BPoint(2, 2);
+
+       BPopUpMenu* contextMenu = new BPopUpMenu("download context");
+       BMenuItem* copyURL = new BMenuItem("Copy URL to clipboard",
+               new BMessage(COPY_URL_TO_CLIPBOARD));
+       copyURL->SetEnabled(fURL.Length() > 0);
+       contextMenu->AddItem(copyURL);
+       BMenuItem* openFolder = new BMenuItem("Open containing folder",
+               new BMessage(OPEN_CONTAINING_FOLDER));
+       contextMenu->AddItem(openFolder);
+
+       contextMenu->SetTargetForItems(this);
+       contextMenu->Go(where, true, true, true);
+}
+
+
+void
 DownloadProgressView::Draw(BRect updateRect)
 {
        BRect bounds(Bounds());
@@ -477,6 +515,71 @@
                        }
                        break;
                }
+
+               // Context menu messages
+               case COPY_URL_TO_CLIPBOARD:
+                       if (be_clipboard->Lock()) {
+                               BMessage* data = be_clipboard->Data();
+                               if (data != NULL) {
+                                       be_clipboard->Clear();
+                                       data->AddData("text/plain", 
B_MIME_TYPE, fURL.String(),
+                                               fURL.Length());
+                               }
+                               be_clipboard->Commit();
+                               be_clipboard->Unlock();
+                       }
+                       break;
+               case OPEN_CONTAINING_FOLDER:
+                       if (fPath.InitCheck() == B_OK) {
+                               BPath containingFolder;
+                               if (fPath.GetParent(&containingFolder) != B_OK)
+                                       break;
+                               BEntry entry(containingFolder.Path());
+                               if (!entry.Exists())
+                                       break;
+                               entry_ref ref;
+                               if (entry.GetRef(&ref) != B_OK)
+                                       break;
+                               be_roster->Launch(&ref);
+
+                               // Use Tracker scripting and select the 
download pose
+                               // in the window.
+                               // TODO: We should somehow get the window that 
just openend.
+                               // Using the name like this is broken when 
there are multiple
+                               // windows open with this name. Also Tracker 
does not scroll
+                               // to this entry.
+                               BString windowName = ref.name;
+                               BString fullWindowName = 
containingFolder.Path();
+
+                               BMessenger 
trackerMessenger("application/x-vnd.Be-TRAK");
+                               if (trackerMessenger.IsValid()
+                                       && get_ref_for_path(fPath.Path(), &ref) 
== B_OK) {
+                                       // We need to wait a bit until the 
folder is open.
+                                       // TODO: This is also too fragile... we 
should be able
+                                       // to wait for the roster message.
+                                       snooze(250000);
+                                       int32 tries = 2;
+                                       while (tries > 0) {
+                                               BMessage 
selectionCommand(B_SET_PROPERTY);
+                                               
selectionCommand.AddSpecifier("Selection");
+                                               
selectionCommand.AddSpecifier("Poses");
+                                               
selectionCommand.AddSpecifier("Window",
+                                                       windowName.String());
+                                               selectionCommand.AddRef("data", 
&ref);
+                                               BMessage reply;
+                                               
trackerMessenger.SendMessage(&selectionCommand, &reply);
+                                               int32 error;
+                                               if (reply.FindInt32("error", 
&error) != B_OK
+                                                       || error == B_OK) {
+                                                       break;
+                                               }
+                                               windowName = fullWindowName;
+                                               tries--;
+                                       }
+                               }
+                       }
+                       break;
+
                default:
                        BGroupView::MessageReceived(message);
        }
@@ -534,6 +637,7 @@
        fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD));
        fBottomButton->SetEnabled(true);
        fInfoView->SetText("");
+       fPath.Unset();
 }
 
 

Modified: webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.h        Sat May 
 1 18:07:40 2010        (r469)
+++ webkit/trunk/WebKit/haiku/WebPositive/DownloadProgressView.h        Sat May 
 1 19:20:53 2010        (r470)
@@ -57,6 +57,8 @@
        virtual void                            DetachedFromWindow();
        virtual void                            AllAttached();
 
+       virtual void                            MouseDown(BPoint where);
+
        virtual void                            Draw(BRect updateRect);
 
        virtual void                            MessageReceived(BMessage* 
message);

Other related posts:

  • » [haiku-webkit-commits] r470 - webkit/trunk/WebKit/haiku/WebPositive - webkit