diff --git a/src/application/appwindow.cpp b/src/application/appwindow.cpp index 777231a6..ce6677ca 100644 --- a/src/application/appwindow.cpp +++ b/src/application/appwindow.cpp @@ -46,7 +46,7 @@ AppWindow::AppWindow(TaskRunner& taskRunner, SettingsManager& settingsManager) { set_size_request(500, 500); - loadWindowState(); + loadPreviousSessionState(); loadWidgets(); addActions(); setupWidgets(); @@ -58,7 +58,7 @@ AppWindow::AppWindow(TaskRunner& taskRunner, SettingsManager& settingsManager) AppWindow::~AppWindow() { - saveWindowState(); + saveCurrentSessionState(); } void AppWindow::setDocument(std::unique_ptr document) @@ -105,7 +105,7 @@ bool AppWindow::on_delete_event(GdkEventAny*) return false; } -void AppWindow::loadWindowState() +void AppWindow::loadPreviousSessionState() { m_windowState = m_settingsManager.loadWindowState(); @@ -113,11 +113,14 @@ void AppWindow::loadWindowState() if (m_windowState.isMaximized) maximize(); + + m_zoomLevel.zoomLevelIndex().set_value(m_settingsManager.loadZoomLevel()); } -void AppWindow::saveWindowState() +void AppWindow::saveCurrentSessionState() { m_settingsManager.saveWindowState(m_windowState); + m_settingsManager.saveZoomLevel(m_zoomLevel.zoomLevelIndex().get_value()); } void AppWindow::loadWidgets() diff --git a/src/application/appwindow.hpp b/src/application/appwindow.hpp index 8e06a9d1..542758d4 100644 --- a/src/application/appwindow.hpp +++ b/src/application/appwindow.hpp @@ -107,8 +107,8 @@ class AppWindow : public Gtk::ApplicationWindow { Glib::RefPtr m_closeWindowAction; // Functions - void loadWindowState(); - void saveWindowState(); + void loadPreviousSessionState(); + void saveCurrentSessionState(); void loadWidgets(); void addActions(); void setupWidgets(); diff --git a/src/application/settingsmanager.cpp b/src/application/settingsmanager.cpp index 34a05c22..43a78298 100644 --- a/src/application/settingsmanager.cpp +++ b/src/application/settingsmanager.cpp @@ -34,6 +34,16 @@ namespace window_state { static const WindowState defaultWindowState = {800, 600, false}; } +namespace misc { + static const std::string groupName = "misc"; + + static const struct { + std::string zoomLevel = "zoom-level"; + } keys; + + static const unsigned int defaultZoomLevel = 0; +} + SettingsManager::SettingsManager() { loadConfigFile(); @@ -74,6 +84,28 @@ void SettingsManager::saveWindowState(const WindowState& windowState) } } +unsigned int SettingsManager::loadZoomLevel() +{ + try { + return static_cast(m_keyFile.get_integer(misc::groupName, misc::keys.zoomLevel)); + } + catch (const Glib::Error& e) { + Logger::logWarning("Error while loading zoom level: " + e.what()); + + return misc::defaultZoomLevel; + } +} + +void SettingsManager::saveZoomLevel(unsigned int zoomLevel) +{ + try { + m_keyFile.set_integer(misc::groupName, misc::keys.zoomLevel, static_cast(zoomLevel)); + } + catch (const Glib::Error& e) { + Logger::logWarning("Error while writing zoom level: " + e.what()); + } +} + void SettingsManager::loadConfigFile() { try { diff --git a/src/application/settingsmanager.hpp b/src/application/settingsmanager.hpp index 1c47e64f..012f6aac 100644 --- a/src/application/settingsmanager.hpp +++ b/src/application/settingsmanager.hpp @@ -35,6 +35,9 @@ class SettingsManager { WindowState loadWindowState(); void saveWindowState(const WindowState& windowState); + unsigned int loadZoomLevel(); + void saveZoomLevel(unsigned int zoomLevel); + private: Glib::KeyFile m_keyFile;