summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorrhin123 <ryanrhin@gmail.com>2019-07-28 23:45:50 -0500
committerAndreas Kling <awesomekling@gmail.com>2019-07-29 20:46:31 +0200
commita175e76948679a241745302d4b10637eecd8f275 (patch)
tree5b55bc8225248a5937f929fa8165b17c057c0d82 /Applications
parent80cb833594587750b78e449de461d84961ed7b13 (diff)
downloadserenity-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 'Applications')
-rw-r--r--Applications/TextEditor/TextEditorWidget.cpp26
-rw-r--r--Applications/TextEditor/TextEditorWidget.h5
2 files changed, 18 insertions, 13 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp
index 91f25f6384..537959135b 100644
--- a/Applications/TextEditor/TextEditorWidget.cpp
+++ b/Applications/TextEditor/TextEditorWidget.cpp
@@ -34,26 +34,26 @@ TextEditorWidget::TextEditorWidget()
});
m_open_action = GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), [this](const GAction&) {
- Optional<String> open_name = GFilePicker::get_open_filepath();
+ Optional<String> open_path = GFilePicker::get_open_filepath();
- if (!open_name.has_value())
+ if (!open_path.has_value())
return;
- open_sesame(open_name.value());
+ open_sesame(open_path.value());
});
m_save_as_action = GAction::create("Save as...", { Mod_None, Key_F12 }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GAction&) {
- Optional<String> save_name = GFilePicker::get_save_filepath();
- if (!save_name.has_value())
+ Optional<String> save_path = GFilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension);
+ if (!save_path.has_value())
return;
- if (!m_editor->write_to_file(save_name.value())) {
+ if (!m_editor->write_to_file(save_path.value())) {
GMessageBox::show("Unable to save file.\n", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window());
return;
}
- set_path(save_name.value());
- dbg() << "Wrote document to " << save_name.value();
+ set_path(FileSystemPath(save_path.value()));
+ dbg() << "Wrote document to " << save_path.value();
});
m_save_action = GAction::create("Save", { Mod_Ctrl, Key_S }, GraphicsBitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GAction&) {
@@ -131,12 +131,14 @@ TextEditorWidget::~TextEditorWidget()
{
}
-void TextEditorWidget::set_path(const StringView& path)
+void TextEditorWidget::set_path(const FileSystemPath& file)
{
- m_path = path;
+ m_path = file.string();
+ m_name = file.title();
+ m_extension = file.extension();
StringBuilder builder;
builder.append("Text Editor: ");
- builder.append(path);
+ builder.append(file.string());
window()->set_title(builder.to_string());
}
@@ -150,5 +152,5 @@ void TextEditorWidget::open_sesame(const String& path)
}
m_editor->set_text(String::copy(file.read_all()));
- set_path(path);
+ set_path(FileSystemPath(path));
}
diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h
index 7515a984bb..7b4a1f5b2e 100644
--- a/Applications/TextEditor/TextEditorWidget.h
+++ b/Applications/TextEditor/TextEditorWidget.h
@@ -1,5 +1,6 @@
#pragma once
+#include <AK/FileSystemPath.h>
#include <AK/Function.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GTextEditor.h>
@@ -15,10 +16,12 @@ public:
void open_sesame(const String& path);
private:
- void set_path(const StringView&);
+ void set_path(const FileSystemPath& file);
GTextEditor* m_editor { nullptr };
String m_path;
+ String m_name;
+ String m_extension;
RefPtr<GAction> m_new_action;
RefPtr<GAction> m_open_action;
RefPtr<GAction> m_save_action;