diff --git a/include/eepp/ui/keyboardshortcut.hpp b/include/eepp/ui/keyboardshortcut.hpp index 58eb5acde..b448e1e34 100644 --- a/include/eepp/ui/keyboardshortcut.hpp +++ b/include/eepp/ui/keyboardshortcut.hpp @@ -85,7 +85,7 @@ class EE_API KeyBindings { const ShortcutMap& getShortcutMap() const; - const std::map getKeybindings() const; + const std::map& getKeybindings() const; Shortcut getShortcutFromCommand( const std::string& cmd ) const; diff --git a/include/eepp/ui/mouseshortcut.hpp b/include/eepp/ui/mouseshortcut.hpp index 88f9885ef..758e82e90 100644 --- a/include/eepp/ui/mouseshortcut.hpp +++ b/include/eepp/ui/mouseshortcut.hpp @@ -3,7 +3,6 @@ #include "eepp/core/containers.hpp" #include #include -#include #include using namespace EE::Window; @@ -42,7 +41,19 @@ class EE_API MouseBindings { Uint32 mod{ 0 }; }; - typedef std::map ShortcutMap; + struct ShortcutHash { + size_t operator()( const Shortcut& shortcut ) const noexcept { + return hashCombine( static_cast( shortcut.action ), + static_cast( shortcut.key ), + static_cast( shortcut.mod ) ); + } + }; + + typedef std::unordered_map ShortcutMap; + + static std::string mouseActionToString( MouseAction action ); + + static MouseAction mouseActionFromString( std::string_view action ); static MouseButtonsMask getMouseButtonsMask( const std::string& str ); @@ -54,18 +65,13 @@ class EE_API MouseBindings { static Shortcut toShortcut( const std::string& keys ); - static std::string fromShortcut( MouseBindings::Shortcut shortcut, - bool format = false ); + static std::string fromShortcut( MouseBindings::Shortcut shortcut, bool format = false ); MouseBindings(); - void addMousebindsString( const std::map& binds ); + void addMousebindsString( const std::unordered_map& binds ); - void addMousebinds( const std::map& binds ); - - void addMousebindsStringUnordered( const std::unordered_map& binds ); - - void addMousebindsUnordered( const std::unordered_map& binds ); + void addMousebinds( const ShortcutMap& binds ); void addMousebindString( const std::string& key, const std::string& command ); @@ -99,7 +105,7 @@ class EE_API MouseBindings { const ShortcutMap& getShortcutMap() const; - const std::map getMousebindings() const; + const std::unordered_map& getMousebindings() const; Shortcut getShortcutFromCommand( const std::string& cmd ) const; @@ -107,17 +113,8 @@ class EE_API MouseBindings { protected: ShortcutMap mShortcuts; - std::map mMousebindingsInvert; + std::unordered_map mActionShortcuts; + std::unordered_map mMousebindingsInvert; }; }} // namespace EE::UI - -namespace std { -template <> struct hash { - size_t operator()( const EE::UI::MouseBindings::Shortcut& shortcut ) const noexcept { - return hashCombine( static_cast( shortcut.action ), - static_cast( shortcut.key ), shortcut.mod ); - } -}; - -} // namespace std diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 1cb2da78c..c16fb3d93 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { static const std::map getDefaultKeybindings(); + static const MouseBindings::ShortcutMap getDefaultMousebindings(); + UICodeEditor( const bool& autoRegisterBaseCommands = true, const bool& autoRegisterBaseKeybindings = true ); @@ -351,6 +354,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { KeyBindings& getKeyBindings(); + MouseBindings& getMouseBindings(); + void setKeyBindings( const KeyBindings& keyBindings ); void addKeyBindingString( const std::string& shortcut, const std::string& command, @@ -725,8 +730,6 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { void invalidateLongestLineWidth(); - const DocumentView& documentView() const { return mDocView; } - LineWrapMode getLineWrapMode() const { return mDocView.getConfig().mode; } void setLineWrapMode( LineWrapMode mode ); @@ -884,6 +887,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { UIScrollBar* mHScrollBar; UnorderedMap mLastXOffset; KeyBindings mKeyBindings; + MouseBindings mMouseBindings; std::unordered_set mUnlockedCmd; Clock mLastDoubleClick; Uint32 mLineBreakingColumn{ 100 }; @@ -1144,6 +1148,12 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { Float editorWidth() const; Float editorHeight() const; + + bool tryExecuteMouseBinding( const MouseBindings::Shortcut& shortcut ); + + void addCursorAtMousePosition(); + + void addCursorsFromCurrentToMousePosition(); }; }} // namespace EE::UI diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index b94a95413..3da515d86 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -264,6 +264,8 @@ class EE_API UINode : public Node { UISceneNode* getUISceneNode() const; + Input* getInput() const; + void setMinWidth( const Float& width ); void setMinHeight( const Float& height ); diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index aaecd1329..4f2291fcd 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -505,13 +505,11 @@ UITableRow* UIAbstractTableView::createRow() { return; auto index = event->getNode()->asType()->getCurIndex(); if ( mSelectionKind == SelectionKind::Single && - getUISceneNode()->getWindow()->getInput()->getSanitizedModState() & - KeyMod::getDefaultModifier() ) { + getInput()->getSanitizedModState() & KeyMod::getDefaultModifier() ) { getSelection().remove( index ); } else { if ( mSelectionKind == SelectionKind::Multiple && - getUISceneNode()->getWindow()->getInput()->getSanitizedModState() & - KeyMod::getDefaultModifier() ) { + getInput()->getSanitizedModState() & KeyMod::getDefaultModifier() ) { getSelection().toggle( index ); } else { getSelection().set( index ); @@ -575,7 +573,7 @@ void UIAbstractTableView::bindNavigationClick( UIWidget* widget ) { onOpenModelIndex( idx, event ); } else if ( isCellSelection() && ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) ) { auto cellIdx = mouseEvent->getNode()->asType()->getCurIndex(); - if ( getUISceneNode()->getWindow()->getInput()->isControlPressed() ) { + if ( getInput()->isControlPressed() ) { getSelection().remove( cellIdx ); } else { getSelection().set( cellIdx ); diff --git a/src/eepp/ui/keyboardshortcut.cpp b/src/eepp/ui/keyboardshortcut.cpp index 07f92d770..6e5bb5ea5 100644 --- a/src/eepp/ui/keyboardshortcut.cpp +++ b/src/eepp/ui/keyboardshortcut.cpp @@ -179,7 +179,7 @@ const KeyBindings::ShortcutMap& KeyBindings::getShortcutMap() const { return mShortcuts; } -const std::map KeyBindings::getKeybindings() const { +const std::map& KeyBindings::getKeybindings() const { return mKeybindingsInvert; } diff --git a/src/eepp/ui/mouseshortcut.cpp b/src/eepp/ui/mouseshortcut.cpp index 4684258d8..49b8ffd74 100644 --- a/src/eepp/ui/mouseshortcut.cpp +++ b/src/eepp/ui/mouseshortcut.cpp @@ -2,6 +2,44 @@ namespace EE { namespace UI { +std::string MouseBindings::mouseActionToString( MouseAction action ) { + switch ( action ) { + case MouseAction::Down: + return "mousedown"; + case MouseAction::Up: + return "mouseup"; + case MouseAction::Move: + return "mousemove"; + case MouseAction::Click: + return "mouseclick"; + case MouseAction::DoubleClick: + return "mousedoubleclick"; + case MouseAction::Over: + return "mouseover"; + case MouseAction::Leave: + return "mouseleave"; + } + return ""; // unreachable +} + +MouseAction MouseBindings::mouseActionFromString( std::string_view action ) { + if ( action == "mousedown" ) + return MouseAction::Down; + if ( action == "mouseup" ) + return MouseAction::Up; + if ( action == "mousemove" ) + return MouseAction::Move; + if ( action == "mouseclick" ) + return MouseAction::Click; + if ( action == "mousedoubleclick" ) + return MouseAction::DoubleClick; + if ( action == "mouseover" ) + return MouseAction::Over; + if ( action == "mouseleave" ) + return MouseAction::Leave; + return MouseAction::Down; +} + MouseButtonsMask MouseBindings::getMouseButtonsMask( const std::string& strc ) { MouseButtonsMask mask; String::readBySeparator( @@ -86,27 +124,14 @@ MouseBindings::Shortcut MouseBindings::sanitizeShortcut( const MouseBindings::Sh MouseBindings::MouseBindings() {} -void MouseBindings::addMousebindsString( const std::map& binds ) { - for ( auto& bind : binds ) { - addMousebindString( bind.first, bind.second ); - } -} - -void MouseBindings::addMousebinds( const std::map& binds ) { - for ( auto& bind : binds ) { - addMousebind( bind.first, bind.second ); - } -} - -void MouseBindings::addMousebindsStringUnordered( +void MouseBindings::addMousebindsString( const std::unordered_map& binds ) { for ( auto& bind : binds ) { addMousebindString( bind.first, bind.second ); } } -void MouseBindings::addMousebindsUnordered( - const std::unordered_map& binds ) { +void MouseBindings::addMousebinds( const ShortcutMap& binds ) { for ( auto& bind : binds ) { addMousebind( bind.first, bind.second ); } @@ -117,8 +142,10 @@ void MouseBindings::addMousebindString( const std::string& key, const std::strin } void MouseBindings::addMousebind( const MouseBindings::Shortcut& key, const std::string& command ) { - mShortcuts[sanitizeShortcut( key )] = command; - mMousebindingsInvert[command] = sanitizeShortcut( key ); + Shortcut sshortcut = sanitizeShortcut( key ); + mShortcuts[sshortcut] = command; + mActionShortcuts[sshortcut.action][sshortcut] = command; + mMousebindingsInvert[command] = sshortcut; } void MouseBindings::replaceMousebindString( const std::string& keys, const std::string& command ) { @@ -127,24 +154,30 @@ void MouseBindings::replaceMousebindString( const std::string& keys, const std:: void MouseBindings::replaceMousebind( const MouseBindings::Shortcut& keys, const std::string& command ) { + Shortcut sshortcut = sanitizeShortcut( keys ); bool erased; do { erased = false; - auto it = mShortcuts.find( sanitizeShortcut( keys ) ); + auto it = mShortcuts.find( sshortcut ); if ( it != mShortcuts.end() ) { mShortcuts.erase( it ); mMousebindingsInvert.erase( it->second ); erased = true; } } while ( erased ); - mShortcuts[sanitizeShortcut( keys )] = command; - mMousebindingsInvert[command] = sanitizeShortcut( keys ); + mShortcuts[sshortcut] = command; + mActionShortcuts[sshortcut.action][sshortcut] = command; + mMousebindingsInvert[command] = sshortcut; } MouseBindings::Shortcut MouseBindings::toShortcut( const std::string& keys ) { Shortcut shortcut; Uint32 mod = 0; - auto keysSplit = String::split( keys, '+' ); + auto actionSplit = String::split( keys, ',' ); + if ( actionSplit.size() != 2 ) + return shortcut; + shortcut.action = mouseActionFromString( actionSplit[0] ); + auto keysSplit = String::split( actionSplit[1], '+' ); for ( auto& part : keysSplit ) { if ( ( mod = KeyMod::getKeyMod( part ) ) ) { shortcut.mod |= mod; @@ -163,6 +196,12 @@ void MouseBindings::removeMousebind( const MouseBindings::Shortcut& keys ) { auto it = mShortcuts.find( keys ); if ( it != mShortcuts.end() ) { mShortcuts.erase( it ); + auto actionIt = mActionShortcuts.find( keys.action ); + if ( actionIt != mActionShortcuts.end() ) { + auto it2 = actionIt->second.find( keys ); + if ( it2 != actionIt->second.end() ) + actionIt->second.erase( it2 ); + } } } @@ -231,6 +270,7 @@ std::string MouseBindings::getCommandMousebindString( const std::string& command void MouseBindings::reset() { mShortcuts.clear(); + mActionShortcuts.clear(); mMousebindingsInvert.clear(); } @@ -238,12 +278,14 @@ const MouseBindings::ShortcutMap& MouseBindings::getShortcutMap() const { return mShortcuts; } -const std::map MouseBindings::getMousebindings() const { +const std::unordered_map& +MouseBindings::getMousebindings() const { return mMousebindingsInvert; } std::string MouseBindings::fromShortcut( MouseBindings::Shortcut shortcut, bool format ) { std::vector mods; + std::string actionname( mouseActionToString( shortcut.action ) ); std::string keyname( String::toLower( getMouseButtonsName( shortcut.key ) ) ); const auto& MOD_MAP = KeyMod::getModMap(); if ( shortcut.mod & MOD_MAP.at( "mod" ) ) @@ -260,7 +302,7 @@ std::string MouseBindings::fromShortcut( MouseBindings::Shortcut shortcut, bool mods.emplace_back( "meta" ); if ( mods.empty() ) return format ? mousebindFormat( keyname ) : keyname; - auto ret = String::join( mods, '+' ) + "+" + keyname; + auto ret = actionname + "," + String::join( mods, '+' ) + "+" + keyname; return format ? mousebindFormat( ret ) : ret; } diff --git a/src/eepp/ui/tools/uidocfindreplace.cpp b/src/eepp/ui/tools/uidocfindreplace.cpp index 8a3b3def0..aba0007f6 100644 --- a/src/eepp/ui/tools/uidocfindreplace.cpp +++ b/src/eepp/ui/tools/uidocfindreplace.cpp @@ -167,7 +167,7 @@ void UIDocFindReplace::setDoc( const std::shared_ptr& doc ) { UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptr& doc, std::unordered_map keybindings ) : UILinearLayout( "docfindreplace", UIOrientation::Horizontal ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ), + WidgetCommandExecuter( getInput() ), mDoc( doc ) { mFlags |= UI_OWNS_CHILDREN_POSITION; diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 20902c7ad..0d4fa90d7 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -118,6 +118,13 @@ const std::map UICodeEditor::getDefaultKeybi }; } +const MouseBindings::ShortcutMap UICodeEditor::getDefaultMousebindings() { + return { { { MouseAction::Down, EE_BUTTON_LMASK, KeyMod::getDefaultModifier() }, + "add-cursor-at-mouse-position" }, + { { MouseAction::Down, EE_BUTTON_LMASK, KEYMOD_SHIFT | KEYMOD_LALT }, + "add-cursors-from-current-to-mouse-position" } }; +} + UICodeEditor::UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands, const bool& autoRegisterBaseKeybindings ) : UIWidget( elementTag ), @@ -133,7 +140,7 @@ UICodeEditor::UICodeEditor( const std::string& elementTag, const bool& autoRegis mLineNumberPaddingRight( PixelDensity::dpToPx( 6 ) ), mFoldRegionWidth( PixelDensity::dpToPx( 12 ) ), mPreviewColor( Color::Transparent ), - mKeyBindings( getUISceneNode()->getWindow()->getInput() ), + mKeyBindings( getInput() ), mFindLongestLineWidthUpdateFrequency( Seconds( 1 ) ) { mFlags |= UI_TAB_STOP | UI_OWNS_CHILDREN_POSITION | UI_SCROLLABLE; setTextSelection( true ); @@ -456,12 +463,11 @@ void UICodeEditor::scheduledUpdate( const Time& ) { } if ( mMouseDown || mMouseDownMinimap ) { - if ( !( getUISceneNode()->getWindow()->getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { - stopMinimapDragging( - getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() ); + if ( !( getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { + stopMinimapDragging( getInput()->getMousePos().asFloat() ); mMouseDown = false; mMouseDownMinimap = false; - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); + getInput()->captureMouse( false ); } else if ( !isMouseOverMeOrChildren() || mMinimapDragging ) { onMouseMove( getUISceneNode()->getEventDispatcher()->getMousePos(), getUISceneNode()->getEventDispatcher()->getPressTrigger() ); @@ -1046,7 +1052,7 @@ void UICodeEditor::setLineWrapKeepIndentation( bool keep ) { Uint32 UICodeEditor::onFocus( NodeFocusReason reason ) { if ( !mLocked ) { - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); resetCursor(); getUISceneNode()->getWindow()->startTextInput(); mDoc->setActiveClient( this ); @@ -1060,8 +1066,8 @@ Uint32 UICodeEditor::onFocus( NodeFocusReason reason ) { Uint32 UICodeEditor::onFocusLoss() { if ( mMouseDown ) - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); - stopMinimapDragging( getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() ); + getInput()->captureMouse( false ); + stopMinimapDragging( getInput()->getMousePos().asFloat() ); mMouseDown = false; mCursorVisible = false; getSceneNode()->getWindow()->stopTextInput(); @@ -1079,7 +1085,7 @@ Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) { if ( mLocked || NULL == mFont ) return 0; - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || ( input->isLeftControlPressed() && !input->isLeftAltPressed() && @@ -1087,7 +1093,7 @@ Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) { input->isMetaPressed() || ( input->isLeftAltPressed() && !input->isLeftControlPressed() ) ) return 0; - if ( mLastExecuteEventId == getUISceneNode()->getWindow()->getInput()->getEventsSentId() && + if ( mLastExecuteEventId == getInput()->getEventsSentId() && !TextDocument::isTextDocumentCommand( mLastCmdHash ) ) return 0; @@ -1276,7 +1282,7 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { if ( !mLocked || mUnlockedCmd.find( cmd ) != mUnlockedCmd.end() ) { mDoc->execute( cmd, this ); mLastCmdHash = String::hash( cmd ); - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); return 1; } } @@ -1289,8 +1295,8 @@ Uint32 UICodeEditor::onKeyUp( const KeyEvent& event ) { for ( auto& plugin : mPlugins ) if ( plugin->onKeyUp( this, event ) ) return 1; - if ( mHandShown && !getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) - resetLinkOver( getUISceneNode()->getWindow()->getInput()->getMousePos() ); + if ( mHandShown && !getInput()->isKeyModPressed() ) + resetLinkOver( getInput()->getMousePos() ); return UIWidget::onKeyUp( event ); } @@ -1497,6 +1503,15 @@ Int64 UICodeEditor::calculateMinimapClickedLine( const Vector2i& position ) { return eeclamp( ret, (Int64)0, (Int64)visualLineCount ); } +bool UICodeEditor::tryExecuteMouseBinding( const MouseBindings::Shortcut& shortcut ) { + std::string cmd( mMouseBindings.getCommandFromMousebind( shortcut ) ); + if ( !cmd.empty() ) { + mDoc->execute( cmd, this ); + return true; + } + return false; +} + Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags ) { mLastActivity.restart(); for ( auto& plugin : mPlugins ) @@ -1537,11 +1552,14 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags } } + MouseBindings::Shortcut shortcut{ MouseAction::Down, flags, + getInput()->getSanitizedModState() }; + if ( ( flags & ( EE_BUTTON_LMASK | EE_BUTTON_RMASK ) ) && isTextSelectionEnabled() && !getEventDispatcher()->isNodeDragging() && NULL != mFont && !mMouseDown && getEventDispatcher()->getMouseDownNode() == this ) { mMouseDown = true; - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); input->captureMouse( true ); setFocus(); @@ -1555,33 +1573,22 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags if ( flags & EE_BUTTON_LMASK ) { if ( localPos.x > mPaddingPx.Left + getLineNumberWidth() && downOverGutter ) { toggleFoldUnfold( textScreenPos.line() ); - } else if ( !downOverGutter && input->isModState( KEYMOD_LALT | KEYMOD_SHIFT ) ) { - TextRange range( mDoc->getSelection().start(), textScreenPos ); - range = mDoc->sanitizeRange( range ); - TextRange nrange = range.normalized(); - TextRanges ranges; - ranges.reserve( nrange.end().line() - nrange.start().line() + 1 ); - for ( Int64 i = nrange.start().line(); i <= nrange.end().line(); ++i ) { - TextPosition pos{ i, range.start().column() }; - ranges.push_back( TextRange{ pos, pos } ); - } - mDoc->addSelections( std::move( ranges ) ); } else if ( !downOverGutter && input->isModState( KEYMOD_SHIFT ) ) { mDoc->selectTo( textScreenPos ); - } else if ( !downOverGutter && input->isModState( KEYMOD_CTRL ) && - checkMouseOverLink( position ).empty() ) { - TextPosition pos( textScreenPos ); - if ( !mDoc->selectionExists( pos ) ) - mDoc->addSelection( { pos, pos } ); } else if ( !downOverGutter && mLastDoubleClick.getElapsedTime() < Milliseconds( 300.f ) ) { mDoc->selectLine(); } else { + if ( !downOverGutter && tryExecuteMouseBinding( shortcut ) ) + return UIWidget::onMouseDown( position, flags ); + if ( !downOverGutter || mAllowSelectingTextFromGutter ) mDoc->setSelection( textScreenPos ); if ( downOverGutter && mAllowSelectingTextFromGutter ) mDoc->selectLine(); } + } else if ( !downOverGutter && tryExecuteMouseBinding( shortcut ) ) { + return UIWidget::onMouseDown( position, flags ); } else if ( !mDoc->hasSelection() ) { mDoc->setSelection( textScreenPos ); } @@ -1589,6 +1596,30 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags return UIWidget::onMouseDown( position, flags ); } +void UICodeEditor::addCursorAtMousePosition() { + auto position = getInput()->getMousePos(); + if ( checkMouseOverLink( position ).empty() ) { + auto pos( resolveScreenPosition( position.asFloat() ) ); + if ( !mDoc->selectionExists( pos ) ) + mDoc->addSelection( { pos, pos } ); + } +} + +void UICodeEditor::addCursorsFromCurrentToMousePosition() { + auto position = getInput()->getMousePos(); + auto textScreenPos( resolveScreenPosition( position.asFloat() ) ); + TextRange range( mDoc->getSelection().start(), textScreenPos ); + range = mDoc->sanitizeRange( range ); + TextRange nrange = range.normalized(); + TextRanges ranges; + ranges.reserve( nrange.end().line() - nrange.start().line() + 1 ); + for ( Int64 i = nrange.start().line(); i <= nrange.end().line(); ++i ) { + TextPosition pos{ i, range.start().column() }; + ranges.push_back( TextRange{ pos, pos } ); + } + mDoc->addSelections( std::move( ranges ) ); +} + bool UICodeEditor::toggleFoldUnfold( Int64 docLineIdx ) { if ( mDoc->getFoldRangeService().isFoldingRegionInLine( docLineIdx ) ) { sendCommonEvent( Event::OnBeforeFoldUnfoldRange ); @@ -1702,7 +1733,9 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) bool minimapHover = mMinimapEnabled && getMinimapRect( getScreenStart() ).contains( position.asFloat() ); - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); + + MouseBindings::Shortcut shortcut{ MouseAction::Up, flags, getInput()->getSanitizedModState() }; if ( flags & EE_BUTTON_LMASK ) { stopMinimapDragging( position.asFloat() ); @@ -1711,8 +1744,10 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) mMouseDownMinimap = false; input->captureMouse( false ); } + + tryExecuteMouseBinding( shortcut ); } else if ( flags & EE_BUTTON_WDMASK ) { - if ( getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { + if ( getInput()->isKeyModPressed() ) { mDoc->execute( "font-size-shrink" ); } else if ( input->isModState( KEYMOD_SHIFT ) ) { setScrollX( mScroll.x + mMouseWheelScroll ); @@ -1720,7 +1755,7 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) setScrollY( mScroll.y + mMouseWheelScroll ); } } else if ( flags & EE_BUTTON_WUMASK ) { - if ( getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { + if ( getInput()->isKeyModPressed() ) { mDoc->execute( "font-size-grow" ); } else if ( input->isModState( KEYMOD_SHIFT ) ) { setScrollX( mScroll.x - mMouseWheelScroll ); @@ -1735,7 +1770,8 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) Vector2f localPos( convertToNodeSpace( position.asFloat() ) ); if ( localPos.x >= mPaddingPx.Left + getGutterWidth() && localPos.y >= mPluginsTopSpace ) onCreateContextMenu( position, flags ); - } + } else if ( tryExecuteMouseBinding( shortcut ) ) + return UIWidget::onMouseUp( position, flags ); return UIWidget::onMouseUp( position, flags ); } @@ -1752,8 +1788,13 @@ Uint32 UICodeEditor::onMouseClick( const Vector2i& position, const Uint32& flags return 1; } - if ( ( flags & EE_BUTTON_LMASK ) && - getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { + MouseBindings::Shortcut shortcut{ MouseAction::Click, flags, + getInput()->getSanitizedModState() }; + + if ( tryExecuteMouseBinding( shortcut ) ) + return 1; + + if ( ( flags & EE_BUTTON_LMASK ) && getInput()->isKeyModPressed() ) { String link( checkMouseOverLink( position ) ); if ( !link.empty() ) { Engine::instance()->openURI( link.toUtf8() ); @@ -1789,6 +1830,12 @@ Uint32 UICodeEditor::onMouseDoubleClick( const Vector2i& position, const Uint32& return 1; } + MouseBindings::Shortcut shortcut{ MouseAction::DoubleClick, flags, + getInput()->getSanitizedModState() }; + + if ( tryExecuteMouseBinding( shortcut ) ) + return 1; + Vector2f localPos( convertToNodeSpace( position.asFloat() ) ); if ( isTextSelectionEnabled() && ( flags & EE_BUTTON_LMASK ) && localPos.x >= mPaddingPx.Left + getGutterWidth() && localPos.y >= mPluginsTopSpace ) { @@ -4398,6 +4445,12 @@ void UICodeEditor::registerCommands() { mDoc->setCommand( "copy-file-path-and-position", [this] { copyFilePath( true ); } ); mDoc->setCommand( "find-replace", [this] { showFindReplace(); } ); mDoc->setCommand( "open-context-menu", [this] { createContextMenu(); } ); + mDoc->setCommand( "add-cursor-at-mouse-position", []( Client* client ) { + static_cast( client )->addCursorAtMousePosition(); + } ); + mDoc->setCommand( "add-cursors-from-current-to-mouse-position", []( Client* client ) { + static_cast( client )->addCursorsFromCurrentToMousePosition(); + } ); mUnlockedCmd.insert( { "copy", "select-all", "open-containing-folder", "copy-containing-folder-path", "copy-file-path", "copy-file-path-and-position", "open-context-menu", "find-replace" } ); @@ -4425,6 +4478,7 @@ Tools::UIDocFindReplace* UICodeEditor::getFindReplace() { void UICodeEditor::registerKeybindings() { mKeyBindings.addKeybinds( getDefaultKeybindings() ); + mMouseBindings.addMousebinds( getDefaultMousebindings() ); } void UICodeEditor::onCursorPosChange() { @@ -4494,7 +4548,7 @@ void UICodeEditor::checkMouseOverColor( const Vector2i& position ) { } String UICodeEditor::checkMouseOverLink( const Vector2i& position ) { - if ( !mInteractiveLinks || !getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) + if ( !mInteractiveLinks || !getInput()->isKeyModPressed() ) return resetLinkOver( position ); TextPosition pos( resolveScreenPosition( position.asFloat(), false ) ); diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index 779b04038..7a8039b36 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -39,7 +39,7 @@ UIConsole* UIConsole::NewOpt( Font* font, const bool& makeDefaultCommands, const UIConsole::UIConsole( Font* font, const bool& makeDefaultCommands, const bool& attachToLog, const unsigned int& maxLogLines ) : - UIWidget( "console" ), mKeyBindings( getUISceneNode()->getWindow()->getInput() ) { + UIWidget( "console" ), mKeyBindings( getInput() ) { setFlags( UI_AUTO_PADDING ); mFlags |= UI_TAB_STOP | UI_SCROLLABLE | UI_TEXT_SELECTION_ENABLED; setClipType( ClipType::ContentBox ); @@ -100,9 +100,9 @@ void UIConsole::setTheme( UITheme* Theme ) { void UIConsole::scheduledUpdate( const Time& ) { if ( mMouseDown ) { - if ( !( getUISceneNode()->getWindow()->getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { + if ( !( getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { mMouseDown = false; - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); + getInput()->captureMouse( false ); } else { onMouseDown( getUISceneNode()->getEventDispatcher()->getMousePos(), getUISceneNode()->getEventDispatcher()->getPressTrigger() ); @@ -921,14 +921,14 @@ Uint32 UIConsole::onKeyDown( const KeyEvent& event ) { if ( !cmd.empty() ) { mDoc.execute( cmd ); mLastCmdHash = String::hash( cmd ); - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); return 1; } return UIWidget::onKeyDown( event ); } Uint32 UIConsole::onTextInput( const TextInputEvent& event ) { - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || ( input->isLeftControlPressed() && !input->isLeftAltPressed() && @@ -936,7 +936,7 @@ Uint32 UIConsole::onTextInput( const TextInputEvent& event ) { input->isMetaPressed() || ( input->isLeftAltPressed() && !input->isLeftControlPressed() ) ) return 0; - if ( mLastExecuteEventId == getUISceneNode()->getWindow()->getInput()->getEventsSentId() && + if ( mLastExecuteEventId == getInput()->getEventsSentId() && !TextDocument::isTextDocumentCommand( mLastCmdHash ) ) return 0; @@ -1032,7 +1032,7 @@ Uint32 UIConsole::onFocus( NodeFocusReason reason ) { getSceneNode()->getWindow()->startTextInput(); - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); return 1; } @@ -1072,7 +1072,7 @@ Uint32 UIConsole::onMouseDown( const Vector2i& position, const Uint32& flags ) { if ( NULL != getEventDispatcher() && isTextSelectionEnabled() && ( flags & EE_BUTTON_LMASK ) && getEventDispatcher()->getMouseDownNode() == this && !mMouseDown ) { - getUISceneNode()->getWindow()->getInput()->captureMouse( true ); + getInput()->captureMouse( true ); mMouseDown = true; auto pos = getPositionOnScreen( position.asFloat() ); auto prevSelection = mSelection; @@ -1144,7 +1144,7 @@ Uint32 UIConsole::onMouseUp( const Vector2i& position, const Uint32& flags ) { } else if ( flags & EE_BUTTON_LMASK ) { if ( mMouseDown ) { mMouseDown = false; - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); + getInput()->captureMouse( false ); } } else if ( ( flags & EE_BUTTON_RMASK ) ) { onCreateContextMenu( position, flags ); diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index bd8fe117f..d232c54eb 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -76,8 +76,8 @@ Uint32 UIMenuItem::onMouseLeave( const Vector2i& pos, const Uint32& flags ) { } Uint32 UIMenuItem::onMouseClick( const Vector2i&, const Uint32& flags ) { - if ( !getUISceneNode()->getWindow()->getInput()->isShiftPressed() && - ( flags & EE_BUTTON_LMASK ) && ( !mOnShouldCloseCb || mOnShouldCloseCb( this ) ) ) { + if ( !getInput()->isShiftPressed() && ( flags & EE_BUTTON_LMASK ) && + ( !mOnShouldCloseCb || mOnShouldCloseCb( this ) ) ) { getParent()->asType()->backpropagateHide(); } return 1; diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 6e9dfb70b..fa2ae958d 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -1320,8 +1320,8 @@ void UINode::setThemeToChildren( UITheme* Theme ) { if ( ChildLoop->isUINode() ) { UINode* node = static_cast( ChildLoop ); node->setThemeToChildren( Theme ); - node->setTheme( Theme ); // First set the theme to children to let the father override the - // children forced themes + node->setTheme( Theme ); // First set the theme to children to let the father override + // the children forced themes } ChildLoop = ChildLoop->getNextNode(); @@ -1756,6 +1756,10 @@ UISceneNode* UINode::getUISceneNode() const { return mUISceneNode; } +Input* UINode::getInput() const { + return mUISceneNode->getWindow()->getInput(); +} + Rectf UINode::getLocalDpBounds() const { return Rectf( 0, 0, mDpSize.getWidth(), mDpSize.getHeight() ); } diff --git a/src/eepp/ui/uipopupmenu.cpp b/src/eepp/ui/uipopupmenu.cpp index 77deb83ef..7ed363c62 100644 --- a/src/eepp/ui/uipopupmenu.cpp +++ b/src/eepp/ui/uipopupmenu.cpp @@ -68,7 +68,7 @@ void UIPopUpMenu::showAtScreenPosition( Vector2f pos ) { } void UIPopUpMenu::showOverMouseCursor() { - showAtScreenPosition( getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() ); + showAtScreenPosition( getInput()->getMousePos().asFloat() ); } bool UIPopUpMenu::hide() { diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index ba3adae0c..94bd655bc 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -387,7 +387,7 @@ Uint32 UITab::onMessage( const NodeMessage* message ) { } else if ( tTabW->getTabsClosable() && ( flags & EE_BUTTON_MMASK ) ) { tTabW->tryCloseTab( this, UITabWidget::FocusTabBehavior::Closest ); } else if ( flags & EE_BUTTONS_WUWD ) { - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); if ( input->isModState( KeyMod::getDefaultModifier() ) ) { UISlider* slider = tTabW->getTabScroll()->getSlider(); if ( flags & EE_BUTTON_WUMASK ) { diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index e55576080..6714d186f 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -34,7 +34,7 @@ UITextInput::UITextInput( const std::string& tag ) : mOnlyNumbers( false ), mAllowFloat( false ), mMouseDown( false ), - mKeyBindings( getUISceneNode()->getWindow()->getInput() ) { + mKeyBindings( getInput() ) { mHintCache = Text::New(); UITheme* theme = getUISceneNode()->getUIThemeManager()->getDefaultTheme(); @@ -86,10 +86,10 @@ bool UITextInput::isType( const Uint32& type ) const { void UITextInput::scheduledUpdate( const Time& time ) { updateWaitingCursor( time ); if ( mMouseDown ) { - if ( !( getUISceneNode()->getWindow()->getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { + if ( !( getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) { mMouseDown = false; mSelecting = false; - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); + getInput()->captureMouse( false ); } else { onMouseDown( getUISceneNode()->getEventDispatcher()->getMousePos(), getUISceneNode()->getEventDispatcher()->getPressTrigger() ); @@ -168,7 +168,7 @@ Uint32 UITextInput::onFocus( NodeFocusReason reason ) { getSceneNode()->getWindow()->startTextInput(); - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); updateIMELocation(); } @@ -290,14 +290,14 @@ void UITextInput::updateText() {} Uint32 UITextInput::onMouseDown( const Vector2i& position, const Uint32& flags ) { int endPos = selCurEnd(); - if ( getUISceneNode()->getWindow()->getInput()->isShiftPressed() ) + if ( getInput()->isShiftPressed() ) mSelecting = true; UITextView::onMouseDown( position, flags ); if ( NULL != getEventDispatcher() && isTextSelectionEnabled() && ( flags & EE_BUTTON_LMASK ) && getEventDispatcher()->getMouseDownNode() == this && !mMouseDown ) { - getUISceneNode()->getWindow()->getInput()->captureMouse( true ); + getInput()->captureMouse( true ); mMouseDown = true; } @@ -312,7 +312,7 @@ Uint32 UITextInput::onMouseUp( const Vector2i& position, const Uint32& flags ) { if ( flags & EE_BUTTON_LMASK ) { if ( mMouseDown ) { mMouseDown = false; - getUISceneNode()->getWindow()->getInput()->captureMouse( false ); + getInput()->captureMouse( false ); } } else if ( ( flags & EE_BUTTON_RMASK ) && mEnabledCreateContextMenu ) { onCreateContextMenu( position, flags ); @@ -771,7 +771,7 @@ Uint32 UITextInput::onKeyDown( const KeyEvent& event ) { if ( mAllowEditing ) { mDoc.execute( cmd ); mLastCmdHash = String::hash( cmd ); - mLastExecuteEventId = getUISceneNode()->getWindow()->getInput()->getEventsSentId(); + mLastExecuteEventId = getInput()->getEventsSentId(); return 1; } } @@ -781,7 +781,7 @@ Uint32 UITextInput::onKeyDown( const KeyEvent& event ) { Uint32 UITextInput::onTextInput( const TextInputEvent& event ) { if ( !mAllowEditing ) return 0; - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || ( input->isLeftControlPressed() && !input->isLeftAltPressed() && @@ -789,7 +789,7 @@ Uint32 UITextInput::onTextInput( const TextInputEvent& event ) { input->isMetaPressed() || ( input->isLeftAltPressed() && !input->isLeftControlPressed() ) ) return 0; - if ( mLastExecuteEventId == getUISceneNode()->getWindow()->getInput()->getEventsSentId() && + if ( mLastExecuteEventId == getInput()->getEventsSentId() && !TextDocument::isTextDocumentCommand( mLastCmdHash ) ) return 0; diff --git a/src/modules/eterm/src/eterm/ui/uiterminal.cpp b/src/modules/eterm/src/eterm/ui/uiterminal.cpp index 2600dc024..b7cb6d3e8 100644 --- a/src/modules/eterm/src/eterm/ui/uiterminal.cpp +++ b/src/modules/eterm/src/eterm/ui/uiterminal.cpp @@ -49,7 +49,7 @@ void UITerminal::draw() { UITerminal::UITerminal( const std::shared_ptr& terminalDisplay ) : UIWidget( "terminal" ), - mKeyBindings( getUISceneNode()->getWindow()->getInput() ), + mKeyBindings( getInput() ), mVScroll( UIScrollBar::NewVertical() ), mTerm( terminalDisplay ) { mFlags |= UI_TAB_STOP | UI_SCROLLABLE; @@ -420,7 +420,7 @@ bool UITerminal::isUsingCustomTitle() const { } Uint32 UITerminal::onTextInput( const TextInputEvent& event ) { - Input* input = getUISceneNode()->getWindow()->getInput(); + Input* input = getInput(); if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) || ( input->isLeftControlPressed() && !input->isLeftAltPressed() && diff --git a/src/tools/ecode/plugins/aiassistant/chatui.cpp b/src/tools/ecode/plugins/aiassistant/chatui.cpp index a90526a27..9e2d463ab 100644 --- a/src/tools/ecode/plugins/aiassistant/chatui.cpp +++ b/src/tools/ecode/plugins/aiassistant/chatui.cpp @@ -197,9 +197,7 @@ static const char* DEFAULT_CHAT_GLOBE = R"xml( )xml"; LLMChatUI::LLMChatUI( PluginManager* manager ) : - UILinearLayout(), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ), - mManager( manager ) { + UILinearLayout(), WidgetCommandExecuter( getInput() ), mManager( manager ) { setClass( "llm_chatui" ); setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp index 18b0a01f0..1b646028a 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -2465,22 +2465,21 @@ bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position const std::optional& info ) { if ( info && mManager->getSplitter()->editorExists( editor ) && !info->result.empty() ) { - editor->runOnMainThread( [this, editor, info = std::move( *info ), - expression]() { - auto mousePos = - editor->getUISceneNode()->getWindow()->getInput()->getMousePos(); - if ( !editor->getScreenRect().contains( mousePos.asFloat() ) ) - return; + editor->runOnMainThread( + [this, editor, info = std::move( *info ), expression]() { + auto mousePos = editor->getInput()->getMousePos(); + if ( !editor->getScreenRect().contains( mousePos.asFloat() ) ) + return; - auto docPos = editor->resolveScreenPosition( mousePos.asFloat() ); - auto range = - editor->getDocument().getWordRangeInPosition( docPos, true ); + auto docPos = editor->resolveScreenPosition( mousePos.asFloat() ); + auto range = + editor->getDocument().getWordRangeInPosition( docPos, true ); - if ( mCurrentHover.contains( range ) ) { - mCurrentHover = range; - displayTooltip( editor, expression, info, mousePos.asFloat() ); - } - } ); + if ( mCurrentHover.contains( range ) ) { + mCurrentHover = range; + displayTooltip( editor, expression, info, mousePos.asFloat() ); + } + } ); } } ); }, diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index dfdbff704..d66f3171d 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -644,7 +644,7 @@ bool LSPClientPlugin::onMouseClick( UICodeEditor* editor, const Vector2i& pos, } } - Input* input = editor->getUISceneNode()->getWindow()->getInput(); + Input* input = editor->getInput(); Uint32 mod = input->getSanitizedModState(); if ( mod != ( KEYMOD_LALT | KeyMod::getDefaultModifier() ) || ( flags & EE_BUTTON_LMASK ) == 0 ) return false; @@ -1642,8 +1642,7 @@ void LSPClientPlugin::hideTooltip( UICodeEditor* editor ) { } static TextPosition currentMouseTextPosition( UICodeEditor* editor ) { - return editor->resolveScreenPosition( - editor->getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() ); + return editor->resolveScreenPosition( editor->getInput()->getMousePos().asFloat() ); } void LSPClientPlugin::tryHideTooltip( UICodeEditor* editor, const Vector2i& position ) { diff --git a/src/tools/ecode/uistatusbar.cpp b/src/tools/ecode/uistatusbar.cpp index e16dcab3e..650eff6e2 100644 --- a/src/tools/ecode/uistatusbar.cpp +++ b/src/tools/ecode/uistatusbar.cpp @@ -1,9 +1,9 @@ +#include "uistatusbar.hpp" #include "globalsearchcontroller.hpp" #include "plugins/plugincontextprovider.hpp" #include "statusappoutputcontroller.hpp" #include "statusbuildoutputcontroller.hpp" #include "statusterminalcontroller.hpp" -#include "uistatusbar.hpp" #include "universallocator.hpp" #include #include @@ -73,8 +73,7 @@ UIStatusBar* UIStatusBar::New() { } UIStatusBar::UIStatusBar() : - UILinearLayout( "statusbar", UIOrientation::Horizontal ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + UILinearLayout( "statusbar", UIOrientation::Horizontal ), WidgetCommandExecuter( getInput() ) {} void UIStatusBar::updateState() { forEachChild( [this]( Node* node ) { diff --git a/src/tools/ecode/uiwelcomescreen.cpp b/src/tools/ecode/uiwelcomescreen.cpp index 195414c1c..cc68e42e8 100644 --- a/src/tools/ecode/uiwelcomescreen.cpp +++ b/src/tools/ecode/uiwelcomescreen.cpp @@ -186,9 +186,7 @@ bool UIWelcomeScreen::isType( const Uint32& type ) const { } UIWelcomeScreen::UIWelcomeScreen( App* app ) : - UIRelativeLayout(), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ), - mApp( app ) { + UIRelativeLayout(), WidgetCommandExecuter( getInput() ), mApp( app ) { setId( "welcome_ecode" ); addClass( "welcome_tab" ); setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); diff --git a/src/tools/ecode/widgetcommandexecuter.hpp b/src/tools/ecode/widgetcommandexecuter.hpp index 8829b66c6..cc87cca02 100644 --- a/src/tools/ecode/widgetcommandexecuter.hpp +++ b/src/tools/ecode/widgetcommandexecuter.hpp @@ -11,7 +11,7 @@ class UISearchBar : public UILinearLayout, public WidgetCommandExecuter { UISearchBar() : UILinearLayout( "searchbar", UIOrientation::Horizontal ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -23,7 +23,7 @@ class UILocateBar : public UILinearLayout, public WidgetCommandExecuter { static UILocateBar* New() { return eeNew( UILocateBar, () ); } UILocateBar() : UILinearLayout( "locatebar", UIOrientation::Horizontal ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -36,7 +36,7 @@ class UIGlobalSearchBar : public UILinearLayout, public WidgetCommandExecuter { UIGlobalSearchBar() : UILinearLayout( "globalsearchbar", UIOrientation::Vertical ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -47,9 +47,7 @@ class UIMainLayout : public UIRelativeLayout, public WidgetCommandExecuter { public: static UIMainLayout* New() { return eeNew( UIMainLayout, () ); } - UIMainLayout() : - UIRelativeLayout( "mainlayout" ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + UIMainLayout() : UIRelativeLayout( "mainlayout" ), WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -63,8 +61,7 @@ class UIRelativeLayoutCommandExecuter : public UIRelativeLayout, public WidgetCo } UIRelativeLayoutCommandExecuter() : - UIRelativeLayout( "rellayce" ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + UIRelativeLayout( "rellayce" ), WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -79,7 +76,7 @@ class UIHLinearLayoutCommandExecuter : public UILinearLayout, public WidgetComma UIHLinearLayoutCommandExecuter() : UILinearLayout( "hboxce", UIOrientation::Horizontal ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event ); @@ -93,8 +90,7 @@ class UIVLinearLayoutCommandExecuter : public UILinearLayout, public WidgetComma } UIVLinearLayoutCommandExecuter() : - UILinearLayout( "vboxce", UIOrientation::Vertical ), - WidgetCommandExecuter( getUISceneNode()->getWindow()->getInput() ) {} + UILinearLayout( "vboxce", UIOrientation::Vertical ), WidgetCommandExecuter( getInput() ) {} virtual Uint32 onKeyDown( const KeyEvent& event ) { return WidgetCommandExecuter::onKeyDown( event );