Ticket #8156: Workspaces.patch

File Workspaces.patch, 3.4 KB (added by rq, 12 years ago)

Patch adding the "Live in the Deskbar" item to the context menu

  • src/apps/workspaces/Workspaces.cpp

    diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp
    index e3415d0..14fa340 100644
    a b  
    1414#include <Alert.h>
    1515#include <Application.h>
    1616#include <Catalog.h>
     17#include <Deskbar.h>
    1718#include <Dragger.h>
    1819#include <Entry.h>
    1920#include <File.h>
     
    4041#define B_TRANSLATE_CONTEXT "Workspaces"
    4142
    4243
     44static const char* kDeskbarItemName = "workspaces";
    4345static const char* kSignature = "application/x-vnd.Be-WORK";
     46static const char* kDeskbarSignature = "application/x-vnd.Be-TSKB";
    4447static const char* kScreenPrefletSignature = "application/x-vnd.Haiku-Screen";
    4548static const char* kOldSettingFile = "Workspace_data";
    4649static const char* kSettingsFile = "Workspaces_settings";
    static const uint32 kMsgToggleTitle = 'tgTt';  
    5053static const uint32 kMsgToggleBorder = 'tgBd';
    5154static const uint32 kMsgToggleAutoRaise = 'tgAR';
    5255static const uint32 kMsgToggleAlwaysOnTop = 'tgAT';
     56static const uint32 kMsgToggleLiveInDeskbar = 'tgDb';
    5357
    5458static const float kScreenBorderOffset = 10.0;
    5559
     60extern "C" _EXPORT BView* instantiate_deskbar_item();
    5661
    5762class WorkspacesSettings {
    5863    public:
    class WorkspacesSettings {  
    8994
    9095class WorkspacesView : public BView {
    9196    public:
    92         WorkspacesView(BRect frame);
     97        WorkspacesView(BRect frame, bool showDragger);
    9398        WorkspacesView(BMessage* archive);
    9499        ~WorkspacesView();
    95100
    WorkspacesSettings::SetWindowFrame(BRect frame)  
    331336//  #pragma mark -
    332337
    333338
    334 WorkspacesView::WorkspacesView(BRect frame)
     339WorkspacesView::WorkspacesView(BRect frame, bool showDragger=true)
    335340    :
    336     BView(frame, "workspaces", B_FOLLOW_ALL,
     341    BView(frame, kDeskbarItemName, B_FOLLOW_ALL,
    337342        kWorkspacesViewFlag | B_FRAME_EVENTS),
    338343    fParentWhichDrawsOnChildren(NULL),
    339344    fCurrentFrame(frame)
    340345{
    341     frame.OffsetTo(B_ORIGIN);
    342     frame.top = frame.bottom - 7;
    343     frame.left = frame.right - 7;
    344     BDragger* dragger = new BDragger(frame, this,
    345         B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
    346     AddChild(dragger);
     346    if(showDragger) {
     347        frame.OffsetTo(B_ORIGIN);
     348        frame.top = frame.bottom - 7;
     349        frame.left = frame.right - 7;
     350        BDragger* dragger = new BDragger(frame, this,
     351            B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
     352        AddChild(dragger);
     353    }
    347354}
    348355
    349356
    WorkspacesView::MouseDown(BPoint where)  
    576583            new BMessage(kMsgToggleAutoRaise)));
    577584        if (window->IsAutoRaising())
    578585            item->SetMarked(true);
     586        if (be_roster->IsRunning(kDeskbarSignature)) {
     587            menu->AddItem(item = new BMenuItem(B_TRANSLATE("Live in the Deskbar"),
     588            new BMessage(kMsgToggleLiveInDeskbar)));
     589            BDeskbar deskbar;
     590            item->SetMarked(deskbar.HasItem(kDeskbarItemName));
     591        }
    579592
    580593        menu->AddSeparatorItem();
    581594        menu->AddItem(new BMenuItem(B_TRANSLATE("About Workspaces"
    WorkspacesWindow::MessageReceived(BMessage *message)  
    772785            fSettings->SetAlwaysOnTop(enable);
    773786            break;
    774787        }
     788       
     789        case kMsgToggleLiveInDeskbar:
     790        {
     791            BDeskbar deskbar;
     792            if (deskbar.HasItem (kDeskbarItemName))
     793                deskbar.RemoveItem (kDeskbarItemName);
     794            else {
     795                entry_ref ref;
     796                be_roster->FindApp(kSignature, &ref);
     797                deskbar.AddItem(&ref);
     798            }
     799            break;
     800        }
    775801
    776802        default:
    777803            BWindow::MessageReceived(message);
    WorkspacesApp::ArgvReceived(int32 argc, char **argv)  
    904930}
    905931
    906932
     933BView* instantiate_deskbar_item()
     934{
     935    return new WorkspacesView(BRect (0, 0, 75, 15), false);
     936}
     937
     938
    907939void
    908940WorkspacesApp::ReadyToRun()
    909941{