Fix saving last opened view
Before it was only saved during a normal exit but not when killing the process with Ctrl+C or from the system monitor. Now save the setting as soon as it is changed.
Also move the related code to C++
Before it was only saved during a normal exit but not when killing the process with Ctrl+C or from the system monitor. Now save the setting as soon as it is changed.
Also move the related code to C++