Skip to content

Commit

Permalink
Minor fixes in UITreeView.
Browse files Browse the repository at this point in the history
Minor fixes in debugger and some new menues.
  • Loading branch information
SpartanJ committed Jan 22, 2025
1 parent 40d21de commit c945b0b
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 70 deletions.
2 changes: 2 additions & 0 deletions include/eepp/ui/uitreeview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class EE_API UITreeView : public UIAbstractTableView {

void setDisableCellClipping( bool disableCellCliping );

void clearViewMetadata();

protected:
enum class IterationDecision {
Continue,
Expand Down
5 changes: 5 additions & 0 deletions src/eepp/ui/abstract/uiabstracttableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ void UIAbstractTableView::updateColumnsWidth() {
if ( columnData( col ).width != width ) {
columnData( col ).width = width;
updateHeaderSize();

ColumnData& colData = columnData( col );
if ( colData.widget )
colData.widget->setPixelsSize( colData.width, getHeaderHeight() );

onColumnSizeChange( col );
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/eepp/ui/uicodeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,9 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags )
} else if ( flags & EE_BUTTON_WLMASK ) {
setScrollX( mScroll.x - mMouseWheelScroll );
} else if ( !minimapHover && ( flags & EE_BUTTON_RMASK ) ) {
onCreateContextMenu( position, flags );
Vector2f localPos( convertToNodeSpace( position.asFloat() ) );
if ( localPos.x >= mPaddingPx.Left + getGutterWidth() && localPos.y >= mPluginsTopSpace )
onCreateContextMenu( position, flags );
}

return UIWidget::onMouseUp( position, flags );
Expand Down
8 changes: 6 additions & 2 deletions src/eepp/ui/uitreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void UITreeView::traverseTree( TreeViewCallback callback ) const {
}

void UITreeView::createOrUpdateColumns( bool resetColumnData ) {
updateContentSize();
if ( !getModel() )
return;
UIAbstractTableView::createOrUpdateColumns( resetColumnData );
updateContentSize();
}

size_t UITreeView::getItemCount() const {
Expand Down Expand Up @@ -184,8 +184,8 @@ UIWidget* UITreeView::setupCell( UITableCell* widget, UIWidget* rowWidget,
widget->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed );
widget->setTextAlign( UI_HALIGN_LEFT );
widget->setCurIndex( index );
bindNavigationClick( widget );
if ( index.column() == (Int64)getModel()->treeColumn() ) {
bindNavigationClick( widget );
widget->onClick( [this]( const MouseEvent* mouseEvent ) {
if ( mSingleClickNavigation )
return;
Expand Down Expand Up @@ -740,6 +740,10 @@ void UITreeView::setDisableCellClipping( bool disableCellClipping ) {
mDisableCellClipping = disableCellClipping;
}

void UITreeView::clearViewMetadata() {
mViewMetadata.clear();
}

void UITreeView::onSortColumn( const size_t& ) {
// Do nothing.
return;
Expand Down
71 changes: 66 additions & 5 deletions src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "debuggerclientlistener.hpp"
#include "../../notificationcenter.hpp"
#include "../../statusappoutputcontroller.hpp"
#include "debuggerclientlistener.hpp"
#include "debuggerplugin.hpp"
#include "eepp/window/clipboard.hpp"
#include "models/stackmodel.hpp"
#include "models/threadsmodel.hpp"
#include "models/variablesmodel.hpp"
Expand Down Expand Up @@ -87,13 +88,73 @@ void DebuggerClientListener::initUI() {
uiVariables->setModel( mVariablesHolder->getModel() );
uiVariables->removeEventsOfType( Event::OnModelEvent );
uiVariables->onModelEvent( [this]( const ModelEvent* modelEvent ) {
auto idx( modelEvent->getModelIndex() );
if ( modelEvent->getModelEventType() == Abstract::ModelEventType::OpenTree ) {
ModelVariableNode* node =
static_cast<ModelVariableNode*>( modelEvent->getModelIndex().internalData() );
ModelVariableNode* node = static_cast<ModelVariableNode*>( idx.internalData() );
mClient->variables( node->var.variablesReference );
mVariablesHolder->saveExpandedState( modelEvent->getModelIndex() );
mVariablesHolder->saveExpandedState( idx );
} else if ( modelEvent->getModelEventType() == Abstract::ModelEventType::CloseTree ) {
mVariablesHolder->removeExpandedState( modelEvent->getModelIndex() );
mVariablesHolder->removeExpandedState( idx );
} else if ( modelEvent->getModelEventType() == Abstract::ModelEventType::OpenMenu &&
idx.isValid() ) {

auto context = mPlugin->getPluginContext();
UIPopUpMenu* menu = UIPopUpMenu::New();

ModelVariableNode* node = static_cast<ModelVariableNode*>( idx.internalData() );
Variable var( node->var );

menu->add( context->i18n( "debugger_copy_variable_value", "Copy Value" ),
context->findIcon( "copy" ) )
->setId( "debugger_copy_variable_value" );

menu->add( context->i18n( "debugger_copy_variable_name", "Copy Name" ),
context->findIcon( "copy" ) )
->setId( "debugger_copy_variable_name" );

if ( var.type ) {
menu->add( context->i18n( "debugger_copy_variable_type", "Copy Type" ),
context->findIcon( "copy" ) )
->setId( "debugger_copy_variable_type" );
}

if ( var.evaluateName ) {
menu->add( context->i18n( "debugger_copy_variable_evaluate_name",
"Copy Evaluate Name" ),
context->findIcon( "copy" ) )
->setId( "debugger_copy_variable_evaluate_name" );
}

if ( var.memoryReference ) {
menu->add( context->i18n( "debugger_copy_variable_memory_reference",
"Copy Memory Reference" ),
context->findIcon( "copy" ) )
->setId( "debugger_copy_variable_memory_reference" );
}

menu->on( Event::OnItemClicked, [this, var = std::move( var )]( const Event* event ) {
UIMenuItem* item = event->getNode()->asType<UIMenuItem>();
std::string id( item->getId() );
if ( id == "debugger_copy_variable_value" ) {
mPlugin->getUISceneNode()->getWindow()->getClipboard()->setText( var.value );
} else if ( id == "debugger_copy_variable_name" ) {
mPlugin->getUISceneNode()->getWindow()->getClipboard()->setText( var.name );
} else if ( id == "debugger_copy_variable_type" ) {
mPlugin->getUISceneNode()->getWindow()->getClipboard()->setText( *var.type );
} else if ( id == "debugger_copy_variable_evaluate_name" ) {
mPlugin->getUISceneNode()->getWindow()->getClipboard()->setText(
*var.evaluateName );
} else if ( id == "debugger_copy_variable_memory_reference" ) {
mPlugin->getUISceneNode()->getWindow()->getClipboard()->setText(
*var.memoryReference );
}
} );

Vector2f pos( context->getWindow()->getInput()->getMousePos().asFloat() );
menu->nodeToWorldTranslation( pos );
UIMenu::findBestMenuPos( pos, menu );
menu->setPixelsPosition( pos );
menu->show();
}
} );

Expand Down
108 changes: 53 additions & 55 deletions src/tools/ecode/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ void DebuggerPlugin::onLoadProject( const std::string& projectFolder,
if ( !FileSystem::fileGet( debuggerStatePath, data ) )
return;

auto sdc = getStatusDebuggerController();

json j;
try {
j = json::parse( data, nullptr, true, true );
Expand All @@ -199,6 +201,9 @@ void DebuggerPlugin::onLoadProject( const std::string& projectFolder,
}
}
}

if ( sdc && sdc->getWidget() && sdc->getUIExpressions() )
sdc->getUIExpressions()->setModel( mExpressionsHolder->getModel() );
}

if ( config.contains( "breakpoints" ) && config["breakpoints"].is_object() ) {
Expand All @@ -221,13 +226,16 @@ void DebuggerPlugin::onLoadProject( const std::string& projectFolder,
mBreakpointsModel =
std::make_shared<BreakpointsModel>( mBreakpoints, getUISceneNode() );
}

if ( sdc && sdc->getWidget() && sdc->getUIBreakpoints() )
sdc->getUIBreakpoints()->setModel( mBreakpointsModel );
}
}
} catch ( const json::exception& e ) {
Log::error(
"DebuggerPlugin::onLoadProject - Error parsing config from path %s, error: %s, config "
"file content:\n%s",
debuggerStatePath.c_str(), e.what(), data.c_str() );
debuggerStatePath, e.what(), data );
}
}

Expand All @@ -246,8 +254,11 @@ void DebuggerPlugin::resetExpressions() {
if ( !mExpressionsHolder )
return;
mExpressionsHolder->clear( true );
std::vector<ModelVariableNode::NodePtr> childs;
childs.reserve( mExpressions.size() );
for ( const auto& expression : mExpressions )
mExpressionsHolder->addChild( std::make_shared<ModelVariableNode>( expression, 0 ) );
childs.emplace_back( std::make_shared<ModelVariableNode>( expression, 0 ) );
mExpressionsHolder->addChilds( childs );
}

void DebuggerPlugin::closeProject() {
Expand Down Expand Up @@ -760,8 +771,7 @@ void DebuggerPlugin::removeExpression( const std::string& name ) {
resetExpressions();
}

void DebuggerPlugin::openExpressionMenu( UITreeView* uiExpressions, ModelIndex idx,
bool fromMouseClick ) {
void DebuggerPlugin::openExpressionMenu( ModelIndex idx ) {
UIPopUpMenu* menu = UIPopUpMenu::New();
auto context = getPluginContext();

Expand Down Expand Up @@ -801,19 +811,10 @@ void DebuggerPlugin::openExpressionMenu( UITreeView* uiExpressions, ModelIndex i
}
} );

UITableCell* cell = uiExpressions->getCellFromIndex( idx );
if ( fromMouseClick || cell == nullptr ) {
Vector2f pos( context->getWindow()->getInput()->getMousePos().asFloat() );
menu->nodeToWorldTranslation( pos );
UIMenu::findBestMenuPos( pos, menu );
menu->setPixelsPosition( pos );
} else {
Vector2f pos( 0, cell->getPixelsSize().getHeight() );
cell->nodeToWorldTranslation( pos );
UIMenu::findBestMenuPos( pos, menu );
menu->setPixelsPosition( pos );
}

Vector2f pos( context->getWindow()->getInput()->getMousePos().asFloat() );
menu->nodeToWorldTranslation( pos );
UIMenu::findBestMenuPos( pos, menu );
menu->setPixelsPosition( pos );
menu->show();
}
void DebuggerPlugin::buildStatusBar() {
Expand Down Expand Up @@ -842,9 +843,9 @@ void DebuggerPlugin::buildStatusBar() {
UITreeView* uiExpressions = sdc->getUIExpressions();
uiExpressions->setModel( mExpressionsHolder->getModel() );
uiExpressions->removeEventsOfType( Event::OnModelEvent );
uiExpressions->onModelEvent( [this, uiExpressions]( const ModelEvent* modelEvent ) {
uiExpressions->onModelEvent( [this]( const ModelEvent* modelEvent ) {
if ( modelEvent->getModelEventType() == Abstract::ModelEventType::OpenMenu ) {
openExpressionMenu( uiExpressions, modelEvent->getModelIndex(), true );
openExpressionMenu( modelEvent->getModelIndex() );
} else if ( mDebugger && mListener &&
modelEvent->getModelEventType() == Abstract::ModelEventType::OpenTree ) {
ModelVariableNode* node =
Expand All @@ -861,11 +862,8 @@ void DebuggerPlugin::buildStatusBar() {
}
} );
uiExpressions->removeEventsOfType( Event::MouseClick );
uiExpressions->onClick(
[this, uiExpressions]( const MouseEvent* ) {
openExpressionMenu( uiExpressions, {}, true );
},
MouseButton::EE_BUTTON_RIGHT );
uiExpressions->onClick( [this]( const MouseEvent* ) { openExpressionMenu( {} ); },
MouseButton::EE_BUTTON_RIGHT );

auto uiBreakpoints = sdc->getUIBreakpoints();
if ( nullptr == uiBreakpoints->onBreakpointEnabledChange ) {
Expand Down Expand Up @@ -947,8 +945,7 @@ void DebuggerPlugin::sendPendingBreakpoints() {
for ( const auto& pbp : mPendingBreakpoints )
sendFileBreakpoints( pbp );
mPendingBreakpoints.clear();
if ( mDebugger )
mDebugger->resume( mListener->getCurrentThreadId() );
resume( mListener->getCurrentThreadId() );
}

void DebuggerPlugin::sendFileBreakpoints( const std::string& filePath ) {
Expand Down Expand Up @@ -1227,7 +1224,7 @@ void DebuggerPlugin::onRegisterDocument( TextDocument* doc ) {
doc->setCommand( "debugger-continue-interrupt", [this] {
if ( mDebugger && mListener ) {
if ( mListener->isStopped() ) {
mDebugger->resume( mListener->getCurrentThreadId() );
resume( mListener->getCurrentThreadId() );
} else {
mDebugger->pause( 1 );
}
Expand Down Expand Up @@ -1763,6 +1760,18 @@ UIWindow* DebuggerPlugin::processPicker() {
return win;
}

bool DebuggerPlugin::resume( int threadId, bool singleThread ) {
mHoverExpressionsHolder->clear( true );

if ( mHoverTooltip && mHoverTooltip->isVisible() )
mHoverTooltip->hide();

if ( !mDebugger )
return false;

return mDebugger->resume( threadId, singleThread );
}

std::optional<Command>
DebuggerPlugin::debuggerBinaryExists( const std::string& debugger,
std::optional<DapRunConfig> optRunConfig ) {
Expand Down Expand Up @@ -2025,17 +2034,11 @@ static Action::UniqueID getMouseMoveHash( UICodeEditor* editor ) {
reinterpret_cast<Action::UniqueID>( editor ) );
}

void DebuggerPlugin::hideTooltip( UICodeEditor* ) {
// if ( mHoverTooltip ) {
// mHoverTooltip->hide();
// }
}

void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& expression,
const EvaluateInfo& info, const Vector2f& position ) {
if ( mHoverTooltip == nullptr ) {
UIWindow* win =
UIWindow::NewOpt( UIMessageBox::WindowBaseContainerType::VERTICAL_LINEAR_LAYOUT );
UIWindow* win = UIWindow::New();
win->setId( "debugger_hover_window" );
win->setMinWindowSize( 400, 250 );
win->setKeyBindingCommand( "closeWindow", [this, win, editor] {
win->closeWindow();
Expand All @@ -2044,20 +2047,26 @@ void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& ex
editor->setFocus();
} );
win->getKeyBindings().addKeybind( { KEY_ESCAPE }, "closeWindow" );
win->setWindowFlags( UI_WIN_NO_DECORATION | UI_WIN_SHADOW | UI_WIN_EPHEMERAL );
win->setWindowFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS |
UI_WIN_SHADOW | UI_WIN_EPHEMERAL | UI_WIN_RESIZEABLE |
UI_WIN_DRAGABLE_CONTAINER | UI_WIN_SHARE_ALPHA_WITH_CHILDS );
win->center();
win->on( Event::OnWindowClose, [this]( auto ) { mHoverTooltip = nullptr; } );
win->on( Event::OnWindowReady, [win]( auto ) { win->setFocus(); } );

UILinearLayout* vbox = UILinearLayout::NewVertical();
vbox->setParent( win->getContainer() );
vbox->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent );

UITreeView* tv = UITreeView::New();
tv->setId( "debugger_hover_treeview" );
tv->setHeadersVisible( false );
tv->setAutoExpandOnSingleColumn( true );
tv->setAutoColumnsWidth( true );
tv->setFitAllColumnsToWidget( true );
tv->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::Fixed );
tv->setLayoutWeight( 1 );
tv->setParent( win->getContainer() );
tv->setParent( vbox );
tv->setModel( mHoverExpressionsHolder->getModel() );
tv->expandAll();
tv->setFocusOnSelection( false );

tv->on( Event::OnModelEvent, [this]( const Event* event ) {
Expand All @@ -2078,6 +2087,10 @@ void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& ex
mHoverTooltip = win;
}

if ( editor->getTooltip() )
editor->getTooltip()->hide();

mHoverTooltip->find( "debugger_hover_treeview" )->asType<UITreeView>()->clearViewMetadata();
mHoverExpressionsHolder->clear( true );

Variable var;
Expand All @@ -2098,25 +2111,11 @@ void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& ex
mHoverTooltip->showWhenReady();
}

void DebuggerPlugin::tryHideTooltip( UICodeEditor* editor, const Vector2i& position ) {
if ( ( editor->hasDocument() && editor->getDocument().isLoading() ) ||
!mCurrentHover.isValid() ||
( mCurrentHover.isValid() &&
!mCurrentHover.contains( editor->resolveScreenPosition( position.asFloat() ) ) ) )
hideTooltip( editor );
}

bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position,
const Uint32& flags ) {

if ( !mDebugger || !mListener || !mDebugger->isServerConnected() ||
mDebuggingState != StatusDebuggerController::State::Paused ) {
tryHideTooltip( editor, position );
return false;
}

if ( flags != 0 ) {
tryHideTooltip( editor, position );
mDebuggingState != StatusDebuggerController::State::Paused || flags != 0 ) {
return false;
}

Expand Down Expand Up @@ -2167,7 +2166,6 @@ bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position
} );
},
mHoverDelay, getMouseMoveHash( editor ) );
tryHideTooltip( editor, position );
editor->updateMouseCursor( position.asFloat() );
return true;
}
Expand Down
Loading

0 comments on commit c945b0b

Please sign in to comment.