]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Various fixes to Tabular, InsetTabular and InsetText. Fixed left border for
[lyx.git] / src / BufferView_pimpl.C
index 78366ad2f7116d2ccf3168c038d7bc7e023ff9eb..6738a2bcd02909328d56268db2b682a61061ead9 100644 (file)
@@ -40,6 +40,7 @@
 #include "insets/insetref.h"
 #include "insets/insetparent.h"
 #include "insets/insetindex.h"
+#include "insets/insetinfo.h"
 #include "insets/insetinclude.h"
 #include "insets/insetcite.h"
 #include "insets/insetert.h"
@@ -2409,10 +2410,14 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        break;
        
        case LFUN_QUOTE:
+#if 0
                beforeChange(TEXT(bv_));
                TEXT(bv_)->InsertChar(bv_, '\"');  // This " matches the single quote in the code
                update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                 moveCursorUpdate(false);
+#else
+               bv_->insertCorrectQuote();
+#endif
                break;
 
        case LFUN_HTMLURL:
@@ -2426,7 +2431,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                owner_->getDialogs()->createUrl( p.getAsString() );
        }
        break;
-                   
+       
        case LFUN_INSERT_URL:
        {
                InsetCommandParams p;
@@ -2439,7 +2444,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        bv_->updateInset( inset, true );
        }
        break;
-                   
+       
        case LFUN_INSET_TEXT:
        {
                InsetText * new_inset = new InsetText;
@@ -2565,7 +2570,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        new InsetTabular(*buffer_, r, c);
                bool rtl =
                        TEXT(bv_)->real_current_font.isRightToLeft();
-               if (!bv_->open_new_inset(new_inset, rtl))
+               if (!open_new_inset(new_inset, rtl))
                        delete new_inset;
        }
        break;
@@ -2664,8 +2669,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_INSERT_MATRIX:
        {          
                if (available()) { 
-                       if (bv_->open_new_inset(new InsetFormula(false)))
-                       {
+                       if (open_new_inset(new InsetFormula(false))) {
                                bv_->theLockingInset()
                                        ->LocalDispatch(bv_, action, argument);
                        }
@@ -2679,7 +2683,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        break;
  
                InsetFormula * f = new InsetFormula(true);
-               bv_->open_new_inset(f);
+               open_new_inset(f);
                f->LocalDispatch(bv_, LFUN_INSERT_MATH, argument);
        }
        break;
@@ -2687,7 +2691,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_MATH_DISPLAY:
        {
                if (available())
-                       bv_->open_new_inset(new InsetFormula(true));
+                       open_new_inset(new InsetFormula(true));
                break;
        }
                    
@@ -2700,7 +2704,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        else {
                                string const s1 = token(s, ' ', 1);
                                int const na = s1.empty() ? 0 : lyx::atoi(s1);
-                               bv_->open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
+                               open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
                        }
                }
        }
@@ -2709,7 +2713,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_MATH_MODE:   // Open or create a math inset
        {               
                if (available())
-                       bv_->open_new_inset(new InsetFormula);
+                       open_new_inset(new InsetFormula);
                owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
        }
        break;
@@ -2882,35 +2886,87 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        break;
        
        case LFUN_INSERT_NOTE:
-               bv_->insertNote();
+               insertNote();
                break;
 
        case LFUN_SELFINSERT:
        {
-               LyXFont const old_font(TEXT(bv_)->real_current_font);
-               for (string::size_type i = 0; i < argument.length(); ++i) {
-                       TEXT(bv_)->InsertChar(bv_, argument[i]);
+#if 0
+               LyXText * lt = TEXT(bv_);
+               
+               LyXFont const old_font(lt->real_current_font);
+
+               string::const_iterator cit = argument.begin();
+               string::const_iterator end = argument.end();
+               for (; cit != end; ++cit) {
+                       lt->InsertChar(bv_, *cit);
                        // This needs to be in the loop, or else we
                        // won't break lines correctly. (Asger)
-                       update(TEXT(bv_),
+                       update(lt,
                               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                }
-               TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
+               lt->sel_cursor = lt->cursor;
                moveCursorUpdate(false);
 
                // real_current_font.number can change so we need to 
                // update the minibuffer
-               if (old_font != TEXT(bv_)->real_current_font)
+               if (old_font != lt->real_current_font)
                        owner_->showState();
+#else
+               if (argument.empty()) break;
+               
+               /* Automatically delete the currently selected
+                * text and replace it with what is being
+                * typed in now. Depends on lyxrc settings
+                * "auto_region_delete", which defaults to
+                * true (on). */
+
+               LyXText * lt = TEXT(bv_);
+               
+               if (lyxrc.auto_region_delete) {
+                       if (lt->selection){
+                               lt->CutSelection(bv_, false);
+                               bv_->update(lt,
+                                           BufferView::SELECT
+                                           | BufferView::FITCUR
+                                           | BufferView::CHANGE);
+                       }
+               }
+               
+               bv_->beforeChange(lt);
+               LyXFont const old_font(lt->real_current_font);
+               
+               string::const_iterator cit = argument.begin();
+               string::const_iterator end = argument.end();
+               for (; cit != end; ++cit) {
+                       if (greek_kb_flag) {
+                               if (!math_insert_greek(bv_, *cit))
+                                       owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
+                       } else
+                               owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
+               }
+               
+               bv_->update(lt,
+                           BufferView::SELECT
+                           | BufferView::FITCUR
+                           | BufferView::CHANGE);
+               
+               lt->sel_cursor = lt->cursor;
+               moveCursorUpdate(false);
+               
+               // real_current_font.number can change so we need to
+               // update the minibuffer
+               if (old_font != lt->real_current_font)
+                       owner_->showState();
+               //return string();
+#endif
        }
        break;
 
        case LFUN_DATE_INSERT:  // jdblair: date-insert cmd
        {
-               struct tm * now_tm;
-               
                time_t now_time_t = time(NULL);
-               now_tm = localtime(&now_time_t);
+               struct tm * now_tm = localtime(&now_time_t);
                setlocale(LC_TIME, "");
                string arg;
                if (!argument.empty())
@@ -2932,67 +2988,39 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        break;
 
        case LFUN_UNKNOWN_ACTION:
-       {
-               // Ok what does this break.
-#if 0
-               if (!buffer_) {
-                       owner_->getLyXFunc()->setErrorMessage(N_("No document open"));
-                       break;
-               }
-
-               if (buffer_->isReadonly()) {
-                       owner_->getLyXFunc()->setErrorMessage(N_("Document is read only"));
-                       break;
-               }
-               if (!argument.empty()) {
-                       /* Automatically delete the currently selected
-                        * text and replace it with what is being
-                        * typed in now. Depends on lyxrc settings
-                        * "auto_region_delete", which defaults to
-                        * true (on). */
-               
-                       if (lyxrc.auto_region_delete) {
-                               if (TEXT(bv_)->selection){
-                                       TEXT(bv_)->CutSelection(bv_, false);
-                                       update(TEXT(bv_),
-                                              BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-                               }
-                       }
-                       
-                       beforeChange(TEXT(bv_));
-                       LyXFont const old_font(TEXT(bv_)->real_current_font);
-                       for (string::size_type i = 0;
-                            i < argument.length(); ++i) {
-                               if (greek_kb_flag) {
-                                       if (!math_insert_greek(bv_, argument[i]))
-                                               owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
-                               } else
-                                       owner_->getIntl()->getTrans().TranslateAndInsert(argument[i], TEXT(bv_));
-                       }
-
-                       update(TEXT(bv_),BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-
-                       TEXT(bv_)->sel_cursor = TEXT(bv_)->cursor;
-                       moveCursorUpdate(false);
-
-                       // real_current_font.number can change so we need to
-                       // update the minibuffer
-                       if (old_font != TEXT(bv_)->real_current_font)
-                               owner_->showState();
-               } else {
-                       // if we don't have an argument there was something
-                       // strange going on so we just tell this to someone!
-                       owner_->getLyXFunc()->setErrorMessage(N_("No argument given"));
-               }
-#else
                owner_->getLyXFunc()->setErrorMessage(N_("Unknow function!"));
-               
-#endif
                break;
-       }
+       
        default:
                return false;
        } // end of switch
 
        return true;
 }
+
+
+void BufferView::Pimpl::insertNote()
+{
+       InsetInfo * new_inset = new InsetInfo();
+       bv_->insertInset(new_inset);
+       new_inset->Edit(bv_, 0, 0, 0);
+}
+
+
+// Open and lock an updatable inset
+bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
+{
+       beforeChange(TEXT(bv_));
+       TEXT(bv_)->FinishUndo();
+       if (!bv_->insertInset(new_inset)) {
+               delete new_inset;
+               return false;
+       }
+       if (behind) {
+               LyXFont & font = bv_->getLyXText()->real_current_font;
+               new_inset->Edit(bv_, new_inset->width(bv_, font), 0, 0);
+       } else
+               new_inset->Edit(bv_, 0, 0, 0);
+       return true;
+}
+