#include "frontends/Alert.h"
#include "frontends/LyXView.h"
+#include "insets/insetcommand.h"
#include "insets/insettext.h"
#include "support/convert.h"
using std::istringstream;
using std::ostringstream;
using std::string;
+using std::vector;
namespace bv_funcs {
return CUR_BELOW;
}
+namespace {
+
+bool gotoNextInset(LCursor & cur,
+ vector<InsetBase_code> const & codes,
+ string const & contents)
+{
+ LCursor tmpcur = cur;
+
+ while (tmpcur) {
+ InsetBase const * inset = tmpcur.nextInset();
+ if (inset
+ && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
+ && (contents.empty() ||
+ static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
+ cur = tmpcur;
+ return true;
+ }
+ tmpcur.forwardInset();
+ }
+
+ return false;
+}
+
+}
+
+
+void gotoInset(BufferView * bv, vector<InsetBase_code> const & codes,
+ bool same_content)
+{
+ string contents;
+ LCursor tmpcur = bv->cursor();
+ tmpcur.forwardInset();
+
+ if (same_content) {
+ InsetBase const * inset = tmpcur.nextInset();
+ if (inset
+ && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
+ contents = static_cast<InsetCommand const *>(inset)->getContents();
+ }
+ }
+
+ if (!gotoNextInset(tmpcur, codes, contents)) {
+ if (tmpcur != doc_iterator_begin(tmpcur.inset())) {
+ tmpcur.reset(tmpcur.bottom().inset());
+ if (!gotoNextInset(tmpcur, codes, contents))
+ bv->cursor().message(_("No more insets"));
+ } else {
+ bv->cursor().message(_("No more insets"));
+ }
+ }
+
+ tmpcur.clearSelection();
+ bv->setCursor(tmpcur);
+}
+
+
+void gotoInset(BufferView * bv, InsetBase_code code, bool same_content)
+{
+ gotoInset(bv, vector<InsetBase_code>(1, code), same_content);
+}
+
} // namespace bv_funcs