From 258a6cb126750e39a9dfd7318c89b96d2cb51426 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Sun, 27 Aug 2023 19:12:52 +0200 Subject: [PATCH] FileManager: Use new window remember state --- Base/home/anon/.config/FileManager.ini | 6 ------ Userland/Applications/FileManager/main.cpp | 23 ++-------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/Base/home/anon/.config/FileManager.ini b/Base/home/anon/.config/FileManager.ini index 8305c32273b..1dc569206d6 100644 --- a/Base/home/anon/.config/FileManager.ini +++ b/Base/home/anon/.config/FileManager.ini @@ -2,12 +2,6 @@ ViewMode=Icon ShowDotFiles=false -[Window] -Left=150 -Top=75 -Width=640 -Height=480 - [Layout] ShowToolbar=true ShowStatusBar=true diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index cfd13d3a783..58b43adfa3c 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -609,12 +609,6 @@ ErrorOr run_in_windowed_mode(DeprecatedString const& initial_location, Depr auto window = TRY(GUI::Window::try_create()); window->set_title("File Manager"); - auto left = Config::read_i32("FileManager"sv, "Window"sv, "Left"sv, 150); - auto top = Config::read_i32("FileManager"sv, "Window"sv, "Top"sv, 75); - auto width = Config::read_i32("FileManager"sv, "Window"sv, "Width"sv, 640); - auto height = Config::read_i32("FileManager"sv, "Window"sv, "Height"sv, 480); - auto was_maximized = Config::read_bool("FileManager"sv, "Window"sv, "Maximized"sv, false); - auto widget = TRY(window->set_main_widget()); TRY(widget->load_from_gml(file_manager_window_gml)); @@ -1313,9 +1307,8 @@ ErrorOr run_in_windowed_mode(DeprecatedString const& initial_location, Depr paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "text/uri-list" && access(initial_location.characters(), W_OK) == 0); - window->set_rect({ left, top, width, height }); - if (was_maximized) - window->set_maximized(true); + window->restore_size_and_position("FileManager"sv, "Window"sv, { { 640, 480 } }); + window->save_size_and_position_on_close("FileManager"sv, "Window"sv); window->show(); @@ -1327,17 +1320,5 @@ ErrorOr run_in_windowed_mode(DeprecatedString const& initial_location, Depr directory_view->current_view().set_cursor(matches.first(), GUI::AbstractView::SelectionUpdate::Set); } - // Write window position to config file on close request. - window->on_close_request = [&] { - Config::write_bool("FileManager"sv, "Window"sv, "Maximized"sv, window->is_maximized()); - if (!window->is_maximized()) { - Config::write_i32("FileManager"sv, "Window"sv, "Left"sv, window->x()); - Config::write_i32("FileManager"sv, "Window"sv, "Top"sv, window->y()); - Config::write_i32("FileManager"sv, "Window"sv, "Width"sv, window->width()); - Config::write_i32("FileManager"sv, "Window"sv, "Height"sv, window->height()); - } - return GUI::Window::CloseRequestDecision::Close; - }; - return GUI::Application::the()->exec(); }