From: Jean-Marc Lasgouttes Date: Mon, 23 Jul 2001 09:11:14 +0000 (+0000) Subject: fix insertion of raw double quote, reading of Info inset, initial width of collapsed... X-Git-Tag: 1.6.10~21038 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=55bf6460f304a4632af2136a62c8a82fb86053f3;p=features.git fix insertion of raw double quote, reading of Info inset, initial width of collapsed insets, insertion of index; better support for insetAllowed, for french quotes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2300 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index b5cbc9bc64..adc2ec4d60 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2001-07-22 Jean-Marc Lasgouttes + + * ui/default.ui: + * bind/cua.bind: + * bind/emacs.bind: + * bind/xemacs.bind: fix binding for raw double quote + 2001-07-22 José Matos * reLyX/MakePreamble.pm (translate_preamble): add lots of options diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index a25f28128b..8efd91810c 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -67,7 +67,7 @@ \bind "C-z" "undo" \bind "C-S-Z" "redo" -\bind "S-C-quotedbl" "quote-insert" +\bind "~S-C-quotedbl" "self-insert \"" \bind "C-minus" "hyphenation-point-insert" \bind "M-S-Right" "depth-increment" \bind "M-S-Left" "depth-decrement" diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind index 2156723b90..5fc5be1554 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -42,7 +42,7 @@ \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" -\bind "C-q" "quote-insert" +\bind "C-q" "self-insert \"" #bind "C-r" "------" \bind "C-s" "find-replace" \bind "M-~S-percent" "find-replace" @@ -66,7 +66,7 @@ \bind "C-~S-slash" "undo" \bind "C-~S-underscore" "undo" -\bind "S-C-quotedbl" "quote-insert" +\bind "~S-C-quotedbl" "self-insert \"" \bind "C-x a" "buffer-auto-save" #\bind "C-x b" "buffer-previous" diff --git a/lib/bind/sciword.bind b/lib/bind/sciword.bind index e8314db6aa..bbfb95e6a7 100644 --- a/lib/bind/sciword.bind +++ b/lib/bind/sciword.bind @@ -45,7 +45,8 @@ \bind "C-o" "inset-toggle" # Insert a quote character. Do I need this? -\bind "C-q" "quote-insert" +# Probably, since we need a way to get a raw quote +\bind "C-q" "self-insert \"" # Sciword mnemonic. \bind "C-r" "math-insert sqrt" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index 4a0a79cf49..c1714331f6 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -43,7 +43,7 @@ \bind "C-p" "up" # this is "quoted-insert" a total different meaning from "quote-insert" -\bind "C-q" "quote-insert" +\bind "C-q" "self-insert \"" #bind "C-r" "------" \bind "C-s" "find-replace" \bind "M-~S-percent" "find-replace" @@ -69,7 +69,7 @@ \bind "C-~S-slash" "undo" \bind "C-~S-underscore" "undo" -\bind "S-C-quotedbl" "quote-insert" +\bind "~S-C-quotedbl" "self-insert \"" \bind "C-x a" "buffer-auto-save" # not currently supported diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 7a3e752a71..08feb4807a 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -222,7 +222,7 @@ Menuset Item "Linebreak|L" "break-line" Item "Ellipsis|i" "dots-insert" Item "End of Sentence|E" "end-of-sentence-period-insert" - Item "Ordinary Quote|Q" "quote-insert" + Item "Ordinary Quote|Q" "self-insert \"" Item "Menu Separator|M" "menu-separator-insert" End diff --git a/src/BufferView.h b/src/BufferView.h index 6a783e7c23..548306dbac 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -133,8 +133,6 @@ public: /// string const nextWord(float & value); /// - void insertCorrectQuote(); - /// bool gotoLabel(string const & label); /// void paste(); diff --git a/src/BufferView2.C b/src/BufferView2.C index 2da94d1b35..6af288a3ab 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -329,21 +329,6 @@ void BufferView::paste() } - - -void BufferView::insertCorrectQuote() -{ - char c; - - if (text->cursor.pos()) - c = text->cursor.par()->getChar(text->cursor.pos() - 1); - else - c = ' '; - - insertInset(new InsetQuotes(c, buffer()->params)); -} - - /* these functions are for the spellchecker */ string const BufferView::nextWord(float & value) { diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d0fc903f9e..5e1e36fce2 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -2660,7 +2660,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) break; case LFUN_QUOTE: - bv_->insertCorrectQuote(); + smartQuote(); break; case LFUN_HTMLURL: @@ -2671,99 +2671,60 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) p.setCmdName("htmlurl"); else p.setCmdName("url"); - owner_->getDialogs()->createUrl( p.getAsString() ); + owner_->getDialogs()->createUrl(p.getAsString()); } break; case LFUN_INSERT_URL: { InsetCommandParams p; - p.setFromString( argument ); + p.setFromString(argument); - InsetUrl * inset = new InsetUrl( p ); + InsetUrl * inset = new InsetUrl(p); if (!insertInset(inset)) delete inset; else - updateInset( inset, true ); + updateInset(inset, true); } break; case LFUN_INSET_TEXT: - { - InsetText * new_inset = new InsetText; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetText); + break; case LFUN_INSET_ERT: - { - InsetERT * new_inset = new InsetERT; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetERT); + break; case LFUN_INSET_EXTERNAL: - { - InsetExternal * new_inset = new InsetExternal; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetExternal); + break; case LFUN_INSET_FOOTNOTE: - { - InsetFoot * new_inset = new InsetFoot; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetFoot); + break; case LFUN_INSET_MARGINAL: - { - InsetMarginal * new_inset = new InsetMarginal; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetMarginal); + break; case LFUN_INSET_MINIPAGE: - { - InsetMinipage * new_inset = new InsetMinipage; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetMinipage); + break; + + case LFUN_INSERT_NOTE: + insertAndEditInset(new InsetNote); + break; case LFUN_INSET_FLOAT: - { // check if the float type exist if (floatList.typeExist(argument)) { - InsetFloat * new_inset = new InsetFloat(argument); - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; + insertAndEditInset(new InsetFloat(argument)); } else { lyxerr << "Non-existant float type: " << argument << endl; } - - } - break; + break; case LFUN_INSET_WIDE_FLOAT: { @@ -2784,24 +2745,12 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) break; case LFUN_INSET_LIST: - { - InsetList * new_inset = new InsetList; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetList); + break; case LFUN_INSET_THEOREM: - { - InsetTheorem * new_inset = new InsetTheorem; - if (insertInset(new_inset)) - new_inset->edit(bv_); - else - delete new_inset; - } - break; + insertAndEditInset(new InsetTheorem); + break; case LFUN_INSET_CAPTION: { @@ -3119,10 +3068,6 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } break; - case LFUN_INSERT_NOTE: - insertNote(); - break; - case LFUN_SELFINSERT: { if (argument.empty()) break; @@ -3145,7 +3090,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } } - bv_->beforeChange(lt); + beforeChange(lt); LyXFont const old_font(lt->real_current_font); string::const_iterator cit = argument.begin(); @@ -3284,14 +3229,31 @@ void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind) } -void BufferView::Pimpl::insertNote() +void BufferView::Pimpl::smartQuote() { - Inset * inset = new InsetNote; - insertInset(inset); - inset->edit(bv_); + char c; + LyXText * lt = bv_->getLyXText(); + + if (lt->cursor.pos()) + c = lt->cursor.par()->getChar(lt->cursor.pos() - 1); + else + c = ' '; + + hideCursor(); + if (!insertInset(new InsetQuotes(c, bv_->buffer()->params))) + Dispatch(LFUN_SELFINSERT, "\""); } +void BufferView::Pimpl::insertAndEditInset(Inset * inset) +{ + if (insertInset(inset)) + inset->edit(bv_); + else + delete inset; +} + + // Open and lock an updatable inset bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind) { diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index f4b9162a10..d5c9bb86e4 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -139,7 +139,9 @@ private: /// void hfill(); /// - void insertNote(); + void smartQuote(); + /// + void insertAndEditInset(Inset *); /// void gotoInset(std::vector const & codes, bool same_content); diff --git a/src/ChangeLog b/src/ChangeLog index 147d691110..9a0aa0fb80 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,38 @@ +2001-07-22 Jean-Marc Lasgouttes + + * ToolbarDefaults.C (read): + * MenuBackend.C (read): allow escaping in all strings + + * BufferView_pimpl.C (insertAndEditInset): new method. + (Dispatch): use insertAndEditInset whenever appropriate. + + * BufferView_pimpl.C (insertNote): removed + + * BufferView_pimpl.C (smartQuote): new method, moved from + BufferView; if an insetquote cannot be inserted, insert a '"' + character instead. + + * BufferView2.C: remove insertCorrectQuote(); + + * lyxfunc.C (getStatus): Add support for all remaingin + inset-insert lfuns. + + * trans_mgr.C (insertVerbatim): do not treat '"' specially. + + * lyxrc.C (read): in RC_BIND, allow escaped sequences in the + command (necessary to pass " as parameter of self-insert. + + * text.C (selectWordWhenUnderCursor): + (selectWord): add word_location parameter + (selectWordWhenUnderCursor): same + remove special code for word + boundary. + (selectNextWord): use kind() to guess type of insetspecialchar, + not latex(). + + * buffer.C (insertStringAsLines): new method, extracted from LyXText. + (insertErtContents): create ert insets as collapsed. + (readInset): better compatibility code for Info inset. + 2001-07-20 Juergen Vigna * lyxfunc.C (dispatch): use always LyXFind now! diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 166c0076bf..98f1539175 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -135,9 +135,9 @@ Menu & Menu::read(LyXLex & lex) optional = true; // fallback to md_item case md_item: { - lex.next(); + lex.next(true); string const name = _(lex.GetString()); - lex.next(); + lex.next(true); string const command = lex.GetString(); add(MenuItem(MenuItem::Command, name, command, optional)); @@ -186,9 +186,9 @@ Menu & Menu::read(LyXLex & lex) break; case md_submenu: { - lex.next(); + lex.next(true); string mlabel = _(lex.GetString()); - lex.next(); + lex.next(true); string mname = lex.GetString(); add(MenuItem(MenuItem::Submenu, mlabel, mname)); break; @@ -438,7 +438,7 @@ void MenuBackend::read(LyXLex & lex) menubar = true; // fallback to md_menu case md_menu: { - lex.next(); + lex.next(true); string name = lex.GetString(); if (hasMenu(name)) { if (getMenu(name).menubar() == menubar) { diff --git a/src/ToolbarDefaults.C b/src/ToolbarDefaults.C index a51b9ff984..390dabb43c 100644 --- a/src/ToolbarDefaults.C +++ b/src/ToolbarDefaults.C @@ -114,7 +114,7 @@ void ToolbarDefaults::read(LyXLex & lex) while (lex.IsOK() && !quit) { switch (lex.lex()) { case TO_ADD: - if (lex.next()) { + if (lex.next(true)) { func = lex.GetString(); lyxerr[Debug::PARSER] << "Toolbar::read TO_ADD func: `" diff --git a/src/buffer.C b/src/buffer.C index cc41db67b7..da8410f78d 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -79,6 +79,7 @@ #include "insets/insettheorem.h" #include "insets/insetcaption.h" #include "insets/insetfloatlist.h" +#include "support/textutils.h" #include "support/filetools.h" #include "support/path.h" #include "support/os.h" @@ -388,7 +389,7 @@ void Buffer::insertErtContents(Paragraph * par, int & pos, if (!ert_comp.contents.empty()) { lyxerr[Debug::INSETS] << "ERT contents:\n" << ert_comp.contents << endl; - Inset * inset = new InsetERT(ert_comp.contents); + Inset * inset = new InsetERT(ert_comp.contents, true); par->insertInset(pos++, inset, font); ert_comp.contents.erase(); } @@ -1314,6 +1315,59 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, return the_end_read; } +// needed to insert the selection +void Buffer::insertStringAsLines(Paragraph *& par, Paragraph::size_type & pos, + LyXFont const & font, + string const & str) const +{ + LyXLayout const & layout = textclasslist.Style(params.textclass, + par->getLayout()); + // insert the string, don't insert doublespace + bool space_inserted = true; + for(string::const_iterator cit = str.begin(); + cit != str.end(); ++cit) { + if (*cit == '\n') { + if (par->size() || layout.keepempty) { + par->breakParagraph(params, pos, + layout.isEnvironment()); + par = par->next(); + pos = 0; + space_inserted = true; + } else { + continue; + } + // do not insert consecutive spaces if !free_spacing + } else if ((*cit == ' ' || *cit == '\t') + && space_inserted && !layout.free_spacing) { + continue; + } else if (*cit == '\t') { + if (!layout.free_spacing) { + // tabs are like spaces here + par->insertChar(pos, ' ', font); + ++pos; + space_inserted = true; + } else { + const Paragraph::value_type nb = 8 - pos % 8; + for (Paragraph::size_type a = 0; + a < nb ; ++a) { + par->insertChar(pos, ' ', font); + ++pos; + } + space_inserted = true; + } + } else if (!IsPrintable(*cit)) { + // Ignore unprintables + continue; + } else { + // just insert the character + par->insertChar(pos, *cit, font); + ++pos; + space_inserted = (*cit == ' '); + } + + } +} + void Buffer::readInset(LyXLex & lex, Paragraph *& par, int & pos, LyXFont & font) @@ -1378,6 +1432,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, inset = new InsetParent(inscmd, *this); } } else { + bool alreadyread = false; if (tmptok == "Quotes") { inset = new InsetQuotes; } else if (tmptok == "External") { @@ -1388,8 +1443,12 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, inset = new InsetFormula; } else if (tmptok == "Figure") { inset = new InsetFig(100, 100, *this); - } else if (tmptok == "Info" // backwards compatibility - || tmptok == "Note") { + } else if (tmptok == "Info") {// backwards compatibility + inset = new InsetNote(this, + lex.getLongString("\\end_inset"), + true); + alreadyread = true; + } else if (tmptok == "Note") { inset = new InsetNote; } else if (tmptok == "Include") { InsetCommandParams p( "Include" ); @@ -1422,7 +1481,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, inset = new InsetFloatList; } - if (inset) inset->read(this, lex); + if (inset && !alreadyread) inset->read(this, lex); } if (inset) { diff --git a/src/buffer.h b/src/buffer.h index dedb17f273..94b5297b81 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -125,6 +125,9 @@ public: Paragraph::depth_type & depth, LyXFont &); /// + void insertStringAsLines(Paragraph *&, Paragraph::size_type &, + LyXFont const &, string const &) const; + /// void insertErtContents(Paragraph * par, int & pos, LyXFont const & font, bool set_inactive = true); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 06f058404b..8f32415840 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,34 @@ +2001-07-22 Jean-Marc Lasgouttes + + * insetcollapsable.h: make WidthCollapsed mutable. + + * insetindex.C (lyxCode): InsetIndex returns INDEX_CODE, + InsetPrintIndex returns INDEX_PRINT_CODE. + + * inset.h: add INDEX_PRINT_CODE + + * insetcollapsable.C (draw): init widthCollapsed if necessary + (width): ditto. + + * insetquotes.C (width): use the local language, not the document + language. + (draw): ditto. + (dispString): add additional spacing for all french languages, + like fr_CA. + (validate): make it work when there is no default language + + * insetspecialchar.h: rename kind to kind_; add kind() accessor. + + * insetnote.C (init): new method, called by the constructors + (InsetNote): new constructor with contents passed as a string + +2001-07-21 Jean-Marc Lasgouttes + + * insetfootlike.C (insetAllowed): disallow float in footlike. + + * insetert.C (InsetERT): add collapsed argument to the constrctor + with contents. + 2001-07-20 Jean-Marc Lasgouttes * insetindex.h: shut off warning diff --git a/src/insets/inset.h b/src/insets/inset.h index b095fab7e6..c309e60a53 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -106,7 +106,9 @@ public: /// CITE_CODE, /// - FLOAT_LIST_CODE + FLOAT_LIST_CODE, + /// + INDEX_PRINT_CODE }; /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index b99efbb55c..5d6739fbcf 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -32,20 +32,18 @@ using std::endl; using std::max; -InsetCollapsable::InsetCollapsable() - : UpdatableInset() +InsetCollapsable::InsetCollapsable(bool collapsed) + : UpdatableInset(), collapsed_(collapsed), + button_length(0), button_top_y(0), button_bottom_y(0), + label("Label"), autocollapse(true), + widthCollapsed(0), oldWidth(0), need_update(FULL) + { inset.setOwner(this); - collapsed_ = false; - label = "Label"; - autocollapse = true; inset.setAutoBreakRows(true); inset.setDrawFrame(0, InsetText::ALWAYS); inset.setFrameColor(0, LColor::collapsableframe); - button_length = button_top_y = button_bottom_y = 0; setInsetName("Collapsable"); - widthCollapsed = oldWidth = 0; - need_update = FULL; } @@ -138,6 +136,9 @@ int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const { + if (!widthCollapsed) + widthCollapsed = width_collapsed(bv->painter(), font); + if (collapsed_) return widthCollapsed; @@ -164,6 +165,9 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, Painter & pain = bv->painter(); + if (!widthCollapsed) + widthCollapsed = width_collapsed(pain, f); + button_length = widthCollapsed; button_top_y = -ascent(bv, f); button_bottom_y = -ascent(bv, f) + ascent_collapsed(pain,f) + diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index e672030953..05dfb96f48 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -27,7 +27,7 @@ class LyXText; class Paragraph; class LyXCursor; -/** A colapsable text inset +/** A collapsable text inset */ class InsetCollapsable : public UpdatableInset { @@ -41,8 +41,8 @@ public: static int const TEXT_TO_TOP_OFFSET = 2; /// static int const TEXT_TO_BOTTOM_OFFSET = 2; - /// - InsetCollapsable(); + /// inset is initially collapsed if bool = true + InsetCollapsable(bool = false); /// void read(Buffer const *, LyXLex &); /// @@ -219,7 +219,7 @@ private: /// bool autocollapse; /// - int widthCollapsed; + mutable int widthCollapsed; /// mutable int oldWidth; /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index d6c4542ae0..14bdf5e3f7 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -37,7 +37,8 @@ InsetERT::InsetERT() : InsetCollapsable() } -InsetERT::InsetERT(string const & contents) +InsetERT::InsetERT(string const & contents, bool collapsed) + : InsetCollapsable(collapsed) { setLabel(_("666")); LyXFont font(LyXFont::ALL_SANE); diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 9533e8eee0..f6a0ebde9d 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -30,7 +30,7 @@ public: /// InsetERT(); /// - InsetERT(string const & contents); + InsetERT(string const & contents, bool collapsed); /// virtual void write(Buffer const * buf, std::ostream & os) const; /// diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index 75dd3ad581..e58ae00e72 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -42,7 +42,8 @@ void InsetFootlike::write(Buffer const * buf, std::ostream & os) const bool InsetFootlike::insetAllowed(Inset::Code code) const { - if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE)) + if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE) + || (code ==Inset::FLOAT_CODE)) return false; return InsetCollapsable::insetAllowed(code); } diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index eccde8d07c..87b3cfaa19 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -34,6 +34,12 @@ void InsetIndex::edit(BufferView * bv, bool) } +Inset::Code InsetIndex::lyxCode() const +{ + return Inset::INDEX_CODE; +} + + InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool) : InsetCommand(p) {} @@ -52,5 +58,5 @@ void InsetPrintIndex::validate(LaTeXFeatures & features) const Inset::Code InsetPrintIndex::lyxCode() const { - return Inset::INDEX_CODE; + return Inset::INDEX_PRINT_CODE; } diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 0479937a8e..051d78cd3f 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -38,6 +38,8 @@ public: void edit(BufferView *, int, int, unsigned int); /// void edit(BufferView * bv, bool front = true); + /// + Inset::Code lyxCode() const; }; diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 4463747b7d..89ac827f58 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -17,6 +17,7 @@ #include "insetnote.h" #include "gettext.h" #include "lyxfont.h" +#include "buffer.h" #include "BufferView.h" #include "lyxtext.h" #include "insets/insettext.h" @@ -25,19 +26,34 @@ using std::ostream; -InsetNote::InsetNote() - : InsetCollapsable() +void InsetNote::init() { LyXFont font(LyXFont::ALL_SANE); font.decSize(); font.setColor(LColor::note); setLabelFont(font); - setAutoCollapse(true); + setAutoCollapse(false); setLabel(_("note")); setInsetName("Note"); } +InsetNote::InsetNote() + : InsetCollapsable() +{ + init(); +} + +InsetNote::InsetNote(Buffer const * buf, string const & contents, + bool collapsed) + : InsetCollapsable(collapsed) +{ + init(); + + Paragraph * par = inset.paragraph(); + Paragraph::size_type pos = 0; + buf->insertStringAsLines(par, pos, labelfont, contents); +} Inset * InsetNote::clone(Buffer const &, bool same_id) const { diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 5ac501f845..a23fbdb219 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -23,8 +23,10 @@ */ class InsetNote : public InsetCollapsable { public: - /// + /// InsetNote(); + /// constructor with initial contents + InsetNote(Buffer const *, string const & contents, bool collapsed); /// virtual Inset * clone(Buffer const &, bool) const; /// @@ -36,6 +38,10 @@ public: /// virtual int latex(Buffer const *, std::ostream &, bool, bool) const { return 0; } +private: + /// used by the constructors + void init(); + }; #endif diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 695187a494..ecb30cb143 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -145,7 +145,7 @@ void InsetQuotes::parseString(string const & s) } -string const InsetQuotes::dispString(Language const * doclang) const +string const InsetQuotes::dispString(Language const * loclang) const { string disp; disp += quote_char[quote_index[side_][language_]]; @@ -160,7 +160,7 @@ string const InsetQuotes::dispString(Language const * doclang) const disp = '»'; // in french, spaces are added inside double quotes - if (times_ == DoubleQ && doclang->code() == "fr") { + if (times_ == DoubleQ && prefixIs(loclang->code(), "fr")) { if (side_ == LeftQ) disp += " "; else @@ -183,9 +183,9 @@ int InsetQuotes::descent(BufferView *, LyXFont const & font) const } -int InsetQuotes::width(BufferView * bv, LyXFont const & font) const +int InsetQuotes::width(BufferView *, LyXFont const & font) const { - string text = dispString(bv->buffer()->getLanguage()); + string const text = dispString(font.language()); int w = 0; for (string::size_type i = 0; i < text.length(); ++i) { @@ -215,7 +215,7 @@ LyXFont const InsetQuotes::convertFont(LyXFont const & f) const void InsetQuotes::draw(BufferView * bv, LyXFont const & font, int baseline, float & x, bool) const { - string text = dispString(bv->buffer()->getLanguage()); + string const text = dispString(font.language()); bv->painter().text(int(x), baseline, text, font); x += width(bv, font); @@ -237,10 +237,8 @@ void InsetQuotes::read(Buffer const *, LyXLex & lex) lex.nextToken(); parseString(lex.GetString()); lex.next(); - string tmp(lex.GetString()); - if (tmp != "\\end_inset") - lyxerr << "LyX Warning: Missing \\end_inset " - "in InsetQuotes::Read." << endl; + if (lex.GetString() != "\\end_inset") + lex.printError("Missing \\end_inset at this point"); } @@ -249,8 +247,11 @@ extern bool use_babel; int InsetQuotes::latex(Buffer const * buf, ostream & os, bool /*fragile*/, bool) const { +#ifdef WITH_WARNINGS +#warning How do we get the local language here?? +#endif string const doclang = buf->getLanguage()->babel(); - int quoteind = quote_index[side_][language_]; + const int quoteind = quote_index[side_][language_]; string qstr; if (language_ == FrenchQ && times_ == DoubleQ) { @@ -258,7 +259,7 @@ int InsetQuotes::latex(Buffer const * buf, ostream & os, if (side_ == LeftQ) qstr = "\\og "; //the spaces are important here else - qstr = " \\fg "; //and here + qstr = " \\fg{}"; //and here } else if (doclang == "french") { if (side_ == LeftQ) qstr = "<< "; //the spaces are important here @@ -321,7 +322,11 @@ void InsetQuotes::validate(LaTeXFeatures & features) const { char type = quote_char[quote_index[side_][language_]]; +#ifdef DO_USE_DEFAULT_LANGUAGE if (features.bufferParams().language->lang() == "default" +#else + if (!use_babel +#endif && lyxrc.fontenc != "T1") { if (times_ == SingleQ) switch (type) { diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 7979f1ff8f..fd4181bc6c 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -24,10 +24,15 @@ using std::ostream; using std::max; InsetSpecialChar::InsetSpecialChar(Kind k) - : kind(k) + : kind_(k) {} +InsetSpecialChar::Kind InsetSpecialChar::kind() const +{ + return kind_; +} + int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const { return lyxfont::maxAscent(font); @@ -42,7 +47,7 @@ int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const int InsetSpecialChar::width(BufferView *, LyXFont const & font) const { - switch (kind) { + switch (kind_) { case HYPHENATION: { int w = lyxfont::width('-', font); @@ -82,7 +87,7 @@ void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, Painter & pain = bv->painter(); LyXFont font(f); - switch (kind) { + switch (kind_) { case HYPHENATION: { font.setColor(LColor::special); @@ -158,7 +163,7 @@ void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, void InsetSpecialChar::write(Buffer const *, ostream & os) const { string command; - switch (kind) { + switch (kind_) { case HYPHENATION: command = "\\-"; break; @@ -190,18 +195,18 @@ void InsetSpecialChar::read(Buffer const *, LyXLex & lex) string const command = lex.GetString(); if (command == "\\-") - kind = HYPHENATION; + kind_ = HYPHENATION; else if (command == "\\textcompwordmark{}") - kind = LIGATURE_BREAK; + kind_ = LIGATURE_BREAK; else if (command == "\\@.") - kind = END_OF_SENTENCE; + kind_ = END_OF_SENTENCE; else if (command == "\\ldots{}") - kind = LDOTS; + kind_ = LDOTS; else if (command == "\\menuseparator") - kind = MENU_SEPARATOR; + kind_ = MENU_SEPARATOR; else if (command == "\\protected_separator" || command == "~") - kind = PROTECTED_SEPARATOR; + kind_ = PROTECTED_SEPARATOR; else lex.printError("InsetSpecialChar: Unknown kind: `$$Token'"); } @@ -210,7 +215,7 @@ void InsetSpecialChar::read(Buffer const *, LyXLex & lex) int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/, bool free_space) const { - switch (kind) { + switch (kind_) { case HYPHENATION: os << "\\-"; break; @@ -236,7 +241,7 @@ int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/, int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const { - switch (kind) { + switch (kind_) { case HYPHENATION: case LIGATURE_BREAK: break; @@ -271,13 +276,13 @@ int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const Inset * InsetSpecialChar::clone(Buffer const &, bool) const { - return new InsetSpecialChar(kind); + return new InsetSpecialChar(kind_); } void InsetSpecialChar::validate(LaTeXFeatures & features) const { - if (kind == MENU_SEPARATOR) { + if (kind_ == MENU_SEPARATOR) { features.lyxarrow = true; } } diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 507f42cb8f..20ff5b3360 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -46,6 +46,8 @@ public: explicit InsetSpecialChar(Kind k); /// + Kind kind() const; + /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; @@ -82,7 +84,7 @@ public: void validate(LaTeXFeatures &) const; private: /// And which kind is this? - Kind kind; + Kind kind_; }; #endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 2d706ca101..860b6958bc 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -600,12 +600,14 @@ func_status::value_type LyXFunc::getStatus(int ac, case LFUN_INSET_ERT: code = Inset::ERT_CODE; break; + case LFUN_FIGURE: case LFUN_INSET_GRAPHICS: code = Inset::GRAPHICS_CODE; break; case LFUN_INSET_FOOTNOTE: code = Inset::FOOT_CODE; break; + case LFUN_DIALOG_TABULAR_INSERT: case LFUN_INSET_TABULAR: code = Inset::TABULAR_CODE; break; @@ -622,6 +624,9 @@ func_status::value_type LyXFunc::getStatus(int ac, case LFUN_INSET_WIDE_FLOAT: code = Inset::FLOAT_CODE; break; + case LFUN_FLOAT_LIST: + code = Inset::FLOAT_LIST_CODE; + break; #if 0 case LFUN_INSET_LIST: code = Inset::LIST_CODE; @@ -642,6 +647,7 @@ func_status::value_type LyXFunc::getStatus(int ac, case LFUN_REF_INSERT: code = Inset::REF_CODE; break; + case LFUN_CITATION_CREATE: case LFUN_CITATION_INSERT: code = Inset::CITE_CODE; break; @@ -650,22 +656,40 @@ func_status::value_type LyXFunc::getStatus(int ac, break; case LFUN_INDEX_INSERT: case LFUN_INDEX_INSERT_LAST: + case LFUN_INDEX_CREATE: code = Inset::INDEX_CODE; break; -#if 0 + case LFUN_INDEX_PRINT: + code = Inset::INDEX_PRINT_CODE; + break; case LFUN_CHILD_INSERT: - code = Inset::CHILD_CODE; + code = Inset::INCLUDE_CODE; break; -#endif case LFUN_TOC_INSERT: code = Inset::TOC_CODE; break; case LFUN_PARENTINSERT: code = Inset::PARENT_CODE; break; + case LFUN_HTMLURL: + case LFUN_URL: case LFUN_INSERT_URL: code = Inset::URL_CODE; break; + case LFUN_QUOTE: + // always allow this, since we will inset a raw quote + // if an inset is not allowed. + break; + case LFUN_HYPHENATION: + case LFUN_LIGATURE_BREAK: + case LFUN_HFILL: + case LFUN_MENU_SEPARATOR: + case LFUN_LDOTS: + case LFUN_END_OF_SENTENCE: + case LFUN_PROTECTEDSPACE: + case LFUN_BREAKLINE: + code = Inset::SPECIALCHAR_CODE; + break; default: break; } diff --git a/src/lyxrc.C b/src/lyxrc.C index bc3b7d302e..ebaa3dccf3 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -698,17 +698,17 @@ int LyXRC::read(string const & filename) int action, res = 0; string seq, cmd; - if (lexrc.lex() == LyXLex::LEX_DATA) { + if (lexrc.next()) { seq = lexrc.GetString(); } else { - lexrc.printError("Bad key sequence: `$$Token'"); + lexrc.printError("RC_BIND: Missing key sequence"); break; } - if (lexrc.lex() == LyXLex::LEX_DATA) { + if (lexrc.next(true)) { cmd = lexrc.GetString(); } else { - lexrc.printError("Bad command: `$$Token'"); + lexrc.printError("RC_BIND: missing command"); break; } diff --git a/src/lyxtext.h b/src/lyxtext.h index e6d29ca8f4..87d6b78c4b 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -268,9 +268,10 @@ public: string const selectionAsString(Buffer const *) const; /// select the word we need depending on word_location - void getWord(LyXCursor & from, LyXCursor & to, word_location) const; + void getWord(LyXCursor & from, LyXCursor & to, + word_location const) const; /// just selects the word the cursor is in - void selectWord(BufferView *); + void selectWord(BufferView *, word_location const = WHOLE_WORD); /// returns the inset at cursor (if it exists), 0 otherwise Inset * getInset() const; @@ -351,7 +352,8 @@ public: /// void deleteLineForward(BufferView *); /// - bool selectWordWhenUnderCursor(BufferView *); + bool selectWordWhenUnderCursor(BufferView *, + word_location const = WHOLE_WORD); /// enum TextCase { /// diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 5f6719d1f9..3d1d494400 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,7 @@ +2001-07-22 Jean-Marc Lasgouttes + + * formula.C (insetAllowed): allow insertion of label + 2001-07-20 André Pönitz * math_macrotable.C: support for \land and \vee diff --git a/src/mathed/formula.C b/src/mathed/formula.C index ffa4eaecb3..31af423668 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -325,6 +325,11 @@ void InsetFormula::validate(LaTeXFeatures & features) const par()->Validate(features); } +bool InsetFormula::insetAllowed(Inset::Code code) const +{ + return code == Inset::LABEL_CODE; +} + int InsetFormula::ascent(BufferView *, LyXFont const &) const { diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 41f8bca786..b98c7ef8dc 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -67,6 +67,8 @@ public: /// Inset::Code lyxCode() const; /// + bool insetAllowed(Inset::Code code) const; + /// virtual RESULT localDispatch(BufferView *, kb_action, string const &); /// std::vector const getLabelList() const; diff --git a/src/text.C b/src/text.C index 7e69df5421..01349da75c 100644 --- a/src/text.C +++ b/src/text.C @@ -19,6 +19,7 @@ #include "support/textutils.h" #include "insets/insetbib.h" #include "insets/insettext.h" +#include "insets/insetspecialchar.h" #include "lyx_gui_misc.h" #include "gettext.h" #include "bufferparams.h" @@ -2157,10 +2158,10 @@ void LyXText::cursorLeftOneWord(LyXCursor & cur) const } } -/* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is - patched as well. */ - -void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location loc) const +/* -------> Select current word. This depends on behaviour of +CursorLeftOneWord(), so it is patched as well. */ +void LyXText::getWord(LyXCursor & from, LyXCursor & to, + word_location const loc) const { // first put the cursor where we wana start to select the word from = cursor; @@ -2188,11 +2189,11 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location loc) const } -void LyXText::selectWord(BufferView * bview) +void LyXText::selectWord(BufferView * bview, word_location const loc) { LyXCursor from; LyXCursor to; - getWord(from, to, WHOLE_WORD); + getWord(from, to, loc); if (cursor != from) setCursor(bview, from.par(), from.pos()); selection.cursor = cursor; @@ -2202,17 +2203,21 @@ void LyXText::selectWord(BufferView * bview) /* -------> Select the word currently under the cursor when: 1: no selection is currently set, - 2: the cursor is not at the borders of the word. */ + [disabled] 2: the cursor is not at the borders of the word. */ -bool LyXText::selectWordWhenUnderCursor(BufferView * bview) +bool LyXText::selectWordWhenUnderCursor(BufferView * bview, + word_location const loc) { - if (!selection.set() && - cursor.pos() > 0 && cursor.pos() < cursor.par()->size() + if (!selection.set() +#if 0 + && cursor.pos() > 0 && cursor.pos() < cursor.par()->size() && !cursor.par()->isSeparator(cursor.pos()) && !cursor.par()->isKomma(cursor.pos()) && !cursor.par()->isSeparator(cursor.pos() -1) - && !cursor.par()->isKomma(cursor.pos() -1)) { - selectWord(bview); + && !cursor.par()->isKomma(cursor.pos() -1) +#endif + ) { + selectWord(bview, loc); return true; } return false; @@ -2291,17 +2296,18 @@ string const LyXText::selectNextWord(BufferView * bview, // Start the selection from here selection.cursor = cursor; - ostringstream latex; + Inset * inset; // and find the end of the word // (optional hyphens are part of a word) while (cursor.pos() < cursor.par()->size() && (cursor.par()->isLetter(cursor.pos())) - || (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET - && cursor.par()->getInset(cursor.pos()) != 0 - && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0 - && latex.str() == "\\-" - )) + // assignment is intentional here + || ((inset = getInset()) + && inset->lyxCode() == Inset::SPECIALCHAR_CODE + && static_cast(inset)->kind() + == InsetSpecialChar::HYPHENATION + )) cursor.pos(cursor.pos() + 1); // Finally, we copy the word to a string and return it @@ -2329,16 +2335,17 @@ void LyXText::selectSelectedWord(BufferView * bview) // set the sel cursor selection.cursor = cursor; - ostringstream latex; + Inset * inset; // now find the end of the word while (cursor.pos() < cursor.par()->size() && (cursor.par()->isLetter(cursor.pos()) - || (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET - && cursor.par()->getInset(cursor.pos()) != 0 - && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0 - && latex.str() == "\\-" - ))) + // assignment is intentional here + || ((inset = getInset()) + && inset->lyxCode() == Inset::SPECIALCHAR_CODE + && static_cast(inset)->kind() + == InsetSpecialChar::HYPHENATION + ))) cursor.pos(cursor.pos() + 1); setCursor(bview, cursor.par(), cursor.pos()); diff --git a/src/text2.C b/src/text2.C index 33bd234118..2e1972b842 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1785,65 +1785,10 @@ void LyXText::insertStringAsLines(BufferView * bview, string const & str) setCursorParUndo(bview); - bool isEnvironment = - textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).isEnvironment(); - bool free_spacing = - textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).free_spacing; - bool keepempty = - textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).keepempty; - // only to be sure, should not be neccessary clearSelection(bview); - // insert the string, don't insert doublespace - bool space_inserted = true; - for(string::const_iterator cit = str.begin(); - cit != str.end(); ++cit) { - if (*cit == '\n') { - if (par->size() || keepempty) { - par->breakParagraph(bview->buffer()->params, - pos, isEnvironment); - par = par->next(); - pos = 0; - space_inserted = true; - } else { - continue; - } - // do not insert consecutive spaces if !free_spacing - } else if ((*cit == ' ' || *cit == '\t') - && space_inserted && !free_spacing) { - continue; - } else if (*cit == '\t') { - if (!free_spacing) { - // tabs are like spaces here - par->insertChar(pos, ' ', - current_font); - ++pos; - space_inserted = true; - } else { - const Paragraph::value_type nb = 8 - pos % 8; - for (Paragraph::size_type a = 0; - a < nb ; ++a) { - par->insertChar(pos, ' ', - current_font); - ++pos; - } - space_inserted = true; - } - } else if (!IsPrintable(*cit)) { - // Ignore unprintables - continue; - } else { - // just insert the character - par->insertChar(pos, *cit, current_font); - ++pos; - space_inserted = (*cit == ' '); - } - - } + bview->buffer()->insertStringAsLines(par, pos, current_font, str); redoParagraphs(bview, cursor, endpar); setCursor(bview, cursor.par(), cursor.pos()); diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 3c5a6904d9..547452a078 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -15,7 +15,6 @@ #include "buffer.h" #include "lyxrc.h" #include "support/lstrings.h" -#include "language.h" using std::endl; using std::pair; @@ -372,16 +371,7 @@ void TransManager::insertVerbatim(string const & str, LyXText * text) string::size_type const l = str.length(); for (string::size_type i = 0; i < l; ++i) { - if (str[i] == '\"' -#ifndef NO_LATEX - && text->getFont(current_view->buffer(),text->cursor.par(), - text->cursor.pos()).latex() == LyXFont::OFF -#endif - && text->getFont(current_view->buffer(),text->cursor.par(), - text->cursor.pos()).language()->lang() != "hebrew") - current_view->insertCorrectQuote(); - else - text->insertChar(current_view, str[i]); + text->insertChar(current_view, str[i]); } } @@ -390,7 +380,7 @@ void TransManager::insert(string const & str, LyXText * text) { // Go through the character encoding only if the current // encoding (chset_->name()) matches the current font_norm - // (lyrxc->font_norm + // (lyrxc->font_norm) // Is false to speak about "only if" the current encoding will // almost always be equal to font_norm.