From: Angus Leeming Date: Fri, 7 Mar 2003 18:44:57 +0000 (+0000) Subject: port the graphics dialog to the new scheme and get rid of the ControlInset X-Git-Tag: 1.6.10~17330 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=120c89f24fae05379fbdc8539d3cfae574c2aecd;p=features.git port the graphics dialog to the new scheme and get rid of the ControlInset template. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6382 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index d33faa1ec4..11c8a93ce2 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-03-05 Angus Leeming + + * ui/default.ui: use 'dialog-show-new-inset "graphics"' instead + of graphics-insert'. + 2003-03-06 Serge Winitzki * bind/sciword.bind: update for 1.3.x diff --git a/lib/ui/default.ui b/lib/ui/default.ui index bca98fcebc..0b732bc561 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -209,7 +209,7 @@ Menuset Separator Item "TeX|T" "ert-insert" Item "Minipage|p" "minipage-insert" - Item "Graphics...|G" "graphics-insert" + Item "Graphics...|G" "dialog-show-new-inset graphics" Item "Tabular Material...|b" "tabular-insert" Submenu "Floats|a" "insert_floats" Separator @@ -433,6 +433,6 @@ Toolbar Icon "marginalnote-insert" Icon "depth-increment" Separator - Icon "graphics-insert" + Icon "dialog-show-new-inset graphics" Icon "tabular-insert" End diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 21e40f877e..26a65e87ff 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -988,19 +988,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) // a tabular-inset break; - case LFUN_INSET_GRAPHICS: - { - Inset * new_inset = new InsetGraphics; - if (!insertInset(new_inset)) { - delete new_inset; - } else { - // this is need because you don't use a inset->Edit() - updateInset(new_inset, true); - new_inset->edit(bv_); - } - break; - } - case LFUN_LAYOUT_COPY: bv_->copyEnvironment(); break; diff --git a/src/ChangeLog b/src/ChangeLog index a823730dfd..30398d7b5c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,15 @@ -2003-03-05 Angus Leeming +2003-03-07 Angus Leeming + + * BufferView_pimpl.C (dispatch): + * LyXAction.C (init): + * ToolbarDefaults.C (init): + * commandtags.h: + * lyxfunc.C (getStatus): + remove LFUN_INSET_GRAPHICS. + + * factory.C (createInset): add "graphics" to LFUN_INSET_APPLY. + +2003-03-07 Angus Leeming * commandtags.h: * LyXAction.C (init): diff --git a/src/LyXAction.C b/src/LyXAction.C index 1db9faa68d..c15a482846 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -174,8 +174,6 @@ void LyXAction::init() N_("Remove all error boxes"), ReadOnly }, { LFUN_INSET_ERT, "ert-insert", N_("Insert a new ERT Inset"), Noop }, - { LFUN_INSET_GRAPHICS, "graphics-insert", - N_("Insert Graphics"), Noop }, { LFUN_FILE_INSERT, "file-insert", "", Noop }, { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop }, { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop }, diff --git a/src/ToolbarDefaults.C b/src/ToolbarDefaults.C index 224457e2be..86c5c151bb 100644 --- a/src/ToolbarDefaults.C +++ b/src/ToolbarDefaults.C @@ -85,7 +85,7 @@ void ToolbarDefaults::init() add(LFUN_MATH_MODE); add(SEPARATOR); - add(LFUN_INSET_GRAPHICS); +// add(LFUN_INSET_GRAPHICS); add(LFUN_TABULAR_INSERT); } diff --git a/src/commandtags.h b/src/commandtags.h index b64d711132..3b1969dcf6 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -233,7 +233,6 @@ enum kb_action { LFUN_DATE_INSERT, // jdblair 20000131 LFUN_LANGUAGE, // Dekel 20000203 LFUN_INSET_ERT, // Jug 20000218 - LFUN_INSET_GRAPHICS, // Lgb 20000226 LFUN_INSET_FOOTNOTE, // Jug 20000307 LFUN_PARAGRAPH_SPACING, // Lgb 20000411 LFUN_TABULAR_INSERT, // Jug 20000412 diff --git a/src/factory.C b/src/factory.C index 57e3070093..5e127756c3 100644 --- a/src/factory.C +++ b/src/factory.C @@ -26,6 +26,7 @@ #include "insets/insetexternal.h" #include "insets/insetfloat.h" #include "insets/insetfoot.h" +#include "insets/insetgraphics.h" #include "insets/insetinclude.h" #include "insets/insetindex.h" #include "insets/insetlabel.h" @@ -192,6 +193,14 @@ Inset * createInset(FuncRequest const & cmd) inset->setFromParams(iep); return inset; + } else if (name == "graphics") { + InsetGraphicsParams igp; + InsetGraphicsMailer::string2params(cmd.argument, igp); + InsetGraphics * inset = new InsetGraphics; + string const fpath = cmd.view()->buffer()->filePath(); + inset->setParams(igp, fpath); + return inset; + } else if (name == "include") { InsetInclude::Params iip; InsetIncludeMailer::string2params(cmd.argument, iip); diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 29f3bb1357..20e43e7198 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2003-03-07 Angus Leeming + + * Dialogs.h: remove showGraphics. + * guiapi.[Ch]: remove gui_showGraphics. + 2003-03-07 Angus Leeming * Dialogs.h: remove showMinipage, updateMinipage. diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index 745bdc13a7..73e90d5c19 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -23,7 +23,6 @@ class Dialog; class InsetBase; class LyXView; -class InsetGraphics; class InsetInfo; class Paragraph; class InsetTabular; @@ -86,8 +85,6 @@ public: void showFile(string const &); /// show all forked child processes void showForks(); - /// - void showGraphics(InsetGraphics *); /// show the LaTeX log or build file void showLogFile(); /// display the top-level maths panel diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index ce6179f0bd..acc4c90052 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,10 @@ +2003-03-07 Angus Leeming + + * ControlGraphics.[Ch]: rewrite to use the Dialog-based scheme. + + * ControlInset.{h, tmpl}: remove. + * Makefile.am: remove files. + 2003-03-07 Angus Leeming * ControlBibitem.[Ch]: diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 5daacdea2f..e87b57479d 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -18,6 +18,7 @@ #include "buffer.h" #include "BufferView.h" +#include "funcrequest.h" #include "gettext.h" #include "lyxrc.h" @@ -41,40 +42,32 @@ extern string system_lyxdir; extern string user_lyxdir; -ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d) - : ControlInset(lv, d) +ControlGraphics::ControlGraphics(Dialog & parent) + : Dialog::Controller(parent) {} -InsetGraphicsParams const ControlGraphics::getParams(string const &) +void ControlGraphics::initialiseParams(string const & data) { - return InsetGraphicsParams(); + InsetGraphicsParams params; + InsetGraphicsMailer::string2params(data, params); + params_.reset(new InsetGraphicsParams(params)); } -InsetGraphicsParams const -ControlGraphics::getParams(InsetGraphics const & inset) +void ControlGraphics::clearParams() { - return inset.params(); + params_.reset(); } -void ControlGraphics::applyParamsToInset() +void ControlGraphics::dispatchParams() { - // Set the parameters in the inset, it also returns true if the new - // parameters are different from what was in the inset already. - bool changed = inset()->setParams(params(), buffer()->filePath()); - - // Tell LyX we've got a change, and mark the document dirty, - // if it changed. - bufferview()->updateInset(inset(), changed); + string const lfun = InsetGraphicsMailer::params2string(params()); + kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); } -void ControlGraphics::applyParamsNoInset() -{} - - string const ControlGraphics::Browse(string const & in_name) { string const title = _("Select graphics file"); @@ -88,14 +81,15 @@ string const ControlGraphics::Browse(string const & in_name) pair dir1(_("Clipart|#C#c"), clipdir); pair dir2(_("Documents|#o#O"), string(lyxrc.document_path)); // Show the file browser dialog - return browseRelFile(in_name, buffer()->filePath(), + return browseRelFile(in_name, kernel().buffer()->filePath(), title, "*.*", false, dir1, dir2); } string const ControlGraphics::readBB(string const & file) { - string const abs_file = MakeAbsPath(file, buffer()->filePath()); + string const abs_file = + MakeAbsPath(file, kernel().buffer()->filePath()); // try to get it from the file, if possible. Zipped files are // unzipped in the readBB_from_PSFile-Function @@ -124,7 +118,7 @@ string const ControlGraphics::readBB(string const & file) bool ControlGraphics::isFilenameValid(string const & fname) const { // It may be that the filename is relative. - string const name = MakeAbsPath(fname, buffer()->filePath()); + string const name = MakeAbsPath(fname, kernel().buffer()->filePath()); return IsFileReadable(name); } diff --git a/src/frontends/controllers/ControlGraphics.h b/src/frontends/controllers/ControlGraphics.h index 279262c9c3..4f632fa91f 100644 --- a/src/frontends/controllers/ControlGraphics.h +++ b/src/frontends/controllers/ControlGraphics.h @@ -15,11 +15,7 @@ #define CONTROLGRAPHICS_H -#include "ControlInset.h" - -// needed to instatiate inset->hideDialog in ControlInset -#include "insets/insetgraphics.h" - +#include "Dialog.h" #include #include @@ -30,11 +26,22 @@ class LyXView; /** A controller for Graphics dialogs. */ -class ControlGraphics - : public ControlInset { +class ControlGraphics : public Dialog::Controller { public: /// - ControlGraphics(LyXView &, Dialogs &); + ControlGraphics(Dialog &); + /// + 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; } + /// + InsetGraphicsParams & params() { return *params_.get(); } + /// + InsetGraphicsParams const & params() const { return *params_.get(); } /// Browse for a file string const Browse(string const &); @@ -46,14 +53,8 @@ public: bool isFilenameValid(string const & fname) const; private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); /// - virtual void applyParamsNoInset(); - /// get the parameters from the string passed to createInset. - virtual InsetGraphicsParams const getParams(string const &); - /// get the parameters from the inset passed to showInset. - virtual InsetGraphicsParams const getParams(InsetGraphics const &); + boost::scoped_ptr params_; }; namespace frnt { diff --git a/src/frontends/controllers/ControlInset.h b/src/frontends/controllers/ControlInset.h deleted file mode 100644 index 99236cdc84..0000000000 --- a/src/frontends/controllers/ControlInset.h +++ /dev/null @@ -1,104 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlInset.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 - * - * ControlInset is to be used as a parent class for dialogs that display and - * can perhaps modify the contents of an individual inset. An example being the - * ubiquitous Citation dialog. - */ - -#ifndef CONTROLINSET_H -#define CONTROLINSET_H - -#include "ControlConnections.h" -#include "LString.h" - -#include - -class Inset; - -template -class ControlInset : public ControlConnectBD { -public: - /// - ControlInset(LyXView &, Dialogs &); - /// Allow the View access to the local copy. - Params & params(); - /// - Params const & params() const; - - /// Slots connected in the daughter classes c-tor. - /// Slot launching dialog to (possibly) create a new inset. - void createInset(string const &); - /// Slot launching dialog to an existing inset. - void showInset(Inset *); -protected: - /// Allow the daughter methods to access the inset. - Inset * inset() const; -private: - /** These 7 methods are all that the individual daughter classes - should need to instantiate. */ - - /// if the inset exists then do this... - virtual void applyParamsToInset() = 0; - /// else this... - virtual void applyParamsNoInset() = 0; - - /// get the parameters from the string passed to createInset. - virtual Params const getParams(string const &) = 0; - /// get the parameters from the inset passed to showInset. - virtual Params const getParams(Inset const &) = 0; - - /** Most derived classes won't need these two, so they default to empty. - */ - - /// set any daughter class-particular data on show(). - virtual void setDaughterParams() {} - /// clean-up any daughter class-particular data on hide(). - virtual void clearDaughterParams() {} - - /** Some dialogs may find it beneficial to disconnect from the inset - when the Apply button is pressed. E.g., doing this with the citation - dialog allows multiple citiations to be inserted easily. */ - virtual bool disconnectOnApply() { return false; } - - /// Instantiation of ControlButtons virtual methods. - - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); - /// Disconnect signals and hide View. - virtual void hide(); - /// Update the dialog. - virtual void update(); - - /** Instantiation of ControlConnectBD private virtual method. - Slot connected to update signal. */ - virtual void updateSlot(bool); - - /// Show the dialog. - void show(Params const &); - /// Connect signals - void connectInset(Inset * = 0); - - /// pointer to the inset passed through connectInset - Inset * inset_; - /// inset::hide connection. - boost::signals::connection ih_; - /** A local copy of the inset's params. - Memory is allocated only whilst the dialog is visible. - */ - Params * params_; - - /// is the dialog built ? - bool dialog_built_; -}; - -#include "ControlInset.tmpl" - -#endif // CONTROLINSET_H diff --git a/src/frontends/controllers/ControlInset.tmpl b/src/frontends/controllers/ControlInset.tmpl deleted file mode 100644 index 19189579b1..0000000000 --- a/src/frontends/controllers/ControlInset.tmpl +++ /dev/null @@ -1,196 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlInset.tmpl - * 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 - * - * ControlInset is a base class and so these templatised methods will be - * instantiated if this file is #included in the derived classes' .C file. - */ - -#include "ControlInset.h" - -#include "ButtonControllerBase.h" -#include "ViewBase.h" -#include "support/LAssert.h" - -#include - -template -ControlInset::ControlInset(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d), - inset_(0), params_(0), dialog_built_(false) -{} - - -template -void ControlInset::showInset(Inset * inset) -{ - if (inset == 0) return; // maybe we should Assert this? - - connectInset(inset); - show(getParams(*inset)); - - // The widgets may not be valid, so refresh the button controller - bc().refresh(); -} - - -template -void ControlInset::createInset(string const & arg) -{ - connectInset(); - - if (!arg.empty()) - bc().valid(); // so that the user can press Ok - - show(getParams(arg)); -} - - -template -void ControlInset::show(Params const & params) -{ - // paranoia check - if (params_) delete params_; - - params_ = new Params(params); - setDaughterParams(); - - if (emergency_exit_) { - hide(); - return; - } - - if (!dialog_built_) { - view().build(); - dialog_built_ = true; - } - - bc().readOnly(bufferIsReadonly()); - view().show(); -} - - -template -void ControlInset::update() -{ - // paranoia check - if (params_) delete params_; - - if (inset_) - params_ = new Params(getParams(*inset_)); - else - params_ = new Params(); - - if (emergency_exit_) { - hide(); - return; - } - - bc().readOnly(bufferIsReadonly()); - view().update(); - - // The widgets may not be valid, so refresh the button controller - bc().refresh(); -} - - -template -void ControlInset::hide() -{ - emergency_exit_ = false; - if (params_) { - delete params_; - params_ = 0; - } - inset_ = 0; - - clearDaughterParams(); - - ih_.disconnect(); - disconnect(); - view().hide(); -} - - -template -void ControlInset::apply() -{ - if (bufferIsReadonly()) - return; - - view().apply(); - - if (inset_) { - if (params() != getParams(*inset_)) { - applyParamsToInset(); - } - } else { - applyParamsNoInset(); - } - - if (disconnectOnApply() && !isClosing()) { - *params_ = getParams(string()); - inset_ = 0; - ih_.disconnect(); - - view().update(); - } -} - - -template -Params & ControlInset::params() -{ - lyx::Assert(params_); - return *params_; -} - - -template -Params const & ControlInset::params() const -{ - lyx::Assert(params_); - return *params_; -} - - -template -Inset * ControlInset::inset() const -{ - lyx::Assert(inset_); - return inset_; -} - - -template -void ControlInset::updateSlot(bool switched) -{ - if (switched) - hide(); - else - update(); -} - - -template -void ControlInset::connectInset(Inset * inset) -{ - // If connected to another inset, disconnect from it. - if (inset_) { - ih_.disconnect(); - inset_ = 0; - } - - if (inset) { - inset_ = inset; - ih_ = inset->hideDialog.connect( - boost::bind(&ControlInset::hide, this)); - } - connect(); -} diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 6751859cdd..fee313842d 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libcontrollers.la INCLUDES = -I$(top_srcdir)/src \ $(BOOST_INCLUDES) -EXTRA_DIST = ButtonController.tmpl ControlDialog.tmpl ControlInset.tmpl +EXTRA_DIST = ButtonController.tmpl ControlDialog.tmpl libcontrollers_la_SOURCES= \ Dialog.C \ @@ -62,7 +62,6 @@ libcontrollers_la_SOURCES= \ ControlGraphics.h \ ControlInclude.C \ ControlInclude.h \ - ControlInset.h \ ControlLog.C \ ControlLog.h \ ControlMath.C \ diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index de4d649120..0c1e8d9bee 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -57,12 +57,6 @@ void gui_ShowForks(Dialogs & d) } -void gui_ShowGraphics(InsetGraphics * ig, Dialogs & d) -{ - d.showGraphics(ig); -} - - void gui_ShowLogFile(Dialogs & d) { d.showLogFile(); diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index 6e7a522f74..71049dda34 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -16,7 +16,6 @@ #include "LString.h" class Dialogs; -class InsetGraphics; class InsetTabular; extern "C" { @@ -29,7 +28,6 @@ void gui_SetUserFreeFont(Dialogs &); void gui_ShowDocument(Dialogs &); void gui_ShowFile(string const &, Dialogs &); void gui_ShowForks(Dialogs &); -void gui_ShowGraphics(InsetGraphics *, Dialogs &); void gui_ShowLogFile(Dialogs &); void gui_ShowMathPanel(Dialogs &); void gui_ShowParagraph(Dialogs &); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 689b03bf9b..16639aeb42 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -3,6 +3,16 @@ * QPrefs.C: * QPrefSpellcheckerModule.ui: Add 'hspell' option. +2003-03-07 Angus Leeming + + * Dialogs.C: + * Dialogs2.C: + * Dialogs_impl.h: remove graphics dialog. + + * Dialogs3.C: add graphics dialog. + + * QGraphics.[Ch]: changes to use the new Dialog-based scheme. + 2003-03-07 Angus Leeming * Dialogs.C: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 58f3987104..05caf4c106 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -31,7 +31,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) character(lv, d), document(lv, d), file(lv, d), - graphics(lv, d), logfile(lv, d), paragraph(lv, d), prefs(lv, d), diff --git a/src/frontends/qt2/Dialogs2.C b/src/frontends/qt2/Dialogs2.C index 45ad0bdee4..dfcab7707b 100644 --- a/src/frontends/qt2/Dialogs2.C +++ b/src/frontends/qt2/Dialogs2.C @@ -55,12 +55,6 @@ void Dialogs::showForks() {} -void Dialogs::showGraphics(InsetGraphics * ig) -{ - pimpl_->graphics.controller().showInset(ig); -} - - void Dialogs::showLogFile() { pimpl_->logfile.controller().show(); diff --git a/src/frontends/qt2/Dialogs3.C b/src/frontends/qt2/Dialogs3.C index a919a66945..8c5445ee33 100644 --- a/src/frontends/qt2/Dialogs3.C +++ b/src/frontends/qt2/Dialogs3.C @@ -19,6 +19,7 @@ #include "ControlERT.h" #include "ControlExternal.h" #include "ControlFloat.h" +#include "ControlGraphics.h" #include "ControlInclude.h" #include "ControlMinipage.h" #include "ControlRef.h" @@ -43,6 +44,8 @@ // of the Qt headers, those most fucked up of disgusting ratholes. // But I won't. #undef signals +#include "QGraphics.h" +#include "QGraphicsDialog.h" #include "QInclude.h" #include "QIncludeDialog.h" #include "QIndex.h" @@ -79,8 +82,8 @@ namespace { char const * const dialognames[] = { "bibitem", "bibtex", "citation", "error", "ert", "external", "float", - "include", "index", "label", "minipage", - "ref", "toc", "url", "wrap" }; + "graphics", "include", "index", "label", + "minipage", "ref", "toc", "url", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -140,6 +143,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlFloat(*dialog)); dialog->setView(new QFloat(*dialog)); dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "graphics") { + dialog->setController(new ControlGraphics(*dialog)); + dialog->setView(new QGraphics(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); } else if (name == "include") { dialog->setController(new ControlInclude(*dialog)); dialog->setView(new QInclude(*dialog)); diff --git a/src/frontends/qt2/Dialogs_impl.h b/src/frontends/qt2/Dialogs_impl.h index ad6339edbd..3cc47d5ce7 100644 --- a/src/frontends/qt2/Dialogs_impl.h +++ b/src/frontends/qt2/Dialogs_impl.h @@ -19,8 +19,6 @@ #include "ControlCharacter.h" #include "ControlDocument.h" #include "ControlForks.h" -#include "ControlGraphics.h" -#include "insets/insetgraphicsParams.h" #include "ControlLog.h" #include "ControlParagraph.h" #include "ControlPrefs.h" @@ -47,8 +45,6 @@ // of the Qt headers, those most fucked up of disgusting ratholes. // But I won't. #undef signals -#include "QGraphics.h" -#include "QGraphicsDialog.h" #include "QLog.h" #include "QLogDialog.h" #include "QParagraph.h" @@ -100,9 +96,6 @@ DocumentDialog; typedef GUI FileDialog; -typedef GUI -GraphicsDialog; - typedef GUI LogFileDialog; @@ -150,7 +143,6 @@ struct Dialogs::Impl { CharacterDialog character; DocumentDialog document; FileDialog file; - GraphicsDialog graphics; LogFileDialog logfile; ParagraphDialog paragraph; PrefsDialog prefs; diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 105583e550..f644acb7fe 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -43,11 +43,11 @@ using std::vector; using std::endl; -typedef Qt2CB > base_class; +typedef QController > base_class; -QGraphics::QGraphics() - : base_class(qt_("LyX: Insert Graphics")) +QGraphics::QGraphics(Dialog & parent) + : base_class(parent, qt_("LyX: Insert Graphics")) { } diff --git a/src/frontends/qt2/QGraphics.h b/src/frontends/qt2/QGraphics.h index 12a781d4ab..5b2ba98941 100644 --- a/src/frontends/qt2/QGraphics.h +++ b/src/frontends/qt2/QGraphics.h @@ -14,21 +14,21 @@ #define QGRAPHICS_H -#include "insets/insetgraphics.h" -#include "Qt2Base.h" +#include "QDialogView.h" + class ControlGraphics; class QGraphicsDialog; /// class QGraphics - : public Qt2CB > + : public QController > { public: /// friend class QGraphicsDialog; /// - QGraphics(); + QGraphics(Dialog &); protected: virtual bool isValid(); private: diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 85e6838cc5..3cc072a820 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,14 @@ +2003-03-07 Angus Leeming + + * Dialogs.C: + * Dialogs2.C: + * Dialogs_impl.h: remove graphics dialog. + + * Dialogs3.C: add graphics dialog. + + * FormGraphics.[Ch]: + * forms/form_graphics.fd: changes to use the new Dialog-based scheme. + 2003-03-07 Angus Leeming * Dialogs.C: diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 7c900ac5b0..8ed62635b2 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -32,7 +32,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) document(lv, d), file(lv, d), forks(lv, d), - graphics(lv, d), logfile(lv, d), mathpanel(lv, d), paragraph(lv, d), diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index 2b0913266a..b54b6ec09a 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -57,12 +57,6 @@ void Dialogs::showForks() } -void Dialogs::showGraphics(InsetGraphics * ig) -{ - pimpl_->graphics.controller().showInset(ig); -} - - void Dialogs::showLogFile() { pimpl_->logfile.controller().show(); diff --git a/src/frontends/xforms/Dialogs3.C b/src/frontends/xforms/Dialogs3.C index d77daafb03..aa46ffec7f 100644 --- a/src/frontends/xforms/Dialogs3.C +++ b/src/frontends/xforms/Dialogs3.C @@ -22,6 +22,7 @@ #include "ControlERT.h" #include "ControlExternal.h" #include "ControlFloat.h" +#include "ControlGraphics.h" #include "ControlInclude.h" #include "ControlMinipage.h" #include "ControlRef.h" @@ -42,6 +43,8 @@ #include "forms/form_external.h" #include "FormFloat.h" #include "forms/form_float.h" +#include "FormGraphics.h" +#include "forms/form_graphics.h" #include "FormInclude.h" #include "forms/form_include.h" #include "FormMinipage.h" @@ -76,15 +79,11 @@ typedef ButtonController 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", "external", "float", - "include", "index", "label", "minipage", - "ref", "toc", "url", "wrap" }; + "graphics", "include", "index", "label", + "minipage", "ref", "toc", "url", "wrap" }; + char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -144,6 +143,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlFloat(*dialog)); dialog->setView(new FormFloat(*dialog)); dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); + } else if (name == "graphics") { + dialog->setController(new ControlGraphics(*dialog)); + dialog->setView(new FormGraphics(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); } else if (name == "include") { dialog->setController(new ControlInclude(*dialog)); dialog->setView(new FormInclude(*dialog)); diff --git a/src/frontends/xforms/Dialogs_impl.h b/src/frontends/xforms/Dialogs_impl.h index 553a04ab3c..2dc7c7a851 100644 --- a/src/frontends/xforms/Dialogs_impl.h +++ b/src/frontends/xforms/Dialogs_impl.h @@ -41,10 +41,6 @@ #include "FormForks.h" #include "forms/form_forks.h" -#include "ControlGraphics.h" -#include "FormGraphics.h" -#include "forms/form_graphics.h" - #include "ControlLog.h" #include "FormLog.h" @@ -122,9 +118,6 @@ FileDialog; typedef GUI ForksDialog; -typedef GUI -GraphicsDialog; - typedef GUI LogFileDialog; @@ -178,7 +171,6 @@ struct Dialogs::Impl { DocumentDialog document; FileDialog file; ForksDialog forks; - GraphicsDialog graphics; LogFileDialog logfile; MathPanelDialog mathpanel; ParagraphDialog paragraph; diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 7a1791d062..f5a29a1c89 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -55,10 +55,10 @@ string defaultUnit("cm"); } // namespace anon -typedef FormCB > base_class; +typedef FormController > base_class; -FormGraphics::FormGraphics() - : base_class(_("Graphics"), false) +FormGraphics::FormGraphics(Dialog & parent) + : base_class(parent, _("Graphics"), false) {} diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index 49f3222e4f..06a3f7201f 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -14,7 +14,7 @@ #define FORMGRAPHICS_H -#include "FormBase.h" +#include "FormDialogView.h" #include @@ -28,10 +28,11 @@ struct FD_graphics_extra; /** This class provides an XForms implementation of the Graphics Dialog. */ -class FormGraphics : public FormCB > { +class FormGraphics + : public FormController > { public: /// - FormGraphics(); + FormGraphics(Dialog &); private: /** Redraw the form (on receipt of a Signal indicating, for example, diff --git a/src/frontends/xforms/forms/form_graphics.fd b/src/frontends/xforms/forms/form_graphics.fd index 1e99a19b87..97d467a24b 100644 --- a/src/frontends/xforms/forms/form_graphics.fd +++ b/src/frontends/xforms/forms/form_graphics.fd @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: ^M resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 =============== FORM =============== @@ -178,7 +178,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_NorthEast name: input_filename -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -196,7 +196,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_NorthEast FL_NorthEast name: button_browse -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -232,7 +232,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: check_draft -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -250,7 +250,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: check_nounzip -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -268,7 +268,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_lyxscale -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -286,7 +286,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_width -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -304,7 +304,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: choice_width -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -322,7 +322,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: choice_height -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -340,7 +340,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_aspectratio -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -358,7 +358,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_height -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -394,7 +394,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_East name: choice_display -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 =============== FORM =============== @@ -436,7 +436,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_bb_x1 -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -454,7 +454,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_bb_y1 -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -472,7 +472,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_bb_x0 -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -490,7 +490,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_bb_y0 -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -544,7 +544,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_North FL_North name: choice_bb_units -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -562,7 +562,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_NorthWest FL_NorthWest name: check_clip -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -580,7 +580,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_NorthWest FL_NorthWest name: button_getBB -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 =============== FORM =============== @@ -640,7 +640,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_special -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -676,7 +676,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: choice_origin -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -694,7 +694,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_subcaption -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -712,7 +712,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_North FL_North name: input_rotate_angle -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -730,7 +730,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_subcaption -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 ============================== diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d48758053e..c026d21c6d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,10 @@ 2003-03-07 Angus Leeming + * insetgraphics.[Ch]: define a new class InsetGraphicsMailer and use + it to communicate with the frontend dialogs. + +cd src2003-03-07 Angus Leeming + * insetexternal.C: remove operator== and operator!= for InsetExternal::Params. They were used only by the old controller scheme. diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index fede136172..932ac0af4e 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -64,20 +64,19 @@ TODO #include "buffer.h" #include "BufferView.h" #include "converter.h" -#include "format.h" -#include "frontends/Painter.h" -#include "lyxrc.h" -#include "frontends/font_metrics.h" #include "debug.h" +#include "format.h" +#include "funcrequest.h" #include "gettext.h" #include "LaTeXFeatures.h" #include "lyxlex.h" +#include "lyxrc.h" #include "frontends/Alert.h" #include "frontends/Dialogs.h" +#include "frontends/font_metrics.h" #include "frontends/LyXView.h" - -#include "frontends/controllers/helper_funcs.h" // getVectorFromString +#include "frontends/Painter.h" #include "support/LAssert.h" #include "support/filetools.h" @@ -213,8 +212,41 @@ Inset * InsetGraphics::clone(Buffer const & buffer, bool same_id) const InsetGraphics::~InsetGraphics() { - // Emits the hide signal to the dialog connected (if any) - hideDialog(); + InsetGraphicsMailer mailer(*this); + mailer.hideDialog(); +} + + +dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd) +{ + dispatch_result result = UNDISPATCHED; + + switch (cmd.action) { + case LFUN_INSET_MODIFY: { + InsetGraphicsParams p; + InsetGraphicsMailer::string2params(cmd.argument, p); + if (p.filename.empty()) + break; + + string const filepath = cmd.view()->buffer()->filePath(); + setParams(p, filepath); + cmd.view()->updateInset(this, true); + result = DISPATCHED; + } + break; + + case LFUN_INSET_DIALOG_UPDATE: { + InsetGraphicsMailer mailer(*this); + mailer.updateDialog(); + } + break; + + default: + result = DISPATCHED; + break; + } + + return result; } @@ -301,6 +333,12 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const } +BufferView * InsetGraphics::view() const +{ + return cache_->view.lock().get(); +} + + void InsetGraphics::draw(BufferView * bv, LyXFont const & font, int baseline, float & x, bool) const { @@ -394,9 +432,10 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, } -void InsetGraphics::edit(BufferView *bv, int, int, mouse_button::state) +void InsetGraphics::edit(BufferView *, int, int, mouse_button::state) { - bv->owner()->getDialogs().showGraphics(this); + InsetGraphicsMailer mailer(*this); + mailer.showDialog(); } @@ -833,3 +872,50 @@ InsetGraphicsParams const & InsetGraphics::params() const { return params_; } + + +string const InsetGraphicsMailer::name_("graphics"); + +InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset) + : inset_(inset) +{} + + +string const InsetGraphicsMailer::inset2string() const +{ + return params2string(inset_.params()); +} + + +void InsetGraphicsMailer::string2params(string const & in, + InsetGraphicsParams & params) +{ + params = InsetGraphicsParams(); + + istringstream data(in); + LyXLex lex(0,0); + lex.setStream(data); + + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token != name_) + return; + } + + InsetGraphics inset; + inset.readInsetGraphics(lex); + params = inset.params(); +} + + +string const +InsetGraphicsMailer::params2string(InsetGraphicsParams const & params) +{ + ostringstream data; + data << name_ << ' '; + params.Write(data); + data << "\\end_inset\n"; + + return data.str(); +} diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 412c1dcafc..ac13376ae9 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -18,8 +18,6 @@ #include "insets/inset.h" #include "insets/insetgraphicsParams.h" -// We need a signal here to hide an active dialog when we are deleted. -#include #include #include @@ -37,6 +35,8 @@ public: /// ~InsetGraphics(); /// + virtual dispatch_result localDispatch(FuncRequest const & cmd); + /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; @@ -88,12 +88,13 @@ public: /// Get the inset parameters, used by the GUIndependent dialog. InsetGraphicsParams const & params() const; - /** This signal is connected by our dialog and called when the inset - is deleted. - */ - boost::signal0 hideDialog; - private: + /// Returns the cached BufferView. + BufferView * view() const; + + /// + friend class InsetGraphicsMailer; + /// Is the image ready to draw, or should we display a message instead? bool imageIsDrawable() const; @@ -125,4 +126,28 @@ private: boost::scoped_ptr const cache_; }; + +#include "mailinset.h" + +class InsetGraphicsMailer : public MailInset { +public: + /// + InsetGraphicsMailer(InsetGraphics & inset); + /// + virtual Inset & inset() const { return inset_; } + /// + virtual string const & name() const { return name_; } + /// + virtual string const inset2string() const; + /// + static void string2params(string const &, InsetGraphicsParams &); + /// + static string const params2string(InsetGraphicsParams const &); +private: + /// + static string const name_; + /// + InsetGraphics & inset_; +}; + #endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 29cf3efc76..64b89f1785 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -543,9 +543,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSET_ERT: code = Inset::ERT_CODE; break; - case LFUN_INSET_GRAPHICS: - code = Inset::GRAPHICS_CODE; - break; case LFUN_INSET_FOOTNOTE: code = Inset::FOOT_CODE; break;