diff --git a/lib/ChangeLog b/lib/ChangeLog index a6e89e98d0..2dcd2e167e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-02-21 Angus Leeming + + * ui/default.ui: use the new 'dialog-show-new-inset "name"' instead + of 'citation-insert', 'reference-insert' and 'bibtex-insert'. + 2003-02-25 Angus Leeming * reLyX/BasicLyX.pm (regularizeLatexLength, getAsLyXLength): diff --git a/lib/ui/default.ui b/lib/ui/default.ui index aa2a363952..979eb0ef0b 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -195,8 +195,8 @@ Menuset Submenu "Math|h" "insert_math" Separator Submenu "Special Character|S" "insert_special" - Item "Citation Reference...|C" "citation-insert" - Item "Cross Reference...|R" "reference-insert" + Item "Citation Reference...|C" "dialog-show-new-inset citation" + Item "Cross Reference...|R" "dialog-show-new-inset ref" Item "Label...|L" "label-insert" Item "Footnote|F" "footnote-insert" Item "Marginal Note|M" "marginalnote-insert" @@ -285,7 +285,7 @@ Menuset Item "Table of Contents|C" "toc-insert" FloatListInsert Item "Index List|I" "index-print" - Item "BibTeX Reference...|B" "bibtex-insert" + Item "BibTeX Reference...|B" "dialog-show-new-inset bibtex" End Menu "insert_file" diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 734dcebeb6..dd0074921b 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -40,8 +40,10 @@ #include "iterators.h" #include "lyxfind.h" +#include "insets/insetbibitem.h" #include "insets/insetbibtex.h" #include "insets/insetcite.h" +#include "insets/insetert.h" #include "insets/insetfloatlist.h" #include "insets/insetgraphics.h" #include "insets/insetinclude.h" @@ -51,6 +53,7 @@ #include "insets/insetref.h" #include "insets/insettext.h" #include "insets/insettoc.h" +#include "insets/inseturl.h" #include "mathed/formulabase.h" @@ -1095,22 +1098,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) MenuInsertLabel(bv_, ev.argument); break; - case LFUN_REF_INSERT: - if (ev.argument.empty()) { - InsetCommandParams p("ref"); - owner_->getDialogs().createRef(p.getAsString()); - } else { - InsetCommandParams p; - p.setFromString(ev.argument); - - InsetRef * inset = new InsetRef(p, *buffer_); - if (!insertInset(inset)) - delete inset; - else - updateInset(inset, true); - } - break; - case LFUN_BOOKMARK_SAVE: savePosition(strToUnsignedInt(ev.argument)); break; @@ -1185,69 +1172,211 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) mathDispatch(FuncRequest(bv_, ev.action, ev.argument)); break; - case LFUN_CITATION_INSERT: - { - InsetCommandParams p; - p.setFromString(ev.argument); + case LFUN_BIBITEM_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); - InsetCitation * inset = new InsetCitation(p); - if (!insertInset(inset)) - delete inset; - else { - inset->setLoadingBuffer(bv_->buffer(), false); - updateInset(inset, true); + InsetBase * base = + owner_->getDialogs().getOpenInset("bibitem"); + InsetBibitem * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + + if (params.getContents() != + inset->params().getContents()) { + bv_->ChangeCitationsIfUnique( + inset->params().getContents(), + params.getContents()); + } + inset->setParams(params); + } else { + inset = new InsetBibitem(params); + if (!insertInset(inset)) { + delete inset; + break; + } + } + updateInset(inset, true); + + // We need to do a redraw because the maximum + // InsetBibitem width could have changed +#warning please check you mean repaint() not update(), +#warning and whether the repaint() is needed at all + bv_->repaint(); + bv_->fitCursor(); + } + break; + + case LFUN_BIBTEX_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); + + InsetBase * base = + owner_->getDialogs().getOpenInset("bibtex"); + InsetBibtex * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + + if (params.getContents() != + inset->params().getContents()) { + bv_->ChangeCitationsIfUnique( + inset->params().getContents(), + params.getContents()); + } + inset->setParams(params); + } else { + inset = new InsetBibtex(params); + if (!insertInset(inset)) { + delete inset; + break; + } + } + updateInset(inset, true); + } + break; + + case LFUN_CITATION_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); + + InsetBase * base = + owner_->getDialogs().getOpenInset("citation"); + InsetCitation * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + + inset->setParams(params); + } else { + inset = new InsetCitation(params); + if (!insertInset(inset)) { + delete inset; + break; + } else { + inset->setLoadingBuffer(bv_->buffer(), false); + } + } + updateInset(inset, true); + } + break; + + case LFUN_ERT_APPLY: { + InsetBase * base = owner_->getDialogs().getOpenInset("ert"); + InsetERT * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + } else { + inset = new InsetERT(bv_->buffer()->params); + if (!insertInset(inset)) { + delete inset; + break; + } } + InsetERT::ERTStatus status; + InsetERTMailer::string2params(ev.argument, status); + + inset->status(bv_, status); + updateInset(inset, true); } break; - case LFUN_INSERT_BIBTEX: - { - // ale970405+lasgoutt970425 - // The argument can be up to two tokens separated - // by a space. The first one is the bibstyle. - string const db = token(ev.argument, ' ', 0); - string bibstyle = token(ev.argument, ' ', 1); - if (bibstyle.empty()) - bibstyle = "plain"; + case LFUN_INDEX_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); - InsetCommandParams p("BibTeX", db, bibstyle); - InsetBibtex * inset = new InsetBibtex(p); + InsetBase * base = owner_->getDialogs().getOpenInset("index"); + InsetIndex * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; - if (insertInset(inset)) { - if (ev.argument.empty()) - inset->edit(bv_); - } else - delete inset; - } - break; - - // BibTeX data bases - case LFUN_BIBDB_ADD: - { - InsetBibtex * inset = - static_cast(getInsetByCode(Inset::BIBTEX_CODE)); - if (inset) { - inset->addDatabase(ev.argument); + inset->setParams(params); + } else { + InsetIndex * inset = new InsetIndex(params); + if (!insertInset(inset)) { + delete inset; + break; + } } + updateInset(inset, true); } break; - case LFUN_BIBDB_DEL: - { - InsetBibtex * inset = - static_cast(getInsetByCode(Inset::BIBTEX_CODE)); - if (inset) - inset->delDatabase(ev.argument); + case LFUN_REF_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); + + InsetBase * base = owner_->getDialogs().getOpenInset("ref"); + InsetRef * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + + inset->setParams(params); + } else { + InsetRef * inset = new InsetRef(params, *buffer_); + if (!insertInset(inset)) { + delete inset; + break; + } + } + updateInset(inset, true); } break; - case LFUN_BIBTEX_STYLE: - { - InsetBibtex * inset = - static_cast(getInsetByCode(Inset::BIBTEX_CODE)); - if (inset) - inset->setOptions(ev.argument); + case LFUN_TOC_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); + + InsetBase * base = owner_->getDialogs().getOpenInset("toc"); + InsetTOC * inset = 0; + if (base) { + InsetTOC * inset = dynamic_cast(base); + if (!inset) + break; + + inset->setParams(params); + } else { + InsetTOC * inset = new InsetTOC(params); + if (!insertInset(inset)) { + delete inset; + break; + } + } + updateInset(inset, true); + } + break; + + case LFUN_URL_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(ev.argument, params); + + InsetBase * base = owner_->getDialogs().getOpenInset("url"); + InsetUrl * inset = 0; + if (base) { + inset = dynamic_cast(base); + if (!inset) + break; + + inset->setParams(params); + } else { + InsetUrl * inset = new InsetUrl(params); + if (!insertInset(inset)) { + delete inset; + break; + } + } + updateInset(inset, true); } break; diff --git a/src/ChangeLog b/src/ChangeLog index 977f127d75..b572a865f5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -4,6 +4,21 @@ * toc.C: make TocItem store an id not a Paragraph * (bug #913) +2003-02-21 Angus Leeming + + * commandtags.h: Retire LFUN_CITATION_INSERT, LFUN_CITATION_CREATE, + LFUN_INSERT_BIBTEX, LFUN_BIBTEX_STYLE, LFUN_BIBDB_ADD, LFUN_BIBDB_DEL. + Bring to life LFUN_DIALOG_SHOW_NEW_INSET, LFUN_DIALOG_SHOW_NEXT_INSET, + LFUN_DIALOG_UPDATE, LFUN_DIALOG_HIDE, LFUN_DIALOG_DISCONNECT_INSET, + LFUN_BIBITEM_APPLY, LFUN_BIBTEX_APPLY, LFUN_CITATION_APPLY, + LFUN_INDEX_APPLY, LFUN_REF_APPLY, LFUN_TOC_APPLY, LFUN_URL_APPLY, + + * BufferView_pimpl.C (dispatch): + * LyXAction.C (init): + * factory.C (createInset): + * lyxfunc.C (getStatus, dispatch): + * text3.C (dispatch): retire old LFUNs and bring new ones to life. + 2003-02-21 Angus Leeming * BufferView_pimpl.C (MenuInsertLyXFile): diff --git a/src/LyXAction.C b/src/LyXAction.C index a1dca28948..15dc26fb4c 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -100,11 +100,6 @@ void LyXAction::init() NoBuffer|ReadOnly }, { LFUN_LEFTSEL, "backward-select", N_("Select previous char"), ReadOnly }, - { LFUN_BIBDB_ADD, "bibtex-database-add", "", Noop }, - { LFUN_BIBDB_DEL, "bibtex-database-del", "", Noop }, - { LFUN_INSERT_BIBTEX, "bibtex-insert", N_("Insert BibTeX"), - Noop }, - { LFUN_BIBTEX_STYLE, "bibtex-style", "", Noop }, { LFUN_BOOKMARK_GOTO, "bookmark-goto", "", ReadOnly }, { LFUN_BOOKMARK_SAVE, "bookmark-save", "", ReadOnly }, { LFUN_BREAKLINE, "break-line", "", Noop }, @@ -151,9 +146,6 @@ void LyXAction::init() ReadOnly }, { LFUN_RIGHT, "char-forward", N_("Go one char forward"), ReadOnly }, - { LFUN_CITATION_CREATE, "citation-insert", - N_("Insert citation"), Noop }, - { LFUN_CITATION_INSERT, "", "internal only", Noop }, { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer }, { LFUN_PREFIX, "command-prefix", N_("Execute command"), NoBuffer }, @@ -245,8 +237,8 @@ void LyXAction::init() Noop }, { LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"), Noop }, - { LFUN_INSERT_BIBITEM, "bibitem-insert", N_("Insert Bibliography Key"), - Noop }, + { LFUN_INSERT_BIBITEM, "bibitem-insert", + N_("Insert Bibliography Key"), Noop }, { LFUN_LANGUAGE, "language", N_("Change language"), Noop }, { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"), ReadOnly }, @@ -416,7 +408,26 @@ void LyXAction::init() { LFUN_ACCEPT_CHANGE, "accept-change", N_("Accept selected change"), Noop }, { LFUN_REJECT_CHANGE, "reject-change", N_("Reject selected change"), Noop }, { LFUN_ACCEPT_ALL_CHANGES, "accept-all-changes", N_("Accept all changes"), Noop }, - { LFUN_REJECT_ALL_CHANGES, "reject-all-changes", N_("Reject all changes"), Noop }, + { LFUN_REJECT_ALL_CHANGES, "reject-all-changes", N_("Reject all changes"), Noop }, + + { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-inset", + N_("Show the inset's dialog"), Noop }, + { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-next-inset", + N_("Show the inset's dialog"), Noop }, + { LFUN_DIALOG_UPDATE, "dialog-update", + N_("Update the dialog"), Noop }, + { LFUN_DIALOG_HIDE, "dialog-hide", + N_("Hide the dialog"), Noop }, + { LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", + N_("Disconnect the dialog from the current inset"), Noop }, + { LFUN_BIBITEM_APPLY, "bibitem-apply", "", Noop }, + { LFUN_BIBTEX_APPLY, "bibtex-apply", "", Noop }, + { LFUN_CITATION_APPLY, "citation-apply", "", Noop }, + { LFUN_ERT_APPLY, "ert-apply", "", Noop }, + { LFUN_INDEX_APPLY, "index-apply", "", Noop }, + { LFUN_REF_APPLY, "ref-apply", "", Noop }, + { LFUN_TOC_APPLY, "toc-apply", "", Noop }, + { LFUN_URL_APPLY, "url-apply", "", Noop }, { LFUN_NOACTION, "", "", Noop } }; diff --git a/src/commandtags.h b/src/commandtags.h index 1216e494d3..571537bd16 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -1,4 +1,4 @@ -// -*- C++ -*- +// -*- C++ --* /* ======================================================================= *\ Docu : To add a new function: - add a new enum constant immediately before LFUN_LASTACTION @@ -190,8 +190,6 @@ enum kb_action { LFUN_MENUNEWTMPLT, // Asger 1997-02-02 LFUN_MENURELOAD, // Asger 1997-02-02 LFUN_RECONFIGURE, // 170 // Asger 1997-02-14 - LFUN_CITATION_INSERT, // AAS 97-02-23 - LFUN_INSERT_BIBTEX, // AAS 97-02-23 LFUN_INDEX_PRINT, // Lgb 97-02-27 LFUN_APROPOS, // Asger 1997-02-27 LFUN_LATEX_LOG, // Lgb 97-04-05 @@ -203,9 +201,6 @@ enum kb_action { LFUN_TOC_INSERT, // Lgb 97-05-27 LFUN_FLOAT_LIST, // Lgb 20010503 LFUN_READ_ONLY_TOGGLE, // Lgb 97-05-27 - LFUN_BIBDB_ADD, // Ale 970530 - LFUN_BIBDB_DEL, // Ale 970530 - LFUN_BIBTEX_STYLE, // 190 // Ale 970530 LFUN_GETTIP, // Ale 970603 LFUN_VC_REGISTER, // Lgb 97-07-01 LFUN_VC_CHECKIN, // Lgb 97-07-01 @@ -258,7 +253,6 @@ enum kb_action { LFUN_INSET_LIST, // Lgb 20000627 LFUN_INSET_THEOREM, // Lgb 20000630 #endif - LFUN_CITATION_CREATE, // 240 // Angus 20000705 LFUN_INSET_CAPTION, // Lgb 20000718 LFUN_SWITCHBUFFER, // and where is this coming from? LFUN_INSERT_URL, // Angus 20000726 @@ -296,7 +290,20 @@ enum kb_action { LFUN_REJECT_CHANGE, // Levon 20021016 LFUN_ACCEPT_ALL_CHANGES, // Levon 20021016 LFUN_REJECT_ALL_CHANGES, // Levon 20021016 - LFUN_INSERT_BIBITEM, // André 14 Feb 2003 + LFUN_INSERT_BIBITEM, // André 14 Feb 2003 + LFUN_DIALOG_SHOW_NEW_INSET, + LFUN_DIALOG_SHOW_NEXT_INSET, + LFUN_DIALOG_UPDATE, + LFUN_DIALOG_HIDE, + LFUN_DIALOG_DISCONNECT_INSET, + LFUN_BIBITEM_APPLY, + LFUN_BIBTEX_APPLY, + LFUN_CITATION_APPLY, + LFUN_ERT_APPLY, + LFUN_INDEX_APPLY, + LFUN_REF_APPLY, + LFUN_TOC_APPLY, + LFUN_URL_APPLY, LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/factory.C b/src/factory.C index 8e032cf51f..c0a8cfab93 100644 --- a/src/factory.C +++ b/src/factory.C @@ -97,17 +97,22 @@ Inset * createInset(FuncRequest const & cmd) return 0; case LFUN_INDEX_INSERT: { - string const entry = cmd.argument.empty() ? - "index" : cmd.argument; - InsetCommandParams icp; - icp.setFromString(entry); + // Try and generate a valid index entry. + InsetCommandParams icp("index"); + string const contents = cmd.argument.empty() ? + bv->getLyXText()->getStringToIndex(bv) : + cmd.argument; + icp.setContents(contents); - if (icp.getContents().empty()) - icp.setContents(bv->getLyXText()->getStringToIndex(bv)); - if (!icp.getContents().empty()) - return new InsetIndex(icp); - - bv->owner()->getDialogs().createIndex(); + string data = InsetCommandMailer::params2string(icp); + LyXView * lv = bv->owner(); + + if (icp.getContents().empty()) { + lv->getDialogs().show("index", data, 0); + } else { + FuncRequest fr(bv, LFUN_INDEX_APPLY, data); + lv->dispatch(fr); + } return 0; } diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 05aed79c94..8a08a03876 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,14 @@ +2003-02-21 Angus Leeming + + * Dialogs.[Ch]: simplify the dialog interface by using a few + methods to do generic things like 'show' a dialog. Individual + dialogs are invoked through a string 'name'. + Use methods 'hideAll' etc to replace signals of the same name: more + transparent code. + + * guiapi.[Ch]: provide a C-interface to the new Dialogs::show + method. Retire the old functions that called dead Dialogs methods. + 2003-02-21 Angus Leeming * Timeout.[Ch]: define a Timeout::Impl abstract base class from diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C index 57b13fe0ec..9d12d28e1c 100644 --- a/src/frontends/Dialogs.C +++ b/src/frontends/Dialogs.C @@ -11,8 +11,11 @@ #include - #include "Dialogs.h" +#include "controllers/Dialog.h" +#include "controllers/ButtonControllerBase.h" +#include + // Note that static boost signals break some compilers, so this wrapper // initialises the signal dynamically when it is first invoked. @@ -39,3 +42,145 @@ boost::signal0 & Dialogs::redrawGUI() static BugfixSignal > thesignal; return thesignal(); } + + +Dialogs::Dialogs(LyXView & lyxview) + : lyxview_(lyxview) +{ + // Connect signals + redrawGUI().connect(boost::bind(&Dialogs::redraw, this)); + + // All this is slated to go + init_pimpl(); + // reduce the number of connections needed in + // dialogs by a simple connection here. + hideAllSignal.connect(hideBufferDependentSignal); +} + + +Dialog * Dialogs::find(string const & name) +{ + if (!isValidName(name)) + return 0; + + std::map::iterator it = + dialogs_.find(name); + + if (it == dialogs_.end()) { + dialogs_[name] = DialogPtr(build(name)); + return dialogs_[name].get(); + } + + return it->second.get(); +} + + +void Dialogs::show(string const & name, string const & data, InsetBase * inset) +{ + Dialog * dialog = find(name); + if (!dialog) + return; + + dialog->show(data); + open_insets_[name] = inset; +} + + +void Dialogs::update(string const & name, string const & data) +{ + Dialog * dialog = find(name); + if (!dialog) + return; + + if (dialog->isVisible()) + dialog->update(data); +} + + +void Dialogs::hide(string const & name) +{ + Dialog * dialog = find(name); + if (!dialog) + return; + + if (dialog->isVisible()) + dialog->hide(); + open_insets_[name] = 0; +} + + +void Dialogs::disconnect(string const & name) +{ + if (!isValidName(name)) + return; + + open_insets_[name] = 0; +} + + +InsetBase * Dialogs::getOpenInset(string const & name) const +{ + if (!isValidName(name)) + return 0; + + std::map::const_iterator it = + open_insets_.find(name); + return it == open_insets_.end() ? 0 : it->second; +} + + +void Dialogs::hideAll() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + it->second->hide(); + } + hideAllSignal(); +} + + +void Dialogs::hideBufferDependent() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * dialog = it->second.get(); + if (dialog->controller().isBufferDependent()) + dialog->hide(); + } + hideBufferDependentSignal(); +} + + +void Dialogs::updateBufferDependent(bool switched) const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * dialog = it->second.get(); + if (switched && dialog->controller().isBufferDependent()) { + dialog->hide(); + } else { + // A bit clunky, but the dialog will request + // that the kernel provides it with the necessary + // data. + dialog->RestoreButton(); + } + } + updateBufferDependentSignal(switched); +} + + +void Dialogs::redraw() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + it->second->redraw(); + } +} diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index dbb20e7645..2e31183cc3 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -19,10 +19,12 @@ #include #include +class Dialog; +class InsetBase; class LyXView; + class InsetCommand; class InsetError; -class InsetERT; class InsetExternal; class InsetFloat; class InsetWrap; @@ -59,46 +61,34 @@ public: /// Are the tooltips on or off? static bool tooltipsEnabled(); - /**@name Global Hide and Update Signals */ + /// Signals slated to go //@{ + boost::signal0 hideAllSignal; + boost::signal0 hideBufferDependentSignal; + boost::signal1 updateBufferDependentSignal; + //@} + /// Hide all visible dialogs - boost::signal0 hideAll; - + void hideAll() const; /// Hide any dialogs that require a buffer for them to operate - boost::signal0 hideBufferDependent; - + void hideBufferDependent() const; /** Update visible, buffer-dependent dialogs If the bool is true then a buffer change has occurred else its still the same buffer. */ - boost::signal1 updateBufferDependent; - //@} + void updateBufferDependent(bool) const ; /**@name Dialog Access Signals. Put into some sort of alphabetical order */ //@{ /// void showAboutlyx(); - /// show the key and label of a bibliography entry - void showBibitem(InsetCommand * ic); - /// show the bibtex dialog - void showBibtex(InsetCommand * ic); /// void showCharacter(); /// connected to the character dialog also void setUserFreeFont(); /// - void showCitation(InsetCommand *); - /// - void createCitation(string const &); - /// void showDocument(); - /// - void showError(InsetError *); - /// - void showERT(InsetERT *); - /// - void updateERT(InsetERT *); /// show the external inset dialog void showExternal(InsetExternal *); /// show the contents of a file. @@ -113,10 +103,6 @@ public: void showGraphics(InsetGraphics *); /// show the details of a LyX file include inset void showInclude(InsetInclude *); - /// - void showIndex(InsetCommand *); - /// - void createIndex(); /// show the LaTeX log or build file void showLogFile(); /// display the top-level maths panel @@ -138,10 +124,6 @@ public: /// void showPrint(); /// - void showRef(InsetCommand *); - /// - void createRef(string const &); - /// void showSearch(); /// void showSendto(); @@ -157,23 +139,54 @@ public: void showTexinfo(); /// show the thesaurus dialog void showThesaurus(string const &); - /// - void showTOC(InsetCommand *); - /// - void createTOC(string const &); - /// - void showUrl(InsetCommand *); - /// - void createUrl(string const &); /// show the version control log void showVCLogFile(); //@} + /** name == "bibtex", "citation" etc + data is generated by the Inset::write method, to be read by the + Inset::read method in the frontends. + inset is stored. On a subsequent Apply from the frontends, the + stored inset will be modified. If no inset is stored, then a + new one will be created at the current cursor position. + */ + void show(string const & name, string const & data, InsetBase * inset); + /** name == "citation", "bibtex" etc. + Update the contents of the dialog. + */ + void update(string const & name, string const & data); + /// + void Dialogs::hide(string const & name); + /// + void disconnect(string const & name); + /// + InsetBase * getOpenInset(string const & name) const; private: - /// Use the Pimpl idiom to hide the internals. + /// + void redraw() const; + /// + bool isValidName(string const & name) const; + /// + Dialog * find(string const & name); + /// + Dialog * build(string const & name); + + /// + LyXView & lyxview_; + /// + std::map open_insets_; + + /// + typedef boost::shared_ptr DialogPtr; + /// + std::map dialogs_; + + /// the stuff below is slated to go... + void init_pimpl(); + /// class Impl; - /// The pointer never changes although *pimpl_'s contents may. - boost::scoped_ptr const pimpl_; + /// + Impl * pimpl_; }; #endif diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 3e6ee386ce..cf63d8c108 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,24 @@ +2003-02-21 Angus Leeming + + * Dialog.[Ch]: + * Kernel.[Ch]: a new, transparent MCV split of the dialogs code. + + * ControlBibitem.[Ch]: + * ControlBibtex.[Ch]: + * ControlCitation.[Ch]: + * ControlCommand.[Ch]: + * ControlError.[Ch]: + * ControlIndex.[Ch]: + * ControlRef.[Ch]: + * ControlToc.[Ch]: + * ControlUrl.[Ch]: New MCV design leads to cleaner code for the + individual controllers too. + Move 'apply' code into the LyX kernel. + + * ControlConnections.C: temporary renaming of Dialogs::signals. + + * Makefile.am: add new files. + 2003-02-21 Angus Leeming * ControlBibtex.C (Browse): diff --git a/src/frontends/controllers/ControlBibitem.C b/src/frontends/controllers/ControlBibitem.C index 896a673db1..42bb262102 100644 --- a/src/frontends/controllers/ControlBibitem.C +++ b/src/frontends/controllers/ControlBibitem.C @@ -11,31 +11,9 @@ #include - #include "ControlBibitem.h" -#include "BufferView.h" -ControlBibitem::ControlBibitem(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d) +ControlBibitem::ControlBibitem(Dialog & d) + : ControlCommand(d, LFUN_BIBITEM_APPLY) {} - - -void ControlBibitem::applyParamsToInset() -{ - // FIXME: - // confirm, is this only necessary for FormBibTeX ??? - if (params().getContents() != inset()->params().getContents()) - bufferview()->ChangeCitationsIfUnique(inset()->params().getContents(), - params().getContents()); - - inset()->setParams(params()); - bufferview()->updateInset(inset(), true); - - // We need to do a redraw because the maximum - // InsetBibKey width could have changed -#warning please check you mean repaint() not update(), -#warning and whether the repaint() is needed at all - bufferview()->repaint(); - bufferview()->fitCursor(); -} diff --git a/src/frontends/controllers/ControlBibitem.h b/src/frontends/controllers/ControlBibitem.h index fa3559d483..226466a27f 100644 --- a/src/frontends/controllers/ControlBibitem.h +++ b/src/frontends/controllers/ControlBibitem.h @@ -21,12 +21,7 @@ class ControlBibitem : public ControlCommand { public: /// - ControlBibitem(LyXView &, Dialogs &); -private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); - /// not needed. - virtual void applyParamsNoInset() {} + ControlBibitem(Dialog &); }; #endif // CONTROLBIBITEM_H diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index e29ff0bc20..7747a78ce6 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -12,44 +12,20 @@ #include - #include "ControlBibtex.h" +#include "Kernel.h" + #include "buffer.h" -#include "BufferView.h" #include "lyxrc.h" #include "helper_funcs.h" #include "tex_helpers.h" #include "gettext.h" -#include "support/lstrings.h" - using std::pair; -ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d) -{} - - - -void ControlBibtex::applyParamsToInset() -{ - if (params().getContents() != inset()->params().getContents()) - bufferview()->ChangeCitationsIfUnique(inset()->params().getContents(), - params().getContents()); - - inset()->setParams(params()); - bufferview()->updateInset(inset(), true); - - // We need to do a redraw because the maximum - // InsetBibKey width could have changed -#warning are you sure you need this repaint() ? - bufferview()->repaint(); - bufferview()->fitCursor(); -} - - -void ControlBibtex::applyParamsNoInset() +ControlBibtex::ControlBibtex(Dialog & d) + : ControlCommand(d, LFUN_BIBTEX_APPLY) {} @@ -59,7 +35,7 @@ string const ControlBibtex::Browse(string const & in_name, { pair dir1(_("Documents|#o#O"), string(lyxrc.document_path)); - return browseRelFile(in_name, buffer()->filePath(), + return browseRelFile(in_name, kernel().buffer()->filePath(), title, pattern, false, dir1); } diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index aee1e5b251..c1449f9115 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -16,12 +16,14 @@ #include "ControlCommand.h" + /** A controller for Bibtex dialogs. */ class ControlBibtex : public ControlCommand { public: /// - ControlBibtex(LyXView &, Dialogs &); + ControlBibtex(Dialog &); + /// Browse for a file string const Browse(string const &, string const &, string const &); /// get the list of bst files @@ -31,11 +33,7 @@ public: /// build filelists of all availabe bib/bst/cls/sty-files. done through /// kpsewhich and an external script, saved in *Files.lst void rescanBibStyles() const; -private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); - /// - virtual void applyParamsNoInset(); }; + #endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 4d0f1c42bd..844375bd04 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -10,8 +10,9 @@ #include - #include "ControlCitation.h" +#include "Kernel.h" + #include "buffer.h" using std::vector; @@ -21,21 +22,17 @@ using std::pair; vector ControlCitation::citeStyles_; -ControlCitation::ControlCitation(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d, LFUN_CITATION_INSERT) +ControlCitation::ControlCitation(Dialog & d) + : ControlCommand(d, LFUN_CITATION_APPLY) {} -void ControlCitation::clearDaughterParams() +void ControlCitation::initialiseParams(string const & data) { - bibkeysInfo_.clear(); -} + ControlCommand::initialiseParams(data); - -void ControlCitation::setDaughterParams() -{ vector > blist; - buffer()->fillWithBibKeys(blist); + kernel().buffer()->fillWithBibKeys(blist); typedef std::map::value_type InfoMapValue; @@ -55,6 +52,14 @@ void ControlCitation::setDaughterParams() } + +void ControlCitation::clearParams() +{ + ControlCommand::clearParams(); + bibkeysInfo_.clear(); +} + + biblio::InfoMap const & ControlCitation::bibkeysInfo() const { return bibkeysInfo_; @@ -63,7 +68,7 @@ biblio::InfoMap const & ControlCitation::bibkeysInfo() const bool ControlCitation::usingNatbib() const { - return buffer()->params.use_natbib; + return kernel().buffer()->params.use_natbib; } @@ -74,7 +79,7 @@ vector const ControlCitation::getCiteStrings(string const & key) const vector const cs = biblio::getCiteStyles(usingNatbib()); - if (buffer()->params.use_numerical_citations) + if (kernel().buffer()->params.use_numerical_citations) styles = biblio::getNumericalStrings(key, bibkeysInfo_, cs); else styles = biblio::getAuthorYearStrings(key, bibkeysInfo_, cs); diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index 451b01e57b..ac51a7fbe4 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -21,7 +21,17 @@ class ControlCitation : public ControlCommand { public: /// - ControlCitation(LyXView &, Dialogs &); + ControlCitation(Dialog &); + + /// + virtual void initialiseParams(string const & data); + /// clean-up on hide. + virtual void clearParams(); + + /** Disconnect from the inset when the Apply button is pressed. + * Allows easy insertion of multiple citations. + */ + virtual bool disconnectOnApply() const { return true; } /// Returns a reference to the map of stored keys biblio::InfoMap const & bibkeysInfo() const; @@ -36,15 +46,6 @@ public: return citeStyles_; } private: - /// create the InfoMap of keys and data - virtual void setDaughterParams(); - /// - virtual void clearDaughterParams(); - - /** disconnect from the inset when the Apply button is pressed. - Allows easy insertion of multiple citations. */ - virtual bool disconnectOnApply() { return true; } - /// The info associated with each key biblio::InfoMap bibkeysInfo_; diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index 054faec3eb..5c632825c2 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -10,44 +10,38 @@ #include - #include "ControlCommand.h" +#include "Kernel.h" -#include "BufferView.h" #include "funcrequest.h" -#include "lyxfunc.h" +#include "insets/insetcommand.h" -ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac) - : ControlInset(lv, d), +ControlCommand::ControlCommand(Dialog & dialog, kb_action ac) + : Dialog::Controller(dialog), action_(ac) {} -InsetCommandParams const ControlCommand::getParams(string const & arg) +void ControlCommand::initialiseParams(string const & data) { - InsetCommandParams params; - params.setFromString(arg); - return params; + InsetCommandMailer::string2params(data, params_); } -InsetCommandParams const ControlCommand::getParams(InsetCommand const & inset) +void ControlCommand::clearParams() { - return inset.params(); + params_.setCmdName(string()); + params_.setOptions(string()); + params_.setContents(string()); } -void ControlCommand::applyParamsToInset() -{ - inset()->setParams(params()); - bufferview()->updateInset(inset(), true); -} - - -void ControlCommand::applyParamsNoInset() +void ControlCommand::dispatchParams() { if (action_ == LFUN_NOACTION) return; - lyxfunc().dispatch(FuncRequest(action_, params().getAsString())); + + FuncRequest fr(action_, InsetCommandMailer::params2string(params_)); + kernel().dispatch(fr); } diff --git a/src/frontends/controllers/ControlCommand.h b/src/frontends/controllers/ControlCommand.h index 9603419cc4..4e9bde7162 100644 --- a/src/frontends/controllers/ControlCommand.h +++ b/src/frontends/controllers/ControlCommand.h @@ -10,41 +10,38 @@ * * ControlCommand is a controller class for dialogs that create or modify * an inset derived from InsetCommand. - * - * The class is likely to be changed as other Inset controllers are created - * and it becomes clear just what functionality can be moved back into - * ControlInset. - * */ #ifndef CONTROLCOMMAND_H #define CONTROLCOMMAND_H -#include "ControlInset.h" -#include "insets/insetcommand.h" +#include "Dialog.h" +#include "insets/insetcommandparams.h" #include "commandtags.h" // kb_action -/** The Inset dialog controller. Connects/disconnects signals, launches - GUI-dependent View and returns the output from this View to the kernel. - */ -class ControlCommand - : public ControlInset -{ + +class ControlCommand : public Dialog::Controller { public: /// - ControlCommand(LyXView &, Dialogs &, kb_action=LFUN_NOACTION); -private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); + ControlCommand(Dialog &, kb_action=LFUN_NOACTION); /// - virtual void applyParamsNoInset(); - /// get the parameters from the string passed to createInset. - virtual InsetCommandParams const getParams(string const &); - /// get the parameters from the inset passed to showInset. - virtual InsetCommandParams const getParams(InsetCommand const &); + InsetCommandParams & params() { return params_; } + /// + InsetCommandParams const & params() const { return params_; } + /// + virtual void initialiseParams(string const & data); + /// clean-up on hide. + virtual void clearParams(); + /// clean-up on hide. + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } - /// Controls what is done in LyXFunc::Dispatch() +private: + /// + InsetCommandParams params_; + /// Flags what action is taken by Kernel::dispatch() kb_action const action_; }; diff --git a/src/frontends/controllers/ControlConnections.C b/src/frontends/controllers/ControlConnections.C index c19c4b31f4..83c42e701a 100644 --- a/src/frontends/controllers/ControlConnections.C +++ b/src/frontends/controllers/ControlConnections.C @@ -125,7 +125,7 @@ ControlConnectBI::ControlConnectBI(LyXView & lv, Dialogs & d) void ControlConnectBI::connect() { - h_ = d_.hideAll.connect(boost::bind(&ControlConnectBI::hide, this)); + h_ = d_.hideAllSignal.connect(boost::bind(&ControlConnectBI::hide, this)); ControlConnectBase::connect(); } @@ -136,9 +136,9 @@ ControlConnectBD::ControlConnectBD(LyXView & lv, Dialogs & d) void ControlConnectBD::connect() { - u_ = d_.updateBufferDependent. + u_ = d_.updateBufferDependentSignal. connect(boost::bind(&ControlConnectBD::updateSlot, this, _1)); - h_ = d_.hideBufferDependent. + h_ = d_.hideBufferDependentSignal. connect(boost::bind(&ControlConnectBD::hide, this)); ControlConnectBase::connect(); } diff --git a/src/frontends/controllers/ControlERT.C b/src/frontends/controllers/ControlERT.C index b0090fa97c..3e64190694 100644 --- a/src/frontends/controllers/ControlERT.C +++ b/src/frontends/controllers/ControlERT.C @@ -11,52 +11,29 @@ #include - #include "ControlERT.h" - -// sorry this is just a temporary hack we should include vspace.h! (Jug) -extern const char * stringFromUnit(int); +#include "funcrequest.h" -ControlERT::ControlERT(LyXView & lv, Dialogs & d) - : ControlInset(lv, d) +ControlERT::ControlERT(Dialog & parent) + : Dialog::Controller(parent), status_(InsetERT::Collapsed) {} -void ControlERT::applyParamsToInset() +void ControlERT::initialiseParams(string const & data) { - inset()->status(bufferview(), params().status); + InsetERTMailer::string2params(data, status_); } -void ControlERT::applyParamsNoInset() +void ControlERT::clearParams() { + status_ = InsetERT::Collapsed; } -ERTParams const ControlERT::getParams(InsetERT const & inset) +void ControlERT::dispatchParams() { - return ERTParams(inset); -} - - -ERTParams::ERTParams() - : status(InsetERT::Collapsed) -{} - - -ERTParams::ERTParams(InsetERT const & inset) - : status(inset.status()) -{} - - -bool operator==(ERTParams const & p1, ERTParams const & p2) -{ - return (p1.status == p2.status); -} - - -bool operator!=(ERTParams const & p1, ERTParams const & p2) -{ - return !(p1 == p2); + FuncRequest fr(LFUN_ERT_APPLY, InsetERTMailer::params2string(status_)); + kernel().dispatch(fr); } diff --git a/src/frontends/controllers/ControlERT.h b/src/frontends/controllers/ControlERT.h index eb6569c1f5..575db4ef38 100644 --- a/src/frontends/controllers/ControlERT.h +++ b/src/frontends/controllers/ControlERT.h @@ -13,47 +13,30 @@ #ifndef CONTROLERT_H #define CONTROLERT_H -#include + +#include "Dialog.h" +#include "insets/insetert.h" // InsetERT::ERTStatus -#include "ControlInset.h" -#include "insets/insetert.h" // InsetERT::Status - -/** This should be moved back into insetert.h and InsetERT should - contain an instance of it. */ - -struct ERTParams { - /// - ERTParams(); - /// - ERTParams(InsetERT const &); - /// - InsetERT::ERTStatus status; -}; - - -/// -bool operator==(ERTParams const &, ERTParams const &); -/// -bool operator!=(ERTParams const &, ERTParams const &); - - -/** A controller for ERT dialogs. - */ -class ControlERT : public ControlInset { +class ControlERT : public Dialog::Controller { public: /// - ControlERT(LyXView &, Dialogs &); -private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); + ControlERT(Dialog &); /// - virtual void applyParamsNoInset(); - /// get the parameters from the string passed to createInset. - virtual ERTParams const getParams(string const &) - { return ERTParams(); } - /// get the parameters from the inset passed to showInset. - virtual ERTParams const getParams(InsetERT const &); + InsetERT::ERTStatus status() const { return status_; } + /// + void setStatus(InsetERT::ERTStatus status) { status_ = status; } + /// + virtual void initialiseParams(string const & data); + /// clean-up on hide. + virtual void clearParams(); + /// clean-up on hide. + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } +private: + /// + InsetERT::ERTStatus status_; }; #endif diff --git a/src/frontends/controllers/ControlError.C b/src/frontends/controllers/ControlError.C index 960bd7d056..fdc0e0f28a 100644 --- a/src/frontends/controllers/ControlError.C +++ b/src/frontends/controllers/ControlError.C @@ -10,17 +10,22 @@ #include - #include "ControlError.h" -#include "insets/inseterror.h" -ControlError::ControlError(LyXView & lv, Dialogs & d) - : ControlInset(lv, d) +ControlError::ControlError(Dialog & parent) + : Dialog::Controller(parent) {} -string const ControlError::getParams(InsetError const & inset) +void ControlError::initialiseParams(string const & data) { - return inset.getContents(); + params_ = data; } + + +void ControlError::clearParams() +{ + params_.clear(); +} + diff --git a/src/frontends/controllers/ControlError.h b/src/frontends/controllers/ControlError.h index 6c9e2f048a..3c9435685f 100644 --- a/src/frontends/controllers/ControlError.h +++ b/src/frontends/controllers/ControlError.h @@ -13,26 +13,28 @@ #define CONTROLERROR_H -#include "ControlInset.h" -#include "insets/inseterror.h" // needed for proper instantiation of GUI<>. +#include "Dialog.h" -class InsetError; -/** A controller for LaTeX Error dialogs. - */ -class ControlError : public ControlInset { +class ControlError : public Dialog::Controller { public: /// - ControlError(LyXView &, Dialogs &); -private: - /// not needed. - virtual void applyParamsToInset() {} + ControlError(Dialog &); /// - virtual void applyParamsNoInset() {} - /// get the parameters from the string passed to createInset. - virtual string const getParams(string const &) { return string(); } - /// get the parameters from the inset passed to showInset. - virtual string const getParams(InsetError const &); + virtual void initialiseParams(string const &); + /// + virtual void clearParams(); + /// + virtual void dispatchParams() {} + /// + virtual bool isBufferDependent() const { return true; } + /// + string & params() { return params_; } + /// + string const & params() const { return params_; } + /// +private: + string params_; }; #endif // CONTROLERROR_H diff --git a/src/frontends/controllers/ControlIndex.C b/src/frontends/controllers/ControlIndex.C index 93871b743a..a80a3b3cce 100644 --- a/src/frontends/controllers/ControlIndex.C +++ b/src/frontends/controllers/ControlIndex.C @@ -14,6 +14,6 @@ #include "ControlIndex.h" -ControlIndex::ControlIndex(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d, LFUN_INDEX_INSERT) +ControlIndex::ControlIndex(Dialog & d) + : ControlCommand(d, LFUN_INDEX_APPLY) {} diff --git a/src/frontends/controllers/ControlIndex.h b/src/frontends/controllers/ControlIndex.h index 95185e21bf..48cc37a780 100644 --- a/src/frontends/controllers/ControlIndex.h +++ b/src/frontends/controllers/ControlIndex.h @@ -20,7 +20,7 @@ class ControlIndex : public ControlCommand { public: /// - ControlIndex(LyXView &, Dialogs &); + ControlIndex(Dialog &); }; #endif // CONTROLINDEX_H diff --git a/src/frontends/controllers/ControlRef.C b/src/frontends/controllers/ControlRef.C index 8e3f7ac16c..a681d7ec64 100644 --- a/src/frontends/controllers/ControlRef.C +++ b/src/frontends/controllers/ControlRef.C @@ -24,8 +24,8 @@ using std::vector; extern BufferList bufferlist; -ControlRef::ControlRef(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d, LFUN_REF_INSERT) +ControlRef::ControlRef(Dialog & d) + : ControlCommand(d, LFUN_REF_APPLY) {} @@ -33,21 +33,21 @@ vector const ControlRef::getLabelList(string const & name) const { Buffer const * buf = bufferlist.getBuffer(MakeAbsPath(name)); if (!buf) - buf = buffer(); + buf = kernel().buffer(); return buf->getLabelList(); } void ControlRef::gotoRef(string const & ref) { - lyxfunc().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"), false); - lyxfunc().dispatch(FuncRequest(LFUN_REF_GOTO, ref)); + kernel().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"), false); + kernel().dispatch(FuncRequest(LFUN_REF_GOTO, ref)); } void ControlRef::gotoBookmark() { - lyxfunc().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"), false); + kernel().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"), false); } @@ -66,7 +66,7 @@ vector const ControlRef::getBufferList() const int ControlRef::getBufferNum() const { vector buffers = bufferlist.getFileNames(); - string const name = buffer()->fileName(); + string const name = kernel().buffer()->fileName(); vector::const_iterator cit = find(buffers.begin(), buffers.end(), name); if (cit == buffers.end()) diff --git a/src/frontends/controllers/ControlRef.h b/src/frontends/controllers/ControlRef.h index 385c9bff00..df13045ec5 100644 --- a/src/frontends/controllers/ControlRef.h +++ b/src/frontends/controllers/ControlRef.h @@ -14,13 +14,15 @@ #include "ControlCommand.h" +#include + /** A controller for the Ref Dialog. */ class ControlRef : public ControlCommand { public: /// - ControlRef(LyXView &, Dialogs &); + ControlRef(Dialog &); /// std::vector const getLabelList(string const &) const; /// @@ -36,7 +38,7 @@ public: private: /** disconnect from the inset when the Apply button is pressed. Allows easy insertion of multiple references. */ - virtual bool disconnectOnApply() { return true; } + virtual bool disconnectOnApply() const { return true; } }; #endif // CONTROLREF_H diff --git a/src/frontends/controllers/ControlToc.C b/src/frontends/controllers/ControlToc.C index 07d9b05ca4..17bf7caf79 100644 --- a/src/frontends/controllers/ControlToc.C +++ b/src/frontends/controllers/ControlToc.C @@ -10,10 +10,7 @@ #include - #include "ControlToc.h" -#include "toc.h" - #include "support/lstrings.h" // tostr using std::vector; @@ -21,20 +18,20 @@ using std::vector; class Buffer; -ControlToc::ControlToc(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d, LFUN_TOC_INSERT) +ControlToc::ControlToc(Dialog & d) + : ControlCommand(d, LFUN_TOC_APPLY) {} -void ControlToc::goTo(toc::TocItem const & item) const +void ControlToc::goTo(toc::TocItem const & item) { - item.goTo(lv_); + item.goTo(kernel().lyxview()); } vector const ControlToc::getTypes() const { - return toc::getTypes(buffer()); + return toc::getTypes(kernel().buffer()); } @@ -43,11 +40,11 @@ toc::Toc const ControlToc::getContents(string const & type) const toc::Toc empty_list; // This shouldn't be possible... - if (!bufferIsAvailable()) { + if (!kernel().isBufferAvailable()) { return empty_list; } - toc::TocList tmp = toc::getTocList(buffer()); + toc::TocList tmp = toc::getTocList(kernel().buffer()); toc::TocList::iterator it = tmp.find(type); if (it == tmp.end()) { return empty_list; diff --git a/src/frontends/controllers/ControlToc.h b/src/frontends/controllers/ControlToc.h index 9615232209..8a236ad25e 100644 --- a/src/frontends/controllers/ControlToc.h +++ b/src/frontends/controllers/ControlToc.h @@ -13,19 +13,19 @@ #define CONTROLTOC_H -#include #include "ControlCommand.h" #include "toc.h" +#include /** A controller for TOC dialogs. */ class ControlToc : public ControlCommand { public: /// - ControlToc(LyXView &, Dialogs &); + ControlToc(Dialog &); /// Goto this paragraph id - void goTo(toc::TocItem const &) const; + void goTo(toc::TocItem const &); /// Return the list of types available std::vector const getTypes() const; diff --git a/src/frontends/controllers/ControlUrl.C b/src/frontends/controllers/ControlUrl.C index 935d4e4e07..c755bc80bf 100644 --- a/src/frontends/controllers/ControlUrl.C +++ b/src/frontends/controllers/ControlUrl.C @@ -14,6 +14,6 @@ #include "ControlUrl.h" -ControlUrl::ControlUrl(LyXView & lv, Dialogs & d) - : ControlCommand(lv, d, LFUN_INSERT_URL) +ControlUrl::ControlUrl(Dialog & d) + : ControlCommand(d, LFUN_URL_APPLY) {} diff --git a/src/frontends/controllers/ControlUrl.h b/src/frontends/controllers/ControlUrl.h index 3e79b862c7..923860f2cf 100644 --- a/src/frontends/controllers/ControlUrl.h +++ b/src/frontends/controllers/ControlUrl.h @@ -21,7 +21,7 @@ class ControlUrl : public ControlCommand { public: /// - ControlUrl(LyXView &, Dialogs &); + ControlUrl(Dialog &); }; #endif // CONTROLURL_H diff --git a/src/frontends/controllers/Dialog.C b/src/frontends/controllers/Dialog.C new file mode 100644 index 0000000000..f75686a950 --- /dev/null +++ b/src/frontends/controllers/Dialog.C @@ -0,0 +1,165 @@ +// -*- C++ -*- +/** + * \file Dialog.C + * 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 + +#include "Dialog.h" + +#include "ButtonControllerBase.h" +#include "support/LAssert.h" + + +Dialog::Dialog(LyXView & lv, string const & name) + : is_closing_(false), kernel_(lv), name_(name) +{} + + +void Dialog::ApplyButton() +{ + apply(); + bc().apply(); +} + + +void Dialog::OKButton() +{ + is_closing_ = true; + apply(); + is_closing_ = false; + hide(); + bc().ok(); +} + + +void Dialog::CancelButton() +{ + hide(); + bc().cancel(); +} + + +void Dialog::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 + // info by calling Dialog::update(). + kernel().updateDialog(name_); + bc().restore(); +} + + +void Dialog::show(string const & data) +{ + if (controller().isBufferDependent() && !kernel().isBufferAvailable()) + return; + + controller().initialiseParams(data); + bc().readOnly(kernel().isBufferReadonly()); + view().show(); + + // The widgets may not be valid, so refresh the button controller + bc().refresh(); +} + + +void Dialog::update(string const & data) +{ + if (controller().isBufferDependent() && !kernel().isBufferAvailable()) + return; + + controller().initialiseParams(data); + + bc().readOnly(kernel().isBufferReadonly()); + view().update(); + + // The widgets may not be valid, so refresh the button controller + bc().refresh(); +} + + +void Dialog::hide() +{ + if (!view().isVisible()) + return; + + controller().clearParams(); + view().hide(); +} + + +void Dialog::apply() +{ + if (kernel().isBufferReadonly()) + return; + + view().apply(); + controller().dispatchParams(); + + if (controller().disconnectOnApply() && !is_closing_) { + kernel().disconnect(name()); + controller().initialiseParams(string()); + view().update(); + } +} + + +bool Dialog::isVisible() const +{ + return view().isVisible(); +} + + +void Dialog::redraw() +{ + view().redraw(); +} + + +ButtonControllerBase & Dialog::bc() const +{ + lyx::Assert(bc_ptr_.get()); + return *bc_ptr_.get(); +} + + +Dialog::Controller & Dialog::controller() const +{ + lyx::Assert(controller_ptr_.get()); + return *controller_ptr_.get(); +} + + +Dialog::View & Dialog::view() const +{ + lyx::Assert(view_ptr_.get()); + return *view_ptr_.get(); +} + + +void Dialog::setButtonController(ButtonControllerBase * bc) +{ + lyx::Assert(bc && !bc_ptr_.get()); + bc_ptr_.reset(bc); +} + + +void Dialog::setController(Controller * i) +{ + lyx::Assert(i && !controller_ptr_.get()); + controller_ptr_.reset(i); +} + + +void Dialog::setView(View * v) +{ + lyx::Assert(v && !view_ptr_.get()); + view_ptr_.reset(v); +} diff --git a/src/frontends/controllers/Dialog.h b/src/frontends/controllers/Dialog.h new file mode 100644 index 0000000000..b61ef4533e --- /dev/null +++ b/src/frontends/controllers/Dialog.h @@ -0,0 +1,201 @@ +// -*- C++ -*- +/** + * \file Dialog.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 + * + * The dialogs use a Model-Controller-View split, instantiated here + * by class Dialog. + */ + +#ifndef DIALOG_H +#define DIALOG_H + + +#include "Kernel.h" +#include "LString.h" +#include +#include + + +class LyXView; +class ButtonControllerBase; + + +class Dialog : boost::noncopyable { +public: + /** the Dialog's "name" is the means with which a dialog identifies + * itself to the kernel. + */ + Dialog(LyXView &, string const & name); + + /// + string const & name() const { return name_; } + + /** These methods are publicly accessible because they are invoked + by the View. + */ + //@{ + /// + void ApplyButton(); + /// + void OKButton(); + /// + void CancelButton(); + /// + void RestoreButton(); + //@} + + /** These methods are publicly accessible because they are invoked + * by the Dialogs class. + */ + //@{ + /** Some dialogs, eg the Tabular or Preferences dialog, can extract + the information they require from the kernel. These dialogs will + probably be passed an empty string by the calling Dialogs class. + The inset dialogs, however, require information specific to + an individual inset. This information will be encoded in "data" + and must be translated into a set of parameters that can be + updated from the dialog. + */ + void show(string const & data = string()); + /// + void update(string const & data = string()); + /// + void hide(); + /// + bool isVisible() const; + /// (Eg, the GUI colours have been changed.) + void redraw(); + //@} + + /** 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. + Kernel & kernel() { return kernel_; } + + /** Different dialogs will have different + Controllers, Views and ButtonControllers. + */ + //@{ + /// + class Controller; + /// + class View; + + /// + void setController(Controller *); + /// + void setView(View *); + /// + void setButtonController(ButtonControllerBase *); + + /// + Controller & controller() const; + /// + ButtonControllerBase & bc() const; +private: + /// + View & view() const; + //@} + + /// + void apply(); + + /// + bool is_closing_; + /// + Kernel kernel_; + /// + string name_; + /// + boost::scoped_ptr bc_ptr_; + /// + boost::scoped_ptr controller_ptr_; + /// + boost::scoped_ptr view_ptr_; +}; + + +class Dialog::Controller : boost::noncopyable { +public: + /// + Controller(Dialog & parent) : parent_(parent) {} + /// + virtual ~Controller() {} + /// + virtual void initialiseParams(string const & data) = 0; + /// + virtual void clearParams() = 0; + /// + virtual void dispatchParams() = 0; + /// + virtual bool isBufferDependent() const = 0; + /// + virtual bool disconnectOnApply() const { return false; } + /// + Kernel & kernel() { return parent_.kernel(); } + /// + Kernel const & kernel() const { return parent_.kernel(); } + +private: + /// + Dialog & parent_; +}; + + +class Dialog::View : boost::noncopyable { +public: + /// + View(Dialog & parent) : p_(parent) {} + /// + virtual ~View() {} + + /// Apply changes to LyX data from dialog. + virtual void apply() = 0; + /// Hide the dialog. + virtual void hide() = 0; + /// Redraw the dialog (e.g. if the colors have been remapped). + virtual void redraw() {} + /// Create the dialog if necessary, update it and display it. + virtual void show() = 0; + /// Update dialog before/whilst showing it. + virtual void update() = 0; + /// + virtual bool isVisible() const = 0; + + /** 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. + */ + virtual void partialUpdate(int) {} + + /// + Dialog & dialog() { return p_; } + /// + Dialog const & dialog() const { return p_; } + + /// + Kernel & kernel() { return p_.kernel(); } + /// + Kernel const & kernel() const { return p_.kernel(); } + + /// + Controller & getController() { return p_.controller(); } + /// + Controller const & getController() const { return p_.controller(); } + +protected: + /// + Dialog & p_; +}; + + +#endif // DIALOG_H diff --git a/src/frontends/controllers/Kernel.C b/src/frontends/controllers/Kernel.C new file mode 100644 index 0000000000..99a1b81f97 --- /dev/null +++ b/src/frontends/controllers/Kernel.C @@ -0,0 +1,84 @@ +#include "Kernel.h" + +#include "buffer.h" +#include "BufferView.h" +#include "funcrequest.h" +#include "lyxfunc.h" +#include "frontends/Dialogs.h" +#include "frontends/LyXView.h" + +Kernel::Kernel(LyXView & lyxview) + : lyxview_(lyxview) +{} + + +void Kernel::dispatch(FuncRequest const & fr, bool verbose) const +{ + lyxview_.getLyXFunc().dispatch(fr, verbose); +} + + +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 +{ + if (!lyxview_.view().get()) + return false; + return lyxview_.view()->available(); +} + + +bool Kernel::isBufferReadonly() const +{ + if (!lyxview_.buffer()) + return true; + return lyxview_.buffer()->isReadonly(); +} + + +Kernel::DocTypes Kernel::docType() const +{ + if (!buffer()) + return LATEX; + + if (buffer()->isLatex()) + return LATEX; + if (buffer()->isLiterate()) + return LITERATE; + if (buffer()->isLinuxDoc()) + return LINUXDOC; + + return DOCBOOK; +} + +BufferView * Kernel::bufferview() +{ + return lyxview_.view().get(); +} + + +BufferView const * Kernel::bufferview() const +{ + return lyxview_.view().get(); +} + + +Buffer * Kernel::buffer() +{ + return lyxview_.buffer(); +} + + +Buffer const * Kernel::buffer() const +{ + return lyxview_.buffer(); +} diff --git a/src/frontends/controllers/Kernel.h b/src/frontends/controllers/Kernel.h new file mode 100644 index 0000000000..1d7d1436b8 --- /dev/null +++ b/src/frontends/controllers/Kernel.h @@ -0,0 +1,65 @@ +// -*- C++ -*- + +#ifndef KERNEL_H +#define KERNEL_H + + +#include "LString.h" + + +class Buffer; +class BufferView; +class FuncRequest; +class LyXView; + + +class Kernel { +public: + /// + enum DocTypes { + /// + LATEX, + /// + LITERATE, + /// + LINUXDOC, + /// + DOCBOOK + }; + + /// + Kernel(LyXView &); + /// + void dispatch(FuncRequest const &, bool verbose = false) const; + /** The Dialog has received a request from the user to update + its contents. It must, therefore, ask the kernel to provide + this information to Dialog 'name'. + */ + void updateDialog(string const & name) const; + /// + void disconnect(string const & name) const; + /// + bool isBufferAvailable() const; + /// + bool isBufferReadonly() const; + /// + DocTypes docType() const; + /// + 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_; +}; + + +#endif // KERNEL_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 437b524a75..de72b27498 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -8,6 +8,10 @@ INCLUDES = -I$(top_srcdir)/src \ EXTRA_DIST = ButtonController.tmpl ControlDialog.tmpl ControlInset.tmpl libcontrollers_la_SOURCES= \ + Dialog.C \ + Dialog.h \ + Kernel.C \ + Kernel.h \ biblio.C \ biblio.h \ character.C \ diff --git a/src/frontends/gnome/Dialogs.C b/src/frontends/gnome/Dialogs.C index 06c44f0520..acb9a8048d 100644 --- a/src/frontends/gnome/Dialogs.C +++ b/src/frontends/gnome/Dialogs.C @@ -12,52 +12,32 @@ #include - #include "Dialogs_impl.h" -Dialogs::Dialogs(LyXView & lv) - : pimpl_(new Impl(lv, *this)) + +void Dialogs::init_pimpl() { - // reduce the number of connections needed in - // dialogs by a simple connection here. - hideAll.connect(hideBufferDependent); + pimpl_ = new Impl(lyxview_, *this); } Dialogs::~Dialogs() -{} - - -void Dialogs::toggleTooltips() { - Tooltips::toggleEnabled(); -} - - -/// Are the tooltips on or off? -bool Dialogs::tooltipsEnabled() -{ - return Tooltips::enabled(); + delete pimpl_; } Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) : aboutlyx(lv, d), - bibitem(lv, d), - bibtex(lv, d), character(lv, d), changes(lv, d), - citation(lv, d), document(lv, d), - error(lv, d), - ert(lv, d), external(lv, d), file(lv, d), floats(lv, d), forks(lv, d), graphics(lv, d), include(lv, d), - index(lv, d), logfile(lv, d), mathpanel(lv, d), minipage(lv, d), @@ -65,7 +45,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) preamble(lv, d), preferences(lv, d), print(lv, d), - ref(lv, d), search(lv, d), sendto(lv, d), spellchecker(lv, d), @@ -76,8 +55,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) thesaurus(lv, d), #endif - toc(lv, d), - url(lv, d), vclogfile(lv, d), wrap(lv, d) {} diff --git a/src/frontends/gnome/Dialogs2.C b/src/frontends/gnome/Dialogs2.C index b9b7605b31..858db6dea4 100644 --- a/src/frontends/gnome/Dialogs2.C +++ b/src/frontends/gnome/Dialogs2.C @@ -21,18 +21,6 @@ void Dialogs::showAboutlyx() } -void Dialogs::showBibitem(InsetCommand * ic) -{ - pimpl_->bibitem.controller().showInset(ic); -} - - -void Dialogs::showBibtex(InsetCommand * ic) -{ - pimpl_->bibtex.controller().showInset(ic); -} - - void Dialogs::showCharacter() { pimpl_->character.controller().show(); @@ -45,42 +33,12 @@ void Dialogs::setUserFreeFont() } -void Dialogs::showCitation(InsetCommand * ic) -{ - pimpl_->citation.controller().showInset(ic); -} - - -void Dialogs::createCitation(string const & s) -{ - pimpl_->citation.controller().createInset(s); -} - - void Dialogs::showDocument() { pimpl_->document.controller().show(); } -void Dialogs::showError(InsetError * ie) -{ - pimpl_->error.controller().showInset(ie); -} - - -void Dialogs::showERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - -void Dialogs::updateERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - void Dialogs::showExternal(InsetExternal * ie) { pimpl_->external.controller().showInset(ie); @@ -117,18 +75,6 @@ void Dialogs::showInclude(InsetInclude * ii) } -void Dialogs::showIndex(InsetCommand * ic) -{ - pimpl_->index.controller().showInset(ic); -} - - -void Dialogs::createIndex() -{ - pimpl_->index.controller().createInset(string()); -} - - void Dialogs::showLogFile() { pimpl_->logfile.controller().show(); @@ -187,18 +133,6 @@ void Dialogs::showPrint() } -void Dialogs::showRef(InsetCommand * ic) -{ - pimpl_->ref.controller().showInset(ic); -} - - -void Dialogs::createRef(string const & s) -{ - pimpl_->ref.controller().createInset(s); -} - - void Dialogs::showSearch() { pimpl_->search.controller().show(); @@ -256,30 +190,6 @@ void Dialogs::showThesaurus(string const &) #endif -void Dialogs::showTOC(InsetCommand * ic) -{ - pimpl_->toc.controller().showInset(ic); -} - - -void Dialogs::createTOC(string const & s) -{ - pimpl_->toc.controller().createInset(s); -} - - -void Dialogs::showUrl(InsetCommand * ic) -{ - pimpl_->url.controller().showInset(ic); -} - - -void Dialogs::createUrl(string const & s) -{ - pimpl_->url.controller().createInset(s); -} - - void Dialogs::showVCLogFile() { pimpl_->vclogfile.controller().show(); diff --git a/src/frontends/gnome/Dialogs3.C b/src/frontends/gnome/Dialogs3.C new file mode 100644 index 0000000000..44d8a0f701 --- /dev/null +++ b/src/frontends/gnome/Dialogs3.C @@ -0,0 +1,150 @@ +/** + * \file qt2/Dialogs3.C + * 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 + +#include "Dialogs.h" +#include "Dialog.h" + +#include "ControlBibitem.h" +#include "ControlBibtex.h" +#include "ControlCitation.h" +#include "ControlError.h" +#include "ControlERT.h" +#include "ControlIndex.h" +#include "ControlRef.h" +#include "ControlToc.h" +#include "ControlUrl.h" + +#include "FormBibitem.h" +#include "forms/form_bibitem.h" + +#include "FormBibtex.h" +#include "forms/form_bibtex.h" + +#include "FormCitation.h" +#include "forms/form_citation.h" + +#include "GError.h" +#include "GERT.h" + +#include "FormIndex.h" +#include "forms/form_index.h" + +#include "FormRef.h" +#include "forms/form_ref.h" + +#include "FormToc.h" +#include "forms/form_toc.h" + +#include "GUrl.h" + +#include "gnomeBC.h" +#include "ButtonController.h" + + +typedef ButtonController + OkCancelBC; + +typedef ButtonController + OkCancelReadOnlyBC; + +typedef ButtonController + NoRepeatedApplyReadOnlyBC; + + +namespace { + +char const * const dialognames[] = { "bibitem", "bibtex", "citation", + "error", "ert", "index", "ref", + "toc", "url" }; + +char const * const * const end_dialognames = + dialognames + (sizeof(dialognames) / sizeof(char *)); + +struct cmpCStr { + cmpCStr(char const * name) : name_(name) {} + bool operator()(char const * other) { + return strcmp(other, name_) == 0; + } +private: + char const * name_; +}; + + +} // namespace anon + + +bool Dialogs::isValidName(string const & name) const +{ + return std::find_if(dialognames, end_dialognames, + cmpCStr(name.c_str())) != end_dialognames; +} + + +Dialog * Dialogs::build(string const & name) +{ + if (!isValidName(name)) + return 0; + + Dialog * dialog = new Dialog(lyxview_, name); + + if (name == "bibitem") { + dialog->setController(new ControlBibitem(*dialog)); + dialog->setView(new FormBibitem(*dialog)); + dialog->setButtonController(new OkCancelReadOnlyBC); + } else if (name == "bibtex") { + dialog->setController(new ControlBibtex(*dialog)); + dialog->setView(new FormBibtex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "citation") { + dialog->setController(new ControlCitation(*dialog)); + dialog->setView(new FormCitation(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "error") { + dialog->setController(new ControlError(*dialog)); + dialog->setView(new GError(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "ert") { + dialog->setController(new ControlERT(*dialog)); + dialog->setView(new GERT(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "index") { + dialog->setController(new ControlIndex(*dialog)); + dialog->setView(new FormIndex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "ref") { + dialog->setController(new ControlRef(*dialog)); + dialog->setView(new FormRef(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "toc") { + dialog->setController(new ControlToc(*dialog)); + dialog->setView(new FormToc(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "url") { + dialog->setController(new ControlUrl(*dialog)); + dialog->setView(new GURL(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } + + return dialog; +} + + +void Dialogs::toggleTooltips() +{ + Tooltips::toggleEnabled(); +} + + +bool Dialogs::tooltipsEnabled() +{ + return Tooltips::enabled(); +} diff --git a/src/frontends/gnome/Dialogs_impl.h b/src/frontends/gnome/Dialogs_impl.h index 6583aa71d4..09e0783dd1 100644 --- a/src/frontends/gnome/Dialogs_impl.h +++ b/src/frontends/gnome/Dialogs_impl.h @@ -22,14 +22,6 @@ #include "ControlAboutlyx.h" #include "GAbout.h" -#include "ControlBibitem.h" -#include "FormBibitem.h" -#include "forms/form_bibitem.h" - -#include "ControlBibtex.h" -#include "FormBibtex.h" -#include "forms/form_bibtex.h" - #include "FormBrowser.h" #include "forms/form_browser.h" @@ -37,10 +29,6 @@ #include "FormCharacter.h" #include "forms/form_character.h" -#include "ControlCitation.h" -#include "FormCitation.h" -#include "forms/form_citation.h" - #include "ControlChanges.h" #include "GChanges.h" @@ -157,31 +145,16 @@ typedef GUI AboutlyxDialog; -typedef GUI -BibitemDialog; - -typedef GUI -BibtexDialog; - typedef GUI CharacterDialog; typedef GUI ChangesDialog; -typedef GUI -CitationDialog; - typedef GUI DocumentDialog; -typedef GUI -ErrorDialog; - -typedef GUI -ERTDialog; - -typedef GUI +ypedef GUI ExternalDialog; typedef GUI @@ -199,9 +172,6 @@ GraphicsDialog; typedef GUI IncludeDialog; -typedef GUI -IndexDialog; - typedef GUI LogFileDialog; @@ -223,9 +193,6 @@ PreferencesDialog; typedef GUI PrintDialog; -typedef GUI -RefDialog; - typedef GUI SearchDialog; @@ -249,12 +216,6 @@ typedef GUI -TocDialog; - -typedef GUI -UrlDialog; - typedef GUI VCLogFileDialog; @@ -265,21 +226,15 @@ struct Dialogs::Impl { Impl(LyXView & lv, Dialogs & d); AboutlyxDialog aboutlyx; - BibitemDialog bibitem; - BibtexDialog bibtex; CharacterDialog character; ChangesDialog changes; - CitationDialog citation; DocumentDialog document; - ErrorDialog error; - ERTDialog ert; ExternalDialog external; FileDialog file; FloatDialog floats; ForksDialog forks; GraphicsDialog graphics; IncludeDialog include; - IndexDialog index; LogFileDialog logfile; MathPanelDialog mathpanel; MinipageDialog minipage; @@ -287,7 +242,6 @@ struct Dialogs::Impl { PreambleDialog preamble; PreferencesDialog preferences; PrintDialog print; - RefDialog ref; SearchDialog search; SendtoDialog sendto; SpellcheckerDialog spellchecker; @@ -299,8 +253,6 @@ struct Dialogs::Impl { ThesaurusDialog thesaurus; #endif - TocDialog toc; - UrlDialog url; VCLogFileDialog vclogfile; WrapDialog wrap; }; diff --git a/src/frontends/gnome/GError.C b/src/frontends/gnome/GError.C index 1284f59d26..291a48341f 100644 --- a/src/frontends/gnome/GError.C +++ b/src/frontends/gnome/GError.C @@ -19,7 +19,7 @@ #include GErrorDialog::GErrorDialog() - : GnomeCB("GError") + : GControlledView("GError") {} diff --git a/src/frontends/gnome/GError.h b/src/frontends/gnome/GError.h index 2668f73f50..3876223125 100644 --- a/src/frontends/gnome/GError.h +++ b/src/frontends/gnome/GError.h @@ -15,7 +15,7 @@ #include "ControlError.h" -#include "GnomeBase.h" +#include "GView.h" namespace Gtk { @@ -27,7 +27,7 @@ class TextView; /** * This class implements the dialog to show error messages. */ -class GErrorDialog : public GnomeCB { +class GErrorDialog : public GControlledView { public: /// GErrorDialog(); diff --git a/src/frontends/gnome/GUrl.C b/src/frontends/gnome/GUrl.C index 487ce7a26f..ecadf760aa 100644 --- a/src/frontends/gnome/GUrl.C +++ b/src/frontends/gnome/GUrl.C @@ -20,7 +20,7 @@ #include GUrl::GUrl() - : GnomeCB("GUrl") + : GControlledView("GUrl") {} diff --git a/src/frontends/gnome/GUrl.h b/src/frontends/gnome/GUrl.h index da046aa232..35fa696ccc 100644 --- a/src/frontends/gnome/GUrl.h +++ b/src/frontends/gnome/GUrl.h @@ -15,7 +15,7 @@ #include "ControlUrl.h" -#include "GnomeBase.h" +#include "GView.h" namespace Gtk { class Button; @@ -26,7 +26,7 @@ class Entry; /** * This class implements the dialog to insert/modify urls. */ -class GUrl : public GnomeCB { +class GUrl : public GControlledView { public: /// GUrl(); diff --git a/src/frontends/gnome/GView.C b/src/frontends/gnome/GView.C new file mode 100644 index 0000000000..57f72d7a1a --- /dev/null +++ b/src/frontends/gnome/GView.C @@ -0,0 +1,118 @@ +/** + * \file GView.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Baruch Even + * + * Full author contact details are available in file CREDITS + */ + + +#include +#include "GView.h" +#include "support/LAssert.h" +#include "debug.h" +#include "support/filetools.h" +#include "ControlButtons.h" +#include +#include + +GView::GView(string const & name) + : ViewBase(), + updating_(false), + file_(name + ".glade"), + title_(name), + widget_name_(name), + xml_(0), + dialog_(0) +{ + loadXML(); +} + +GView::~GView() +{} + +gnomeBC & GView::bc() +{ + return static_cast(getController().bc()); +} + +void GView::loadXML() +{ +#ifdef WITH_WARNINGS +#warning Change this before declaring it production code! (be 20010325) +#endif + string const path("src/frontends/gnome/dialogs/;frontends/gnome/dialogs/;"); + + string const file = FileOpenSearch(path, file_, "glade"); + + if (file.empty()) { + lyxerr << "Cannot find glade file. Aborting." << std::endl; + lyx::Assert(true); + } + + lyxerr[Debug::GUI] << "Glade file to open is " << file << '\n'; + + xml_ = Gnome::Glade::Xml::create (file, widget_name_); +} + + +void GView::show() +{ + update(); + dialog()->show(); +} + + +void GView::hide() +{ + dialog()->hide(); +} + +bool GView::isValid() +{ + return true; +} + +void GView::OKClicked() +{ + lyxerr[Debug::GUI] << "GView::OKClicked()\n"; + getController().OKButton(); +} + +void GView::CancelClicked() +{ + lyxerr[Debug::GUI] << "GView::CancelClicked()\n"; + getController().CancelButton(); +} + +void GView::ApplyClicked() +{ + lyxerr[Debug::GUI] << "GView::ApplyClicked()\n"; + getController().ApplyButton(); +} + +void GView::RestoreClicked() +{ + lyxerr[Debug::GUI] << "GView::RestoreClicked()\n"; + getController().RestoreButton(); +} + +void GView::InputChanged() +{ + bc().valid(isValid()); +} + +Gtk::Dialog * GView::dialog() +{ + if (!dialog_) + dialog_ = getWidget(widget_name_); + + return dialog_; +} + +bool GView::isVisible() const +{ + return dialog_ && dialog_->is_visible(); +} diff --git a/src/frontends/gnome/GView.h b/src/frontends/gnome/GView.h new file mode 100644 index 0000000000..50459b8b8b --- /dev/null +++ b/src/frontends/gnome/GView.h @@ -0,0 +1,131 @@ +// -*- C++ -*- +/** + * \file GView.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Baruch Even + * + * Full author contact details are available in file CREDITS + */ + +#ifndef GView_H +#define GView_H + + +#include "gnome_helpers.h" + +#include +#include + +#include "ViewBase.h" +#include "gnomeBC.h" + +namespace Gtk { + class Dialog; +}; + +/** + * This is a base class for Gnome dialogs. It handles all the common + * work that is needed for all dialogs. + */ +class GView : public ViewBase, public SigC::Object { +public: + /// + GView(string const & name); + /// + virtual ~GView(); + +protected: + /// Get the widget named 'name' from the xml representation. + template + T* getWidget(const string & name) const; + + /// Get the dialog we use. + Gtk::Dialog * dialog(); + + /// Show the dialog. + void show(); + /// Hide the dialog. + void hide(); + /// Build the dialog. Also connects signals and prepares it for work. + virtual void build() = 0; + /// Dialog is valid + virtual bool isValid(); + /// dialog is visible + virtual bool isVisible() const; + /// Default OK behaviour + virtual void OKClicked(); + /// Default Cancel behaviour + virtual void CancelClicked(); + /// Default Restore behaviour + virtual void RestoreClicked(); + /// Default apply behaviour + virtual void ApplyClicked(); + /// Default changed input behaviour + virtual void InputChanged(); + + /// + gnomeBC & bc(); + + /// are we updating ? + bool updating_; +private: + /// Loads the glade file to memory. + void loadXML(); + + /// The glade file name + const string file_; + /// The widget name + const string widget_name_; + /// The XML representation of the dialogs. + Glib::RefPtr xml_; + + /** The dialog we work with, since it is managed by libglade, we do not + * need to delete it or destroy it, it will be destroyed with the rest + * of the libglade GladeXML structure. + */ + Gtk::Dialog * dialog_; + + /// dialog title, displayed by WM. + string title_; +}; + + +template +T* GView::getWidget(const string & name) const +{ + return dynamic_cast(xml_->get_widget(name)); +} + +/** + * This class is used to provide a simple automatic casting of the controller. + * We chose not to make GView a template since it has some size and we + * have no reason to duplicate it by making it a template. + * + * Basically the GControlledView template instantiates GView and + * passes the parameters to it and it also adds the controller() method to + * give us a reference to the controller of the correct type (the type is + * set by the template parameter). +*/ +template +class GControlledView : public GView { +public: + GControlledView(string const & name); +protected: + Controller & controller(); +}; + +template +GControlledView::GControlledView(string const & name) + : GView(name) +{} + +template +Controller & +GControlledView::controller() +{ + return static_cast(getController()); +} + +#endif diff --git a/src/frontends/gnome/Makefile.am b/src/frontends/gnome/Makefile.am index aacdb81fbc..02531bfc54 100644 --- a/src/frontends/gnome/Makefile.am +++ b/src/frontends/gnome/Makefile.am @@ -23,6 +23,7 @@ xforms_objects = \ ../xforms/FontInfo.lo \ ../xforms/FormAboutlyx.lo \ ../xforms/FormBase.lo \ + ../xforms/FormDialogView.lo \ ../xforms/FormBibitem.lo \ ../xforms/FormBibtex.lo \ ../xforms/FormBrowser.lo \ @@ -149,6 +150,8 @@ libgnome_la_SOURCES = \ gnome_helpers.h \ GnomeBase.C \ GnomeBase.h \ + GView.C \ + GView.h \ gnomeBC.C \ gnomeBC.h \ lyx_gui.C \ diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index 2528efed49..876e532308 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -11,30 +11,22 @@ #include - #include "guiapi.h" #include "Dialogs.h" extern "C" { +void gui_show_dialog(Dialogs * d, char const * name, char const * data) +{ + d->show(name, data, 0); +} + void gui_ShowAboutlyx(Dialogs & d) { d.showAboutlyx(); } -void gui_ShowBibitem(InsetCommand * ic, Dialogs & d) -{ - d.showBibitem(ic); -} - - -void gui_ShowBibtex(InsetCommand * ic, Dialogs & d) -{ - d.showBibtex(ic); -} - - void gui_ShowCharacter(Dialogs & d) { d.showCharacter(); @@ -47,42 +39,12 @@ void gui_SetUserFreeFont(Dialogs & d) } -void gui_ShowCitation(InsetCommand * ic, Dialogs & d) -{ - d.showCitation(ic); -} - - -void gui_CreateCitation(string const & s, Dialogs & d) -{ - d.createCitation(s); -} - - void gui_ShowDocument(Dialogs & d) { d.showDocument(); } -void gui_ShowError(InsetError * ie, Dialogs & d) -{ - d.showError(ie); -} - - -void gui_ShowERT(InsetERT * ie, Dialogs & d) -{ - d.showERT(ie); -} - - -void gui_UpdateERT(InsetERT * ie, Dialogs & d) -{ - d.updateERT(ie); -} - - void gui_ShowExternal(InsetExternal * ie, Dialogs & d) { d.showExternal(ie); @@ -100,6 +62,7 @@ void gui_ShowFloat(InsetFloat * ifl, Dialogs & d) d.showFloat(ifl); } + void gui_ShowWrap(InsetWrap * iw, Dialogs & d) { d.showWrap(iw); @@ -123,18 +86,6 @@ void gui_ShowInclude(InsetInclude * ii, Dialogs & d) } -void gui_ShowIndex(InsetCommand * ic, Dialogs & d) -{ - d.showIndex(ic); -} - - -void gui_CreateIndex(Dialogs & d) -{ - d.createIndex(); -} - - void gui_ShowLogFile(Dialogs & d) { d.showLogFile(); @@ -189,18 +140,6 @@ void gui_ShowPrint(Dialogs & d) } -void gui_ShowRef(InsetCommand * ic, Dialogs & d) -{ - d.showRef(ic); -} - - -void gui_CreateRef(string const & s, Dialogs & d) -{ - d.createRef(s); -} - - void gui_ShowSearch(Dialogs & d) { d.showSearch(); @@ -249,30 +188,6 @@ void gui_ShowThesaurus(string const & s, Dialogs & d) } -void gui_ShowTOC(InsetCommand * ic, Dialogs & d) -{ - d.showTOC(ic); -} - - -void gui_CreateTOC(string const & s, Dialogs & d) -{ - d.createTOC(s); -} - - -void gui_ShowUrl(InsetCommand * ic, Dialogs & d) -{ - d.showUrl(ic); -} - - -void gui_CreateUrl(string const & s, Dialogs & d) -{ - d.createUrl(s); -} - - void gui_ShowVCLogFile(Dialogs & d) { d.showVCLogFile(); diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index 7e779dacd3..7763e6a726 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -16,9 +16,6 @@ #include "LString.h" class Dialogs; -class InsetCommand; -class InsetError; -class InsetERT; class InsetExternal; class InsetFloat; class InsetWrap; @@ -29,26 +26,18 @@ class InsetTabular; extern "C" { +void gui_show_dialog(Dialogs *, char const * name, char const * data); + void gui_ShowAboutlyx(Dialogs &); -void gui_ShowBibitem(InsetCommand *, Dialogs &); -void gui_ShowBibtex(InsetCommand *, Dialogs &); void gui_ShowCharacter(Dialogs &); void gui_SetUserFreeFont(Dialogs &); -void gui_ShowCitation(InsetCommand *, Dialogs &); -void gui_CreateCitation(string const &, Dialogs &); void gui_ShowDocument(Dialogs &); -void gui_ShowError(InsetError *, Dialogs &); -void gui_ShowERT(InsetERT *, Dialogs &); -void gui_UpdateERT(InsetERT *, Dialogs &); void gui_ShowExternal(InsetExternal *, Dialogs &); void gui_ShowFile(string const &, Dialogs &); void gui_ShowFloat(InsetFloat *, Dialogs &); -void gui_ShowWrap(InsetWrap *, Dialogs &); void gui_ShowForks(Dialogs &); void gui_ShowGraphics(InsetGraphics *, Dialogs &); void gui_ShowInclude(InsetInclude *, Dialogs &); -void gui_ShowIndex(InsetCommand *, Dialogs &); -void gui_CreateIndex(Dialogs &); void gui_ShowLogFile(Dialogs &); void gui_ShowMathPanel(Dialogs &); void gui_ShowMinipage(InsetMinipage *, Dialogs &); @@ -58,8 +47,6 @@ void gui_UpdateParagraph(Dialogs &); void gui_ShowPreamble(Dialogs &); void gui_ShowPreferences(Dialogs &); void gui_ShowPrint(Dialogs &); -void gui_ShowRef(InsetCommand *, Dialogs &); -void gui_CreateRef(string const &, Dialogs &); void gui_ShowSearch(Dialogs &); void gui_ShowSendto(Dialogs &); void gui_ShowSpellchecker(Dialogs &); @@ -68,11 +55,8 @@ void gui_UpdateTabular(InsetTabular *, Dialogs &); void gui_ShowTabularCreate(Dialogs &); void gui_ShowTexinfo(Dialogs &); void gui_ShowThesaurus(string const &, Dialogs &); -void gui_ShowTOC(InsetCommand *, Dialogs &); -void gui_CreateTOC(string const &, Dialogs &); -void gui_ShowUrl(InsetCommand *, Dialogs &); -void gui_CreateUrl(string const &, Dialogs &); void gui_ShowVCLogFile(Dialogs &); +void gui_ShowWrap(InsetWrap *, Dialogs &); } // extern "C" diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 56d05e6e04..68d0669bd9 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -1,10 +1,8 @@ /** * \file qt2/Dialogs.C - * Copyright 1995 Matthias Ettrich * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Allan Rae * \author Angus Leeming * * Full author contact details are available in file CREDITS @@ -12,56 +10,36 @@ #include - #include "Dialogs_impl.h" -Dialogs::Dialogs(LyXView & lv) - : pimpl_(new Impl(lv, *this)) +void Dialogs::init_pimpl() { - // reduce the number of connections needed in - // dialogs by a simple connection here. - hideAll.connect(hideBufferDependent); + pimpl_ = new Impl(lyxview_, *this); } Dialogs::~Dialogs() -{} - - -void Dialogs::toggleTooltips() -{} - - -/// Are the tooltips on or off? -bool Dialogs::tooltipsEnabled() { - return false; + delete pimpl_; } Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) : aboutlyx(lv, d), - bibitem(lv, d), - bibtex(lv, d), changes(lv, d), character(lv, d), - citation(lv, d), document(lv, d), - error(lv, d), - ert(lv, d), external(lv, d), file(lv, d), floats(lv, d), graphics(lv, d), include(lv, d), - index(lv, d), logfile(lv, d), minipage(lv, d), paragraph(lv, d), prefs(lv, d), print(lv, d), - ref(lv, d), search(lv, d), sendto(lv, d), spellchecker(lv, d), @@ -73,8 +51,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) thesaurus(lv, d), #endif - toc(lv, d), - url(lv, d), vclogfile(lv, d), wrap(lv, d) {} diff --git a/src/frontends/qt2/Dialogs2.C b/src/frontends/qt2/Dialogs2.C index 2f9b552702..abff472248 100644 --- a/src/frontends/qt2/Dialogs2.C +++ b/src/frontends/qt2/Dialogs2.C @@ -22,18 +22,6 @@ void Dialogs::showAboutlyx() } -void Dialogs::showBibitem(InsetCommand * ic) -{ - pimpl_->bibitem.controller().showInset(ic); -} - - -void Dialogs::showBibtex(InsetCommand * ic) -{ - pimpl_->bibtex.controller().showInset(ic); -} - - void Dialogs::showMergeChanges() { pimpl_->changes.controller().show(); @@ -52,42 +40,12 @@ void Dialogs::setUserFreeFont() } -void Dialogs::showCitation(InsetCommand * ic) -{ - pimpl_->citation.controller().showInset(ic); -} - - -void Dialogs::createCitation(string const & s) -{ - pimpl_->citation.controller().createInset(s); -} - - void Dialogs::showDocument() { pimpl_->document.controller().show(); } -void Dialogs::showError(InsetError * ie) -{ - pimpl_->error.controller().showInset(ie); -} - - -void Dialogs::showERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - -void Dialogs::updateERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - void Dialogs::showExternal(InsetExternal * ie) { pimpl_->external.controller().showInset(ie); @@ -122,18 +80,6 @@ void Dialogs::showInclude(InsetInclude * ii) } -void Dialogs::showIndex(InsetCommand * ic) -{ - pimpl_->index.controller().showInset(ic); -} - - -void Dialogs::createIndex() -{ - pimpl_->index.controller().createInset("index"); -} - - void Dialogs::showLogFile() { pimpl_->logfile.controller().show(); @@ -191,18 +137,6 @@ void Dialogs::showPrint() } -void Dialogs::showRef(InsetCommand * ic) -{ - pimpl_->ref.controller().showInset(ic); -} - - -void Dialogs::createRef(string const & s) -{ - pimpl_->ref.controller().createInset(s); -} - - void Dialogs::showSearch() { pimpl_->search.controller().show(); @@ -260,30 +194,6 @@ void Dialogs::showThesaurus(string const &) #endif -void Dialogs::showTOC(InsetCommand * ic) -{ - pimpl_->toc.controller().showInset(ic); -} - - -void Dialogs::createTOC(string const & s) -{ - pimpl_->toc.controller().createInset(s); -} - - -void Dialogs::showUrl(InsetCommand * ic) -{ - pimpl_->url.controller().showInset(ic); -} - - -void Dialogs::createUrl(string const & s) -{ - pimpl_->url.controller().createInset(s); -} - - void Dialogs::showVCLogFile() { pimpl_->vclogfile.controller().show(); diff --git a/src/frontends/qt2/Dialogs3.C b/src/frontends/qt2/Dialogs3.C new file mode 100644 index 0000000000..9bf18247c8 --- /dev/null +++ b/src/frontends/qt2/Dialogs3.C @@ -0,0 +1,149 @@ +/** + * \file qt2/Dialogs3.C + * 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 + +#include "Dialogs.h" +#include "Dialog.h" + +#include "ControlBibitem.h" +#include "ControlBibtex.h" +#include "ControlCitation.h" +#include "ControlError.h" +#include "ControlERT.h" +#include "ControlIndex.h" +#include "ControlRef.h" +#include "ControlToc.h" +#include "ControlUrl.h" + +#include "QBibitem.h" +#include "QBibitemDialog.h" +#include "QBibtex.h" +#include "QBibtexDialog.h" +#include "QCitation.h" +#include "QCitationDialog.h" +#include "QError.h" +#include "QErrorDialog.h" +#include "QERT.h" +#include "QERTDialog.h" +// Here would be an appropriate point to lecture on the evils +// of the Qt headers, those most fucked up of disgusting ratholes. +// But I won't. +#undef signals +#include "QIndex.h" +#include "QIndexDialog.h" +#include "QRef.h" +#include "QRefDialog.h" +#include "QToc.h" +#include "QTocDialog.h" +#include "QURL.h" +#include "QURLDialog.h" + +#include "Qt2BC.h" +#include "ButtonController.h" + + +typedef ButtonController + OkCancelBC; + +typedef ButtonController + OkCancelReadOnlyBC; + +typedef ButtonController + NoRepeatedApplyReadOnlyBC; + + +namespace { + +char const * const dialognames[] = { "bibitem", "bibtex", "citation", + "error", "ert", "index", "ref", + "toc", "url" }; + +char const * const * const end_dialognames = + dialognames + (sizeof(dialognames) / sizeof(char *)); + +struct cmpCStr { + cmpCStr(char const * name) : name_(name) {} + bool operator()(char const * other) { + return strcmp(other, name_) == 0; + } +private: + char const * name_; +}; + + +} // namespace anon + + +bool Dialogs::isValidName(string const & name) const +{ + return std::find_if(dialognames, end_dialognames, + cmpCStr(name.c_str())) != end_dialognames; +} + + +Dialog * Dialogs::build(string const & name) +{ + if (!isValidName(name)) + return 0; + + Dialog * dialog = new Dialog(lyxview_, name); + + if (name == "bibitem") { + dialog->setController(new ControlBibitem(*dialog)); + dialog->setView(new QBibitem(*dialog)); + dialog->setButtonController(new OkCancelReadOnlyBC); + } else if (name == "bibtex") { + dialog->setController(new ControlBibtex(*dialog)); + dialog->setView(new QBibtex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "citation") { + dialog->setController(new ControlCitation(*dialog)); + dialog->setView(new QCitation(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "error") { + dialog->setController(new ControlError(*dialog)); + dialog->setView(new QError(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "ert") { + dialog->setController(new ControlERT(*dialog)); + dialog->setView(new QERT(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "index") { + dialog->setController(new ControlIndex(*dialog)); + dialog->setView(new QIndex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "ref") { + dialog->setController(new ControlRef(*dialog)); + dialog->setView(new QRef(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "toc") { + dialog->setController(new ControlToc(*dialog)); + dialog->setView(new QToc(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "url") { + dialog->setController(new ControlUrl(*dialog)); + dialog->setView(new QURL(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } + + return dialog; +} + + +void Dialogs::toggleTooltips() +{} + + +/// Are the tooltips on or off? +bool Dialogs::tooltipsEnabled() +{ + return false; +} diff --git a/src/frontends/qt2/Dialogs_impl.h b/src/frontends/qt2/Dialogs_impl.h index 187394ca60..98e4e41229 100644 --- a/src/frontends/qt2/Dialogs_impl.h +++ b/src/frontends/qt2/Dialogs_impl.h @@ -16,27 +16,20 @@ #include "controllers/GUI.h" #include "ControlAboutlyx.h" -#include "ControlBibitem.h" -#include "ControlBibtex.h" #include "ControlChanges.h" #include "ControlCharacter.h" -#include "ControlCitation.h" #include "ControlDocument.h" -#include "ControlError.h" -#include "ControlERT.h" #include "ControlExternal.h" #include "ControlFloat.h" #include "ControlForks.h" #include "ControlGraphics.h" #include "insets/insetgraphicsParams.h" #include "ControlInclude.h" -#include "ControlIndex.h" #include "ControlLog.h" #include "ControlMinipage.h" #include "ControlParagraph.h" #include "ControlPrefs.h" #include "ControlPrint.h" -#include "ControlRef.h" #include "ControlSearch.h" #include "ControlSendto.h" #include "ControlShowFile.h" @@ -44,29 +37,17 @@ #include "ControlTabularCreate.h" #include "ControlTabular.h" #include "ControlTexinfo.h" -#include "ControlToc.h" -#include "ControlUrl.h" #include "ControlVCLog.h" #include "ControlWrap.h" #include "QAbout.h" #include "QAboutDialog.h" -#include "QBibitem.h" -#include "QBibitemDialog.h" -#include "QBibtex.h" -#include "QBibtexDialog.h" #include "QChanges.h" #include "QChangesDialog.h" #include "QCharacter.h" #include "QCharacterDialog.h" -#include "QCitation.h" -#include "QCitationDialog.h" #include "QDocument.h" #include "QDocumentDialog.h" -#include "QError.h" -#include "QErrorDialog.h" -#include "QERT.h" -#include "QERTDialog.h" #include "QExternal.h" #include "QExternalDialog.h" #include "QFloat.h" @@ -80,8 +61,6 @@ #include "QGraphicsDialog.h" #include "QInclude.h" #include "QIncludeDialog.h" -#include "QIndex.h" -#include "QIndexDialog.h" #include "QLog.h" #include "QLogDialog.h" #include "QMinipage.h" @@ -92,8 +71,6 @@ #include "QPrefsDialog.h" #include "QPrint.h" #include "QLPrintDialog.h" -#include "QRef.h" -#include "QRefDialog.h" #include "QSearch.h" #include "QSearchDialog.h" #include "QSendto.h" @@ -115,10 +92,6 @@ #include "QThesaurusDialog.h" #endif -#include "QToc.h" -#include "QTocDialog.h" -#include "QURL.h" -#include "QURLDialog.h" #include "QVCLog.h" #include "QVCLogDialog.h" #include "QWrap.h" @@ -131,30 +104,15 @@ typedef GUI AboutlyxDialog; -typedef GUI -BibitemDialog; - -typedef GUI -BibtexDialog; - typedef GUI ChangesDialog; typedef GUI CharacterDialog; -typedef GUI -CitationDialog; - typedef GUI DocumentDialog; -typedef GUI -ErrorDialog; - -typedef GUI -ERTDialog; - typedef GUI ExternalDialog; @@ -170,9 +128,6 @@ GraphicsDialog; typedef GUI IncludeDialog; -typedef GUI -IndexDialog; - typedef GUI LogFileDialog; @@ -188,9 +143,6 @@ PrefsDialog; typedef GUI PrintDialog; -typedef GUI -RefDialog; - typedef GUI SearchDialog; @@ -214,12 +166,6 @@ typedef GUI ThesaurusDialog; #endif -typedef GUI -TocDialog; - -typedef GUI -UrlDialog; - typedef GUI VCLogFileDialog; @@ -231,26 +177,19 @@ struct Dialogs::Impl { Impl(LyXView & lv, Dialogs & d); AboutlyxDialog aboutlyx; - BibitemDialog bibitem; - BibtexDialog bibtex; ChangesDialog changes; CharacterDialog character; - CitationDialog citation; DocumentDialog document; - ErrorDialog error; - ERTDialog ert; ExternalDialog external; FileDialog file; FloatDialog floats; GraphicsDialog graphics; IncludeDialog include; - IndexDialog index; LogFileDialog logfile; MinipageDialog minipage; ParagraphDialog paragraph; PrefsDialog prefs; PrintDialog print; - RefDialog ref; SearchDialog search; SendtoDialog sendto; SpellcheckerDialog spellchecker; @@ -262,8 +201,6 @@ struct Dialogs::Impl { ThesaurusDialog thesaurus; #endif - TocDialog toc; - UrlDialog url; VCLogFileDialog vclogfile; WrapDialog wrap; }; diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 5b4155514c..83ab731c92 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -14,11 +14,15 @@ INCLUDES = -I$(top_srcdir)/src/ -I$(top_srcdir)/src/frontends/ \ AM_CXXFLAGS = -DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_TRANSLATION + libqt2_la_SOURCES = \ + QDialogView.C \ + QDialogView.h \ Alert_pimpl.C \ bulletstrings.C bulletstrings.h \ Dialogs.C \ Dialogs2.C \ + Dialogs3.C \ Dialogs_impl.h \ FileDialog.C \ LyXKeySymFactory.C \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 7f9f3d5fde..a5621676a7 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -104,6 +104,7 @@ MOCFILES = \ QShowFileDialog.C QShowFileDialog.h \ QSpellcheckerDialog.C QSpellcheckerDialog.h \ Qt2Base.C Qt2Base.h \ + QDialogView.C QDialogView.h \ QTabularCreateDialog.C QTabularCreateDialog.h \ QTabularDialog.C QTabularDialog.h \ QTexinfoDialog.C QTexinfoDialog.h \ diff --git a/src/frontends/qt2/QBibitem.C b/src/frontends/qt2/QBibitem.C index 12267a8a9b..2a86aa04a0 100644 --- a/src/frontends/qt2/QBibitem.C +++ b/src/frontends/qt2/QBibitem.C @@ -24,11 +24,11 @@ #include "QBibitem.h" #include "Qt2BC.h" -typedef Qt2CB > base_class; +typedef QController > base_class; -QBibitem::QBibitem() - : base_class(qt_("LyX: Insert Bibliography Item")) +QBibitem::QBibitem(Dialog & parent) + : base_class(parent, qt_("LyX: Insert Bibliography Item")) { } diff --git a/src/frontends/qt2/QBibitem.h b/src/frontends/qt2/QBibitem.h index 8fa2291b89..12dd72bfc4 100644 --- a/src/frontends/qt2/QBibitem.h +++ b/src/frontends/qt2/QBibitem.h @@ -13,18 +13,18 @@ #define QBIBITEM_H -#include "Qt2Base.h" +#include "QDialogView.h" class ControlBibitem; class QBibitemDialog; class QBibitem - : public Qt2CB > + : public QController > { public: friend class QBibitemDialog; - QBibitem(); + QBibitem(Dialog &); protected: virtual bool isValid(); private: diff --git a/src/frontends/qt2/QBibtex.C b/src/frontends/qt2/QBibtex.C index 4eca11fdb9..3beb7eba33 100644 --- a/src/frontends/qt2/QBibtex.C +++ b/src/frontends/qt2/QBibtex.C @@ -33,11 +33,11 @@ using std::vector; -typedef Qt2CB > base_class; +typedef QController > base_class; -QBibtex::QBibtex() - : base_class(qt_("BibTeX")) +QBibtex::QBibtex(Dialog & parent) + : base_class(parent, qt_("BibTeX")) { } diff --git a/src/frontends/qt2/QBibtex.h b/src/frontends/qt2/QBibtex.h index 65e27b6bde..eee2d25960 100644 --- a/src/frontends/qt2/QBibtex.h +++ b/src/frontends/qt2/QBibtex.h @@ -13,18 +13,18 @@ #define QBIBTEX_H -#include "Qt2Base.h" +#include "QDialogView.h" class ControlBibtex; class QBibtexDialog; class QBibtex - : public Qt2CB > + : public QController > { public: friend class QBibtexDialog; - QBibtex(); + QBibtex(Dialog &); protected: virtual bool isValid(); private: diff --git a/src/frontends/qt2/QCitation.C b/src/frontends/qt2/QCitation.C index 64ecb9166d..293b9d88eb 100644 --- a/src/frontends/qt2/QCitation.C +++ b/src/frontends/qt2/QCitation.C @@ -38,11 +38,11 @@ using std::pair; using std::sort; using std::vector; -typedef Qt2CB > base_class; +typedef QController > base_class; -QCitation::QCitation() - : base_class(qt_("LyX: Insert Citation")) +QCitation::QCitation(Dialog & parent) + : base_class(parent, qt_("LyX: Insert Citation")) {} @@ -71,7 +71,7 @@ void QCitation::hide() citekeys.clear(); bibkeys.clear(); - Qt2Base::hide(); + QDialogView::hide(); } diff --git a/src/frontends/qt2/QCitation.h b/src/frontends/qt2/QCitation.h index 89a7203e0a..6f9da4dad3 100644 --- a/src/frontends/qt2/QCitation.h +++ b/src/frontends/qt2/QCitation.h @@ -14,20 +14,20 @@ #define QCITATION_H -#include "Qt2Base.h" +#include "QDialogView.h" + class QListBox; class ControlCitation; class QCitationDialog; -class QCitation - : public Qt2CB > +class QCitation : public QController > { public: friend class QCitationDialog; /// - QCitation(); + QCitation(Dialog &); private: /// enum State { diff --git a/src/frontends/qt2/QDialogView.C b/src/frontends/qt2/QDialogView.C new file mode 100644 index 0000000000..d683273b3d --- /dev/null +++ b/src/frontends/qt2/QDialogView.C @@ -0,0 +1,119 @@ +/** + * \file QDialogView.C + * 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 + + +#include +#include + +#include "debug.h" +#include "QtLyXView.h" +#include "Dialogs.h" +#include "QDialogView.h" +#include "Qt2BC.h" +#include "support/LAssert.h" + + +QDialogView::QDialogView(Dialog & parent, QString const & t) + : Dialog::View(parent), updating_(false), title_(t) +{} + + +Qt2BC & QDialogView::bc() +{ + return static_cast(dialog().bc()); +} + + +bool QDialogView::isVisible() const +{ + return form() && form()->isVisible(); +} + + +bool QDialogView::readOnly() const +{ + return kernel().isBufferReadonly(); +} + + +void QDialogView::show() +{ + if (!form()) { + build(); + } + + form()->setMinimumSize(form()->sizeHint()); + + update(); // make sure its up-to-date + + if (form()->isVisible()) { + form()->raise(); + } else { + form()->setCaption(title_); + form()->show(); + } +} + + +void QDialogView::hide() +{ + if (form() && form()->isVisible()) + form()->hide(); +} + + +bool QDialogView::isValid() +{ + return true; +} + + +void QDialogView::changed() +{ + if (updating_) + return; + + if (isValid()) + bc().valid(); + else + bc().invalid(); +} + + +void QDialogView::slotWMHide() +{ + dialog().CancelButton(); +} + + +void QDialogView::slotApply() +{ + dialog().ApplyButton(); +} + + +void QDialogView::slotOK() +{ + dialog().OKButton(); +} + + +void QDialogView::slotClose() +{ + dialog().CancelButton(); +} + + +void QDialogView::slotRestore() +{ + dialog().RestoreButton(); +} diff --git a/src/frontends/qt2/QDialogView.h b/src/frontends/qt2/QDialogView.h new file mode 100644 index 0000000000..4fe4a816d8 --- /dev/null +++ b/src/frontends/qt2/QDialogView.h @@ -0,0 +1,185 @@ +// -*- C++ -*- +/** + * \file QDialogView.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 QDIALOGVIEW_H +#define QDIALOGVIEW_H + + +#include "Dialog.h" +#include + +#include +#include +#include +#include + +class Qt2BC; + +/** This class is an Qt2 GUI base class. + */ +class QDialogView : public QObject, public Dialog::View { + Q_OBJECT +public: + /// + QDialogView(Dialog &, QString const &); + /// + virtual ~QDialogView() {} + /// + bool readOnly() const; + +protected: + /// build the actual dialog + virtual void build_dialog() = 0; + /// + virtual void build() = 0; + /// Hide the dialog. + virtual void hide(); + /// Create the dialog if necessary, update it and display it. + virtual void show(); + /// update the dialog's contents + virtual void update_contents() = 0; + /// + virtual bool isVisible() const; + + /// the dialog has changed contents + virtual void changed(); + + /// is the dialog currently valid ? + virtual bool isValid(); + + /// + Qt2BC & bc(); + + /// are we updating ? + bool updating_; +protected slots: + // dialog closed from WM + void slotWMHide(); + + // Restore button clicked + void slotRestore(); + + // OK button clicked + void slotOK(); + + // Apply button clicked + void slotApply(); + + // Close button clicked + void slotClose(); +private: + /// Pointer to the actual instantiation of the Qt dialog + virtual QDialog * form() const = 0; + +private: + /// dialog title, displayed by WM. + QString title_; +}; + + +template +class QView: public QDialogView { +protected: + QView(Dialog &, QString const &); + + /// update the dialog + virtual void update(); + + /// Build the dialog + virtual void build(); + + /// Pointer to the actual instantiation of the Qt dialog + virtual QDialog * form() const; + + /// Real GUI implementation. + boost::scoped_ptr dialog_; + +}; + + +template +QView::QView(Dialog & p, QString const & t) + : QDialogView(p, t) +{} + + +template +QDialog * QView::form() const +{ + return dialog_.get(); +} + + +template +void QView::update() +{ + form()->setUpdatesEnabled(false); + + // protect the BC from unwarranted state transitions + + qApp->processEvents(); + updating_ = true; + update_contents(); + qApp->processEvents(); + updating_ = false; + + form()->setUpdatesEnabled(true); + form()->update(); +} + + +template +void QView::build() +{ + // protect the BC from unwarranted state transitions + + qApp->processEvents(); + updating_ = true; + build_dialog(); + qApp->processEvents(); + updating_ = false; +} + + +template +class QController: public Base +{ +protected: + /// + QController(Dialog &, QString const &); + /// The parent controller + Controller & controller(); + /// The parent controller + Controller const & controller() const; +}; + + +template +QController::QController(Dialog & p, QString const & t) + : Base(p, t) +{} + + +template +Controller & QController::controller() +{ + return static_cast(getController()); +} + + +template +Controller const & QController::controller() const +{ + return static_cast(getController()); +} + + +#endif // QDIALOGVIEW_H diff --git a/src/frontends/qt2/QERT.C b/src/frontends/qt2/QERT.C index fcfb480cd7..12ea8be4dd 100644 --- a/src/frontends/qt2/QERT.C +++ b/src/frontends/qt2/QERT.C @@ -21,11 +21,11 @@ #include "QERT.h" #include "Qt2BC.h" -typedef Qt2CB > base_class; +typedef QController > base_class; -QERT::QERT() - : base_class(qt_("LyX: LaTeX Code Settings")) +QERT::QERT(Dialog & parent) + : base_class(parent, qt_("LyX: LaTeX Code Settings")) { } @@ -41,14 +41,12 @@ void QERT::build_dialog() void QERT::apply() { - ERTParams & params = controller().params(); - if (dialog_->openRB->isChecked()) - params.status = InsetERT::Open; + controller().setStatus(InsetERT::Open); else if (dialog_->inlineRB->isChecked()) - params.status = InsetERT::Inlined; + controller().setStatus(InsetERT::Inlined); else - params.status = InsetERT::Collapsed; + controller().setStatus(InsetERT::Collapsed); } @@ -56,7 +54,7 @@ void QERT::update_contents() { QRadioButton * rb = 0; - switch (controller().params().status) { + switch (controller().status()) { case InsetERT::Open: rb = dialog_->openRB; break; case InsetERT::Inlined: rb = dialog_->inlineRB; break; case InsetERT::Collapsed: rb = dialog_->collapsedRB; break; diff --git a/src/frontends/qt2/QERT.h b/src/frontends/qt2/QERT.h index 6f98398ce7..3be76ddfbc 100644 --- a/src/frontends/qt2/QERT.h +++ b/src/frontends/qt2/QERT.h @@ -13,18 +13,19 @@ #define QERT_H -#include "Qt2Base.h" +#include "QDialogView.h" + class ControlERT; class QERTDialog; -class QERT - : public Qt2CB > + +class QERT : public QController > { public: friend class QERTDialog; - QERT(); + QERT(Dialog &); private: /// Apply changes virtual void apply(); diff --git a/src/frontends/qt2/QError.C b/src/frontends/qt2/QError.C index b82b1b5b20..46748760cb 100644 --- a/src/frontends/qt2/QError.C +++ b/src/frontends/qt2/QError.C @@ -21,11 +21,11 @@ #include "QError.h" #include "Qt2BC.h" -typedef Qt2CB > base_class; +typedef QController > base_class; -QError::QError() - : base_class(qt_("LyX: LaTeX Error")) +QError::QError(Dialog & parent) + : base_class(parent, qt_("LyX: LaTeX Error")) { } diff --git a/src/frontends/qt2/QError.h b/src/frontends/qt2/QError.h index a697a8a4c1..84de64a00a 100644 --- a/src/frontends/qt2/QError.h +++ b/src/frontends/qt2/QError.h @@ -13,19 +13,19 @@ #define QERROR_H -#include "Qt2Base.h" +#include "QDialogView.h" class ControlError; class QErrorDialog; class QError - : public Qt2CB > + : public QController > { public: friend class QErrorDialog; - QError(); + QError(Dialog &); private: /// Apply changes virtual void apply() {} diff --git a/src/frontends/qt2/QIndex.C b/src/frontends/qt2/QIndex.C index 7558b3f724..1f025efb4c 100644 --- a/src/frontends/qt2/QIndex.C +++ b/src/frontends/qt2/QIndex.C @@ -20,11 +20,11 @@ #include #include -typedef Qt2CB > base_class; +typedef QController > base_class; -QIndex::QIndex() - : base_class(qt_("LyX: Insert Index Entry")) +QIndex::QIndex(Dialog & parent) + : base_class(parent, qt_("LyX: Insert Index Entry")) { } diff --git a/src/frontends/qt2/QIndex.h b/src/frontends/qt2/QIndex.h index cee1e99f65..18fafd4ba8 100644 --- a/src/frontends/qt2/QIndex.h +++ b/src/frontends/qt2/QIndex.h @@ -14,19 +14,19 @@ #define QINDEX_H -#include "Qt2Base.h" +#include "QDialogView.h" class ControlIndex; class QIndexDialog; class QIndex : - public Qt2CB > + public QController > { public: friend class QIndexDialog; - QIndex(); + QIndex(Dialog &); protected: virtual bool isValid(); private: diff --git a/src/frontends/qt2/QRef.C b/src/frontends/qt2/QRef.C index 583b55bdbd..797bfd089a 100644 --- a/src/frontends/qt2/QRef.C +++ b/src/frontends/qt2/QRef.C @@ -35,11 +35,11 @@ using std::vector; using std::endl; -typedef Qt2CB > base_class; +typedef QController > base_class; -QRef::QRef() - : base_class(qt_("LyX: Insert Cross-reference")), +QRef::QRef(Dialog & parent) + : base_class(parent, qt_("LyX: Insert Cross-reference")), sort_(false), at_ref_(false) { } @@ -102,15 +102,17 @@ void QRef::apply() bool QRef::nameAllowed() { - return controller().docType() != ControlRef::LATEX && - controller().docType() != ControlRef::LITERATE; + Kernel::DocTypes doc_type = kernel().docType(); + return doc_type != Kernel::LATEX && + doc_type != Kernel::LITERATE; } bool QRef::typeAllowed() { - return controller().docType() != ControlRef::LINUXDOC && - controller().docType() != ControlRef::DOCBOOK; + Kernel::DocTypes doc_type = kernel().docType(); + return doc_type != Kernel::LINUXDOC && + doc_type != Kernel::DOCBOOK; } diff --git a/src/frontends/qt2/QRef.h b/src/frontends/qt2/QRef.h index 1afca59eee..ba721a9bf4 100644 --- a/src/frontends/qt2/QRef.h +++ b/src/frontends/qt2/QRef.h @@ -13,7 +13,7 @@ #define QREF_H -#include "Qt2Base.h" +#include "QDialogView.h" #include #include "LString.h" @@ -22,12 +22,12 @@ class QRefDialog; class QRef - : public Qt2CB > + : public QController > { public: friend class QRefDialog; - QRef(); + QRef(Dialog &); private: /// apply changes virtual void apply(); diff --git a/src/frontends/qt2/QToc.C b/src/frontends/qt2/QToc.C index a5a9ada7e1..867b4a9419 100644 --- a/src/frontends/qt2/QToc.C +++ b/src/frontends/qt2/QToc.C @@ -33,10 +33,10 @@ using std::pair; using std::stack; using std::vector; -typedef Qt2CB > base_class; +typedef QController > base_class; -QToc::QToc() - : base_class(qt_("LyX: Table of Contents")), depth_(1) +QToc::QToc(Dialog & parent) + : base_class(parent, qt_("LyX: Table of Contents")), depth_(1) {} diff --git a/src/frontends/qt2/QToc.h b/src/frontends/qt2/QToc.h index 10294dc9cb..94a04308c5 100644 --- a/src/frontends/qt2/QToc.h +++ b/src/frontends/qt2/QToc.h @@ -14,19 +14,19 @@ #define QTOC_H -#include "Qt2Base.h" +#include "QDialogView.h" #include "toc.h" class ControlToc; class QTocDialog; class QToc : - public Qt2CB > + public QController > { public: friend class QTocDialog; - QToc(); + QToc(Dialog &); private: /// update the listview void updateToc(int newdepth); diff --git a/src/frontends/qt2/QURL.C b/src/frontends/qt2/QURL.C index 14b522adfc..1c4b77fb91 100644 --- a/src/frontends/qt2/QURL.C +++ b/src/frontends/qt2/QURL.C @@ -23,11 +23,11 @@ #include #include -typedef Qt2CB > base_class; +typedef QController > base_class; -QURL::QURL() - : base_class(qt_("LyX: Insert URL")) +QURL::QURL(Dialog & parent) + : base_class(parent, qt_("LyX: Insert URL")) { } diff --git a/src/frontends/qt2/QURL.h b/src/frontends/qt2/QURL.h index e9f40b7cc4..4a61ce9ca7 100644 --- a/src/frontends/qt2/QURL.h +++ b/src/frontends/qt2/QURL.h @@ -13,18 +13,18 @@ #define QURL_H -#include "Qt2Base.h" +#include "QDialogView.h" class ControlUrl; class QURLDialog; class QURL : - public Qt2CB > + public QController > { public: friend class QURLDialog; - QURL(); + QURL(Dialog &); protected: virtual bool isValid(); private: diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index d3e96357fc..b5d6a97233 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,38 @@ +2003-02-21 Angus Leeming + + * FormDialogView.[Ch]: new base class for the xforms dialogs, + deriving from Dialog::View. Otherwise identical to the existing + FormBase that derives from ViewBase. + + * Dialogs_impl.h: + * Dialogs.C: + * Dilaogs2.C: strip out those dialogs that now use the new + Dialog class as the platform for an MCV split. + + * Dialogs3.C: new file. Lazy instantiation of those dialogs that + now use the new Dialog class. + + * FormBibitem.[Ch]: + * FormBibtex.[Ch]: + * FormCitation.[Ch]: + * FormError.[Ch]: + * FormERT.[Ch]: + * FormIndex.[Ch]: + * FormRef.[Ch]: + * FormToc.[Ch]: + * FormUrl.[Ch]: + * forms/form_bibitem.fd: + * forms/form_bibtex.fd: + * forms/form_citation.fd: + * forms/form_error.fd: + * forms/form_ert.fd: + * forms/form_index.fd: + * forms/form_ref.fd: + * forms/form_toc.fd: + * forms/form_url.fd: minor changes to reflect the new heirarchy. + + * Makefile.am: add new files. + 2003-02-22 Alfredo Braunstein * lyx_gui.C (parse_init): added a call to LoaderQueue::setPriority diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 9eb84bcabf..231f3aa2e9 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -1,10 +1,8 @@ /** * \file xforms/Dialogs.C - * Copyright 1995 Matthias Ettrich * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Allan Rae * \author Angus Leeming * * Full author contact details are available in file CREDITS @@ -12,52 +10,32 @@ #include - #include "Dialogs_impl.h" -Dialogs::Dialogs(LyXView & lv) - : pimpl_(new Impl(lv, *this)) + +void Dialogs::init_pimpl() { - // reduce the number of connections needed in - // dialogs by a simple connection here. - hideAll.connect(hideBufferDependent); + pimpl_ = new Impl(lyxview_, *this); } Dialogs::~Dialogs() -{} - - -void Dialogs::toggleTooltips() { - Tooltips::toggleEnabled(); -} - - -/// Are the tooltips on or off? -bool Dialogs::tooltipsEnabled() -{ - return Tooltips::enabled(); + delete pimpl_; } Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) : aboutlyx(lv, d), - bibitem(lv, d), - bibtex(lv, d), changes(lv, d), character(lv, d), - citation(lv, d), document(lv, d), - error(lv, d), - ert(lv, d), external(lv, d), file(lv, d), floats(lv, d), forks(lv, d), graphics(lv, d), include(lv, d), - index(lv, d), logfile(lv, d), mathpanel(lv, d), minipage(lv, d), @@ -65,7 +43,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) preamble(lv, d), preferences(lv, d), print(lv, d), - ref(lv, d), search(lv, d), sendto(lv, d), spellchecker(lv, d), @@ -77,8 +54,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) thesaurus(lv, d), #endif - toc(lv, d), - url(lv, d), vclogfile(lv, d), wrap(lv, d) {} diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index 8e77fb1989..39cfbeba6a 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -22,18 +22,6 @@ void Dialogs::showAboutlyx() } -void Dialogs::showBibitem(InsetCommand * ic) -{ - pimpl_->bibitem.controller().showInset(ic); -} - - -void Dialogs::showBibtex(InsetCommand * ic) -{ - pimpl_->bibtex.controller().showInset(ic); -} - - void Dialogs::showMergeChanges() { pimpl_->changes.controller().show(); @@ -52,42 +40,12 @@ void Dialogs::setUserFreeFont() } -void Dialogs::showCitation(InsetCommand * ic) -{ - pimpl_->citation.controller().showInset(ic); -} - - -void Dialogs::createCitation(string const & s) -{ - pimpl_->citation.controller().createInset(s); -} - - void Dialogs::showDocument() { pimpl_->document.controller().show(); } -void Dialogs::showError(InsetError * ie) -{ - pimpl_->error.controller().showInset(ie); -} - - -void Dialogs::showERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - -void Dialogs::updateERT(InsetERT * ie) -{ - pimpl_->ert.controller().showInset(ie); -} - - void Dialogs::showExternal(InsetExternal * ie) { pimpl_->external.controller().showInset(ie); @@ -124,18 +82,6 @@ void Dialogs::showInclude(InsetInclude * ii) } -void Dialogs::showIndex(InsetCommand * ic) -{ - pimpl_->index.controller().showInset(ic); -} - - -void Dialogs::createIndex() -{ - pimpl_->index.controller().createInset("index"); -} - - void Dialogs::showLogFile() { pimpl_->logfile.controller().show(); @@ -190,18 +136,6 @@ void Dialogs::showPrint() } -void Dialogs::showRef(InsetCommand * ic) -{ - pimpl_->ref.controller().showInset(ic); -} - - -void Dialogs::createRef(string const & s) -{ - pimpl_->ref.controller().createInset(s); -} - - void Dialogs::showSearch() { pimpl_->search.controller().show(); @@ -259,30 +193,6 @@ void Dialogs::showThesaurus(string const &) #endif -void Dialogs::showTOC(InsetCommand * ic) -{ - pimpl_->toc.controller().showInset(ic); -} - - -void Dialogs::createTOC(string const & s) -{ - pimpl_->toc.controller().createInset(s); -} - - -void Dialogs::showUrl(InsetCommand * ic) -{ - pimpl_->url.controller().showInset(ic); -} - - -void Dialogs::createUrl(string const & s) -{ - pimpl_->url.controller().createInset(s); -} - - void Dialogs::showVCLogFile() { pimpl_->vclogfile.controller().show(); diff --git a/src/frontends/xforms/Dialogs3.C b/src/frontends/xforms/Dialogs3.C new file mode 100644 index 0000000000..0e826a1cf0 --- /dev/null +++ b/src/frontends/xforms/Dialogs3.C @@ -0,0 +1,161 @@ +/** + * \file xforms/Dialogs3.C + * 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 + +#include "Dialogs.h" +#include "Dialog.h" + +#include "Tooltips.h" + +#include "ControlBibitem.h" +#include "FormBibitem.h" +#include "forms/form_bibitem.h" + +#include "ControlBibtex.h" +#include "FormBibtex.h" +#include "forms/form_bibtex.h" + +#include "ControlCitation.h" +#include "FormCitation.h" +#include "forms/form_citation.h" + +#include "ControlError.h" +#include "FormError.h" +#include "forms/form_error.h" + +#include "ControlERT.h" +#include "FormERT.h" +#include "forms/form_ert.h" + +#include "ControlIndex.h" +#include "FormIndex.h" +#include "forms/form_index.h" + +#include "ControlRef.h" +#include "FormRef.h" +#include "forms/form_ref.h" + +#include "ControlToc.h" +#include "FormToc.h" +#include "forms/form_toc.h" + +#include "ControlUrl.h" +#include "FormUrl.h" +#include "forms/form_url.h" + +#include "xformsBC.h" +#include "ButtonController.h" + + +typedef ButtonController + OkCancelBC; + +typedef ButtonController + OkCancelReadOnlyBC; + +typedef ButtonController + NoRepeatedApplyReadOnlyBC; + + +namespace { + +// char const * const dialognames[] = { "bibitem", "bibtex", "citation", +// "error", "ert", "external", "float", +// "graphics", "include", "index", +// "minipage", "ref", "tabular", "toc", +// "url", "wrap" }; +char const * const dialognames[] = { "bibitem", "bibtex", "citation", + "error", "ert", "index", "ref", + "toc", "url" }; + +char const * const * const end_dialognames = + dialognames + (sizeof(dialognames) / sizeof(char *)); + +struct cmpCStr { + cmpCStr(char const * name) : name_(name) {} + bool operator()(char const * other) { + return strcmp(other, name_) == 0; + } +private: + char const * name_; +}; + + +} // namespace anon + + +bool Dialogs::isValidName(string const & name) const +{ + return std::find_if(dialognames, end_dialognames, + cmpCStr(name.c_str())) != end_dialognames; +} + + +Dialog * Dialogs::build(string const & name) +{ + if (!isValidName(name)) + return 0; + + Dialog * dialog = new Dialog(lyxview_, name); + + if (name == "bibitem") { + dialog->setController(new ControlBibitem(*dialog)); + dialog->setView(new FormBibitem(*dialog)); + dialog->setButtonController(new OkCancelReadOnlyBC); + } else if (name == "bibtex") { + dialog->setController(new ControlBibtex(*dialog)); + dialog->setView(new FormBibtex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "citation") { + dialog->setController(new ControlCitation(*dialog)); + dialog->setView(new FormCitation(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "error") { + dialog->setController(new ControlError(*dialog)); + dialog->setView(new FormError(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "ert") { + dialog->setController(new ControlERT(*dialog)); + dialog->setView(new FormERT(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "index") { + dialog->setController(new ControlIndex(*dialog)); + dialog->setView(new FormIndex(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "ref") { + dialog->setController(new ControlRef(*dialog)); + dialog->setView(new FormRef(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "toc") { + dialog->setController(new ControlToc(*dialog)); + dialog->setView(new FormToc(*dialog)); + dialog->setButtonController(new OkCancelBC); + } else if (name == "url") { + dialog->setController(new ControlUrl(*dialog)); + dialog->setView(new FormUrl(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } + + return dialog; +} + + +void Dialogs::toggleTooltips() +{ + Tooltips::toggleEnabled(); +} + + +/// Are the tooltips on or off? +bool Dialogs::tooltipsEnabled() +{ + return Tooltips::enabled(); +} diff --git a/src/frontends/xforms/Dialogs_impl.h b/src/frontends/xforms/Dialogs_impl.h index 5ffc0f7b6f..5233665b2b 100644 --- a/src/frontends/xforms/Dialogs_impl.h +++ b/src/frontends/xforms/Dialogs_impl.h @@ -23,14 +23,6 @@ #include "FormAboutlyx.h" #include "forms/form_aboutlyx.h" -#include "ControlBibitem.h" -#include "FormBibitem.h" -#include "forms/form_bibitem.h" - -#include "ControlBibtex.h" -#include "FormBibtex.h" -#include "forms/form_bibtex.h" - #include "FormBrowser.h" #include "forms/form_browser.h" @@ -42,22 +34,10 @@ #include "FormCharacter.h" #include "forms/form_character.h" -#include "ControlCitation.h" -#include "FormCitation.h" -#include "forms/form_citation.h" - #include "ControlDocument.h" #include "FormDocument.h" #include "forms/form_document.h" -#include "ControlError.h" -#include "FormError.h" -#include "forms/form_error.h" - -#include "ControlERT.h" -#include "FormERT.h" -#include "forms/form_ert.h" - #include "ControlExternal.h" #include "FormExternal.h" #include "forms/form_external.h" @@ -78,10 +58,6 @@ #include "FormInclude.h" #include "forms/form_include.h" -#include "ControlIndex.h" -#include "FormIndex.h" -#include "forms/form_index.h" - #include "ControlLog.h" #include "FormLog.h" @@ -112,10 +88,6 @@ #include "FormPrint.h" #include "forms/form_print.h" -#include "ControlRef.h" -#include "FormRef.h" -#include "forms/form_ref.h" - #include "ControlSearch.h" #include "FormSearch.h" #include "forms/form_search.h" @@ -146,14 +118,6 @@ #include "forms/form_thesaurus.h" #endif -#include "ControlToc.h" -#include "FormToc.h" -#include "forms/form_toc.h" - -#include "ControlUrl.h" -#include "FormUrl.h" -#include "forms/form_url.h" - #include "ControlVCLog.h" #include "FormVCLog.h" @@ -165,30 +129,15 @@ typedef GUI AboutlyxDialog; -typedef GUI -BibitemDialog; - -typedef GUI -BibtexDialog; - typedef GUI ChangesDialog; typedef GUI CharacterDialog; -typedef GUI -CitationDialog; - typedef GUI DocumentDialog; -typedef GUI -ErrorDialog; - -typedef GUI -ERTDialog; - typedef GUI ExternalDialog; @@ -207,9 +156,6 @@ GraphicsDialog; typedef GUI IncludeDialog; -typedef GUI -IndexDialog; - typedef GUI LogFileDialog; @@ -231,9 +177,6 @@ PreferencesDialog; typedef GUI PrintDialog; -typedef GUI -RefDialog; - typedef GUI SearchDialog; @@ -257,12 +200,6 @@ typedef GUI -TocDialog; - -typedef GUI -UrlDialog; - typedef GUI VCLogFileDialog; @@ -273,21 +210,15 @@ struct Dialogs::Impl { Impl(LyXView & lv, Dialogs & d); AboutlyxDialog aboutlyx; - BibitemDialog bibitem; - BibtexDialog bibtex; ChangesDialog changes; CharacterDialog character; - CitationDialog citation; DocumentDialog document; - ErrorDialog error; - ERTDialog ert; ExternalDialog external; FileDialog file; FloatDialog floats; ForksDialog forks; GraphicsDialog graphics; IncludeDialog include; - IndexDialog index; LogFileDialog logfile; MathPanelDialog mathpanel; MinipageDialog minipage; @@ -295,7 +226,6 @@ struct Dialogs::Impl { PreambleDialog preamble; PreferencesDialog preferences; PrintDialog print; - RefDialog ref; SearchDialog search; SendtoDialog sendto; SpellcheckerDialog spellchecker; @@ -307,8 +237,6 @@ struct Dialogs::Impl { ThesaurusDialog thesaurus; #endif - TocDialog toc; - UrlDialog url; VCLogFileDialog vclogfile; WrapDialog wrap; }; diff --git a/src/frontends/xforms/FormBibitem.C b/src/frontends/xforms/FormBibitem.C index e7747adca1..791687a0c3 100644 --- a/src/frontends/xforms/FormBibitem.C +++ b/src/frontends/xforms/FormBibitem.C @@ -20,10 +20,10 @@ #include "gettext.h" #include "support/lstrings.h" // compare -typedef FormCB > base_class; +typedef FormController > base_class; -FormBibitem::FormBibitem() - : base_class(_("Bibliography Entry")) +FormBibitem::FormBibitem(Dialog & parent) + : base_class(parent, _("Bibliography Entry")) {} diff --git a/src/frontends/xforms/FormBibitem.h b/src/frontends/xforms/FormBibitem.h index de978d714e..9206642d90 100644 --- a/src/frontends/xforms/FormBibitem.h +++ b/src/frontends/xforms/FormBibitem.h @@ -14,7 +14,7 @@ #define FORMBIBITEM_H -#include "FormBase.h" +#include "FormDialogView.h" class ControlBibitem; struct FD_bibitem; @@ -22,10 +22,10 @@ struct FD_bibitem; /** * For bibliography entry editing */ -class FormBibitem : public FormCB > { +class FormBibitem : public FormController > { public: /// - FormBibitem(); + FormBibitem(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index 973d70b0f8..b69409217b 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -32,10 +32,10 @@ using std::vector; using std::sort; -typedef FormCB > base_class; +typedef FormController > base_class; -FormBibtex::FormBibtex() - : base_class(_("BibTeX Database")) +FormBibtex::FormBibtex(Dialog & parent) + : base_class(parent, _("BibTeX Database")) {} @@ -66,7 +66,7 @@ void FormBibtex::build() // callback for double click in browser fl_set_browser_dblclick_callback(dialog_->browser_styles, - C_FormBaseInputCB, 2); + C_FormDialogView_InputCB, 2); // set up the tooltips string str = _("The database you want to cite from. Insert it " diff --git a/src/frontends/xforms/FormBibtex.h b/src/frontends/xforms/FormBibtex.h index 913b68aba2..11435b850f 100644 --- a/src/frontends/xforms/FormBibtex.h +++ b/src/frontends/xforms/FormBibtex.h @@ -14,7 +14,7 @@ #define FORMBIBTEX_H -#include "FormBase.h" +#include "FormDialogView.h" class ControlBibtex; struct FD_bibtex; @@ -22,10 +22,10 @@ struct FD_bibtex; /** * For bibtex database setting */ -class FormBibtex : public FormCB > { +class FormBibtex : public FormController > { public: /// - FormBibtex(); + FormBibtex(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index a1b9014b58..11a493e227 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -17,6 +17,7 @@ #include "ControlCitation.h" #include "FormCitation.h" #include "forms/form_citation.h" +#include "Kernel.h" #include "Tooltips.h" #include "helper_funcs.h" #include "xforms_helpers.h" @@ -86,11 +87,11 @@ void updateStyle(FD_citation * dialog, string command) } // namespace anon -typedef FormCB > base_class; +typedef FormController > base_class; -FormCitation::FormCitation() - : base_class(_("Citation")) +FormCitation::FormCitation(Dialog & parent) + : base_class(parent, _("Citation")) {} @@ -124,7 +125,7 @@ void FormCitation::hide() citekeys.clear(); bibkeys.clear(); - FormBase::hide(); + FormDialogView::hide(); } @@ -286,7 +287,7 @@ ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long) fl_set_browser_topline(dialog_->browser_cite, n + 1); } - if (!controller().bufferIsReadonly()) { + if (!kernel().isBufferReadonly()) { if (cit != citekeys.end()) { setBibButtons(OFF); setCiteButtons(ON); @@ -301,7 +302,7 @@ ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long) if (sel < 1 || sel > citekeys.size()) return ButtonPolicy::SMI_NOOP; - if (!controller().bufferIsReadonly()) { + if (!kernel().isBufferReadonly()) { setBibButtons(OFF); setCiteButtons(ON); } diff --git a/src/frontends/xforms/FormCitation.h b/src/frontends/xforms/FormCitation.h index 8c03035160..09ca816b04 100644 --- a/src/frontends/xforms/FormCitation.h +++ b/src/frontends/xforms/FormCitation.h @@ -13,7 +13,7 @@ #define FORMCITATION_H -#include "FormBase.h" +#include "FormDialogView.h" #include "biblio.h" /** This class provides an XForms implementation of the Citation Dialog. @@ -21,10 +21,10 @@ class ControlCitation; struct FD_citation; -class FormCitation : public FormCB > { +class FormCitation : public FormController > { public: /// - FormCitation(); + FormCitation(Dialog &); private: /// enum State { diff --git a/src/frontends/xforms/FormDialogView.C b/src/frontends/xforms/FormDialogView.C new file mode 100644 index 0000000000..7996633485 --- /dev/null +++ b/src/frontends/xforms/FormDialogView.C @@ -0,0 +1,443 @@ +/** + * \file FormDialogView.C + * 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 + + +#include "FormDialogView.h" + +#include "Dialog.h" +#include "xformsBC.h" +#include "xforms_resize.h" +#include "Tooltips.h" +#include "xforms_helpers.h" // formatted + +#include "gettext.h" // _() +#include "lyxrc.h" +#include "BoostFormat.h" + +#include "support/LAssert.h" +#include "support/filetools.h" // LibFileSearch + +#include FORMS_H_LOCATION + +extern "C" { + +// These should be in forms.h but aren't +void fl_show_tooltip(const char *, int, int); + +void fl_hide_tooltip(); + +// Callback function invoked by xforms when the dialog is closed by the +// window manager. +static int C_WMHideCB(FL_FORM * form, void *); + +// Callback function invoked by the xforms pre-handler routine. +static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *); + +} // extern "C" + + +FormDialogView::FormDialogView(Dialog & parent, + string const & t, bool allowResize) + : Dialog::View(parent), + warning_posted_(false), message_widget_(0), + minw_(0), minh_(0), allow_resize_(allowResize), + title_(t), icon_pixmap_(0), icon_mask_(0), + tooltips_(new Tooltips()) +{} + + +FormDialogView::~FormDialogView() +{ + if (icon_pixmap_) + XFreePixmap(fl_get_display(), icon_pixmap_); + + delete tooltips_; +} + + +bool FormDialogView::isVisible() const +{ + return form() && form()->visible; +} + + +Tooltips & FormDialogView::tooltips() +{ + return *tooltips_; +} + + +void FormDialogView::redraw() +{ + if (form() && form()->visible) + fl_redraw_form(form()); +} + + +xformsBC & FormDialogView::bc() +{ + return static_cast(dialog().bc()); +} + + +void FormDialogView::prepare_to_show() +{ + double const scale = get_scale_to_fit(form()); + if (scale > 1.001) + scale_form_horizontally(form(), scale); + + // work around dumb xforms sizing bug + minw_ = form()->w; + minh_ = form()->h; + + fl_set_form_atclose(form(), C_WMHideCB, 0); + + // set the title for the minimized form + if (!lyxrc.dialogs_iconify_with_main) + fl_winicontitle(form()->window, title_.c_str()); + + // assign an icon to the form + string const iconname = LibFileSearch("images", "lyx", "xpm"); + if (!iconname.empty()) { + unsigned int w, h; + icon_pixmap_ = fl_read_pixmapfile(fl_root, + iconname.c_str(), + &w, + &h, + &icon_mask_, + 0, 0, 0); + fl_set_form_icon(form(), icon_pixmap_, icon_mask_); + } +} + + +void FormDialogView::show() +{ + if (!form()) { + build(); + } + + // we use minw_ to flag whether the dialog has ever been shown. + // In turn, prepare_to_show() initialises various bits 'n' pieces + // (including minw_). + if (minw_ == 0) { + prepare_to_show(); + } + + // make sure the form is up to date. + fl_freeze_form(form()); + update(); + fl_unfreeze_form(form()); + + if (form()->visible) { + fl_raise_form(form()); + /* This XMapWindow() will hopefully ensure that + * iconified dialogs are de-iconified. Mad props + * out to those crazy Xlib guys for forgetting a + * XDeiconifyWindow(). At least WindowMaker, when + * being notified of the redirected MapRequest will + * specifically de-iconify. From source, fvwm2 seems + * to do the same. + */ + XMapWindow(fl_get_display(), form()->window); + } else { + // calls to fl_set_form_minsize/maxsize apply only to the next + // fl_show_form(), so this comes first. + fl_set_form_minsize(form(), minw_, minh_); + if (!allow_resize_) + fl_set_form_maxsize(form(), minw_, minh_); + + string const maximize_title = "LyX: " + title_; + int const iconify_policy = lyxrc.dialogs_iconify_with_main ? + FL_TRANSIENT : 0; + + fl_show_form(form(), + FL_PLACE_MOUSE | FL_FREE_SIZE, + iconify_policy, + maximize_title.c_str()); + } +} + + +void FormDialogView::hide() +{ +#if FL_VERSION < 1 + // Does no harm if none is visible and ensures that the tooltip form + // is hidden should the dialog be closed from the keyboard. + fl_hide_tooltip(); +#endif + + // xforms sometimes tries to process a hint-type MotionNotify, and + // use XQueryPointer, without verifying if the window still exists. + // So we try to clear out motion events in the queue before the + // DestroyNotify + XSync(fl_get_display(), false); + + if (form() && form()->visible) + fl_hide_form(form()); +} + + +void FormDialogView::setPrehandler(FL_OBJECT * ob) +{ + lyx::Assert(ob); + fl_set_object_prehandler(ob, C_PrehandlerCB); +} + + +void FormDialogView::setMessageWidget(FL_OBJECT * ob) +{ + lyx::Assert(ob && ob->objclass == FL_TEXT); + message_widget_ = ob; + fl_set_object_lsize(message_widget_, FL_NORMAL_SIZE); +} + + +void FormDialogView::InputCB(FL_OBJECT * ob, long data) +{ + // It is possible to set the choice to 0 when using the + // keyboard shortcuts. This work-around deals with the problem. + if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) { + fl_set_choice(ob, 1); + } + + bc().input(input(ob, data)); +} + + +ButtonPolicy::SMInput FormDialogView::input(FL_OBJECT *, long) +{ + return ButtonPolicy::SMI_VALID; +} + + +// preemptive handler for feedback messages +void FormDialogView::MessageCB(FL_OBJECT * ob, int event) +{ + lyx::Assert(ob); + + switch (event) { + case FL_ENTER: + { + string const feedback = getFeedback(ob); + if (feedback.empty() && warning_posted_) + break; + + warning_posted_ = false; + postMessage(getFeedback(ob)); + break; + } + + case FL_LEAVE: + if (!warning_posted_) + clearMessage(); + break; + + default: + break; + } +} + + +void FormDialogView::PrehandlerCB(FL_OBJECT * ob, int event, int key) +{ + lyx::Assert(ob); + + if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) { + // Trigger an input event when pasting in an xforms input + // object using the middle mouse button. + InputCB(ob, 0); + return; + } + + switch (event) { + case FL_ENTER: + case FL_LEAVE: + if (message_widget_) { + // Post feedback as the mouse enters the object, + // remove it as the mouse leaves. + MessageCB(ob, event); + } + +#if FL_VERSION < 1 + if (ob->objclass == FL_TABFOLDER) { + // This prehandler is used to work-around an xforms + // bug and ensures that the form->x, form->y coords of + // the active tabfolder are up to date. + + // The tabfolder itself can be very narrow, being just + // the visible border to the tabs. + // We thus use both FL_ENTER and FL_LEAVE as flags, + // in case the FL_ENTER event is not caught. + + FL_FORM * const folder = fl_get_active_folder(ob); + if (folder && folder->window) { + fl_get_winorigin(folder->window, + &(folder->x), &(folder->y)); + } + } +#endif + break; + } + + // Tooltips are not displayed on browser widgets due to an xforms' bug. + // I have a fix, but it's not yet in the xforms sources. + // This is a work-around: + switch (event) { + case FL_ENTER: + if (ob->objclass == FL_BROWSER && + ob->tooltip && *(ob->tooltip)) { + int const x = ob->form->x + ob->x; + int const y = ob->form->y + ob->y + ob->h + 1; + fl_show_tooltip(ob->tooltip, x, y); + } + break; + case FL_LEAVE: + case FL_PUSH: + case FL_KEYPRESS: + if (ob->objclass == FL_BROWSER) + fl_hide_tooltip(); + break; + } +} + + +void FormDialogView::postWarning(string const & warning) +{ + warning_posted_ = true; + postMessage(warning); +} + + +void FormDialogView::clearMessage() +{ + lyx::Assert(message_widget_); + + warning_posted_ = false; + + string const existing = message_widget_->label + ? message_widget_->label : string(); + if (existing.empty()) + return; + + // This trick is needed to get xforms to clear the label... + fl_set_object_label(message_widget_, ""); + fl_hide_object(message_widget_); +} + + +void FormDialogView::postMessage(string const & message) +{ + lyx::Assert(message_widget_); + + int const width = message_widget_->w - 10; +#if USE_BOOST_FORMAT + boost::format fmter = warning_posted_ ? + boost::format(_("WARNING! %1$s")) : + boost::format("%1$s"); + + string const str = formatted(boost::io::str(fmter % message), + width, FL_NORMAL_SIZE); +#else + string const tmp = warning_posted_ ? + _("WARNING!") + string(" ") + message : + message; + + string const str = formatted(tmp, width, FL_NORMAL_SIZE); +#endif + + fl_set_object_label(message_widget_, str.c_str()); + FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_LCOL; + fl_set_object_lcol(message_widget_, label_color); + + if (!message_widget_->visible) + fl_show_object(message_widget_); +} + + +namespace { + +FormDialogView * GetForm(FL_OBJECT * ob) +{ + lyx::Assert(ob && ob->form && ob->form->u_vdata); + FormDialogView * ptr = + static_cast(ob->form->u_vdata); + return ptr; +} + +} // namespace anon + + +extern "C" { + +void C_FormDialogView_ApplyCB(FL_OBJECT * ob, long) +{ + GetForm(ob)->dialog().ApplyButton(); +} + + +void C_FormDialogView_OKCB(FL_OBJECT * ob, long) +{ + GetForm(ob)->dialog().OKButton(); +} + + +void C_FormDialogView_CancelCB(FL_OBJECT * ob, long) +{ + FormDialogView * form = GetForm(ob); + form->dialog().CancelButton(); +} + + +void C_FormDialogView_RestoreCB(FL_OBJECT * ob, long) +{ + GetForm(ob)->dialog().RestoreButton(); +} + + +void C_FormDialogView_InputCB(FL_OBJECT * ob, long d) +{ + GetForm(ob)->InputCB(ob, d); +} + + +static int C_WMHideCB(FL_FORM * form, void *) +{ + // Close the dialog cleanly, even if the WM is used to do so. + lyx::Assert(form && form->u_vdata); + FormDialogView * ptr = static_cast(form->u_vdata); + ptr->dialog().CancelButton(); + return FL_CANCEL; +} + +static int C_PrehandlerCB(FL_OBJECT * ob, int event, + FL_Coord, FL_Coord, int key, void *) +{ + // Note that the return value is important in the pre-emptive handler. + // Don't return anything other than 0. + lyx::Assert(ob); + + // Don't Assert this one, as it can happen quite naturally when things + // are being deleted in the d-tor. + //Assert(ob->form); + if (!ob->form) return 0; + + FormDialogView * ptr = + static_cast(ob->form->u_vdata); + + if (ptr) + ptr->PrehandlerCB(ob, event, key); + + return 0; +} + +} // extern "C" diff --git a/src/frontends/xforms/FormDialogView.h b/src/frontends/xforms/FormDialogView.h new file mode 100644 index 0000000000..c76eed0c0f --- /dev/null +++ b/src/frontends/xforms/FormDialogView.h @@ -0,0 +1,198 @@ +// -*- C++ -*- +/** + * \file FormDialogView.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 + */ + +/* A base class for the MCV-ed xforms dialogs. + */ + +#ifndef FORMDIALOGVIEW_H +#define FORMDIALOGVIEW_H + + +#include "Dialog.h" +#include "ButtonPolicies.h" +#include "forms_fwd.h" + +#include "LString.h" +#include +#include // for Pixmap + +class xformsBC; +class Tooltips; + + +/** This class is an XForms GUI base class. + */ +class FormDialogView : public Dialog::View { +public: + /// + FormDialogView(Dialog &, string const &, bool allowResize); + /// + virtual ~FormDialogView(); + + /** Input callback function. + * Invoked only by the xforms callback interface + */ + void InputCB(FL_OBJECT *, long); + + /** Message callback function. + * Invoked only by the xforms callback interface + */ + void MessageCB(FL_OBJECT *, int event); + + /** Prehandler callback function. + * Invoked only by the xforms callback interface + */ + void PrehandlerCB(FL_OBJECT * ob, int event, int key); + + /// + Tooltips & tooltips(); + +protected: + /// Build the dialog + virtual void build() = 0; + /// Hide the dialog. + virtual void hide(); + /// Create the dialog if necessary, update it and display it. + virtual void show(); + /// + virtual bool isVisible() const; + + /** Prepare the way to: + * 1. display feedback as the mouse moves over ob. This feedback will + * typically be rather more verbose than just a tooltip. + * 2. activate the button controller after a paste with the middle + * mouse button. + */ + static void setPrehandler(FL_OBJECT * ob); + + /** Pass the class a pointer to the message_widget so that it can + post the message */ + void setMessageWidget(FL_OBJECT * message_widget); + + /** Send the warning message from the daughter class to the + message_widget direct. The message will persist till the mouse + movesto a new object. */ + void postWarning(string const & warning); + /// Reset the message_widget_ + void clearMessage(); + + /// + xformsBC & bc(); + +private: + /// Pointer to the actual instantiation of xform's form + virtual FL_FORM * form() const = 0; + /// Filter the inputs on callback from xforms + virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); + + /** Redraw the form (on receipt of a Signal indicating, for example, + * that the xform colors have been re-mapped). + */ + virtual void redraw(); + + /** Called on the first show() request, initialising various bits and + * pieces. + */ + void prepare_to_show(); + + /** Get the feedback message for ob. + Called if warning_posted_ == false. */ + virtual string const getFeedback(FL_OBJECT * /* ob */) + { return string(); } + + /// Post the feedback message for ob to message_widget_ + void postMessage(string const & message); + + /** Variable used to decide whether to remove the existing feedback + message or not (if it is in fact a warning) */ + bool warning_posted_; + /// The widget to display the feedback + FL_OBJECT * message_widget_; + + /// The dialog's minimum allowable dimensions. + int minw_; + /// + int minh_; + /// Can the dialog be resized after it has been created? + bool allow_resize_; + /// dialog title, displayed by the window manager. + string title_; + /// Passed to the window manager to give a pretty little symbol ;-) + Pixmap icon_pixmap_; + /// + Pixmap icon_mask_; + /// + Tooltips * tooltips_; +}; + + +template +class FormView: public FormDialogView { +protected: + /// + FormView(Dialog &, string const &, bool allowResize=true); + /// Pointer to the actual instantiation of xform's form + virtual FL_FORM * form() const; + /// Real GUI implementation. + boost::scoped_ptr dialog_; +}; + + +template +FormView::FormView(Dialog & parent, string const & t, + bool allowResize) + : FormDialogView(parent, t, allowResize) +{} + + +template +FL_FORM * FormView::form() const +{ + return dialog_.get() ? dialog_->form : 0; +} + + +template +class FormController: public Base { +public: + /// The parent controller + Controller & controller(); + /// + Controller const & controller() const; + +protected: + /// + FormController(Dialog &, string const &, bool allowResize = true); +}; + + +template +FormController::FormController(Dialog & p, + string const & t, bool resize) + : Base(p, t, resize) +{} + + +template +Controller & FormController::controller() +{ + return static_cast(getController()); +} + + +template +Controller const & FormController::controller() const +{ + return static_cast(getController()); +} + + +#endif // FORMDIALOGVIEW_H diff --git a/src/frontends/xforms/FormERT.C b/src/frontends/xforms/FormERT.C index ad707be361..e5760ccb28 100644 --- a/src/frontends/xforms/FormERT.C +++ b/src/frontends/xforms/FormERT.C @@ -20,10 +20,10 @@ #include "debug.h" #include FORMS_H_LOCATION -typedef FormCB > base_class; +typedef FormController > base_class; -FormERT::FormERT() - : base_class(_("ERT Options")) +FormERT::FormERT(Dialog & parent) + : base_class(parent, _("ERT Options")) {} @@ -45,17 +45,17 @@ void FormERT::build() void FormERT::apply() { if (fl_get_button(dialog_->radio_open)) - controller().params().status = InsetERT::Open; + controller().setStatus(InsetERT::Open); else if (fl_get_button(dialog_->radio_collapsed)) - controller().params().status = InsetERT::Collapsed; + controller().setStatus(InsetERT::Collapsed); else - controller().params().status = InsetERT::Inlined; + controller().setStatus(InsetERT::Inlined); } void FormERT::update() { - switch (controller().params().status) { + switch (controller().status()) { case InsetERT::Open: fl_set_button(dialog_->radio_open, 1); break; diff --git a/src/frontends/xforms/FormERT.h b/src/frontends/xforms/FormERT.h index 4074b4de20..edfe7771ae 100644 --- a/src/frontends/xforms/FormERT.h +++ b/src/frontends/xforms/FormERT.h @@ -13,7 +13,8 @@ #define FORMERT_H -#include "FormBase.h" +#include "FormDialogView.h" + class ControlERT; struct FD_ert; @@ -21,11 +22,10 @@ struct FD_ert; /** This class provides an XForms implementation of the ERT Dialog. */ -class FormERT - : public FormCB > { +class FormERT : public FormController > { public: /// - FormERT(); + FormERT(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/FormError.C b/src/frontends/xforms/FormError.C index efa06d7d16..300f285a8c 100644 --- a/src/frontends/xforms/FormError.C +++ b/src/frontends/xforms/FormError.C @@ -18,10 +18,10 @@ #include "xforms_helpers.h" // formatted #include FORMS_H_LOCATION -typedef FormCB > base_class; +typedef FormController > base_class; -FormError::FormError() - : base_class(_("LaTeX Error")) +FormError::FormError(Dialog & parent) + : base_class(parent, _("LaTeX Error")) {} diff --git a/src/frontends/xforms/FormError.h b/src/frontends/xforms/FormError.h index fd817c29e7..d613e57d70 100644 --- a/src/frontends/xforms/FormError.h +++ b/src/frontends/xforms/FormError.h @@ -13,17 +13,18 @@ #define FORMERROR_H -#include "FormBase.h" +#include "FormDialogView.h" + class ControlError; struct FD_error; /** This class provides an XForms implementation of the Error Dialog. */ -class FormError : public FormCB > { +class FormError : public FormController > { public: /// Constructor - FormError(); + FormError(Dialog &); private: /// not needed. virtual void apply() {} diff --git a/src/frontends/xforms/FormIndex.C b/src/frontends/xforms/FormIndex.C index e5be7a92ef..99ef7d6036 100644 --- a/src/frontends/xforms/FormIndex.C +++ b/src/frontends/xforms/FormIndex.C @@ -20,10 +20,10 @@ #include FORMS_H_LOCATION -typedef FormCB > base_class; +typedef FormController > base_class; -FormIndex::FormIndex() - : base_class(_("Index")) +FormIndex::FormIndex(Dialog & parent) + : base_class(parent, _("Index")) {} diff --git a/src/frontends/xforms/FormIndex.h b/src/frontends/xforms/FormIndex.h index 3cb4bc8b8e..c1b2d29081 100644 --- a/src/frontends/xforms/FormIndex.h +++ b/src/frontends/xforms/FormIndex.h @@ -13,17 +13,17 @@ #define FORMINDEX_H -#include "FormBase.h" +#include "FormDialogView.h" class ControlIndex; struct FD_index; /** This class provides an XForms implementation of the Index Dialog. */ -class FormIndex : public FormCB > { +class FormIndex : public FormController > { public: /// - FormIndex(); + FormIndex(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/FormRef.C b/src/frontends/xforms/FormRef.C index 5e23ecaed9..9e65a8eb5b 100644 --- a/src/frontends/xforms/FormRef.C +++ b/src/frontends/xforms/FormRef.C @@ -28,10 +28,10 @@ using std::max; using std::sort; using std::vector; -typedef FormCB > base_class; +typedef FormController > base_class; -FormRef::FormRef() - : base_class(_("Reference")), +FormRef::FormRef(Dialog & parent) + : base_class(parent, _("Reference")), at_ref_(false) {} @@ -90,16 +90,15 @@ void FormRef::update() switch_go_button(); // Name is irrelevant to LaTeX/Literate documents - if (controller().docType() == ControlRef::LATEX || - controller().docType() == ControlRef::LITERATE) { + Kernel::DocTypes doctype = kernel().docType(); + if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) { setEnabled(dialog_->input_name, false); } else { setEnabled(dialog_->input_name, true); } // type is irrelevant to LinuxDoc/DocBook. - if (controller().docType() == ControlRef::LINUXDOC || - controller().docType() == ControlRef::DOCBOOK) { + if (doctype == Kernel::LINUXDOC || doctype == Kernel::DOCBOOK) { fl_set_choice(dialog_->choice_format, 1); setEnabled(dialog_->choice_format, false); } else { @@ -226,7 +225,7 @@ ButtonPolicy::SMInput FormRef::input(FL_OBJECT * ob, long) if (sel < 1 || sel > refs_.size()) return ButtonPolicy::SMI_NOOP; - if (!controller().bufferIsReadonly()) { + if (!kernel().isBufferReadonly()) { string s = fl_get_browser_line(dialog_->browser_refs, sel); fl_set_input(dialog_->input_ref, s.c_str()); } diff --git a/src/frontends/xforms/FormRef.h b/src/frontends/xforms/FormRef.h index c1e1d867aa..51b5f2893c 100644 --- a/src/frontends/xforms/FormRef.h +++ b/src/frontends/xforms/FormRef.h @@ -13,17 +13,17 @@ #define FORMREF_H -#include "FormBase.h" +#include "FormDialogView.h" class ControlRef; struct FD_ref; /** This class provides an XForms implementation of the FormRef Dialog. */ -class FormRef : public FormCB > { +class FormRef : public FormController > { public: /// - FormRef(); + FormRef(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/FormToc.C b/src/frontends/xforms/FormToc.C index 8d1cd43038..c62488ac29 100644 --- a/src/frontends/xforms/FormToc.C +++ b/src/frontends/xforms/FormToc.C @@ -27,10 +27,10 @@ using std::vector; using std::endl; -typedef FormCB > base_class; +typedef FormController > base_class; -FormToc::FormToc() - : base_class(_("Table of Contents")) +FormToc::FormToc(Dialog & parent) + : base_class(parent, _("Table of Contents")) {} diff --git a/src/frontends/xforms/FormToc.h b/src/frontends/xforms/FormToc.h index 0276e3d09f..d3a3c6f651 100644 --- a/src/frontends/xforms/FormToc.h +++ b/src/frontends/xforms/FormToc.h @@ -13,7 +13,7 @@ #define FORMTOC_H -#include "FormBase.h" +#include "FormDialogView.h" #include "toc.h" class ControlToc; @@ -21,10 +21,10 @@ struct FD_toc; /** This class provides an XForms implementation of the FormToc Dialog. */ -class FormToc : public FormCB > { +class FormToc : public FormController > { public: /// - FormToc(); + FormToc(Dialog &); private: /// not needed virtual void apply() {} diff --git a/src/frontends/xforms/FormUrl.C b/src/frontends/xforms/FormUrl.C index 6ce4b266a0..1ab86a837a 100644 --- a/src/frontends/xforms/FormUrl.C +++ b/src/frontends/xforms/FormUrl.C @@ -18,10 +18,10 @@ #include "forms/form_url.h" #include FORMS_H_LOCATION -typedef FormCB > base_class; +typedef FormController > base_class; -FormUrl::FormUrl() - : base_class(_("Url")) +FormUrl::FormUrl(Dialog & parent) + : base_class(parent, _("Url")) {} diff --git a/src/frontends/xforms/FormUrl.h b/src/frontends/xforms/FormUrl.h index 067a93f386..7e7b3a1766 100644 --- a/src/frontends/xforms/FormUrl.h +++ b/src/frontends/xforms/FormUrl.h @@ -13,17 +13,17 @@ #define FORMURL_H -#include "FormBase.h" +#include "FormDialogView.h" class ControlUrl; struct FD_url; /** This class provides an XForms implementation of the Url Dialog. */ -class FormUrl : public FormCB > { +class FormUrl : public FormController > { public: /// - FormUrl(); + FormUrl(Dialog &); private: /// Apply from dialog (modify or create inset) virtual void apply(); diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index a67ac6279a..3ac9282f94 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -48,6 +48,7 @@ libxforms_la_SOURCES = \ ColorHandler.h \ Dialogs.C \ Dialogs2.C \ + Dialogs3.C \ Dialogs_impl.h \ DropDown.h \ DropDown.C \ @@ -60,6 +61,8 @@ libxforms_la_SOURCES = \ FormAboutlyx.h \ FormBase.C \ FormBase.h \ + FormDialogView.C \ + FormDialogView.h \ FormBibitem.C \ FormBibitem.h \ FormBibtex.C \ @@ -163,17 +166,3 @@ libxforms_la_SOURCES = \ XWorkArea.C libxforms.la: $(libxforms_la_OBJECTS) $(libxforms_la_DEPENDENCIES) - -# just copied from old lyx repository -#dist-hook: -# for subdir in $(LYXDATADIRS) ; do \ -# test -d $(distdir)/$$subdir \ -# || mkdir $(distdir)/$$subdir \ -# || exit 1; \ -# chmod 777 $(distdir)/$$subdir; \ -# list=`(cd $(srcdir)/$$subdir && ls -1 | grep -v CVS)`; \ -# echo $$list ; \ -# for fil in $$list ; do \ -# cp -p $(srcdir)/$$subdir/$$fil $(distdir)/$$subdir ; \ -# done ; \ -# done diff --git a/src/frontends/xforms/XWorkArea.C b/src/frontends/xforms/XWorkArea.C index 561d90b5b5..3bf532b960 100644 --- a/src/frontends/xforms/XWorkArea.C +++ b/src/frontends/xforms/XWorkArea.C @@ -368,55 +368,20 @@ int XWorkArea::work_area_handler(FL_OBJECT * ob, int event, case FL_KEYPRESS: { lyxerr[Debug::WORKAREA] << "Workarea event: KEYPRESS" << endl; - - KeySym keysym = 0; - char dummy[1]; XKeyEvent * xke = reinterpret_cast(ev); - XLookupString(xke, dummy, 1, &keysym, 0); if (lyxerr.debugging(Debug::KEY)) { char const * const tmp = XKeysymToString(key); - char const * const tmp2 = XKeysymToString(keysym); - string const stm = (tmp ? tmp : string()); - string const stm2 = (tmp2 ? tmp2 : string()); - - lyxerr << "XWorkArea: Key is `" << stm - << "' [" << key << "]\n" - << "XWorkArea: Keysym is `" << stm2 - << "' [" << keysym << ']' << endl; + lyxerr << "XWorkArea: Key is `" << tmp + << "' [" << key << "]" << endl; } - // Note that we need this handling because of a bug - // in XForms 0.89, if this bug is resolved in the way I hope - // we can just use the keysym directly without looking - // at key at all. (Lgb) - KeySym ret_key = 0; if (!key) { - // We might have to add more keysyms here also, - // we will do that as the issues arise. (Lgb) - if (keysym == XK_space) { - ret_key = keysym; - lyxerr[Debug::KEY] << "Using keysym [A]" - << endl; - } else - break; - } else { - // It seems that this was a bit optimistic... - // With this hacking things seems to be better (Lgb) - //if (!iscntrl(key)) { - // ret_key = key; - // lyxerr[Debug::KEY] - // << "Using key [B]\n" - // << "Uchar[" - // << static_cast(key) - // << endl; - //} else { - ret_key = (keysym ? keysym : key); - lyxerr[Debug::KEY] << "Using keysym [B]" - << endl; - //} + lyxerr << "Probably composing" << endl; + break; } + KeySym ret_key = key; unsigned int const ret_state = xke->state; // If you have a better way to handle "wild-output" of diff --git a/src/frontends/xforms/forms/form_bibitem.fd b/src/frontends/xforms/forms/form_bibitem.fd index b509d17d79..ac9724b7c4 100644 --- a/src/frontends/xforms/forms/form_bibitem.fd +++ b/src/frontends/xforms/forms/form_bibitem.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_key -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 3 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_label -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 2 ============================== diff --git a/src/frontends/xforms/forms/form_bibtex.fd b/src/frontends/xforms/forms/form_bibtex.fd index 2c8636ef2b..7065b4a9f1 100644 --- a/src/frontends/xforms/forms/form_bibtex.fd +++ b/src/frontends/xforms/forms/form_bibtex.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: button_rescan -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_database -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_style -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_database_browse -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_bibtotoc -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -172,7 +172,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_North FL_South name: browser_styles -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -190,7 +190,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_style_browse -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -208,7 +208,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -226,7 +226,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_citation.fd b/src/frontends/xforms/forms/form_citation.fd index 6e3e6904f7..cf82e82f62 100644 --- a/src/frontends/xforms/forms/form_citation.fd +++ b/src/frontends/xforms/forms/form_citation.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NorthWest FL_South name: browser_cite -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_North FL_SouthEast name: browser_bib -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: #&D resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_add -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: #X resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_del -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: #&A resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_up -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -172,7 +172,7 @@ shortcut: #&B resize: FL_RESIZE_NONE gravity: FL_North FL_North name: button_down -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -262,7 +262,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: button_previous -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -280,7 +280,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: button_next -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -298,7 +298,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: choice_style -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -316,7 +316,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: check_full_author_list -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -334,7 +334,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: check_force_uppercase -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -352,7 +352,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: input_before -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -370,7 +370,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: input_after -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -388,7 +388,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -406,7 +406,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -424,7 +424,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_error.fd b/src/frontends/xforms/forms/form_error.fd index 34df475736..ae80b8d469 100644 --- a/src/frontends/xforms/forms/form_error.fd +++ b/src/frontends/xforms/forms/form_error.fd @@ -63,7 +63,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_South FL_South name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_ert.fd b/src/frontends/xforms/forms/form_ert.fd index 9aed80c36f..d94e18086b 100644 --- a/src/frontends/xforms/forms/form_ert.fd +++ b/src/frontends/xforms/forms/form_ert.fd @@ -81,7 +81,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: radio_open -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -99,7 +99,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: radio_collapsed -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -117,7 +117,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: radio_inlined -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -153,7 +153,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -171,7 +171,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -189,7 +189,7 @@ shortcut: ^M resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_index.fd b/src/frontends/xforms/forms/form_index.fd index efad37bfe1..72d4c05883 100644 --- a/src/frontends/xforms/forms/form_index.fd +++ b/src/frontends/xforms/forms/form_index.fd @@ -45,7 +45,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_key -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -63,7 +63,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 -------------------- @@ -81,7 +81,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -99,7 +99,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -117,7 +117,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_ref.fd b/src/frontends/xforms/forms/form_ref.fd index e3e8efec9c..ede6b7cf1c 100644 --- a/src/frontends/xforms/forms/form_ref.fd +++ b/src/frontends/xforms/forms/form_ref.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NorthWest FL_SouthEast name: browser_refs -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: button_update -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: check_sort -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -172,7 +172,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_NorthWest FL_NorthEast name: choice_document -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 align: FL_ALIGN_LEFT @@ -209,7 +209,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_South FL_South name: input_ref -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -227,7 +227,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_South FL_South name: choice_format -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -245,7 +245,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: button_go -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_toc.fd b/src/frontends/xforms/forms/form_toc.fd index a6ea906ed6..a08212c932 100644 --- a/src/frontends/xforms/forms/form_toc.fd +++ b/src/frontends/xforms/forms/form_toc.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NorthWest FL_SouthEast name: browser_toc -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_update -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: choice_toc_type -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_url.fd b/src/frontends/xforms/forms/form_url.fd index 86b3e27431..a2bcd43ca2 100644 --- a/src/frontends/xforms/forms/form_url.fd +++ b/src/frontends/xforms/forms/form_url.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_url -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_name -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_html -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 ============================== diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 6ac5408a22..7217ea5f10 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -9,6 +9,32 @@ * insetfloat.C: * insetwrap.C: TocItem changed API (bug 913) +2003-02-21 Angus Leeming + + * insetcollapsable.[Ch] (cache, edit): + * insetbutton.[Ch] (cache, edit): new methods to cache the + BufferView in the draw method. + + * insetcommand.[Ch]: implement a new class, InsetCommandMailer, to + simplify comunication between InsetCommand-derived classes and + the Dialogs. + + * insetbibitem.[Ch]: + * insetbibtex.[Ch]: + * insetcite.[Ch]: + * inseterror.[Ch]: + * insetfloatlist.[Ch]: + * insetindex.[Ch]: + * insetref.[Ch]: + * insettoc.[Ch]: + * inseturl.[Ch]: small changes to reflect the new interface to the + Dialogs code. + + * mailinset.[Ch]: new files. Base class to InsetCommandMailer and + other, similar classes. + + * Makefile.am: add new files. + 2003-02-21 Angus Leeming * updatableinset.h (setView, view): remove. diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 98871f3f6b..9476738dee 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -13,6 +13,8 @@ EXTRA_DIST = \ insettheorem.h libinsets_la_SOURCES = \ + mailinset.C \ + mailinset.h \ ExternalTemplate.C \ ExternalTemplate.h \ inset.C \ diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 2e569cd048..513a4efd74 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -15,8 +15,6 @@ #include "lyxlex.h" #include "frontends/font_metrics.h" -#include "frontends/LyXView.h" -#include "frontends/Dialogs.h" #include "support/lstrings.h" @@ -35,6 +33,13 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p) } +InsetBibitem::~InsetBibitem() +{ + InsetCommandMailer mailer("bibitem", *this); + mailer.hideDialog(); +} + + Inset * InsetBibitem::clone(Buffer const &, bool) const { InsetBibitem * b = new InsetBibitem(params()); @@ -91,9 +96,10 @@ string const InsetBibitem::getScreenLabel(Buffer const *) const } -void InsetBibitem::edit(BufferView * bv, int, int, mouse_button::state) +void InsetBibitem::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showBibitem(this); + InsetCommandMailer mailer("bibitem", *this); + mailer.showDialog(); } diff --git a/src/insets/insetbibitem.h b/src/insets/insetbibitem.h index 62408b63b4..105f23ed46 100644 --- a/src/insets/insetbibitem.h +++ b/src/insets/insetbibitem.h @@ -27,6 +27,8 @@ public: /// InsetBibitem(InsetCommandParams const &); /// + ~InsetBibitem(); + /// Inset * clone(Buffer const &, bool same_id = false) const; /** Currently \bibitem is used as a LyX2.x command, so we need this method. diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index da263a4969..95c97a5250 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -12,13 +12,9 @@ #include "insetbibtex.h" #include "buffer.h" -#include "BufferView.h" #include "debug.h" #include "gettext.h" -#include "frontends/LyXView.h" -#include "frontends/Dialogs.h" - #include "support/filetools.h" #include "support/path.h" #include "support/os.h" @@ -41,6 +37,13 @@ InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool) {} +InsetBibtex::~InsetBibtex() +{ + InsetCommandMailer mailer("bibtex", *this); + mailer.hideDialog(); +} + + string const InsetBibtex::getScreenLabel(Buffer const *) const { return _("BibTeX Generated References"); @@ -185,9 +188,10 @@ void InsetBibtex::fillWithBibKeys } -void InsetBibtex::edit(BufferView * bv, int, int, mouse_button::state) +void InsetBibtex::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showBibtex(this); + InsetCommandMailer mailer("bibtex", *this); + mailer.showDialog(); } diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 0efae323f9..7c7b2676ef 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -25,6 +25,8 @@ public: /// InsetBibtex(InsetCommandParams const &, bool same_id = false); /// + ~InsetBibtex(); + /// Inset * clone(Buffer const &, bool same_id = false) const { return new InsetBibtex(params(), same_id); } diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index 832dae795c..13c399043f 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -16,6 +16,7 @@ #include "insetbutton.h" #include "debug.h" #include "BufferView.h" +#include "frontends/LyXView.h" #include "frontends/Painter.h" #include "support/LAssert.h" #include "lyxfont.h" @@ -95,6 +96,7 @@ void InsetButton::draw(BufferView * bv, LyXFont const &, int baseline, float & x, bool) const { lyx::Assert(bv); + cache(bv); Painter & pain = bv->painter(); // Draw it as a box with the LaTeX text @@ -112,3 +114,15 @@ void InsetButton::draw(BufferView * bv, LyXFont const &, x += width(bv, font); } + + +void InsetButton::cache(BufferView * bv) const +{ + view_ = bv->owner()->view(); +} + + +BufferView * InsetButton::view() const +{ + return view_.get(); +} diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index 1b90a3b255..6d5b872e39 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -17,6 +17,7 @@ #include "inset.h" #include "LString.h" +#include /** Used to provide an inset that looks like a button. */ @@ -32,8 +33,14 @@ public: void draw(BufferView *, LyXFont const &, int, float &, bool) const; protected: + /// + virtual void cache(BufferView *) const; + /// + virtual BufferView * view() const; /// This should provide the text for the button virtual string const getScreenLabel(Buffer const *) const = 0; +private: + mutable boost::weak_ptr view_; }; #endif diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 9df8737b02..9d9db5b0df 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -11,24 +11,14 @@ #include - #include "insetcite.h" #include "buffer.h" #include "BufferView.h" #include "LaTeXFeatures.h" -#include "frontends/LyXView.h" -#include "debug.h" -#include "gettext.h" #include "frontends/controllers/biblio.h" -#include "frontends/Dialogs.h" -#include "support/filetools.h" #include "support/lstrings.h" -#include "support/path.h" -#include "support/os.h" -#include "support/lstrings.h" -#include "support/LAssert.h" #include @@ -235,6 +225,13 @@ InsetCitation::InsetCitation(InsetCommandParams const & p, bool) {} +InsetCitation::~InsetCitation() +{ + InsetCommandMailer mailer("citation", *this); + mailer.hideDialog(); +} + + string const InsetCitation::generateLabel(Buffer const * buffer) const { string const before = string(); @@ -326,7 +323,8 @@ void InsetCitation::edit(BufferView * bv, int, int, mouse_button::state) // buffer but doing some real work. setLoadingBuffer(bv->buffer(), false); - bv->owner()->getDialogs().showCitation(this); + InsetCommandMailer mailer("citation", *this); + mailer.showDialog(); } diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 409464ffd8..3cec12c54d 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -23,6 +23,8 @@ public: /// InsetCitation(InsetCommandParams const &, bool same_id = false); /// + ~InsetCitation(); + /// Inset * clone(Buffer const &, bool same_id = false) const { return new InsetCitation(params(), same_id); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 5ae85084a0..b01fd7082b 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -27,6 +27,7 @@ #include "frontends/font_metrics.h" #include "frontends/Painter.h" +#include "frontends/LyXView.h" #include "support/LOstream.h" #include "support/lstrings.h" @@ -716,3 +717,17 @@ void InsetCollapsable::addPreview(grfx::PreviewLoader & loader) const { inset.addPreview(loader); } + + +void InsetCollapsable::cache(BufferView * bv) const +{ + view_ = bv->owner()->view(); +} + + +BufferView * InsetCollapsable::view() const +{ + return view_.get(); +} + + diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index f29428a3f7..00bc07abff 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -20,6 +20,8 @@ #include "lyxfont.h" #include "LColor.h" +#include + class Painter; class LyXText; class Paragraph; @@ -191,6 +193,11 @@ public: void addPreview(grfx::PreviewLoader &) const; protected: + /// + virtual void cache(BufferView *) const; + /// + virtual BufferView * view() const; + /// int ascent_collapsed() const; /// @@ -243,6 +250,8 @@ private: bool in_update; /// mutable bool first_after_edit; + /// + mutable boost::weak_ptr view_; }; #endif diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 27324e97e4..3b2874b036 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -15,6 +15,8 @@ #include "insetcommand.h" #include "debug.h" #include "frontends/Painter.h" +#include "Lsstream.h" +#include "lyxlex.h" using std::ostream; using std::endl; @@ -57,3 +59,44 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const { return 0; } + + +InsetCommandMailer::InsetCommandMailer(string const & name, + InsetCommand & inset) + : name_(name), inset_(inset) +{} + + +string const InsetCommandMailer::inset2string() const +{ + return params2string(inset_.params()); +} + + +void InsetCommandMailer::string2params(string const & in, + InsetCommandParams & params) +{ + params.setCmdName(string()); + params.setContents(string()); + params.setOptions(string()); + + if (in.empty()) + return; + + istringstream data(in); + LyXLex lex(0,0); + lex.setStream(data); + + params.read(lex); +} + + +string const +InsetCommandMailer::params2string(InsetCommandParams const & params) +{ + ostringstream data; + params.write(data); + data << "\\end_inset\n"; + + return data.str(); +} diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 8ddee55aa2..387363a7d2 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -16,7 +16,7 @@ #include "insetbutton.h" #include "insetcommandparams.h" -#include +#include "mailinset.h" #include // Created by Alejandro 970222 @@ -33,8 +33,6 @@ public: explicit InsetCommand(InsetCommandParams const &, bool same_id = false); /// - virtual ~InsetCommand() { hideDialog(); } - /// void write(Buffer const *, std::ostream & os) const { p_.write(os); } /// @@ -72,12 +70,33 @@ public: InsetCommandParams const & params() const { return p_; } /// void setParams(InsetCommandParams const &); - /// - boost::signal0 hideDialog; private: /// InsetCommandParams p_; }; + +class InsetCommandMailer : public MailInset { +public: + /// + InsetCommandMailer(string const & name, InsetCommand & inset); + /// + virtual Inset & inset() const { return inset_; } + /// + virtual string const & name() const { return name_; } + /// + virtual string const inset2string() const; + /// + static void string2params(string const &, InsetCommandParams &); + /// + static string const params2string(InsetCommandParams const &); +private: + /// + string const name_; + /// + InsetCommand & inset_; +}; + + #endif diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index b887c52e3e..08b9b4179e 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -19,6 +19,7 @@ #include "frontends/LyXView.h" #include "frontends/Painter.h" #include "frontends/Dialogs.h" +#include "support/LAssert.h" using std::ostream; @@ -29,6 +30,13 @@ InsetError::InsetError(string const & str, bool) {} +InsetError::~InsetError() +{ + if (view()) + view()->owner()->getDialogs().hide("error"); +} + + int InsetError::ascent(BufferView *, LyXFont const & font) const { LyXFont efont; @@ -56,6 +64,9 @@ int InsetError::width(BufferView *, LyXFont const & font) const void InsetError::draw(BufferView * bv, LyXFont const & font, int baseline, float & x, bool) const { + lyx::Assert(bv); + cache(bv); + Painter & pain = bv->painter(); LyXFont efont; efont.setSize(font.size()).decSize(); @@ -85,7 +96,7 @@ string const InsetError::editMessage() const void InsetError::edit(BufferView * bv, int, int, mouse_button::state) { - bv->owner()->getDialogs().showError(this); + bv->owner()->getDialogs().show("error", getContents(), this); } diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 4d40f04e4f..e24aa22bd2 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -16,8 +16,6 @@ #include "inset.h" #include "LString.h" -#include - /** Used for error messages from LaTeX runs. The edit-operation opens a @@ -29,7 +27,7 @@ public: explicit InsetError(string const &, bool same_id = false); /// - ~InsetError() { hideDialog(); } + ~InsetError(); /// int ascent(BufferView *, LyXFont const &) const; /// @@ -70,8 +68,6 @@ public: bool directWrite() const { return true; }; /// string const & getContents() const { return contents; } - /// - boost::signal0 hideDialog; private: /// string contents; diff --git a/src/insets/insetert.C b/src/insets/insetert.C index eece0b9846..7f0c4a2bf6 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -10,7 +10,6 @@ */ #include - #include "insetert.h" #include "insettext.h" @@ -31,6 +30,8 @@ #include "frontends/LyXView.h" #include "support/LOstream.h" +#include "support/LAssert.h" +#include "support/lstrings.h" using std::ostream; @@ -104,7 +105,8 @@ InsetERT::InsetERT(BufferParams const & bp, InsetERT::~InsetERT() { - hideDialog(); + InsetERTMailer mailer(*this); + mailer.hideDialog(); } @@ -493,8 +495,8 @@ string const InsetERT::get_new_label() const pos_type const max_length = 15; pos_type const p_siz = inset.paragraph()->size(); pos_type const n = min(max_length, p_siz); - int i = 0; - int j = 0; + pos_type i = 0; + pos_type j = 0; for(; i < n && j < p_siz; ++j) { if (inset.paragraph()->isInset(j)) continue; @@ -563,6 +565,9 @@ int InsetERT::width(BufferView * bv, LyXFont const & font) const void InsetERT::draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool cleared) const { + lyx::Assert(bv); + cache(bv); + Painter & pain = bv->painter(); button_length = width_collapsed(); @@ -651,9 +656,10 @@ void InsetERT::status(BufferView * bv, ERTStatus const st) const } -bool InsetERT::showInsetDialog(BufferView * bv) const +bool InsetERT::showInsetDialog(BufferView *) const { - bv->owner()->getDialogs().showERT(const_cast(this)); + InsetERTMailer mailer(const_cast(*this)); + mailer.showDialog(); return true; } @@ -718,3 +724,32 @@ void InsetERT::update(BufferView * bv, LyXFont const & font, } InsetCollapsable::update(bv, font, reinit); } + + +InsetERTMailer::InsetERTMailer(InsetERT & inset) + : name_("ert"), inset_(inset) +{} + + +string const InsetERTMailer::inset2string() const +{ + return params2string(inset_.status()); +} + + +void InsetERTMailer::string2params(string const & in, + InsetERT::ERTStatus & status) +{ + status = InsetERT::Collapsed; + if (in.empty()) + return; + + status = static_cast(strToInt(in)); +} + + +string const +InsetERTMailer::params2string(InsetERT::ERTStatus status) +{ + return tostr(status); +} diff --git a/src/insets/insetert.h b/src/insets/insetert.h index a03d9877b9..9919ae1249 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -16,8 +16,6 @@ #include "insetcollapsable.h" -#include - /** A collapsable text inset for LaTeX insertions. To write full ert (including styles and other insets) in a given @@ -70,8 +68,6 @@ public: /// EDITABLE editable() const; /// - boost::signal0 hideDialog; - /// int latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; /// @@ -155,4 +151,29 @@ private: mutable ERTStatus status_; }; + +#include "mailinset.h" + +class InsetERTMailer : public MailInset { +public: + /// + InsetERTMailer(InsetERT & inset); + /// + virtual Inset & inset() const { return inset_; } + /// + virtual string const & name() const { return name_; } + /// + virtual string const inset2string() const; + /// + static void string2params(string const &, InsetERT::ERTStatus &); + /// + static string const params2string(InsetERT::ERTStatus); +private: + /// + string const name_; + /// + InsetERT & inset_; +}; + + #endif diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index ad85096c8d..f6b49cef57 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -41,6 +41,13 @@ InsetFloatList::InsetFloatList(string const & type) } +InsetFloatList::~InsetFloatList() +{ + InsetCommandMailer mailer("toc", *this); + mailer.hideDialog(); +} + + string const InsetFloatList::getScreenLabel(Buffer const * buf) const { FloatList const & floats = buf->params.getLyXTextClass().floats(); @@ -89,9 +96,10 @@ void InsetFloatList::read(Buffer const * buf, LyXLex & lex) } -void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state) +void InsetFloatList::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showTOC(this); + InsetCommandMailer mailer("toc", *this); + mailer.showDialog(); } diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index f875133377..a5b7f68442 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -24,6 +24,8 @@ public: /// InsetFloatList(string const & type); /// + ~InsetFloatList(); + /// Inset * clone(Buffer const &, bool = false) const { return new InsetFloatList(getCmdName()); } diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index d863960194..29d2aa4b80 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -25,15 +25,23 @@ InsetIndex::InsetIndex(InsetCommandParams const & p, bool) {} +InsetIndex::~InsetIndex() +{ + InsetCommandMailer mailer("index", *this); + mailer.hideDialog(); +} + + string const InsetIndex::getScreenLabel(Buffer const *) const { return _("Idx"); } -void InsetIndex::edit(BufferView * bv, int, int, mouse_button::state) +void InsetIndex::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showIndex(this); + InsetCommandMailer mailer("index", *this); + mailer.showDialog(); } diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index db4a138713..3f13751563 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -24,6 +24,8 @@ public: /// InsetIndex(InsetCommandParams const &, bool same_id = false); /// + ~InsetIndex(); + /// virtual Inset * clone(Buffer const &, bool same_id = false) const { return new InsetIndex(params(), same_id); } diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 4da8535664..7f0e3f1b8f 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -28,13 +28,22 @@ InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool) {} +InsetRef::~InsetRef() +{ + InsetCommandMailer mailer("ref", *this); + mailer.hideDialog(); +} + + void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button) { // FuncRequestually trigger dialog with button 3 not 1 if (button == mouse_button::button3) bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents())); - else if (button == mouse_button::button1) - bv->owner()->getDialogs().showRef(this); + else if (button == mouse_button::button1) { + InsetCommandMailer mailer("ref", *this); + mailer.showDialog(); + } } diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 87b8716593..9a5dac30df 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -38,6 +38,8 @@ public: /// InsetRef(InsetCommandParams const &, Buffer const &, bool same_id = false); /// + ~InsetRef(); + /// virtual Inset * clone(Buffer const & buffer, bool same_id = false) const { return new InsetRef(params(), buffer, same_id); } diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 277212db00..0c64eb5013 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -22,6 +22,18 @@ using std::vector; using std::ostream; +InsetTOC::InsetTOC(InsetCommandParams const & p, bool same_id) + : InsetCommand(p, same_id) +{} + + +InsetTOC::~InsetTOC() +{ + InsetCommandMailer mailer("toc", *this); + mailer.hideDialog(); +} + + string const InsetTOC::getScreenLabel(Buffer const *) const { string const cmdname(getCmdName()); @@ -41,9 +53,10 @@ Inset::Code InsetTOC::lyxCode() const } -void InsetTOC::edit(BufferView * bv, int, int, mouse_button::state) +void InsetTOC::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showTOC(this); + InsetCommandMailer mailer("toc", *this); + mailer.showDialog(); } diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 50d0f7c1d3..142c8de333 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -20,8 +20,9 @@ class InsetTOC : public InsetCommand { public: /// - InsetTOC(InsetCommandParams const & p, bool same_id = false) - : InsetCommand(p, same_id) {} + InsetTOC(InsetCommandParams const &, bool same_id = false); + /// + ~InsetTOC(); /// virtual Inset * clone(Buffer const &, bool same_id = false) const { return new InsetTOC(params(), same_id); diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 0ad00a3c67..60c2ab2a12 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -27,9 +27,17 @@ InsetUrl::InsetUrl(InsetCommandParams const & p, bool) {} -void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state) +InsetUrl::~InsetUrl() { - bv->owner()->getDialogs().showUrl(this); + InsetCommandMailer mailer("url", *this); + mailer.hideDialog(); +} + + +void InsetUrl::edit(BufferView *, int, int, mouse_button::state) +{ + InsetCommandMailer mailer("url", *this); + mailer.showDialog(); } diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index 3e8f712188..4f5d2693a4 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -25,6 +25,8 @@ public: explicit InsetUrl(InsetCommandParams const &, bool same_id = false); /// + ~InsetUrl(); + /// virtual Inset * clone(Buffer const &, bool same_id = false) const { return new InsetUrl(params(), same_id); } diff --git a/src/insets/mailinset.C b/src/insets/mailinset.C new file mode 100644 index 0000000000..725ca45baf --- /dev/null +++ b/src/insets/mailinset.C @@ -0,0 +1,49 @@ +// -*- C++ -*- +/** + * \file mailinset.C + * 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 + +#include "mailinset.h" +#include "inset.h" +#include "BufferView.h" +#include "frontends/LyXView.h" +#include "frontends/Dialogs.h" +#include "Lsstream.h" + + +void MailInset::showDialog() const +{ + BufferView * bv = inset().view(); + if (!bv) + return; + + bv->owner()->getDialogs().show(name(), inset2string(), &inset()); +} + + +void MailInset::updateDialog() const +{ + BufferView * bv = inset().view(); + if (!bv) + return; + + bv->owner()->getDialogs().update(name(), inset2string()); +} + + +void MailInset::hideDialog() const +{ + BufferView * bv = inset().view(); + if (!bv) + return; + + bv->owner()->getDialogs().hide(name()); +} diff --git a/src/insets/mailinset.h b/src/insets/mailinset.h new file mode 100644 index 0000000000..965895deb9 --- /dev/null +++ b/src/insets/mailinset.h @@ -0,0 +1,43 @@ +// -*- C++ -*- +/** + * \file mailinset.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 MAILINSET_H +#define MAILINSET_H + + +#include "LString.h" + + +class Inset; + + +class MailInset { +public: + /// + virtual ~MailInset() {}; + /// + void showDialog() const; + /// + void updateDialog() const; + /// + void hideDialog() const; + /// + virtual string const inset2string() const = 0; + +protected: + /// + virtual Inset & inset() const = 0; + /// + virtual string const & name() const = 0; +}; + + +#endif // MAILINSET_H diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 2b0a43513a..904070eb03 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -43,6 +43,8 @@ #include "ParagraphParameters.h" #include "insets/insetcommand.h" +#include "insets/inseterror.h" +#include "insets/insetert.h" #include "insets/insettabular.h" #include "mathed/formulamacro.h" @@ -559,13 +561,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_REF_INSERT: code = Inset::REF_CODE; break; - case LFUN_CITATION_CREATE: - case LFUN_CITATION_INSERT: - code = Inset::CITE_CODE; - break; - case LFUN_INSERT_BIBTEX: + case LFUN_BIBTEX_APPLY: code = Inset::BIBTEX_CODE; break; + case LFUN_CITATION_APPLY: + code = Inset::CITE_CODE; + break; case LFUN_INDEX_INSERT: code = Inset::INDEX_CODE; break; @@ -1047,27 +1048,10 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) break; case LFUN_TOCVIEW: -#if 0 - case LFUN_LOFVIEW: - case LFUN_LOTVIEW: - case LFUN_LOAVIEW: -#endif { - InsetCommandParams p; - -#if 0 - if (action == LFUN_TOCVIEW) -#endif - p.setCmdName("tableofcontents"); -#if 0 - else if (action == LFUN_LOAVIEW) - p.setCmdName("listof{algorithm}{List of Algorithms}"); - else if (action == LFUN_LOFVIEW) - p.setCmdName("listoffigures"); - else - p.setCmdName("listoftables"); -#endif - owner->getDialogs().createTOC(p.getAsString()); + InsetCommandParams p("tableofcontents"); + string const data = InsetCommandMailer::params2string(p); + owner->getDialogs().show("toc", data, 0); break; } @@ -1374,27 +1358,79 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) owner->getDialogs().showMathPanel(); break; - case LFUN_CITATION_CREATE: - { - InsetCommandParams p("cite"); - - if (!argument.empty()) { - // This should be set at source, ie when typing - // "citation-insert foo" in the minibuffer. - // Question: would pybibliographer also need to be - // changed. Suspect so. Leave as-is therefore. - if (contains(argument, "|")) { - p.setContents(token(argument, '|', 0)); - p.setOptions(token(argument, '|', 1)); - } else { - p.setContents(argument); - } - dispatch(FuncRequest(view(), LFUN_CITATION_INSERT, p.getAsString())); - } else - owner->getDialogs().createCitation(p.getAsString()); + case LFUN_DIALOG_SHOW_NEW_INSET: { + string const & name = argument; + string data; + if (name == "bibitem" || + name == "bibtex" || + name == "index" || + name == "ref" || + name == "toc" || + name == "url") { + InsetCommandParams p(name); + data = InsetCommandMailer::params2string(p); + } else if (name == "citation") { + InsetCommandParams p("cite"); + data = InsetCommandMailer::params2string(p); +// } else if (name == "error" || name == "ert") { +// // need do nothing special + } + owner->getDialogs().show(name, data, 0); } break; + case LFUN_DIALOG_SHOW_NEXT_INSET: { + } + break; + + case LFUN_DIALOG_UPDATE: { + string const & name = argument; + // Can only update a dialog connected to an existing inset + InsetBase * i = owner->getDialogs().getOpenInset(name); + if (!i) + break; + + if (name == "bibitem" || + name == "bibtex" || + name == "citation" || + name == "index" || + name == "ref" || + name == "toc" || + name == "url") { + InsetCommand * inset = dynamic_cast(i); + if (!inset) + break; + + InsetCommandMailer mailer(name, *inset); + mailer.updateDialog(); + + } else if (name == "error") { + InsetError * inset = dynamic_cast(i); + if (!inset) + break; + + owner->getDialogs().update("error", + inset->getContents()); + + } else if (name == "ert") { + InsetERT * inset = dynamic_cast(i); + if (!inset) + break; + + InsetERTMailer mailer(*inset); + mailer.updateDialog(); + } + } + break; + + case LFUN_DIALOG_HIDE: + owner ->getDialogs().hide(argument); + break; + + case LFUN_DIALOG_DISCONNECT_INSET: + owner->getDialogs().disconnect(argument); + break; + case LFUN_CHILDOPEN: { string const filename = diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 768593d128..c049d028af 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2003-02-21 Angus Leeming + + * formulabase.C (localDispatch): retire LFUN_REF_INSERT. Add + LFUN_DIALOG_SHOW_NEW_INSET "ref" and LFUN_REF_APPLY. The latter + is not yet safe. Posted some ideas to the list for further discussion. + + * ref_inset.C (dispatch): a first stab at activating the code + to display the reference dialog from within mathed. Not yet working. + 2003-02-14 Dekel Tsur * math_parser.C (parse1): Do not remove braces for {}^ diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 27a2df6176..f1b50471c0 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -51,7 +51,7 @@ #include "textpainter.h" #include "frontends/Dialogs.h" #include "intl.h" -#include "insets/insetcommandparams.h" +#include "insets/insetcommand.h" #include "ref_inset.h" using std::endl; @@ -795,31 +795,42 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) updateLocal(bv, true); break; - case LFUN_REF_INSERT: - //if (argument.empty()) { - // InsetCommandParams p("ref"); - // owner_->getDialogs().createRef(p.getAsString()); - //} else { - // InsetCommandParams p; - // p.setFromString(argument); + case LFUN_DIALOG_SHOW_NEW_INSET: { + string const & name = argument; + if (name == "ref") { + InsetCommandParams p(name); + string data = InsetCommandMailer::params2string(p); + bv->owner()->getDialogs().show(name, data, 0); + } else + result = UNDISPATCHED; + } + break; - // InsetRef * inset = new InsetRef(p, *buffer_); - // if (!insertInset(inset)) - // delete inset; - // else - // updateInset(inset, true); - //} - // - if (cmd.argument.empty()) { - InsetCommandParams p("ref"); - bv->owner()->getDialogs().createRef(p.getAsString()); + case LFUN_REF_APPLY: { + InsetCommandParams params; + InsetCommandMailer::string2params(argument, params); + + // It would be nice if RefInset could handle an + // InsetCommandParams arg, but for now we convert it to + // 'foo|++|bar|++|nonsense'. + string const tmp = params.getAsString(); + + InsetBase * base = + bv->owner()->getDialogs().getOpenInset("ref"); + if (base) { + RefInset * inset = dynamic_cast(base); + if (!inset) { + result = UNDISPATCHED; + break; + } + + *inset = RefInset(tmp); } else { - //mathcursor->handleNest(new InsetRef2); - //mathcursor->insert(arg); - mathcursor->insert(MathAtom(new RefInset(cmd.argument))); + mathcursor->insert(MathAtom(new RefInset(tmp))); } updateLocal(bv, true); - break; + } + break; default: result = UNDISPATCHED; diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index 9e3b5a8e30..98de8ee722 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -12,6 +12,8 @@ #include "gettext.h" #include "LaTeXFeatures.h" #include "debug.h" +#include "math_mathmlstream.h" +#include "Lsstream.h" RefInset::RefInset() @@ -39,8 +41,9 @@ void RefInset::infoize(std::ostream & os) const dispatch_result RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { + lyxerr << "RefInset::dispatch" << std::endl; + lyxerr << "dispatching " << cmd.argument << "\n"; switch (cmd.action) { - lyxerr << "dispatching " << cmd.argument << "\n"; case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { lyxerr << "trying to goto ref" << cell(0) << "\n"; @@ -49,8 +52,19 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) } if (cmd.button() == mouse_button::button1) { lyxerr << "trying to open ref" << cell(0) << "\n"; - // Eventually trigger dialog with button 3 not 1 - // cmd.view()->owner()->getDialogs()->showRef(this); + // Eventually trigger dialog with button 3 + // not 1 + ostringstream data; + WriteStream wsdata(data); + write(wsdata); + + lyxerr << "ref_inset dispatch.\n" + << "this " << this << "\n" + << "The data is "<< data.str() + << std::endl; + + cmd.view()->owner()->getDialogs(). + show("ref", data.str(), this); return DISPATCHED; } break; diff --git a/src/text3.C b/src/text3.C index 9de9251e6f..e37f2bf1dc 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1592,13 +1592,15 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_HTMLURL: { InsetCommandParams p("htmlurl"); - bv->owner()->getDialogs().createUrl(p.getAsString()); + string const data = InsetCommandMailer::params2string(p); + bv->owner()->getDialogs().show("url", data, 0); break; } case LFUN_URL: { InsetCommandParams p("url"); - bv->owner()->getDialogs().createUrl(p.getAsString()); + string const data = InsetCommandMailer::params2string(p); + bv->owner()->getDialogs().show("url", data, 0); break; }