]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
insetquote fix; getStatus tweaks
[lyx.git] / src / text2.C
index c61d56219ea49188cbb6af5881c50000d3a5f54d..938d9fd3a201fea559db7fc53fa9f8fff6538588 100644 (file)
@@ -25,6 +25,7 @@
 #include "layout.h"
 #include "LyXView.h"
 #include "support/textutils.h"
+#include "support/lstrings.h"
 #include "undo_funcs.h"
 #include "buffer.h"
 #include "bufferparams.h"
@@ -198,7 +199,7 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
        if (par->getChar(pos) == Paragraph::META_INSET) {
                Inset * inset = par->getInset(pos);
                if (inset) {
-                       if (inset->editable()==Inset::HIGHLY_EDITABLE) {
+                       if (inset->editable()==Inset::IS_EDITABLE) {
                                UpdatableInset * uinset =
                                        static_cast<UpdatableInset *>(inset);
                                uinset->setFont(bv, fnt, toggleall, true);
@@ -422,15 +423,14 @@ void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf,
        LyXLayout const & layout =
                textclasslist.Style(buf->params.textclass, par->getLayout());
 
-       LyXFont layoutfont, tmpfont;
-       for (Paragraph::size_type pos = 0;
-            pos < par->size(); ++pos) {
+       LyXFont layoutfont;
+       for (Paragraph::size_type pos = 0; pos < par->size(); ++pos) {
                if (pos < beginningOfMainBody(buf, par))
                        layoutfont = layout.labelfont;
                else
                        layoutfont = layout.font;
       
-               tmpfont = par->getFontSettings(buf->params, pos);
+               LyXFont tmpfont = par->getFontSettings(buf->params, pos);
                tmpfont.reduce(layoutfont);
                par->setFont(pos, tmpfont);
        }
@@ -523,7 +523,7 @@ void LyXText::setLayout(BufferView * bview, LyXTextClass::size_type layout)
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos(), false);
        updateCounters(bview, cursor.row());
-       clearSelection(bview);
+       clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
 }
@@ -604,7 +604,7 @@ void  LyXText::incDepth(BufferView * bview)
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
        updateCounters(bview, cursor.row());
-       clearSelection(bview);
+       clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
@@ -661,7 +661,7 @@ void  LyXText::decDepth(BufferView * bview)
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
        updateCounters(bview, cursor.row());
-       clearSelection(bview);
+       clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
@@ -723,7 +723,7 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
        setCursor(bview, selection.start.par(), selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       clearSelection(bview);
+       clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
                  tmpcursor.boundary());
@@ -779,7 +779,7 @@ void LyXText::redoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
 // and the specified par 
 // This function is needed after SetLayout and SetFont etc.
 void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
-                            Paragraph const * endpar) const
+                             Paragraph const * endpar) const
 {
        Row * tmprow2;
        Paragraph * tmppar = 0;
@@ -797,7 +797,8 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
        } else {
                first_phys_par = tmprow->par();
                while (tmprow->previous()
-                      && tmprow->previous()->par() == first_phys_par) {
+                      && tmprow->previous()->par() == first_phys_par)
+               {
                        tmprow = tmprow->previous();
                        y -= tmprow->height();
                }
@@ -807,8 +808,8 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
        status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = y;
        refresh_row = tmprow->previous();        /* the real refresh row will
-                                                   be deleted, so I store
-                                                   the previous here */ 
+                                               be deleted, so I store
+                                               the previous here */ 
        // remove it
        if (tmprow->next())
                tmppar = tmprow->next()->par();
@@ -824,7 +825,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
    
        // remove the first one
        tmprow2 = tmprow;     /* this is because tmprow->previous()
-                                can be 0 */
+                                can be 0 */
        tmprow = tmprow->previous();
        removeRow(tmprow2);
    
@@ -976,7 +977,7 @@ string const LyXText::selectionAsString(Buffer const * buffer) const
 }
 
 
-void LyXText::clearSelection(BufferView * /*bview*/) const
+void LyXText::clearSelection() const
 {
        selection.set(false);
        selection.mark(false);
@@ -1040,7 +1041,7 @@ void LyXText::toggleFree(BufferView * bview,
        LyXCursor resetCursor = cursor;
        bool implicitSelection = (font.language() == ignore_language
                                  && font.number() == LyXFont::IGNORE)
-               ? selectWordWhenUnderCursor(bview) : false;
+               ? selectWordWhenUnderCursor(bview, WHOLE_WORD_STRICT) : false;
 
        // Set font
        setFont(bview, font, toggleall);
@@ -1048,7 +1049,7 @@ void LyXText::toggleFree(BufferView * bview,
        // Implicit selections are cleared afterwards
        //and cursor is set to the original position.
        if (implicitSelection) {
-               clearSelection(bview);
+               clearSelection();
                cursor = resetCursor;
                setCursor(bview, cursor.par(), cursor.pos());
                selection.cursor = cursor;
@@ -1058,6 +1059,39 @@ void LyXText::toggleFree(BufferView * bview,
 }
 
 
+string
+LyXText::getStringToIndex(BufferView * bview)
+{
+       string idxstring;
+       
+       // Try implicit word selection
+       // If there is a change in the language the implicit word selection 
+       // is disabled.
+       LyXCursor resetCursor = cursor;
+       bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
+
+       if (!selection.set()) {
+               bview->owner()->message(_("Nothing to index!"));
+               return string();
+       }
+       if (selection.start.par() != selection.end.par()) {
+               bview->owner()->message(_("Cannot index more than one paragraph!"));
+               return string();
+       }
+
+       idxstring = selectionAsString(bview->buffer());
+       
+       // Implicit selections are cleared afterwards
+       //and cursor is set to the original position.
+       if (implicitSelection) {
+               clearSelection();
+               cursor = resetCursor;
+               setCursor(bview, cursor.par(), cursor.pos());
+               selection.cursor = cursor;
+       }
+       return idxstring;
+}
+
 Paragraph::size_type
 LyXText::beginningOfMainBody(Buffer const * buf,
                             Paragraph const * par) const
@@ -1143,7 +1177,7 @@ void LyXText::setParagraph(BufferView * bview,
        
        redoParagraphs(bview, selection.start, endpar);
        
-       clearSelection(bview);
+       clearSelection();
        setCursor(bview, selection.start.par(), selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
@@ -1672,7 +1706,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear)
        cursor = selection.start;
 
        // need a valid cursor. (Lgb)
-       clearSelection(bview);
+       clearSelection();
 
        setCursor(bview, cursor.par(), cursor.pos());
        selection.cursor = cursor;
@@ -1731,7 +1765,7 @@ void LyXText::pasteSelection(BufferView * bview)
        redoParagraphs(bview, cursor, endpar);
        
        setCursor(bview, cursor.par(), cursor.pos());
-       clearSelection(bview);
+       clearSelection();
    
        selection.cursor = cursor;
        setCursor(bview, actpar, pos);
@@ -1801,7 +1835,7 @@ void LyXText::insertStringAsLines(BufferView * bview, string const & str)
        setCursorParUndo(bview);
        
        // only to be sure, should not be neccessary
-       clearSelection(bview);
+       clearSelection();
        
        bview->buffer()->insertStringAsLines(par, pos, current_font, str);
 
@@ -2128,19 +2162,24 @@ void LyXText::setCurrentFont(BufferView * bview) const
 void LyXText::setCursorFromCoordinates(BufferView * bview, int x, int y) const
 {
        LyXCursor old_cursor = cursor;
-   
+
+#if 0
        // Get the row first. 
    
        Row * row = getRowNearY(y);
-       cursor.par(row->par());
 
        bool bound = false;
        int column = getColumnNearX(bview, row, x, bound);
+
+       cursor.par(row->par());
        cursor.pos(row->pos() + column);
        cursor.x(x);
        cursor.y(y + row->baseline());
        cursor.row(row);
        cursor.boundary(bound);
+#else
+       setCursorFromCoordinates(bview, cursor, x, y);
+#endif
        setCurrentFont(bview);
        deleteEmptyParagraphMechanism(bview, old_cursor);
 }
@@ -2153,7 +2192,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
    
        Row * row = getRowNearY(y);
        bool bound = false;
-       int column = getColumnNearX(bview, row, x, bound);
+       int const column = getColumnNearX(bview, row, x, bound);
    
        cur.par(row->par());
        cur.pos(row->pos() + column);
@@ -2498,6 +2537,11 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const
                status_ = st;
                if (inset_owner && st != UNCHANGED) {
                        bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
+                       if (!bview->text->refresh_row) {
+                               bview->text->refresh_row = bview->text->cursor.row();
+                               bview->text->refresh_y = bview->text->cursor.y() -
+                                       bview->text->cursor.row()->baseline();
+                       }
                }
        }
 #endif