1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 22:35:07 +00:00

TextEditor: Include extension during SaveAs

When we save-as in the text editor we now auto-populate GFilePicker /w
the current name & extension.
This commit is contained in:
rhin123 2019-07-28 23:45:50 -05:00 committed by Andreas Kling
parent 80cb833594
commit a175e76948
6 changed files with 34 additions and 20 deletions

View file

@ -1,5 +1,6 @@
#include <AK/FileSystemPath.h>
#include <AK/Function.h>
#include <LibDraw/PNGLoader.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h>
@ -11,7 +12,6 @@
#include <LibGUI/GSortingProxyModel.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GToolBar.h>
#include <LibDraw/PNGLoader.h>
Optional<String> GFilePicker::get_open_filepath()
{
@ -28,9 +28,9 @@ Optional<String> GFilePicker::get_open_filepath()
return {};
}
Optional<String> GFilePicker::get_save_filepath()
Optional<String> GFilePicker::get_save_filepath(const String& title, const String& extension)
{
GFilePicker picker(Mode::Save);
GFilePicker picker(Mode::Save, String::format("%s.%s", title.characters(), extension.characters()));
if (picker.exec() == GDialog::ExecOK) {
String file_path = picker.selected_file().string();
@ -43,7 +43,7 @@ Optional<String> GFilePicker::get_save_filepath()
return {};
}
GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringView& path, CObject* parent)
: GDialog(parent)
, m_model(GDirectoryModel::create())
, m_mode(mode)
@ -134,7 +134,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
filename_label->set_preferred_size(60, 0);
auto* filename_textbox = new GTextBox(filename_container);
if (m_mode == Mode::Save) {
filename_textbox->set_text("Untitled.txt"); //TODO: replace .txt with a preferred extension
filename_textbox->set_text(file_name);
filename_textbox->set_focus(true);
filename_textbox->select_all();
}