Dialogs::Dialogs(LyXView & lyxview)
: lyxview_(lyxview), in_show_(false)
-{
-}
+{}
Dialog * Dialogs::find_or_build(string const & name)
void Dialogs::show(string const & name, string const & data)
{
- if (in_show_) {
+ if (in_show_)
return;
- }
+
in_show_ = true;
Dialog * dialog = find_or_build(name);
- if (dialog) {
- // FIXME! Should check that the dialog is NOT an inset dialog.
- dialog->show(data);
- }
+ if (dialog)
+ dialog->showData(data);
+
in_show_ = false;
}
void Dialogs::show(string const & name, string const & data, Inset * inset)
{
- if (in_show_) {
+ if (in_show_)
return;
- }
+
in_show_ = true;
Dialog * dialog = find_or_build(name);
if (dialog) {
- // FIXME! Should check that the dialog IS an inset dialog.
- dialog->show(data);
+ dialog->showData(data);
open_insets_[name] = inset;
}
in_show_ = false;
dialogs_.find(name);
if (it == dialogs_.end())
return false;
- return it->second.get()->isVisible();
+ return it->second.get()->isVisibleView();
}
return;
Dialog * const dialog = it->second.get();
- if (dialog->isVisible())
- dialog->update(data);
+ if (dialog->isVisibleView())
+ dialog->updateData(data);
}
return;
Dialog * const dialog = it->second.get();
- if (dialog->isVisible())
+ if (dialog->isVisibleView())
dialog->hide();
open_insets_[name] = 0;
}
std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
- for(; it != end; ++it) {
+ for(; it != end; ++it)
it->second->hide();
- }
}
std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
for(; it != end; ++it) {
- Dialog * dialog = it->second.get();
+ Dialog * dialog = it->second.get();
if (dialog->controller().isBufferDependent())
dialog->hide();
}
std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
for(; it != end; ++it) {
- Dialog * dialog = it->second.get();
+ Dialog * dialog = it->second.get();
if (switched && dialog->controller().isBufferDependent()) {
- if (dialog->isVisible() && dialog->controller().initialiseParams(""))
+ if (dialog->isVisibleView() && dialog->controller().initialiseParams(""))
dialog->updateView();
else
dialog->hide();
std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
- for(; it != end; ++it) {
+ for(; it != end; ++it)
it->second->redraw();
- }
}
for(; it != end; ++it) {
Dialog * const dialog = it->second.get();
- if (dialog->isVisible())
+ if (dialog->isVisibleView())
dialog->checkStatus();
}
}
{
// FIXME UNICODE
pair<docstring, docstring> dir1(_("Documents|#o#O"),
- lyx::from_utf8(lyxrc.document_path));
+ from_utf8(lyxrc.document_path));
FileFilterList const filter(_("BibTeX Databases (*.bib)"));
- return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
+ return browseRelFile(in_name, from_utf8(bufferFilepath()),
_("Select a BibTeX database to add"),
filter, false, dir1);
}
{
// FIXME UNICODE
pair<docstring, docstring> dir1(_("Documents|#o#O"),
- lyx::from_utf8(lyxrc.document_path));
+ from_utf8(lyxrc.document_path));
FileFilterList const filter(_("BibTeX Styles (*.bst)"));
- return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
+ return browseRelFile(in_name, from_utf8(bufferFilepath()),
_("Select a BibTeX style"), filter, false, dir1);
}
bool ControlBibtex::usingBibtopic() const
{
- return kernel().buffer().params().use_bibtopic;
+ return buffer().params().use_bibtopic;
}
bool ControlBibtex::bibtotoc() const
{
- return prefixIs(lyx::to_utf8(params()["options"]), "bibtotoc");
+ return prefixIs(to_utf8(params()["options"]), "bibtotoc");
}
{
// the different bibtex packages have (and need) their
// own "plain" stylefiles
- biblio::CiteEngine const engine =
- kernel().buffer().params().getEngine();
+ biblio::CiteEngine const engine = buffer().params().getEngine();
docstring defaultstyle;
switch (engine) {
case biblio::ENGINE_BASIC:
- defaultstyle = lyx::from_ascii("plain");
+ defaultstyle = from_ascii("plain");
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
- defaultstyle = lyx::from_ascii("plainnat");
+ defaultstyle = from_ascii("plainnat");
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
- defaultstyle = lyx::from_ascii("plainnat");
+ defaultstyle = from_ascii("plainnat");
break;
case biblio::ENGINE_JURABIB:
- defaultstyle = lyx::from_ascii("jurabib");
+ defaultstyle = from_ascii("jurabib");
break;
}
if (bibtotoc()){
// bibstyle exists?
if (contains(bst, ',')) {
- docstring bibtotoc = lyx::from_ascii("bibtotoc");
+ docstring bibtotoc = from_ascii("bibtotoc");
bst = split(bst, bibtotoc, ',');
} else
bst.erase();
bst = defaultstyle;
// FIXME UNICODE
- return lyx::to_utf8(bst);
+ return to_utf8(bst);
}
} // namespace frontend
void ControlBox::dispatchParams()
{
string const lfun = InsetBoxMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
void ControlBranch::dispatchParams()
{
string const lfun = InsetBranchMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
BranchList const & ControlBranch::branchlist() const
{
- return kernel().buffer().params().branchlist();
+ return buffer().params().branchlist();
}
} // namespace frontend
void ControlChanges::next()
{
- kernel().dispatch(FuncRequest(LFUN_CHANGE_NEXT));
+ dispatch(FuncRequest(LFUN_CHANGE_NEXT));
}
docstring const ControlChanges::getChangeDate()
{
- Change const & c = kernel().bufferview()->getCurrentChange();
+ Change const & c = bufferview()->getCurrentChange();
if (c.type == Change::UNCHANGED)
return docstring();
docstring const ControlChanges::getChangeAuthor()
{
- Change const & c = kernel().bufferview()->getCurrentChange();
+ Change const & c = bufferview()->getCurrentChange();
if (c.type == Change::UNCHANGED)
return docstring();
- Author const & a = kernel().buffer().params().authors().get(c.author);
+ Author const & a = buffer().params().authors().get(c.author);
- docstring author(a.name());
+ docstring author = a.name();
- if (!a.email().empty()) {
+ if (!a.email().empty())
author += " (" + a.email() + ")";
- }
return author;
}
void ControlChanges::accept()
{
- kernel().dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
+ dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
next();
}
void ControlChanges::reject()
{
- kernel().dispatch(FuncRequest(LFUN_CHANGE_REJECT));
+ dispatch(FuncRequest(LFUN_CHANGE_REJECT));
next();
}
string data;
if (font2string(*font_.get(), toggleall_, data)) {
- kernel().dispatch(FuncRequest(getLfun(), data));
+ dispatch(FuncRequest(getLfun(), data));
}
}
else if (val == "reset") {
reset_lang_ = true;
// Ignored in getLanguage, but needed for dispatchParams
- font_->setLanguage(kernel().buffer().params().language);
- } else
+ font_->setLanguage(buffer().params().language);
+ } else {
font_->setLanguage(languages.getLanguage(val));
+ }
}
if (!ControlCommand::initialiseParams(data))
return false;
- biblio::CiteEngine const engine =
- kernel().buffer().params().getEngine();
+ biblio::CiteEngine const engine = buffer().params().getEngine();
bool use_styles = engine != biblio::ENGINE_BASIC;
- bibkeysInfo_.fillWithBibKeys(&(kernel().buffer()));
+ bibkeysInfo_.fillWithBibKeys(&buffer());
if (citeStyles_.empty())
citeStyles_ = biblio::getCiteStyles(engine);
biblio::CiteEngine const ControlCitation::getEngine() const
{
- return kernel().buffer().params().getEngine();
+ return buffer().params().getEngine();
}
vector<docstring> const ControlCitation::getCiteStrings(docstring const & key) const
{
- return bibkeysInfo_.getCiteStrings(key, kernel().buffer());
+ return bibkeysInfo_.getCiteStrings(key, buffer());
}
} // namespace frontend
string const lfun = InsetCommandMailer::params2string(lfun_name_,
params_);
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
#include <config.h>
#include "ControlDocument.h"
-#include "Kernel.h"
#include "BranchList.h"
#include "Buffer.h"
bool ControlDocument::initialiseParams(std::string const &)
{
bp_.reset(new BufferParams);
- *bp_ = kernel().buffer().params();
+ *bp_ = buffer().params();
return true;
}
BufferId ControlDocument::id() const
{
- return &kernel().buffer();
+ return &buffer();
}
}
-namespace {
-
-void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
- kb_action lfun)
+static void dispatch_bufferparams(Controller const & controller,
+ BufferParams const & bp, kb_action lfun)
{
ostringstream ss;
ss << "\\begin_header\n";
bp.writeFile(ss);
ss << "\\end_header\n";
- kernel.dispatch(FuncRequest(lfun, ss.str()));
+ controller.dispatch(FuncRequest(lfun, ss.str()));
}
-} // namespace anon
-
void ControlDocument::dispatchParams()
{
// and then update the buffer's layout.
//FIXME Could this be done last? Then, I think, we'd get the automatic
//update mentioned in the next FIXME...
- dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
+ dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
// Generate the colours requested by each new branch.
BranchList & branchlist = params().branchlist();
lyx::X11hexname(branch->getColor());
// display the new color
docstring const str = current_branch + ' ' + from_ascii(x11hexname);
- kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
+ dispatch(FuncRequest(LFUN_SET_COLOR, str));
}
// Open insets of selected branches, close deselected ones
- kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
+ dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
"assign branch"));
}
// FIXME: If we used an LFUN, we would not need those two lines:
- kernel().bufferview()->update();
- kernel().lyxview().currentWorkArea()->redraw();
+ bufferview()->update();
+ lyxview().currentWorkArea()->redraw();
}
void ControlDocument::setLanguage() const
{
Language const * const newL = bp_->language;
- if (kernel().buffer().params().language == newL)
+ if (buffer().params().language == newL)
return;
string const lang_name = newL->lang();
- kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
+ dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
}
void ControlDocument::saveAsDefault() const
{
- dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
+ dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
}
void ControlERT::dispatchParams()
{
string const lfun = InsetERTMailer::params2string(status_);
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
{
- return kernel().buffer().embeddedFiles();
+ return buffer().embeddedFiles();
}
void ControlEmbeddedFiles::updateEmbeddedFiles()
{
// copy buffer embeddedFiles to a local copy
- kernel().buffer().embeddedFiles().update();
- kernel().buffer().embeddingChanged();
+ buffer().embeddedFiles().update();
+ buffer().embeddingChanged();
}
{
// FIXME: the right thing to do? QT guys?
// lyx view will only be updated if we do something to the main window. :-)
- kernel().dispatch(FuncRequest(LFUN_MESSAGE, msg));
+ dispatch(FuncRequest(LFUN_MESSAGE, msg));
}
void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
{
BOOST_ASSERT(idx < item.refCount());
- item.saveBookmark(&kernel().buffer(), idx);
- kernel().lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
+ item.saveBookmark(&buffer(), idx);
+ lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
}
void ControlEmbeddedFiles::view(EmbeddedFile const & item)
{
- formats.view(kernel().buffer(), item, formats.getFormatFromFile(item));
+ formats.view(buffer(), item, formats.getFormatFromFile(item));
}
{
// FIXME: updateFromExternalFile() or extract() may fail...
if (embed)
- item.updateFromExternalFile(&kernel().buffer());
+ item.updateFromExternalFile(&buffer());
else
- item.extract(&kernel().buffer());
+ item.extract(&buffer());
item.setEmbed(embed);
}
docstring const ControlEmbeddedFiles::browseFile()
{
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
- lyx::from_utf8(lyxrc.document_path));
+ from_utf8(lyxrc.document_path));
FileFilterList const filter(_("All file (*.*)"));
- return browseRelFile(docstring(), lyx::from_utf8(kernel().bufferFilepath()),
+ return browseRelFile(docstring(), from_utf8(bufferFilepath()),
_("Select a file to embed"),
filter, false, dir1);
}
bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
{
if (item.embedded())
- return item.extract(&kernel().buffer());
+ return item.extract(&buffer());
else
return false;
}
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
{
if (item.embedded())
- return item.updateFromExternalFile(&kernel().buffer());
+ return item.updateFromExternalFile(&buffer());
else
return false;
}
ErrorList const & ControlErrorList::errorList() const
{
- return kernel().bufferview()->buffer().errorList(error_type_);
+ return bufferview()->buffer().errorList(error_type_);
}
bool ControlErrorList::initialiseParams(string const & error_type)
{
error_type_ = error_type;
- Buffer const & buf = kernel().bufferview()->buffer();
+ Buffer const & buf = bufferview()->buffer();
// FIXME UNICODE
docstring const title = bformat(_("%1$s Errors (%2$s)"),
_(error_type),
if (err.par_id == -1)
return;
- Buffer & buf = kernel().buffer();
+ Buffer & buf = buffer();
ParIterator pit = buf.getParFromID(err.par_id);
if (pit == buf.par_iterator_end()) {
pos_type const start = std::min(err.pos_start, end);
pos_type const range = end - start;
DocIterator const dit = makeDocIterator(pit, start);
- kernel().bufferview()->putSelectionAt(dit, range, false);
+ bufferview()->putSelectionAt(dit, range, false);
// FIXME: If we used an LFUN, we would not need those two lines:
- kernel().bufferview()->update();
- kernel().lyxview().currentWorkArea()->redraw();
+ bufferview()->update();
+ lyxview().currentWorkArea()->redraw();
}
} // namespace frontend
bool ControlExternal::initialiseParams(string const & data)
{
params_.reset(new InsetExternalParams);
- InsetExternalMailer::string2params(data, kernel().buffer(), *params_);
+ InsetExternalMailer::string2params(data, buffer(), *params_);
return true;
}
void ControlExternal::dispatchParams()
{
string const lfun = InsetExternalMailer::params2string(params(),
- kernel().buffer());
+ buffer());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
dialog().applyView();
string const lfun =
- InsetExternalMailer::params2string(params(), kernel().buffer());
- kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
+ InsetExternalMailer::params2string(params(), buffer());
+ dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
}
{
docstring const title = _("Select external file");
- docstring const bufpath = lyx::from_utf8(kernel().bufferFilepath());
+ docstring const bufpath = lyx::from_utf8(bufferFilepath());
FileFilterList const filter =
FileFilterList(lyx::from_utf8(getTemplateFilters(lyx::to_utf8(template_name))));
string const ControlExternal::readBB(string const & file)
{
- FileName const abs_file(makeAbsPath(file, kernel().bufferFilepath()));
+ FileName const abs_file(makeAbsPath(file, bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
void ControlFloat::dispatchParams()
{
string const lfun = InsetFloatMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
bool ControlGraphics::initialiseParams(string const & data)
{
InsetGraphicsParams params;
- InsetGraphicsMailer::string2params(data, kernel().buffer(), params);
+ InsetGraphicsMailer::string2params(data, buffer(), params);
params_.reset(new InsetGraphicsParams(params));
return true;
}
{
InsetGraphicsParams tmp_params(params());
string const lfun =
- InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ InsetGraphicsMailer::params2string(tmp_params, buffer());
+ dispatch(FuncRequest(getLfun(), lfun));
}
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
// Show the file browser dialog
- return browseRelFile(in_name, from_utf8(kernel().bufferFilepath()),
+ return browseRelFile(in_name, from_utf8(bufferFilepath()),
title,
FileFilterList(),
false, dir1, dir2);
string const ControlGraphics::readBB(string const & file)
{
- FileName const abs_file(makeAbsPath(file, kernel().bufferFilepath()));
+ FileName const abs_file(makeAbsPath(file, bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
bool ControlGraphics::isFilenameValid(string const & fname) const
{
// It may be that the filename is relative.
- FileName const name(makeAbsPath(fname, kernel().bufferFilepath()));
+ FileName const name(makeAbsPath(fname, bufferFilepath()));
return isFileReadable(name);
}
dialog().applyView();
string const lfun =
- InsetGraphicsMailer::params2string(params(), kernel().buffer());
- kernel().dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
+ InsetGraphicsMailer::params2string(params(), buffer());
+ dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
}
#include "ControlInclude.h"
#include "frontend_helpers.h"
-#include "Kernel.h"
#include "Buffer.h"
#include "Format.h"
void ControlInclude::dispatchParams()
{
string const lfun = InsetIncludeMailer::params2string(params_);
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
}
pair<docstring, docstring> dir1(_("Documents|#o#O"),
- lyx::from_utf8(lyxrc.document_path));
+ from_utf8(lyxrc.document_path));
- docstring const docpath = lyx::from_utf8(onlyPath(kernel().buffer().fileName()));
+ docstring const docpath = from_utf8(onlyPath(buffer().fileName()));
return browseRelFile(in_name, docpath, title,
filters, false, dir1);
{
string const ext = support::getExtension(file);
if (ext == "lyx")
- kernel().dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file));
+ dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file));
else
// tex file or other text file in verbatim mode
- formats.edit(kernel().buffer(),
- FileName(makeAbsPath(file, onlyPath(kernel().buffer().fileName()))),
+ formats.edit(buffer(),
+ FileName(makeAbsPath(file, onlyPath(buffer().fileName()))),
"text");
}
bool ControlInclude::fileExists(string const & file)
{
FileName const fileWithAbsPath(
- makeAbsPath(file, onlyPath(kernel().buffer().fileName())));
+ makeAbsPath(file, onlyPath(buffer().fileName())));
if (isFileReadable(fileWithAbsPath))
return true;
void ControlListings::dispatchParams()
{
string const lfun = InsetListingsMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
void ControlMath::dispatchFunc(kb_action action, string const & arg) const
{
- kernel().dispatch(FuncRequest(action, arg));
+ dispatch(FuncRequest(action, arg));
}
void ControlNote::dispatchParams()
{
string const lfun = InsetNoteMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
ostringstream data;
params().write(data);
FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
- kernel().dispatch(fr);
+ dispatch(fr);
}
}
-bool const ControlParagraph::haveMulitParSelection() {
- Cursor cur = kernel().bufferview()->cursor();
- if (!cur.selection())
- return false;
- return (cur.selBegin().pit() != cur.selEnd().pit());
+bool const ControlParagraph::haveMulitParSelection()
+{
+ Cursor cur = bufferview()->cursor();
+ return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
}
+
bool ControlParagraph::inInset() const
{
return ininset_;
}
+
bool ControlParagraph::canIndent() const
{
- return kernel().buffer().params().paragraph_separation ==
+ return buffer().params().paragraph_separation ==
BufferParams::PARSEP_INDENT;
}
+
LyXAlignment ControlParagraph::alignPossible() const
{
return alignpossible_;
#include "ControlPrefs.h"
#include "frontend_helpers.h"
-#include "Kernel.h"
#include "BufferList.h"
#include "gettext.h"
{
ostringstream ss;
rc_.write(ss, true);
- kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
-
+ dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
// FIXME: these need lfuns
// FIXME UNICODE
theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end();
for (; it != end; ++it)
- kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
+ dispatch(FuncRequest(LFUN_SET_COLOR, *it));
colors_.clear();
if (update_screen_font_) {
- kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+ dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
update_screen_font_ = false;
}
// The Save button has been pressed
if (dialog().isClosing()) {
- kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
+ dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
}
}
bool ControlPrint::initialiseParams(std::string const &)
{
/// get global printer parameters
- string const name = changeExtension(kernel().buffer().fileName(),
+ string const name = changeExtension(buffer().fileName(),
lyxrc.print_file_extension);
params_.reset(new PrinterParams(PrinterParams::PRINTER,
lyxrc.printer, name));
docstring const ControlPrint::browse(docstring const & in_name) const
{
- return browseRelFile(in_name, lyx::from_utf8(kernel().buffer().filePath()),
+ return browseRelFile(in_name, lyx::from_utf8(buffer().filePath()),
_("Print to file"),
FileFilterList(_("PostScript files (*.ps)")),
true);
command += lyxrc.print_extra_options + ' ';
}
- command += kernel().buffer().params().dvips_options();
+ command += buffer().params().dvips_options();
string const target = (pp.target == PrinterParams::PRINTER) ?
"printer" : "file";
pp.file_name;
string const data = target + " \"" + target_name + "\" \"" + command + '"';
- kernel().dispatch(FuncRequest(getLfun(), data));
+ dispatch(FuncRequest(getLfun(), data));
}
} // namespace frontend
void ControlRef::gotoRef(string const & ref)
{
- kernel().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
- kernel().dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
+ dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
+ dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
}
void ControlRef::gotoBookmark()
{
- kernel().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
+ dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
}
int ControlRef::getBufferNum() const
{
vector<string> buffers = theBufferList().getFileNames();
- string const name = kernel().buffer().fileName();
+ string const name = buffer().fileName();
vector<string>::const_iterator cit =
find(buffers.begin(), buffers.end(), name);
if (cit == buffers.end())
{
docstring const data = find2string(search, casesensitive,
matchword, forward);
- kernel().dispatch(FuncRequest(LFUN_WORD_FIND, data));
+ dispatch(FuncRequest(LFUN_WORD_FIND, data));
}
docstring const data =
replace2string(search, replace, casesensitive,
matchword, all, forward);
- kernel().dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
+ dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
}
} // namespace frontend
return;
string const data = format_->name() + " " + command_;
- kernel().dispatch(FuncRequest(getLfun(), data));
+ dispatch(FuncRequest(getLfun(), data));
}
exports.push_back("lyx");
exports.push_back("text");
- Buffer const & buffer = kernel().buffer();
-
- if (buffer.isLatex())
+ if (buffer().isLatex())
exports.push_back("latex");
- else if (buffer.isDocBook())
+ else if (buffer().isDocBook())
exports.push_back("docbook");
- else if (buffer.isLiterate())
+ else if (buffer().isLiterate())
exports.push_back("literate");
// Loop over these native formats and ascertain what formats we
{
LYXERR(Debug::GUI) << "Spellchecker::initialiseParams" << endl;
- speller_.reset(getSpeller(kernel().buffer().params()));
+ speller_.reset(getSpeller(buffer().params()));
if (!speller_.get())
return false;
SpellBase::Result res = SpellBase::OK;
- Cursor cur = kernel().bufferview()->cursor();
+ Cursor cur = bufferview()->cursor();
while (cur && cur.pos() && isLetter(cur)) {
cur.backwardPos();
}
ptrdiff_t start = 0, total = 0;
- DocIterator it = DocIterator(kernel().buffer().inset());
+ DocIterator it = DocIterator(buffer().inset());
for (start = 0; it != cur; it.forwardPos())
++start;
int const size = cur.selEnd().pos() - cur.selBegin().pos();
cur.pos() -= size;
- kernel().bufferview()->putSelectionAt(cur, size, false);
+ bufferview()->putSelectionAt(cur, size, false);
// FIXME: if we used a lfun like in find/replace, dispatch would do
// that for us
- kernel().bufferview()->update();
+ bufferview()->update();
// FIXME: this Controller is very badly designed...
- kernel().lyxview().currentWorkArea()->redraw();
+ lyxview().currentWorkArea()->redraw();
// set suggestions
if (res != SpellBase::OK && res != SpellBase::IGNORED_WORD) {
{
LYXERR(Debug::GUI) << "ControlSpellchecker::replace("
<< to_utf8(replacement) << ")" << std::endl;
- BufferView & bufferview = *kernel().bufferview();
- cap::replaceSelectionWithString(bufferview.cursor(), replacement, true);
- kernel().buffer().markDirty();
+ cap::replaceSelectionWithString(bufferview()->cursor(), replacement, true);
+ buffer().markDirty();
// If we used an LFUN, we would not need that
- bufferview.update();
+ bufferview()->update();
// fix up the count
--count_;
check();
bool ControlTabular::initialiseParams(string const & data)
{
// try to get the current cell
- BufferView const * const bv = kernel().bufferview();
+ BufferView const * const bv = bufferview();
InsetTabular const * current_inset = 0;
if (bv) {
Cursor const & cur = bv->cursor();
return true;
}
- InsetTabular tmp(kernel().buffer());
+ InsetTabular tmp(buffer());
InsetTabularMailer::string2params(data, tmp);
params_.reset(new Tabular(tmp.tabular));
return true;
void ControlTabular::set(Tabular::Feature f, string const & arg)
{
string const data = featureAsString(f) + ' ' + arg;
- kernel().dispatch(FuncRequest(getLfun(), data));
+ dispatch(FuncRequest(getLfun(), data));
}
void ControlTabularCreate::dispatchParams()
{
string const data = convert<string>(params().first) + ' ' + convert<string>(params().second);
- kernel().dispatch(FuncRequest(getLfun(), data));
+ dispatch(FuncRequest(getLfun(), data));
}
} // namespace frontend
void ControlTexinfo::viewFile(string const & filename) const
{
string const arg = "file " + filename;
- kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
+ dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));
}
true, // match word
false, // all words
true); // forward
- kernel().dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
+ dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
}
using std::string;
-class Buffer;
-
namespace lyx {
namespace frontend {
-
ControlToc::ControlToc(Dialog & d)
: ControlCommand(d, "tableofcontents", "toc")
{
TocList const & ControlToc::tocs() const
{
- return kernel().buffer().getMasterBuffer()->tocBackend().tocs();
+ return buffer().getMasterBuffer()->tocBackend().tocs();
}
types_.clear();
type_names_.clear();
- TocList const & tocs = kernel().buffer().getMasterBuffer()->
+ TocList const & tocs = buffer().getMasterBuffer()->
tocBackend().tocs();
TocList::const_iterator it = tocs.begin();
TocList::const_iterator end = tocs.end();
return true;
}
+
void ControlToc::goTo(TocItem const & item)
{
string const tmp = convert<string>(item.id());
- kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+ lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
void ControlToc::outlineUp()
{
- kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
+ dispatch(FuncRequest(LFUN_OUTLINE_UP));
}
void ControlToc::outlineDown()
{
- kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
+ dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
}
void ControlToc::outlineIn()
{
- kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
+ dispatch(FuncRequest(LFUN_OUTLINE_IN));
}
void ControlToc::outlineOut()
{
- kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
+ dispatch(FuncRequest(LFUN_OUTLINE_OUT));
}
void ControlToc::updateBackend()
{
- kernel().buffer().getMasterBuffer()->tocBackend().update();
- kernel().buffer().structureChanged();
+ buffer().getMasterBuffer()->tocBackend().update();
+ buffer().structureChanged();
}
TocIterator const ControlToc::getCurrentTocItem(size_t type) const
{
- BOOST_ASSERT(kernel().bufferview());
- ParConstIterator it(kernel().bufferview()->cursor());
- Buffer const * master = kernel().buffer().getMasterBuffer();
+ BOOST_ASSERT(bufferview());
+ ParConstIterator it(bufferview()->cursor());
+ Buffer const * master = buffer().getMasterBuffer();
return master->tocBackend().item(types_[type], it);
}
if (type == "tableofcontents")
return _("Table of Contents");
- FloatList const & floats =
- kernel().buffer().params().getTextClass().floats();
+ FloatList const & floats = buffer().params().getTextClass().floats();
if (floats.typeExist(type))
return _(floats.getType(type).listName());
else
bool ControlVSpace::initialiseParams(string const & data)
{
InsetVSpaceMailer::string2params(data, params_);
-
- // so that the user can press Ok
dialog().setButtonsValid(true);
return true;
void ControlVSpace::dispatchParams()
{
string const str = InsetVSpaceMailer::params2string(params_);
- kernel().dispatch(FuncRequest(getLfun(), str));
+ dispatch(FuncRequest(getLfun(), str));
}
#include "Buffer.h"
#include "Cursor.h"
#include "TexRow.h"
-#include <sstream>
+
using std::string;
return true;
}
+
docstring const ControlViewSource::updateContent(bool fullSource)
{
// get the *top* level paragraphs that contain the cursor,
// or the selected text
- lyx::pit_type par_begin;
- lyx::pit_type par_end;
+ pit_type par_begin;
+ pit_type par_end;
- BufferView * view = kernel().bufferview();
+ BufferView * view = bufferview();
if (!view->cursor().selection()) {
par_begin = view->cursor().bottom().pit();
par_end = par_begin;
}
if (par_begin > par_end)
std::swap(par_begin, par_end);
- lyx::odocstringstream ostr;
+ odocstringstream ostr;
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
return ostr.str();
}
std::pair<int, int> ControlViewSource::getRows() const
{
- BufferView const * view = kernel().bufferview();
+ BufferView const * view = bufferview();
CursorSlice beg = view->cursor().selectionBegin().bottom();
CursorSlice end = view->cursor().selectionEnd().bottom();
docstring const ControlViewSource::title() const
{
- string source_type;
-
- Kernel::DocType doctype = kernel().docType();
- switch (doctype) {
- case Kernel::LATEX:
- source_type = "LaTeX";
- break;
- case Kernel::DOCBOOK:
- source_type = "DocBook";
- break;
- case Kernel::LITERATE:
- source_type = "Literate";
- default:
- BOOST_ASSERT(false);
+ switch (docType()) {
+ case LATEX:
+ return _("LaTeX Source");
+ case DOCBOOK:
+ return _("DocBook Source");
+ case LITERATE:
+ return _("Literate Source");
+ default:
+ BOOST_ASSERT(false);
+ return docstring();
}
- return _(source_type + " Source");
}
} // namespace frontend
void ControlWrap::dispatchParams()
{
string const lfun = InsetWrapMailer::params2string(params());
- kernel().dispatch(FuncRequest(getLfun(), lfun));
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
#include "Dialog.h"
-#include "frontends/LyXView.h"
-
-#include "debug.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LyXFunc.h"
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h" // FIXME
+
+#include "Buffer.h"
-using std::string;
namespace lyx {
namespace frontend {
-Dialog::Dialog(LyXView & lv, string const & name)
- : is_closing_(false), kernel_(lv), name_(name), controller_(0)
+
+Dialog::~Dialog()
{}
-Dialog::~Dialog()
+Controller::Controller(Dialog & parent)
+ : parent_(parent), lyxview_(0)
+{}
+
+
+Controller::~Controller()
+{}
+
+
+bool Controller::canApply() const
{
- delete controller_;
+ FuncRequest const fr(getLfun(), dialog().name());
+ FuncStatus const fs(getStatus(fr));
+ return fs.enabled();
}
-void Dialog::show(string const & data)
+void Controller::dispatch(FuncRequest const & fr) const
{
- if (controller().isBufferDependent() && !kernel().isBufferAvailable())
- return;
-
- if (!controller().initialiseParams(data)) {
- lyxerr << "Dialog \"" << name_
- << "\" failed to translate the data "
- "string passed to show()" << std::endl;
- return;
- }
-
- preShow();
- showView();
- postShow();
+ lyxview_->dispatch(fr);
}
-void Dialog::update(string const & data)
+void Controller::updateDialog(std::string const & name) const
{
- if (controller().isBufferDependent() && !kernel().isBufferAvailable())
- return;
-
- if (!controller().initialiseParams(data)) {
- lyxerr << "Dialog \"" << name_
- << "\" could not be initialized" << std::endl;
- return;
- }
-
- preUpdate();
- updateView();
- postUpdate();
+ dispatch(FuncRequest(LFUN_DIALOG_UPDATE, name));
}
-void Dialog::checkStatus()
+void Controller::disconnect(std::string const & name) const
{
+ lyxview_->getDialogs().disconnect(name);
}
-void Dialog::hide()
+bool Controller::isBufferAvailable() const
{
- if (!isVisibleView())
- return;
-
- controller().clearParams();
- hideView();
- kernel().disconnect(name_);
+ return lyxview_->buffer() != 0;
}
-void Dialog::apply()
+bool Controller::isBufferReadonly() const
{
- if (controller().isBufferDependent()) {
- if (!kernel().isBufferAvailable() ||
- (kernel().isBufferReadonly() && !controller().canApplyToReadOnly()))
- return;
- }
-
- applyView();
- controller().dispatchParams();
-
- if (controller().disconnectOnApply() && !is_closing_) {
- kernel().disconnect(name_);
- controller().initialiseParams(string());
- updateView();
- }
+ if (!lyxview_->buffer())
+ return true;
+ return lyxview_->buffer()->isReadonly();
}
-bool Dialog::isVisible() const
+std::string const Controller::bufferFilepath() const
{
- return isVisibleView();
+ return buffer().filePath();
}
-void Dialog::redraw()
+KernelDocType Controller::docType() const
{
- redrawView();
+ if (buffer().isLatex())
+ return LATEX;
+ if (buffer().isLiterate())
+ return LITERATE;
+
+ return DOCBOOK;
}
-void Dialog::setController(Controller * controller)
+BufferView * Controller::bufferview()
{
- BOOST_ASSERT(controller);
- BOOST_ASSERT(!controller_);
- controller_ = controller;
+ return lyxview_->view();
}
-Controller & Dialog::controller() const
+
+BufferView const * Controller::bufferview() const
{
- BOOST_ASSERT(controller_);
- return *controller_;
+ return lyxview_->view();
}
-Controller::Controller(Dialog & parent)
- : parent_(parent)
-{}
+Buffer & Controller::buffer()
+{
+ BOOST_ASSERT(lyxview_->buffer());
+ return *lyxview_->buffer();
+}
-bool Controller::canApply() const
+Buffer const & Controller::buffer() const
{
- FuncRequest const fr(getLfun(), dialog().name());
- FuncStatus const fs(getStatus(fr));
- return fs.enabled();
+ BOOST_ASSERT(lyxview_->buffer());
+ return *lyxview_->buffer();
}
-
} // namespace frontend
} // namespace lyx
#ifndef DIALOG_H
#define DIALOG_H
-#include "Kernel.h"
#include "lfuns.h"
#include "support/docstring.h"
-#include <boost/scoped_ptr.hpp>
+#include <string>
namespace lyx {
+
+class Buffer;
+class BufferView;
+class FuncRequest;
+
namespace frontend {
class LyXView;
+/** \enum KernelDocType used to flag the different kinds of buffer
+ * without making the kernel header files available to the
+ * dialog's Controller or View.
+ */
+enum KernelDocType
+{
+ LATEX,
+ LITERATE,
+ DOCBOOK
+};
+
+
/** Different dialogs will have different Controllers and Views.
* deriving from these base classes.
*/
/// \param lv is the access point for the dialog to the LyX kernel.
/// \param name is the identifier given to the dialog by its parent
/// container.
- Dialog(LyXView & lv, std::string const & name);
+ Dialog() {}
virtual ~Dialog();
/** \name Container Access
//@{
/// \param data is a string encoding of the data to be displayed.
/// It is passed to the Controller to be translated into a useable form.
- void show(std::string const & data);
- void update(std::string const & data);
+ virtual void showData(std::string const & /*data*/) {}
+ virtual void updateData(std::string const & /*data*/) {}
- void hide();
- bool isVisible() const;
+ virtual void hide() {}
// Override in GuiDialog
- virtual void preShow() {}
- virtual void postShow() {}
- virtual void preUpdate() {}
- virtual void postUpdate() {}
-
virtual void OkButton() {}
virtual void ApplyButton() {}
virtual void CancelButton() {}
/** This function is called, for example, if the GUI colours
* have been changed.
*/
- void redraw();
+ virtual void redraw() {}
//@}
/** Check whether we may apply our data.
*
* The buttons are disabled if not and (re-)enabled if yes.
*/
- void checkStatus();
+ virtual void checkStatus() {}
/** When applying, it's useful to know whether the dialog is about
* to close or not (no point refreshing the display for example).
*/
- bool isClosing() const { return is_closing_; }
-
- /** The LyX kernel is made available through this wrapper class.
- * In an ideal world, it will shrink as more info is passed to the
- * show() and update() methods.
- */
- Kernel & kernel() { return kernel_; }
- Kernel const & kernel() const { return kernel_; }
+ virtual bool isClosing() const { return false; }
/** \name Dialog Specialization
* Methods to set the Controller and View and so specialise
* to a particular dialog.
*/
//@{
- /// \param ptr is stored and destroyed by \c Dialog.
- void setController(Controller * ptr);
- //@}
-
- /** \name Dialog Components
- * Methods to access the various components making up a dialog.
- */
- //@{
- virtual Controller & controller() const;
+ virtual Controller & controller() const = 0;
//@}
/** \c Button controller part
virtual void hideView() = 0;
/// Redraw the dialog (e.g. if the colors have been remapped).
- virtual void redrawView() {}
+ virtual void redrawView() = 0;
/// Create the dialog if necessary, update it and display it.
virtual void showView() = 0;
* dialog therefore needs updating.
* \param id identifies what should be updated.
*/
- virtual void partialUpdateView(int /*id*/) {}
+ virtual void partialUpdateView(int /*id*/) = 0;
///
- std::string name() const { return name_; }
+ virtual std::string name() const = 0;
+
+protected:
+ virtual void apply() {}
private:
/// intentionally unimplemented, therefore uncopiable
Dialog(Dialog const &);
void operator=(Dialog const &);
-
-protected:
- void apply();
-
- bool is_closing_;
- Kernel kernel_;
- /** The Dialog's name is the means by which a dialog identifies
- * itself to the kernel.
- */
- std::string name_;
- Controller * controller_;
};
public:
/// \param parent Dialog owning this Controller.
Controller(Dialog & parent);
- virtual ~Controller() {}
+ virtual ~Controller();
+ void setLyXView(LyXView & lv) { lyxview_ = &lv; }
/** \name Generic Controller
* These few methods are all that a generic dialog needs of a
*/
virtual bool exitEarly() const { return false; }
//@}
-
- /// Main Window access.
- /// This is unfortunately needed for the qt4 frontend and the \c
- /// QDialogView framework. This permits to give a parent to the
- /// constructed \c QDialog via a cast to \c GuiView.
- LyXView * view() { return &parent_.kernel().lyxview(); }
-
-protected:
+public:
/** \name Controller Access
* Enable the derived classes to access the other parts of the whole.
*/
//@{
Dialog & dialog() { return parent_; }
Dialog const & dialog() const { return parent_; }
+ //@}
+
+ /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
+ * (Ie, it provides an interface to the Model part of the Model-Controller-
+ * View split.
+ * In an ideal world, it will shrink as more info is passed to the
+ * Dialog::show() and Dialog::update() methods.
+ */
- Kernel & kernel() { return parent_.kernel(); }
- Kernel const & kernel() const { return parent_.kernel(); }
+
+ /** This method is the primary purpose of the class. It provides
+ * the "gateway" by which the dialog can send a request (of a
+ * change in the data, for more information) to the kernel.
+ * \param fr is the encoding of the request.
+ */
+ void dispatch(FuncRequest const & fr) const;
+
+ /** The dialog has received a request from the user
+ * (who pressed the "Restore" button) to update contents.
+ * It must, therefore, ask the kernel to provide this information.
+ * \param name is used to identify the dialog to the kernel.
+ */
+ void updateDialog(std::string const & name) const;
+
+ /** A request from the Controller that future changes to the data
+ * stored by the dialog are not applied to the inset currently
+ * connected to the dialog. Instead, they will be used to generate
+ * a new inset at the cursor position.
+ * \param name is used to identify the dialog to the kernel.
+ */
+ void disconnect(std::string const & name) const;
+
+ /** \name Kernel Wrappers
+ * Simple wrapper functions to Buffer methods.
+ */
+ //@{
+ bool isBufferAvailable() const;
+ bool isBufferReadonly() const;
+ std::string const bufferFilepath() const;
+ //@}
+
+ /// The type of the current buffer.
+ KernelDocType docType() const;
+
+ /** \name Kernel Nasties
+ * Unpleasantly public internals of the LyX kernel.
+ * We should aim to reduce/remove these from the interface.
+ */
+ //@{
+ LyXView & lyxview() { return *lyxview_; }
+ LyXView const & lyxview() const { return *lyxview_; }
+
+ Buffer & buffer();
+ Buffer const & buffer() const;
+
+ BufferView * bufferview();
+ BufferView const * bufferview() const;
//@}
private:
private:
Dialog & parent_;
+ LyXView * lyxview_;
};
-
} // namespace frontend
} // namespace lyx
+++ /dev/null
-/**
- * \file Kernel.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Kernel.h"
-
-#include "Buffer.h"
-#include "BufferView.h"
-#include "FuncRequest.h"
-#include "LyXFunc.h"
-#include "frontends/Dialogs.h"
-#include "frontends/LyXView.h"
-
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-Kernel::Kernel(LyXView & lyxview)
- : lyxview_(lyxview)
-{}
-
-
-void Kernel::dispatch(FuncRequest const & fr) const
-{
- lyxview_.dispatch(fr);
-}
-
-
-void Kernel::updateDialog(string const & name) const
-{
- dispatch(FuncRequest(LFUN_DIALOG_UPDATE, name));
-}
-
-
-void Kernel::disconnect(string const & name) const
-{
- lyxview_.getDialogs().disconnect(name);
-}
-
-bool Kernel::isBufferAvailable() const
-{
- return lyxview_.buffer() != 0;
-}
-
-
-bool Kernel::isBufferReadonly() const
-{
- if (!lyxview_.buffer())
- return true;
- return lyxview_.buffer()->isReadonly();
-}
-
-
-string const Kernel::bufferFilepath() const
-{
- return buffer().filePath();
-}
-
-
-Kernel::DocType Kernel::docType() const
-{
- if (buffer().isLatex())
- return LATEX;
- if (buffer().isLiterate())
- return LITERATE;
-
- return DOCBOOK;
-}
-
-
-BufferView * Kernel::bufferview()
-{
- return lyxview_.view();
-}
-
-
-BufferView const * Kernel::bufferview() const
-{
- return lyxview_.view();
-}
-
-
-Buffer & Kernel::buffer()
-{
- BOOST_ASSERT(lyxview_.buffer());
- return *lyxview_.buffer();
-}
-
-
-Buffer const & Kernel::buffer() const
-{
- BOOST_ASSERT(lyxview_.buffer());
- return *lyxview_.buffer();
-}
-
-} // namespace frontend
-} // namespace lyx
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file Kernel.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef KERNEL_H
-#define KERNEL_H
-
-#include <string>
-
-namespace lyx {
-
-class Buffer;
-class BufferView;
-class FuncRequest;
-
-namespace frontend {
-
-class LyXView;
-
-/** \c Kernel is a wrapper making the LyX kernel available to the dialog.
- * (Ie, it provides an interface to the Model part of the Model-Controller-
- * View split.
- * In an ideal world, it will shrink as more info is passed to the
- * Dialog::show() and Dialog::update() methods.
- */
-class Kernel {
-public:
- /// \param lv is the access point for the dialog to the LyX kernel.
- Kernel(LyXView & lv);
-
- /** This method is the primary purpose of the class. It provides
- * the "gateway" by which the dialog can send a request (of a
- * change in the data, for more information) to the kernel.
- * \param fr is the encoding of the request.
- */
- void dispatch(FuncRequest const & fr) const;
-
- /** The dialog has received a request from the user
- * (who pressed the "Restore" button) to update contents.
- * It must, therefore, ask the kernel to provide this information.
- * \param name is used to identify the dialog to the kernel.
- */
- void updateDialog(std::string const & name) const;
-
- /** A request from the Controller that future changes to the data
- * stored by the dialog are not applied to the inset currently
- * connected to the dialog. Instead, they will be used to generate
- * a new inset at the cursor position.
- * \param name is used to identify the dialog to the kernel.
- */
- void disconnect(std::string const & name) const;
-
- /** \name Kernel Wrappers
- * Simple wrapper functions to Buffer methods.
- */
- //@{
- bool isBufferAvailable() const;
- bool isBufferReadonly() const;
- std::string const bufferFilepath() const;
- //@}
-
- /** \enum DocType used to flag the different kinds of buffer
- * without making the kernel header files available to the
- * dialog's Controller or View.
- */
- enum DocType {
- LATEX,
- LITERATE,
- DOCBOOK
- };
- /// The type of the current buffer.
- DocType docType() const;
-
- /** \name Kernel Nasties
- * Unpleasantly public internals of the LyX kernel.
- * We should aim to reduce/remove these from the interface.
- */
- //@{
- LyXView & lyxview() { return lyxview_; }
- LyXView const & lyxview() const { return lyxview_; }
-
- Buffer & buffer();
- Buffer const & buffer() const;
-
- BufferView * bufferview();
- BufferView const * bufferview() const;
- //@}
-
-private:
- LyXView & lyxview_;
-};
-
-
-/** \c KernelDocType is a wrapper for Kernel::DocType.
- * It can be forward-declared and passed as a function argument without
- * having to expose Kernel.h.
- */
-class KernelDocType {
-public:
- KernelDocType(Kernel::DocType val) : val_(val) {}
- operator Kernel::DocType() const { return val_; }
-private:
- Kernel::DocType val_;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // KERNEL_H
SOURCEFILES = \
Dialog.cpp \
- Kernel.cpp \
ButtonPolicy.cpp \
ControlBibtex.cpp \
ControlBox.cpp \
frontend_helpers.cpp
HEADERFILES = \
- Kernel.h \
ButtonPolicy.h \
ControlBibtex.h \
ControlBox.h \
#include <QDockWidget>
-#include <boost/scoped_ptr.hpp>
-
-#include <string>
-
namespace lyx {
namespace frontend {
std::string const & name, ///< dialog identifier.
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
Qt::WindowFlags flags = 0
- )
- : QDockWidget(&parent, flags),
- Dialog(parent, name)
+ )
+ : QDockWidget(&parent, flags), name_(name)
{
if (flags & Qt::Drawer)
setFeatures(QDockWidget::NoDockWidgetFeatures);
- MyController * controller = new MyController(*this);
- setController(controller);
- widget_.reset(new MyWidget(*controller));
- setWidget(widget_.get());
+ MyController * c = new MyController(*this);
+ controller_ = c;
+ controller_->setLyXView(parent);
+ widget_ = new MyWidget(*c);
+ setWidget(widget_);
setWindowTitle(widget_->windowTitle());
parent.addDockWidget(area, this);
}
+ ~DockView() { delete widget_; delete controller_; }
/// Dialog inherited methods
//@{
void hideView() { QDockWidget::hide(); }
void showView() { QDockWidget::show(); }
bool isVisibleView() const { return QDockWidget::isVisible(); }
+ void checkStatus() {}
+ void redraw() { redrawView(); }
void redrawView() {}
void updateView()
{
widget_->updateView();
QDockWidget::update();
}
+ bool isClosing() const { return false; }
+ void partialUpdateView(int /*id*/) {}
+ Controller & controller() const { return *controller_; }
+ std::string name() const { return name_; }
//@}
private:
/// The encapsulated widget.
- boost::scoped_ptr<MyWidget> widget_;
+ MyWidget * widget_;
+ Controller * controller_;
+ std::string name_;
};
} // frontend
ControlCommand & GuiBibitemDialog::controller() const
{
- return static_cast<ControlCommand &>(Dialog::controller());
+ return static_cast<ControlCommand &>(GuiDialog::controller());
}
ControlBibtex & GuiBibtexDialog::controller() const
{
- return static_cast<ControlBibtex &>(Dialog::controller());
+ return static_cast<ControlBibtex &>(GuiDialog::controller());
}
ControlBox & GuiBoxDialog::controller() const
{
- return static_cast<ControlBox &>(Dialog::controller());
+ return static_cast<ControlBox &>(GuiDialog::controller());
}
ControlBranch & GuiBranchDialog::controller() const
{
- return static_cast<ControlBranch &>(Dialog::controller());
+ return static_cast<ControlBranch &>(GuiDialog::controller());
}
ControlChanges & GuiChangesDialog::controller() const
{
- return static_cast<ControlChanges &>(Dialog::controller());
+ return static_cast<ControlChanges &>(GuiDialog::controller());
}
ControlCharacter & GuiCharacterDialog::controller() const
{
- return static_cast<ControlCharacter &>(Dialog::controller());
+ return static_cast<ControlCharacter &>(GuiDialog::controller());
}
ControlCitation & GuiCitationDialog::controller() const
{
- return static_cast<ControlCitation &>(Dialog::controller());
+ return static_cast<ControlCitation &>(GuiDialog::controller());
}
#include "GuiDialog.h"
#include "debug.h"
#include "qt_helpers.h"
+#include "frontends/LyXView.h"
+
+using std::string;
namespace lyx {
namespace frontend {
GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
- : Dialog(lv, name)
-{}
+ : is_closing_(false), name_(name), controller_(0)
+{
+ lyxview_ = &lv;
+}
+
+
+GuiDialog::~GuiDialog()
+{
+ delete controller_;
+}
void GuiDialog::setViewTitle(docstring const & title)
void GuiDialog::RestoreButton()
{
- // Tell the kernel that a request to refresh the dialog's contents
- // has been received. It's up to the kernel to supply the necessary
+ // Tell the controller that a request to refresh the dialog's contents
+ // has been received. It's up to the controller to supply the necessary
// info by calling GuiDialog::updateView().
- kernel().updateDialog(name_);
+ controller().updateDialog(name_);
bc().restore();
}
-
-void GuiDialog::preShow()
-{
- bc().setReadOnly(kernel().isBufferReadonly());
-}
-
-
-void GuiDialog::postShow()
-{
- // The widgets may not be valid, so refresh the button controller
- bc().refresh();
-}
-
-
-void GuiDialog::preUpdate()
-{
- bc().setReadOnly(kernel().isBufferReadonly());
-}
-
-
-void GuiDialog::postUpdate()
-{
- // The widgets may not be valid, so refresh the button controller
- bc().refresh();
-}
-
-
void GuiDialog::checkStatus()
{
// buffer independant dialogs are always active.
return;
// deactivate the dialog if we have no buffer
- if (!kernel().isBufferAvailable()) {
+ if (!controller().isBufferAvailable()) {
bc().setReadOnly(true);
return;
}
// check whether this dialog may be active
if (controller().canApply()) {
- bool const readonly = kernel().isBufferReadonly();
+ bool const readonly = controller().isBufferReadonly();
bc().setReadOnly(readonly);
// refreshReadOnly() is too generous in _enabling_ widgets
// update dialog to disable disabled widgets again
bool GuiDialog::readOnly() const
{
- return kernel().isBufferReadonly();
+ return controller().isBufferReadonly();
}
}
-bool GuiDialog::isValid()
-{
- return true;
-}
-
-
void GuiDialog::changed()
{
if (updating_)
RestoreButton();
}
+
void GuiDialog::updateView()
{
setUpdatesEnabled(false);
QDialog::update();
}
+
+void GuiDialog::showData(string const & data)
+{
+ if (controller().isBufferDependent() && !controller().isBufferAvailable())
+ return;
+
+ if (!controller().initialiseParams(data)) {
+ lyxerr << "Dialog \"" << name_
+ << "\" failed to translate the data "
+ "string passed to show()" << std::endl;
+ return;
+ }
+
+ bc().setReadOnly(controller().isBufferReadonly());
+ showView();
+ // The widgets may not be valid, so refresh the button controller
+ bc().refresh();
+}
+
+
+void GuiDialog::updateData(string const & data)
+{
+ if (controller().isBufferDependent() && !controller().isBufferAvailable())
+ return;
+
+ if (!controller().initialiseParams(data)) {
+ lyxerr << "Dialog \"" << name_
+ << "\" could not be initialized" << std::endl;
+ return;
+ }
+
+ bc().setReadOnly(controller().isBufferReadonly());
+ updateView();
+ // The widgets may not be valid, so refresh the button controller
+ bc().refresh();
+}
+
+
+void GuiDialog::hide()
+{
+ if (!isVisibleView())
+ return;
+
+ controller().clearParams();
+ hideView();
+ controller().disconnect(name_);
+}
+
+
+void GuiDialog::apply()
+{
+ if (controller().isBufferDependent()) {
+ if (!controller().isBufferAvailable() ||
+ (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
+ return;
+ }
+
+ applyView();
+ controller().dispatchParams();
+
+ if (controller().disconnectOnApply() && !is_closing_) {
+ controller().disconnect(name_);
+ controller().initialiseParams(string());
+ updateView();
+ }
+}
+
+
+void GuiDialog::setController(Controller * controller)
+{
+ BOOST_ASSERT(controller);
+ BOOST_ASSERT(!controller_);
+ controller_ = controller;
+ controller_->setLyXView(*lyxview_);
+}
+
+
} // namespace frontend
} // namespace lyx
/// \param lv is the access point for the dialog to the LyX kernel.
/// \param name is the identifier given to the dialog by its parent
/// container.
- GuiDialog(LyXView & lv, std::string const & name);
- //GuiDialog(GuiDialog &, docstring const &);
+ explicit GuiDialog(LyXView & lv, std::string const & name);
+ ~GuiDialog();
public Q_SLOTS:
// dialog closed from WM
ButtonController & bc() { return bc_; }
//@}
- void preShow();
- void postShow();
- void preUpdate();
- void postUpdate();
-
void setViewTitle(docstring const & title);
///
///
virtual bool isVisibleView() const;
/// is the dialog currently valid ?
- virtual bool isValid();
+ virtual bool isValid() { return true; }
+
+public:
+ /** \name Container Access
+ * These methods are publicly accessible because they are invoked
+ * by the parent container acting on commands from the LyX kernel.
+ */
+ //@{
+ /// \param data is a string encoding of the data to be displayed.
+ /// It is passed to the Controller to be translated into a useable form.
+ void showData(std::string const & data);
+ void updateData(std::string const & data);
+
+ void hide();
+
+ /** This function is called, for example, if the GUI colours
+ * have been changed.
+ */
+ void redraw() { redrawView(); }
+ //@}
+
+ /** When applying, it's useful to know whether the dialog is about
+ * to close or not (no point refreshing the display for example).
+ */
+ bool isClosing() const { return is_closing_; }
+
+ /** \name Dialog Specialization
+ * Methods to set the Controller and View and so specialise
+ * to a particular dialog.
+ */
+ //@{
+ /// \param ptr is stored and destroyed by \c Dialog.
+ void setController(Controller * ptr);
+ //@}
+
+ /** \name Dialog Components
+ * Methods to access the various components making up a dialog.
+ */
+ //@{
+ virtual Controller & controller() const { return *controller_; }
+ //@}
+
+ /** Defaults to nothing. Can be used by the Controller, however, to
+ * indicate to the View that something has changed and that the
+ * dialog therefore needs updating.
+ * \param id identifies what should be updated.
+ */
+ virtual void partialUpdateView(int /*id*/) {}
+
+ ///
+ std::string name() const { return name_; }
+
+ void apply();
+ void redrawView() {}
private:
- /// update the dialog
+ /// Update the display of the dialog whilst it is still visible.
virtual void updateView();
ButtonController bc_;
/// are we updating ?
bool updating_;
+
+ bool is_closing_;
+ /** The Dialog's name is the means by which a dialog identifies
+ * itself to the kernel.
+ */
+ std::string name_;
+ Controller * controller_;
+ LyXView * lyxview_; // FIXME: replace by moving to constructor
};
} // namespace frontend
ControlDocument & GuiDocumentDialog::controller() const
{
- return static_cast<ControlDocument &>(Dialog::controller());
+ return static_cast<ControlDocument &>(GuiDialog::controller());
}
ControlERT & GuiERTDialog::controller() const
{
- return static_cast<ControlERT &>(Dialog::controller());
+ return static_cast<ControlERT &>(GuiDialog::controller());
}
public:
GuiEmbeddedFilesDialog(ControlEmbeddedFiles &);
+ std::string name() const { return "embedding"; }
public Q_SLOTS:
///
ControlErrorList & GuiErrorListDialog::controller() const
{
- return static_cast<ControlErrorList &>(Dialog::controller());
+ return static_cast<ControlErrorList &>(GuiDialog::controller());
}
ControlExternal & GuiExternalDialog::controller() const
{
- return static_cast<ControlExternal &>(Dialog::controller());
+ return static_cast<ControlExternal &>(GuiDialog::controller());
}
InsetExternalParams const & params = controller().params();
string const name =
- params.filename.outputFilename(kernel().bufferFilepath());
+ params.filename.outputFilename(controller().bufferFilepath());
fileED->setText(toqstr(name));
externalCO->setCurrentIndex(
tab->setTabEnabled(
tab->indexOf(optionstab), enabled);
- extraED->setEnabled(enabled && !kernel().isBufferReadonly());
+ extraED->setEnabled(enabled && !controller().isBufferReadonly());
extraFormatCO->setEnabled(enabled);
if (enabled) {
InsetExternalParams params = controller().params();
params.filename.set(internal_path(fromqstr(fileED->text())),
- kernel().bufferFilepath());
+ controller().bufferFilepath());
params.settemplate(controller().getTemplate(
externalCO->currentIndex()).lyxName);
ControlFloat & GuiFloatDialog::controller() const
{
- return static_cast<ControlFloat &>(Dialog::controller());
+ return static_cast<ControlFloat &>(GuiDialog::controller());
}
}
string const name =
- igp.filename.outputFilename(kernel().bufferFilepath());
+ igp.filename.outputFilename(controller().bufferFilepath());
filename->setText(toqstr(name));
// set the bounding box values
InsetGraphicsParams & igp = controller().params();
igp.filename.set(internal_path(fromqstr(filename->text())),
- kernel().bufferFilepath());
+ controller().bufferFilepath());
// the bb section
igp.bb.erase();
ControlInclude & GuiIncludeDialog::controller() const
{
- return static_cast<ControlInclude &>(Dialog::controller());
+ return static_cast<ControlInclude &>(GuiDialog::controller());
}
ControlCommand & GuiIndexDialogBase::controller() const
{
- return static_cast<ControlCommand &>(Dialog::controller());
+ return static_cast<ControlCommand &>(GuiDialog::controller());
}
ControlListings & GuiListingsDialog::controller() const
{
- return static_cast<ControlListings &>(Dialog::controller());
+ return static_cast<ControlListings &>(GuiDialog::controller());
}
ControlLog & GuiLogDialog::controller() const
{
- return static_cast<ControlLog &>(Dialog::controller());
+ return static_cast<ControlLog &>(GuiDialog::controller());
}
ControlMath & GuiMathMatrixDialog::controller() const
{
- return static_cast<ControlMath &>(Dialog::controller());
+ return static_cast<ControlMath &>(GuiDialog::controller());
}
ControlCommand & GuiNomenclDialog::controller() const
{
- return static_cast<ControlCommand &>(Dialog::controller());
+ return static_cast<ControlCommand &>(GuiDialog::controller());
}
ControlNote & GuiNoteDialog::controller() const
{
- return static_cast<ControlNote &>(Dialog::controller());
+ return static_cast<ControlNote &>(GuiDialog::controller());
}
ControlParagraph & GuiParagraphDialog::controller() const
{
- return static_cast<ControlParagraph &>(Dialog::controller());
+ return static_cast<ControlParagraph &>(GuiDialog::controller());
}
ControlPrefs & GuiPrefsDialog::controller() const
{
- return static_cast<ControlPrefs &>(Dialog::controller());
+ return static_cast<ControlPrefs &>(GuiDialog::controller());
}
ControlPrint & GuiPrintDialog::controller() const
{
- return static_cast<ControlPrint &>(Dialog::controller());
+ return static_cast<ControlPrint &>(GuiDialog::controller());
}
ControlRef & GuiRefDialog::controller() const
{
- return static_cast<ControlRef &>(Dialog::controller());
+ return static_cast<ControlRef &>(GuiDialog::controller());
}
bool GuiRefDialog::nameAllowed()
{
- Kernel::DocType const doc_type = kernel().docType();
- return doc_type != Kernel::LATEX &&
- doc_type != Kernel::LITERATE;
+ KernelDocType const doc_type = controller().docType();
+ return doc_type != LATEX && doc_type != LITERATE;
}
bool GuiRefDialog::typeAllowed()
{
- Kernel::DocType const doc_type = kernel().docType();
- return doc_type != Kernel::DOCBOOK;
+ return controller().docType() != DOCBOOK;
}
void GuiRefDialog::gotoRef()
{
- string ref(fromqstr(referenceED->text()));
+ string ref = fromqstr(referenceED->text());
if (at_ref_) {
// go back
ControlSearch & GuiSearchDialog::controller() const
{
- return static_cast<ControlSearch &>(Dialog::controller());
+ return static_cast<ControlSearch &>(GuiDialog::controller());
}
ControlSendto & GuiSendtoDialog::controller() const
{
- return static_cast<ControlSendto &>(Dialog::controller());
+ return static_cast<ControlSendto &>(GuiDialog::controller());
}
ControlShowFile & GuiShowFileDialog::controller() const
{
- return static_cast<ControlShowFile &>(Dialog::controller());
+ return static_cast<ControlShowFile &>(GuiDialog::controller());
}
ControlSpellchecker & GuiSpellcheckerDialog::controller() const
{
- return static_cast<ControlSpellchecker &>(Dialog::controller());
+ return static_cast<ControlSpellchecker &>(GuiDialog::controller());
}
ControlTabular & GuiTabularDialog::controller() const
{
- return static_cast<ControlTabular &>(Dialog::controller());
+ return static_cast<ControlTabular &>(GuiDialog::controller());
}
ControlTabularCreate & GuiTabularCreateDialog::controller() const
{
- return static_cast<ControlTabularCreate &>(Dialog::controller());
+ return static_cast<ControlTabularCreate &>(GuiDialog::controller());
}
ControlTexinfo & GuiTexinfoDialog::controller() const
{
- return static_cast<ControlTexinfo &>(Dialog::controller());
+ return static_cast<ControlTexinfo &>(GuiDialog::controller());
}
ControlThesaurus & GuiThesaurusDialog::controller() const
{
- return static_cast<ControlThesaurus &>(Dialog::controller());
+ return static_cast<ControlThesaurus &>(GuiDialog::controller());
}
void GuiThesaurusDialog::change_adaptor()
ControlCommand & GuiURLDialog::controller() const
{
- return static_cast<ControlCommand &>(Dialog::controller());
+ return static_cast<ControlCommand &>(GuiDialog::controller());
}
ControlVSpace & GuiVSpaceDialog::controller() const
{
- return static_cast<ControlVSpace &>(Dialog::controller());
+ return static_cast<ControlVSpace &>(GuiDialog::controller());
}
ControlWrap & GuiWrapDialog::controller() const
{
- return static_cast<ControlWrap &>(Dialog::controller());
+ return static_cast<ControlWrap &>(GuiDialog::controller());
}
GlueLength gl;
return (isValidGlueLength(text, &gl)) ?
QValidator::Acceptable : QValidator::Intermediate;
- }
+ }
Length l;
bool const valid_length = isValidLength(text, &l);
void PathValidator::setChecker(lyx::frontend::KernelDocType const & type,
LyXRC const & lyxrc)
{
- latex_doc_ = type == lyx::frontend::Kernel::LATEX;
+ latex_doc_ = type == frontend::LATEX;
tex_allows_spaces_ = lyxrc.tex_allows_spaces;
}
#define VALIDATOR_H
#include "Length.h"
+#include "Dialog.h"
#include <QValidator>
// Forward declarations
class LyXRC;
-namespace frontend { class KernelDocType; }
-
-
/** A class to ascertain whether the data passed to the @c validate()
* member function is a valid file path.
* The test is active only when the path is to be stored in a LaTeX