From: lyx-devel@lists.lyx.org [lyx-devel@lists.lyx.org] on behalf of Jean-Marc
Lasgouttes [lasgout...@lyx.org]
Sent: Tuesday, February 21, 2012 3:55 AM
>What I would do is to study the code of the Insert->Citation dialog,
>which has the correct behaviour in the search (find?) field, if I
>understand correctly.
Ah, I was wondering why my grepping for setDefault didn't return many results.
I'm getting closer. I realize that I need to connect the signal returnPressed
from newBranchLE to on_addBranchPB_pressed. I did this, and it seems to have
partially done what I want, but when I enter text into the LE and press return
the dialog goes away. The branch is correctly entered (which can be seen by
going back to document settings > branches). What did I do wrong? Why is it
closing? Is updateView() doing that?
The new patch is attached.
Scott
Index: src/frontends/qt4/GuiBranches.cpp
===================================================================
--- src/frontends/qt4/GuiBranches.cpp (revision 40790)
+++ src/frontends/qt4/GuiBranches.cpp (working copy)
@@ -70,6 +70,8 @@
undef_, SLOT(accept()));
connect(undef_->cancelPB, SIGNAL(clicked()),
undef_, SLOT(reject()));
+ connect(newBranchLE, SIGNAL(returnPressed()),
+ this, SLOT(on_addBranchPB_pressed()));
newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
}
@@ -132,17 +134,25 @@
}
-void GuiBranches::on_addBranchPB_pressed()
+void GuiBranches::on_newBranchLE_textChanged(QString)
{
QString const new_branch = newBranchLE->text();
if (!new_branch.isEmpty()) {
- branchlist_.add(qstring_to_ucs4(new_branch));
- newBranchLE->clear();
- updateView();
+ addBranchPB->setEnabled(TRUE);
}
}
+void GuiBranches::on_addBranchPB_pressed()
+{
+ QString const new_branch = newBranchLE->text();
+ branchlist_.add(qstring_to_ucs4(new_branch));
+ newBranchLE->clear();
+ addBranchPB->setEnabled(FALSE);
+ updateView();
+}
+
+
void GuiBranches::on_removePB_pressed()
{
QTreeWidgetItem * selItem = branchesTW->currentItem();
Index: src/frontends/qt4/GuiBranches.h
===================================================================
--- src/frontends/qt4/GuiBranches.h (revision 40790)
+++ src/frontends/qt4/GuiBranches.h (working copy)
@@ -60,6 +60,7 @@
void updateView();
protected Q_SLOTS:
+ void on_newBranchLE_textChanged(QString);
void on_addBranchPB_pressed();
void on_removePB_pressed();
void on_renamePB_pressed();
Index: src/frontends/qt4/ui/BranchesUi.ui
===================================================================
--- src/frontends/qt4/ui/BranchesUi.ui (revision 40790)
+++ src/frontends/qt4/ui/BranchesUi.ui (working copy)
@@ -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>