From 436ab3a2c2d42c815b17f17ea0ae649b068ed448 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Sat, 3 Mar 2012 15:55:00 +0000 Subject: [PATCH] branch: Fix handling of the add branch textfield in GuiBranches - Enter in the textfield adds the branch, - Make sure the dialog is not closed when pressing enter, - Pressing Ctrl+Enter or the Enter on the numpad closes the dialog. Patch based on a patch from Scott Kostyshak. see r40839. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40847 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiBranches.cpp | 47 ++++++++++++++++++++++++++---- src/frontends/qt4/GuiBranches.h | 4 +++ src/frontends/qt4/GuiDocument.cpp | 1 + src/frontends/qt4/ui/BranchesUi.ui | 3 ++ status.20x | 3 ++ 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt4/GuiBranches.cpp b/src/frontends/qt4/GuiBranches.cpp index c79a42def2..9c59f125e4 100644 --- a/src/frontends/qt4/GuiBranches.cpp +++ b/src/frontends/qt4/GuiBranches.cpp @@ -28,6 +28,7 @@ #include "support/gettext.h" #include "support/lstrings.h" +#include #include #include #include @@ -71,9 +72,39 @@ GuiBranches::GuiBranches(QWidget * parent) connect(undef_->cancelPB, SIGNAL(clicked()), undef_, SLOT(reject())); + newBranchLE->installEventFilter(this); newBranchLE->setValidator(new NoNewLineValidator(newBranchLE)); } + +bool GuiBranches::eventFilter(QObject * obj, QEvent * event) +{ + QEvent::Type etype = event->type(); + if (etype == QEvent::KeyPress + && obj == newBranchLE + && addBranchPB->isEnabled()) { + QKeyEvent * keyEvent = static_cast(event); + int const keyPressed = keyEvent->key(); + Qt::KeyboardModifiers const keyModifiers = keyEvent->modifiers(); + + if (keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) { + if (!keyModifiers) { + on_addBranchPB_pressed(); + } else if (keyModifiers == Qt::ControlModifier + || keyModifiers == Qt::KeypadModifier + || keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier)) { + on_addBranchPB_pressed(); + newBranchLE->clearFocus(); + okPressed(); + } + event->accept(); + return true; + } + } + return QObject::eventFilter(obj, event); +} + + void GuiBranches::update(BufferParams const & params) { branchlist_ = params.branchlist(); @@ -132,14 +163,20 @@ void GuiBranches::apply(BufferParams & params) const } +void GuiBranches::on_newBranchLE_textChanged(QString) +{ + QString const new_branch = newBranchLE->text(); + addBranchPB->setEnabled(!new_branch.isEmpty()); +} + + void GuiBranches::on_addBranchPB_pressed() { QString const new_branch = newBranchLE->text(); - if (!new_branch.isEmpty()) { - branchlist_.add(qstring_to_ucs4(new_branch)); - newBranchLE->clear(); - updateView(); - } + branchlist_.add(qstring_to_ucs4(new_branch)); + newBranchLE->clear(); + addBranchPB->setEnabled(false); + updateView(); } diff --git a/src/frontends/qt4/GuiBranches.h b/src/frontends/qt4/GuiBranches.h index 803a7017ee..fc29167cd0 100644 --- a/src/frontends/qt4/GuiBranches.h +++ b/src/frontends/qt4/GuiBranches.h @@ -49,9 +49,12 @@ public: void apply(BufferParams & params) const; void setUnknownBranches(QStringList const & b) { unknown_branches_ = b; } + bool eventFilter(QObject * obj, QEvent * event); + Q_SIGNALS: void changed(); void renameBranches(docstring const &, docstring const &); + void okPressed(); protected: void toggleBranch(QTreeWidgetItem *); @@ -60,6 +63,7 @@ protected: void updateView(); protected Q_SLOTS: + void on_newBranchLE_textChanged(QString); void on_addBranchPB_pressed(); void on_removePB_pressed(); void on_renamePB_pressed(); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 7150097a89..1852ec85df 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1192,6 +1192,7 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)), this, SLOT(branchesRename(docstring const &, docstring const &))); + connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK())); updateUnknownBranches(); diff --git a/src/frontends/qt4/ui/BranchesUi.ui b/src/frontends/qt4/ui/BranchesUi.ui index d8e97e22e7..4c83b18f16 100644 --- a/src/frontends/qt4/ui/BranchesUi.ui +++ b/src/frontends/qt4/ui/BranchesUi.ui @@ -103,6 +103,9 @@ + + false + Add a new branch to the list diff --git a/status.20x b/status.20x index 57dd19f84a..bec9389f46 100644 --- a/status.20x +++ b/status.20x @@ -68,6 +68,9 @@ What's new - Do not allow to add a citation in the citation dialog using the key if the Add button is disabled. +- Allow the key to add a new branch in document settings. + Only and numpad- will also close the dialog. + * DOCUMENTATION AND LOCALIZATION -- 2.39.5