// to handle (Andre')
bool enable = true;
switch (cmd.action) {
+
+ case LFUN_DIALOG_TOGGLE:
+ case LFUN_DIALOG_SHOW:
+ case LFUN_DIALOG_UPDATE:
+ case LFUN_TOOLBAR_TOGGLE:
+ if (lyx_view_)
+ return lyx_view_->getStatus(cmd);
+ enable = false;
+ break;
+
case LFUN_BUFFER_TOGGLE_READ_ONLY:
flag.setOnOff(buf->isReadonly());
break;
break;
}
- case LFUN_DIALOG_TOGGLE:
- flag.setOnOff(lyx_view_?
- lyx_view_->isDialogVisible(cmd.getArg(0)) : false);
- // fall through to set "enable"
- case LFUN_DIALOG_SHOW: {
- string const name = cmd.getArg(0);
- if (!buf)
- enable = name == "aboutlyx"
- || name == "file" //FIXME: should be removed.
- || name == "prefs"
- || name == "texinfo";
- else if (name == "print")
- enable = buf->isExportable("dvi")
- && lyxrc.print_command != "none";
- else if (name == "character") {
- if (!view())
- enable = false;
- else {
- InsetCode ic = view()->cursor().inset().lyxCode();
- enable = ic != ERT_CODE && ic != LISTINGS_CODE;
- }
- }
- else if (name == "latexlog")
- enable = FileName(buf->logName()).isFileReadable();
- else if (name == "spellchecker")
-#if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL)
- enable = !buf->isReadonly();
-#else
- enable = false;
-#endif
- else if (name == "vclog")
- enable = buf->lyxvc().inUse();
- break;
- }
-
- case LFUN_DIALOG_UPDATE: {
- string const name = cmd.getArg(0);
- if (!buf)
- enable = name == "prefs";
- break;
- }
-
case LFUN_CITATION_INSERT: {
FuncRequest fr(LFUN_INSET_INSERT, "citation");
enable = getStatus(fr).enabled();
enable = LyX::ref().session().bookmarks().size() > 0;
break;
- case LFUN_TOOLBAR_TOGGLE: {
- bool const current = lyx_view_?
- lyx_view_->isToolbarVisible(cmd.getArg(0)) : false;
- flag.setOnOff(current);
- break;
- }
- case LFUN_WINDOW_CLOSE: {
+ case LFUN_WINDOW_CLOSE:
enable = theApp()->viewCount() > 0;
break;
- }
// this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence
case LFUN_DROP_LAYOUTS_CHOICE:
case LFUN_MENU_OPEN:
case LFUN_TOOLBAR_TOGGLE:
+ case LFUN_DIALOG_UPDATE:
+ case LFUN_DIALOG_TOGGLE:
+ case LFUN_DIALOG_DISCONNECT_INSET:
+ case LFUN_DIALOG_HIDE:
BOOST_ASSERT(lyx_view_);
lyx_view_->dispatch(cmd);
break;
break;
}
- case LFUN_DIALOG_SHOW: {
- BOOST_ASSERT(lyx_view_);
- string const name = cmd.getArg(0);
- string data = trim(to_utf8(cmd.argument()).substr(name.size()));
-
- if (name == "character") {
- data = freefont2string();
- if (!data.empty())
- lyx_view_->showDialog("character", data);
- } else if (name == "latexlog") {
- Buffer::LogType type;
- string const logfile = lyx_view_->buffer()->logName(&type);
- switch (type) {
- case Buffer::latexlog:
- data = "latex ";
- break;
- case Buffer::buildlog:
- data = "literate ";
- break;
- }
- data += Lexer::quoteString(logfile);
- lyx_view_->showDialog("log", data);
- } else if (name == "vclog") {
- string const data = "vc " +
- Lexer::quoteString(lyx_view_->buffer()->lyxvc().getLogFile());
- lyx_view_->showDialog("log", data);
- } else
- lyx_view_->showDialog(name, data);
- break;
- }
case LFUN_DIALOG_SHOW_NEW_INSET: {
BOOST_ASSERT(lyx_view_);
break;
}
- case LFUN_DIALOG_UPDATE: {
- BOOST_ASSERT(lyx_view_);
- string const & name = argument;
- // Can only update a dialog connected to an existing inset
- Inset * inset = lyx_view_->getOpenInset(name);
- if (inset) {
- FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
- inset->dispatch(view()->cursor(), fr);
- } else if (name == "paragraph") {
- dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
- } else if (name == "prefs") {
- lyx_view_->updateDialog(name, string());
- }
- break;
- }
-
- case LFUN_DIALOG_HIDE: {
- if (quitting || !use_gui)
- break;
- theApp()->hideDialogs(argument, 0);
- break;
- }
-
- case LFUN_DIALOG_TOGGLE: {
- BOOST_ASSERT(lyx_view_);
- if (lyx_view_->isDialogVisible(cmd.getArg(0)))
- dispatch(FuncRequest(LFUN_DIALOG_HIDE, argument));
- else
- dispatch(FuncRequest(LFUN_DIALOG_SHOW, argument));
- break;
- }
-
- case LFUN_DIALOG_DISCONNECT_INSET:
- BOOST_ASSERT(lyx_view_);
- lyx_view_->disconnectDialog(argument);
- break;
-
-
case LFUN_CITATION_INSERT: {
BOOST_ASSERT(lyx_view_);
if (!argument.empty()) {
///
virtual bool closeAllViews() = 0;
///
- virtual LyXView & view(int id) const = 0;
- ///
virtual size_t viewCount() const = 0;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
std::string const & data, Inset * inset = 0) = 0;
/// This function is called when some dialogs needs to be updated.
+ /** \param name == "citation", "bibtex" etc; an identifier used\r
+ to update the contents of a particular dialog with \param data.\r
+ See the comments to 'show', above.\r
+ */\r
virtual void updateDialog(std::string const & name,
std::string const & data) = 0;
};
class Buffer;
class BufferView;
+class FuncStatus;
class FuncRequest;
class Inset;
/// set a buffer to the current workarea.
virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
- ///
- virtual bool isToolbarVisible(std::string const & id) = 0;
-
//@}
/// updates the possible layouts selectable
/// display a message in the view
virtual void message(docstring const &) = 0;
+ ///
+ virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
/// dispatch to current BufferView
virtual void dispatch(FuncRequest const & cmd) = 0;
virtual void showDialog(std::string const & name,
std::string const & data, Inset * inset = 0) = 0;
- /** \param name == "citation", "bibtex" etc; an identifier used
- to update the contents of a particular dialog with \param data.
- See the comments to 'show', above.
- */
- virtual void updateDialog(std::string const & name, std::string const & data) = 0;
-
- /// Is the dialog currently visible?
- virtual bool isDialogVisible(std::string const & name) const = 0;
-
- /** All Dialogs of the given \param name will be closed if they are
- connected to the given \param inset.
- */
- virtual void hideDialog(std::string const & name, Inset * inset) = 0;
///
virtual void disconnectDialog(std::string const & name) = 0;
///
}
-LyXView & GuiApplication::view(int id) const
+GuiView & GuiApplication::view(int id) const
{
BOOST_ASSERT(views_.find(id) != views_.end());
return *views_.find(id)->second;
///
virtual bool unregisterView(int id);
///
- virtual LyXView & view(int id) const;
+ virtual GuiView & view(int id) const;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const;
///
#include "gettext.h"
#include "Intl.h"
#include "Layout.h"
+#include "Lexer.h"
#include "LyXFunc.h"
#include "LyX.h"
#include "LyXRC.h"
+#include "LyXVC.h"
#include "MenuBackend.h"
#include "Paragraph.h"
#include "TextClass.h"
#include "version.h"
#include "support/convert.h"
+#include "support/FileName.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "support/Timeout.h"
namespace frontend {
using support::bformat;
+using support::FileName;
+using support::trim;
namespace {
}
-bool GuiView::isToolbarVisible(std::string const & id)
-{
- return d.toolbars_->visible(id);
-}
-
void GuiView::updateToolbars()
{
if (d.current_work_area_) {
}
+FuncStatus GuiView::getStatus(FuncRequest const & cmd)
+{
+ FuncStatus flag;
+ bool enable = true;
+ Buffer * buf = buffer();
+
+ switch(cmd.action) {
+ case LFUN_TOOLBAR_TOGGLE:
+ flag.setOnOff(d.toolbars_->visible(cmd.getArg(0)));
+ break;
+
+ case LFUN_DIALOG_TOGGLE:
+ flag.setOnOff(isDialogVisible(cmd.getArg(0)));
+ // fall through to set "enable"
+ case LFUN_DIALOG_SHOW: {
+ string const name = cmd.getArg(0);
+ if (!buf)
+ enable = name == "aboutlyx"
+ || name == "file" //FIXME: should be removed.
+ || name == "prefs"
+ || name == "texinfo";
+ else if (name == "print")
+ enable = buf->isExportable("dvi")
+ && lyxrc.print_command != "none";
+ else if (name == "character") {
+ if (!view())
+ enable = false;
+ else {
+ InsetCode ic = view()->cursor().inset().lyxCode();
+ enable = ic != ERT_CODE && ic != LISTINGS_CODE;
+ }
+ }
+ else if (name == "latexlog")
+ enable = FileName(buf->logName()).isFileReadable();
+ else if (name == "spellchecker")
+#if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL)
+ enable = !buf->isReadonly();
+#else
+ enable = false;
+#endif
+ else if (name == "vclog")
+ enable = buf->lyxvc().inUse();
+ break;
+ }
+
+ case LFUN_DIALOG_UPDATE: {
+ string const name = cmd.getArg(0);
+ if (!buf)
+ enable = name == "prefs";
+ break;
+ }
+
+ default:
+ if (!view()) {
+ enable = false;
+ break;
+ }
+ }
+
+ if (!enable)
+ flag.enabled(false);
+
+ return flag;
+}
+
+
void GuiView::dispatch(FuncRequest const & cmd)
{
+ Buffer * buf = buffer();
switch(cmd.action) {
case LFUN_BUFFER_SWITCH:
setBuffer(theBufferList().getBuffer(to_utf8(cmd.argument())));
break;
}
+ case LFUN_DIALOG_UPDATE: {
+ string const name = to_utf8(cmd.argument());
+ // Can only update a dialog connected to an existing inset
+ Inset * inset = getOpenInset(name);
+ if (inset) {
+ FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
+ inset->dispatch(view()->cursor(), fr);
+ } else if (name == "paragraph") {
+ lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
+ } else if (name == "prefs") {
+ updateDialog(name, string());
+ }
+ break;
+ }
+
+ case LFUN_DIALOG_TOGGLE: {
+ if (isDialogVisible(cmd.getArg(0)))
+ dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()));
+ else
+ dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()));
+ break;
+ }
+
+ case LFUN_DIALOG_DISCONNECT_INSET:
+ disconnectDialog(to_utf8(cmd.argument()));
+ break;
+
+ case LFUN_DIALOG_HIDE: {
+ if (quitting)
+ break;
+ guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
+ break;
+ }
+
+ case LFUN_DIALOG_SHOW: {
+ string const name = cmd.getArg(0);
+ string data = trim(to_utf8(cmd.argument()).substr(name.size()));
+
+ if (name == "character") {
+ data = freefont2string();
+ if (!data.empty())
+ showDialog("character", data);
+ } else if (name == "latexlog") {
+ Buffer::LogType type;
+ string const logfile = buf->logName(&type);
+ switch (type) {
+ case Buffer::latexlog:
+ data = "latex ";
+ break;
+ case Buffer::buildlog:
+ data = "literate ";
+ break;
+ }
+ data += Lexer::quoteString(logfile);
+ showDialog("log", data);
+ } else if (name == "vclog") {
+ string const data = "vc " +
+ Lexer::quoteString(buf->lyxvc().getLogFile());
+ showDialog("log", data);
+ } else
+ showDialog(name, data);
+ break;
+ }
+
default:
theLyXFunc().setLyXView(this);
lyx::dispatch(cmd);
virtual void message(docstring const & str);
virtual bool hasFocus() const;
void updateLayoutChoice(bool force);
- bool isToolbarVisible(std::string const & id);
void updateToolbars();
- ///
QMenu * createPopupMenu();
-
- /// dispatch to current BufferView
+ FuncStatus getStatus(FuncRequest const & cmd);
void dispatch(FuncRequest const & cmd);
/// \return the buffer currently shown in this window
*/
void updateDialog(std::string const & name, std::string const & data);
- /// Is the dialog currently visible?
- bool isDialogVisible(std::string const & name) const;
-
/** All Dialogs of the given \param name will be closed if they are
connected to the given \param inset.
*/
Inset * getOpenInset(std::string const & name) const;
private:
+ /// Is the dialog currently visible?
+ bool isDialogVisible(std::string const & name) const;
///
Dialog * find_or_build(std::string const & name);
///