]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBranches.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiBranches.cpp
index 45e60de9624c0a101de3a247dc9de2b1c4d8a02c..bf2c5242da7d257588522fc38572352f885f1740 100644 (file)
@@ -49,7 +49,10 @@ GuiBranches::GuiBranches(QWidget * parent)
        branchesTW->headerItem()->setText(0, qt_("Branch"));
        branchesTW->headerItem()->setText(1, qt_("Activated"));
        branchesTW->headerItem()->setText(2, qt_("Color"));
+       branchesTW->headerItem()->setText(3, qt_("Filename Suffix"));
        branchesTW->setSortingEnabled(true);
+       branchesTW->resizeColumnToContents(1);
+       branchesTW->resizeColumnToContents(2);
 
        undef_ = new BranchesUnknownDialog(this);
        undef_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
@@ -101,6 +104,7 @@ void GuiBranches::updateView()
                        coloritem.fill(itemcolor);
                        newItem->setIcon(2, QIcon(coloritem));
                }
+               newItem->setText(3, it->hasFilenameSuffix() ? qt_("Yes") : qt_("No"));
                // restore selected branch
                if (bname == sel_branch) {
                        branchesTW->setCurrentItem(newItem);
@@ -108,6 +112,13 @@ void GuiBranches::updateView()
                }
        }
        unknownPB->setEnabled(!unknown_branches_.isEmpty());
+       bool const have_sel =
+               !branchesTW->selectedItems().isEmpty();
+       removePB->setEnabled(have_sel);
+       renamePB->setEnabled(have_sel);
+       colorPB->setEnabled(have_sel);
+       activatePB->setEnabled(have_sel);
+       suffixPB->setEnabled(have_sel);
        // emit signal
        changed();
 }
@@ -154,7 +165,9 @@ void GuiBranches::on_renamePB_pressed()
                docstring newname;
                docstring const oldname = qstring_to_ucs4(sel_branch);
                bool success = false;
-               if (Alert::askForText(newname, _("Enter new branch name"))) {
+               if (Alert::askForText(newname, _("Enter new branch name"), oldname)) {
+                       if (newname.empty() || oldname == newname)
+                               return;
                        if (branchlist_.find(newname)) {
                                docstring text = support::bformat(
                                        _("A branch with the name \"%1$s\" already exists.\n"
@@ -167,13 +180,14 @@ void GuiBranches::on_renamePB_pressed()
                                success = branchlist_.rename(oldname, newname);
                        newBranchLE->clear();
                        updateView();
+
+                       if (!success)
+                               Alert::error(_("Renaming failed"), 
+                                     _("The branch could not be renamed."));
+                       else
+                               // emit signal
+                               renameBranches(oldname, newname);
                }
-               if (!success)
-                       Alert::error(_("Renaming failed"), 
-                             _("The branch could not be renamed."));
-               else
-                       // emit signal
-                       renameBranches(oldname, newname);
        }
 }
 
@@ -184,12 +198,32 @@ void GuiBranches::on_activatePB_pressed()
 }
 
 
+void GuiBranches::on_suffixPB_pressed()
+{
+       toggleSuffix(branchesTW->currentItem());
+}
+
+
 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
 {
        if (col < 2)
                toggleBranch(item);
-       else
+       else if (col == 2)
                toggleColor(item);
+       else if (col == 3)
+               toggleSuffix(item);
+}
+
+
+void GuiBranches::on_branchesTW_itemSelectionChanged()
+{
+       bool const have_sel =
+               !branchesTW->selectedItems().isEmpty();
+       removePB->setEnabled(have_sel);
+       renamePB->setEnabled(have_sel);
+       colorPB->setEnabled(have_sel);
+       activatePB->setEnabled(have_sel);
+       suffixPB->setEnabled(have_sel);
 }
 
 
@@ -202,9 +236,8 @@ void GuiBranches::toggleBranch(QTreeWidgetItem * item)
        if (sel_branch.isEmpty())
                return;
 
-       bool const selected = (item->text(1) == qt_("Yes"));
        Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
-       if (branch && branch->setSelected(!selected)) {
+       if (branch && branch->setSelected(!branch->isSelected())) {
                newBranchLE->clear();
                updateView();
        }
@@ -243,6 +276,24 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item)
 }
 
 
+void GuiBranches::toggleSuffix(QTreeWidgetItem * item)
+{
+       if (item == 0)
+               return;
+
+       QString sel_branch = item->text(0);
+       if (sel_branch.isEmpty())
+               return;
+
+       Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
+       if (branch) {
+               branch->setFilenameSuffix(!branch->hasFilenameSuffix());
+               newBranchLE->clear();
+               updateView();
+       }
+}
+
+
 void GuiBranches::on_unknownPB_pressed()
 {
        undef_->branchesLW->clear();