mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 13:48:59 +00:00
Re-engineer the toolbar support code:
- We now rely more upon Qt features, - the initial toolbar positioning defined in "lib/ui/default.ui" is now only used if there is no session or if session handling is disabled, - The session saving/restoring is window dependent. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24954 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1a560fe0e2
commit
7bb8a5f183
@ -746,7 +746,6 @@ src_frontends_qt4_header_files = Split('''
|
|||||||
GuiThesaurus.h
|
GuiThesaurus.h
|
||||||
GuiToc.h
|
GuiToc.h
|
||||||
GuiToolbar.h
|
GuiToolbar.h
|
||||||
GuiToolbars.h
|
|
||||||
GuiView.h
|
GuiView.h
|
||||||
GuiViewSource.h
|
GuiViewSource.h
|
||||||
GuiVSpace.h
|
GuiVSpace.h
|
||||||
@ -837,7 +836,6 @@ src_frontends_qt4_files = Split('''
|
|||||||
GuiThesaurus.cpp
|
GuiThesaurus.cpp
|
||||||
GuiToc.cpp
|
GuiToc.cpp
|
||||||
GuiToolbar.cpp
|
GuiToolbar.cpp
|
||||||
GuiToolbars.cpp
|
|
||||||
GuiView.cpp
|
GuiView.cpp
|
||||||
GuiViewSource.cpp
|
GuiViewSource.cpp
|
||||||
GuiVSpace.cpp
|
GuiVSpace.cpp
|
||||||
|
@ -32,6 +32,7 @@ Include "stdtoolbars.inc"
|
|||||||
# math: the toolbar is visible only when in math
|
# math: the toolbar is visible only when in math
|
||||||
# mathmacrotemplate: the toolbar is visible only when in a macro definition
|
# mathmacrotemplate: the toolbar is visible only when in a macro definition
|
||||||
# table: the toolbar is visible only when in a table
|
# table: the toolbar is visible only when in a table
|
||||||
|
# review: the toolbar is visible only when inside a tracked change
|
||||||
#
|
#
|
||||||
# top: the toolbar should be at the top of the window
|
# top: the toolbar should be at the top of the window
|
||||||
# bottom: the toolbar should be at the bottom of the window
|
# bottom: the toolbar should be at the bottom of the window
|
||||||
|
@ -291,96 +291,6 @@ BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) co
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ToolbarSection::read(istream & is)
|
|
||||||
{
|
|
||||||
string tmp;
|
|
||||||
do {
|
|
||||||
char c = is.peek();
|
|
||||||
if (c == '[')
|
|
||||||
break;
|
|
||||||
getline(is, tmp);
|
|
||||||
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Read session info, saved as key/value pairs
|
|
||||||
// would better yell if pos returns npos
|
|
||||||
size_t pos = tmp.find_first_of(" = ");
|
|
||||||
// silently ignore lines without " = "
|
|
||||||
if (pos != string::npos) {
|
|
||||||
ToolbarItem item;
|
|
||||||
item.key = tmp.substr(0, pos);
|
|
||||||
int state;
|
|
||||||
int location;
|
|
||||||
istringstream value(tmp.substr(pos + 3));
|
|
||||||
value >> state;
|
|
||||||
value >> location;
|
|
||||||
value >> item.info.posx;
|
|
||||||
value >> item.info.posy;
|
|
||||||
item.info.state = ToolbarInfo::State(state);
|
|
||||||
item.info.location = ToolbarInfo::Location(location);
|
|
||||||
toolbars.push_back(item);
|
|
||||||
} else
|
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: Ignore toolbar info: " << tmp);
|
|
||||||
} catch (...) {
|
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: unknown Toolbar info: " << tmp);
|
|
||||||
}
|
|
||||||
} while (is.good());
|
|
||||||
// sort the toolbars by location, line and position
|
|
||||||
sort(toolbars.begin(), toolbars.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ToolbarSection::write(ostream & os) const
|
|
||||||
{
|
|
||||||
os << '\n' << sec_toolbars << '\n';
|
|
||||||
for (ToolbarList::const_iterator tb = toolbars.begin();
|
|
||||||
tb != toolbars.end(); ++tb) {
|
|
||||||
os << tb->key << " = "
|
|
||||||
<< static_cast<int>(tb->info.state) << " "
|
|
||||||
<< static_cast<int>(tb->info.location) << " "
|
|
||||||
<< tb->info.posx << " "
|
|
||||||
<< tb->info.posy << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name)
|
|
||||||
{
|
|
||||||
for (ToolbarList::iterator tb = toolbars.begin();
|
|
||||||
tb != toolbars.end(); ++tb)
|
|
||||||
if (tb->key == name)
|
|
||||||
return tb->info;
|
|
||||||
|
|
||||||
// add a new item
|
|
||||||
ToolbarItem item;
|
|
||||||
item.key = name;
|
|
||||||
toolbars.push_back(item);
|
|
||||||
return toolbars.back().info;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator<(ToolbarSection::ToolbarItem const & a, ToolbarSection::ToolbarItem const & b)
|
|
||||||
{
|
|
||||||
ToolbarSection::ToolbarInfo lhs = a.info;
|
|
||||||
ToolbarSection::ToolbarInfo rhs = b.info;
|
|
||||||
// on if before off
|
|
||||||
if (lhs.state != rhs.state)
|
|
||||||
return static_cast<int>(lhs.state) < static_cast<int>(rhs.state);
|
|
||||||
// order of dock does not really matter
|
|
||||||
if (lhs.location != rhs.location)
|
|
||||||
return static_cast<int>(lhs.location) < static_cast<int>(rhs.location);
|
|
||||||
// if the same dock, the order depends on position
|
|
||||||
if (lhs.location == ToolbarSection::ToolbarInfo::TOP ||
|
|
||||||
lhs.location == ToolbarSection::ToolbarInfo::BOTTOM)
|
|
||||||
return lhs.posy < rhs.posy || (lhs.posy == rhs.posy && lhs.posx < rhs.posx);
|
|
||||||
else if (lhs.location == ToolbarSection::ToolbarInfo::LEFT ||
|
|
||||||
lhs.location == ToolbarSection::ToolbarInfo::RIGHT)
|
|
||||||
return lhs.posx < rhs.posx || (lhs.posx == rhs.posx && lhs.posy < rhs.posy);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionInfoSection::read(istream & is)
|
void SessionInfoSection::read(istream & is)
|
||||||
{
|
{
|
||||||
string tmp;
|
string tmp;
|
||||||
@ -470,8 +380,6 @@ void Session::readFile()
|
|||||||
lastFilePos().read(is);
|
lastFilePos().read(is);
|
||||||
else if (tmp == sec_bookmarks)
|
else if (tmp == sec_bookmarks)
|
||||||
bookmarks().read(is);
|
bookmarks().read(is);
|
||||||
else if (tmp == sec_toolbars)
|
|
||||||
toolbars().read(is);
|
|
||||||
else if (tmp == sec_session)
|
else if (tmp == sec_session)
|
||||||
sessionInfo().read(is);
|
sessionInfo().read(is);
|
||||||
else
|
else
|
||||||
@ -491,7 +399,6 @@ void Session::writeFile() const
|
|||||||
lastOpened().write(os);
|
lastOpened().write(os);
|
||||||
lastFilePos().write(os);
|
lastFilePos().write(os);
|
||||||
bookmarks().write(os);
|
bookmarks().write(os);
|
||||||
toolbars().write(os);
|
|
||||||
sessionInfo().write(os);
|
sessionInfo().write(os);
|
||||||
} else
|
} else
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
|
LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
|
||||||
|
@ -263,93 +263,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ToolbarSection : SessionSection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/// information about a toolbar, not all information can be
|
|
||||||
/// saved/restored by all frontends, but this class provides
|
|
||||||
/// a superset of things that can be managed by session.
|
|
||||||
class ToolbarInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
ToolbarInfo()
|
|
||||||
: state(ON), location(NOTSET), posx(0), posy(0)
|
|
||||||
{}
|
|
||||||
///
|
|
||||||
//ToolbarInfo(int s, int loc, int x = 0, int y = 0)
|
|
||||||
// : state(State(s)), location(Location(loc)), posx(x), posy(y)
|
|
||||||
// {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum State {
|
|
||||||
ON,
|
|
||||||
OFF,
|
|
||||||
AUTO
|
|
||||||
};
|
|
||||||
|
|
||||||
/// on/off/auto
|
|
||||||
State state;
|
|
||||||
|
|
||||||
/// location: this can be intepreted differently.
|
|
||||||
enum Location {
|
|
||||||
TOP,
|
|
||||||
BOTTOM,
|
|
||||||
LEFT,
|
|
||||||
RIGHT,
|
|
||||||
NOTSET
|
|
||||||
};
|
|
||||||
|
|
||||||
Location location;
|
|
||||||
|
|
||||||
/// x-position of the toolbar
|
|
||||||
int posx;
|
|
||||||
|
|
||||||
/// y-position of the toolbar
|
|
||||||
int posy;
|
|
||||||
|
|
||||||
/// potentially, icons
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ToolbarItem {
|
|
||||||
std::string key;
|
|
||||||
ToolbarInfo info;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// info for each toolbar
|
|
||||||
typedef std::vector<ToolbarItem> ToolbarList;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
void read(std::istream & is);
|
|
||||||
|
|
||||||
///
|
|
||||||
void write(std::ostream & os) const;
|
|
||||||
|
|
||||||
/// return reference to toolbar info, create a new one if needed
|
|
||||||
ToolbarInfo & load(std::string const & name);
|
|
||||||
|
|
||||||
/// toolbar begin
|
|
||||||
ToolbarList::const_iterator begin() { return toolbars.begin(); }
|
|
||||||
|
|
||||||
/// toolbar end
|
|
||||||
ToolbarList::const_iterator end() { return toolbars.end(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// toolbar information
|
|
||||||
ToolbarList toolbars;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// comparison operator to sort toolbars, the rules are:
|
|
||||||
/// ON before OFF
|
|
||||||
/// TOP < BOTTOM < LEFT < RIGHT
|
|
||||||
/// Line at each side
|
|
||||||
/// order in each line
|
|
||||||
bool operator<(ToolbarSection::ToolbarItem const & a,
|
|
||||||
ToolbarSection::ToolbarItem const & b);
|
|
||||||
|
|
||||||
|
|
||||||
class SessionInfoSection : SessionSection
|
class SessionInfoSection : SessionSection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -406,10 +319,6 @@ public:
|
|||||||
///
|
///
|
||||||
BookmarksSection const & bookmarks() const { return bookmarks_; }
|
BookmarksSection const & bookmarks() const { return bookmarks_; }
|
||||||
///
|
///
|
||||||
ToolbarSection & toolbars() { return toolbars_; }
|
|
||||||
///
|
|
||||||
ToolbarSection const & toolbars() const { return toolbars_; }
|
|
||||||
///
|
|
||||||
SessionInfoSection & sessionInfo() { return session_info; }
|
SessionInfoSection & sessionInfo() { return session_info; }
|
||||||
///
|
///
|
||||||
SessionInfoSection const & sessionInfo() const { return session_info; }
|
SessionInfoSection const & sessionInfo() const { return session_info; }
|
||||||
@ -438,8 +347,6 @@ private:
|
|||||||
///
|
///
|
||||||
BookmarksSection bookmarks_;
|
BookmarksSection bookmarks_;
|
||||||
///
|
///
|
||||||
ToolbarSection toolbars_;
|
|
||||||
///
|
|
||||||
SessionInfoSection session_info;
|
SessionInfoSection session_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,9 +57,11 @@
|
|||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QSettings>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
#include <QString>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTextFrame>
|
#include <QTextFrame>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
@ -839,8 +841,8 @@ void GuiLayoutBox::selected(int index)
|
|||||||
|
|
||||||
|
|
||||||
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
||||||
: QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
|
: QToolBar(qt_(tbinfo.gui_name), &owner), visibility_(0),
|
||||||
layout_(0), command_buffer_(0)
|
allowauto_(false), owner_(owner), layout_(0), command_buffer_(0)
|
||||||
{
|
{
|
||||||
// give visual separation between adjacent toolbars
|
// give visual separation between adjacent toolbars
|
||||||
addSeparator();
|
addSeparator();
|
||||||
@ -848,10 +850,22 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
|||||||
// TODO: save toolbar position
|
// TODO: save toolbar position
|
||||||
setMovable(true);
|
setMovable(true);
|
||||||
|
|
||||||
|
//
|
||||||
|
setObjectName(toqstr(tbinfo.name));
|
||||||
|
|
||||||
ToolbarInfo::item_iterator it = tbinfo.items.begin();
|
ToolbarInfo::item_iterator it = tbinfo.items.begin();
|
||||||
ToolbarInfo::item_iterator end = tbinfo.items.end();
|
ToolbarInfo::item_iterator end = tbinfo.items.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
add(*it);
|
add(*it);
|
||||||
|
|
||||||
|
restoreSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiToolbar::setVisibility(int visibility)
|
||||||
|
{
|
||||||
|
visibility_ = visibility;
|
||||||
|
allowauto_ = visibility_ >= Toolbars::MATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -882,8 +896,7 @@ public:
|
|||||||
connect(bar_, SIGNAL(iconSizeChanged(QSize)),
|
connect(bar_, SIGNAL(iconSizeChanged(QSize)),
|
||||||
this, SLOT(setIconSize(QSize)));
|
this, SLOT(setIconSize(QSize)));
|
||||||
setCheckable(true);
|
setCheckable(true);
|
||||||
ToolbarInfo const * tbinfo =
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
||||||
guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_);
|
|
||||||
if (tbinfo)
|
if (tbinfo)
|
||||||
// use the icon of first action for the toolbar button
|
// use the icon of first action for the toolbar button
|
||||||
setIcon(getIcon(tbinfo->items.begin()->func_, true));
|
setIcon(getIcon(tbinfo->items.begin()->func_, true));
|
||||||
@ -898,8 +911,7 @@ public:
|
|||||||
|
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
ToolbarInfo const * tbinfo =
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
||||||
guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_);
|
|
||||||
if (!tbinfo) {
|
if (!tbinfo) {
|
||||||
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
||||||
return;
|
return;
|
||||||
@ -953,8 +965,7 @@ public:
|
|||||||
m->setWindowTitle(label);
|
m->setWindowTitle(label);
|
||||||
m->setTearOffEnabled(true);
|
m->setTearOffEnabled(true);
|
||||||
connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
|
connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
|
||||||
ToolbarInfo const * tbinfo =
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
||||||
guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_);
|
|
||||||
if (!tbinfo) {
|
if (!tbinfo) {
|
||||||
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
||||||
return;
|
return;
|
||||||
@ -1023,42 +1034,21 @@ void GuiToolbar::add(ToolbarItem const & item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
|
void GuiToolbar::update(bool in_math, bool in_table, bool in_review,
|
||||||
|
bool in_mathmacrotemplate)
|
||||||
{
|
{
|
||||||
// if tbinfo.state == auto *do not* set on/off
|
if (visibility_ & Toolbars::AUTO) {
|
||||||
if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
|
bool show_it = in_math && (visibility_ & Toolbars::MATH)
|
||||||
if (GuiToolbar::isVisible())
|
|| in_table && (visibility_ & Toolbars::TABLE)
|
||||||
tbinfo.state = ToolbarSection::ToolbarInfo::ON;
|
|| in_review && (visibility_ & Toolbars::REVIEW)
|
||||||
else
|
|| in_mathmacrotemplate && (visibility_ & Toolbars::MATHMACROTEMPLATE);
|
||||||
tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
|
setVisible(show_it);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// no need to save it here.
|
|
||||||
Qt::ToolBarArea loc = owner_.toolBarArea(this);
|
|
||||||
|
|
||||||
if (loc == Qt::TopToolBarArea)
|
|
||||||
tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
|
|
||||||
else if (loc == Qt::BottomToolBarArea)
|
|
||||||
tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
|
|
||||||
else if (loc == Qt::RightToolBarArea)
|
|
||||||
tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
|
|
||||||
else if (loc == Qt::LeftToolBarArea)
|
|
||||||
tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
|
|
||||||
else
|
|
||||||
tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
|
|
||||||
|
|
||||||
// save toolbar position. They are not used to restore toolbar position
|
|
||||||
// now because move(x,y) does not work for toolbar.
|
|
||||||
tbinfo.posx = pos().x();
|
|
||||||
tbinfo.posy = pos().y();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbar::updateContents()
|
|
||||||
{
|
|
||||||
// update visible toolbars only
|
// update visible toolbars only
|
||||||
if (!isVisible())
|
if (!isVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// This is a speed bottleneck because this is called on every keypress
|
// This is a speed bottleneck because this is called on every keypress
|
||||||
// and update calls getStatus, which copies the cursor at least two times
|
// and update calls getStatus, which copies the cursor at least two times
|
||||||
for (int i = 0; i < actions_.size(); ++i)
|
for (int i = 0; i < actions_.size(); ++i)
|
||||||
@ -1072,6 +1062,58 @@ void GuiToolbar::updateContents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString GuiToolbar::sessionKey() const
|
||||||
|
{
|
||||||
|
return "view-" + QString::number(owner_.id()) + "/" + objectName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiToolbar::saveSession() const
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
settings.setValue(sessionKey() + "/visibility", visibility_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiToolbar::restoreSession()
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
setVisibility(settings.value(sessionKey() + "/visibility").toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiToolbar::toggle()
|
||||||
|
{
|
||||||
|
docstring state;
|
||||||
|
if (allowauto_) {
|
||||||
|
if (!(visibility_ & Toolbars::AUTO)) {
|
||||||
|
visibility_ |= Toolbars::AUTO;
|
||||||
|
hide();
|
||||||
|
state = _("auto");
|
||||||
|
} else {
|
||||||
|
visibility_ &= ~Toolbars::AUTO;
|
||||||
|
if (isVisible()) {
|
||||||
|
hide();
|
||||||
|
state = _("off");
|
||||||
|
} else {
|
||||||
|
show();
|
||||||
|
state = _("on");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isVisible()) {
|
||||||
|
hide();
|
||||||
|
state = _("off");
|
||||||
|
} else {
|
||||||
|
show();
|
||||||
|
state = _("on");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
|
||||||
|
qstring_to_ucs4(windowTitle()), state));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -112,16 +112,32 @@ class GuiToolbar : public QToolBar
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
///
|
||||||
GuiToolbar(ToolbarInfo const &, GuiView &);
|
GuiToolbar(ToolbarInfo const &, GuiView &);
|
||||||
|
|
||||||
|
///
|
||||||
|
void setVisibility(int visibility);
|
||||||
|
|
||||||
/// Add a button to the bar.
|
/// Add a button to the bar.
|
||||||
void add(ToolbarItem const & item);
|
void add(ToolbarItem const & item);
|
||||||
/** update toolbar information
|
|
||||||
* ToolbarInfo will then be saved by session
|
/// Session key.
|
||||||
*/
|
/**
|
||||||
void saveInfo(ToolbarSection::ToolbarInfo & info);
|
* This key must be used for any session setting.
|
||||||
|
**/
|
||||||
|
QString sessionKey() const;
|
||||||
|
/// Save session settings.
|
||||||
|
void saveSession() const;
|
||||||
|
/// Restore session settings.
|
||||||
|
void restoreSession();
|
||||||
|
|
||||||
/// Refresh the contents of the bar.
|
/// Refresh the contents of the bar.
|
||||||
void updateContents();
|
void update(bool in_math, bool in_table, bool review,
|
||||||
|
bool in_mathmacrotemplate);
|
||||||
|
|
||||||
|
///
|
||||||
|
void toggle();
|
||||||
|
|
||||||
///
|
///
|
||||||
GuiCommandBuffer * commandBuffer() { return command_buffer_; }
|
GuiCommandBuffer * commandBuffer() { return command_buffer_; }
|
||||||
|
|
||||||
@ -133,11 +149,18 @@ Q_SIGNALS:
|
|||||||
void updated();
|
void updated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// load flags with saved values
|
||||||
|
void initFlags();
|
||||||
|
///
|
||||||
|
QString name_;
|
||||||
///
|
///
|
||||||
QList<Action *> actions_;
|
QList<Action *> actions_;
|
||||||
|
/// initial visibility flags
|
||||||
|
int visibility_;
|
||||||
|
///
|
||||||
|
bool allowauto_;
|
||||||
///
|
///
|
||||||
GuiView & owner_;
|
GuiView & owner_;
|
||||||
|
|
||||||
///
|
///
|
||||||
GuiLayoutBox * layout_;
|
GuiLayoutBox * layout_;
|
||||||
///
|
///
|
||||||
|
@ -1,387 +0,0 @@
|
|||||||
/**
|
|
||||||
* \file GuiToolbars.cpp
|
|
||||||
* This file is part of LyX, the document processor.
|
|
||||||
* Licence details can be found in the file COPYING.
|
|
||||||
*
|
|
||||||
* \author Lars Gullik Bjønnes
|
|
||||||
* \author Angus Leeming
|
|
||||||
* \author Abdelrazak Younes
|
|
||||||
*
|
|
||||||
* Full author contact details are available in file CREDITS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "GuiToolbars.h"
|
|
||||||
|
|
||||||
#include "GuiApplication.h"
|
|
||||||
#include "GuiCommandBuffer.h"
|
|
||||||
#include "GuiToolbar.h"
|
|
||||||
#include "GuiView.h"
|
|
||||||
#include "Toolbars.h"
|
|
||||||
|
|
||||||
#include "Buffer.h"
|
|
||||||
#include "BufferParams.h"
|
|
||||||
#include "FuncRequest.h"
|
|
||||||
#include "FuncStatus.h"
|
|
||||||
#include "Layout.h"
|
|
||||||
#include "LyX.h"
|
|
||||||
#include "LyXFunc.h"
|
|
||||||
#include "TextClass.h"
|
|
||||||
|
|
||||||
#include "support/debug.h"
|
|
||||||
#include "support/gettext.h"
|
|
||||||
|
|
||||||
#include "support/lassert.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace lyx {
|
|
||||||
namespace frontend {
|
|
||||||
|
|
||||||
#define TurnOnFlag(x) flags |= ToolbarInfo::x
|
|
||||||
#define TurnOffFlag(x) flags &= ~ToolbarInfo::x
|
|
||||||
|
|
||||||
GuiToolbars::GuiToolbars(GuiView & owner)
|
|
||||||
: owner_(owner)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::initFlags(ToolbarInfo & tbinfo)
|
|
||||||
{
|
|
||||||
ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name);
|
|
||||||
|
|
||||||
unsigned int flags = static_cast<unsigned int>(tbinfo.flags);
|
|
||||||
|
|
||||||
// Remove default.ui positions. Only when a valid postion is stored
|
|
||||||
// in the session file the default.ui value will be overwritten
|
|
||||||
unsigned int save = flags;
|
|
||||||
TurnOffFlag(TOP);
|
|
||||||
TurnOffFlag(BOTTOM);
|
|
||||||
TurnOffFlag(RIGHT);
|
|
||||||
TurnOffFlag(LEFT);
|
|
||||||
|
|
||||||
bool valid_location = true;
|
|
||||||
// init tbinfo.flags with saved location
|
|
||||||
if (info.location == ToolbarSection::ToolbarInfo::TOP)
|
|
||||||
TurnOnFlag(TOP);
|
|
||||||
else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM)
|
|
||||||
TurnOnFlag(BOTTOM);
|
|
||||||
else if (info.location == ToolbarSection::ToolbarInfo::RIGHT)
|
|
||||||
TurnOnFlag(RIGHT);
|
|
||||||
else if (info.location == ToolbarSection::ToolbarInfo::LEFT)
|
|
||||||
TurnOnFlag(LEFT);
|
|
||||||
else {
|
|
||||||
// use setting from default.ui
|
|
||||||
flags = save;
|
|
||||||
valid_location = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalid location is for a new toolbar that has no saved information,
|
|
||||||
// so info.visible is not used for this case.
|
|
||||||
if (valid_location) {
|
|
||||||
// init tbinfo.flags with saved visibility,
|
|
||||||
TurnOffFlag(ON);
|
|
||||||
TurnOffFlag(OFF);
|
|
||||||
TurnOffFlag(AUTO);
|
|
||||||
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
|
||||||
TurnOnFlag(ON);
|
|
||||||
else if (info.state == ToolbarSection::ToolbarInfo::OFF)
|
|
||||||
TurnOnFlag(OFF);
|
|
||||||
else
|
|
||||||
TurnOnFlag(AUTO);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
cout << "State " << info.state << " FLAGS: " << flags
|
|
||||||
<< " ON:" << (flags & Toolbars::ON)
|
|
||||||
<< " OFF:" << (flags & Toolbars::OFF)
|
|
||||||
<< " L:" << (flags & Toolbars::LEFT)
|
|
||||||
<< " R:" << (flags & Toolbars::RIGHT)
|
|
||||||
<< " T:" << (flags & Toolbars::TOP)
|
|
||||||
<< " B:" << (flags & Toolbars::BOTTOM)
|
|
||||||
<< " MA:" << (flags & Toolbars::MATH)
|
|
||||||
<< " RE:" << (flags & Toolbars::REVIEW)
|
|
||||||
<< " TB:" << (flags & Toolbars::TABLE)
|
|
||||||
<< " AU:" << (flags & Toolbars::AUTO)
|
|
||||||
<< endl;
|
|
||||||
*/
|
|
||||||
// now set the flags
|
|
||||||
tbinfo.flags = static_cast<ToolbarInfo::Flags>(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::init()
|
|
||||||
{
|
|
||||||
ToolbarsMap::iterator it = toolbars_.begin();
|
|
||||||
for (; it != toolbars_.end(); ++it)
|
|
||||||
delete it->second;
|
|
||||||
toolbars_.clear();
|
|
||||||
|
|
||||||
// extracts the toolbars from the backend
|
|
||||||
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
||||||
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
|
||||||
|
|
||||||
// init flags will also add these toolbars to session if they
|
|
||||||
// are not already there (e.g. first run of lyx).
|
|
||||||
for (; cit != end; ++cit)
|
|
||||||
initFlags(*cit);
|
|
||||||
|
|
||||||
// add toolbars according the order in session
|
|
||||||
ToolbarSection::ToolbarList::const_iterator tb =
|
|
||||||
LyX::ref().session().toolbars().begin();
|
|
||||||
ToolbarSection::ToolbarList::const_iterator te =
|
|
||||||
LyX::ref().session().toolbars().end();
|
|
||||||
ToolbarSection::ToolbarInfo::Location last_loc =
|
|
||||||
ToolbarSection::ToolbarInfo::NOTSET;
|
|
||||||
int last_posx = 0;
|
|
||||||
int last_posy = 0;
|
|
||||||
for (; tb != te; ++tb) {
|
|
||||||
LYXERR(Debug::INIT, "Adding " << tb->key << " at position "
|
|
||||||
<< tb->info.posx << " " << tb->info.posy);
|
|
||||||
// add toolbar break if posx or posy changes
|
|
||||||
bool newline = tb->info.location == last_loc && (
|
|
||||||
// if two toolbars at the same location, assume uninitialized and add toolbar break
|
|
||||||
(tb->info.posx == last_posx && tb->info.posy == last_posy) ||
|
|
||||||
(last_loc == ToolbarSection::ToolbarInfo::TOP && tb->info.posy != last_posy) ||
|
|
||||||
(last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->info.posy != last_posy) ||
|
|
||||||
(last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->info.posx != last_posx) ||
|
|
||||||
(last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->info.posx != last_posx) );
|
|
||||||
// find the backend item and add
|
|
||||||
for (cit = guiApp->toolbars().begin(); cit != end; ++cit)
|
|
||||||
if (cit->name == tb->key) {
|
|
||||||
add(*cit, newline);
|
|
||||||
last_loc = tb->info.location;
|
|
||||||
last_posx = tb->info.posx;
|
|
||||||
last_posy = tb->info.posy;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::display(string const & name, bool show)
|
|
||||||
{
|
|
||||||
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
||||||
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
|
||||||
if (cit->name == name) {
|
|
||||||
unsigned int flags = cit->flags;
|
|
||||||
TurnOffFlag(ON);
|
|
||||||
TurnOffFlag(OFF);
|
|
||||||
TurnOffFlag(AUTO);
|
|
||||||
if (show)
|
|
||||||
TurnOnFlag(ON);
|
|
||||||
else
|
|
||||||
TurnOnFlag(OFF);
|
|
||||||
cit->flags = static_cast<ToolbarInfo::Flags>(flags);
|
|
||||||
displayToolbar(*cit, show);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ToolbarInfo * GuiToolbars::getToolbarInfo(string const & name)
|
|
||||||
{
|
|
||||||
return guiApp->toolbars().getUsedToolbarInfo(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::toggleToolbarState(string const & name, bool allowauto)
|
|
||||||
{
|
|
||||||
ToolbarInfo * tbi = guiApp->toolbars().getUsedToolbarInfo(name);
|
|
||||||
|
|
||||||
if (!tbi) {
|
|
||||||
LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int flags = tbi->flags;
|
|
||||||
// off -> on
|
|
||||||
if (flags & ToolbarInfo::OFF) {
|
|
||||||
TurnOffFlag(OFF);
|
|
||||||
TurnOnFlag(ON);
|
|
||||||
// auto -> off
|
|
||||||
} else if (flags & ToolbarInfo::AUTO) {
|
|
||||||
TurnOffFlag(AUTO);
|
|
||||||
TurnOnFlag(OFF);
|
|
||||||
} else if (allowauto
|
|
||||||
&& ((flags & ToolbarInfo::MATH)
|
|
||||||
|| (flags & ToolbarInfo::TABLE)
|
|
||||||
|| (flags & ToolbarInfo::REVIEW)
|
|
||||||
|| (flags & ToolbarInfo::MATHMACROTEMPLATE))) {
|
|
||||||
// for math etc, toggle from on -> auto
|
|
||||||
TurnOffFlag(ON);
|
|
||||||
TurnOnFlag(AUTO);
|
|
||||||
} else {
|
|
||||||
// for others, toggle from on -> off
|
|
||||||
TurnOffFlag(ON);
|
|
||||||
TurnOnFlag(OFF);
|
|
||||||
}
|
|
||||||
tbi->flags = static_cast<ToolbarInfo::Flags>(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::toggleFullScreen(bool start_full_screen)
|
|
||||||
{
|
|
||||||
// we need to know number of fullscreens until every
|
|
||||||
// LyXView has its own toolbar configuration
|
|
||||||
guiApp->toolbars().fullScreenWindows += start_full_screen ? 1 : -1;
|
|
||||||
|
|
||||||
// extracts the toolbars from the backend
|
|
||||||
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
||||||
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
|
||||||
|
|
||||||
if (start_full_screen) {
|
|
||||||
if (guiApp->toolbars().fullScreenWindows == 1)
|
|
||||||
flags = cit->before_fullscreen = cit->flags;
|
|
||||||
TurnOffFlag(ON);
|
|
||||||
TurnOffFlag(AUTO);
|
|
||||||
TurnOnFlag(OFF);
|
|
||||||
} else
|
|
||||||
flags = cit->before_fullscreen;
|
|
||||||
|
|
||||||
cit->flags = static_cast<ToolbarInfo::Flags>(flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#undef TurnOnFlag
|
|
||||||
#undef TurnOffFlag
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::update(bool in_math, bool in_table, bool review,
|
|
||||||
bool in_mathmacrotemplate)
|
|
||||||
{
|
|
||||||
updateIcons();
|
|
||||||
|
|
||||||
// extracts the toolbars from the backend
|
|
||||||
Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
|
|
||||||
Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
|
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
|
||||||
if (cit->flags & ToolbarInfo::ON)
|
|
||||||
displayToolbar(*cit, true);
|
|
||||||
else if (cit->flags & ToolbarInfo::OFF)
|
|
||||||
displayToolbar(*cit, false);
|
|
||||||
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH))
|
|
||||||
displayToolbar(*cit, in_math);
|
|
||||||
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE))
|
|
||||||
displayToolbar(*cit, in_table);
|
|
||||||
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW))
|
|
||||||
displayToolbar(*cit, review);
|
|
||||||
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATHMACROTEMPLATE))
|
|
||||||
displayToolbar(*cit, in_mathmacrotemplate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GuiToolbars::visible(string const & name) const
|
|
||||||
{
|
|
||||||
map<string, GuiToolbar *>::const_iterator it =
|
|
||||||
toolbars_.find(name);
|
|
||||||
if (it == toolbars_.end())
|
|
||||||
return false;
|
|
||||||
return it->second->isVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::saveToolbarInfo()
|
|
||||||
{
|
|
||||||
ToolbarSection & tb = LyX::ref().session().toolbars();
|
|
||||||
|
|
||||||
for (Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
||||||
cit != guiApp->toolbars().end(); ++cit) {
|
|
||||||
ToolbarsMap::iterator it = toolbars_.find(cit->name);
|
|
||||||
LASSERT(it != toolbars_.end(), /**/);
|
|
||||||
// get toolbar info from session.
|
|
||||||
ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
|
|
||||||
if (cit->flags & ToolbarInfo::ON)
|
|
||||||
info.state = ToolbarSection::ToolbarInfo::ON;
|
|
||||||
else if (cit->flags & ToolbarInfo::OFF)
|
|
||||||
info.state = ToolbarSection::ToolbarInfo::OFF;
|
|
||||||
else if (cit->flags & ToolbarInfo::AUTO)
|
|
||||||
info.state = ToolbarSection::ToolbarInfo::AUTO;
|
|
||||||
// save other information
|
|
||||||
// if auto, frontend should *not* set on/off
|
|
||||||
it->second->saveInfo(info);
|
|
||||||
// maybe it is useful to update flags with real status. I do not know
|
|
||||||
/*
|
|
||||||
if (!(cit->flags & ToolbarInfo::AUTO)) {
|
|
||||||
unsigned int flags = static_cast<unsigned int>(cit->flags);
|
|
||||||
flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
|
|
||||||
flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
|
|
||||||
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
|
||||||
cit->flags = static_cast<ToolbarInfo::Flags>(flags);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
|
||||||
{
|
|
||||||
GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline);
|
|
||||||
toolbars_[tbinfo.name] = tb_ptr;
|
|
||||||
|
|
||||||
if (tbinfo.flags & ToolbarInfo::ON)
|
|
||||||
tb_ptr->show();
|
|
||||||
else
|
|
||||||
tb_ptr->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::displayToolbar(ToolbarInfo const & tbinfo,
|
|
||||||
bool show_it)
|
|
||||||
{
|
|
||||||
ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
|
|
||||||
LASSERT(it != toolbars_.end(), /**/);
|
|
||||||
|
|
||||||
if (show_it) {
|
|
||||||
if (it->second->isVisible())
|
|
||||||
return;
|
|
||||||
it->second->show();
|
|
||||||
}
|
|
||||||
else if (it->second->isVisible())
|
|
||||||
it->second->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::updateIcons()
|
|
||||||
{
|
|
||||||
ToolbarsMap::const_iterator it = toolbars_.begin();
|
|
||||||
ToolbarsMap::const_iterator const end = toolbars_.end();
|
|
||||||
for (; it != end; ++it)
|
|
||||||
it->second->updateContents();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiToolbars::showCommandBuffer(bool show_it)
|
|
||||||
{
|
|
||||||
ToolbarsMap::const_iterator it = toolbars_.begin();
|
|
||||||
ToolbarsMap::const_iterator const end = toolbars_.end();
|
|
||||||
for (; it != end; ++it) {
|
|
||||||
GuiCommandBuffer * cb = it->second->commandBuffer();
|
|
||||||
if (!cb)
|
|
||||||
continue;
|
|
||||||
if (!show_it) {
|
|
||||||
// FIXME: this is a hack, "minibuffer" should not be
|
|
||||||
// hardcoded.
|
|
||||||
display("minibuffer", false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!it->second->isVisible())
|
|
||||||
display("minibuffer", true);
|
|
||||||
cb->setFocus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace frontend
|
|
||||||
} // namespace lyx
|
|
@ -1,95 +0,0 @@
|
|||||||
// -*- C++ -*-
|
|
||||||
/**
|
|
||||||
* \file GuiToolbars.h
|
|
||||||
* This file is part of LyX, the document processor.
|
|
||||||
* Licence details can be found in the file COPYING.
|
|
||||||
*
|
|
||||||
* \author Lars Gullik Bjønnes
|
|
||||||
* \author Angus Leeming
|
|
||||||
* \author Abdelrazak Younes
|
|
||||||
*
|
|
||||||
* Full author contact details are available in file CREDITS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GUI_TOOLBARS_H
|
|
||||||
#define GUI_TOOLBARS_H
|
|
||||||
|
|
||||||
#include "support/docstring.h"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace lyx {
|
|
||||||
|
|
||||||
class DocumentClass;
|
|
||||||
|
|
||||||
namespace frontend {
|
|
||||||
|
|
||||||
class GuiToolbar;
|
|
||||||
class GuiView;
|
|
||||||
class ToolbarInfo;
|
|
||||||
|
|
||||||
class GuiToolbars
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
GuiToolbars(GuiView & owner);
|
|
||||||
|
|
||||||
/// Initialize the toolbars using the backend database.
|
|
||||||
void init();
|
|
||||||
|
|
||||||
/// Show/hide the named toolbar.
|
|
||||||
void display(std::string const & name, bool show);
|
|
||||||
|
|
||||||
/// get toolbar info
|
|
||||||
ToolbarInfo * getToolbarInfo(std::string const & name);
|
|
||||||
|
|
||||||
/** toggle the state of toolbars (on/off/auto). Skip "auto"
|
|
||||||
* when allowauto is false.
|
|
||||||
*/
|
|
||||||
void toggleToolbarState(std::string const & name, bool allowauto);
|
|
||||||
|
|
||||||
/// Update the state of the toolbars.
|
|
||||||
void update(bool in_math, bool in_table, bool review,
|
|
||||||
bool in_mathmacrotemplate);
|
|
||||||
|
|
||||||
/// Is the Toolbar currently visible?
|
|
||||||
bool visible(std::string const & name) const;
|
|
||||||
|
|
||||||
/// save toolbar information
|
|
||||||
void saveToolbarInfo();
|
|
||||||
|
|
||||||
/// Show or hide the command buffer.
|
|
||||||
void showCommandBuffer(bool show_it);
|
|
||||||
|
|
||||||
/// toggle visibility of toolbars and save its flags for return
|
|
||||||
void toggleFullScreen(bool start_full_screen);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Add a new toolbar. if newline==true, start from a new line
|
|
||||||
void add(ToolbarInfo const & tbinfo, bool newline);
|
|
||||||
|
|
||||||
/// Show or hide a toolbar.
|
|
||||||
void displayToolbar(ToolbarInfo const & tbinfo, bool show);
|
|
||||||
|
|
||||||
/// Update the state of the icons
|
|
||||||
void updateIcons();
|
|
||||||
|
|
||||||
// load flags with saved values
|
|
||||||
void initFlags(ToolbarInfo & tbinfo);
|
|
||||||
|
|
||||||
/// The parent window.
|
|
||||||
GuiView & owner_;
|
|
||||||
|
|
||||||
/// Toolbar store providing access to individual toolbars by name.
|
|
||||||
typedef std::map<std::string, GuiToolbar *> ToolbarsMap;
|
|
||||||
ToolbarsMap toolbars_;
|
|
||||||
|
|
||||||
/// The last textclass layout list in the layout choice selector
|
|
||||||
DocumentClass * last_textclass_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
|
||||||
} // namespace lyx
|
|
||||||
|
|
||||||
#endif // GUI_TOOLBARS_H
|
|
@ -141,11 +141,14 @@ private:
|
|||||||
QPixmap splash_;
|
QPixmap splash_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace anon
|
/// Toolbar store providing access to individual toolbars by name.
|
||||||
|
typedef std::map<std::string, GuiToolbar *> ToolbarMap;
|
||||||
|
|
||||||
typedef boost::shared_ptr<Dialog> DialogPtr;
|
typedef boost::shared_ptr<Dialog> DialogPtr;
|
||||||
|
|
||||||
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
struct GuiView::GuiViewPrivate
|
struct GuiView::GuiViewPrivate
|
||||||
{
|
{
|
||||||
GuiViewPrivate()
|
GuiViewPrivate()
|
||||||
@ -170,7 +173,6 @@ struct GuiView::GuiViewPrivate
|
|||||||
delete splitter_;
|
delete splitter_;
|
||||||
delete bg_widget_;
|
delete bg_widget_;
|
||||||
delete stack_widget_;
|
delete stack_widget_;
|
||||||
delete toolbars_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu * toolBarPopup(GuiView * parent)
|
QMenu * toolBarPopup(GuiView * parent)
|
||||||
@ -244,7 +246,7 @@ public:
|
|||||||
QStackedWidget * stack_widget_;
|
QStackedWidget * stack_widget_;
|
||||||
BackgroundWidget * bg_widget_;
|
BackgroundWidget * bg_widget_;
|
||||||
/// view's toolbars
|
/// view's toolbars
|
||||||
GuiToolbars * toolbars_;
|
ToolbarMap toolbars_;
|
||||||
/// The main layout box.
|
/// The main layout box.
|
||||||
/**
|
/**
|
||||||
* \warning Don't Delete! The layout box is actually owned by
|
* \warning Don't Delete! The layout box is actually owned by
|
||||||
@ -281,7 +283,7 @@ GuiView::GuiView(int id)
|
|||||||
: d(*new GuiViewPrivate), id_(id)
|
: d(*new GuiViewPrivate), id_(id)
|
||||||
{
|
{
|
||||||
// GuiToolbars *must* be initialised before the menu bar.
|
// GuiToolbars *must* be initialised before the menu bar.
|
||||||
d.toolbars_ = new GuiToolbars(*this);
|
constructToolbars();
|
||||||
|
|
||||||
// set ourself as the current view. This is needed for the menu bar
|
// set ourself as the current view. This is needed for the menu bar
|
||||||
// filling, at least for the static special menu item on Mac. Otherwise
|
// filling, at least for the static special menu item on Mac. Otherwise
|
||||||
@ -320,12 +322,17 @@ GuiView::GuiView(int id)
|
|||||||
// with some window manager under X11.
|
// with some window manager under X11.
|
||||||
setMinimumSize(300, 200);
|
setMinimumSize(300, 200);
|
||||||
|
|
||||||
if (!lyxrc.allow_geometry_session)
|
|
||||||
// No session handling, default to a sane size.
|
|
||||||
setGeometry(50, 50, 690, 510);
|
|
||||||
|
|
||||||
// Now take care of session management.
|
// Now take care of session management.
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
if (!lyxrc.allow_geometry_session) {
|
||||||
|
// No session handling, default to a sane size.
|
||||||
|
setGeometry(50, 50, 690, 510);
|
||||||
|
initToolbars();
|
||||||
|
settings.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString const key = "view-" + QString::number(id_);
|
QString const key = "view-" + QString::number(id_);
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
QPoint pos = settings.value(key + "/pos", QPoint(50, 50)).toPoint();
|
QPoint pos = settings.value(key + "/pos", QPoint(50, 50)).toPoint();
|
||||||
@ -336,6 +343,9 @@ GuiView::GuiView(int id)
|
|||||||
if (!restoreGeometry(settings.value(key + "/geometry").toByteArray()))
|
if (!restoreGeometry(settings.value(key + "/geometry").toByteArray()))
|
||||||
setGeometry(50, 50, 690, 510);
|
setGeometry(50, 50, 690, 510);
|
||||||
#endif
|
#endif
|
||||||
|
if (!restoreState(settings.value(key + "/layout").toByteArray(), 0))
|
||||||
|
initToolbars();
|
||||||
|
|
||||||
setIconSize(settings.value(key + "/icon_size").toSize());
|
setIconSize(settings.value(key + "/icon_size").toSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,6 +356,83 @@ GuiView::~GuiView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GuiToolbar * GuiView::toolbar(string const & name)
|
||||||
|
{
|
||||||
|
ToolbarMap::iterator it = d.toolbars_.find(name);
|
||||||
|
if (it != d.toolbars_.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
|
||||||
|
message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiView::constructToolbars()
|
||||||
|
{
|
||||||
|
ToolbarMap::iterator it = d.toolbars_.begin();
|
||||||
|
for (; it != d.toolbars_.end(); ++it)
|
||||||
|
delete it->second;
|
||||||
|
d.toolbars_.clear();
|
||||||
|
|
||||||
|
// extracts the toolbars from the backend
|
||||||
|
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
||||||
|
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
||||||
|
for (; cit != end; ++cit)
|
||||||
|
d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiView::initToolbars()
|
||||||
|
{
|
||||||
|
// extracts the toolbars from the backend
|
||||||
|
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
||||||
|
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
||||||
|
for (; cit != end; ++cit) {
|
||||||
|
GuiToolbar * tb = toolbar(cit->name);
|
||||||
|
if (!tb)
|
||||||
|
continue;
|
||||||
|
int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
|
||||||
|
bool newline = true;
|
||||||
|
tb->setVisible(false);
|
||||||
|
tb->setVisibility(visibility);
|
||||||
|
|
||||||
|
if (visibility & Toolbars::TOP) {
|
||||||
|
if (newline)
|
||||||
|
addToolBarBreak(Qt::TopToolBarArea);
|
||||||
|
addToolBar(Qt::TopToolBarArea, tb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibility & Toolbars::BOTTOM) {
|
||||||
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
||||||
|
#if (QT_VERSION >= 0x040202)
|
||||||
|
addToolBarBreak(Qt::BottomToolBarArea);
|
||||||
|
#endif
|
||||||
|
addToolBar(Qt::BottomToolBarArea, tb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibility & Toolbars::LEFT) {
|
||||||
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
||||||
|
#if (QT_VERSION >= 0x040202)
|
||||||
|
addToolBarBreak(Qt::LeftToolBarArea);
|
||||||
|
#endif
|
||||||
|
addToolBar(Qt::LeftToolBarArea, tb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibility & Toolbars::RIGHT) {
|
||||||
|
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
||||||
|
#if (QT_VERSION >= 0x040202)
|
||||||
|
addToolBarBreak(Qt::RightToolBarArea);
|
||||||
|
#endif
|
||||||
|
addToolBar(Qt::RightToolBarArea, tb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibility & Toolbars::ON)
|
||||||
|
tb->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TocModels & GuiView::tocModels()
|
TocModels & GuiView::tocModels()
|
||||||
{
|
{
|
||||||
return d.toc_models_;
|
return d.toc_models_;
|
||||||
@ -428,7 +515,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
|||||||
|
|
||||||
// Save toolbars configuration
|
// Save toolbars configuration
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
d.toolbars_->toggleFullScreen(!isFullScreen());
|
// d.toolbars_->toggleFullScreen(!isFullScreen());
|
||||||
updateDialogs();
|
updateDialogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +534,11 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
|||||||
settings.setValue(key + "/geometry", saveGeometry());
|
settings.setValue(key + "/geometry", saveGeometry());
|
||||||
#endif
|
#endif
|
||||||
settings.setValue(key + "/icon_size", iconSize());
|
settings.setValue(key + "/icon_size", iconSize());
|
||||||
d.toolbars_->saveToolbarInfo();
|
settings.setValue(key + "/layout", saveState(0));
|
||||||
|
|
||||||
|
ToolbarMap::iterator end = d.toolbars_.end();
|
||||||
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
||||||
|
it->second->saveSession();
|
||||||
// Now take care of all other dialogs:
|
// Now take care of all other dialogs:
|
||||||
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
||||||
for (; it!= d.dialogs_.end(); ++it)
|
for (; it!= d.dialogs_.end(); ++it)
|
||||||
@ -699,53 +790,6 @@ void GuiView::setBusy(bool busy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiToolbar * GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
|
|
||||||
{
|
|
||||||
GuiToolbar * toolBar = new GuiToolbar(tbinfo, *this);
|
|
||||||
|
|
||||||
if (tbinfo.flags & ToolbarInfo::TOP) {
|
|
||||||
if (newline)
|
|
||||||
addToolBarBreak(Qt::TopToolBarArea);
|
|
||||||
addToolBar(Qt::TopToolBarArea, toolBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tbinfo.flags & ToolbarInfo::BOTTOM) {
|
|
||||||
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
||||||
#if (QT_VERSION >= 0x040202)
|
|
||||||
if (newline)
|
|
||||||
addToolBarBreak(Qt::BottomToolBarArea);
|
|
||||||
#endif
|
|
||||||
addToolBar(Qt::BottomToolBarArea, toolBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tbinfo.flags & ToolbarInfo::LEFT) {
|
|
||||||
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
||||||
#if (QT_VERSION >= 0x040202)
|
|
||||||
if (newline)
|
|
||||||
addToolBarBreak(Qt::LeftToolBarArea);
|
|
||||||
#endif
|
|
||||||
addToolBar(Qt::LeftToolBarArea, toolBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tbinfo.flags & ToolbarInfo::RIGHT) {
|
|
||||||
// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
|
|
||||||
#if (QT_VERSION >= 0x040202)
|
|
||||||
if (newline)
|
|
||||||
addToolBarBreak(Qt::RightToolBarArea);
|
|
||||||
#endif
|
|
||||||
addToolBar(Qt::RightToolBarArea, toolBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following does not work so I cannot restore to exact toolbar location
|
|
||||||
/*
|
|
||||||
ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
|
|
||||||
toolBar->move(tbinfo.posx, tbinfo.posy);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return toolBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GuiWorkArea * GuiView::workArea(Buffer & buffer)
|
GuiWorkArea * GuiView::workArea(Buffer & buffer)
|
||||||
{
|
{
|
||||||
if (TabWorkArea * twa = d.currentTabWorkArea())
|
if (TabWorkArea * twa = d.currentTabWorkArea())
|
||||||
@ -846,6 +890,7 @@ void GuiView::updateLayoutList()
|
|||||||
|
|
||||||
void GuiView::updateToolbars()
|
void GuiView::updateToolbars()
|
||||||
{
|
{
|
||||||
|
ToolbarMap::iterator end = d.toolbars_.end();
|
||||||
if (d.current_work_area_) {
|
if (d.current_work_area_) {
|
||||||
bool const math =
|
bool const math =
|
||||||
d.current_work_area_->bufferView().cursor().inMathed();
|
d.current_work_area_->bufferView().cursor().inMathed();
|
||||||
@ -857,9 +902,11 @@ void GuiView::updateToolbars()
|
|||||||
bool const mathmacrotemplate =
|
bool const mathmacrotemplate =
|
||||||
lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
|
lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
|
||||||
|
|
||||||
d.toolbars_->update(math, table, review, mathmacrotemplate);
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
||||||
|
it->second->update(math, table, review, mathmacrotemplate);
|
||||||
} else
|
} else
|
||||||
d.toolbars_->update(false, false, false, false);
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
||||||
|
it->second->update(false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1014,7 +1061,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_TOOLBAR_TOGGLE:
|
case LFUN_TOOLBAR_TOGGLE:
|
||||||
flag.setOnOff(d.toolbars_->visible(cmd.getArg(0)));
|
if (GuiToolbar * t = toolbar(cmd.getArg(0)))
|
||||||
|
flag.setOnOff(t->isVisible());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_UI_TOGGLE:
|
case LFUN_UI_TOGGLE:
|
||||||
@ -1693,7 +1741,10 @@ bool GuiView::dispatch(FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_COMMAND_EXECUTE: {
|
case LFUN_COMMAND_EXECUTE: {
|
||||||
bool const show_it = cmd.argument() != "off";
|
bool const show_it = cmd.argument() != "off";
|
||||||
d.toolbars_->showCommandBuffer(show_it);
|
// FIXME: this is a hack, "minibuffer" should not be
|
||||||
|
// hardcoded.
|
||||||
|
if (GuiToolbar * t = toolbar("minibuffer"))
|
||||||
|
t->setVisible(show_it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LFUN_DROP_LAYOUTS_CHOICE:
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
||||||
@ -1747,32 +1798,8 @@ bool GuiView::dispatch(FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_TOOLBAR_TOGGLE: {
|
case LFUN_TOOLBAR_TOGGLE: {
|
||||||
string const name = cmd.getArg(0);
|
string const name = cmd.getArg(0);
|
||||||
bool const allowauto = cmd.getArg(1) == "allowauto";
|
if (GuiToolbar * t = toolbar(name))
|
||||||
// it is possible to get current toolbar status like this,...
|
t->toggle();
|
||||||
// but I decide to obey the order of Toolbars::flags
|
|
||||||
// and disregard real toolbar status.
|
|
||||||
// toolbars_->saveToolbarInfo();
|
|
||||||
//
|
|
||||||
// toggle state on/off/auto
|
|
||||||
d.toolbars_->toggleToolbarState(name, allowauto);
|
|
||||||
// update toolbar
|
|
||||||
updateToolbars();
|
|
||||||
|
|
||||||
ToolbarInfo * tbi = d.toolbars_->getToolbarInfo(name);
|
|
||||||
if (!tbi) {
|
|
||||||
message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
docstring state;
|
|
||||||
if (tbi->flags & ToolbarInfo::ON)
|
|
||||||
state = _("on");
|
|
||||||
else if (tbi->flags & ToolbarInfo::OFF)
|
|
||||||
state = _("off");
|
|
||||||
else if (tbi->flags & ToolbarInfo::AUTO)
|
|
||||||
state = _("auto");
|
|
||||||
|
|
||||||
message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
|
|
||||||
_(tbi->gui_name), state));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1959,8 +1986,12 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lyxrc.full_screen_toolbars)
|
if (lyxrc.full_screen_toolbars) {
|
||||||
d.toolbars_->toggleFullScreen(!isFullScreen());
|
ToolbarMap::iterator end = d.toolbars_.end();
|
||||||
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
||||||
|
; //it->second->toggleFullScreen(!isFullScreen());
|
||||||
|
}
|
||||||
|
// d.toolbars_->toggleFullScreen(!isFullScreen());
|
||||||
|
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
for (int i = 0; i != d.splitter_->count(); ++i)
|
for (int i = 0; i != d.splitter_->count(); ++i)
|
||||||
@ -2063,7 +2094,7 @@ void GuiView::resetDialogs()
|
|||||||
theLyXFunc().setLyXView(0);
|
theLyXFunc().setLyXView(0);
|
||||||
// FIXME: the "math panels" toolbar takes an awful lot of time to
|
// FIXME: the "math panels" toolbar takes an awful lot of time to
|
||||||
// initialise so we don't do that for the time being.
|
// initialise so we don't do that for the time being.
|
||||||
//d.toolbars_->init();
|
//initToolbars();
|
||||||
guiApp->menus().fillMenuBar(menuBar(), this);
|
guiApp->menus().fillMenuBar(menuBar(), this);
|
||||||
if (d.layout_)
|
if (d.layout_)
|
||||||
d.layout_->updateContents(true);
|
d.layout_->updateContents(true);
|
||||||
|
@ -245,6 +245,12 @@ public:
|
|||||||
void updateCompletion(Cursor & cur, bool start, bool keep);
|
void updateCompletion(Cursor & cur, bool start, bool keep);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
///
|
||||||
|
GuiToolbar * toolbar(std::string const & name);
|
||||||
|
///
|
||||||
|
void constructToolbars();
|
||||||
|
///
|
||||||
|
void initToolbars();
|
||||||
///
|
///
|
||||||
void lfunUiToggle(FuncRequest const & cmd);
|
void lfunUiToggle(FuncRequest const & cmd);
|
||||||
|
|
||||||
|
@ -116,7 +116,6 @@ SOURCEFILES = \
|
|||||||
GuiThesaurus.cpp \
|
GuiThesaurus.cpp \
|
||||||
GuiToc.cpp \
|
GuiToc.cpp \
|
||||||
GuiToolbar.cpp \
|
GuiToolbar.cpp \
|
||||||
GuiToolbars.cpp \
|
|
||||||
GuiView.cpp \
|
GuiView.cpp \
|
||||||
GuiViewSource.cpp \
|
GuiViewSource.cpp \
|
||||||
GuiVSpace.cpp \
|
GuiVSpace.cpp \
|
||||||
@ -149,7 +148,6 @@ NOMOCHEADER = \
|
|||||||
GuiKeySymbol.h \
|
GuiKeySymbol.h \
|
||||||
GuiMath.h \
|
GuiMath.h \
|
||||||
GuiPainter.h \
|
GuiPainter.h \
|
||||||
GuiToolbars.h \
|
|
||||||
LaTeXHighlighter.h \
|
LaTeXHighlighter.h \
|
||||||
qt_i18n.h \
|
qt_i18n.h \
|
||||||
qt_helpers.h \
|
qt_helpers.h \
|
||||||
|
@ -1004,27 +1004,12 @@ void MenuDefinition::expandPasteRecent()
|
|||||||
|
|
||||||
void MenuDefinition::expandToolbars()
|
void MenuDefinition::expandToolbars()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// extracts the toolbars from the backend
|
// extracts the toolbars from the backend
|
||||||
Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
|
Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin();
|
||||||
Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
|
Toolbars::Infos::const_iterator end = guiApp->toolbars().end();
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
QString label = qt_(cit->gui_name);
|
add(MenuItem(MenuItem::Command, qt_(cit->gui_name),
|
||||||
// frontends are not supposed to turn on/off toolbars,
|
FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name)));
|
||||||
// if they cannot update Toolbars::flags. That
|
|
||||||
// is to say, ToolbarsBackend::flags should reflect
|
|
||||||
// the true state of toolbars.
|
|
||||||
//
|
|
||||||
// menu is displayed as
|
|
||||||
// on/off review
|
|
||||||
// and
|
|
||||||
// review (auto)
|
|
||||||
// in the case of auto.
|
|
||||||
if (cit->flags & ToolbarInfo::AUTO)
|
|
||||||
label += qt_(" (auto)");
|
|
||||||
add(MenuItem(MenuItem::Command, label,
|
|
||||||
FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name + " allowauto")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,18 +32,6 @@ namespace frontend {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class ToolbarNamesEqual
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ToolbarNamesEqual(string const & name) : name_(name) {}
|
|
||||||
bool operator()(ToolbarInfo const & tbinfo) const
|
|
||||||
{
|
|
||||||
return tbinfo.name == name_;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
string name_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
@ -65,10 +53,6 @@ ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ToolbarItem::~ToolbarItem()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void ToolbarInfo::add(ToolbarItem const & item)
|
void ToolbarInfo::add(ToolbarItem const & item)
|
||||||
{
|
{
|
||||||
items.push_back(item);
|
items.push_back(item);
|
||||||
@ -207,12 +191,6 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
Toolbars::Toolbars()
|
|
||||||
{
|
|
||||||
fullScreenWindows = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Toolbars::readToolbars(Lexer & lex)
|
void Toolbars::readToolbars(Lexer & lex)
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
@ -242,7 +220,7 @@ void Toolbars::readToolbars(Lexer & lex)
|
|||||||
case TO_TOOLBAR: {
|
case TO_TOOLBAR: {
|
||||||
ToolbarInfo tbinfo;
|
ToolbarInfo tbinfo;
|
||||||
tbinfo.read(lex);
|
tbinfo.read(lex);
|
||||||
toolbars.push_back(tbinfo);
|
toolbar_info_.push_back(tbinfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TO_ENDTOOLBARSET:
|
case TO_ENDTOOLBARSET:
|
||||||
@ -276,19 +254,7 @@ void Toolbars::readToolbarSettings(Lexer & lex)
|
|||||||
if (!compare_ascii_no_case(name, "end"))
|
if (!compare_ascii_no_case(name, "end"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Infos::iterator tcit = toolbars.begin();
|
int visibility = 0;
|
||||||
Infos::iterator tend = toolbars.end();
|
|
||||||
for (; tcit != tend; ++tcit) {
|
|
||||||
if (tcit->name == name)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tcit == tend) {
|
|
||||||
LYXERR0("Toolbars: undefined toolbar " << name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tcit->flags = static_cast<ToolbarInfo::Flags>(0);
|
|
||||||
string flagstr = lex.getString();
|
string flagstr = lex.getString();
|
||||||
lex.next(true);
|
lex.next(true);
|
||||||
vector<string> flags = getVectorFromString(flagstr);
|
vector<string> flags = getVectorFromString(flagstr);
|
||||||
@ -297,58 +263,65 @@ void Toolbars::readToolbarSettings(Lexer & lex)
|
|||||||
vector<string>::const_iterator end = flags.end();
|
vector<string>::const_iterator end = flags.end();
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
int flag = 0;
|
Visibility flag = ON;
|
||||||
if (!compare_ascii_no_case(*cit, "off"))
|
if (!compare_ascii_no_case(*cit, "off"))
|
||||||
flag = ToolbarInfo::OFF;
|
flag = OFF;
|
||||||
else if (!compare_ascii_no_case(*cit, "on"))
|
else if (!compare_ascii_no_case(*cit, "on"))
|
||||||
flag = ToolbarInfo::ON;
|
flag = ON;
|
||||||
else if (!compare_ascii_no_case(*cit, "math"))
|
else if (!compare_ascii_no_case(*cit, "math"))
|
||||||
flag = ToolbarInfo::MATH;
|
flag = MATH;
|
||||||
else if (!compare_ascii_no_case(*cit, "table"))
|
else if (!compare_ascii_no_case(*cit, "table"))
|
||||||
flag = ToolbarInfo::TABLE;
|
flag = TABLE;
|
||||||
else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
|
else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
|
||||||
flag = ToolbarInfo::MATHMACROTEMPLATE;
|
flag = MATHMACROTEMPLATE;
|
||||||
else if (!compare_ascii_no_case(*cit, "review"))
|
else if (!compare_ascii_no_case(*cit, "review"))
|
||||||
flag = ToolbarInfo::REVIEW;
|
flag = REVIEW;
|
||||||
else if (!compare_ascii_no_case(*cit, "top"))
|
else if (!compare_ascii_no_case(*cit, "top"))
|
||||||
flag = ToolbarInfo::TOP;
|
flag = TOP;
|
||||||
else if (!compare_ascii_no_case(*cit, "bottom"))
|
else if (!compare_ascii_no_case(*cit, "bottom"))
|
||||||
flag = ToolbarInfo::BOTTOM;
|
flag = BOTTOM;
|
||||||
else if (!compare_ascii_no_case(*cit, "left"))
|
else if (!compare_ascii_no_case(*cit, "left"))
|
||||||
flag = ToolbarInfo::LEFT;
|
flag = LEFT;
|
||||||
else if (!compare_ascii_no_case(*cit, "right"))
|
else if (!compare_ascii_no_case(*cit, "right"))
|
||||||
flag = ToolbarInfo::RIGHT;
|
flag = RIGHT;
|
||||||
else if (!compare_ascii_no_case(*cit, "auto"))
|
else if (!compare_ascii_no_case(*cit, "auto"))
|
||||||
flag = ToolbarInfo::AUTO;
|
flag = AUTO;
|
||||||
else {
|
else {
|
||||||
LYXERR(Debug::ANY,
|
LYXERR(Debug::ANY,
|
||||||
"Toolbars::readToolbarSettings: unrecognised token:`"
|
"Toolbars::readToolbarSettings: unrecognised token:`"
|
||||||
<< *cit << '\'');
|
<< *cit << '\'');
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
|
visibility |= flag;
|
||||||
}
|
}
|
||||||
|
toolbar_visibility_[name] = visibility;
|
||||||
|
|
||||||
usedtoolbars.push_back(*tcit);
|
if (visibility >= MATH) {
|
||||||
|
if (ToolbarInfo const * ti = info(name))
|
||||||
|
const_cast<ToolbarInfo *>(ti)->gui_name += " (auto)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ToolbarInfo const * Toolbars::getDefinedToolbarInfo(string const & name) const
|
ToolbarInfo const * Toolbars::info(std::string const & name) const
|
||||||
{
|
{
|
||||||
Infos::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
|
Infos::const_iterator end = toolbar_info_.end();
|
||||||
if (it == toolbars.end())
|
for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
|
||||||
return 0;
|
if (it->name == name)
|
||||||
return &(*it);
|
return &(*it);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ToolbarInfo * Toolbars::getUsedToolbarInfo(string const &name)
|
int Toolbars::defaultVisibility(std::string const & name) const
|
||||||
{
|
{
|
||||||
Infos::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
|
map<string, int>::const_iterator it = toolbar_visibility_.find(name);
|
||||||
if (it == usedtoolbars.end())
|
if (it != toolbar_visibility_.end())
|
||||||
return 0;
|
return it->second;
|
||||||
return &(*it);
|
return OFF | BOTTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -51,8 +51,6 @@ public:
|
|||||||
std::string const & name = std::string(),
|
std::string const & name = std::string(),
|
||||||
docstring const & label = docstring());
|
docstring const & label = docstring());
|
||||||
|
|
||||||
~ToolbarItem();
|
|
||||||
|
|
||||||
/// item type
|
/// item type
|
||||||
Type type_;
|
Type type_;
|
||||||
/// action
|
/// action
|
||||||
@ -67,20 +65,6 @@ public:
|
|||||||
///
|
///
|
||||||
class ToolbarInfo {
|
class ToolbarInfo {
|
||||||
public:
|
public:
|
||||||
/// toolbar flags
|
|
||||||
enum Flags {
|
|
||||||
ON = 1, //< show
|
|
||||||
OFF = 2, //< do not show
|
|
||||||
MATH = 4, //< show when in math
|
|
||||||
TABLE = 8, //< show when in table
|
|
||||||
TOP = 16, //< show at top
|
|
||||||
BOTTOM = 32, //< show at bottom
|
|
||||||
LEFT = 64, //< show at left
|
|
||||||
RIGHT = 128, //< show at right
|
|
||||||
REVIEW = 256, //< show when change tracking is enabled
|
|
||||||
AUTO = 512, //< only if AUTO is set, when MATH, TABLE and REVIEW is used
|
|
||||||
MATHMACROTEMPLATE = 1024 //< show in math macro template
|
|
||||||
};
|
|
||||||
/// the toolbar items
|
/// the toolbar items
|
||||||
typedef std::vector<ToolbarItem> Items;
|
typedef std::vector<ToolbarItem> Items;
|
||||||
|
|
||||||
@ -95,10 +79,6 @@ public:
|
|||||||
std::string gui_name;
|
std::string gui_name;
|
||||||
/// toolbar contents
|
/// toolbar contents
|
||||||
Items items;
|
Items items;
|
||||||
/// flags
|
|
||||||
Flags flags;
|
|
||||||
/// store flags when coming to fullscreen mode
|
|
||||||
Flags before_fullscreen;
|
|
||||||
|
|
||||||
/// read a toolbar from the file
|
/// read a toolbar from the file
|
||||||
ToolbarInfo & read(Lexer &);
|
ToolbarInfo & read(Lexer &);
|
||||||
@ -112,18 +92,33 @@ private:
|
|||||||
///
|
///
|
||||||
class Toolbars {
|
class Toolbars {
|
||||||
public:
|
public:
|
||||||
|
/// toolbar visibility flags
|
||||||
|
enum Visibility {
|
||||||
|
ON = 1, //< show
|
||||||
|
OFF = 2, //< do not show
|
||||||
|
TOP = 4, //< show at top
|
||||||
|
BOTTOM = 8, //< show at bottom
|
||||||
|
LEFT = 16, //< show at left
|
||||||
|
RIGHT = 32, //< show at right
|
||||||
|
AUTO = 64, //< only if AUTO is set, when MATH, TABLE and REVIEW is used
|
||||||
|
MATH = 128, //< show when in math
|
||||||
|
TABLE = 256, //< show when in table
|
||||||
|
REVIEW = 512, //< show when change tracking is enabled
|
||||||
|
MATHMACROTEMPLATE = 1024 //< show in math macro template
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::vector<ToolbarInfo> Infos;
|
typedef std::vector<ToolbarInfo> Infos;
|
||||||
|
|
||||||
Toolbars();
|
Toolbars() {}
|
||||||
|
|
||||||
/// iterator for all toolbars
|
/// iterator for all toolbars
|
||||||
Infos::const_iterator begin() const { return usedtoolbars.begin(); }
|
Infos::const_iterator begin() const { return toolbar_info_.begin(); }
|
||||||
|
|
||||||
Infos::const_iterator end() const { return usedtoolbars.end(); }
|
Infos::const_iterator end() const { return toolbar_info_.end(); }
|
||||||
|
|
||||||
Infos::iterator begin() { return usedtoolbars.begin(); }
|
Infos::iterator begin() { return toolbar_info_.begin(); }
|
||||||
|
|
||||||
Infos::iterator end() { return usedtoolbars.end(); }
|
Infos::iterator end() { return toolbar_info_.end(); }
|
||||||
|
|
||||||
/// read toolbars from the file
|
/// read toolbars from the file
|
||||||
void readToolbars(Lexer &);
|
void readToolbars(Lexer &);
|
||||||
@ -132,20 +127,15 @@ public:
|
|||||||
void readToolbarSettings(Lexer &);
|
void readToolbarSettings(Lexer &);
|
||||||
|
|
||||||
///
|
///
|
||||||
ToolbarInfo const * getDefinedToolbarInfo(std::string const & name) const;
|
ToolbarInfo const * info(std::string const & name) const;
|
||||||
///
|
///
|
||||||
ToolbarInfo * getUsedToolbarInfo(std::string const & name);
|
int defaultVisibility(std::string const & name) const;
|
||||||
|
|
||||||
// FIXME should be deleted when every window has its own toolbar config.
|
|
||||||
/// number of toggleFullScreen calls, i.e. number of FullScreen windows.
|
|
||||||
int fullScreenWindows;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// all the defined toolbars
|
/// all the defined toolbars
|
||||||
Infos toolbars;
|
Infos toolbar_info_;
|
||||||
|
///
|
||||||
/// toolbars listed
|
std::map<std::string, int> toolbar_visibility_;
|
||||||
Infos usedtoolbars;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
Loading…
Reference in New Issue
Block a user