mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
QuickShow: Add Delete action
Delete current file from file system.
This commit is contained in:
parent
f88ceb872a
commit
6c1af174a1
3 changed files with 62 additions and 11 deletions
|
@ -42,6 +42,15 @@ QSWidget::~QSWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QSWidget::clear()
|
||||||
|
{
|
||||||
|
m_bitmap = nullptr;
|
||||||
|
m_path = {};
|
||||||
|
|
||||||
|
on_scale_change(100);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void QSWidget::flip(Gfx::Orientation orientation)
|
void QSWidget::flip(Gfx::Orientation orientation)
|
||||||
{
|
{
|
||||||
m_bitmap = m_bitmap->flipped(orientation);
|
m_bitmap = m_bitmap->flipped(orientation);
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
void set_scale(int);
|
void set_scale(int);
|
||||||
int scale() { return m_scale; }
|
int scale() { return m_scale; }
|
||||||
|
|
||||||
|
void clear();
|
||||||
void flip(Gfx::Orientation);
|
void flip(Gfx::Orientation);
|
||||||
void rotate(Gfx::RotationDirection);
|
void rotate(Gfx::RotationDirection);
|
||||||
void navigate(Directions);
|
void navigate(Directions);
|
||||||
|
|
|
@ -36,20 +36,22 @@
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/MenuBar.h>
|
#include <LibGUI/MenuBar.h>
|
||||||
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (pledge("stdio shared_buffer accept rpath unix cpath fattr proc exec thread", nullptr) < 0) {
|
if (pledge("stdio shared_buffer accept cpath rpath unix cpath fattr proc exec thread", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::Application app(argc, argv);
|
GUI::Application app(argc, argv);
|
||||||
|
|
||||||
if (pledge("stdio shared_buffer accept rpath proc exec thread", nullptr) < 0) {
|
if (pledge("stdio shared_buffer accept cpath rpath proc exec thread", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +102,51 @@ int main(int argc, char** argv)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
auto open_action = GUI::CommonActions::make_open_action(
|
||||||
|
[&](auto&) {
|
||||||
|
Optional<String> path = GUI::FilePicker::get_open_filepath("Open image...");
|
||||||
|
if (path.has_value()) {
|
||||||
|
widget.load_from_file(path.value());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto delete_action = GUI::CommonActions::make_delete_action(
|
||||||
|
[&](auto&) {
|
||||||
|
auto path = widget.path();
|
||||||
|
if(path.is_empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto msgbox_result = GUI::MessageBox::show(String::format("Really delete %s?", path.characters()),
|
||||||
|
"Confirm deletion",
|
||||||
|
GUI::MessageBox::Type::Warning,
|
||||||
|
GUI::MessageBox::InputType::OKCancel,
|
||||||
|
window);
|
||||||
|
|
||||||
|
if (msgbox_result == GUI::MessageBox::ExecCancel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto unlink_result = unlink(widget.path().characters());
|
||||||
|
dbg() << "unlink_result::" << unlink_result;
|
||||||
|
|
||||||
|
if (unlink_result < 0) {
|
||||||
|
int saved_errno = errno;
|
||||||
|
GUI::MessageBox::show(String::format("unlink(%s) failed: %s", path.characters(), strerror(saved_errno)),
|
||||||
|
"Delete failed",
|
||||||
|
GUI::MessageBox::Type::Error,
|
||||||
|
GUI::MessageBox::InputType::OK,
|
||||||
|
window);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
auto quit_action = GUI::CommonActions::make_quit_action(
|
||||||
|
[&](auto&) {
|
||||||
|
app.quit();
|
||||||
|
});
|
||||||
|
|
||||||
auto rotate_left_action = GUI::Action::create("Rotate Left", { Mod_None, Key_L },
|
auto rotate_left_action = GUI::Action::create("Rotate Left", { Mod_None, Key_L },
|
||||||
[&](auto&) {
|
[&](auto&) {
|
||||||
widget.rotate(Gfx::RotationDirection::Left);
|
widget.rotate(Gfx::RotationDirection::Left);
|
||||||
|
@ -163,16 +210,10 @@ int main(int argc, char** argv)
|
||||||
auto menubar = make<GUI::MenuBar>();
|
auto menubar = make<GUI::MenuBar>();
|
||||||
|
|
||||||
auto& app_menu = menubar->add_menu("QuickShow");
|
auto& app_menu = menubar->add_menu("QuickShow");
|
||||||
app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
app_menu.add_action(open_action);
|
||||||
Optional<String> path = GUI::FilePicker::get_open_filepath("Open image...");
|
app_menu.add_action(delete_action);
|
||||||
if (path.has_value()) {
|
|
||||||
widget.load_from_file(path.value());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
app_menu.add_separator();
|
app_menu.add_separator();
|
||||||
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
app_menu.add_action(quit_action);
|
||||||
app.quit();
|
|
||||||
}));
|
|
||||||
|
|
||||||
auto& image_menu = menubar->add_menu("Image");
|
auto& image_menu = menubar->add_menu("Image");
|
||||||
image_menu.add_action(rotate_left_action);
|
image_menu.add_action(rotate_left_action);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue