]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Remove unused font variable which caused a warning.
[lyx.git] / src / BufferView_pimpl.C
index e63c903df79f0b321b948aa4f22d9bffdb5c21b4..e3a4b0f8a13e98ecc826367dea6ad9c34d03d2c1 100644 (file)
@@ -41,7 +41,7 @@
 #include "insets/insetref.h"
 #include "insets/insetparent.h"
 #include "insets/insetindex.h"
-#include "insets/insetinfo.h"
+#include "insets/insetnote.h"
 #include "insets/insetinclude.h"
 #include "insets/insetcite.h"
 #include "insets/insetert.h"
 #include "insets/insetmarginal.h"
 #include "insets/insetminipage.h"
 #include "insets/insetfloat.h"
-#include "insets/insetlist.h"
 #include "insets/insettabular.h"
+#if 0
 #include "insets/insettheorem.h"
+#include "insets/insetlist.h"
+#endif
 #include "insets/insetcaption.h"
 #include "insets/insetfloatlist.h"
 #include "insets/insetspecialchar.h"
 #include "gettext.h"
 #include "ParagraphParameters.h"
+#include "undo_funcs.h"
 #include "mathed/formulabase.h"
 
 extern LyXTextClass::size_type current_layout;
@@ -81,7 +84,7 @@ extern BufferList bufferlist;
 extern char ascii_type;
 
 extern bool math_insert_greek(BufferView *, char);
-extern void sigchldhandler(pid_t pid, int * status);
+extern void sigchldchecker(pid_t pid, int * status);
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 
@@ -255,9 +258,16 @@ bool BufferView::Pimpl::fitCursor(LyXText * text)
 {
        lyx::Assert(screen_.get());
 
-       bv_->owner()->getDialogs()->updateParagraph();
+       bool ret;
+
+       if (bv_->theLockingInset()) {
+               bv_->theLockingInset()->fitInsetCursor(bv_);
+               ret = true;
+       } else {
+               ret = screen_->fitCursor(text, bv_);
+       }
 
-       bool const ret = screen_->fitCursor(text, bv_);
+       bv_->owner()->getDialogs()->updateParagraph();
        if (ret)
            updateScrollbar();
        return ret;
@@ -376,7 +386,6 @@ void BufferView::Pimpl::updateScrollbar()
        /* If the text is smaller than the working area, the scrollbar
         * maximum must be the working area height. No scrolling will 
         * be possible */
-
        if (!bv_->text) {
                workarea_.setScrollbar(0, 1.0);
                return;
@@ -385,11 +394,12 @@ void BufferView::Pimpl::updateScrollbar()
        long const text_height = bv_->text->height;
 
        double const lineh = bv_->text->defaultHeight();
-       double const slider_size = 1.0 / double(text_height);
+       double const slider_size =
+               (text_height == 0) ? 1.0 : 1.0 / double(text_height);
 
-       static long old_text_height;
-       static double old_lineh;
-       static double old_slider_size;
+       static long old_text_height = 0;
+       static double old_lineh = 0;
+       static double old_slider_size = 0;
 
        if (text_height != old_text_height) {
                workarea_.setScrollbarBounds(0, text_height - workarea_.height());
@@ -597,7 +607,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        bool paste_internally = false;
        if (button == 2
            && bv_->text->selection.set()) {
-               owner_->getLyXFunc()->Dispatch(LFUN_COPY);
+               owner_->getLyXFunc()->dispatch(LFUN_COPY);
                paste_internally = true;
        }
        
@@ -629,7 +639,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        
        if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
                bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
-       bv_->text->finishUndo();
+       finishUndo();
        bv_->text->selection.cursor = bv_->text->cursor;
        bv_->text->cursor.x_fix(bv_->text->cursor.x());
        
@@ -643,9 +653,9 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        // insert this
        if (button == 2) {
                if (paste_internally)
-                       owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
+                       owner_->getLyXFunc()->dispatch(LFUN_PASTE);
                else
-                       owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
+                       owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
                                                       "paragraph");
                selection_possible = false;
                return;
@@ -774,7 +784,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                // ...or maybe the SetCursorParUndo()
                // below isn't necessary at all anylonger?
                if (inset_hit->lyxCode() == Inset::REF_CODE) {
-                       bv_->text->setCursorParUndo(buffer_);
+                       setCursorParUndo(bv_);
                }
 
                owner_->message(inset_hit->editMessage());
@@ -1003,14 +1013,15 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
        text->fullRebreak(bv_);
 
        if (text->inset_owner) {
-           text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
+               text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
            updateInset(text->inset_owner, true);
-       } else
+       } else {
            update();
-
+       }
+               
        if ((f & FITCUR)) {
                fitCursor(text);
-       }
+       }
 
        if ((f & CHANGE)) {
                buffer_->markDirty();
@@ -1033,7 +1044,7 @@ void BufferView::Pimpl::cursorToggle()
        if (pid == -1) // error find out what is wrong
                ; // ignore it for now.
        else if (pid > 0)
-               sigchldhandler(pid, &status);
+               sigchldchecker(pid, &status);
 
        updatelist.update(bv_);
        
@@ -1062,7 +1073,7 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
                y += bv_->text->first;
        Row * cursorrow = text->cursor.row();
        text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
-       bv_->text->finishUndo();
+       finishUndo();
        // This is to allow jumping over large insets
        if ((cursorrow == text->cursor.row()))
                text->cursorUp(bv_);
@@ -1090,7 +1101,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
     
        Row * cursorrow = text->cursor.row();
        text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
-       bv_->text->finishUndo();
+       finishUndo();
        // This is to allow jumping over large insets
        if ((cursorrow == bv_->text->cursor.row()))
                text->cursorDown(bv_);
@@ -1148,7 +1159,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
                if (b != 0 ) buffer(b);
        }
 
-       Paragraph * par = bv_->text->getParFromID(saved_positions[i].par_id);
+       Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
        if (!par)
                return;
 
@@ -1219,7 +1230,7 @@ void BufferView::Pimpl::insetUnlock()
                if (!inset_slept)
                        bv_->theLockingInset()->insetUnlock(bv_);
                bv_->theLockingInset(0);
-               bv_->text->finishUndo();
+               finishUndo();
                inset_slept = false;
        }
 }
@@ -1251,22 +1262,33 @@ bool BufferView::Pimpl::belowMouse() const
 
 void BufferView::Pimpl::showCursor()
 {
-       if (screen_.get())
-               screen_->showCursor(bv_->text, bv_);
+       if (screen_.get()) {
+               if (bv_->theLockingInset())
+                       bv_->theLockingInset()->showInsetCursor(bv_);
+               else
+                       screen_->showCursor(bv_->text, bv_);
+       }
 }
 
 
 void BufferView::Pimpl::hideCursor()
 {
-       if (screen_.get())
-               screen_->hideCursor();
+       if (screen_.get()) {
+               if (!bv_->theLockingInset())
+//                     bv_->theLockingInset()->hideInsetCursor(bv_);
+//             else
+                       screen_->hideCursor();
+       }
 }
 
 
 void BufferView::Pimpl::toggleSelection(bool b)
 {
-       if (screen_.get())
+       if (screen_.get()) {
+               if (bv_->theLockingInset())
+                       bv_->theLockingInset()->toggleSelection(bv_, b);
                screen_->toggleSelection(bv_->text, bv_, b);
+       }
 }
 
 
@@ -1463,7 +1485,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                } else {
                        // this is need because you don't use a inset->Edit()
                        updateInset(new_inset, true);
-                       new_inset->edit(bv_, 0, 0, 0);
+                       new_inset->edit(bv_);
                }
                break;
        }
@@ -1516,19 +1538,23 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
 
        case LFUN_HYPHENATION:
-               hyphenationPoint();
+               specialChar(InsetSpecialChar::HYPHENATION);
+               break;
+               
+       case LFUN_LIGATURE_BREAK:
+               specialChar(InsetSpecialChar::LIGATURE_BREAK);
                break;
                
        case LFUN_LDOTS:
-               ldots();
+               specialChar(InsetSpecialChar::LDOTS);
                break;
                
        case LFUN_END_OF_SENTENCE:
-               endOfSentenceDot();
+               specialChar(InsetSpecialChar::END_OF_SENTENCE);
                break;
 
        case LFUN_MENU_SEPARATOR:
-               menuSeparator();
+               specialChar(InsetSpecialChar::MENU_SEPARATOR);
                break;
                
        case LFUN_HFILL:
@@ -1806,20 +1832,15 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                    && lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
-                       int y = 0;
-                       if (is_rtl) {
-                               LyXFont const font = 
-                                       lt->getFont(buffer_,
-                                                   lt->cursor.par(),
-                                                   lt->cursor.pos());  
-                               y = tmpinset->descent(bv_,font);
-                       }
-                       tmpinset->edit(bv_, 0, y, 0);
+                       if (is_rtl)
+                               tmpinset->edit(bv_, false);
+                       else
+                               tmpinset->edit(bv_);
                        break;
                }
                if (!is_rtl)
                        lt->cursorRight(bv_, false);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1847,21 +1868,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                {
                        Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
                        owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
-                       LyXFont const font = lt->getFont(buffer_,
-                                                        lt->cursor.par(),
-                                                        lt->cursor.pos());
-                       int y = is_rtl ? 0 
-                               : tmpinset->descent(bv_,font);
-                       tmpinset->edit(bv_,
-                                      tmpinset->x() +
-                                      tmpinset->width(bv_,font),
-                                      y, 0);
+                       if (is_rtl)
+                               tmpinset->edit(bv_);
+                       else
+                               tmpinset->edit(bv_, false);
                        break;
                }
                if  (is_rtl)
                        lt->cursorRight(bv_, false);
 
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1875,7 +1891,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorUp(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1889,7 +1905,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorDown(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1903,7 +1919,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorUpParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1917,7 +1933,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorDownParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1931,7 +1947,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                cursorPrevious(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1945,7 +1961,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                cursorNext(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1959,7 +1975,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorHome(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1974,7 +1990,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorEnd(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1990,7 +2006,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTab(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2007,7 +2023,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeftOneWord(bv_);
                else
                        lt->cursorRightOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2024,7 +2040,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRightOneWord(bv_);
                else
                        lt->cursorLeftOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2039,7 +2055,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTop(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2054,7 +2070,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorBottom(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2071,7 +2087,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeft(bv_);
                else
                        lt->cursorRight(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2087,7 +2103,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRight(bv_);
                else
                        lt->cursorLeft(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2100,7 +2116,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorUp(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2113,7 +2129,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorDown(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2126,7 +2142,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorUpParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2139,7 +2155,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorDownParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2151,7 +2167,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                cursorPrevious(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2163,7 +2179,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                cursorNext(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2175,7 +2191,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorHome(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2187,7 +2203,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorEnd(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2202,7 +2218,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeftOneWord(bv_);
                else
                        lt->cursorRightOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2217,7 +2233,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRightOneWord(bv_);
                else
                        lt->cursorLeftOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2231,7 +2247,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        break;
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTop(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2246,7 +2262,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorBottom(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2633,8 +2649,20 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break;
        
+       case LFUN_INSET_TOGGLE:
+       {
+               LyXText * lt = bv_->getLyXText();
+               hideCursor();
+               beforeChange(lt);
+               update(lt, BufferView::SELECT|BufferView::FITCUR);
+               lt->toggleInset(bv_);
+               update(lt, BufferView::SELECT|BufferView::FITCUR);
+               setState();
+       }       
+               break;
+
        case LFUN_QUOTE:
-               bv_->insertCorrectQuote();
+               smartQuote();
                break;
 
        case LFUN_HTMLURL:
@@ -2645,99 +2673,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_, 0, 0, 0);
-               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_, 0, 0, 0);
-               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_, 0, 0, 0);
-               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_, 0, 0, 0);
-               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_, 0, 0, 0);
-               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_, 0, 0, 0);
-               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_, 0, 0, 0);
-                       else
-                               delete new_inset;
+                       insertAndEditInset(new InsetFloat(argument));
                } else {
                        lyxerr << "Non-existant float type: "
                               << argument << endl;
                }
-               
-       }
-       break;
+               break;
 
        case LFUN_INSET_WIDE_FLOAT:
        {
@@ -2746,7 +2735,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        InsetFloat * new_inset = new InsetFloat(argument);
                        new_inset->wide(true);
                        if (insertInset(new_inset))
-                               new_inset->edit(bv_, 0, 0, 0);
+                               new_inset->edit(bv_);
                        else
                                delete new_inset;
                } else {
@@ -2757,26 +2746,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        }
        break;
 
+#if 0
        case LFUN_INSET_LIST:
-       {
-               InsetList * new_inset = new InsetList;
-               if (insertInset(new_inset))
-                       new_inset->edit(bv_, 0, 0, 0);
-               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_, 0, 0, 0);
-               else
-                       delete new_inset;
-       }
-       break;
-
+               insertAndEditInset(new InsetTheorem);
+               break;
+#endif
+               
        case LFUN_INSET_CAPTION:
        {
                // Do we have a locking inset...
@@ -2789,7 +2768,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        new_inset->setDrawFrame(0, InsetText::LOCKED);
                        new_inset->setFrameColor(0, LColor::captionframe);
                        if (insertInset(new_inset))
-                               new_inset->edit(bv_, 0, 0, 0);
+                               new_inset->edit(bv_);
                        else
                                delete new_inset;
                }
@@ -2960,7 +2939,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                if (insertInset(inset)) {
                        if (argument.empty())
-                               inset->edit(bv_, 0, 0, 0);
+                               inset->edit(bv_);
                } else
                        delete inset;
        }
@@ -2999,24 +2978,21 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
        case LFUN_INDEX_CREATE:
        {
-               InsetCommandParams p( "index" );
+               InsetCommandParams p("index");
                
                if (argument.empty()) {
-                       // Get the word immediately preceding the cursor
-                       Paragraph::size_type curpos = 
-                               bv_->getLyXText()->cursor.pos() - 1;
-
-                       string curstring;
-                       if (curpos >= 0 )
-                               curstring = bv_->getLyXText()
-                                       ->cursor.par()->getWord(curpos);
+                       // Get word or selection
+                       bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
+                       
+                       string const curstring = 
+                               bv_->getLyXText()->selectionAsString(buffer_);
 
-                       p.setContents( curstring );
+                       p.setContents(curstring);
                } else {
-                       p.setContents( argument );
+                       p.setContents(argument);
                }
 
-               owner_->getDialogs()->createIndex( p.getAsString() );
+               owner_->getDialogs()->createIndex(p.getAsString());
        }
        break;
                    
@@ -3035,14 +3011,11 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                    
        case LFUN_INDEX_INSERT_LAST:
        {
-               // Get word immediately preceding the cursor
-               Paragraph::size_type curpos = 
-                       bv_->getLyXText()->cursor.pos() - 1;
-               // Can't do that at the beginning of a paragraph
-               if (curpos < 0) break;
+               // Get word or selection
+               bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
 
-               string const curstring(bv_->getLyXText()
-                                      ->cursor.par()->getWord(curpos));
+               string const curstring = 
+                       bv_->getLyXText()->selectionAsString(buffer_);
 
                InsetCommandParams p("index", curstring);
                InsetIndex * inset = new InsetIndex(p);
@@ -3099,10 +3072,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;
@@ -3125,7 +3094,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();
@@ -3236,6 +3205,12 @@ void BufferView::Pimpl::protectedBlank(LyXText * lt)
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                InsetSpecialChar * new_inset =
                        new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
+#ifdef WITH_WARNINGS
+#warning Why is this code different from specialChar() below? (JMarc)
+// the code in specialChar is a generic version of what used to exist
+// for other special chars. I did not merge this case because of the
+// call to updateInset(), but what does it do?
+#endif
                if (!insertInset(new_inset))
                        delete new_inset;
                else
@@ -3244,7 +3219,7 @@ void BufferView::Pimpl::protectedBlank(LyXText * lt)
 }
 
 
-void BufferView::Pimpl::menuSeparator()
+void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
 {
        if (available()) {
                LyXText * lt = bv_->getLyXText();
@@ -3252,72 +3227,49 @@ void BufferView::Pimpl::menuSeparator()
                hideCursor();
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
-               insertInset(new_inset);
-       }
-}
-
-
-void BufferView::Pimpl::endOfSentenceDot()
-{
-       if (available()) {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
+                       new InsetSpecialChar(kind);
                insertInset(new_inset);
        }
 }
 
 
-void BufferView::Pimpl::ldots()
+void BufferView::Pimpl::smartQuote()
 {
-       if (available())  {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::LDOTS);
-               insertInset(new_inset);
-       }
-}
+       char c;
+       LyXText * lt = bv_->getLyXText();
 
+       if (lt->cursor.pos())
+               c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
+       else 
+               c = ' ';
 
-void BufferView::Pimpl::hyphenationPoint()
-{
-       if (available()) {
-               hideCursor();
-               update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset = 
-                       new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
-               insertInset(new_inset);
-       }
+       hideCursor();
+       if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
+               Dispatch(LFUN_SELFINSERT, "\"");
 }
 
 
-void BufferView::Pimpl::insertNote()
+void BufferView::Pimpl::insertAndEditInset(Inset * inset)
 {
-       InsetInfo * new_inset = new InsetInfo();
-       insertInset(new_inset);
-       new_inset->edit(bv_, 0, 0, 0);
+       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)
 {
        LyXText * lt = bv_->getLyXText();
        
        beforeChange(lt);
-       lt->finishUndo();
+       finishUndo();
        if (!insertInset(new_inset)) {
                delete new_inset;
                return false;
        }
-       if (behind) {
-               LyXFont & font = lt->real_current_font;
-               new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
-       } else
-               new_inset->edit(bv_, 0, 0, 0);
+       new_inset->edit(bv_, !behind);
        return true;
 }
 
@@ -3327,14 +3279,14 @@ 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;
        }
 
        // not quite sure if we want this...
-       bv_->text->setCursorParUndo(buffer_);
-       bv_->text->freezeUndo();
+       setCursorParUndo(bv_);
+       freezeUndo();
        
        beforeChange(bv_->text);
        if (!lout.empty()) {
@@ -3378,7 +3330,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
        bv_->text->insertInset(bv_, inset);
        update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
 
-       bv_->text->unFreezeUndo();
+       unFreezeUndo();
        return true;
 }