mirror of
https://github.com/RGBCube/serenity
synced 2025-07-22 21:57:35 +00:00
LibGUI+PaintBrush: Fix to GFilePicker and PaintBrush enhancements.
GFilePicker - Fixed GFilePicker to use new ref-counted construct method to stop crashing on open dialog. - PaintBrush is still crashing on open dialog due to an unrelated issue. PaintBrush - Created 16x16 icon for PaintBrush - Moved Open option into App menu. - Changed help menu to make use of the standardized About dialog.
This commit is contained in:
parent
3fb88cb76d
commit
08a1fb8f1a
4 changed files with 26 additions and 22 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "PaintableWidget.h"
|
#include "PaintableWidget.h"
|
||||||
#include "PaletteWidget.h"
|
#include "PaletteWidget.h"
|
||||||
#include "ToolboxWidget.h"
|
#include "ToolboxWidget.h"
|
||||||
|
#include <LibDraw/PNGLoader.h>
|
||||||
|
#include <LibGUI/GAboutDialog.h>
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GApplication.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
|
@ -9,7 +11,6 @@
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
#include <LibGUI/GMessageBox.h>
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include <LibDraw/PNGLoader.h>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +19,7 @@ int main(int argc, char** argv)
|
||||||
auto window = GWindow::construct();
|
auto window = GWindow::construct();
|
||||||
window->set_title("PaintBrush");
|
window->set_title("PaintBrush");
|
||||||
window->set_rect(100, 100, 640, 480);
|
window->set_rect(100, 100, 640, 480);
|
||||||
|
window->set_icon(load_png("/res/icons/16x16/app-paintbrush.png"));
|
||||||
|
|
||||||
auto horizontal_container = GWidget::construct();
|
auto horizontal_container = GWidget::construct();
|
||||||
window->set_main_widget(horizontal_container);
|
window->set_main_widget(horizontal_container);
|
||||||
|
@ -37,33 +39,34 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto menubar = make<GMenuBar>();
|
auto menubar = make<GMenuBar>();
|
||||||
auto app_menu = make<GMenu>("PaintBrush");
|
auto app_menu = make<GMenu>("PaintBrush");
|
||||||
|
|
||||||
|
app_menu->add_action(GCommonActions::make_open_action([&](auto&) {
|
||||||
|
Optional<String> open_path = GFilePicker::get_open_filepath();
|
||||||
|
|
||||||
|
if (!open_path.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto bitmap = load_png(open_path.value());
|
||||||
|
if (!bitmap) {
|
||||||
|
GMessageBox::show(String::format("Failed to load '%s'", open_path.value().characters()), "Open failed", GMessageBox::Type::Error, GMessageBox::InputType::OK, window);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
paintable_widget->set_bitmap(*bitmap);
|
||||||
|
}));
|
||||||
|
app_menu->add_separator();
|
||||||
app_menu->add_action(GCommonActions::make_quit_action([](auto&) {
|
app_menu->add_action(GCommonActions::make_quit_action([](auto&) {
|
||||||
GApplication::the().quit(0);
|
GApplication::the().quit(0);
|
||||||
return;
|
return;
|
||||||
}));
|
}));
|
||||||
menubar->add_menu(move(app_menu));
|
|
||||||
|
|
||||||
auto file_menu = make<GMenu>("File");
|
menubar->add_menu(move(app_menu));
|
||||||
file_menu->add_action(GCommonActions::make_open_action([&](auto&) {
|
|
||||||
GFilePicker picker;
|
|
||||||
if (picker.exec() == GFilePicker::ExecOK) {
|
|
||||||
auto filename = picker.selected_file().string();
|
|
||||||
auto bitmap = load_png(filename);
|
|
||||||
if (!bitmap) {
|
|
||||||
GMessageBox::show(String::format("Failed to load '%s'", filename.characters()), "Open failed", GMessageBox::Type::Error, GMessageBox::InputType::OK, window);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
paintable_widget->set_bitmap(*bitmap);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
menubar->add_menu(move(file_menu));
|
|
||||||
|
|
||||||
auto edit_menu = make<GMenu>("Edit");
|
auto edit_menu = make<GMenu>("Edit");
|
||||||
menubar->add_menu(move(edit_menu));
|
menubar->add_menu(move(edit_menu));
|
||||||
|
|
||||||
auto help_menu = make<GMenu>("Help");
|
auto help_menu = make<GMenu>("Help");
|
||||||
help_menu->add_action(GAction::create("About", [](const GAction&) {
|
help_menu->add_action(GAction::create("About", [&](auto&) {
|
||||||
dbgprintf("FIXME: Implement Help/About\n");
|
GAboutDialog::show("PaintBrush", load_png("/res/icons/32x32/app-paintbrush.png"), window);
|
||||||
}));
|
}));
|
||||||
menubar->add_menu(move(help_menu));
|
menubar->add_menu(move(help_menu));
|
||||||
|
|
||||||
|
|
BIN
Base/res/icons/16x16/app-paintbrush.png
Normal file
BIN
Base/res/icons/16x16/app-paintbrush.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 473 B |
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
Optional<String> GFilePicker::get_open_filepath()
|
Optional<String> GFilePicker::get_open_filepath()
|
||||||
{
|
{
|
||||||
GFilePicker picker(Mode::Open);
|
auto picker = GFilePicker::construct(Mode::Open);
|
||||||
|
|
||||||
if (picker.exec() == GDialog::ExecOK) {
|
if (picker->exec() == GDialog::ExecOK) {
|
||||||
String file_path = picker.selected_file().string();
|
String file_path = picker->selected_file().string();
|
||||||
|
|
||||||
if (file_path.is_null())
|
if (file_path.is_null())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -20,7 +20,6 @@ public:
|
||||||
static Optional<String> get_save_filepath(const String& title, const String& extension);
|
static Optional<String> get_save_filepath(const String& title, const String& extension);
|
||||||
static bool file_exists(const StringView& path);
|
static bool file_exists(const StringView& path);
|
||||||
|
|
||||||
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;
|
virtual ~GFilePicker() override;
|
||||||
|
|
||||||
FileSystemPath selected_file() const { return m_selected_file; }
|
FileSystemPath selected_file() const { return m_selected_file; }
|
||||||
|
@ -30,6 +29,8 @@ private:
|
||||||
void clear_preview();
|
void clear_preview();
|
||||||
void on_file_return();
|
void on_file_return();
|
||||||
|
|
||||||
|
GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
|
||||||
|
|
||||||
static String ok_button_name(Mode mode)
|
static String ok_button_name(Mode mode)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue