Author: vfr
Date: Sat Mar 3 16:55:00 2012
New Revision: 40847
URL: http://www.lyx.org/trac/changeset/40847
Log:
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.
Modified:
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.h
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BranchesUi.ui
lyx-devel/branches/BRANCH_2_0_X/status.20x
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp Sat Mar
3 16:52:21 2012 (r40846)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.cpp Sat Mar
3 16:55:00 2012 (r40847)
@@ -28,6 +28,7 @@
#include "support/gettext.h"
#include "support/lstrings.h"
+#include <QKeyEvent>
#include <QListWidget>
#include <QTreeWidget>
#include <QTreeWidgetItem>
@@ -71,9 +72,39 @@
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<QKeyEvent *>(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::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();
}
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.h
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.h Sat Mar
3 16:52:21 2012 (r40846)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiBranches.h Sat Mar
3 16:55:00 2012 (r40847)
@@ -49,9 +49,12 @@
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 @@
void updateView();
protected Q_SLOTS:
+ void on_newBranchLE_textChanged(QString);
void on_addBranchPB_pressed();
void on_removePB_pressed();
void on_renamePB_pressed();
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp Sat Mar
3 16:52:21 2012 (r40846)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiDocument.cpp Sat Mar
3 16:55:00 2012 (r40847)
@@ -1192,6 +1192,7 @@
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();
Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BranchesUi.ui
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BranchesUi.ui Sat Mar
3 16:52:21 2012 (r40846)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/BranchesUi.ui Sat Mar
3 16:55:00 2012 (r40847)
@@ -103,6 +103,9 @@
</item>
<item row="0" column="3" >
<widget class="QPushButton" name="addBranchPB" >
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="toolTip" >
<string>Add a new branch to the list</string>
</property>
Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x Sat Mar 3 16:52:21 2012
(r40846)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x Sat Mar 3 16:55:00 2012
(r40847)
@@ -68,6 +68,9 @@
- Do not allow to add a citation in the citation dialog using the
<Enter> key if the Add button is disabled.
+- Allow the <Enter> key to add a new branch in document settings.
+ Only <Ctrl+Enter> and numpad-<Enter> will also close the dialog.
+
* DOCUMENTATION AND LOCALIZATION