Ticket #7002: ClipboardMenu.diff

File ClipboardMenu.diff, 4.6 KB (added by dancxjo, 13 years ago)
  • src/kits/locale/Jamfile

     
    6767SEARCH on [ FGristFiles StringForSize.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ;
    6868SEARCH on [ FGristFiles AboutWindow.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ;
    6969SEARCH on [ FGristFiles ColorControl.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ;
     70SEARCH on [ FGristFiles TextInput.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ;
    7071
    7172DoCatalogs liblocale.so
    7273    : system
     
    7475    AboutWindow.cpp
    7576    ColorControl.cpp
    7677    StringForSize.cpp
     78    TextInput.cpp   
    7779    ;
  • src/kits/interface/TextInput.h

     
    4646virtual void            InsertText(const char *inText, int32 inLength,
    4747                                   int32 inOffset, const text_run_array *inRuns);
    4848virtual void            DeleteText(int32 fromOffset, int32 toOffset);
     49virtual void            MessageReceived(BMessage* message);
    4950
    5051private:
     52        void            _Init();
    5153
    5254        BTextControl    *TextControl();
    5355
  • src/kits/interface/TextInput.cpp

     
    1414#include <stdlib.h>
    1515#include <string.h>
    1616
     17#include <Clipboard.h>
    1718#include <ControlLook.h>
    1819#include <InterfaceDefs.h>
     20#include <LayoutBuilder.h>
    1921#include <LayoutUtils.h>
     22#include <Menu.h>
     23#include <MenuItem.h>
    2024#include <Message.h>
     25#include <PopUpMenu.h>
    2126#include <String.h>
    2227#include <TextControl.h>
    2328#include <TextView.h>
    2429#include <Window.h>
    2530
     31#include <Catalog.h>
     32#include <LocaleBackend.h>
    2633
     34
     35using BPrivate::gLocaleBackend;
     36using BPrivate::LocaleBackend;
     37
     38
     39#undef B_TRANSLATE_CONTEXT
     40#define B_TRANSLATE_CONTEXT "TextInput"
     41
     42
     43#define TRANSLATE(str) gLocaleBackend->GetString(B_TRANSLATE_MARK(str), \
     44        "TextInput")
     45
     46
    2747namespace BPrivate {
    2848
     49const uint32 kMsgClearInput = 'CLER';
    2950
    3051_BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask,
    3152        uint32 flags)
    3253    : BTextView(frame, "_input_", textRect, resizeMask, flags),
    3354    fPreviousText(NULL)
    3455{
    35     MakeResizable(true);
     56    _Init();
    3657}
    3758
    3859
     
    4061    : BTextView(archive),
    4162    fPreviousText(NULL)
    4263{
    43     MakeResizable(true);
     64    _Init();
    4465}
    4566
    4667
     
    7596        return;
    7697    }
    7798
    78     // only pass through to base class if we already have focus
    79     BTextView::MouseDown(where);
     99    int32 buttons = B_SECONDARY_MOUSE_BUTTON;
     100    if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
     101        Looper()->CurrentMessage()->FindInt32("buttons", &buttons);
     102
     103    if (buttons == B_SECONDARY_MOUSE_BUTTON) {
     104        bool isRedo;
     105        undo_state state = UndoState(&isRedo);
     106        bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo;
     107
     108        int32 start;
     109        int32 finish;
     110        GetSelection(&start, &finish);
     111       
     112        bool canEdit = IsEditable();
     113        int32 length = TextLength();
     114   
     115        BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
     116
     117        BLayoutBuilder::Menu<>(menu)
     118            .AddItem(TRANSLATE("Undo"), B_UNDO/*, 'Z'*/)
     119                .SetEnabled(canEdit && isUndo)
     120            .AddItem(TRANSLATE("Redo"), B_UNDO/*, 'Z', B_SHIFT_KEY*/)
     121                .SetEnabled(canEdit && isRedo)
     122            .AddSeparator()
     123            .AddItem(TRANSLATE("Cut"), B_CUT, 'X')
     124                .SetEnabled(canEdit && start != finish)
     125            .AddItem(TRANSLATE("Copy"), B_COPY, 'C')
     126                .SetEnabled(start != finish)
     127            .AddItem(TRANSLATE("Paste"), B_PASTE, 'V')
     128                .SetEnabled(canEdit && be_clipboard->SystemCount() > 0)
     129            .AddSeparator()
     130            .AddItem(TRANSLATE("Select All"), B_SELECT_ALL, 'A')
     131                .SetEnabled(!(start == 0 && finish == length))
     132            .AddItem(TRANSLATE("Clear"), kMsgClearInput)
     133                .SetEnabled(canEdit && length > 0)
     134        ;
     135
     136        menu->SetTargetForItems(this);
     137        ConvertToScreen(&where);
     138        menu->Go(where, true, true, true);
     139    } else {
     140        // only pass through to base class if we already have focus
     141        BTextView::MouseDown(where);
     142    }
    80143}
    81144
    82145
     
    118181    }
    119182}
    120183
     184
    121185void
    122186_BTextInput_::MakeFocus(bool state)
    123187{
     
    249313}
    250314
    251315
     316void
     317_BTextInput_::MessageReceived(BMessage* message)
     318{
     319    switch(message->what) {
     320        case kMsgClearInput:
     321            SelectAll();
     322            Clear();
     323            break;
     324
     325        default:
     326            BTextView::MessageReceived(message);
     327            break;
     328    }
     329}
     330
     331
     332void
     333_BTextInput_::_Init()
     334{
     335    // we need to translate some strings, and in order to do so, we need
     336    // to use the LocaleBackend to reache liblocale.so
     337    if (gLocaleBackend == NULL)
     338        LocaleBackend::LoadBackend();
     339
     340    MakeResizable(true);
     341}
     342
     343
    252344}   // namespace BPrivate
    253345