mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	LibGUI: Add a GToolBar class that can be populated with GActions.
The same action can be added to both a menu and a toolbar. Use this to put a toolbar into FileManager. This is pretty neat. :^)
This commit is contained in:
		
							parent
							
								
									4804609b7e
								
							
						
					
					
						commit
						b704d3d295
					
				
					 24 changed files with 196 additions and 44 deletions
				
			
		|  | @ -3,47 +3,52 @@ | |||
| #include <LibGUI/GBoxLayout.h> | ||||
| #include <LibGUI/GApplication.h> | ||||
| #include <LibGUI/GStatusBar.h> | ||||
| #include <LibGUI/GToolBar.h> | ||||
| #include <LibGUI/GMenuBar.h> | ||||
| #include <LibGUI/GAction.h> | ||||
| #include <unistd.h> | ||||
| #include <stdio.h> | ||||
| #include "DirectoryView.h" | ||||
| 
 | ||||
| static GWindow* make_window(); | ||||
| 
 | ||||
| int main(int argc, char** argv) | ||||
| { | ||||
|     GApplication app(argc, argv); | ||||
| 
 | ||||
|     auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/mkdir16.rgb", { 16, 16 }), [] (const GAction&) { | ||||
|         dbgprintf("'New directory' action activated!\n"); | ||||
|     }); | ||||
| 
 | ||||
|     auto copy_action = GAction::create("Copy", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/copyfile16.rgb", { 16, 16 }), [] (const GAction&) { | ||||
|         dbgprintf("'Copy' action activated!\n"); | ||||
|     }); | ||||
| 
 | ||||
|     auto delete_action = GAction::create("Delete", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/trash16.rgb", { 16, 16 }), [] (const GAction&) { | ||||
|         dbgprintf("'Delete' action activated!\n"); | ||||
|     }); | ||||
| 
 | ||||
|     auto menubar = make<GMenuBar>(); | ||||
| 
 | ||||
|     auto app_menu = make<GMenu>("FileManager"); | ||||
|     app_menu->add_action(make<GAction>("Quit", String(), [] (const GAction&) { | ||||
|     app_menu->add_action(GAction::create("Quit", String(), [] (const GAction&) { | ||||
|         GApplication::the().quit(0); | ||||
|         return; | ||||
|     })); | ||||
|     menubar->add_menu(move(app_menu)); | ||||
| 
 | ||||
|     auto file_menu = make<GMenu>("File"); | ||||
|     file_menu->add_action(mkdir_action.copy_ref()); | ||||
|     file_menu->add_action(copy_action.copy_ref()); | ||||
|     file_menu->add_action(delete_action.copy_ref()); | ||||
|     menubar->add_menu(move(file_menu)); | ||||
| 
 | ||||
|     auto help_menu = make<GMenu>("Help"); | ||||
|     help_menu->add_action(make<GAction>("About", [] (const GAction&) { | ||||
|     help_menu->add_action(GAction::create("About", [] (const GAction&) { | ||||
|         dbgprintf("FIXME: Implement Help/About\n"); | ||||
|     })); | ||||
|     menubar->add_menu(move(help_menu)); | ||||
| 
 | ||||
|     app.set_menubar(move(menubar)); | ||||
| 
 | ||||
|     auto* window = make_window(); | ||||
|     window->set_should_exit_app_on_close(true); | ||||
|     window->show(); | ||||
| 
 | ||||
|     return app.exec(); | ||||
| } | ||||
| 
 | ||||
| GWindow* make_window() | ||||
| { | ||||
|     auto* window = new GWindow; | ||||
|     window->set_title("FileManager"); | ||||
|     window->set_rect(20, 200, 240, 300); | ||||
|  | @ -53,6 +58,11 @@ GWindow* make_window() | |||
| 
 | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
| 
 | ||||
|     auto* toolbar = new GToolBar(widget); | ||||
|     toolbar->add_action(mkdir_action.copy_ref()); | ||||
|     toolbar->add_action(copy_action.copy_ref()); | ||||
|     toolbar->add_action(delete_action.copy_ref()); | ||||
| 
 | ||||
|     auto* directory_view = new DirectoryView(widget); | ||||
| 
 | ||||
|     auto* statusbar = new GStatusBar(widget); | ||||
|  | @ -68,6 +78,8 @@ GWindow* make_window() | |||
| 
 | ||||
|     directory_view->open("/"); | ||||
| 
 | ||||
|     return window; | ||||
| } | ||||
|     window->set_should_exit_app_on_close(true); | ||||
|     window->show(); | ||||
| 
 | ||||
|     return app.exec(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling