2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiBranches.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiBranches.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-23 08:43:07 +00:00
|
|
|
#include "ColorCache.h"
|
2006-09-26 09:57:47 +00:00
|
|
|
#include "GuiApplication.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2009-07-09 09:48:34 +00:00
|
|
|
#include "ui_BranchesUnknownUi.h"
|
|
|
|
|
2009-07-10 06:49:51 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2009-07-09 09:48:34 +00:00
|
|
|
#include "Buffer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-07-10 06:49:51 +00:00
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2012-03-03 14:39:32 +00:00
|
|
|
#include <QKeyEvent>
|
2009-07-09 09:48:34 +00:00
|
|
|
#include <QListWidget>
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPixmap>
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QIcon>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QColor>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
2012-03-24 14:25:30 +00:00
|
|
|
#ifdef KeyPress
|
|
|
|
#undef KeyPress
|
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
2008-09-21 19:27:20 +00:00
|
|
|
GuiBranches::GuiBranches(QWidget * parent)
|
|
|
|
: QWidget(parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2006-11-04 15:08:53 +00:00
|
|
|
branchesTW->setColumnCount(3);
|
2006-05-07 10:20:43 +00:00
|
|
|
branchesTW->headerItem()->setText(0, qt_("Branch"));
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->headerItem()->setText(1, qt_("Activated"));
|
2006-11-04 15:08:53 +00:00
|
|
|
branchesTW->headerItem()->setText(2, qt_("Color"));
|
2009-07-13 14:30:08 +00:00
|
|
|
branchesTW->headerItem()->setText(3, qt_("Filename Suffix"));
|
2006-11-04 15:08:53 +00:00
|
|
|
branchesTW->setSortingEnabled(true);
|
2009-08-12 09:46:26 +00:00
|
|
|
branchesTW->resizeColumnToContents(1);
|
|
|
|
branchesTW->resizeColumnToContents(2);
|
2009-07-09 09:48:34 +00:00
|
|
|
|
|
|
|
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()));
|
2011-09-24 16:39:23 +00:00
|
|
|
|
2012-03-03 14:39:32 +00:00
|
|
|
newBranchLE->installEventFilter(this);
|
2011-09-24 16:39:23 +00:00
|
|
|
newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-03 14:39:32 +00:00
|
|
|
|
|
|
|
bool GuiBranches::eventFilter(QObject * obj, QEvent * event)
|
|
|
|
{
|
|
|
|
QEvent::Type etype = event->type();
|
|
|
|
if (etype == QEvent::KeyPress
|
|
|
|
&& obj == newBranchLE
|
|
|
|
&& addBranchPB->isEnabled()) {
|
|
|
|
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::update(BufferParams const & params)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
branchlist_ = params.branchlist();
|
2007-09-03 20:28:26 +00:00
|
|
|
updateView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 23:12:55 +00:00
|
|
|
|
2007-09-03 20:28:26 +00:00
|
|
|
void GuiBranches::updateView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// store the selected branch
|
2006-05-07 10:20:43 +00:00
|
|
|
QTreeWidgetItem * item = branchesTW->currentItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
QString sel_branch;
|
2006-05-04 07:31:46 +00:00
|
|
|
if (item != 0)
|
|
|
|
sel_branch = item->text(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
BranchList::const_iterator it = branchlist_.begin();
|
|
|
|
BranchList::const_iterator const end = branchlist_.end();
|
|
|
|
for (; it != end; ++it) {
|
2007-10-05 23:12:55 +00:00
|
|
|
QTreeWidgetItem * newItem = new QTreeWidgetItem(branchesTW);
|
2006-05-04 07:31:46 +00:00
|
|
|
|
2008-09-21 19:27:20 +00:00
|
|
|
QString const bname = toqstr(it->branch());
|
2006-05-04 07:31:46 +00:00
|
|
|
newItem->setText(0, bname);
|
2008-09-21 19:27:20 +00:00
|
|
|
newItem->setText(1, it->isSelected() ? qt_("Yes") : qt_("No"));
|
2006-05-04 07:31:46 +00:00
|
|
|
|
2008-09-21 19:27:20 +00:00
|
|
|
QColor const itemcolor = rgb2qcolor(it->color());
|
2006-03-05 17:24:44 +00:00
|
|
|
if (itemcolor.isValid()) {
|
2006-11-04 15:08:53 +00:00
|
|
|
QPixmap coloritem(30, 10);
|
2006-03-05 17:24:44 +00:00
|
|
|
coloritem.fill(itemcolor);
|
2006-11-04 15:08:53 +00:00
|
|
|
newItem->setIcon(2, QIcon(coloritem));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2010-04-21 01:19:35 +00:00
|
|
|
newItem->setText(3, it->hasFileNameSuffix() ? qt_("Yes") : qt_("No"));
|
2006-03-05 17:24:44 +00:00
|
|
|
// restore selected branch
|
2006-11-04 15:08:53 +00:00
|
|
|
if (bname == sel_branch) {
|
|
|
|
branchesTW->setCurrentItem(newItem);
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->setItemSelected(newItem, true);
|
2006-11-04 15:08:53 +00:00
|
|
|
}
|
2006-03-20 17:25:02 +00:00
|
|
|
}
|
2009-07-09 09:48:34 +00:00
|
|
|
unknownPB->setEnabled(!unknown_branches_.isEmpty());
|
2009-07-11 06:12:27 +00:00
|
|
|
bool const have_sel =
|
|
|
|
!branchesTW->selectedItems().isEmpty();
|
|
|
|
removePB->setEnabled(have_sel);
|
|
|
|
renamePB->setEnabled(have_sel);
|
2009-07-11 06:29:57 +00:00
|
|
|
colorPB->setEnabled(have_sel);
|
|
|
|
activatePB->setEnabled(have_sel);
|
2009-07-13 14:30:08 +00:00
|
|
|
suffixPB->setEnabled(have_sel);
|
2006-07-06 08:18:51 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 23:12:55 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::apply(BufferParams & params) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
params.branchlist() = branchlist_;
|
|
|
|
}
|
|
|
|
|
2007-10-05 23:12:55 +00:00
|
|
|
|
2012-03-03 14:39:32 +00:00
|
|
|
void GuiBranches::on_newBranchLE_textChanged(QString)
|
|
|
|
{
|
|
|
|
QString const new_branch = newBranchLE->text();
|
|
|
|
addBranchPB->setEnabled(!new_branch.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::on_addBranchPB_pressed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QString const new_branch = newBranchLE->text();
|
2012-03-03 14:39:32 +00:00
|
|
|
branchlist_.add(qstring_to_ucs4(new_branch));
|
|
|
|
newBranchLE->clear();
|
|
|
|
addBranchPB->setEnabled(false);
|
|
|
|
updateView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::on_removePB_pressed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-05 23:12:55 +00:00
|
|
|
QTreeWidgetItem * selItem = branchesTW->currentItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
QString sel_branch;
|
|
|
|
if (selItem != 0)
|
|
|
|
sel_branch = selItem->text(0);
|
|
|
|
if (!sel_branch.isEmpty()) {
|
2006-11-03 15:16:45 +00:00
|
|
|
branchlist_.remove(qstring_to_ucs4(sel_branch));
|
2006-03-05 17:24:44 +00:00
|
|
|
newBranchLE->clear();
|
2007-09-03 20:28:26 +00:00
|
|
|
updateView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-10 06:49:51 +00:00
|
|
|
void GuiBranches::on_renamePB_pressed()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem * selItem = branchesTW->currentItem();
|
|
|
|
QString sel_branch;
|
|
|
|
if (selItem != 0)
|
|
|
|
sel_branch = selItem->text(0);
|
|
|
|
if (!sel_branch.isEmpty()) {
|
|
|
|
docstring newname;
|
|
|
|
docstring const oldname = qstring_to_ucs4(sel_branch);
|
|
|
|
bool success = false;
|
2009-07-11 06:12:27 +00:00
|
|
|
if (Alert::askForText(newname, _("Enter new branch name"), oldname)) {
|
|
|
|
if (newname.empty() || oldname == newname)
|
|
|
|
return;
|
2009-07-10 06:49:51 +00:00
|
|
|
if (branchlist_.find(newname)) {
|
|
|
|
docstring text = support::bformat(
|
|
|
|
_("A branch with the name \"%1$s\" already exists.\n"
|
|
|
|
"Do you want to merge branch \"%2$s\" with that one?"),
|
|
|
|
newname, oldname);
|
|
|
|
if (frontend::Alert::prompt(_("Branch already exists"),
|
|
|
|
text, 0, 1, _("&Merge"), _("&Cancel")) == 0)
|
|
|
|
success = branchlist_.rename(oldname, newname, true);
|
|
|
|
} else
|
|
|
|
success = branchlist_.rename(oldname, newname);
|
|
|
|
newBranchLE->clear();
|
|
|
|
updateView();
|
2009-07-11 17:29:52 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
Alert::error(_("Renaming failed"),
|
|
|
|
_("The branch could not be renamed."));
|
|
|
|
else
|
|
|
|
// emit signal
|
|
|
|
renameBranches(oldname, newname);
|
2009-07-10 06:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::on_activatePB_pressed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
toggleBranch(branchesTW->currentItem());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 14:30:08 +00:00
|
|
|
void GuiBranches::on_suffixPB_pressed()
|
|
|
|
{
|
|
|
|
toggleSuffix(branchesTW->currentItem());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-11-04 15:08:53 +00:00
|
|
|
if (col < 2)
|
|
|
|
toggleBranch(item);
|
2009-07-13 14:30:08 +00:00
|
|
|
else if (col == 2)
|
2006-11-04 15:08:53 +00:00
|
|
|
toggleColor(item);
|
2009-07-13 14:30:08 +00:00
|
|
|
else if (col == 3)
|
|
|
|
toggleSuffix(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 06:12:27 +00:00
|
|
|
void GuiBranches::on_branchesTW_itemSelectionChanged()
|
|
|
|
{
|
|
|
|
bool const have_sel =
|
|
|
|
!branchesTW->selectedItems().isEmpty();
|
|
|
|
removePB->setEnabled(have_sel);
|
|
|
|
renamePB->setEnabled(have_sel);
|
2009-07-11 06:29:57 +00:00
|
|
|
colorPB->setEnabled(have_sel);
|
|
|
|
activatePB->setEnabled(have_sel);
|
2009-07-13 14:30:08 +00:00
|
|
|
suffixPB->setEnabled(have_sel);
|
2009-07-11 06:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::toggleBranch(QTreeWidgetItem * item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
if (item == 0)
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
QString sel_branch = item->text(0);
|
2007-10-05 23:12:55 +00:00
|
|
|
if (sel_branch.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
|
2009-07-13 14:30:08 +00:00
|
|
|
if (branch && branch->setSelected(!branch->isSelected())) {
|
2007-10-05 23:12:55 +00:00
|
|
|
newBranchLE->clear();
|
|
|
|
updateView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::on_colorPB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-11-04 15:08:53 +00:00
|
|
|
toggleColor(branchesTW->currentItem());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiBranches::toggleColor(QTreeWidgetItem * item)
|
2006-11-04 15:08:53 +00:00
|
|
|
{
|
|
|
|
if (item == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString sel_branch = item->text(0);
|
2007-10-05 23:12:55 +00:00
|
|
|
if (sel_branch.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
docstring current_branch = qstring_to_ucs4(sel_branch);
|
2008-05-27 19:00:42 +00:00
|
|
|
Branch * branch = branchlist_.find(current_branch);
|
2007-10-05 23:12:55 +00:00
|
|
|
if (!branch)
|
|
|
|
return;
|
|
|
|
|
2008-09-21 19:27:20 +00:00
|
|
|
QColor const initial = rgb2qcolor(branch->color());
|
2007-10-05 23:12:55 +00:00
|
|
|
QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget());
|
|
|
|
if (!ncol.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// add the color to the branchlist
|
|
|
|
branch->setColor(fromqstr(ncol.name()));
|
|
|
|
newBranchLE->clear();
|
|
|
|
updateView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 09:48:34 +00:00
|
|
|
|
2009-07-13 14:30:08 +00:00
|
|
|
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) {
|
2010-04-21 01:19:35 +00:00
|
|
|
branch->setFileNameSuffix(!branch->hasFileNameSuffix());
|
2009-07-13 14:30:08 +00:00
|
|
|
newBranchLE->clear();
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-09 09:48:34 +00:00
|
|
|
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();
|
2009-07-09 11:16:27 +00:00
|
|
|
for (; it != selItems.end() ; ++it) {
|
2009-07-09 09:48:34 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiBranches.cpp"
|