Skip to content

Commit

Permalink
Added show/hide shortcut to functions filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hteso committed May 18, 2017
1 parent 1cf395d commit f662360
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/widgets/functionswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QDebug>
#include <QString>
#include <QResource>
#include <QShortcut>

FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *import_addresses, bool nested, QFont default_font, QFont highlight_font, MainWindow *main, QObject *parent)
: QAbstractItemModel(parent),
Expand Down Expand Up @@ -329,6 +330,19 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
// Radare core found in:
this->main = main;

// leave the filter visible by default so users know it exists
//ui->filterLineEdit->setVisible(false);

// Ctrl-F to show/hide the filter entry
QShortcut *search_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this);
connect(search_shortcut, SIGNAL(activated()), this, SLOT(toggle_visibility()));
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);

// Esc to clear the filter entry
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clear_filter()));
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);

QFontInfo font_info = ui->functionsTreeView->fontInfo();
QFont default_font = QFont(font_info.family(), font_info.pointSize());
QFont highlight_font = QFont(font_info.family(), font_info.pointSize(), QFont::Bold);
Expand Down Expand Up @@ -602,3 +616,22 @@ void FunctionsWidget::setScrollMode()
{
qhelpers::setVerticalScrollMode(ui->functionsTreeView);
}

void FunctionsWidget::toggle_visibility() {
if (ui->filterLineEdit->isVisible()) {
ui->filterLineEdit->setVisible(false);
ui->functionsTreeView->setFocus();
} else {
ui->filterLineEdit->setVisible(true);
ui->filterLineEdit->setFocus();
}
}

void FunctionsWidget::clear_filter() {
if (ui->filterLineEdit->text() == "") {
ui->filterLineEdit->setVisible(false);
ui->functionsTreeView->setFocus();
} else {
ui->filterLineEdit->setText("");
}
}
5 changes: 4 additions & 1 deletion src/widgets/functionswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class FunctionModel : public QAbstractItemModel
private slots:
void cursorAddressChanged(RVA addr);
void functionRenamed(const QString &prev_name, const QString &new_name);

};


Expand Down Expand Up @@ -104,6 +103,10 @@ private slots:

void on_actionVertical_triggered();

void toggle_visibility();

void clear_filter();

protected:
void resizeEvent(QResizeEvent *event) override;

Expand Down
3 changes: 3 additions & 0 deletions src/widgets/functionswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ QToolTip {
<property name="placeholderText">
<string>Quick Filter</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down

0 comments on commit f662360

Please sign in to comment.