]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[lyx.git] / src / BufferView.cpp
index b0dc5d47b5ca7224f406d9f5b3cfaa1d3a9de20c..33d9199f2e573d8075be72ae4dfd4b28800be061 100644 (file)
@@ -107,10 +107,7 @@ T * getInsetByCode(Cursor const & cur, InsetCode code)
        return 0;
 }
 
-
-bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
-       bool same_content);
-
+/// Note that comparing contents can only be used for InsetCommand
 bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
        docstring const & contents)
 {
@@ -118,12 +115,17 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
 
        while (tmpdit) {
                Inset const * inset = tmpdit.nextInset();
-               if (inset
-                   && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
-                   && (contents.empty() ||
-                   static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
-                       dit = tmpdit;
-                       return true;
+               if (inset) {
+                       bool const valid_code = std::find(codes.begin(), codes.end(), 
+                               inset->lyxCode()) != codes.end();
+                       InsetCommand const * ic = inset->asInsetCommand();
+                       bool const same_or_no_contents =  contents.empty()
+                               || (ic && (ic->getFirstNonOptParam() == contents));
+                       
+                       if (valid_code && same_or_no_contents) {
+                               dit = tmpdit;
+                               return true;
+                       }
                }
                tmpdit.forwardInset();
        }
@@ -133,6 +135,7 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
 
 
 /// Looks for next inset with one of the given codes.
+/// Note that same_content can only be used for InsetCommand
 bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content)
 {
@@ -142,11 +145,14 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        if (!tmpdit)
                return false;
 
-       if (same_content) {
-               Inset const * inset = tmpdit.nextInset();
-               if (inset
-                   && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
-                       contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
+       Inset const * inset = tmpdit.nextInset();
+       if (same_content && inset) {
+               InsetCommand const * ic = inset->asInsetCommand();
+               if (ic) {
+                       bool const valid_code = std::find(codes.begin(), codes.end(),
+                               ic->lyxCode()) != codes.end();
+                       if (valid_code)
+                               contents = ic->getFirstNonOptParam();
                }
        }
 
@@ -220,7 +226,8 @@ struct BufferView::Private
        Private(BufferView & bv): wh_(0), cursor_(bv),
                anchor_pit_(0), anchor_ypos_(0),
                inlineCompletionUniqueChars_(0),
-               last_inset_(0), mouse_position_cache_(),
+               last_inset_(0), clickable_inset_(false), 
+               mouse_position_cache_(),
                bookmark_edit_position_(-1), gui_(0)
        {}
 
@@ -263,6 +270,8 @@ struct BufferView::Private
          * Not owned, so don't delete.
          */
        Inset * last_inset_;
+       /// are we hovering something that we can click
+       bool clickable_inset_;
 
        /// position of the mouse at the time of the last mouse move
        /// This is used to update the hovering status of inset in
@@ -1837,7 +1846,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                icp["key"] = from_utf8(arg);
                if (!opt1.empty())
                        icp["before"] = from_utf8(opt1);
-               string icstr = InsetCommand::params2string("citation", icp);
+               string icstr = InsetCommand::params2string(icp);
                FuncRequest fr(LFUN_INSET_INSERT, icstr);
                lyx::dispatch(fr);
                break;
@@ -1959,8 +1968,12 @@ Inset const * BufferView::getCoveringInset(Text const & text,
 void BufferView::updateHoveredInset() const
 {
        // Get inset under mouse, if there is one.
-       Inset const * covering_inset = getCoveringInset(buffer_.text(),
-                       d->mouse_position_cache_.x_, d->mouse_position_cache_.y_);
+       int const x = d->mouse_position_cache_.x_;
+       int const y = d->mouse_position_cache_.y_;
+       Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+
+       d->clickable_inset_ = covering_inset && covering_inset->clickable(x, y);
+
        if (covering_inset == d->last_inset_)
                // Same inset, no need to do anything...
                return;
@@ -2500,7 +2513,7 @@ void BufferView::insertLyXFile(FileName const & fname)
 
        docstring res;
        Buffer buf("", false);
-       if (buf.loadLyXFile(filename)) {
+       if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) {
                ErrorList & el = buffer_.errorList("Parse");
                // Copy the inserted document error list into the current buffer one.
                el = buf.errorList("Parse");
@@ -2888,4 +2901,10 @@ void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
        }
 }
 
+
+bool BufferView::clickableInset() const
+{ 
+       return d->clickable_inset_; 
+}
+
 } // namespace lyx