diff --git a/lib/ChangeLog b/lib/ChangeLog index dd2d3cac5e..9893e0f6cd 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2004-03-30 Angus Leeming + + * bind/aqua.bind: + * bind/cua.bind: + * bind/emacs.bind: + * bind/xemacs.bind: s/inset_toggle/next-inset-toggle/. + 2004-03-29 Jürgen Spitzmüller * dco/LaTeXConfig.lyx.in: check for bibtopic. diff --git a/lib/bind/aqua.bind b/lib/bind/aqua.bind index bf30aaa471..11e617285c 100644 --- a/lib/bind/aqua.bind +++ b/lib/bind/aqua.bind @@ -77,7 +77,7 @@ \bind "M-~S-e s" "spellchecker" \bind "M-~S-e h" "buffer-chktex" \bind "M-~S-e e" "error-remove-all" -\bind "M-~S-e l" "inset-toggle" +\bind "M-~S-e l" "next-inset-toggle" \bind "M-~S-e p" "dialog-preferences" \bind "M-~S-e r" "reconfigure" diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 9aa7fba25c..dfe14041c1 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -62,7 +62,7 @@ \bind "C-f" "dialog-show findreplace" \bind "C-g" "error-next" -\bind "C-i" "inset-toggle" # 'i' for Inset +\bind "C-i" "next-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 c9d8eb4334..7e4ce76efc 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -42,7 +42,7 @@ \bind "C-l" "screen-recenter" \bind "C-m" "mark-toggle" \bind "C-n" "down" -\bind "C-o" "inset-toggle" +\bind "C-o" "next-inset-toggle" \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index 963e2b6cf3..6b9e74ca8c 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -44,7 +44,7 @@ \bind "C-l" "screen-recenter" \bind "C-m" "mark-toggle" \bind "C-n" "down" -\bind "C-o" "inset-toggle" +\bind "C-o" "next-inset-toggle" \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" diff --git a/src/ChangeLog b/src/ChangeLog index 8aa23d6f14..0127d69f47 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2004-03-30 Angus Leeming + + * lfuns.h: + * LyXAction.C (init): new lfuns, LFUN_KEYMAP_TOGGLE, + LFUN_NEXT_INSET_TOGGLE, LFUN_ALL_INSETS_TOGGLE. + + * lyxfunc.C (dispatch): LFUN_ALL_INSETS_TOGGLE is used to toggle the + open/closed state of ollapsable insets. Usage: + + all-inset-toggle , where + == "open" || "closed" || "toggle" and + is an identifier for a 'type' of inset. Eg "branch", "ert",... + + * lyxtext.h, text2.C (toggleInset): removed. + + * text3.C (dispatch): split the existing LFUN_INSET_TOGGLE in two, + LFUN_KEYMAP_TOGGLE and LFUN_NEXT_INSET_TOGGLE. LFUN_NEXT_INSET_TOGGLE + now passes LFUN_INSET_TOGGLE to the found inset. + + * InsetList.[Ch] (insetsOpenCloseBranch): removed. Functionality + is now invoked as "all-insets-toggle toggle branch". + 2004-03-30 Angus Leeming * dociterator.C: diff --git a/src/InsetList.C b/src/InsetList.C index d9d90d5591..ca82bf28e1 100644 --- a/src/InsetList.C +++ b/src/InsetList.C @@ -135,23 +135,3 @@ void InsetList::decreasePosAfterPos(pos_type pos) --it->pos; } } - - -void InsetList::insetsOpenCloseBranch(Buffer const & buf) -{ - List::iterator it = list.begin(); - List::iterator end = list.end(); - for (; it != end; ++it) { - if (!it->inset) - continue; - if (it->inset->lyxCode() != InsetBase::BRANCH_CODE) - continue; - - InsetBranch * inset = static_cast(it->inset); - if (inset->isBranchSelected(buf.params().branchlist())) { - inset->open(); - } else { - inset->close(); - } - } -} diff --git a/src/InsetList.h b/src/InsetList.h index 5baa908794..7c0e150b22 100644 --- a/src/InsetList.h +++ b/src/InsetList.h @@ -67,8 +67,6 @@ public: void increasePosAfterPos(lyx::pos_type pos); /// void decreasePosAfterPos(lyx::pos_type pos); - /// - void insetsOpenCloseBranch(Buffer const & buf); private: /// diff --git a/src/LyXAction.C b/src/LyXAction.C index 94dbbc7e19..5e1def0120 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -231,7 +231,9 @@ void LyXAction::init() { LFUN_INSERT_NOTE, "note-insert", Noop }, { LFUN_INSERT_BOX, "box-insert", Noop }, { LFUN_GOTONOTE, "note-next", ReadOnly }, - { LFUN_INSET_TOGGLE, "inset-toggle", ReadOnly }, + { LFUN_INSET_TOGGLE, "", ReadOnly }, + { LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly }, + { LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly }, { LFUN_DOWN_PARAGRAPH, "paragraph-down", ReadOnly }, { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select", ReadOnly }, { LFUN_GOTO_PARAGRAPH, "paragraph-goto", ReadOnly }, @@ -326,6 +328,7 @@ void LyXAction::init() { LFUN_REPEAT, "repeat", NoBuffer }, { LFUN_WORD_FIND, "word-find", Noop }, { LFUN_WORD_REPLACE, "word-replace", Noop }, + { LFUN_KEYMAP_TOGGLE, "keymap-toggle", Noop }, { LFUN_NOACTION, "", Noop } }; diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 27f3f01dc2..aa7aa6e8cf 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,9 @@ +2004-03-30 Angus Leeming + + * ControlDocument.C (apply): replace the loop over paragraphs + invoking insetsOpenCloseBranch with + LFUN_ALL_INSETS_TOGGLE, "toggle branch". + 2004-03-29 Jürgen Spitzmüller * ControlBibtex.[Ch]: add member usingBibtopic(). diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index d10194032e..40ae2d6304 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -28,7 +28,6 @@ #include "lfuns.h" #include "paragraph.h" #include "ParagraphList_fwd.h" -#include "pariterator.h" #include "frontends/Alert.h" #include "frontends/LyXView.h" @@ -104,12 +103,7 @@ void ControlDocument::apply() } // Open insets of selected branches, close deselected ones - // Currently only top-level insets in buffer handled (bug). - ParIterator pit = buffer()->par_iterator_begin(); - ParIterator pend = buffer()->par_iterator_end(); - for (; pit != pend; ++pit) { - pit->insetlist.insetsOpenCloseBranch(*buffer()); - } + lv_.dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "toggle branch")); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 5cdcb1b7d0..c47e2f9bdb 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2004-03-30 Angus Leeming + + * insetbase.[Ch] (translate): new static member function, returns + an InsetBase::Code corresponding to the input string. + + * insetcollapsable.C (priv_dispatch): handle LFUN_INSET_TOGGLE. + + * insetbranch.C(priv_dispatch): specialize LFUN_INSET_TOGGLE + so that it opens the inset if it refers to the currently active + branch. 2004-03-30 Alfredo Braunstein diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index a6ded266b9..45d957ab34 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -25,6 +25,88 @@ #include "frontends/Painter.h" +#include + +namespace { + +struct InsetName { + InsetName(std::string const & n, InsetBase::Code c) + : name(n), code(c) {} + std::string name; + InsetBase::Code code; +}; + +typedef std::map TranslatorMap; + +TranslatorMap const build_translator() +{ + InsetName const insetnames[] = { + InsetName("toc", InsetBase::TOC_CODE), + InsetName("quote", InsetBase::QUOTE_CODE), + InsetName("ref", InsetBase::REF_CODE), + InsetName("url", InsetBase::URL_CODE), + InsetName("htmlurl", InsetBase::HTMLURL_CODE), + InsetName("separator", InsetBase::SEPARATOR_CODE), + InsetName("ending", InsetBase::ENDING_CODE), + InsetName("label", InsetBase::LABEL_CODE), + InsetName("note", InsetBase::NOTE_CODE), + InsetName("accent", InsetBase::ACCENT_CODE), + InsetName("math", InsetBase::MATH_CODE), + InsetName("index", InsetBase::INDEX_CODE), + InsetName("include", InsetBase::INCLUDE_CODE), + InsetName("graphics", InsetBase::GRAPHICS_CODE), + InsetName("bibitem", InsetBase::BIBITEM_CODE), + InsetName("bibtex", InsetBase::BIBTEX_CODE), + InsetName("text", InsetBase::TEXT_CODE), + InsetName("ert", InsetBase::ERT_CODE), + InsetName("foot", InsetBase::FOOT_CODE), + InsetName("margin", InsetBase::MARGIN_CODE), + InsetName("float", InsetBase::FLOAT_CODE), + InsetName("wrap", InsetBase::WRAP_CODE), + InsetName("specialchar", InsetBase::SPECIALCHAR_CODE), + InsetName("tabular", InsetBase::TABULAR_CODE), + InsetName("external", InsetBase::EXTERNAL_CODE), + InsetName("caption", InsetBase::CAPTION_CODE), + InsetName("mathmacro", InsetBase::MATHMACRO_CODE), + InsetName("error", InsetBase::ERROR_CODE), + InsetName("cite", InsetBase::CITE_CODE), + InsetName("float_list", InsetBase::FLOAT_LIST_CODE), + InsetName("index_print", InsetBase::INDEX_PRINT_CODE), + InsetName("optarg", InsetBase::OPTARG_CODE), + InsetName("environment", InsetBase::ENVIRONMENT_CODE), + InsetName("hfill", InsetBase::HFILL_CODE), + InsetName("newline", InsetBase::NEWLINE_CODE), + InsetName("line", InsetBase::LINE_CODE), + InsetName("branch", InsetBase::BRANCH_CODE), + InsetName("box", InsetBase::BOX_CODE), + InsetName("charstyle", InsetBase::CHARSTYLE_CODE), + InsetName("vspace", InsetBase::VSPACE_CODE), + InsetName("mathgrid", InsetBase::MATHGRID_CODE), + InsetName("mathhull", InsetBase::MATHHULL_CODE) + }; + + std::size_t const insetnames_size = + sizeof(insetnames) / sizeof(insetnames[0]); + + std::map data; + for (std::size_t i = 0; i != insetnames_size; ++i) { + InsetName const & var = insetnames[i]; + data[var.name] = var.code; + } + + return data; +} + +} // namespace anon + + +InsetBase::Code InsetBase::translate(std::string const & name) +{ + static TranslatorMap const translator = build_translator(); + + TranslatorMap::const_iterator it = translator.find(name); + return it == translator.end() ? NO_CODE : it->second; +} void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd) @@ -229,5 +311,3 @@ bool isHighlyEditableInset(InsetBase const * inset) { return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE; } - - diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index e6601105f6..e0749aedcc 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -298,6 +298,12 @@ public: /// MATHHULL_CODE }; + + /** returns the Code corresponding to the \c name. + * Eg, translate("branch") == BRANCH_CODE + */ + static Code translate(std::string const & name); + /// returns true the inset can hold an inset of given type virtual bool insetAllowed(Code) const { return false; } // if this inset has paragraphs should they be output all as default diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index ef8b06db3e..eb571074a4 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -13,6 +13,7 @@ #include "insetbranch.h" #include "buffer.h" +#include "BufferView.h" #include "bufferparams.h" #include "BranchList.h" #include "cursor.h" @@ -139,6 +140,35 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd) InsetCollapsable::priv_dispatch(cur, cmd); break; + + case LFUN_INSET_TOGGLE: + // We assume that this lfun is indeed going to be dispatched. + cur.dispatched(); + + if (cmd.argument == "open") + setStatus(Open); + else if (cmd.argument == "close") + setStatus(Collapsed); + + // The branch inset specialises its behaviour on "toggle". + else if (cmd.argument == "toggle" + || cmd.argument.empty()) { + BranchList const & branchlist = + cur.bv().buffer()->params().branchlist(); + if (isBranchSelected(branchlist)) { + if (status() != Open) + setStatus(Open); + else + cur.undispatched(); + } else { + if (status() != Collapsed) + setStatus(Collapsed); + else + cur.undispatched(); + } + } + break; + default: InsetCollapsable::priv_dispatch(cur, cmd); break; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 12736bef03..ea1e834903 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -250,70 +250,73 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd // << " button y: " << button_dim.y2 << endl; switch (cmd.action) { - case LFUN_MOUSE_PRESS: - if (status_ == Inlined) - InsetText::priv_dispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) - InsetText::priv_dispatch(cur, cmd); + case LFUN_MOUSE_PRESS: + if (status_ == Inlined) + InsetText::priv_dispatch(cur, cmd); + else if (status_ == Open && !hitButton(cmd)) + InsetText::priv_dispatch(cur, cmd); + break; + + case LFUN_MOUSE_MOTION: + if (status_ == Inlined) + InsetText::priv_dispatch(cur, cmd); + else if (status_ == Open && !hitButton(cmd)) + InsetText::priv_dispatch(cur, cmd); + break; + + case LFUN_MOUSE_RELEASE: + if (cmd.button() == mouse_button::button3) { + showInsetDialog(&cur.bv()); + break; + } + + switch (status_) { + + case Collapsed: + lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; + setStatus(Open); + edit(cur, true); break; - case LFUN_MOUSE_MOTION: - if (status_ == Inlined) + case Open: { + FuncRequest cmd1 = cmd; + if (hitButton(cmd1)) { + lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; + setStatus(Collapsed); + cur.undispatched(); + cmd = FuncRequest(LFUN_FINISHED_RIGHT); + } else { + lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; InsetText::priv_dispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) - InsetText::priv_dispatch(cur, cmd); - break; - - case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3) { - showInsetDialog(&cur.bv()); - break; - } - - switch (status_) { - - case Collapsed: - lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; - setStatus(Open); - edit(cur, true); - break; - - case Open: { - FuncRequest cmd1 = cmd; - if (hitButton(cmd1)) { - lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; - setStatus(Collapsed); - cur.undispatched(); - cmd = FuncRequest(LFUN_FINISHED_RIGHT); - } else { - lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; - InsetText::priv_dispatch(cur, cmd); - } - break; - } - - case Inlined: - lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl; - InsetText::priv_dispatch(cur, cmd); - break; } break; + } - case LFUN_INSET_TOGGLE: - if (InsetText::text_.toggleInset(cur)) - break; - if (status_ == Open) { - setStatus(Inlined); - break; - } - setStatus(Collapsed); - cur.undispatched(); - cmd = FuncRequest(LFUN_FINISHED_RIGHT); - break; - - default: + case Inlined: + lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl; InsetText::priv_dispatch(cur, cmd); break; + } + break; + + case LFUN_INSET_TOGGLE: + if (cmd.argument == "open") + setStatus(Open); + else if (cmd.argument == "close") + setStatus(Collapsed); + else if (cmd.argument == "toggle" + || cmd.argument.empty()) { + if (isOpen()) + setStatus(Collapsed); + else + setStatus(Open); + } + cur.dispatched(); + break; + + default: + InsetText::priv_dispatch(cur, cmd); + break; } } diff --git a/src/lfuns.h b/src/lfuns.h index dc455b67b1..35f52adf1f 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -337,6 +337,9 @@ enum kb_action { // 255 LFUN_EXPORT_CUSTOM, LFUN_PRINT, + LFUN_KEYMAP_TOGGLE, + LFUN_NEXT_INSET_TOGGLE, + LFUN_ALL_INSETS_TOGGLE, LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 54c68f6acd..b4ebfabc8e 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -36,6 +36,7 @@ #include "funcrequest.h" #include "gettext.h" #include "importer.h" +#include "insetiterator.h" #include "intl.h" #include "kbmap.h" #include "LColor.h" @@ -494,6 +495,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_FILE_INSERT: case LFUN_FILE_INSERT_ASCII: case LFUN_FILE_INSERT_ASCII_PARA: + case LFUN_ALL_INSETS_TOGGLE: // these are handled in our dispatch() break; @@ -1242,6 +1244,31 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) case LFUN_BREAKLINE: { #warning swallow 'Return' if the minibuffer is focused. But how? + break; + } + + case LFUN_ALL_INSETS_TOGGLE: { + string action; + string const name = split(argument, action, ' '); + InsetBase::Code const inset_code = + InsetBase::translate(name); + + LCursor & cur = view()->cursor(); + FuncRequest fr(LFUN_INSET_TOGGLE, action); + + InsetBase & inset = owner->buffer()->inset(); + InsetIterator it = inset_iterator_begin(inset); + InsetIterator const end = inset_iterator_end(inset); + for (; it != end; ++it) { + if (inset_code == InsetBase::NO_CODE + || inset_code == it->lyxCode()) { + it->dispatch(cur, fr); + if (&cur.inset() == &*it + && cur.disp_.dispatched()) + cur.pop(); + } + } + break; } default: { diff --git a/src/lyxtext.h b/src/lyxtext.h index b2bcdf6358..ddfc3aedd0 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -231,8 +231,6 @@ public: }; /// Change the case of the word at cursor position. void changeCase(LCursor & cur, TextCase action); - /// returns success - bool toggleInset(LCursor & cur); /** the DTP switches for paragraphs. LyX will store the top settings always in the first physical paragraph, the bottom settings in the diff --git a/src/text2.C b/src/text2.C index 30ac68f634..19606e11c4 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1413,26 +1413,6 @@ void LyXText::recUndo(par_type par) const } -bool LyXText::toggleInset(LCursor & cur) -{ - InsetBase * inset = cur.nextInset(); - // is there an editable inset at cursor position? - if (!isEditableInset(inset)) - return false; - cur.message(inset->editMessage()); - - // do we want to keep this?? (JMarc) - if (!isHighlyEditableInset(inset)) - recordUndo(cur); - - if (inset->isOpen()) - inset->close(); - else - inset->open(); - return true; -} - - int defaultRowHeight() { return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2); diff --git a/src/text3.C b/src/text3.C index 00f48fcc04..546cb6c01c 100644 --- a/src/text3.C +++ b/src/text3.C @@ -787,12 +787,20 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cur.inset().asUpdatableInset()->showInsetDialog(bv); break; - case LFUN_INSET_TOGGLE: + case LFUN_NEXT_INSET_TOGGLE: { + InsetBase * inset = cur.nextInset(); + if (inset) { + cur.clearSelection(); + FuncRequest fr = cmd; + fr.action = LFUN_INSET_TOGGLE; + inset->dispatch(cur, fr); + } + break; + } + + case LFUN_KEYMAP_TOGGLE: cur.clearSelection(); - if (!toggleInset(cur)) - cur.undispatched(); - else - bv->switchKeyMap(); + bv->switchKeyMap(); break; case LFUN_SPACE_INSERT: @@ -1815,7 +1823,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_PARAGRAPH_SPACING: case LFUN_INSET_APPLY: case LFUN_INSET_INSERT: - case LFUN_INSET_TOGGLE: + case LFUN_NEXT_INSET_TOGGLE: case LFUN_UPCASE_WORD: case LFUN_LOWCASE_WORD: case LFUN_CAPITALIZE_WORD: @@ -1884,6 +1892,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_THESAURUS_ENTRY: case LFUN_PARAGRAPH_APPLY: case LFUN_ESCAPE: + case LFUN_KEYMAP_TOGGLE: // these are handled in our dispatch() enable = true; break;