Skip to content

Commit

Permalink
[ci release] feature: Add go to line action in menu (#334)
Browse files Browse the repository at this point in the history
This adds "go to line" action to Edit menu. Line numbers are interpreted
as lines of main view. Filtered view goes to line that is nearest match.
  • Loading branch information
variar committed Jun 9, 2021
1 parent 406e4ba commit 4c29f49
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/ui/include/abstractlogview.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class AbstractLogView : public QAbstractScrollArea, public SearchableWidgetInter
public slots:
// Makes the widget select and display the passed line.
// Scrolling as necessary
void trySelectLine( LineNumber newLine );
void selectAndDisplayLine( LineNumber line );

// Use the current QFP to go and select the next match.
Expand Down
1 change: 1 addition & 0 deletions src/ui/include/crawlerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class CrawlerWidget : public QSplitter,
void setEncoding( std::optional<int> mib );

void focusSearchEdit();
void goToLine();

// Instructs the widget to reconfigure itself because Config() has changed.
void applyConfiguration();
Expand Down
1 change: 1 addition & 0 deletions src/ui/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class MainWindow : public QMainWindow {
QAction* exitAction;
QAction* copyAction;
QAction* selectAllAction;
QAction* goToLineAction;
QAction* findAction;
QAction* clearLogAction;
QAction* copyPathToClipboardAction;
Expand Down
33 changes: 12 additions & 21 deletions src/ui/src/abstractlogview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

#include <tbb/flow_graph.h>

#include "data/linetypes.h"
#include "data/regularexpressionpattern.h"
#include "log.h"

Expand Down Expand Up @@ -586,28 +587,9 @@ void AbstractLogView::doRegisterShortcuts()

registerShortcut( ShortcutAction::LogViewMark, [ this ]() { markSelected(); } );

auto trySelectLine = [ this ]( uint32_t newLine ) {
auto lineToSelect = LineNumber( static_cast<LineNumber::UnderlyingType>( newLine ) );
if ( lineToSelect >= logData_->getNbLine() ) {
lineToSelect = lineToSelect - 1_lcount;
}

selectAndDisplayLine( lineToSelect );
};

registerShortcut( ShortcutAction::LogViewJumpToLine, [ this, trySelectLine ]() {
bool isLineSelected = true;
const auto newLine = QInputDialog::getInt( this, "Jump to line", "Line", 1, 1,
static_cast<int>( logData_->getNbLine().get() ),
1, &isLineSelected );
if ( isLineSelected ) {
trySelectLine( static_cast<uint32_t>( newLine - 1 ) );
}
} );

registerShortcut( ShortcutAction::LogViewJumpToLineNumber, [ this, trySelectLine ]() {
registerShortcut( ShortcutAction::LogViewJumpToLineNumber, [ this ]() {
const auto newLine = qMax( 0, digitsBuffer_.content() - 1 );
trySelectLine( static_cast<uint32_t>( newLine ) );
trySelectLine( LineNumber( static_cast<LineNumber::UnderlyingType>( newLine ) ) );
} );

registerShortcut( ShortcutAction::LogViewExitView, [ this ]() { emit exitView(); } );
Expand Down Expand Up @@ -1324,6 +1306,15 @@ void AbstractLogView::selectAll()
update();
}

void AbstractLogView::trySelectLine( LineNumber lineToSelect )
{
if ( lineToSelect >= logData_->getNbLine() ) {
lineToSelect = lineToSelect - 1_lcount;
}

selectAndDisplayLine( lineToSelect );
}

void AbstractLogView::selectAndDisplayLine( LineNumber line )
{
disableFollow();
Expand Down
39 changes: 27 additions & 12 deletions src/ui/src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <QFile>
#include <QFileInfo>
#include <QHeaderView>
#include <QInputDialog>
#include <QJsonDocument>
#include <QKeySequence>
#include <QLineEdit>
Expand Down Expand Up @@ -280,6 +281,20 @@ void CrawlerWidget::focusSearchEdit()
searchLineEdit_->setFocus( Qt::ShortcutFocusReason );
}

void CrawlerWidget::goToLine()
{
bool isLineSelected = true;
const auto newLine = QInputDialog::getInt( this, "Jump to line", "Line", 1, 1,
static_cast<int>( logData_->getNbLine().get() ), 1,
&isLineSelected );
if ( isLineSelected ) {
const auto selectedLine
= LineNumber( static_cast<LineNumber::UnderlyingType>( newLine - 1 ) );
filteredView_->trySelectLine( logFilteredData_->getLineIndexNumber( selectedLine ) );
logMainView_->trySelectLine( selectedLine );
}
}

//
// Protected functions
//
Expand Down Expand Up @@ -1157,20 +1172,20 @@ void CrawlerWidget::registerShortcuts()
const auto& config = Configuration::get();
const auto& configuredShortcuts = config.shortcuts();

ShortcutAction::registerShortcut( configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerChangeVisibility, [ this ]() {
visibilityBox_->setCurrentIndex(
( visibilityBox_->currentIndex() + 1 )
% visibilityBox_->count() );
} );
ShortcutAction::registerShortcut(
configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerChangeVisibility, [ this ]() {
visibilityBox_->setCurrentIndex( ( visibilityBox_->currentIndex() + 1 )
% visibilityBox_->count() );
} );

ShortcutAction::registerShortcut( configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerIncreseTopViewSize,
[ this ]() { changeTopViewSize( 1 ); } );
ShortcutAction::registerShortcut(
configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerIncreseTopViewSize, [ this ]() { changeTopViewSize( 1 ); } );

ShortcutAction::registerShortcut( configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerDecreaseTopViewSize,
[ this ]() { changeTopViewSize( -1 ); } );
ShortcutAction::registerShortcut(
configuredShortcuts, shortcuts_, this, Qt::WidgetWithChildrenShortcut,
ShortcutAction::CrawlerDecreaseTopViewSize, [ this ]() { changeTopViewSize( -1 ); } );

logMainView_->registerShortcuts();
filteredView_->registerShortcuts();
Expand Down
8 changes: 8 additions & 0 deletions src/ui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <iostream>

#include <cmath>
#include <qaction.h>

#ifdef Q_OS_WIN
#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -315,6 +316,10 @@ void MainWindow::createActions()
selectAllAction->setStatusTip( tr( "Select all the text" ) );
connect( selectAllAction, &QAction::triggered, [ this ]( auto ) { this->selectAll(); } );

goToLineAction = new QAction( tr( "Go to line..." ), this );
goToLineAction->setStatusTip( tr( "Scrolls selected main view to specified line" ) );
signalMux_.connect( goToLineAction, SIGNAL( triggered() ), SLOT( goToLine() ) );

findAction = new QAction( tr( "&Find..." ), this );
findAction->setStatusTip( tr( "Find the text" ) );
connect( findAction, &QAction::triggered, [ this ]( auto ) { this->find(); } );
Expand Down Expand Up @@ -507,6 +512,7 @@ void MainWindow::updateShortcuts()
setShortcuts( stopAction, ShortcutAction::MainWindowStop );
setShortcuts( showScratchPadAction, ShortcutAction::MainWindowScratchpad );
setShortcuts( selectOpenFileAction, ShortcutAction::MainWindowSelectOpenFile );
setShortcuts( goToLineAction, ShortcutAction::LogViewJumpToLine );
}

void MainWindow::loadIcons()
Expand Down Expand Up @@ -545,6 +551,8 @@ void MainWindow::createMenus()
editMenu->addSeparator();
editMenu->addAction( findAction );
editMenu->addSeparator();
editMenu->addAction( goToLineAction );
editMenu->addSeparator();
editMenu->addAction( copyPathToClipboardAction );
editMenu->addAction( openContainingFolderAction );
editMenu->addSeparator();
Expand Down

0 comments on commit 4c29f49

Please sign in to comment.