mirror of
https://github.com/KDE/konsole.git
synced 2026-06-11 23:45:09 -04:00
Improve the Keyboard tab and the KeyBindings editor
Summary: - Change updateKeyBindingsList() to select the last edited keybindings scheme after closing the editor dialog - Add a tooltip showing the path of each keybinding scheme, this should lessen the confusion when the scheme description and the file name of the .keytab file are different - Add a button to the Keyboard tab to reset a scheme to its default values, this is only applicable for schemes that exist in both system-wide and user specific locations - Move a lot of the construction of the keybinding editor widgets from EditProfileDialog to KeyBindingEditor - Change the wording from "key bindings list" to "key bindings scheme" to differentiate between a keyboard translator "scheme" and the key bindings "list" on the Keyboard tab KeyBindingEditor: - Make the KeyBindingEditor a QDialog and set Qt::WA_DeleteOnClose - Disallow saving a scheme with an empty description - Add a QLineEdit to show only the rows that have strings matching the text entered in the line edit box - Reimplement sizeHint() to make the dialog slightly smaller than the Edit Profile dialog, for better visibility of the entries KeyboardTranslatorManager: - Make findTranslatorPath() const and public - Make allTranslators() return type const Test Plan: - Editing a key bindings scheme works and closing the dialog selects the edited scheme - Creating a new scheme works as before - "Defaults" button works for system-wide schemes if they were previously edited and saved under the user's home dir - Remove button is only enabled for schemes saved in a dir writable for the user Reviewers: #konsole, hindenburg Reviewed By: #konsole, hindenburg Subscribers: konsole-devel, #konsole Tags: #konsole Differential Revision: https://phabricator.kde.org/D12981
This commit is contained in:
committed by
Kurt Hindenburg
parent
c4baeb5ab1
commit
581df2a23a
@@ -16,34 +16,59 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
*/
|
||||
|
||||
// Own
|
||||
#include "KeyBindingEditor.h"
|
||||
|
||||
// Qt
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QKeyEvent>
|
||||
#include <QIcon>
|
||||
|
||||
// KDE
|
||||
#include <KLocalizedString>
|
||||
#include <KMessageBox>
|
||||
|
||||
// Konsole
|
||||
#include "ui_KeyBindingEditor.h"
|
||||
#include "EditProfileDialog.h"
|
||||
#include "KeyboardTranslator.h"
|
||||
#include "KeyboardTranslatorManager.h"
|
||||
|
||||
using namespace Konsole;
|
||||
|
||||
KeyBindingEditor::KeyBindingEditor(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
QDialog(parent),
|
||||
_ui(nullptr),
|
||||
_translator(new KeyboardTranslator(QString()))
|
||||
_translator(new KeyboardTranslator(QString())),
|
||||
_isNewTranslator(false)
|
||||
{
|
||||
auto layout = new QVBoxLayout;
|
||||
|
||||
auto mainWidget = new QWidget(this);
|
||||
layout->addWidget(mainWidget);
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->button(QDialogButtonBox::Cancel)->setDefault(true);
|
||||
layout->addWidget(buttonBox);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &Konsole::KeyBindingEditor::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
_ui = new Ui::KeyBindingEditor();
|
||||
_ui->setupUi(this);
|
||||
_ui->setupUi(mainWidget);
|
||||
|
||||
// description edit
|
||||
_ui->descriptionEdit->setPlaceholderText(i18nc("@label:textbox", "Enter descriptive label"));
|
||||
connect(_ui->descriptionEdit, &QLineEdit::textChanged, this,
|
||||
&Konsole::KeyBindingEditor::setTranslatorDescription);
|
||||
// filter edit
|
||||
connect(_ui->filterEdit, &QLineEdit::textChanged, this,
|
||||
&Konsole::KeyBindingEditor::filterRows);
|
||||
|
||||
// key bindings table
|
||||
_ui->keyBindingTable->setColumnCount(2);
|
||||
@@ -52,10 +77,7 @@ KeyBindingEditor::KeyBindingEditor(QWidget *parent) :
|
||||
labels << i18n("Key Combination") << i18n("Output");
|
||||
|
||||
_ui->keyBindingTable->setHorizontalHeaderLabels(labels);
|
||||
_ui->keyBindingTable->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
// see also the sizes set in EditProfileDialog::showKeyBindingEditor()
|
||||
_ui->keyBindingTable->setColumnWidth(0, 300);
|
||||
_ui->keyBindingTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
|
||||
_ui->keyBindingTable->verticalHeader()->hide();
|
||||
_ui->keyBindingTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
@@ -79,6 +101,25 @@ KeyBindingEditor::~KeyBindingEditor()
|
||||
delete _translator;
|
||||
}
|
||||
|
||||
void KeyBindingEditor::filterRows(const QString &text)
|
||||
{
|
||||
const int rows = _ui->keyBindingTable->rowCount();
|
||||
|
||||
QList<int> matchedRows;
|
||||
|
||||
for (QTableWidgetItem *matchedItem : _ui->keyBindingTable->findItems(text, Qt::MatchContains)) {
|
||||
matchedRows.append(matchedItem->row());
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
if (matchedRows.contains(i) && _ui->keyBindingTable->isRowHidden(i)) {
|
||||
_ui->keyBindingTable->showRow(i);
|
||||
} else if (!matchedRows.contains(i)) {
|
||||
_ui->keyBindingTable->hideRow(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyBindingEditor::removeSelectedEntry()
|
||||
{
|
||||
QList<QTableWidgetItem *> uniqueList;
|
||||
@@ -178,15 +219,29 @@ QString KeyBindingEditor::description() const
|
||||
return _ui->descriptionEdit->text();
|
||||
}
|
||||
|
||||
void KeyBindingEditor::setup(const KeyboardTranslator *translator)
|
||||
void KeyBindingEditor::setup(const KeyboardTranslator *translator,
|
||||
const QString ¤tProfileTranslator, bool isNewTranslator)
|
||||
{
|
||||
delete _translator;
|
||||
|
||||
_isNewTranslator = isNewTranslator;
|
||||
|
||||
_currentProfileTranslator = currentProfileTranslator;
|
||||
|
||||
_translator = new KeyboardTranslator(*translator);
|
||||
|
||||
// setup description edit
|
||||
// setup description edit line
|
||||
_ui->descriptionEdit->setClearButtonEnabled(true);
|
||||
_ui->descriptionEdit->setText(translator->description());
|
||||
// setup filter edit line
|
||||
_ui->filterEdit->setClearButtonEnabled(true);
|
||||
|
||||
if (_isNewTranslator) {
|
||||
setDescription(i18n("New Key Binding List"));
|
||||
setWindowTitle(i18n("New Key Binding List"));
|
||||
} else {
|
||||
_ui->descriptionEdit->setText(translator->description());
|
||||
setWindowTitle(i18n("Edit Key Binding List"));
|
||||
}
|
||||
|
||||
// setup key binding table
|
||||
setupKeyBindingTable(translator);
|
||||
@@ -240,3 +295,43 @@ void KeyBindingEditor::setupKeyBindingTable(const KeyboardTranslator *translator
|
||||
connect(_ui->keyBindingTable, &QTableWidget::itemChanged, this,
|
||||
&Konsole::KeyBindingEditor::bindingTableItemChanged);
|
||||
}
|
||||
|
||||
void KeyBindingEditor::accept()
|
||||
{
|
||||
if (_translator == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto newTranslator = new KeyboardTranslator(*_translator);
|
||||
|
||||
if (newTranslator->description().isEmpty()) {
|
||||
KMessageBox::sorry(this, i18n("A key bindings scheme cannot be saved with an empty description."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isNewTranslator) {
|
||||
newTranslator->setName(newTranslator->description());
|
||||
}
|
||||
|
||||
KeyboardTranslatorManager::instance()->addTranslator(newTranslator);
|
||||
|
||||
const QString ¤tTranslatorName = newTranslator->name();
|
||||
|
||||
emit updateKeyBindingsListRequest(currentTranslatorName);
|
||||
|
||||
if (currentTranslatorName == _currentProfileTranslator) {
|
||||
emit updateTempProfileKeyBindingsRequest(Profile::KeyBindings, currentTranslatorName);
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
QSize KeyBindingEditor::sizeHint() const
|
||||
{
|
||||
const auto parent = parentWidget();
|
||||
if (parent != nullptr) {
|
||||
return QSize(parent->width() * 0.9, parent->height() * 0.95);
|
||||
}
|
||||
|
||||
return QSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user