BoxUi.ui
BranchUi.ui
BranchesUi.ui
+ BranchesUnknownUi.ui
BulletsUi.ui
ChangesUi.ui
CharacterUi.ui
#include "insets/InsetBibitem.h"
#include "insets/InsetBibtex.h"
+#include "insets/InsetBranch.h"
#include "insets/InsetInclude.h"
#include "insets/InsetText.h"
break;
}
+ case LFUN_BRANCH_ADD:
case LFUN_BUFFER_PRINT:
// if no Buffer is present, then of course we won't be called!
flag.setEnabled(true);
break;
}
+ case LFUN_BRANCH_ADD: {
+ BranchList & branchList = params().branchlist();
+ docstring const branchName = func.argument();
+ if (branchName.empty()) {
+ dispatched = false;
+ break;
+ }
+ Branch * branch = branchList.find(branchName);
+ if (branch) {
+ LYXERR0("Branch " << branchName << " does already exist.");
+ dr.setError(true);
+ docstring const msg =
+ bformat(_("Branch \"%1$s\" does already exist."), branchName);
+ dr.setMessage(msg);
+ } else {
+ branchList.add(branchName);
+ dr.setError(false);
+ dr.update(Update::Force);
+ }
+ break;
+ }
+
case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: {
BranchList & branchList = params().branchlist();
}
+void Buffer::getUsedBranches(std::list<docstring> & result, bool const from_master) const
+{
+ // Iterate over buffer, starting with first paragraph
+ // The scope must be bigger than any lookup DocIterator
+ // later. For the global lookup, lastpit+1 is used, hence
+ // we use lastpit+2 here.
+ DocIterator it = par_iterator_begin();
+ DocIterator scope = it;
+ scope.pit() = scope.lastpit() + 2;
+ pit_type lastpit = it.lastpit();
+
+ while (it.pit() <= lastpit) {
+ Paragraph & par = it.paragraph();
+
+ // iterate over the insets of the current paragraph
+ InsetList const & insets = par.insetList();
+ InsetList::const_iterator iit = insets.begin();
+ InsetList::const_iterator end = insets.end();
+ for (; iit != end; ++iit) {
+ it.pos() = iit->pos;
+
+ if (iit->inset->lyxCode() == BRANCH_CODE) {
+ // get buffer of external file
+ InsetBranch const & br =
+ static_cast<InsetBranch const &>(*iit->inset);
+ docstring const name = br.branch();
+ if (!from_master && !params().branchlist().find(name))
+ result.push_back(name);
+ else if (from_master && !masterBuffer()->params().branchlist().find(name))
+ result.push_back(name);
+ continue;
+ }
+
+ // is it an external file?
+ if (iit->inset->lyxCode() == INCLUDE_CODE) {
+ // get buffer of external file
+ InsetInclude const & inset =
+ static_cast<InsetInclude const &>(*iit->inset);
+ Buffer * child = inset.getChildBuffer();
+ if (!child)
+ continue;
+ child->getUsedBranches(result, true);
+ }
+ }
+ // next paragraph
+ it.pit()++;
+ it.pos() = 0;
+ }
+ // remove duplicates
+ result.unique();
+}
+
+
void Buffer::updateMacroInstances() const
{
LYXERR(Debug::MACROS, "updateMacroInstances for "
// Do this here in case the master has no gui associated with it. Then,
// the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
if (!master->gui_)
- structureChanged();
+ structureChanged();
// was buf referenced from the master (i.e. not in bufToUpdate anymore)?
if (bufToUpdate.find(this) == bufToUpdate.end())
#include "support/types.h"
#include "support/SignalSlot.h"
+#include <list>
#include <string>
#include <vector>
void setInsetLabel(docstring const & label, InsetLabel const * il);
InsetLabel const * insetLabel(docstring const & label) const;
+ /// return a list of all used branches (also in children)
+ void getUsedBranches(std::list<docstring> &, bool const from_master = false) const;
+
/// sets the buffer_ member for every inset in this buffer.
// FIXME This really shouldn't be needed, but at the moment it's not
// clear how to do it just for the individual pieces we need.
#include "CutAndPaste.h"
+#include "BranchList.h"
#include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferList.h"
#include "ParIterator.h"
#include "Undo.h"
-#include "insets/InsetFlex.h"
+#include "insets/InsetBranch.h"
#include "insets/InsetCommand.h"
+#include "insets/InsetFlex.h"
#include "insets/InsetGraphics.h"
#include "insets/InsetGraphicsParams.h"
#include "insets/InsetInclude.h"
#include "support/limited_stack.h"
#include "support/lstrings.h"
+#include "frontends/alert.h"
#include "frontends/Clipboard.h"
#include "frontends/Selection.h"
break;
}
+ case BRANCH_CODE: {
+ // check if branch is known to target buffer
+ // or its master
+ InsetBranch & br = static_cast<InsetBranch &>(*it);
+ docstring const name = br.branch();
+ if (name.empty())
+ break;
+ bool const is_child = (&buffer != buffer.masterBuffer());
+ BranchList branchlist = buffer.params().branchlist();
+ if ((!is_child && branchlist.find(name))
+ || (is_child && (branchlist.find(name)
+ || buffer.masterBuffer()->params().branchlist().find(name))))
+ break;
+ // FIXME: add an option to add the branch to the master's BranchList.
+ docstring text = bformat(
+ _("The pasted branch \"%1$s\" is undefined.\n"
+ "Do you want to add it to the document's branch list?"),
+ name);
+ if (frontend::Alert::prompt(_("Unknown branch"),
+ text, 0, 1, _("&Add"), _("&Don't Add")) != 0)
+ break;
+ lyx::dispatch(FuncRequest(LFUN_BRANCH_ADD, name));
+ break;
+ }
+
default:
break; // nothing
}
LFUN_FONT_UWAVE,
LFUN_BUFFER_EXPORT, // Lgb 97-07-29
LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427
+ LFUN_BRANCH_ADD, // spitz 20090707
LFUN_LASTACTION // end of the table
};
{ LFUN_COMPLETION_ACCEPT, "completion-accept", SingleParUpdate, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_ADD
+ * \li Action: Add a branch to the buffer's BranchList
+ * \li Syntax: branch-add <BRANCH>
+ * \li Params: <BRANCH>: Name of the branch to add
+ * \li Origin: spitz, 7 Jul 2009
+ * \endvar
+ */
+ { LFUN_BRANCH_ADD, "branch-add", Noop, Buffer },
+
+
/*!
* \var lyx::FuncCode lyx::LFUN_BRANCH_ACTIVATE
* \li Action: Activate the branch
#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>
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)
branchesTW->setItemSelected(newItem, true);
}
}
+ unknownPB->setEnabled(!unknown_branches_.isEmpty());
// emit signal
changed();
}
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
#ifndef GUIBRANCHES_H
#define GUIBRANCHES_H
+#include "Buffer.h"
#include "GuiDocument.h"
+#include "ui_BranchesUnknownUi.h"
#include "ui_BranchesUi.h"
#include "BranchList.h"
namespace frontend {
+class BranchesUnknownDialog : public QDialog, public Ui::BranchesUnknownUi
+{
+public:
+ BranchesUnknownDialog(QWidget * parent) : QDialog(parent)
+ {
+ Ui::BranchesUnknownUi::setupUi(this);
+ QDialog::setModal(true);
+ }
+};
+
class GuiBranches : public QWidget, public Ui::BranchesUi
{
Q_OBJECT
void update(BufferParams const & params);
void apply(BufferParams & params) const;
+ void setUnknownBranches(QStringList const & b) { unknown_branches_ = b; }
Q_SIGNALS:
void changed();
void on_activatePB_pressed();
void on_branchesTW_itemDoubleClicked(QTreeWidgetItem *, int);
void on_colorPB_clicked();
+ void on_unknownPB_pressed();
+ void addUnknown();
+ void addAllUnknown();
+ void unknownBranchSelChanged();
private:
/// Contains all legal branches for this doc
BranchList branchlist_;
+ ///
+ BranchesUnknownDialog * undef_;
+ ///
+ ButtonController undef_bc_;
+ ///
+ QStringList unknown_branches_;
};
} // namespace frontend
branchesModule = new GuiBranches;
connect(branchesModule, SIGNAL(changed()),
this, SLOT(change_adaptor()));
+ updateUnknownBranches();
// preamble
preambleModule = new PreambleModule;
lengthToWidgets(m->columnsepLE, m->columnsepUnit,
bp_.columnsep, defaultUnit);
+ // branches
+ updateUnknownBranches();
branchesModule->update(bp_);
// PDF support
}
+void GuiDocument::updateUnknownBranches()
+{
+ list<docstring> used_branches;
+ buffer().getUsedBranches(used_branches);
+ list<docstring>::const_iterator it = used_branches.begin();
+ QStringList unknown_branches;
+ for (it ; it != used_branches.end() ; ++it) {
+ if (!buffer().params().branchlist().find(*it))
+ unknown_branches.append(toqstr(*it));
+ }
+ branchesModule->setUnknownBranches(unknown_branches);
+}
+
+
Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
///
void loadModuleInfo();
///
+ void updateUnknownBranches();
+ ///
BufferParams bp_;
/// List of names of available modules
std::list<modInfoStruct> moduleNames_;
BibtexUi.ui \
BoxUi.ui \
BranchesUi.ui \
+ BranchesUnknownUi.ui \
BranchUi.ui \
BulletsUi.ui \
ChangesUi.ui \
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>BranchesUi</class>
<widget class="QWidget" name="BranchesUi" >
<property name="geometry" >
<x>0</x>
<y>0</y>
<width>401</width>
- <height>300</height>
+ <height>327</height>
</rect>
</property>
<property name="windowTitle" >
<property name="spacing" >
<number>6</number>
</property>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="newBranchLE" />
+ <item row="7" column="2" colspan="2" >
+ <widget class="QPushButton" name="unknownPB" >
+ <property name="toolTip" >
+ <string>Show undefined branches used in this document.</string>
+ </property>
+ <property name="text" >
+ <string>&Undefined Branches</string>
+ </property>
+ </widget>
</item>
- <item row="5" column="2" >
+ <item row="4" column="3" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
- <item row="0" column="2" >
- <widget class="QPushButton" name="addBranchPB" >
- <property name="toolTip" >
- <string>Add a new branch to the list</string>
+ <item row="7" column="0" colspan="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
</property>
- <property name="text" >
- <string>&Add</string>
+ <property name="sizeHint" >
+ <size>
+ <width>251</width>
+ <height>20</height>
+ </size>
</property>
- </widget>
+ </spacer>
</item>
- <item row="1" column="0" colspan="2" >
+ <item row="1" column="0" colspan="3" >
<widget class="QLabel" name="availableLB" >
<property name="text" >
<string>A&vailable Branches:</string>
</property>
</widget>
</item>
- <item row="0" column="0" >
- <widget class="QLabel" name="newBranchLA" >
- <property name="text" >
- <string>&New:</string>
- </property>
- <property name="buddy" >
- <cstring>newBranchLE</cstring>
- </property>
- </widget>
- </item>
- <item rowspan="4" row="2" column="0" colspan="2" >
- <widget class="QTreeWidget" name="branchesTW" />
- </item>
- <item row="2" column="2" >
+ <item row="2" column="3" >
<widget class="QPushButton" name="removePB" >
<property name="toolTip" >
<string>Remove the selected branch</string>
</property>
</widget>
</item>
- <item row="5" column="2" >
+ <item row="5" column="3" >
<widget class="QPushButton" name="activatePB" >
<property name="toolTip" >
<string>Toggle the selected branch</string>
</property>
</widget>
</item>
- <item row="3" column="2" >
+ <item row="3" column="3" >
<widget class="QPushButton" name="colorPB" >
<property name="toolTip" >
<string>Define or change background color</string>
</property>
</widget>
</item>
+ <item rowspan="5" row="2" column="0" colspan="3" >
+ <widget class="QTreeWidget" name="branchesTW" />
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="newBranchLA" >
+ <property name="text" >
+ <string>&New:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>newBranchLE</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <widget class="QPushButton" name="addBranchPB" >
+ <property name="toolTip" >
+ <string>Add a new branch to the list</string>
+ </property>
+ <property name="text" >
+ <string>&Add</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2" >
+ <widget class="QLineEdit" name="newBranchLE" />
+ </item>
</layout>
</widget>
- <pixmapfunction></pixmapfunction>
<includes>
<include location="local" >qt_i18n.h</include>
</includes>
--- /dev/null
+<ui version="4.0" >
+ <class>BranchesUnknownUi</class>
+ <widget class="QWidget" name="BranchesUnknownUi" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>401</width>
+ <height>234</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string/>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="1" column="1" >
+ <widget class="QPushButton" name="addSelectedPB" >
+ <property name="toolTip" >
+ <string>Add the selected branches to the list.</string>
+ </property>
+ <property name="text" >
+ <string>&Add Selected</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QPushButton" name="addAllPB" >
+ <property name="toolTip" >
+ <string>Add all unknown branches to the list.</string>
+ </property>
+ <property name="text" >
+ <string>Add A&ll</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>81</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" column="1" >
+ <widget class="QPushButton" name="cancelPB" >
+ <property name="text" >
+ <string>&Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="branchesLA" >
+ <property name="toolTip" >
+ <string>Undefined branches used in this document.</string>
+ </property>
+ <property name="text" >
+ <string>&Undefined Branches:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>branchesLW</cstring>
+ </property>
+ </widget>
+ </item>
+ <item rowspan="4" row="1" column="0" >
+ <widget class="QListWidget" name="branchesLW" >
+ <property name="toolTip" >
+ <string>Undefined branches used in this document.</string>
+ </property>
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::MultiSelection</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <includes>
+ <include location="local" >qt_i18n.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>DocumentUi</class>
<widget class="QDialog" name="DocumentUi" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>422</width>
- <height>124</height>
+ <width>436</width>
+ <height>175</height>
</rect>
</property>
<property name="sizePolicy" >
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QGridLayout" >
<property name="margin" >
- <number>11</number>
+ <number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
- <item>
- <widget class="lyx::frontend::PanelStack" name="docPS" />
- </item>
- <item>
+ <item row="0" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
<number>6</number>
</property>
<item>
- <widget class="QPushButton" name="defaultPB" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <widget class="QRadioButton" name="childRB" >
<property name="toolTip" >
- <string>Reset to the default settings for the document class</string>
+ <string>Click to edit the settings of the child document</string>
</property>
<property name="text" >
- <string>Use Class Defaults</string>
+ <string>Child Settings</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="savePB" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <widget class="QRadioButton" name="masterRB" >
<property name="toolTip" >
- <string>Save settings as LyX's default document settings</string>
+ <string>Click to edit the settings of the Master document</string>
</property>
<property name="text" >
- <string>Save as Document Defaults</string>
+ <string>Master Settings</string>
</property>
</widget>
</item>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
<property name="sizeHint" >
<size>
- <width>20</width>
+ <width>181</width>
<height>20</height>
</size>
</property>
</item>
</layout>
</item>
- <item>
+ <item row="3" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</item>
</layout>
</item>
+ <item row="2" column="0" >
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="defaultPB" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Reset to the default settings for the document class</string>
+ </property>
+ <property name="text" >
+ <string>Use Class Defaults</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="savePB" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Save settings as LyX's default document settings</string>
+ </property>
+ <property name="text" >
+ <string>Save as Document Defaults</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" >
+ <widget class="lyx::frontend::PanelStack" native="1" name="docPS" />
+ </item>
</layout>
</widget>
- <pixmapfunction></pixmapfunction>
- <includes>
- <include location="local" >qt_i18n.h</include>
- </includes>
<customwidgets>
<customwidget>
<class>lyx::frontend::PanelStack</class>
- <extends></extends>
+ <extends>QWidget</extends>
<header>PanelStack.h</header>
<container>1</container>
- <pixmap></pixmap>
</customwidget>
</customwidgets>
+ <includes>
+ <include location="local" >qt_i18n.h</include>
+ </includes>
<resources/>
<connections/>
</ui>
static std::string params2string(InsetBranchParams const &);
///
static void string2params(std::string const &, InsetBranchParams &);
+ ///
+ docstring branch() const { return params_.branch; }
private:
///