]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBranches.cpp
Ease the pain with unknown branches:
[lyx.git] / src / frontends / qt4 / GuiBranches.cpp
index 46966c9fbbda5ef1b24c04f1ba79682550f0d854..a38b034b5d4ce4ff320cc42a0cc8b51c63a081cc 100644 (file)
 
 #include "GuiBranches.h"
 
-#include "ControlDocument.h"
+#include "ColorCache.h"
 #include "GuiApplication.h"
 #include "Validator.h"
 #include "qt_helpers.h"
 
+#include "ui_BranchesUnknownUi.h"
+
+#include "Buffer.h"
 #include "BufferParams.h"
 
 #include "support/lstrings.h"
 
+#include <QListWidget>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
 #include <QPixmap>
@@ -34,8 +38,8 @@ namespace lyx {
 namespace frontend {
 
 
-GuiBranches::GuiBranches(QWidget * parent, Qt::WFlags f)
-       : QWidget(parent, f)
+GuiBranches::GuiBranches(QWidget * parent)
+       : QWidget(parent)
 {
        setupUi(this);
        branchesTW->setColumnCount(3);
@@ -43,6 +47,23 @@ GuiBranches::GuiBranches(QWidget * parent, Qt::WFlags f)
        branchesTW->headerItem()->setText(1, qt_("Activated"));
        branchesTW->headerItem()->setText(2, qt_("Color"));
        branchesTW->setSortingEnabled(true);
+
+       undef_ = new BranchesUnknownDialog(this);
+       undef_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
+       undef_bc_.setCancel(undef_->cancelPB);
+
+       connect(undef_->branchesLW, SIGNAL(itemSelectionChanged()),
+               this, SLOT(unknownBranchSelChanged()));
+       connect(undef_->addSelectedPB, SIGNAL(clicked()),
+               this, SLOT(addUnknown()));
+       connect(undef_->addAllPB, SIGNAL(clicked()),
+               this, SLOT(addAllUnknown()));
+       connect(undef_->addSelectedPB, SIGNAL(clicked()),
+               undef_, SLOT(accept()));
+       connect(undef_->addAllPB, SIGNAL(clicked()),
+               undef_, SLOT(accept()));
+       connect(undef_->cancelPB, SIGNAL(clicked()),
+               undef_, SLOT(reject()));
 }
 
 void GuiBranches::update(BufferParams const & params)
@@ -67,13 +88,11 @@ void GuiBranches::updateView()
        for (; it != end; ++it) {
                QTreeWidgetItem * newItem = new QTreeWidgetItem(branchesTW);
 
-               QString const bname = toqstr(it->getBranch());
+               QString const bname = toqstr(it->branch());
                newItem->setText(0, bname);
+               newItem->setText(1, it->isSelected() ? qt_("Yes") : qt_("No"));
 
-               QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
-               newItem->setText(1, sel);
-
-               QColor const itemcolor = rgb2qcolor(it->getColor());
+               QColor const itemcolor = rgb2qcolor(it->color());
                if (itemcolor.isValid()) {
                        QPixmap coloritem(30, 10);
                        coloritem.fill(itemcolor);
@@ -85,6 +104,7 @@ void GuiBranches::updateView()
                        branchesTW->setItemSelected(newItem, true);
                }
        }
+       unknownPB->setEnabled(!unknown_branches_.isEmpty());
        // emit signal
        changed();
 }
@@ -170,12 +190,11 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item)
                return;
 
        docstring current_branch = qstring_to_ucs4(sel_branch);
-       Branch * branch =
-               branchlist_.find(current_branch);
+       Branch * branch = branchlist_.find(current_branch);
        if (!branch)
                return;
 
-       QColor const initial = rgb2qcolor(branch->getColor());
+       QColor const initial = rgb2qcolor(branch->color());
        QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget());
        if (!ncol.isValid())
                return;
@@ -186,7 +205,50 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item)
        updateView();
 }
 
+
+void GuiBranches::on_unknownPB_pressed()
+{
+       undef_->branchesLW->clear();
+       for (int i = 0; i != unknown_branches_.count(); ++i) {
+               if (branchesTW->findItems(unknown_branches_[i], Qt::MatchExactly, 0).empty())
+                       undef_->branchesLW->addItem(unknown_branches_[i]);
+       }
+       unknownBranchSelChanged();
+       undef_->exec();
+}
+
+
+void GuiBranches::addUnknown()
+{
+       QList<QListWidgetItem *> selItems =
+               undef_->branchesLW->selectedItems();
+       
+       QList<QListWidgetItem *>::const_iterator it = selItems.begin();
+       for (it ; it != selItems.end() ; ++it) {
+               QListWidgetItem const * new_branch = *it;
+               if (new_branch) {
+                       branchlist_.add(qstring_to_ucs4(new_branch->text()));
+                       updateView();
+               }
+       }
+}
+
+
+void GuiBranches::addAllUnknown()
+{
+       undef_->branchesLW->selectAll();
+       addUnknown();
+}
+
+
+void GuiBranches::unknownBranchSelChanged()
+{
+       undef_->addSelectedPB->setEnabled(
+               !undef_->branchesLW->selectedItems().isEmpty());
+}
+
+
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiBranches_moc.cpp"
+#include "moc_GuiBranches.cpp"