diff --git a/src/logdata/src/logdataoperation.cpp b/src/logdata/src/logdataoperation.cpp index 2bb1b3393..bd6b6910b 100644 --- a/src/logdata/src/logdataoperation.cpp +++ b/src/logdata/src/logdataoperation.cpp @@ -122,7 +122,7 @@ void OperationQueue::tryStartOperation() beforeOperationStart_(); operation.start( worker_.get() ); }, - [this]( absl::monostate ) { LOG_INFO << "no operation to start"; } ), + []( absl::monostate ) { LOG_INFO << "no operation to start"; } ), executingOperation_ ); } diff --git a/src/ui/include/abstractlogview.h b/src/ui/include/abstractlogview.h index 30f6d00f9..9fb5dade3 100644 --- a/src/ui/include/abstractlogview.h +++ b/src/ui/include/abstractlogview.h @@ -384,6 +384,7 @@ class AbstractLogView : public QAbstractScrollArea, public SearchableWidgetInter LineNumber searchStart_; LineNumber searchEnd_; + OptionalLineNumber contextMenuLine_; OptionalLineNumber selectionStart_; // Text handling diff --git a/src/ui/src/abstractlogview.cpp b/src/ui/src/abstractlogview.cpp index c9d7c3fe9..96a1527ff 100644 --- a/src/ui/src/abstractlogview.cpp +++ b/src/ui/src/abstractlogview.cpp @@ -316,10 +316,12 @@ void AbstractLogView::mousePressEvent( QMouseEvent* mouseEvent ) textAreaCache_.invalid_ = true; } else if ( mouseEvent->button() == Qt::RightButton ) { - // Prepare the popup depending on selection type - if ( selection_.isSingleLine() ) { - copyAction_->setText( "&Copy this line" ); + contextMenuLine_ = convertCoordToLine( mouseEvent->y() ); + if ( contextMenuLine_.has_value() && contextMenuLine_ >= logData->getNbLine() ) { + contextMenuLine_ = {}; + } + if ( contextMenuLine_.has_value() ) { setSearchStartAction_->setEnabled( true ); setSearchEndAction_->setEnabled( true ); @@ -327,9 +329,6 @@ void AbstractLogView::mousePressEvent( QMouseEvent* mouseEvent ) setSelectionEndAction_->setEnabled( !!selectionStart_ ); } else { - copyAction_->setText( "&Copy" ); - copyAction_->setStatusTip( tr( "Copy the selection" ) ); - setSearchStartAction_->setEnabled( false ); setSearchEndAction_->setEnabled( false ); @@ -337,6 +336,15 @@ void AbstractLogView::mousePressEvent( QMouseEvent* mouseEvent ) setSelectionEndAction_->setEnabled( false ); } + // Prepare the popup depending on selection type + if ( selection_.isSingleLine() || contextMenuLine_.has_value() ) { + copyAction_->setText( "&Copy this line" ); + } + else { + copyAction_->setText( "&Copy" ); + copyAction_->setStatusTip( tr( "Copy the selection" ) ); + } + if ( selection_.isPortion() ) { findNextAction_->setEnabled( true ); findPreviousAction_->setEnabled( true ); @@ -1166,32 +1174,39 @@ void AbstractLogView::updateSearchLimits() void AbstractLogView::setSearchStart() { - const auto selectedLine = selection_.selectedLine(); searchStart_ - = selectedLine.has_value() ? displayLineNumber( *selectedLine ) - 1_lcount : 0_lnum; + = contextMenuLine_.has_value() ? displayLineNumber( *contextMenuLine_ ) - 1_lcount : 0_lnum; updateSearchLimits(); } void AbstractLogView::setSearchEnd() { - const auto selectedLine = selection_.selectedLine(); - searchEnd_ = selectedLine.has_value() ? displayLineNumber( *selectedLine ) - : LineNumber( logData->getNbLine().get() ); + searchEnd_ = contextMenuLine_.has_value() ? displayLineNumber( *contextMenuLine_ ) + : LineNumber( logData->getNbLine().get() ); updateSearchLimits(); } void AbstractLogView::setSelectionStart() { - selectionStart_ = selection_.selectedLine(); + selectionStart_ = contextMenuLine_; + if ( selectionStart_.has_value() ) { + selection_.selectLine( *selectionStart_ ); + emit updateLineNumber( *selectionStart_ ); + emit newSelection( *selectionStart_ ); + + textAreaCache_.invalid_ = true; + update(); + } } void AbstractLogView::setSelectionEnd() { - auto selectionEnd = selection_.selectedLine(); + const auto selectionEnd = contextMenuLine_; if ( selectionStart_ && selectionEnd ) { selection_.selectRange( *selectionStart_, *selectionEnd ); selectionStart_ = {}; + textAreaCache_.invalid_ = true; update(); } diff --git a/src/utils/include/dispatch_to.h b/src/utils/include/dispatch_to.h index 889856ff9..2abb3f5bf 100644 --- a/src/utils/include/dispatch_to.h +++ b/src/utils/include/dispatch_to.h @@ -17,14 +17,15 @@ * along with klogg. If not, see . */ - #ifndef KLOGG_DISPATCH_TO -#include #include +#include #include #include +#include "log.h" + // by // https://github.com/KubaO/stackoverflown/blob/master/questions/metacall-21646467/main.cpp #if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 ) @@ -49,29 +50,30 @@ struct FEvent : public QEvent { FEvent( Fun&& fun ) : QEvent( QEvent::None ) - , fun( std::move( fun ) ) + , fun_( std::move( fun ) ) { } FEvent( const Fun& fun ) : QEvent( QEvent::None ) - , fun( fun ) + , fun_( fun ) { } ~FEvent() { - fun(); + fun_(); } private: - Fun fun; + Fun fun_; }; } // namespace detail template static void dispatchToObject( F&& fun, QObject* obj = qApp ) { - if ( qobject_cast( obj ) ) - qWarning() << "posting a call to a thread object - consider using postToThread"; + if ( qobject_cast( obj ) ) { + LOG_WARNING << "posting a call to a thread object - consider using postToThread"; + } QCoreApplication::postEvent( obj, new detail::FEvent( std::forward( fun ) ) ); }