mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:22:45 +00:00 
			
		
		
		
	Playground: Support opening gml file by path as command line argument
This commit is contained in:
		
							parent
							
								
									7d5a369ac9
								
							
						
					
					
						commit
						5c0c4f4b2d
					
				
					 3 changed files with 21 additions and 4 deletions
				
			
		|  | @ -12,6 +12,7 @@ wav=/bin/SoundPlayer | |||
| txt=/bin/TextEditor | ||||
| font=/bin/FontEditor | ||||
| sheets=/bin/Spreadsheet | ||||
| gml=/bin/Playground | ||||
| *=/bin/TextEditor | ||||
| 
 | ||||
| [Protocol] | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ Playground - GUI Markup Language (GML) editor | |||
| ## Synopsis | ||||
| 
 | ||||
| ```**sh | ||||
| $ Playground | ||||
| $ Playground [file] | ||||
| ``` | ||||
| 
 | ||||
| ## Description | ||||
|  | @ -20,7 +20,7 @@ window, allowing rapid prototyping and development of application GUIs. | |||
| ## Examples | ||||
| 
 | ||||
| ```sh | ||||
| $ Playground | ||||
| $ Playground /home/anon/example.gml | ||||
| ``` | ||||
| 
 | ||||
| ## See also | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ | |||
| 
 | ||||
| #include <AK/QuickSort.h> | ||||
| #include <AK/URL.h> | ||||
| #include <LibCore/ArgsParser.h> | ||||
| #include <LibCore/File.h> | ||||
| #include <LibCore/Property.h> | ||||
| #include <LibDesktop/Launcher.h> | ||||
|  | @ -250,6 +251,11 @@ int main(int argc, char** argv) | |||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     const char* path = nullptr; | ||||
|     Core::ArgsParser args_parser; | ||||
|     args_parser.add_positional_argument(path, "GML file to edit", "file", Core::ArgsParser::Required::No); | ||||
|     args_parser.parse(argc, argv); | ||||
| 
 | ||||
|     auto app_icon = GUI::Icon::default_icon("app-playground"); | ||||
|     auto window = GUI::Window::construct(); | ||||
|     window->set_title("GML Playground"); | ||||
|  | @ -265,14 +271,24 @@ int main(int argc, char** argv) | |||
|     editor.set_autocomplete_provider(make<GMLAutocompleteProvider>()); | ||||
|     editor.set_should_autocomplete_automatically(true); | ||||
|     editor.set_automatic_indentation_enabled(true); | ||||
|     editor.set_text(R"~~~(@GUI::Widget { | ||||
| 
 | ||||
|     if (String(path).is_empty()) { | ||||
|         editor.set_text(R"~~~(@GUI::Widget { | ||||
|     layout: @GUI::VerticalBoxLayout { | ||||
|     } | ||||
| 
 | ||||
|     // Now add some widgets!
 | ||||
| } | ||||
| )~~~"); | ||||
|     editor.set_cursor(4, 28); // after "...widgets!"
 | ||||
|         editor.set_cursor(4, 28); // after "...widgets!"
 | ||||
|     } else { | ||||
|         auto file = Core::File::construct(path); | ||||
|         if (!file->open(Core::IODevice::ReadOnly)) { | ||||
|             GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error); | ||||
|             return 1; | ||||
|         } | ||||
|         editor.set_text(file->read_all()); | ||||
|     } | ||||
| 
 | ||||
|     editor.on_change = [&] { | ||||
|         preview.remove_all_children(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brendan Coles
						Brendan Coles