X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiBranches.cpp;h=ab91587098bc2c4f3d28ea2df73d0eb7325df729;hb=b7f6b979d0f889f08e735f35378bb20ba3788b4b;hp=c79a42def221ba4cc45b4d27325ff88ee1b8dad6;hpb=c48091f33a773732fa6c789927e5833e44108d9d;p=lyx.git diff --git a/src/frontends/qt4/GuiBranches.cpp b/src/frontends/qt4/GuiBranches.cpp index c79a42def2..ab91587098 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 @@ -36,6 +37,9 @@ #include #include +#ifdef KeyPress +#undef KeyPress +#endif namespace lyx { namespace frontend { @@ -71,9 +75,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 +166,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(); } @@ -166,10 +206,10 @@ void GuiBranches::on_renamePB_pressed() if (!sel_branch.isEmpty()) { docstring newname; docstring const oldname = qstring_to_ucs4(sel_branch); - bool success = false; if (Alert::askForText(newname, _("Enter new branch name"), oldname)) { if (newname.empty() || oldname == newname) return; + bool success = false; if (branchlist_.find(newname)) { docstring text = support::bformat( _("A branch with the name \"%1$s\" already exists.\n" @@ -184,7 +224,7 @@ void GuiBranches::on_renamePB_pressed() updateView(); if (!success) - Alert::error(_("Renaming failed"), + Alert::error(_("Renaming failed"), _("The branch could not be renamed.")); else // emit signal @@ -312,7 +352,7 @@ void GuiBranches::addUnknown() { QList selItems = undef_->branchesLW->selectedItems(); - + QList::const_iterator it = selItems.begin(); for (; it != selItems.end() ; ++it) { QListWidgetItem const * new_branch = *it;