From: Jean-Marc Lasgouttes Date: Thu, 19 Jul 2001 08:52:59 +0000 (+0000) Subject: partial inset toggling ; insetAllowed stuff X-Git-Tag: 1.6.10~21055 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b15e539c6868321078523e60d2c1a210c639a4eb;p=features.git partial inset toggling ; insetAllowed stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2277 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 1d48e0a565..edfdc04c9d 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,11 @@ +2001-07-19 Jean-Marc Lasgouttes + + * bind/xemacs.bind: + * bind/sciword.bind: + * bind/emacs.bind: + * bind/cua.bind: + * ui/default.ui: use inset-toggle instead of open-stuff + 2001-07-12 Kayvan A. Sylvan * layouts/literate-scrap.inc: Added PassThru tag diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 42be18c81f..a25f28128b 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -55,7 +55,7 @@ \bind "C-f" "find-replace" \bind "C-g" "error-next" -\bind "C-i" "open-stuff" # 'i' for Inset +\bind "C-i" "inset-toggle" # 'i' for Inset \bind "C-c" "copy" \bind "C-x" "cut" diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind index 962b869e94..2156723b90 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -38,7 +38,7 @@ \bind "C-l" "screen-recenter" \bind "C-m" "mark-toggle" \bind "C-n" "down" -\bind "C-o" "open-stuff" +\bind "C-o" "inset-toggle" \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" diff --git a/lib/bind/sciword.bind b/lib/bind/sciword.bind index e730b692df..e8314db6aa 100644 --- a/lib/bind/sciword.bind +++ b/lib/bind/sciword.bind @@ -42,7 +42,7 @@ # Numbering equations. Should perhaps simplify math-number and math-nonumber into one command since they are used in very different contexts. This and also math-macro stuff should be available in the Lyx menus! \bind "C-n" "math-number" \bind "S-C-n" "math-nonumber" -\bind "C-o" "open-stuff" +\bind "C-o" "inset-toggle" # Insert a quote character. Do I need this? \bind "C-q" "quote-insert" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index eee2260474..4a0a79cf49 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -39,7 +39,7 @@ \bind "C-l" "screen-recenter" \bind "C-m" "mark-toggle" \bind "C-n" "down" -\bind "C-o" "open-stuff" +\bind "C-o" "inset-toggle" \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 7238604144..abbeafc1f2 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -114,7 +114,7 @@ Menuset End Menu "edit_floats" - Item "Open/Close|O" "open-stuff" + Item "Open/Close|O" "inset-toggle" # Item "Melt|M" "melt" # Item "Open All Figures/Tables|F" "floats-operate openfig" # Item "Close All Figures/Tables|T" "floats-operate closefig" diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index e56cc687f0..f0c6fc86c0 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -2637,13 +2637,13 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } break; - case LFUN_OPENSTUFF: + case LFUN_INSET_TOGGLE: { LyXText * lt = bv_->getLyXText(); hideCursor(); beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); - lt->openStuff(bv_); + lt->toggleInset(bv_); update(lt, BufferView::SELECT|BufferView::FITCUR); setState(); } @@ -3343,7 +3343,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout) // if we are in a locking inset we should try to insert the // inset there otherwise this is a illegal function now if (bv_->theLockingInset()) { - if (bv_->theLockingInset()->insertInsetAllowed(inset)) + if (bv_->theLockingInset()->insetAllowed(inset)) return bv_->theLockingInset()->insertInset(bv_, inset); return false; } diff --git a/src/ChangeLog b/src/ChangeLog index 2c0119a3aa..e51590b368 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,26 @@ +2001-07-19 Jean-Marc Lasgouttes + + * lyxfunc.C (getStatus): add support for all the inset insertion + commands. + + * text2.C (insertInset): + * paragraph.C (insetAllowed): + * BufferView_pimpl.C (insertInset): update to take in account the + renaming of insertInsetAllowed + + * lyxfunc.C (getStatus): add support for LFUN_INSET_TOGGLE. + + * text2.C (getInset): new method. returns inset at cursor position. + + * BufferView_pimpl.C (Dispatch): changes because of this. + + * LyXAction.C (init): rename open-stuff to inset-toggle. + + * commandtags.h: rename LFUN_OPENSTUFF to LFUN_INSET_TOGGLE. + + * text2.C (toggleInset): renamed from openStuff; use + Inset::open(). + 2001-07-13 Yves Bastide * lyxrc.C (set_font_norm_type): recognise ISO_8859_15. diff --git a/src/LyXAction.C b/src/LyXAction.C index e2d123d13c..7ad4169916 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -310,7 +310,8 @@ void LyXAction::init() { LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop }, { LFUN_INSERT_NOTE, "note-insert", "", Noop }, { LFUN_GOTONOTE, "note-next", "", ReadOnly }, - { LFUN_OPENSTUFF, "open-stuff", "", ReadOnly }, + { LFUN_INSET_TOGGLE, "inset-toggle", + N_("toggle inset"), ReadOnly }, { LFUN_DOWN_PARAGRAPH, "paragraph-down", N_("Go one paragraph down"), ReadOnly }, { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select", diff --git a/src/commandtags.h b/src/commandtags.h index 0908881e36..f422a7e673 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -49,7 +49,7 @@ enum kb_action { LFUN_COPY, LFUN_GOTOERROR, LFUN_GOTONOTE, - LFUN_OPENSTUFF, + LFUN_INSET_TOGGLE, LFUN_HYPHENATION, LFUN_HFILL, LFUN_DEPTH, @@ -233,7 +233,10 @@ enum kb_action { LFUN_VC_UNDO, // Lgb 97-07-01 LFUN_VC_HISTORY, // Lgb 97-07-01 LFUN_EXPORT, // Lgb 97-07-29 +#if 0 LFUN_INSERTFOOTNOTE, // Bernhard 97-08-07 +// schedule for deletion +#endif LFUN_REF_GOTO, // 200 // Ale 970806 //LFUN_REF_BACK, // Ale 970806 LFUN_PARENTINSERT, // Ale 970813 diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index a47d2c98fb..64e55b4823 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,17 @@ +2001-07-18 Jean-Marc Lasgouttes + + * many files: update to match the change below + + * inset.h (insetAllowed): renamed from insertInsetAllowed; + implement the version which takes an inset here. + + * insetcollapsable.[Ch]: implement open and isOpen + + * inset.h: remove insertInsetAllowed from Inset + (open): new method, to open or close an inset + (isOpen): returns the status of an inset + (isCollapsable, colapse): removed + 2001-07-13 Yves Bastide * insetquotes.C (dispString): display french guillemets when using diff --git a/src/insets/inset.h b/src/insets/inset.h index 33b8f7ad7f..84625c98e8 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -161,6 +161,12 @@ public: virtual bool doClearArea() const { return true; } /// virtual bool autoDelete() const; + /// returns true the inset can hold an inset of given type + virtual bool insetAllowed(Inset::Code) const { return false; } + /// wrapper around the above + bool insetAllowed(Inset * in) const { + return insetAllowed(in->lyxCode()); + } /// virtual void write(Buffer const *, std::ostream &) const = 0; /// @@ -207,8 +213,6 @@ public: /// virtual bool needFullRow() const { return false; } /// - virtual bool insertInsetAllowed(Inset *) const { return false; } - /// void setInsetName(string const & s) { name = s; } /// string const getInsetName() const { return name; } @@ -258,6 +262,11 @@ public: int id() const; void id(int id_arg); + /// used to toggle insets + // is the inset open? + virtual bool isOpen() const { return false; } + // open or close the inset, depending on the bool + virtual void open(BufferView *, bool) {} protected: /// mutable int top_x; @@ -367,9 +376,6 @@ public: /// virtual bool insertInset(BufferView *, Inset *) { return false; } /// - virtual bool insertInsetAllowed(Inset *) const { return false; } - virtual bool insertInsetAllowed(Inset::Code) const { return false; } - /// virtual UpdatableInset * getLockingInset() const { return const_cast(this); } @@ -410,11 +416,6 @@ public: return block_drawing_; } /// - virtual bool isCollapsable() const { return false; } - /// - virtual bool collapsed() const { return false; } - virtual void collapsed(BufferView *, bool) {} - /// // needed for spellchecking text /// virtual string selectNextWord(BufferView *, float & value) const; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 622dc4f14a..1b45ec382d 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -51,7 +51,7 @@ InsetCollapsable::InsetCollapsable() bool InsetCollapsable::insertInset(BufferView * bv, Inset * in) { - if (!insertInsetAllowed(in)) { + if (!insetAllowed(in->lyxCode())) { lyxerr << "InsetCollapsable::InsertInset: " "Unable to insert inset." << endl; return false; @@ -524,10 +524,10 @@ Inset * InsetCollapsable::getInsetFromID(int id_arg) const return inset.getInsetFromID(id_arg); } -void InsetCollapsable::collapsed(BufferView * bv, bool flag) +void InsetCollapsable::open(BufferView * bv, bool flag) { - if (flag == collapsed_) + if (flag == !collapsed_) return; - collapsed_ = flag; + collapsed_ = !flag; bv->updateInset(this, false); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 73f892c962..3fdd9e2145 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -64,11 +64,8 @@ public: /// bool insertInset(BufferView *, Inset * inset); /// - bool insertInsetAllowed(Inset * in) const { - return inset.insertInsetAllowed(in); - } - bool insertInsetAllowed(Inset::Code code) const { - return inset.insertInsetAllowed(code); + bool insetAllowed(Inset::Code code) const { + return inset.insetAllowed(code); } /// bool isTextInset() const { return true; } @@ -157,9 +154,8 @@ public: /// LyXCursor const & cursor(BufferView *) const; /// - bool isCollapsable() const { return true; } - bool collapsed() const { return collapsed_; } - void collapsed(BufferView *, bool); + bool isOpen() const { return !collapsed_; } + void open(BufferView *, bool); /// string selectNextWord(BufferView * bv, float & value) const { return inset.selectNextWord(bv, value); diff --git a/src/insets/insetert.h b/src/insets/insetert.h index dbb7f8e80c..8308203ca4 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -40,7 +40,7 @@ public: /// virtual bool insertInset(BufferView *, Inset *); /// - virtual bool insertInsetAllowed(Inset *) const { return false; } + virtual bool insetAllowed(Inset::Code) const { return false; } /// virtual void setFont(BufferView *, LyXFont const &, bool toggleall = false, bool selectall = false); diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 551407e8d7..eef703a5f5 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -234,18 +234,12 @@ int InsetFloat::docBook(Buffer const * buf, ostream & os) const } -bool InsetFloat::insertInsetAllowed(Inset * in) const -{ - return insertInsetAllowed(in->lyxCode()); -} - - -bool InsetFloat::insertInsetAllowed(Inset::Code code) const +bool InsetFloat::insetAllowed(Inset::Code code) const { if (code == Inset::FLOAT_CODE) return false; if (inset.getLockingInset() != const_cast(this)) - return inset.insertInsetAllowed(code); + return inset.insetAllowed(code); if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE)) return false; return true; diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index d7ec169fbc..c92569fe2e 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -44,8 +44,7 @@ public: /// string const editMessage() const; /// - bool insertInsetAllowed(Inset * inset) const; - bool insertInsetAllowed(Inset::Code) const; + bool insetAllowed(Inset::Code) const; /// void insetButtonRelease(BufferView * bv, int x, int y, int button); /// diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index 141cde152d..75dd3ad581 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -40,14 +40,9 @@ void InsetFootlike::write(Buffer const * buf, std::ostream & os) const } -bool InsetFootlike::insertInsetAllowed(Inset * in) const -{ - return insertInsetAllowed(in->lyxCode()); -} - -bool InsetFootlike::insertInsetAllowed(Inset::Code code) const +bool InsetFootlike::insetAllowed(Inset::Code code) const { if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE)) return false; - return InsetCollapsable::insertInsetAllowed(code); + return InsetCollapsable::insetAllowed(code); } diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index b6b2b54a71..d41829b8e3 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -32,8 +32,7 @@ public: /// void write(Buffer const * buf, std::ostream & os) const; /// - bool insertInsetAllowed(Inset * inset) const; - bool insertInsetAllowed(Inset::Code) const; + bool insetAllowed(Inset::Code) const; }; #endif diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index f425b2be1d..fff7461d45 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -269,17 +269,12 @@ int InsetMinipage::latex(Buffer const * buf, } -bool InsetMinipage::insertInsetAllowed(Inset * in) const -{ - return insertInsetAllowed(in->lyxCode()); -} - -bool InsetMinipage::insertInsetAllowed(Inset::Code code) const +bool InsetMinipage::insetAllowed(Inset::Code code) const { if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE)) return false; - return InsetCollapsable::insertInsetAllowed(code); + return InsetCollapsable::insetAllowed(code); } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 246696d838..0f89a757e4 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -59,8 +59,7 @@ public: /// string const editMessage() const; /// - bool insertInsetAllowed(Inset * inset) const; - bool insertInsetAllowed(Inset::Code) const; + bool insetAllowed(Inset::Code) const; /// Position pos() const; /// diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 10ec2bf72a..7736de5983 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -123,7 +123,7 @@ public: /// bool insertInset(BufferView *, Inset *); /// - bool insertInsetAllowed(Inset *) const { + bool insetAllowed(Inset::Code) const { return the_locking_inset != 0; } /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a17efbd2ae..234bb87c76 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1410,7 +1410,7 @@ InsetText::moveDown(BufferView * bv) bool InsetText::insertInset(BufferView * bv, Inset * inset) { if (the_locking_inset) { - if (the_locking_inset->insertInsetAllowed(inset)) + if (the_locking_inset->insetAllowed(inset)) return the_locking_inset->insertInset(bv, inset); return false; } @@ -1435,17 +1435,10 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset) } -bool InsetText::insertInsetAllowed(Inset * in) const +bool InsetText::insetAllowed(Inset::Code code) const { if (the_locking_inset) - return the_locking_inset->insertInsetAllowed(in); - return true; -} - -bool InsetText::insertInsetAllowed(Inset::Code code) const -{ - if (the_locking_inset) - return the_locking_inset->insertInsetAllowed(code); + return the_locking_inset->insetAllowed(code); return true; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 1c6a448b6e..5d11d617fa 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -152,8 +152,7 @@ public: /// bool insertInset(BufferView *, Inset *); /// - bool insertInsetAllowed(Inset *) const; - bool insertInsetAllowed(Inset::Code) const; + bool insetAllowed(Inset::Code) const; /// UpdatableInset * getLockingInset() const; /// diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9a6fbe629a..537ce1aeec 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -428,15 +428,6 @@ func_status::value_type LyXFunc::getStatus(int ac, disable = !Exporter::IsExportable(buf, "program"); break; - case LFUN_INSERTFOOTNOTE: - // Disable insertion of floats in a tabular. - disable = false; - if (owner->view()->theLockingInset()) { - disable = (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) || - owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE); - } - break; - case LFUN_LAYOUT_TABULAR: disable = true; if (owner->view()->theLockingInset()) { @@ -490,6 +481,12 @@ func_status::value_type LyXFunc::getStatus(int ac, case LFUN_BOOKMARK_GOTO: disable = !owner->view()-> isSavedPosition(strToUnsignedInt(argument)); + break; + + + case LFUN_INSET_TOGGLE: + disable = (TEXT(false)->getInset() == 0); + break; case LFUN_MATH_VALIGN: { // I think this test can be simplified (Andre') @@ -592,43 +589,127 @@ func_status::value_type LyXFunc::getStatus(int ac, default: break; - } - if (disable) - flag |= func_status::Disabled; - - if (buf) { - func_status::value_type box = func_status::ToggleOff; - LyXFont const & font = - TEXT(false)->real_current_font; - switch (action) { - case LFUN_EMPH: - if (font.emph() == LyXFont::ON) - box = func_status::ToggleOn; - break; - case LFUN_NOUN: - if (font.noun() == LyXFont::ON) - box = func_status::ToggleOn; - break; - case LFUN_BOLD: - if (font.series() == LyXFont::BOLD_SERIES) - box = func_status::ToggleOn; - break; + } + + // the functions which insert insets + Inset::Code code = Inset::NO_CODE; + switch (action) { + case LFUN_INSET_TEXT: + code = Inset::TEXT_CODE; + break; + 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; + case LFUN_INSET_TABULAR: + code = Inset::TABULAR_CODE; + break; + case LFUN_INSET_EXTERNAL: + code = Inset::EXTERNAL_CODE; + break; + case LFUN_INSET_MARGINAL: + code = Inset::MARGIN_CODE; + break; + case LFUN_INSET_MINIPAGE: + code = Inset::MINIPAGE_CODE; + break; + case LFUN_INSET_FLOAT: + case LFUN_INSET_WIDE_FLOAT: + code = Inset::FLOAT_CODE; + break; +#if 0 + case LFUN_INSET_LIST: + code = Inset::LIST_CODE; + break; +#endif + case LFUN_INSET_THEOREM: + code = Inset::THEOREM_CODE; + break; + case LFUN_INSET_CAPTION: + code = Inset::CAPTION_CODE; + break; + case LFUN_INSERT_NOTE: + code = Inset::IGNORE_CODE; + break; + case LFUN_INSERT_LABEL: + code = Inset::LABEL_CODE; + break; + case LFUN_REF_INSERT: + code = Inset::REF_CODE; + break; + case LFUN_CITATION_INSERT: + code = Inset::CITE_CODE; + break; + case LFUN_INSERT_BIBTEX: + code = Inset::BIBTEX_CODE; + break; + case LFUN_INDEX_INSERT: + case LFUN_INDEX_INSERT_LAST: + code = Inset::INDEX_CODE; + break; +#if 0 + case LFUN_CHILD_INSERT: + code = Inset::CHILD_CODE; + break; +#endif + case LFUN_TOC_INSERT: + code = Inset::TOC_CODE; + break; + case LFUN_PARENTINSERT: + code = Inset::PARENT_CODE; + break; + case LFUN_INSERT_URL: + code = Inset::URL_CODE; + break; + default: + break; + } + if (code != Inset::NO_CODE + && owner->view()->theLockingInset() + && !owner->view()->theLockingInset()->insetAllowed(code)) { + disable = true; + } + + if (disable) + flag |= func_status::Disabled; + + // the font related functions + func_status::value_type box = func_status::ToggleOff; + LyXFont const & font = + TEXT(false)->real_current_font; + switch (action) { + case LFUN_EMPH: + if (font.emph() == LyXFont::ON) + box = func_status::ToggleOn; + break; + case LFUN_NOUN: + if (font.noun() == LyXFont::ON) + box = func_status::ToggleOn; + break; + case LFUN_BOLD: + if (font.series() == LyXFont::BOLD_SERIES) + box = func_status::ToggleOn; + break; #ifndef NO_LATEX - case LFUN_TEX: - if (font.latex() == LyXFont::ON) - box = func_status::ToggleOn; - break; + case LFUN_TEX: + if (font.latex() == LyXFont::ON) + box = func_status::ToggleOn; + break; #endif - case LFUN_READ_ONLY_TOGGLE: - if (buf->isReadonly()) - box = func_status::ToggleOn; - break; - default: - box = func_status::OK; - break; - } - flag |= box; + case LFUN_READ_ONLY_TOGGLE: + if (buf->isReadonly()) + box = func_status::ToggleOn; + break; + default: + box = func_status::OK; + break; } + flag |= box; return flag; } diff --git a/src/lyxtext.h b/src/lyxtext.h index 9cf1d7859f..95b61730c0 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -271,6 +271,8 @@ public: void getWord(LyXCursor & from, LyXCursor & to, word_location) const; /// just selects the word the cursor is in void selectWord(BufferView *); + /// returns the inset at cursor (if it exists), 0 otherwise + Inset * getInset() const; /** 'selects" the next word, where the cursor is not in and returns this word as string. THe cursor will be moved @@ -377,7 +379,7 @@ public: Row * row_ptr, int y, bool cleared=false); /// - void openStuff(BufferView *); + void toggleInset(BufferView *); /// void cutSelection(BufferView *, bool = true); /// diff --git a/src/paragraph.C b/src/paragraph.C index 6f6d0e848c..5e70fda1ec 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -430,7 +430,7 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, bool Paragraph::insertFromMinibuffer(Paragraph::size_type pos) { if ((minibuffer_char == Paragraph::META_INSET) && - !insertInsetAllowed(minibuffer_inset)) + !insetAllowed(minibuffer_inset->lyxCode())) return false; if (minibuffer_char == Paragraph::META_INSET) insertInset(pos, minibuffer_inset, minibuffer_font); @@ -489,12 +489,12 @@ void Paragraph::insertInset(Paragraph::size_type pos, } -bool Paragraph::insertInsetAllowed(Inset * inset) +bool Paragraph::insetAllowed(Inset::Code code) { //lyxerr << "Paragraph::InsertInsetAllowed" << endl; if (pimpl_->inset_owner) - return pimpl_->inset_owner->insertInsetAllowed(inset); + return pimpl_->inset_owner->insetAllowed(code); return true; } diff --git a/src/paragraph.h b/src/paragraph.h index 9fc5b9b16f..042da4b717 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -274,7 +274,7 @@ public: /// void insertInset(size_type pos, Inset * inset, LyXFont const &); /// - bool insertInsetAllowed(Inset * inset); + bool insetAllowed(Inset::Code code); /// Inset * getInset(size_type pos); /// diff --git a/src/text2.C b/src/text2.C index 3c64a7ab75..99497d0555 100644 --- a/src/text2.C +++ b/src/text2.C @@ -360,20 +360,29 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par, } } -void LyXText::openStuff(BufferView * bview) +Inset * LyXText::getInset() const { + Inset * inset = 0; if (cursor.pos() == 0 && cursor.par()->bibkey){ - cursor.par()->bibkey->edit(bview, 0, 0, 0); + inset = cursor.par()->bibkey; } else if (cursor.pos() < cursor.par()->size() && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) { - Inset * inset = cursor.par()->getInset(cursor.pos()); - if (!inset->editable()) - return; - bview->owner()->message(inset->editMessage()); - if (inset->editable() != Inset::HIGHLY_EDITABLE) - setCursorParUndo(bview); - inset->edit(bview, 0, 0, 0); + inset = cursor.par()->getInset(cursor.pos()); } + return inset; +} + +void LyXText::toggleInset(BufferView * bview) +{ + Inset * inset = getInset(); + if (!inset->editable()) + return; + //bview->owner()->message(inset->editMessage()); + + // do we want to keep this?? (JMarc) + if (inset->editable() != Inset::HIGHLY_EDITABLE) + setCursorParUndo(bview); + inset->open(bview, !inset->isOpen()); } @@ -1534,7 +1543,7 @@ void LyXText::updateCounters(BufferView * bview, Row * row) const void LyXText::insertInset(BufferView * bview, Inset * inset) { - if (!cursor.par()->insertInsetAllowed(inset)) + if (!cursor.par()->insetAllowed(inset->lyxCode())) return; setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());