]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView2.C
Dekels tabular/textinset patches
[lyx.git] / src / BufferView2.C
index 606f2044e5ea75c767728a4bcbe4356484ffb700..5381ebdfab718c3c911cd7c5484dcdb44aabfe89 100644 (file)
@@ -39,6 +39,7 @@ using std::endl;
 using std::ifstream;
 using std::vector;
 using std::find;
+using std::count;
 
 // Inserts a file into current document
 bool BufferView::insertLyXFile(string const & filen)
@@ -52,10 +53,10 @@ bool BufferView::insertLyXFile(string const & filen)
 {
        if (filen.empty()) return false;
 
-       string fname = MakeAbsPath(filen);
+       string const fname = MakeAbsPath(filen);
 
        // check if file exist
-       FileInfo fi(fname);
+       FileInfo const fi(fname);
 
        if (!fi.readable()) {
                WriteAlert(_("Error!"),
@@ -74,7 +75,7 @@ bool BufferView::insertLyXFile(string const & filen)
                return false;
        }
        
-       char c = ifs.peek();
+       char const c = ifs.peek();
        
        LyXLex lex(0, 0);
        lex.setStream(ifs);
@@ -93,6 +94,7 @@ bool BufferView::insertLyXFile(string const & filen)
        return res;
 }
 
+
 bool BufferView::removeAutoInsets()
 {
        LyXParagraph * par = buffer()->paragraph;
@@ -144,10 +146,10 @@ void BufferView::insertErrors(TeXErrors & terr)
        for (TeXErrors::Errors::const_iterator cit = terr.begin();
             cit != terr.end();
             ++cit) {
-               string desctext((*cit).error_desc);
-               string errortext((*cit).error_text);
-               string msgtxt = desctext + '\n' + errortext;
-               int errorrow = (*cit).error_in_line;
+               string const desctext((*cit).error_desc);
+               string const errortext((*cit).error_text);
+               string const msgtxt = desctext + '\n' + errortext;
+               int const errorrow = (*cit).error_in_line;
 
                // Insert error string for row number
                int tmpid = -1; 
@@ -260,7 +262,7 @@ bool BufferView::insertInset(Inset * inset, string const & lout,
 
 
 // Open and lock an updatable inset
-bool BufferView::open_new_inset(UpdatableInset * new_inset)
+bool BufferView::open_new_inset(UpdatableInset * new_inset, bool behind)
 {
        beforeChange();
        text->FinishUndo();
@@ -268,9 +270,11 @@ bool BufferView::open_new_inset(UpdatableInset * new_inset)
                delete new_inset;
                return false;
        }
-//     text->CursorLeft(this);
-//     update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-       new_inset->Edit(this, 0, 0, 0);
+       if (behind) {
+               LyXFont & font = getLyXText()->real_current_font;
+               new_inset->Edit(this, new_inset->width(this, font), 0, 0);
+       } else
+               new_inset->Edit(this, 0, 0, 0);
        return true;
 }
 
@@ -740,9 +744,20 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
                     theLockingInset()->GetLockingInset()))
                        text->SetCursor(this, cursor,
                                        cursor.par(), cursor.pos() - 1);
+               LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
+               LyXText * txt = getLyXText();
+               if (theLockingInset()->GetLockingInset()->LyxCode() ==
+                   Inset::TEXT_CODE &&
+                   (txt->real_current_font.language() !=
+                    buffer()->params.language
+                    || txt->real_current_font.isVisibleRightToLeft()
+                    != buffer()->params.language->RightToLeft()))
+                       shape = (txt->real_current_font.isVisibleRightToLeft())
+                               ? LyXScreen::REVERSED_L_SHAPE
+                               : LyXScreen::L_SHAPE;
                y += cursor.y() + theLockingInset()->InsetInInsetY();
                pimpl_->screen_->ShowManualCursor(text, x, y, asc, desc,
-                                                 LyXScreen::BAR_SHAPE);
+                                                 shape);
        }
 }
 
@@ -757,9 +772,9 @@ void BufferView::hideLockedInsetCursor()
 
 void BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
-       if (theLockingInset() && available()){
+       if (theLockingInset() && available()) {
                y += text->cursor.y() + theLockingInset()->InsetInInsetY();
-               if (pimpl_->screen_->FitManualCursor(text, x, y, asc, desc))
+               if (pimpl_->screen_->FitManualCursor(text, this, x, y, asc, desc))
                        updateScrollbar();
        }
 }
@@ -809,9 +824,9 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
        // first check for locking insets
        if (theLockingInset()) {
                if (theLockingInset() == inset) {
-                       if (text->UpdateInset(this, inset)){
+                       if (text->UpdateInset(this, inset)) {
                                update();
-                               if (mark_dirty){
+                               if (mark_dirty) {
                                        if (buffer()->isLyxClean())
                                                owner()->getMiniBuffer()->
                                                        setTimer(4);
@@ -839,7 +854,7 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
        if (available()) {
                hideCursor();
                update(BufferView::UPDATE);
-               if (text->UpdateInset(this, inset)){
+               if (text->UpdateInset(this, inset)) {
                        if (mark_dirty)
                                update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                        else 
@@ -849,6 +864,7 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
        }
 }
 
+
 bool BufferView::ChangeRefs(string const & from, string const & to)
 {
        bool flag = false;
@@ -897,9 +913,23 @@ bool BufferView::ChangeRefs(string const & from, string const & to)
 }
 
 
+bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
+{
+       // Check if the label 'from' appears more than once
+       vector<string> labels = buffer()->getLabelList();
+       if (count(labels.begin(), labels.end(), from) > 1)
+               return false;
+
+       return ChangeRefs(from, to);
+}
+
+
 UpdatableInset * BufferView::theLockingInset() const
 {
-    return text->the_locking_inset;
+       // If NULL is not allowed we should put an Assert here. (Lgb)
+       if (text)
+               return text->the_locking_inset;
+       return 0;
 }
 
 
@@ -907,3 +937,35 @@ void BufferView::theLockingInset(UpdatableInset * inset)
 {
     text->the_locking_inset = inset;
 }
+
+
+LyXText * BufferView::getLyXText() const
+{
+       if (theLockingInset()) {
+               LyXText * txt = theLockingInset()->getLyXText(this);
+               if (txt)
+                       return txt;
+       }
+       return text;
+}
+
+
+LyXText * BufferView::getParentText(Inset * inset) const
+{
+       if (inset->owner()) {
+               LyXText * txt = inset->getLyXText(this);
+               inset = inset->owner();
+               while (inset && inset->getLyXText(this) == txt)
+                       inset = inset->owner();
+               if (inset)
+                       return inset->getLyXText(this);
+       }
+       return text;
+}
+
+Language const * BufferView::getParentLanguage(Inset * inset) const
+{
+       LyXText * text = getParentText(inset);
+       return text->cursor.par()->GetFontSettings(buffer()->params,
+                                                  text->cursor.pos()).language();
+}