diff --git a/headers/os/interface/TextView.h b/headers/os/interface/TextView.h index caaeeaf746..e43c116c18 100644 --- a/headers/os/interface/TextView.h +++ b/headers/os/interface/TextView.h @@ -357,6 +357,10 @@ private: void _PerformAutoScrolling(); void _UpdateScrollbars(); + void _ScrollBy(float horizontalStep, + float verticalStep); + void _ScrollTo(float x, float y); + void _AutoResize(bool doRedraw = true); void _NewOffscreen(float padding = 0.0); @@ -405,9 +409,7 @@ private: float _NullStyleHeight() const; - void _ScrollBy(float horizontalStep, - float verticalStep); - void _ScrollTo(float x, float y); + void _ShowContextMenu(BPoint where); private: BPrivate::TextGapBuffer* fText; diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 2e991133a3..b50d1e47a0 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -34,9 +34,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -52,8 +54,21 @@ #include "UndoBuffer.h" #include "WidthBuffer.h" +#include +#include + using namespace std; +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "TextView" + + +#define TRANSLATE(str) gLocaleBackend->GetString(B_TRANSLATE_MARK(str), \ + "TextView") #undef TRACE #undef CALLED @@ -558,19 +573,24 @@ BTextView::MouseDown(BPoint where) _StopMouseTracking(); + int32 modifiers = 0; + uint32 buttons; + BMessage *currentMessage = Window()->CurrentMessage(); + if (currentMessage != NULL) { + currentMessage->FindInt32("modifiers", &modifiers); + currentMessage->FindInt32("buttons", (int32 *)&buttons); + } + + if (buttons == B_SECONDARY_MOUSE_BUTTON) { + _ShowContextMenu(where); + return; + } + BMessenger messenger(this); fTrackingMouse = new (nothrow) TextTrackState(messenger); if (fTrackingMouse == NULL) return; - int32 modifiers = 0; - //uint32 buttons; - BMessage *currentMessage = Window()->CurrentMessage(); - if (currentMessage != NULL) { - currentMessage->FindInt32("modifiers", &modifiers); - //currentMessage->FindInt32("buttons", (int32 *)&buttons); - } - fTrackingMouse->clickOffset = OffsetAt(where); fTrackingMouse->shiftDown = modifiers & B_SHIFT_KEY; fTrackingMouse->where = where; @@ -3238,6 +3258,11 @@ BTextView::_InitObject(BRect textRect, const BFont *initialFont, fLastClickOffset = -1; SetDoesUndo(true); + + // We need to translate some strings, and in order to do so, we need + // to use the LocaleBackend to reach liblocale.so + if (gLocaleBackend == NULL) + LocaleBackend::LoadBackend(); } @@ -5539,6 +5564,44 @@ BTextView::_NullStyleHeight() const } +void +BTextView::_ShowContextMenu(BPoint where) +{ + bool isRedo; + undo_state state = UndoState(&isRedo); + bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; + + int32 start; + int32 finish; + GetSelection(&start, &finish); + + bool canEdit = IsEditable(); + int32 length = TextLength(); + + BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); + + BLayoutBuilder::Menu<>(menu) + .AddItem(TRANSLATE("Undo"), B_UNDO/*, 'Z'*/) + .SetEnabled(canEdit && isUndo) + .AddItem(TRANSLATE("Redo"), B_UNDO/*, 'Z', B_SHIFT_KEY*/) + .SetEnabled(canEdit && isRedo) + .AddSeparator() + .AddItem(TRANSLATE("Cut"), B_CUT, 'X') + .SetEnabled(canEdit && start != finish) + .AddItem(TRANSLATE("Copy"), B_COPY, 'C') + .SetEnabled(start != finish) + .AddItem(TRANSLATE("Paste"), B_PASTE, 'V') + .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) + .AddSeparator() + .AddItem(TRANSLATE("Select All"), B_SELECT_ALL, 'A') + .SetEnabled(!(start == 0 && finish == length)) + ; + + menu->SetTargetForItems(this); + ConvertToScreen(&where); + menu->Go(where, true, true, true); +} + // #pragma mark - BTextView::TextTrackState diff --git a/src/kits/locale/Jamfile b/src/kits/locale/Jamfile index de642c1526..73df30bda3 100644 --- a/src/kits/locale/Jamfile +++ b/src/kits/locale/Jamfile @@ -67,6 +67,7 @@ StaticLibrary liblocalestub.a SEARCH on [ FGristFiles StringForSize.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ; SEARCH on [ FGristFiles AboutWindow.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ; SEARCH on [ FGristFiles ColorControl.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; +SEARCH on [ FGristFiles TextView.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; DoCatalogs liblocale.so : system @@ -74,4 +75,5 @@ DoCatalogs liblocale.so AboutWindow.cpp ColorControl.cpp StringForSize.cpp + TextView.cpp ;