mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
Fix bug #5131: Remember last file active.
A bool is added to the entry of a last opened file in the Session file. This bool, indicates whether the file was the last one being edited. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29546 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
04c734f7a7
commit
d1e3d75da2
@ -111,14 +111,31 @@ void LastOpenedSection::read(istream & is)
|
||||
if (c == '[')
|
||||
break;
|
||||
getline(is, tmp);
|
||||
if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ' || !FileName::isAbsolute(tmp))
|
||||
if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ')
|
||||
continue;
|
||||
|
||||
FileName const file(tmp);
|
||||
if (file.exists() && !file.isDirectory())
|
||||
lastopened.push_back(file);
|
||||
else
|
||||
LYXERR(Debug::INIT, "LyX: Warning: Ignore last opened file: " << tmp);
|
||||
try {
|
||||
LastOpenedFile lof;
|
||||
istringstream itmp(tmp);
|
||||
itmp >> lof.active;
|
||||
itmp.ignore(2); // ignore ", "
|
||||
string fname;
|
||||
getline(itmp, fname);
|
||||
if (!FileName::isAbsolute(fname))
|
||||
continue;
|
||||
|
||||
FileName const file(fname);
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
lof.file_name = file;
|
||||
lastopened.push_back(lof);
|
||||
} else {
|
||||
LYXERR(Debug::INIT,
|
||||
"LyX: Warning: Ignore last opened file: " << tmp);
|
||||
}
|
||||
} catch (...) {
|
||||
LYXERR(Debug::INIT,
|
||||
"LyX: Warning: unknown state of last opened file: " << tmp);
|
||||
}
|
||||
} while (is.good());
|
||||
}
|
||||
|
||||
@ -126,14 +143,15 @@ void LastOpenedSection::read(istream & is)
|
||||
void LastOpenedSection::write(ostream & os) const
|
||||
{
|
||||
os << '\n' << sec_lastopened << '\n';
|
||||
copy(lastopened.begin(), lastopened.end(),
|
||||
ostream_iterator<FileName>(os, "\n"));
|
||||
for (size_t i = 0; i < lastopened.size(); ++i)
|
||||
os << lastopened[i].active << ", " << lastopened[i].file_name << '\n';
|
||||
}
|
||||
|
||||
|
||||
void LastOpenedSection::add(FileName const & file)
|
||||
void LastOpenedSection::add(FileName const & file, bool active)
|
||||
{
|
||||
lastopened.push_back(file);
|
||||
LastOpenedFile lof(file, active);
|
||||
lastopened.push_back(lof);
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,7 +106,17 @@ class LastOpenedSection : SessionSection
|
||||
{
|
||||
public:
|
||||
///
|
||||
typedef std::vector<support::FileName> LastOpened;
|
||||
struct LastOpenedFile {
|
||||
LastOpenedFile() : file_name(), active(false) {}
|
||||
|
||||
LastOpenedFile(support::FileName file_name_, bool active_)
|
||||
: file_name(file_name_), active(active_) {}
|
||||
|
||||
support::FileName file_name;
|
||||
bool active;
|
||||
};
|
||||
///
|
||||
typedef std::vector<LastOpenedFile> LastOpened;
|
||||
|
||||
public:
|
||||
///
|
||||
@ -121,7 +131,7 @@ public:
|
||||
/** add file to lastopened file list
|
||||
@param file filename to add
|
||||
*/
|
||||
void add(support::FileName const & file);
|
||||
void add(support::FileName const & file, bool active = false);
|
||||
|
||||
/** clear lastopened file list
|
||||
*/
|
||||
|
@ -1203,14 +1203,25 @@ void GuiApplication::restoreGuiSession()
|
||||
return;
|
||||
|
||||
Session & session = theSession();
|
||||
vector<FileName> const & lastopened = session.lastOpened().getfiles();
|
||||
LastOpenedSection::LastOpened const & lastopened =
|
||||
session.lastOpened().getfiles();
|
||||
|
||||
FileName active_file;
|
||||
// do not add to the lastfile list since these files are restored from
|
||||
// last session, and should be already there (regular files), or should
|
||||
// not be added at all (help files).
|
||||
// Note that we open them in reverse order. This is because we close
|
||||
// buffers also in reverse order (aesthetically motivated).
|
||||
for (size_t i = lastopened.size(); i > 0; --i)
|
||||
current_view_->loadDocument(lastopened[i - 1], false);
|
||||
for (size_t i = lastopened.size(); i > 0; --i) {
|
||||
current_view_->loadDocument(lastopened[i - 1].file_name, false);
|
||||
if (lastopened[i - 1].active)
|
||||
active_file = lastopened[i - 1].file_name;
|
||||
}
|
||||
|
||||
// Restore last active buffer
|
||||
Buffer * buffer = theBufferList().getBuffer(active_file);
|
||||
if (buffer)
|
||||
current_view_->setBuffer(buffer);
|
||||
|
||||
// clear this list to save a few bytes of RAM
|
||||
session.lastOpened().clear();
|
||||
|
@ -533,7 +533,8 @@ 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();
|
||||
setCurrentWorkArea(currentMainWorkArea());
|
||||
GuiWorkArea * active_wa = currentMainWorkArea();
|
||||
setCurrentWorkArea(active_wa);
|
||||
|
||||
int splitter_count = d.splitter_->count();
|
||||
for (; splitter_count; --splitter_count) {
|
||||
@ -544,11 +545,12 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
||||
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)) {
|
||||
if (!closeBuffer(*b, true, is_active_wa)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
@ -591,7 +593,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
|
||||
}
|
||||
// closeBuffer() needs buffer workArea still alive and
|
||||
// set as currrent one, and destroys it
|
||||
if (b && !closeBuffer(*b, true)) {
|
||||
if (b && !closeBuffer(*b, true, is_active_wa)) {
|
||||
closing_ = false;
|
||||
close_event->ignore();
|
||||
return;
|
||||
@ -1898,7 +1900,7 @@ bool GuiView::closeBuffer()
|
||||
}
|
||||
|
||||
|
||||
bool GuiView::closeBuffer(Buffer & buf, bool tolastopened)
|
||||
bool GuiView::closeBuffer(Buffer & buf, bool tolastopened, bool mark_active)
|
||||
{
|
||||
// goto bookmark to update bookmark pit.
|
||||
//FIXME: we should update only the bookmarks related to this buffer!
|
||||
@ -1911,7 +1913,7 @@ bool GuiView::closeBuffer(Buffer & buf, bool tolastopened)
|
||||
// do not save childs if their master
|
||||
// is opened as well
|
||||
if (tolastopened)
|
||||
theSession().lastOpened().add(buf.fileName());
|
||||
theSession().lastOpened().add(buf.fileName(), mark_active);
|
||||
if (buf.parent())
|
||||
// Don't close child documents.
|
||||
removeWorkArea(currentMainWorkArea());
|
||||
@ -1955,7 +1957,7 @@ bool GuiView::closeBuffer(Buffer & buf, bool tolastopened)
|
||||
|
||||
// save file names to .lyx/session
|
||||
if (tolastopened)
|
||||
theSession().lastOpened().add(buf.fileName());
|
||||
theSession().lastOpened().add(buf.fileName(), mark_active);
|
||||
|
||||
if (buf.parent())
|
||||
// Don't close child documents.
|
||||
|
@ -294,7 +294,9 @@ private:
|
||||
///
|
||||
bool saveBuffer(Buffer & b);
|
||||
///
|
||||
bool closeBuffer(Buffer & buf, bool tolastopened = false);
|
||||
bool closeBuffer(Buffer & buf, bool tolastopened = false,
|
||||
bool mark_active = false);
|
||||
///
|
||||
enum NextOrPrevious {
|
||||
NEXTBUFFER,
|
||||
PREVBUFFER
|
||||
|
Loading…
Reference in New Issue
Block a user