Abdelrazak Younes wrote: > Abdelrazak Younes wrote: >> Abdelrazak Younes wrote: >>> Here is my most recent patch. What is not working yet:
Btw, very nice design description. I think it is very useful. >>> - the close tab button: it is implemented but does not show up. >>> - the splash screen: it is implemented but does not show up. >> >> I solved the splash screen bug Cool. > Here is a patch with this fix against latest trunk. Just for review [I did it with s&r on the patched file], this is the BufferView.cpp part of the patch without the Buffer * -> Buffer & change (half as big). A/
Index: BufferView.cpp =================================================================== --- BufferView.cpp (revision 19626) +++ BufferView.cpp (working copy) @@ -122,143 +122,45 @@ } // anon namespace -BufferView::BufferView() - : width_(0), height_(0), buffer_(0), wh_(0), +BufferView::BufferView(Buffer & buf) + : width_(0), height_(0), buffer_(&buf), wh_(0), cursor_(*this), multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0), intl_(new Intl), last_inset_(0) { + LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION + << "Buffer addr: " << buffer_ << endl; + xsel_cache_.set = false; intl_->initKeyMapper(lyxrc.use_kbmap); + + cursor_.push(buffer_->inset()); + cursor_.resetAnchor(); + buffer_->text().setCurrentFont(cursor_); + + if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) + graphics::Previews::get().generateBufferPreviews(*buffer_); } BufferView::~BufferView() { + delete buffer_; } -Buffer * BufferView::buffer() const +Buffer * BufferView::buffer() { return buffer_; } -Buffer * BufferView::setBuffer(Buffer * b) +Buffer const * BufferView::buffer() const { - LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION - << "[ b = " << b << "]" << endl; - - if (buffer_) { - // Save the current selection if any - cap::saveSelection(cursor_); - // Save the actual cursor position and anchor inside the - // buffer so that it can be restored in case we rechange - // to this buffer later on. - buffer_->saveCursor(cursor_.selectionBegin(), - cursor_.selectionEnd()); - // update bookmark pit of the current buffer before switch - for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) { - BookmarksSection::Bookmark const & bm = LyX::ref().session().bookmarks().bookmark(i); - if (buffer()->fileName() != bm.filename.absFilename()) - continue; - // if top_id or bottom_pit, bottom_pos has been changed, update bookmark - // see http://bugzilla.lyx.org/show_bug.cgi?id=3092 - pit_type new_pit; - pos_type new_pos; - int new_id; - boost::tie(new_pit, new_pos, new_id) = moveToPosition(bm.bottom_pit, bm.bottom_pos, bm.top_id, bm.top_pos); - if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos || bm.top_id != new_id ) - const_cast<BookmarksSection::Bookmark &>(bm).updatePos(new_pit, new_pos, new_id); - } - // current buffer is going to be switched-off, save cursor pos - // Ideally, the whole cursor stack should be saved, but session - // currently can only handle bottom (whole document) level pit and pos. - // That is to say, if a cursor is in a nested inset, it will be - // restore to the left of the top level inset. - LyX::ref().session().lastFilePos().save(FileName(buffer_->fileName()), - boost::tie(cursor_.bottom().pit(), cursor_.bottom().pos()) ); - } - - // If we're quitting lyx, don't bother updating stuff - if (quitting) { - buffer_ = 0; - return 0; - } - - //FIXME Fix for bug 3440 is here. - // If we are closing current buffer, switch to the first in - // buffer list. - if (!b) { - LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION - << " No Buffer!" << endl; - // We are closing the buffer, use the first buffer as current - //FIXME 3440 - // if (last_buffer_) buffer_ = last_buffer_; - // also check that this is in theBufferList()? - buffer_ = theBufferList().first(); - } else { - //FIXME 3440 - // last_buffer = buffer_; - // Set current buffer - buffer_ = b; - } - - // Reset old cursor - cursor_ = Cursor(*this); - anchor_ref_ = 0; - offset_ref_ = 0; - - if (!buffer_) - return 0; - - LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION - << "Buffer addr: " << buffer_ << endl; - cursor_.push(buffer_->inset()); - cursor_.resetAnchor(); - buffer_->text().setCurrentFont(cursor_); - - // Update the metrics now that we have a proper Cursor. - updateMetrics(false); - - // FIXME: This code won't be needed once we switch to - // "one Buffer" / "one BufferView". - if (buffer_->getCursor().size() > 0 && - buffer_->getAnchor().size() > 0) - { - cursor_.setCursor(buffer_->getAnchor().asDocIterator(&(buffer_->inset()))); - cursor_.resetAnchor(); - cursor_.setCursor(buffer_->getCursor().asDocIterator(&(buffer_->inset()))); - cursor_.setSelection(); - // do not set selection to the new buffer because we - // only paste recent selection. - - // Make sure that the restored cursor is not broken. This can happen for - // example if this Buffer has been modified by another view. - cursor_.fixIfBroken(); - - if (fitCursor()) - // Update the metrics if the cursor new position was off screen. - updateMetrics(false); - } - - if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) - graphics::Previews::get().generateBufferPreviews(*buffer_); return buffer_; } -void BufferView::resize() -{ - if (!buffer_) - return; - - LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION << endl; - - updateMetrics(false); -} - - bool BufferView::fitCursor() { if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) { @@ -300,12 +202,6 @@ << ", singlepar = " << (flags & Update::SinglePar) << "] buffer: " << buffer_ << endl; - // Check needed to survive LyX startup - if (!buffer_) - return false; - - LYXERR(Debug::WORKAREA) << "BufferView::update" << std::endl; - // Update macro store if (!(cursor().inMathed() && cursor().inMacroMode())) buffer_->buildMacros(); @@ -360,13 +256,6 @@ void BufferView::updateScrollbar() { - if (!buffer_) { - LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION - << " no text in updateScrollbar" << endl; - scrollbarParameters_.reset(); - return; - } - Text & t = buffer_->text(); TextMetrics & tm = text_metrics_[&t]; @@ -432,9 +321,6 @@ LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION << "[ value = " << value << "]" << endl; - if (!buffer_) - return; - Text & t = buffer_->text(); TextMetrics & tm = text_metrics_[&t]; @@ -453,9 +339,6 @@ void BufferView::setCursorFromScrollbar() { - if (!buffer_) - return; - Text & t = buffer_->text(); int const height = 2 * defaultRowHeight(); @@ -660,7 +543,7 @@ break; case LFUN_CHANGES_OUTPUT: - flag.enabled(buffer_); + flag.enabled(true); flag.setOnOff(buffer_->params().outputChanges); break; @@ -672,7 +555,7 @@ // In principle, these command should only be enabled if there // is a change in the document. However, without proper // optimizations, this will inevitably result in poor performance. - flag.enabled(buffer_); + flag.enabled(true); break; case LFUN_BUFFER_TOGGLE_COMPRESSION: { @@ -702,10 +585,6 @@ << " button[" << cmd.button() << ']' << endl; - // FIXME: this should not be possible. - if (!buffer_) - return Update::None; - Cursor & cur = cursor_; // Default Update flags. Update::flags updateFlags = Update::Force | Update::FitCursor; @@ -774,7 +653,9 @@ case LFUN_PARAGRAPH_GOTO: { int const id = convert<int>(to_utf8(cmd.argument())); int i = 0; - for (Buffer * b = buffer_; i == 0 || b != buffer_; b = theBufferList().next(b)) { + for (Buffer * b = buffer_; i == 0 || b != buffer_; + b = theBufferList().next(b)) { + ParIterator par = b->getParFromID(id); if (par == b->par_iterator_end()) { LYXERR(Debug::INFO) @@ -1031,9 +912,6 @@ docstring const BufferView::requestSelection() { - if (!buffer_) - return docstring(); - Cursor & cur = cursor_; if (!cur.selection()) { @@ -1056,17 +934,15 @@ void BufferView::clearSelection() { - if (buffer_) { - cursor_.clearSelection(); - // Clear the selection buffer. Otherwise a subsequent - // middle-mouse-button paste would use the selection buffer, - // not the more current external selection. - cap::clearSelection(); - xsel_cache_.set = false; - // The buffer did not really change, but this causes the - // redraw we need because we cleared the selection above. - buffer_->changed(); - } + cursor_.clearSelection(); + // Clear the selection buffer. Otherwise a subsequent + // middle-mouse-button paste would use the selection buffer, + // not the more current external selection. + cap::clearSelection(); + xsel_cache_.set = false; + // The buffer did not really change, but this causes the + // redraw we need because we cleared the selection above. + buffer_->changed(); } @@ -1078,9 +954,7 @@ // The complete text metrics will be redone. text_metrics_.clear(); - - if (buffer_) - resize(); + updateMetrics(false); } @@ -1140,10 +1014,6 @@ // LFUN_FILE_OPEN generated by drag-and-drop. FuncRequest cmd = cmd0; - // E.g. Qt mouse press when no buffer - if (!buffer_) - return false; - Cursor cur(*this); cur.push(buffer_->inset()); cur.selection() = cursor_.selection(); @@ -1239,10 +1109,7 @@ void BufferView::scroll(int /*lines*/) { -// if (!buffer_) -// return; -// -// Text const * t = &buffer_->text(); +// Text const * t = buffer_->text(); // int const line_height = defaultRowHeight(); // // // The new absolute coordinate @@ -1571,14 +1438,11 @@ // Launch a file browser // FIXME UNICODE string initpath = lyxrc.document_path; + string const trypath = buffer_->filePath(); + // If directory is writeable, use this as default. + if (isDirWriteable(FileName(trypath))) + initpath = trypath; - if (buffer_) { - string const trypath = buffer_->filePath(); - // If directory is writeable, use this as default. - if (isDirWriteable(FileName(trypath))) - initpath = trypath; - } - // FIXME UNICODE FileDialog fileDlg(_("Select LyX document to insert"), LFUN_FILE_INSERT, @@ -1630,7 +1494,7 @@ // emit message signal. message(bformat(res, disp_fn)); buffer_->errors("Parse"); - resize(); + updateMetrics(false); } } // namespace lyx