I am new to C++ and to the LyX source code so extra checks and suggestions 
would be appreciated.

The attached patch fixes 1 bug and tries to fix another. To see the buglettes 
I'm trying to fix, see the steps below to reproduce:

1. start a new lyx document
2. go to document settings > branches
bug 1: the "Add" button is active.
3. enter some text into the text box to the left of the "Add" button.
4. press enter
bug 2a: nothing happens
5. click the "Add" button. A new branch is created.
6. enter some text in the now blank text box.
7. press enter
bug 2b: instead of creating a new branch, the dialog disappears.

my fix for bug 1:
1. disable the add button (BranchesUi.ui)
2. enable the add button when there is text in the text box (GuiBranches.cpp)

my (partially implemented) idea for bug 2:
set the add button as default when there is text in the text box 
(GuiBranches.cpp)
--That works fine, but I can't figure out how to set the OK button back to 
default (which it was before) because okPB is not in the scope of 
GuiBranches.cpp. This has a global affect on the dialog because even after the 
panel is switched okPB does not have default enabled. What should I do about 
this?

An additional question:
In GuiBranches.cpp for on_addBranchPB_pressed I removed the "if" that checked 
if the text box is empty because I implemented that check in 
on_newBranchLE_textChanged. I suppose the conservative approach would have been 
to leave that extra check. Should I not remove it?

My fix for bug 1 and my attempt at bug 2 are in the attached patch.

Best,

Scott Kostyshak
Index: src/frontends/qt4/ui/BranchesUi.ui
===================================================================
--- src/frontends/qt4/ui/BranchesUi.ui	(revision 40746)
+++ 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>
Index: src/frontends/qt4/GuiBranches.cpp
===================================================================
--- src/frontends/qt4/GuiBranches.cpp	(revision 40746)
+++ src/frontends/qt4/GuiBranches.cpp	(working copy)
@@ -132,17 +132,26 @@
 }
 
 
-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);
+		addBranchPB->setDefault(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 40746)
+++ 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();

Reply via email to