mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
FileManager+LibGUI: Make the breadcrumb bar accept text/uri-list drags
This commit is contained in:
parent
67b91d51a7
commit
12d0d12a78
3 changed files with 28 additions and 5 deletions
|
@ -913,12 +913,17 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
||||||
refresh_tree_view();
|
refresh_tree_view();
|
||||||
};
|
};
|
||||||
|
|
||||||
breadcrumb_bar.on_drop = [&](size_t segment_index, const GUI::DropEvent& event) {
|
breadcrumb_bar.on_segment_drop = [&](size_t segment_index, const GUI::DropEvent& event) {
|
||||||
if (!event.mime_data().has_urls())
|
if (!event.mime_data().has_urls())
|
||||||
return;
|
return;
|
||||||
copy_urls_to_directory(event.mime_data().urls(), breadcrumb_bar.segment_data(segment_index));
|
copy_urls_to_directory(event.mime_data().urls(), breadcrumb_bar.segment_data(segment_index));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
breadcrumb_bar.on_segment_drag_enter = [&](size_t, GUI::DragEvent& event) {
|
||||||
|
if (event.mime_types().contains_slow("text/uri-list"))
|
||||||
|
event.accept();
|
||||||
|
};
|
||||||
|
|
||||||
tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) {
|
tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) {
|
||||||
if (!event.mime_data().has_urls())
|
if (!event.mime_data().has_urls())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -27,13 +27,15 @@
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/BreadcrumbBar.h>
|
#include <LibGUI/BreadcrumbBar.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
REGISTER_WIDGET(GUI, BreadcrumbBar)
|
REGISTER_WIDGET(GUI, BreadcrumbBar)
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class BreadcrumbButton : public GUI::Button {
|
class BreadcrumbButton : public Button {
|
||||||
C_OBJECT(BreadcrumbButton);
|
C_OBJECT(BreadcrumbButton);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -46,7 +48,18 @@ public:
|
||||||
on_drop(event);
|
on_drop(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void drag_enter_event(DragEvent& event) override
|
||||||
|
{
|
||||||
|
if (on_drag_enter)
|
||||||
|
on_drag_enter(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drag_leave_event(Event&) override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Function<void(DropEvent&)> on_drop;
|
Function<void(DropEvent&)> on_drop;
|
||||||
|
Function<void(DragEvent&)> on_drag_enter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BreadcrumbButton() { }
|
BreadcrumbButton() { }
|
||||||
|
@ -82,8 +95,12 @@ void BreadcrumbBar::append_segment(const String& text, const Gfx::Bitmap* icon,
|
||||||
on_segment_click(index);
|
on_segment_click(index);
|
||||||
};
|
};
|
||||||
button.on_drop = [this, index = m_segments.size()](auto& drop_event) {
|
button.on_drop = [this, index = m_segments.size()](auto& drop_event) {
|
||||||
if (on_drop)
|
if (on_segment_drop)
|
||||||
on_drop(index, drop_event);
|
on_segment_drop(index, drop_event);
|
||||||
|
};
|
||||||
|
button.on_drag_enter = [this, index = m_segments.size()](auto& event) {
|
||||||
|
if (on_segment_drag_enter)
|
||||||
|
on_segment_drag_enter(index, event);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto button_text_width = button.font().width(text);
|
auto button_text_width = button.font().width(text);
|
||||||
|
|
|
@ -46,7 +46,8 @@ public:
|
||||||
Optional<size_t> selected_segment() const { return m_selected_segment; }
|
Optional<size_t> selected_segment() const { return m_selected_segment; }
|
||||||
|
|
||||||
Function<void(size_t index)> on_segment_click;
|
Function<void(size_t index)> on_segment_click;
|
||||||
Function<void(size_t index, DropEvent&)> on_drop;
|
Function<void(size_t index, DropEvent&)> on_segment_drop;
|
||||||
|
Function<void(size_t index, DragEvent&)> on_segment_drag_enter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BreadcrumbBar();
|
BreadcrumbBar();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue