mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
- Cleanup and simplify the layout list GUI handling.
- Transfer toolbar, statusbar and layoutlist handling to the frontend. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21684 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
228bd9b277
commit
ba3fa9bd03
@ -487,17 +487,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
|
||||
FuncStatus flag;
|
||||
|
||||
/* In LyX/Mac, when a dialog is open, the menus of the
|
||||
application can still be accessed without giving focus to
|
||||
the main window. In this case, we want to disable the menu
|
||||
entries that are buffer-related.
|
||||
|
||||
Note that this code is not perfect, as bug 1941 attests:
|
||||
http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
|
||||
*/
|
||||
Buffer * buf = lyx_view_? lyx_view_->buffer() : 0;
|
||||
if (lyx_view_ && cmd.origin == FuncRequest::MENU && !lyx_view_->hasFocus())
|
||||
buf = 0;
|
||||
|
||||
if (cmd.action == LFUN_NOACTION) {
|
||||
flag.message(from_utf8(N_("Nothing to do")));
|
||||
@ -1888,9 +1878,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
|
||||
actOnUpdatedPrefs(lyxrc_orig, lyxrc);
|
||||
|
||||
if (lyx_view_ && lyx_view_->buffer())
|
||||
lyx_view_->updateLayoutChoice(true);
|
||||
|
||||
/// We force the redraw in any case because there might be
|
||||
/// some screen font changes.
|
||||
/// FIXME: only the current view will be updated. the Gui
|
||||
@ -1940,7 +1927,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
// (at least partially) visible top-level paragraphs.
|
||||
// We will redraw the screen only if needed.
|
||||
view()->processUpdateFlags(updateFlags);
|
||||
lyx_view_->updateStatusBar();
|
||||
|
||||
// if we executed a mutating lfun, mark the buffer as dirty
|
||||
if (flag.enabled()
|
||||
@ -1952,12 +1938,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
theSelection().haveSelection(view()->cursor().selection());
|
||||
|
||||
if (view()->cursor().inTexted()) {
|
||||
lyx_view_->updateLayoutChoice(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!quitting && lyx_view_) {
|
||||
lyx_view_->updateToolbars();
|
||||
// Some messages may already be translated, so we cannot use _()
|
||||
sendDispatchMessage(translateIfPossible(getMessage()), cmd);
|
||||
}
|
||||
@ -2070,7 +2054,6 @@ Buffer * LyXFunc::loadAndViewFile(FileName const & filename, bool tolastfiles)
|
||||
|
||||
if (!newBuffer) {
|
||||
lyx_view_->message(_("Document not loaded."));
|
||||
lyx_view_->updateStatusBar();
|
||||
lyx_view_->setBusy(false);
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,12 +70,6 @@ public:
|
||||
|
||||
//@}
|
||||
|
||||
/// updates the possible layouts selectable
|
||||
virtual void updateLayoutChoice(bool force) = 0;
|
||||
/// update the toolbar
|
||||
virtual void updateToolbars() = 0;
|
||||
/// update the status bar
|
||||
virtual void updateStatusBar() = 0;
|
||||
/// display a message in the view
|
||||
virtual void message(docstring const &) = 0;
|
||||
|
||||
@ -84,14 +78,6 @@ public:
|
||||
/// dispatch to current BufferView
|
||||
virtual void dispatch(FuncRequest const & cmd) = 0;
|
||||
|
||||
/** redraw \c inset in all the BufferViews in which it is currently
|
||||
* visible. If successful return a pointer to the owning Buffer.
|
||||
*/
|
||||
virtual Buffer const * updateInset(Inset const *) = 0;
|
||||
|
||||
/// returns true if this view has the focus.
|
||||
virtual bool hasFocus() const = 0;
|
||||
|
||||
///
|
||||
virtual void restartCursor() = 0;
|
||||
|
||||
@ -100,14 +86,10 @@ public:
|
||||
//
|
||||
virtual void errors(std::string const &) = 0;
|
||||
|
||||
|
||||
//
|
||||
// This View's Dialogs
|
||||
//
|
||||
|
||||
/// Hide all visible dialogs
|
||||
virtual void hideAll() const = 0;
|
||||
|
||||
/** \param name == "bibtex", "citation" etc; an identifier used to
|
||||
launch a particular dialog.
|
||||
\param data is a string representation of the Inset contents.
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
@ -23,6 +25,7 @@
|
||||
#include "IconPalette.h"
|
||||
#include "Layout.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TextClass.h"
|
||||
#include "ToolbarBackend.h"
|
||||
|
||||
@ -227,12 +230,6 @@ static QIcon getIcon(FuncRequest const & f, bool unknown)
|
||||
}
|
||||
|
||||
|
||||
static TextClass const & textClass(LyXView const & lv)
|
||||
{
|
||||
return lv.buffer()->params().getTextClass();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GuiLayoutBox
|
||||
@ -249,22 +246,23 @@ GuiLayoutBox::GuiLayoutBox(GuiView & owner)
|
||||
|
||||
QObject::connect(this, SIGNAL(activated(QString)),
|
||||
this, SLOT(selected(QString)));
|
||||
owner_.setLayoutDialog(this);
|
||||
}
|
||||
|
||||
|
||||
void GuiLayoutBox::set(docstring const & layout)
|
||||
{
|
||||
TextClass const & tc = textClass(owner_);
|
||||
if (!text_class_)
|
||||
return;
|
||||
|
||||
QString const & name = toqstr(translateIfPossible(tc[layout]->name()));
|
||||
QString const & name = toqstr(translateIfPossible(
|
||||
(*text_class_)[layout]->name()));
|
||||
|
||||
int i = 0;
|
||||
for (; i < count(); ++i) {
|
||||
if (name == itemText(i))
|
||||
break;
|
||||
}
|
||||
if (name == currentText())
|
||||
return;
|
||||
|
||||
if (i == count()) {
|
||||
int i = findText(name);
|
||||
if (i == -1) {
|
||||
lyxerr << "Trying to select non existent layout type "
|
||||
<< fromqstr(name) << endl;
|
||||
return;
|
||||
@ -297,15 +295,30 @@ void GuiLayoutBox::addItemSort(QString const & item, bool sorted)
|
||||
}
|
||||
|
||||
|
||||
void GuiLayoutBox::updateContents()
|
||||
void GuiLayoutBox::updateContents(bool reset)
|
||||
{
|
||||
TextClass const & tc = textClass(owner_);
|
||||
Buffer const * buffer = owner_.buffer();
|
||||
if (!buffer) {
|
||||
clear();
|
||||
setEnabled(false);
|
||||
text_class_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
setEnabled(true);
|
||||
TextClass const * text_class = &buffer->params().getTextClass();
|
||||
if (!reset && text_class_ == text_class) {
|
||||
set(owner_.view()->cursor().innerParagraph().layout()->name());
|
||||
return;
|
||||
}
|
||||
|
||||
text_class_ = text_class;
|
||||
|
||||
setUpdatesEnabled(false);
|
||||
clear();
|
||||
|
||||
TextClass::const_iterator it = tc.begin();
|
||||
TextClass::const_iterator const end = tc.end();
|
||||
TextClass::const_iterator it = text_class_->begin();
|
||||
TextClass::const_iterator const end = text_class_->end();
|
||||
for (; it != end; ++it) {
|
||||
// ignore obsolete entries
|
||||
addItemSort(toqstr(translateIfPossible((*it)->name())), lyxrc.sort_layouts);
|
||||
@ -316,6 +329,7 @@ void GuiLayoutBox::updateContents()
|
||||
// needed to recalculate size hint
|
||||
hide();
|
||||
setMinimumWidth(sizeHint().width());
|
||||
set(owner_.view()->cursor().innerParagraph().layout()->name());
|
||||
show();
|
||||
|
||||
setUpdatesEnabled(true);
|
||||
@ -325,10 +339,13 @@ void GuiLayoutBox::updateContents()
|
||||
void GuiLayoutBox::selected(const QString & str)
|
||||
{
|
||||
owner_.setFocus();
|
||||
TextClass const & tc = owner_.buffer()->params().getTextClass();
|
||||
updateContents(false);
|
||||
if (!text_class_)
|
||||
return;
|
||||
|
||||
docstring const name = qstring_to_ucs4(str);
|
||||
TextClass::const_iterator it = tc.begin();
|
||||
TextClass::const_iterator const end = tc.end();
|
||||
TextClass::const_iterator it = text_class_->begin();
|
||||
TextClass::const_iterator const end = text_class_->end();
|
||||
for (; it != end; ++it) {
|
||||
docstring const & itname = (*it)->name();
|
||||
if (translateIfPossible(itname) == name) {
|
||||
@ -517,6 +534,9 @@ void GuiToolbar::updateContents()
|
||||
for (int i = 0; i < actions_.size(); ++i)
|
||||
actions_[i]->update();
|
||||
|
||||
if (layout_)
|
||||
layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
|
||||
|
||||
// emit signal
|
||||
updated();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class TextClass;
|
||||
class ToolbarItem;
|
||||
|
||||
namespace frontend {
|
||||
@ -42,7 +43,7 @@ public:
|
||||
/// select the right layout in the combobox.
|
||||
void set(docstring const & layout);
|
||||
/// Populate the layout combobox.
|
||||
void updateContents();
|
||||
void updateContents(bool reset);
|
||||
/// Add Item to Layout box according to sorting settings from preferences
|
||||
void addItemSort(QString const & item, bool sorted);
|
||||
|
||||
@ -51,6 +52,7 @@ private Q_SLOTS:
|
||||
|
||||
private:
|
||||
GuiView & owner_;
|
||||
TextClass const * text_class_;
|
||||
};
|
||||
|
||||
|
||||
@ -68,7 +70,6 @@ public:
|
||||
void saveInfo(ToolbarSection::ToolbarInfo & info);
|
||||
/// Refresh the contents of the bar.
|
||||
void updateContents();
|
||||
GuiLayoutBox * layout() const { return layout_; }
|
||||
///
|
||||
GuiCommandBuffer * commandBuffer() { return command_buffer_; }
|
||||
|
||||
|
@ -41,9 +41,7 @@ namespace frontend {
|
||||
#define TurnOffFlag(x) flags &= ~ToolbarInfo::x
|
||||
|
||||
GuiToolbars::GuiToolbars(GuiView & owner)
|
||||
: owner_(owner),
|
||||
layout_(0),
|
||||
last_textclass_(TextClassPtr())
|
||||
: owner_(owner)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -288,41 +286,6 @@ void GuiToolbars::saveToolbarInfo()
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::setLayout(docstring const & layout)
|
||||
{
|
||||
if (layout_)
|
||||
layout_->set(layout);
|
||||
}
|
||||
|
||||
|
||||
bool GuiToolbars::updateLayoutList(TextClassPtr textclass, bool force)
|
||||
{
|
||||
// update the layout display
|
||||
if (last_textclass_ != textclass || force) {
|
||||
if (layout_)
|
||||
layout_->updateContents();
|
||||
last_textclass_ = textclass;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::openLayoutList()
|
||||
{
|
||||
if (layout_)
|
||||
layout_->showPopup();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::clearLayoutList()
|
||||
{
|
||||
last_textclass_ = TextClassPtr();
|
||||
if (layout_)
|
||||
layout_->clear();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
||||
{
|
||||
GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline);
|
||||
@ -332,9 +295,6 @@ void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
||||
tb_ptr->show();
|
||||
else
|
||||
tb_ptr->hide();
|
||||
|
||||
if (tb_ptr->layout())
|
||||
layout_ = tb_ptr->layout();
|
||||
}
|
||||
|
||||
|
||||
@ -360,12 +320,6 @@ void GuiToolbars::updateIcons()
|
||||
ToolbarsMap::const_iterator const end = toolbars_.end();
|
||||
for (; it != end; ++it)
|
||||
it->second->updateContents();
|
||||
|
||||
bool const enable =
|
||||
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
|
||||
|
||||
if (layout_)
|
||||
layout_->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,6 @@ class ToolbarInfo;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class GuiLayoutBox;
|
||||
class GuiToolbar;
|
||||
class GuiView;
|
||||
|
||||
@ -59,19 +58,6 @@ public:
|
||||
/// save toolbar information
|
||||
void saveToolbarInfo();
|
||||
|
||||
/// Select the right layout in the combox.
|
||||
void setLayout(docstring const & layout);
|
||||
|
||||
/** Populate the layout combox - returns whether we did a full
|
||||
* update or not
|
||||
*/
|
||||
bool updateLayoutList(TextClassPtr textclass, bool force);
|
||||
|
||||
/// Drop down the layout list.
|
||||
void openLayoutList();
|
||||
/// Erase the layout list.
|
||||
void clearLayoutList();
|
||||
|
||||
/// Show or hide the command buffer.
|
||||
void showCommandBuffer(bool show_it);
|
||||
|
||||
@ -92,15 +78,6 @@ private:
|
||||
/// The parent window.
|
||||
GuiView & owner_;
|
||||
|
||||
/** The layout box is actually owned by whichever toolbar
|
||||
* contains it. All the Toolbars class needs is a means of
|
||||
* accessing it.
|
||||
*
|
||||
* We don't need to use boost::weak_ptr here because the toolbars
|
||||
* are also stored here. There are, therefore, no lifetime issues.
|
||||
*/
|
||||
GuiLayoutBox * layout_;
|
||||
|
||||
/// Toolbar store providing access to individual toolbars by name.
|
||||
typedef std::map<std::string, GuiToolbar *> ToolbarsMap;
|
||||
ToolbarsMap toolbars_;
|
||||
|
@ -155,7 +155,7 @@ typedef boost::shared_ptr<Dialog> DialogPtr;
|
||||
struct GuiView::GuiViewPrivate
|
||||
{
|
||||
GuiViewPrivate()
|
||||
: current_work_area_(0), posx_offset(0), posy_offset(0),
|
||||
: current_work_area_(0), layout_(0),
|
||||
autosave_timeout_(new Timeout(5000)), quitting_by_menu_(false),
|
||||
in_show_(false)
|
||||
{
|
||||
@ -263,9 +263,6 @@ public:
|
||||
string cur_title;
|
||||
|
||||
GuiWorkArea * current_work_area_;
|
||||
int posx_offset;
|
||||
int posy_offset;
|
||||
|
||||
QSplitter * splitter_;
|
||||
QStackedWidget * stack_widget_;
|
||||
BackgroundWidget * bg_widget_;
|
||||
@ -273,8 +270,16 @@ public:
|
||||
GuiMenubar * menubar_;
|
||||
/// view's toolbars
|
||||
GuiToolbars * toolbars_;
|
||||
///
|
||||
docstring current_layout;
|
||||
/// The main layout box.
|
||||
/**
|
||||
* \warning Don't Delete! The layout box is actually owned by
|
||||
* whichever toolbar contains it. All the GuiView class needs is a
|
||||
* means of accessing it.
|
||||
*
|
||||
* FIXME: replace that with a proper model so that we are not limited
|
||||
* to only one dialog.
|
||||
*/
|
||||
GuiLayoutBox * layout_;
|
||||
|
||||
///
|
||||
std::map<std::string, Inset *> open_insets_;
|
||||
@ -538,7 +543,7 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
|
||||
// require bv_->text.
|
||||
updateBufferDependent(true);
|
||||
updateToolbars();
|
||||
updateLayoutChoice(false);
|
||||
updateLayoutList();
|
||||
updateStatusBar();
|
||||
}
|
||||
|
||||
@ -787,26 +792,16 @@ void GuiView::removeWorkArea(GuiWorkArea * work_area)
|
||||
}
|
||||
|
||||
|
||||
void GuiView::updateLayoutChoice(bool force)
|
||||
void GuiView::setLayoutDialog(GuiLayoutBox * layout)
|
||||
{
|
||||
// Don't show any layouts without a buffer
|
||||
if (!buffer()) {
|
||||
d.toolbars_->clearLayoutList();
|
||||
return;
|
||||
}
|
||||
d.layout_ = layout;
|
||||
}
|
||||
|
||||
// Update the layout display
|
||||
if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr(), force)) {
|
||||
d.current_layout = buffer()->params().getTextClass().defaultLayoutName();
|
||||
}
|
||||
|
||||
docstring const & layout = d.current_work_area_->bufferView().cursor().
|
||||
innerParagraph().layout()->name();
|
||||
|
||||
if (layout != d.current_layout) {
|
||||
d.toolbars_->setLayout(layout);
|
||||
d.current_layout = layout;
|
||||
}
|
||||
void GuiView::updateLayoutList()
|
||||
{
|
||||
if (d.layout_)
|
||||
d.layout_->updateContents(false);
|
||||
}
|
||||
|
||||
|
||||
@ -956,6 +951,17 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
|
||||
bool enable = true;
|
||||
Buffer * buf = buffer();
|
||||
|
||||
/* In LyX/Mac, when a dialog is open, the menus of the
|
||||
application can still be accessed without giving focus to
|
||||
the main window. In this case, we want to disable the menu
|
||||
entries that are buffer-related.
|
||||
|
||||
Note that this code is not perfect, as bug 1941 attests:
|
||||
http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
|
||||
*/
|
||||
if (cmd.origin == FuncRequest::MENU && !hasFocus())
|
||||
buf = 0;
|
||||
|
||||
switch(cmd.action) {
|
||||
case LFUN_TOOLBAR_TOGGLE:
|
||||
flag.setOnOff(d.toolbars_->visible(cmd.getArg(0)));
|
||||
@ -1030,7 +1036,8 @@ void GuiView::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
}
|
||||
case LFUN_DROP_LAYOUTS_CHOICE:
|
||||
d.toolbars_->openLayoutList();
|
||||
if (d.layout_)
|
||||
d.layout_->showPopup();
|
||||
break;
|
||||
|
||||
case LFUN_MENU_OPEN:
|
||||
|
@ -36,6 +36,7 @@ class ToolbarInfo;
|
||||
namespace frontend {
|
||||
|
||||
class Dialog;
|
||||
class GuiLayoutBox;
|
||||
class GuiToolbar;
|
||||
class GuiWorkArea;
|
||||
|
||||
@ -63,18 +64,24 @@ public:
|
||||
void close();
|
||||
void setFocus();
|
||||
void setBusy(bool);
|
||||
/// returns true if this view has the focus.
|
||||
bool hasFocus() const;
|
||||
|
||||
/// add toolbar, if newline==true, add a toolbar break before the toolbar
|
||||
GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
|
||||
virtual void updateStatusBar();
|
||||
virtual void message(docstring const & str);
|
||||
virtual bool hasFocus() const;
|
||||
void updateLayoutChoice(bool force);
|
||||
|
||||
/// updates the possible layouts selectable
|
||||
void updateLayoutList();
|
||||
void updateToolbars();
|
||||
QMenu * createPopupMenu();
|
||||
FuncStatus getStatus(FuncRequest const & cmd);
|
||||
void dispatch(FuncRequest const & cmd);
|
||||
|
||||
///
|
||||
void setLayoutDialog(GuiLayoutBox *);
|
||||
|
||||
/// \return the buffer currently shown in this window
|
||||
Buffer * buffer();
|
||||
Buffer const * buffer() const;
|
||||
|
@ -323,6 +323,8 @@ void GuiWorkArea::redraw()
|
||||
updateScreen();
|
||||
update(0, 0, viewport()->width(), viewport()->height());
|
||||
|
||||
lyx_view_->updateStatusBar();
|
||||
|
||||
if (lyxerr.debugging(Debug::WORKAREA))
|
||||
buffer_view_->coordCache().dump();
|
||||
}
|
||||
@ -336,6 +338,8 @@ void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
|
||||
|
||||
theLyXFunc().setLyXView(lyx_view_);
|
||||
theLyXFunc().processKeySym(key, mod);
|
||||
lyx_view_->updateLayoutList();
|
||||
lyx_view_->updateToolbars();
|
||||
}
|
||||
|
||||
|
||||
@ -372,7 +376,7 @@ void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
|
||||
|
||||
// Skip these when selecting
|
||||
if (cmd.action != LFUN_MOUSE_MOTION) {
|
||||
lyx_view_->updateLayoutChoice(false);
|
||||
lyx_view_->updateLayoutList();
|
||||
lyx_view_->updateToolbars();
|
||||
}
|
||||
|
||||
@ -396,7 +400,7 @@ void GuiWorkArea::resizeBufferView()
|
||||
// We are already inside a paint event.
|
||||
lyx_view_->setBusy(true);
|
||||
buffer_view_->resize(viewport()->width(), viewport()->height());
|
||||
lyx_view_->updateLayoutChoice(false);
|
||||
lyx_view_->updateLayoutList();
|
||||
lyx_view_->setBusy(false);
|
||||
need_resize_ = false;
|
||||
}
|
||||
@ -502,7 +506,7 @@ void GuiWorkArea::adjustViewWithScrollBar(int action)
|
||||
|
||||
if (lyxrc.cursor_follows_scrollbar) {
|
||||
buffer_view_->setCursorFromScrollbar();
|
||||
lyx_view_->updateLayoutChoice(false);
|
||||
lyx_view_->updateLayoutList();
|
||||
}
|
||||
// Show the cursor immediately after any operation.
|
||||
startBlinkingCursor();
|
||||
|
Loading…
Reference in New Issue
Block a user