| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGUI/GModel.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GFileSystemModel : public GModel { | 
					
						
							|  |  |  |     friend class Node; | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  |     enum Mode { | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |         Invalid, | 
					
						
							|  |  |  |         DirectoriesOnly, | 
					
						
							|  |  |  |         FilesAndDirectories | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:14:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:37:47 +02:00
										 |  |  |     static NonnullRefPtr<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories) | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-03-29 17:14:03 +01:00
										 |  |  |         return adopt(*new GFileSystemModel(root_path, mode)); | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     virtual ~GFileSystemModel() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     String root_path() const { return m_root_path; } | 
					
						
							| 
									
										
										
										
											2019-03-30 02:22:38 +01:00
										 |  |  |     String path(const GModelIndex&) const; | 
					
						
							| 
									
										
										
										
											2019-06-02 14:58:02 +02:00
										 |  |  |     GModelIndex index(const StringView& path) const; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual int row_count(const GModelIndex& = GModelIndex()) const override; | 
					
						
							|  |  |  |     virtual int column_count(const GModelIndex& = GModelIndex()) const override; | 
					
						
							|  |  |  |     virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; | 
					
						
							|  |  |  |     virtual void update() override; | 
					
						
							|  |  |  |     virtual GModelIndex parent_index(const GModelIndex&) const override; | 
					
						
							| 
									
										
										
										
											2019-03-29 20:36:15 +01:00
										 |  |  |     virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-06-02 14:58:02 +02:00
										 |  |  |     GFileSystemModel(const StringView& root_path, Mode); | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     String m_root_path; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:14:03 +01:00
										 |  |  |     Mode m_mode { Invalid }; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     struct Node; | 
					
						
							|  |  |  |     Node* m_root { nullptr }; | 
					
						
							| 
									
										
										
										
											2019-09-17 02:26:10 -05:00
										 |  |  |     void cleanup(); | 
					
						
							| 
									
										
										
										
											2019-03-30 04:20:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     GIcon m_open_folder_icon; | 
					
						
							|  |  |  |     GIcon m_closed_folder_icon; | 
					
						
							|  |  |  |     GIcon m_file_icon; | 
					
						
							| 
									
										
										
										
											2019-03-29 17:03:30 +01:00
										 |  |  | }; |