mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-18 21:45:24 +00:00
branch: Fix bug #740: Wish for added menu item: File->Close all.
see r30882, r30883, r30890. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@32454 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ec7d1e6c2a
commit
3cd6a2b0b7
@ -46,6 +46,7 @@ Menuset
|
||||
Submenu "Open Recent|t" "file_lastfiles"
|
||||
Separator
|
||||
Item "Close|C" "buffer-close"
|
||||
Item "Close All" "buffer-close-all"
|
||||
Item "Save|S" "buffer-write"
|
||||
Item "Save As...|A" "buffer-write-as"
|
||||
Item "Save All|l" "buffer-write-all"
|
||||
|
@ -428,6 +428,7 @@ enum FuncCode
|
||||
LFUN_GRAPHICS_RELOAD, // vfr 20090810
|
||||
LFUN_SCREEN_SHOW_CURSOR, // vfr, 20090325
|
||||
LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE, // ARRae 971202
|
||||
LFUN_BUFFER_CLOSE_ALL, // vfr 20090806
|
||||
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
@ -2767,6 +2767,15 @@ void LyXAction::init()
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BUFFER_CLOSE, "buffer-close", ReadOnly, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BUFFER_CLOSE_ALL
|
||||
* \li Action: Closes all buffers.
|
||||
* \li Notion: Closes all buffers, asking whether to save it, etc,
|
||||
if a buffer has been modified.
|
||||
* \li Syntax: buffer-close-all
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BUFFER_CLOSE_ALL, "buffer-close-all", ReadOnly, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BUFFER_EXPORT
|
||||
* \li Action: Exports the current buffer (document) to the given format.
|
||||
|
@ -851,6 +851,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
updateFlags = Update::None;
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_CLOSE_ALL:
|
||||
lyx_view_->closeBufferAll();
|
||||
buffer = 0;
|
||||
updateFlags = Update::None;
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_RELOAD: {
|
||||
LASSERT(lyx_view_ && buffer, /**/);
|
||||
docstring const file = makeDisplayPath(buffer->absFileName(), 20);
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
|
||||
///
|
||||
virtual bool closeBuffer() = 0;
|
||||
///
|
||||
virtual bool closeBufferAll(bool tolastopened = false) = 0;
|
||||
|
||||
/// load a document into the current workarea.
|
||||
virtual Buffer * loadDocument(
|
||||
|
@ -532,82 +532,12 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
||||
// it can happen that this event arrives without selecting the view,
|
||||
// e.g. when clicking the close button on a background window.
|
||||
setFocus();
|
||||
GuiWorkArea const * active_wa = currentWorkArea();
|
||||
|
||||
// We might be in a situation that there is still a tabWorkArea, but
|
||||
// there are no tabs anymore. This can happen when we get here after a
|
||||
// TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
|
||||
// many TabWorkArea's have no documents anymore.
|
||||
int empty_twa = 0;
|
||||
|
||||
// We have to call count() each time, because it can happen that
|
||||
// more than one splitter will disappear in one iteration (bug 5998).
|
||||
for (; d.splitter_->count() > empty_twa; ) {
|
||||
TabWorkArea * twa = d.tabWorkArea(empty_twa);
|
||||
|
||||
if (twa->count() == 0) {
|
||||
++empty_twa;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (; twa == d.tabWorkArea(empty_twa);) {
|
||||
twa->setCurrentIndex(twa->count() - 1);
|
||||
|
||||
GuiWorkArea * wa = twa->currentWorkArea();
|
||||
bool const is_active_wa = active_wa == wa;
|
||||
Buffer * b = &wa->bufferView().buffer();
|
||||
|
||||
if (b->parent()) {
|
||||
// This is a child document, just close the tab
|
||||
// after saving but keep the file loaded.
|
||||
if (!closeBuffer(*b, true, is_active_wa)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<Buffer *> clist = b->getChildren();
|
||||
for (vector<Buffer *>::const_iterator it = clist.begin();
|
||||
it != clist.end(); ++it) {
|
||||
if ((*it)->isClean())
|
||||
continue;
|
||||
Buffer * c = *it;
|
||||
// If a child is dirty, do not close
|
||||
// without user intervention
|
||||
if (!closeBuffer(*c, false)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QList<int> const ids = guiApp->viewIds();
|
||||
for (int i = 0; i != ids.size(); ++i) {
|
||||
if (id_ == ids[i])
|
||||
continue;
|
||||
if (guiApp->view(ids[i]).workArea(*b)) {
|
||||
// FIXME 1: should we put an alert box here that the buffer
|
||||
// is viewed elsewhere?
|
||||
// FIXME 2: should we try to save this buffer in any case?
|
||||
//saveBuffer(b);
|
||||
|
||||
// This buffer is also opened in another view, so
|
||||
// close the associated work area...
|
||||
removeWorkArea(d.current_work_area_);
|
||||
// ... but don't close the buffer.
|
||||
b = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (b && !closeBuffer(*b, true, is_active_wa)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!closeBufferAll(true)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure that nothing will use this close to be closed View.
|
||||
guiApp->unregisterView(this);
|
||||
|
||||
@ -639,6 +569,79 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
||||
}
|
||||
|
||||
|
||||
bool GuiView::closeBufferAll(bool tolastopened)
|
||||
{
|
||||
GuiWorkArea const * active_wa = currentWorkArea();
|
||||
|
||||
// We might be in a situation that there is still a tabWorkArea, but
|
||||
// there are no tabs anymore. This can happen when we get here after a
|
||||
// TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
|
||||
// many TabWorkArea's have no documents anymore.
|
||||
int empty_twa = 0;
|
||||
|
||||
// We have to call count() each time, because it can happen that
|
||||
// more than one splitter will disappear in one iteration (bug 5998).
|
||||
for (; d.splitter_->count() > empty_twa; ) {
|
||||
TabWorkArea * twa = d.tabWorkArea(empty_twa);
|
||||
|
||||
if (twa->count() == 0) {
|
||||
++empty_twa;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (; twa == d.tabWorkArea(empty_twa);) {
|
||||
twa->setCurrentIndex(twa->count() - 1);
|
||||
|
||||
GuiWorkArea * wa = twa->currentWorkArea();
|
||||
bool const is_active_wa = active_wa == wa;
|
||||
Buffer * b = &wa->bufferView().buffer();
|
||||
|
||||
if (b->parent()) {
|
||||
// This is a child document, just close the tab
|
||||
// after saving but keep the file loaded.
|
||||
if (!closeBuffer(*b, tolastopened, is_active_wa))
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<Buffer *> clist = b->getChildren();
|
||||
for (vector<Buffer *>::const_iterator it = clist.begin();
|
||||
it != clist.end(); ++it) {
|
||||
if ((*it)->isClean())
|
||||
continue;
|
||||
Buffer * c = *it;
|
||||
// If a child is dirty, do not close
|
||||
// without user intervention
|
||||
if (!closeBuffer(*c, false))
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<int> const ids = guiApp->viewIds();
|
||||
for (int i = 0; i != ids.size(); ++i) {
|
||||
if (id_ == ids[i])
|
||||
continue;
|
||||
if (guiApp->view(ids[i]).workArea(*b)) {
|
||||
// FIXME 1: should we put an alert box here that the buffer
|
||||
// is viewed elsewhere?
|
||||
// FIXME 2: should we try to save this buffer in any case?
|
||||
//saveBuffer(b);
|
||||
|
||||
// This buffer is also opened in another view, so
|
||||
// close the associated work area...
|
||||
removeWorkArea(d.current_work_area_);
|
||||
// ... but don't close the buffer.
|
||||
b = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (b && !closeBuffer(*b, tolastopened, is_active_wa))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void GuiView::dragEnterEvent(QDragEnterEvent * event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
@ -1178,6 +1181,22 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
enable = buf;
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_CLOSE_ALL: {
|
||||
enable = false;
|
||||
BufferList::iterator it = theBufferList().begin();
|
||||
BufferList::iterator end = theBufferList().end();
|
||||
int visible_buffers = 0;
|
||||
for (; it != end; ++it) {
|
||||
if (workArea(**it))
|
||||
++visible_buffers;
|
||||
if (visible_buffers > 1) {
|
||||
enable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_SPLIT_VIEW:
|
||||
if (cmd.getArg(0) == "vertical")
|
||||
enable = buf && (d.splitter_->count() == 1 ||
|
||||
|
@ -290,6 +290,8 @@ private:
|
||||
bool closeBuffer(Buffer & buf, bool tolastopened = false,
|
||||
bool mark_active = false);
|
||||
///
|
||||
bool closeBufferAll(bool tolastopened = false);
|
||||
///
|
||||
enum NextOrPrevious {
|
||||
NEXTBUFFER,
|
||||
PREVBUFFER
|
||||
|
@ -86,6 +86,8 @@ What's new
|
||||
- Fix layout of the Paragraph dialog (particularly within CJK
|
||||
localization).
|
||||
|
||||
- Add a Close All menu item to the menu (bug 740).
|
||||
|
||||
|
||||
* DOCUMENTATION AND LOCALIZATION
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user