mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:12:43 +00:00 
			
		
		
		
	LibGUI: Traverse into directory upon filename entry in FilePicker
Previously, typing e.g. `/home/anon` in the filename field of the FilePicker resulted in an error for applications expecting an existing file to open. Intuitively I expected the file picker to navigate to the directory I typed there, similar to what we have with the location text box at the top, so I changed it to do exactly that :^)
This commit is contained in:
		
							parent
							
								
									c985a1b2af
								
							
						
					
					
						commit
						9466512847
					
				
					 1 changed files with 10 additions and 4 deletions
				
			
		|  | @ -32,7 +32,6 @@ | |||
| #include <LibGUI/Widget.h> | ||||
| #include <LibGfx/Font/FontDatabase.h> | ||||
| #include <LibGfx/Palette.h> | ||||
| #include <string.h> | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| namespace GUI { | ||||
|  | @ -340,11 +339,11 @@ void FilePicker::model_did_update(unsigned) | |||
| void FilePicker::on_file_return() | ||||
| { | ||||
|     auto path = m_filename_textbox->text(); | ||||
|     if (!path.starts_with('/')) { | ||||
|     if (!path.starts_with('/')) | ||||
|         path = LexicalPath::join(m_model->root_path(), path).string(); | ||||
|     } | ||||
| 
 | ||||
|     bool file_exists = FileSystem::exists(path); | ||||
|     auto stat_or_error = Core::System::stat(path); | ||||
|     bool file_exists = !stat_or_error.is_error(); | ||||
| 
 | ||||
|     if (!file_exists && (m_mode == Mode::Open || m_mode == Mode::OpenFolder)) { | ||||
|         (void)MessageBox::try_show_error(this, DeprecatedString::formatted("Opening \"{}\" failed: {}", m_filename_textbox->text(), Error::from_errno(ENOENT))); | ||||
|  | @ -360,6 +359,13 @@ void FilePicker::on_file_return() | |||
|             return; | ||||
|     } | ||||
| 
 | ||||
|     // If the entered filename matches an existing directory, traverse into it
 | ||||
|     if (file_exists && m_mode != Mode::OpenFolder && S_ISDIR(stat_or_error.value().st_mode)) { | ||||
|         m_filename_textbox->clear(); | ||||
|         set_path(path); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     m_selected_file = path; | ||||
|     done(ExecResult::OK); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jelle Raaijmakers
						Jelle Raaijmakers