From c2377531104c24353f6a74bf7cd1105da74bd658 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 6 Aug 2007 16:15:32 +0000 Subject: [PATCH] Introduce LFUN to save all modified files, and add menu entries. Patch from Guillaume Pothier for 1.4.x adapted by me to current branch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@19342 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXAction.cpp | 1 + src/LyXFunc.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/lfuns.h | 1 + 3 files changed, 49 insertions(+) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 02a5193032..b7d9ef7588 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -130,6 +130,7 @@ void LyXAction::init() { LFUN_BUFFER_VIEW, "buffer-view", ReadOnly }, { LFUN_BUFFER_WRITE, "buffer-write", ReadOnly }, { LFUN_BUFFER_WRITE_AS, "buffer-write-as", ReadOnly }, + { LFUN_BUFFER_WRITE_ALL, "buffer-write-all", ReadOnly }, { LFUN_CANCEL, "cancel", NoBuffer }, { LFUN_CAPTION_INSERT, "caption-insert", Noop }, { LFUN_CHAR_BACKWARD, "char-backward", ReadOnly | NoUpdate}, diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 49bd2363c4..075dd6c427 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -612,6 +612,29 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } + + case LFUN_BUFFER_WRITE_ALL: { + // We enable the command only if there are some modified buffers + Buffer * first = theBufferList().first(); + bool modified = false; + if (first) { + Buffer * b = first; + + // We cannot use a for loop as the buffer list is a cycle. + do { + if (!b->isClean()) { + modified = true; + break; + } + b = theBufferList().next(b); + } while (b != first); + } + + enable = modified; + + break; + } + case LFUN_BOOKMARK_GOTO: { const unsigned int num = convert(to_utf8(cmd.argument())); enable = LyX::ref().session().bookmarks().isValid(num); @@ -907,6 +930,30 @@ void LyXFunc::dispatch(FuncRequest const & cmd) updateFlags = Update::None; break; + case LFUN_BUFFER_WRITE_ALL: { + Buffer * first = theBufferList().first(); + if (first) { + Buffer * b = first; + lyx_view_->message(_("Saving all documents...")); + + // We cannot use a for loop as the buffer list cycles. + do { + if (!b->isClean()) { + if (!b->isUnnamed()) { + menuWrite(b); + lyxerr[Debug::ACTION] << "Saved " << b->fileName() << endl; + } else + writeAs(b); + } + b = theBufferList().next(b); + } while (b != first); + lyx_view_->message(_("All documents saved.")); + } + + updateFlags = Update::None; + break; + } + case LFUN_BUFFER_RELOAD: { BOOST_ASSERT(lyx_view_ && lyx_view_->buffer()); docstring const file = makeDisplayPath(view()->buffer()->fileName(), 20); diff --git a/src/lfuns.h b/src/lfuns.h index c6a094f2c4..4232fd5033 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -378,6 +378,7 @@ enum kb_action { LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125 LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502 LFUN_TOOLBAR_TOGGLE, // Edwin 20070521 + LFUN_BUFFER_WRITE_ALL, // rgh, gpothier 200707XX LFUN_LASTACTION // end of the table };