From 3af09a190a90030049f6190ddd86522dc066c58a Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Mon, 29 Jun 2015 15:45:44 +0100 Subject: [PATCH] Text SelectAll and buttons shown depending on context SelectAll shown if selecting text and not all text selected. Default order of buttons changed Change-Id: I587987e626f85d1110b1c0df03321505fee2b423 Signed-off-by: Agnelo Vaz --- .../text-controls/text-selection-popup-impl.cpp | 4 +- .../internal/text/text-controller-impl.cpp | 78 +++++++++++++++------- dali-toolkit/internal/text/text-controller-impl.h | 4 +- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index e0d6435..db7596a 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -768,8 +768,8 @@ TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* cal mPressedColor( DEFAULT_OPTION_ICON_PRESSED ), mSelectOptionPriority( 1 ), mSelectAllOptionPriority ( 2 ), - mCutOptionPriority ( 3 ), - mCopyOptionPriority ( 4 ), + mCutOptionPriority ( 4 ), + mCopyOptionPriority ( 3 ), mPasteOptionPriority ( 5 ), mClipboardOptionPriority( 6 ), mShowIcons( false ), diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 5df31dc..08790c2 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -136,7 +136,8 @@ EventData::EventData( DecoratorPtr decorator ) mUpdateLeftSelectionPosition( false ), mUpdateRightSelectionPosition( false ), mScrollAfterUpdatePosition( false ), - mScrollAfterDelete( false ) + mScrollAfterDelete( false ), + mAllTextSelected( false ) {} EventData::~EventData() @@ -237,6 +238,7 @@ bool Controller::Impl::ProcessInputEvents() leftScroll = true; } + SetPopupButtons(); mEventData->mDecoratorUpdated = true; mEventData->mUpdateLeftSelectionPosition = false; } @@ -253,6 +255,7 @@ bool Controller::Impl::ProcessInputEvents() rightScroll = true; } + SetPopupButtons(); mEventData->mDecoratorUpdated = true; mEventData->mUpdateRightSelectionPosition = false; } @@ -966,6 +969,47 @@ void Controller::Impl::RepositionSelectionHandles( float visualX, float visualY RepositionSelectionHandles( selectionStart, selectionEnd ); } +void Controller::Impl::SetPopupButtons() +{ + /** + * Sets the Popup buttons to be shown depending on State. + * + * If SELECTING : CUT & COPY + ( PASTE & CLIPBOARD if content available to paste ) + * + * If EDITING_WITH_POPUP : SELECT & SELECT_ALL + */ + + TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::NONE; + + if ( ( EventData::SELECTING == mEventData->mState ) || ( EventData::SELECTION_CHANGED == mEventData->mState ) ) + { + buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY ); + + if ( !IsClipboardEmpty() ) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); + } + + if ( !mEventData->mAllTextSelected ) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::SELECT_ALL ) ); + } + } + else if ( EventData::EDITING_WITH_POPUP == mEventData->mState ) + { + buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL ); + + if ( !IsClipboardEmpty() ) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); + } + } + + mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); +} + void Controller::Impl::ChangeState( EventData::State newState ) { if( NULL == mEventData ) @@ -998,14 +1042,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); if( mEventData->mGrabHandlePopupEnabled ) { - TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY ); - if ( !IsClipboardEmpty() ) - { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); - } - - mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); + SetPopupButtons(); mEventData->mDecorator->SetPopupActive( true ); } mEventData->mDecoratorUpdated = true; @@ -1014,14 +1051,8 @@ void Controller::Impl::ChangeState( EventData::State newState ) { if( mEventData->mGrabHandlePopupEnabled ) { - TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY ); - if ( !IsClipboardEmpty() ) - { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); - } + SetPopupButtons(); mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); mEventData->mDecorator->SetPopupActive( true ); } mEventData->mDecoratorUpdated = true; @@ -1062,15 +1093,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) } if( mEventData->mGrabHandlePopupEnabled ) { - TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL ); - - if ( !IsClipboardEmpty() ) - { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); - } - - mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); + SetPopupButtons(); mEventData->mDecorator->SetPopupActive( true ); } HideClipboard(); @@ -1640,6 +1663,11 @@ void Controller::Impl::UpdateSelectionHandle( HandleType handleType ) cursorPosition.x, cursorPosition.y, cursorInfo.lineHeight ); + + // If selection handle at start of the text and other at end of the text then all text is selected. + const CharacterIndex startOfSelection = std::min( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition ); + const CharacterIndex endOfSelection = std::max ( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition ); + mEventData->mAllTextSelected = ( startOfSelection == 0 ) && ( endOfSelection == mLogicalModel->mText.Count() ); } void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize ) diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index db0c0c3..24b10e8 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -153,6 +153,7 @@ struct EventData bool mUpdateRightSelectionPosition : 1; ///< True if the visual position of the right selection handle must be recalculated. bool mScrollAfterUpdatePosition : 1; ///< Whether to scroll after the cursor position is updated. bool mScrollAfterDelete : 1; ///< Whether to scroll after delete characters. + bool mAllTextSelected : 1; ///< True if the selection handles are selecting all the text }; struct ModifyEvent @@ -354,8 +355,9 @@ struct Controller::Impl void RepositionSelectionHandles( CharacterIndex selectionStart, CharacterIndex selectionEnd ); void RepositionSelectionHandles( float visualX, float visualY ); - void ChangeState( EventData::State newState ); + void SetPopupButtons(); + void ChangeState( EventData::State newState ); LineIndex GetClosestLine( float y ) const; void FindSelectionIndices( float visualX, float visualY, CharacterIndex& startIndex, CharacterIndex& endIndex ); -- 2.7.4