mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
First step towards fixing bug 4588: move the ui file reading and the ToolbarBackend to the frontend.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24921 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bbb9cb65e7
commit
145585dc18
@ -115,7 +115,6 @@ src_header_files = Split('''
|
||||
TextMetrics.h
|
||||
Thesaurus.h
|
||||
TocBackend.h
|
||||
ToolbarBackend.h
|
||||
Trans.h
|
||||
Undo.h
|
||||
VCBackend.h
|
||||
@ -210,7 +209,6 @@ src_pre_files = Split('''
|
||||
TextClass.cpp
|
||||
TextMetrics.cpp
|
||||
TocBackend.cpp
|
||||
ToolbarBackend.cpp
|
||||
Trans.cpp
|
||||
Undo.cpp
|
||||
VCBackend.cpp
|
||||
@ -762,6 +760,7 @@ src_frontends_qt4_header_files = Split('''
|
||||
PanelStack.h
|
||||
TocModel.h
|
||||
TocWidget.h
|
||||
ToolbarBackend.h
|
||||
Validator.h
|
||||
qt_helpers.h
|
||||
qt_i18n.h
|
||||
@ -852,6 +851,7 @@ src_frontends_qt4_files = Split('''
|
||||
PanelStack.cpp
|
||||
TocModel.cpp
|
||||
TocWidget.cpp
|
||||
ToolbarBackend.cpp
|
||||
Validator.cpp
|
||||
qt_helpers.cpp
|
||||
''')
|
||||
|
99
src/LyX.cpp
99
src/LyX.cpp
@ -40,7 +40,6 @@
|
||||
#include "Server.h"
|
||||
#include "ServerSocket.h"
|
||||
#include "Session.h"
|
||||
#include "ToolbarBackend.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Application.h"
|
||||
@ -827,10 +826,6 @@ bool LyX::init()
|
||||
|
||||
pimpl_->lyxfunc_.initKeySequences(&pimpl_->toplevel_keymap_);
|
||||
|
||||
// Read menus
|
||||
if (use_gui && !readUIFile(lyxrc.ui_file))
|
||||
return false;
|
||||
|
||||
if (lyxerr.debugging(Debug::LYXRC))
|
||||
lyxrc.print();
|
||||
|
||||
@ -971,100 +966,6 @@ bool LyX::readRcFile(string const & name)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Read the ui file `name'
|
||||
bool LyX::readUIFile(string const & name, bool include)
|
||||
{
|
||||
enum {
|
||||
ui_menuset = 1,
|
||||
ui_toolbars,
|
||||
ui_toolbarset,
|
||||
ui_include,
|
||||
ui_last
|
||||
};
|
||||
|
||||
LexerKeyword uitags[] = {
|
||||
{ "include", ui_include },
|
||||
{ "menuset", ui_menuset },
|
||||
{ "toolbars", ui_toolbars },
|
||||
{ "toolbarset", ui_toolbarset }
|
||||
};
|
||||
|
||||
// Ensure that a file is read only once (prevents include loops)
|
||||
static list<string> uifiles;
|
||||
list<string>::const_iterator it = uifiles.begin();
|
||||
list<string>::const_iterator end = uifiles.end();
|
||||
it = find(it, end, name);
|
||||
if (it != end) {
|
||||
LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. "
|
||||
<< "Is this an include loop?");
|
||||
return false;
|
||||
}
|
||||
|
||||
LYXERR(Debug::INIT, "About to read " << name << "...");
|
||||
|
||||
|
||||
FileName ui_path;
|
||||
if (include) {
|
||||
ui_path = libFileSearch("ui", name, "inc");
|
||||
if (ui_path.empty())
|
||||
ui_path = libFileSearch("ui",
|
||||
changeExtension(name, "inc"));
|
||||
}
|
||||
else
|
||||
ui_path = libFileSearch("ui", name, "ui");
|
||||
|
||||
if (ui_path.empty()) {
|
||||
LYXERR(Debug::INIT, "Could not find " << name);
|
||||
showFileError(name);
|
||||
return false;
|
||||
}
|
||||
|
||||
uifiles.push_back(name);
|
||||
|
||||
LYXERR(Debug::INIT, "Found " << name << " in " << ui_path);
|
||||
Lexer lex(uitags);
|
||||
lex.setFile(ui_path);
|
||||
if (!lex.isOK()) {
|
||||
lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
|
||||
<< endl;
|
||||
}
|
||||
|
||||
if (lyxerr.debugging(Debug::PARSER))
|
||||
lex.printTable(lyxerr);
|
||||
|
||||
while (lex.isOK()) {
|
||||
switch (lex.lex()) {
|
||||
case ui_include: {
|
||||
lex.next(true);
|
||||
string const file = lex.getString();
|
||||
if (!readUIFile(file, true))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ui_menuset:
|
||||
theApp()->readMenus(lex);
|
||||
break;
|
||||
|
||||
case ui_toolbarset:
|
||||
toolbarbackend.readToolbars(lex);
|
||||
break;
|
||||
|
||||
case ui_toolbars:
|
||||
toolbarbackend.readToolbarSettings(lex);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!rtrim(lex.getString()).empty())
|
||||
lex.printError("LyX::ReadUIFile: "
|
||||
"Unknown menu tag: `$$Token'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Read the languages file `name'
|
||||
bool LyX::readLanguagesFile(string const & name)
|
||||
{
|
||||
|
@ -136,8 +136,6 @@ private:
|
||||
bool queryUserLyXDir(bool explicit_userdir);
|
||||
/// read lyxrc/preferences
|
||||
bool readRcFile(std::string const & name);
|
||||
/// read the given ui (menu/toolbar) file
|
||||
bool readUIFile(std::string const & name, bool include = false);
|
||||
/// read the given languages file
|
||||
bool readLanguagesFile(std::string const & name);
|
||||
/// read the encodings.
|
||||
|
@ -164,7 +164,6 @@ SOURCEFILESCORE = \
|
||||
TextClass.cpp \
|
||||
TextMetrics.cpp \
|
||||
TocBackend.cpp \
|
||||
ToolbarBackend.cpp \
|
||||
Trans.cpp \
|
||||
Undo.cpp \
|
||||
VCBackend.cpp \
|
||||
@ -264,7 +263,6 @@ HEADERFILESCORE = \
|
||||
TextClass.h \
|
||||
TextMetrics.h \
|
||||
TocBackend.h \
|
||||
ToolbarBackend.h \
|
||||
Trans.h \
|
||||
Undo.h \
|
||||
update_flags.h \
|
||||
|
@ -209,11 +209,6 @@ public:
|
||||
*/
|
||||
virtual std::string const hexName(ColorCode col) = 0;
|
||||
|
||||
/**
|
||||
* read and create the menu structure
|
||||
*/
|
||||
virtual void readMenus(Lexer & lex) = 0;
|
||||
|
||||
/**
|
||||
* add a callback for socket read notification
|
||||
* @param fd socket descriptor (file/socket/etc)
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "GuiView.h"
|
||||
#include "Menus.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "ToolbarBackend.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Application.h"
|
||||
@ -36,6 +37,7 @@
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "Language.h"
|
||||
#include "Lexer.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
@ -749,6 +751,11 @@ void GuiApplication::exit(int status)
|
||||
|
||||
void GuiApplication::execBatchCommands()
|
||||
{
|
||||
// Read menus
|
||||
if (!readUIFile(lyxrc.ui_file))
|
||||
// Gives some error box here.
|
||||
return;
|
||||
|
||||
// init the global menubar on Mac. This must be done after the session
|
||||
// was recovered to know the "last files".
|
||||
if (d->global_menubar_)
|
||||
@ -1041,6 +1048,100 @@ bool GuiApplication::searchMenu(FuncRequest const & func,
|
||||
}
|
||||
|
||||
|
||||
bool GuiApplication::readUIFile(string const & name, bool include)
|
||||
{
|
||||
enum {
|
||||
ui_menuset = 1,
|
||||
ui_toolbars,
|
||||
ui_toolbarset,
|
||||
ui_include,
|
||||
ui_last
|
||||
};
|
||||
|
||||
LexerKeyword uitags[] = {
|
||||
{ "include", ui_include },
|
||||
{ "menuset", ui_menuset },
|
||||
{ "toolbars", ui_toolbars },
|
||||
{ "toolbarset", ui_toolbarset }
|
||||
};
|
||||
|
||||
// Ensure that a file is read only once (prevents include loops)
|
||||
static list<string> uifiles;
|
||||
list<string>::const_iterator it = uifiles.begin();
|
||||
list<string>::const_iterator end = uifiles.end();
|
||||
it = find(it, end, name);
|
||||
if (it != end) {
|
||||
LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. "
|
||||
<< "Is this an include loop?");
|
||||
return false;
|
||||
}
|
||||
|
||||
LYXERR(Debug::INIT, "About to read " << name << "...");
|
||||
|
||||
|
||||
FileName ui_path;
|
||||
if (include) {
|
||||
ui_path = libFileSearch("ui", toqstr(name), "inc");
|
||||
if (ui_path.empty())
|
||||
ui_path = libFileSearch("ui",
|
||||
changeExtension(toqstr(name), "inc"));
|
||||
}
|
||||
else
|
||||
ui_path = libFileSearch("ui", toqstr(name), "ui");
|
||||
|
||||
if (ui_path.empty()) {
|
||||
LYXERR(Debug::INIT, "Could not find " << name);
|
||||
Alert::warning(_("Could not find UI defintion file"),
|
||||
bformat(_("Error while reading the configuration file\n%1$s.\n"
|
||||
"Please check your installation."), from_utf8(name)));
|
||||
return false;
|
||||
}
|
||||
|
||||
uifiles.push_back(name);
|
||||
|
||||
LYXERR(Debug::INIT, "Found " << name << " in " << ui_path);
|
||||
Lexer lex(uitags);
|
||||
lex.setFile(ui_path);
|
||||
if (!lex.isOK()) {
|
||||
lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
|
||||
<< endl;
|
||||
}
|
||||
|
||||
if (lyxerr.debugging(Debug::PARSER))
|
||||
lex.printTable(lyxerr);
|
||||
|
||||
while (lex.isOK()) {
|
||||
switch (lex.lex()) {
|
||||
case ui_include: {
|
||||
lex.next(true);
|
||||
string const file = lex.getString();
|
||||
if (!readUIFile(file, true))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ui_menuset:
|
||||
readMenus(lex);
|
||||
break;
|
||||
|
||||
case ui_toolbarset:
|
||||
toolbarbackend.readToolbars(lex);
|
||||
break;
|
||||
|
||||
case ui_toolbars:
|
||||
toolbarbackend.readToolbarSettings(lex);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!rtrim(lex.getString()).empty())
|
||||
lex.printError("LyX::ReadUIFile: "
|
||||
"Unknown menu tag: `$$Token'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void GuiApplication::onLastWindowClosed()
|
||||
{
|
||||
if (d->global_menubar_)
|
||||
|
@ -127,6 +127,9 @@ private Q_SLOTS:
|
||||
private:
|
||||
///
|
||||
bool closeAllViews();
|
||||
/// read the given ui (menu/toolbar) file
|
||||
bool readUIFile(std::string const & name, bool include = false);
|
||||
|
||||
/// This LyXView is the one receiving Clipboard and Selection
|
||||
/// events
|
||||
GuiView * current_view_;
|
||||
|
@ -132,6 +132,7 @@ SOURCEFILES = \
|
||||
qt_helpers.cpp \
|
||||
TocModel.cpp \
|
||||
TocWidget.cpp \
|
||||
ToolbarBackend.cpp \
|
||||
Validator.cpp
|
||||
|
||||
NOMOCHEADER = \
|
||||
@ -151,7 +152,8 @@ NOMOCHEADER = \
|
||||
GuiToolbars.h \
|
||||
LaTeXHighlighter.h \
|
||||
qt_i18n.h \
|
||||
qt_helpers.h
|
||||
qt_helpers.h \
|
||||
ToolbarBackend.h
|
||||
|
||||
MOCHEADER = \
|
||||
Action.h \
|
||||
|
Loading…
Reference in New Issue
Block a user