Skip to content

Commit

Permalink
feat: add more shortcuts (#407, #408)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Dec 18, 2021
1 parent fb478e6 commit e874eb1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/settings/include/shortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ struct ShortcutAction {
static constexpr auto LogViewClearColorLabels = "logview.clear_color_labels";
static constexpr auto LogViewAddNextColorLabel = "logview.add_next_color_label";

static constexpr auto LogViewSendSelectionToScratchpad = "logview.send_selection_to_scratchpad";

static constexpr auto LogViewAddToSearch = "logview.add_to_search";
static constexpr auto LogViewExcludeFromSearch = "logview.exclude_from_search";
static constexpr auto LogViewReplaceSearch = "logview.replace_search";

static const std::map<std::string, QStringList>& defaultShortcuts();

static QStringList defaultShortcuts( const std::string& action );
Expand Down
13 changes: 13 additions & 0 deletions src/settings/src/shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ const std::map<std::string, QStringList>& ShortcutAction::defaultShortcuts()
shortcuts.emplace( LogViewClearColorLabels, QStringList() << "Ctrl+Shift+0" );
shortcuts.emplace( LogViewAddNextColorLabel, QStringList() << "Ctrl+D" );

shortcuts.emplace( LogViewSendSelectionToScratchpad, QStringList() << "Ctrl+Z" );

shortcuts.emplace( LogViewSendSelectionToScratchpad, QStringList() << "Ctrl+Z" );
shortcuts.emplace( LogViewAddToSearch, QStringList() << "Shift+A" );
shortcuts.emplace( LogViewExcludeFromSearch, QStringList() << "Shift+E" );
shortcuts.emplace( LogViewReplaceSearch, QStringList() << "Shift+R" );

return shortcuts;
}();

Expand Down Expand Up @@ -229,6 +236,12 @@ QString ShortcutAction::actionName( const std::string& action )

shortcuts.emplace( LogViewClearColorLabels, "Clear all color labels" );

shortcuts.emplace( LogViewSendSelectionToScratchpad, "Send selection to scratchpad" );

shortcuts.emplace( LogViewAddToSearch, "Add selection to search pattern" );
shortcuts.emplace( LogViewExcludeFromSearch, "Exclude selection from search pattern " );
shortcuts.emplace( LogViewReplaceSearch, "Replace search pattern with selection" );

return shortcuts;
}();

Expand Down
8 changes: 8 additions & 0 deletions src/ui/src/abstractlogview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <memory>
#include <numeric>
#include <optional>
#include <qobjectdefs.h>
#include <qpen.h>
#include <qwidget.h>
#include <string_view>
Expand Down Expand Up @@ -715,6 +716,13 @@ void AbstractLogView::doRegisterShortcuts()
} );

registerShortcut( ShortcutAction::LogViewExitView, [ this ]() { emit exitView(); } );

registerShortcut( ShortcutAction::LogViewSendSelectionToScratchpad,
[ this ]() { emit sendSelectionToScratchpad(); } );

registerShortcut( ShortcutAction::LogViewAddToSearch, [ this ]() { addToSearch(); } );
registerShortcut( ShortcutAction::LogViewExcludeFromSearch, [ this ]() { excludeFromSearch(); } );
registerShortcut( ShortcutAction::LogViewReplaceSearch, [ this ]() { replaceSearch(); } );
}

void AbstractLogView::keyPressEvent( QKeyEvent* keyEvent )
Expand Down
10 changes: 7 additions & 3 deletions src/ui/src/scratchpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ ScratchPad::ScratchPad( QWidget* parent )
&ScratchPad::updateTransformation );
}

void ScratchPad::addData( QString data )
void ScratchPad::addData( QString newData )
{
if ( newData.isEmpty() ) {
return;
}

auto cursor = textEdit_->textCursor();
cursor.insertText( data );
cursor.insertText( QString{QChar::LineFeed} );
cursor.insertText( newData );
cursor.insertText( QString{ QChar::LineFeed } );
}

QString ScratchPad::transformText( const std::function<QString( QString )>& transform )
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/tabbedscratchpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ void TabbedScratchPad::addTab()
tabWidget_->setCurrentIndex( newIndex );
}

void TabbedScratchPad::addData( QString data )
void TabbedScratchPad::addData( QString newData )
{
auto curretScratchPad = qobject_cast<ScratchPad*>( tabWidget_->currentWidget() );
if ( curretScratchPad ) {
curretScratchPad->addData( data );
curretScratchPad->addData( std::move(newData) );
}
}

0 comments on commit e874eb1

Please sign in to comment.