#include "support/gettext.h"
#include "support/lstrings.h"
+#include <QKeyEvent>
#include <QListWidget>
#include <QTreeWidget>
#include <QTreeWidgetItem>
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();
}
+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();
}
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 *);
void updateView();
protected Q_SLOTS:
+ void on_newBranchLE_textChanged(QString);
void on_addBranchPB_pressed();
void on_removePB_pressed();
void on_renamePB_pressed();
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();