mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
Transfer some LFUNs from LyXFunc to GuiView.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21681 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4bdd6f7937
commit
359ced5e65
133
src/LyXFunc.cpp
133
src/LyXFunc.cpp
@ -544,6 +544,16 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
// 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;
|
||||
@ -609,48 +619,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
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();
|
||||
@ -696,16 +664,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
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
|
||||
@ -920,6 +881,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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;
|
||||
@ -1418,36 +1383,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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_);
|
||||
@ -1546,44 +1481,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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()) {
|
||||
|
@ -154,8 +154,6 @@ public:
|
||||
///
|
||||
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;
|
||||
|
@ -34,6 +34,10 @@ public:
|
||||
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
|
||||
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;
|
||||
};
|
||||
|
@ -22,6 +22,7 @@ namespace support { class FileName; }
|
||||
|
||||
class Buffer;
|
||||
class BufferView;
|
||||
class FuncStatus;
|
||||
class FuncRequest;
|
||||
class Inset;
|
||||
|
||||
@ -67,9 +68,6 @@ public:
|
||||
/// 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
|
||||
@ -81,6 +79,8 @@ public:
|
||||
/// 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;
|
||||
|
||||
@ -124,19 +124,6 @@ public:
|
||||
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;
|
||||
///
|
||||
|
@ -495,7 +495,7 @@ bool GuiApplication::closeAllViews()
|
||||
}
|
||||
|
||||
|
||||
LyXView & GuiApplication::view(int id) const
|
||||
GuiView & GuiApplication::view(int id) const
|
||||
{
|
||||
BOOST_ASSERT(views_.find(id) != views_.end());
|
||||
return *views_.find(id)->second;
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -43,9 +43,11 @@ using std::string;
|
||||
#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"
|
||||
@ -54,6 +56,7 @@ using std::string;
|
||||
#include "version.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Timeout.h"
|
||||
@ -100,6 +103,8 @@ extern bool quitting;
|
||||
namespace frontend {
|
||||
|
||||
using support::bformat;
|
||||
using support::FileName;
|
||||
using support::trim;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -805,11 +810,6 @@ void GuiView::updateLayoutChoice(bool force)
|
||||
}
|
||||
|
||||
|
||||
bool GuiView::isToolbarVisible(std::string const & id)
|
||||
{
|
||||
return d.toolbars_->visible(id);
|
||||
}
|
||||
|
||||
void GuiView::updateToolbars()
|
||||
{
|
||||
if (d.current_work_area_) {
|
||||
@ -950,8 +950,75 @@ void GuiView::resetAutosaveTimers()
|
||||
}
|
||||
|
||||
|
||||
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())));
|
||||
@ -1001,6 +1068,70 @@ void GuiView::dispatch(FuncRequest const & cmd)
|
||||
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);
|
||||
|
@ -70,12 +70,9 @@ public:
|
||||
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
|
||||
@ -218,9 +215,6 @@ public:
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -231,6 +225,8 @@ public:
|
||||
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);
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user