8
8
*/
9
9
10
10
#include < AK/URL.h>
11
+ #include < LibConfig/Client.h>
11
12
#include < LibCore/ArgsParser.h>
12
13
#include < LibCore/System.h>
13
14
#include < LibDesktop/Launcher.h>
@@ -67,6 +68,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
67
68
TRY (Core::System::pledge (" stdio thread recvfd sendfd cpath rpath wpath unix" ));
68
69
auto app = TRY (GUI::Application::try_create (arguments));
69
70
71
+ Config::pledge_domain (" GMLPlayground" );
72
+ app->set_config_domain (TRY (" GMLPlayground" _string));
73
+
70
74
TRY (Core::System::unveil (" /res" , " r" ));
71
75
TRY (Core::System::unveil (" /tmp/session/%sid/portal/launch" , " rw" ));
72
76
TRY (Core::System::unveil (" /tmp/session/%sid/portal/filesystemaccess" , " rw" ));
@@ -136,6 +140,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
136
140
update_title ();
137
141
};
138
142
143
+ auto load_file = [&](auto file) {
144
+ auto buffer_or_error = file.stream ().read_until_eof ();
145
+ if (buffer_or_error.is_error ())
146
+ return ;
147
+
148
+ editor->set_text (buffer_or_error.release_value ());
149
+ editor->set_focus (true );
150
+ update_title ();
151
+
152
+ GUI::Application::the ()->set_most_recently_open_file (file.filename ());
153
+ };
154
+
139
155
auto file_menu = TRY (window->try_add_menu (" &File" ));
140
156
141
157
auto save_as_action = GUI::CommonActions::make_save_as_action ([&](auto &) {
@@ -150,6 +166,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
150
166
}
151
167
file_path = response.value ().filename ().to_deprecated_string ();
152
168
update_title ();
169
+
170
+ GUI::Application::the ()->set_most_recently_open_file (response.value ().filename ());
153
171
});
154
172
155
173
auto save_action = GUI::CommonActions::make_save_action ([&](auto &) {
@@ -182,22 +200,30 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
182
200
if (response.is_error ())
183
201
return ;
184
202
185
- auto file = response.release_value ();
186
- file_path = file.filename ().to_deprecated_string ();
187
- auto buffer_or_error = file.stream ().read_until_eof ();
188
- if (buffer_or_error.is_error ())
189
- return ;
190
-
191
- editor->set_text (buffer_or_error.release_value ());
192
- editor->set_focus (true );
193
- update_title ();
203
+ load_file (response.release_value ());
194
204
});
195
205
196
206
TRY (file_menu->try_add_action (open_action));
197
207
TRY (file_menu->try_add_action (save_action));
198
208
TRY (file_menu->try_add_action (save_as_action));
199
209
TRY (file_menu->try_add_separator ());
200
210
211
+ TRY (file_menu->add_recent_files_list ([&](auto & action) {
212
+ if (window->is_modified ()) {
213
+ auto result = GUI::MessageBox::ask_about_unsaved_changes (window, file_path, editor->document ().undo_stack ().last_unmodified_timestamp ());
214
+ if (result == GUI::MessageBox::ExecResult::Yes)
215
+ save_action->activate ();
216
+ if (result != GUI::MessageBox::ExecResult::No && window->is_modified ())
217
+ return ;
218
+ }
219
+
220
+ auto response = FileSystemAccessClient::Client::the ().request_file_read_only_approved (window, action.text ());
221
+ if (response.is_error ())
222
+ return ;
223
+ file_path = response.value ().filename ().to_deprecated_string ();
224
+ load_file (response.release_value ());
225
+ }));
226
+
201
227
TRY (file_menu->try_add_action (GUI::CommonActions::make_quit_action ([&](auto &) {
202
228
if (window->on_close_request () == GUI::Window::CloseRequestDecision::Close)
203
229
app->quit ();
0 commit comments