diff options
author | rhin123 <ryanrhin@gmail.com> | 2019-07-28 23:45:50 -0500 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-29 20:46:31 +0200 |
commit | a175e76948679a241745302d4b10637eecd8f275 (patch) | |
tree | 5b55bc8225248a5937f929fa8165b17c057c0d82 /Libraries/LibGUI | |
parent | 80cb833594587750b78e449de461d84961ed7b13 (diff) | |
download | serenity-a175e76948679a241745302d4b10637eecd8f275.zip |
TextEditor: Include extension during SaveAs
When we save-as in the text editor we now auto-populate GFilePicker /w
the current name & extension.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/GFilePicker.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/GFilePicker.h | 4 |
2 files changed, 7 insertions, 7 deletions
diff --git a/Libraries/LibGUI/GFilePicker.cpp b/Libraries/LibGUI/GFilePicker.cpp index 323b357106..1e9a44fea7 100644 --- a/Libraries/LibGUI/GFilePicker.cpp +++ b/Libraries/LibGUI/GFilePicker.cpp @@ -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(); } diff --git a/Libraries/LibGUI/GFilePicker.h b/Libraries/LibGUI/GFilePicker.h index 55d394c895..1316ccd290 100644 --- a/Libraries/LibGUI/GFilePicker.h +++ b/Libraries/LibGUI/GFilePicker.h @@ -16,10 +16,10 @@ public: }; static Optional<String> get_open_filepath(); - static Optional<String> get_save_filepath(); + static Optional<String> get_save_filepath(const String& title, const String& extension); static bool file_exists(const StringView& path); - GFilePicker(Mode type = Mode::Open, const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr); + GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr); virtual ~GFilePicker() override; FileSystemPath selected_file() const { return m_selected_file; } |