Skip to content

Commit

Permalink
Sync data before reading and check window ptr (nickbnf#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Feb 24, 2021
1 parent 18a66e9 commit 6b5a6e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/ui/include/sessioninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class SessionInfo : public Persistable<SessionInfo, session_settings> {
bool remove( const QString& windowId )
{
if ( windows_.size() > 1 ) {
auto window = std::find_if( windows_.begin(), windows_.end(),
[&windowId]( const auto& w ) { return w.id == windowId; } );
auto window
= std::find_if( windows_.begin(), windows_.end(),
[ &windowId ]( const auto& w ) { return w.id == windowId; } );
if ( window != windows_.end() ) {
windows_.erase( window );
}
Expand All @@ -117,23 +118,31 @@ class SessionInfo : public Persistable<SessionInfo, session_settings> {

QByteArray geometry( const QString& windowId ) const
{
return findWindow( windowId )->geometry;
auto window = findWindow( windowId );
return window ? window->geometry : QByteArray{};
}

void setGeometry( const QString& windowId, const QByteArray& geometry )
{
findWindow( windowId )->geometry = geometry;
auto window = findWindow( windowId );
if ( window ) {
window->geometry = geometry;
}
}

// List of the loaded files
std::vector<OpenFile> openFiles( const QString& windowId ) const
{
return findWindow( windowId )->openFiles;
auto window = findWindow( windowId );
return window ? window->openFiles : std::vector<OpenFile>{};
}

void setOpenFiles( const QString& windowId, const std::vector<OpenFile>& loaded_files )
{
findWindow( windowId )->openFiles = loaded_files;
auto window = findWindow( windowId );
if ( window ) {
window->openFiles = loaded_files;
}
}

// Reads/writes the current config in the QSettings object passed
Expand All @@ -144,7 +153,7 @@ class SessionInfo : public Persistable<SessionInfo, session_settings> {
Window* findWindow( const QString& windowId ) const
{
auto window = std::find_if( windows_.begin(), windows_.end(),
[&windowId]( const auto& w ) { return w.id == windowId; } );
[ &windowId ]( const auto& w ) { return w.id == windowId; } );

if ( window == windows_.end() ) {
LOG( logINFO ) << "Can't find window " << windowId;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/include/persistable.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Persistable {
void retrieve()
{
auto& settings = PersistentInfo::getSettings(SettingsType{});

settings.sync();
static_cast<T&>(*this).retrieveFromStorage( settings );
}
};
Expand Down

0 comments on commit 6b5a6e6

Please sign in to comment.