//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")));
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
// (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()
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);
}
if (!newBuffer) {
lyx_view_->message(_("Document not loaded."));
- lyx_view_->updateStatusBar();
lyx_view_->setBusy(false);
return 0;
}
//@}
- /// 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;
/// 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;
//
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.
#include "Buffer.h"
#include "BufferParams.h"
+#include "BufferView.h"
+#include "Cursor.h"
#include "debug.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "IconPalette.h"
#include "Layout.h"
#include "LyXFunc.h"
+#include "Paragraph.h"
#include "TextClass.h"
#include "ToolbarBackend.h"
}
-static TextClass const & textClass(LyXView const & lv)
-{
- return lv.buffer()->params().getTextClass();
-}
-
-
/////////////////////////////////////////////////////////////////////
//
// GuiLayoutBox
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;
}
-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);
// needed to recalculate size hint
hide();
setMinimumWidth(sizeHint().width());
+ set(owner_.view()->cursor().innerParagraph().layout()->name());
show();
setUpdatesEnabled(true);
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) {
for (int i = 0; i < actions_.size(); ++i)
actions_[i]->update();
+ if (layout_)
+ layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
+
// emit signal
updated();
}
namespace lyx {
+class TextClass;
class ToolbarItem;
namespace frontend {
/// 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);
private:
GuiView & owner_;
+ TextClass const * text_class_;
};
void saveInfo(ToolbarSection::ToolbarInfo & info);
/// Refresh the contents of the bar.
void updateContents();
- GuiLayoutBox * layout() const { return layout_; }
///
GuiCommandBuffer * commandBuffer() { return command_buffer_; }
#define TurnOffFlag(x) flags &= ~ToolbarInfo::x
GuiToolbars::GuiToolbars(GuiView & owner)
- : owner_(owner),
- layout_(0),
- last_textclass_(TextClassPtr())
+ : owner_(owner)
{
init();
}
}
-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);
tb_ptr->show();
else
tb_ptr->hide();
-
- if (tb_ptr->layout())
- layout_ = tb_ptr->layout();
}
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);
}
namespace frontend {
-class GuiLayoutBox;
class GuiToolbar;
class GuiView;
/// 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);
/// 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_;
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)
{
string cur_title;
GuiWorkArea * current_work_area_;
- int posx_offset;
- int posy_offset;
-
QSplitter * splitter_;
QStackedWidget * stack_widget_;
BackgroundWidget * bg_widget_;
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_;
// require bv_->text.
updateBufferDependent(true);
updateToolbars();
- updateLayoutChoice(false);
+ updateLayoutList();
updateStatusBar();
}
}
-void GuiView::updateLayoutChoice(bool force)
+void GuiView::setLayoutDialog(GuiLayoutBox * layout)
{
- // Don't show any layouts without a buffer
- if (!buffer()) {
- d.toolbars_->clearLayoutList();
- return;
- }
-
- // Update the layout display
- if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr(), force)) {
- d.current_layout = buffer()->params().getTextClass().defaultLayoutName();
- }
+ d.layout_ = layout;
+}
- 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);
}
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)));
break;
}
case LFUN_DROP_LAYOUTS_CHOICE:
- d.toolbars_->openLayoutList();
+ if (d.layout_)
+ d.layout_->showPopup();
break;
case LFUN_MENU_OPEN:
namespace frontend {
class Dialog;
+class GuiLayoutBox;
class GuiToolbar;
class GuiWorkArea;
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;
updateScreen();
update(0, 0, viewport()->width(), viewport()->height());
+ lyx_view_->updateStatusBar();
+
if (lyxerr.debugging(Debug::WORKAREA))
buffer_view_->coordCache().dump();
}
theLyXFunc().setLyXView(lyx_view_);
theLyXFunc().processKeySym(key, mod);
+ lyx_view_->updateLayoutList();
+ lyx_view_->updateToolbars();
}
// Skip these when selecting
if (cmd.action != LFUN_MOUSE_MOTION) {
- lyx_view_->updateLayoutChoice(false);
+ lyx_view_->updateLayoutList();
lyx_view_->updateToolbars();
}
// 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;
}
if (lyxrc.cursor_follows_scrollbar) {
buffer_view_->setCursorFromScrollbar();
- lyx_view_->updateLayoutChoice(false);
+ lyx_view_->updateLayoutList();
}
// Show the cursor immediately after any operation.
startBlinkingCursor();