mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
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. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40839 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
803e7a9cfa
commit
1991488377
@ -28,6 +28,7 @@
|
|||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
@ -71,9 +72,39 @@ GuiBranches::GuiBranches(QWidget * parent)
|
|||||||
connect(undef_->cancelPB, SIGNAL(clicked()),
|
connect(undef_->cancelPB, SIGNAL(clicked()),
|
||||||
undef_, SLOT(reject()));
|
undef_, SLOT(reject()));
|
||||||
|
|
||||||
|
newBranchLE->installEventFilter(this);
|
||||||
newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
|
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)
|
void GuiBranches::update(BufferParams const & params)
|
||||||
{
|
{
|
||||||
branchlist_ = params.branchlist();
|
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()
|
void GuiBranches::on_addBranchPB_pressed()
|
||||||
{
|
{
|
||||||
QString const new_branch = newBranchLE->text();
|
QString const new_branch = newBranchLE->text();
|
||||||
if (!new_branch.isEmpty()) {
|
branchlist_.add(qstring_to_ucs4(new_branch));
|
||||||
branchlist_.add(qstring_to_ucs4(new_branch));
|
newBranchLE->clear();
|
||||||
newBranchLE->clear();
|
addBranchPB->setEnabled(false);
|
||||||
updateView();
|
updateView();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,9 +49,12 @@ public:
|
|||||||
void apply(BufferParams & params) const;
|
void apply(BufferParams & params) const;
|
||||||
void setUnknownBranches(QStringList const & b) { unknown_branches_ = b; }
|
void setUnknownBranches(QStringList const & b) { unknown_branches_ = b; }
|
||||||
|
|
||||||
|
bool eventFilter(QObject * obj, QEvent * event);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void changed();
|
void changed();
|
||||||
void renameBranches(docstring const &, docstring const &);
|
void renameBranches(docstring const &, docstring const &);
|
||||||
|
void okPressed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void toggleBranch(QTreeWidgetItem *);
|
void toggleBranch(QTreeWidgetItem *);
|
||||||
@ -60,6 +63,7 @@ protected:
|
|||||||
void updateView();
|
void updateView();
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
|
void on_newBranchLE_textChanged(QString);
|
||||||
void on_addBranchPB_pressed();
|
void on_addBranchPB_pressed();
|
||||||
void on_removePB_pressed();
|
void on_removePB_pressed();
|
||||||
void on_renamePB_pressed();
|
void on_renamePB_pressed();
|
||||||
|
@ -1289,6 +1289,7 @@ GuiDocument::GuiDocument(GuiView & lv)
|
|||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
|
connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
|
||||||
this, SLOT(branchesRename(docstring const &, docstring const &)));
|
this, SLOT(branchesRename(docstring const &, docstring const &)));
|
||||||
|
connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
|
||||||
updateUnknownBranches();
|
updateUnknownBranches();
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,6 +103,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="3" >
|
<item row="0" column="3" >
|
||||||
<widget class="QPushButton" name="addBranchPB" >
|
<widget class="QPushButton" name="addBranchPB" >
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="toolTip" >
|
<property name="toolTip" >
|
||||||
<string>Add a new branch to the list</string>
|
<string>Add a new branch to the list</string>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user