mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:57:35 +00:00
LibGUI: Remove GModel activations to GAbstractView.
Now you can hook activation via GAbstractView::on_activation. The design still isn't quite right, we should eventually move the selection away from the model somehow.
This commit is contained in:
parent
bffaa5ece6
commit
fa232ac180
25 changed files with 107 additions and 104 deletions
|
@ -1,5 +1,47 @@
|
|||
#include "DirectoryView.h"
|
||||
#include <LibGUI/GSortingProxyModel.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void DirectoryView::handle_activation(const GModelIndex& index)
|
||||
{
|
||||
if (!index.is_valid())
|
||||
return;
|
||||
dbgprintf("on activation: %d,%d, this=%p, m_model=%p\n", index.row(), index.column(), this, m_model.ptr());
|
||||
auto& entry = model().entry(index.row());
|
||||
FileSystemPath path(String::format("%s/%s", model().path().characters(), entry.name.characters()));
|
||||
if (entry.is_directory()) {
|
||||
open(path.string());
|
||||
return;
|
||||
}
|
||||
if (entry.is_executable()) {
|
||||
if (fork() == 0) {
|
||||
int rc = execl(path.string().characters(), path.string().characters(), nullptr);
|
||||
if (rc < 0)
|
||||
perror("exec");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.string().to_lowercase().ends_with(".png")) {
|
||||
if (fork() == 0) {
|
||||
int rc = execl("/bin/qs", "/bin/qs", path.string().characters(), nullptr);
|
||||
if (rc < 0)
|
||||
perror("exec");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fork() == 0) {
|
||||
int rc = execl("/bin/TextEditor", "/bin/TextEditor", path.string().characters(), nullptr);
|
||||
if (rc < 0)
|
||||
perror("exec");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
DirectoryView::DirectoryView(GWidget* parent)
|
||||
: GStackWidget(parent)
|
||||
|
@ -34,6 +76,14 @@ DirectoryView::DirectoryView(GWidget* parent)
|
|||
on_thumbnail_progress(done, total);
|
||||
};
|
||||
|
||||
m_item_view->on_activation = [&] (const GModelIndex& index) {
|
||||
handle_activation(index);
|
||||
};
|
||||
m_table_view->on_activation = [&] (auto& index) {
|
||||
auto& filter_model = (GSortingProxyModel&)*m_table_view->model();
|
||||
handle_activation(filter_model.map_to_target(index));
|
||||
};
|
||||
|
||||
set_view_mode(ViewMode::Icon);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ private:
|
|||
GDirectoryModel& model() { return *m_model; }
|
||||
const GDirectoryModel& model() const { return *m_model; }
|
||||
|
||||
void handle_activation(const GModelIndex&);
|
||||
|
||||
void set_status_message(const String&);
|
||||
|
||||
ViewMode m_view_mode { Invalid };
|
||||
|
|
|
@ -151,9 +151,11 @@ void IRCAppWindow::setup_widgets()
|
|||
m_window_list->set_headers_visible(false);
|
||||
m_window_list->set_alternating_row_colors(false);
|
||||
m_window_list->set_model(m_client.client_window_list_model());
|
||||
m_window_list->set_activates_on_selection(true);
|
||||
m_window_list->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
m_window_list->set_preferred_size({ 100, 0 });
|
||||
m_client.client_window_list_model()->on_activation = [this] (IRCWindow& window) {
|
||||
m_window_list->on_activation = [this] (auto& index) {
|
||||
auto& window = m_client.window_at(index.row());
|
||||
m_container->set_active_widget(&window);
|
||||
window.clear_unread_count();
|
||||
};
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
IRCChannelMemberListModel::IRCChannelMemberListModel(IRCChannel& channel)
|
||||
: m_channel(channel)
|
||||
{
|
||||
set_activates_on_selection(true);
|
||||
}
|
||||
|
||||
IRCChannelMemberListModel::~IRCChannelMemberListModel()
|
||||
|
@ -53,9 +52,3 @@ void IRCChannelMemberListModel::update()
|
|||
{
|
||||
did_update();
|
||||
}
|
||||
|
||||
void IRCChannelMemberListModel::activate(const GModelIndex& index)
|
||||
{
|
||||
if (on_activation)
|
||||
on_activation(m_channel.member_at(index.row()));
|
||||
}
|
||||
|
|
|
@ -17,9 +17,6 @@ public:
|
|||
virtual ColumnMetadata column_metadata(int column) const override;
|
||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual void activate(const GModelIndex&) override;
|
||||
|
||||
Function<void(const String&)> on_activation;
|
||||
|
||||
private:
|
||||
explicit IRCChannelMemberListModel(IRCChannel&);
|
||||
|
|
|
@ -72,7 +72,3 @@ void IRCLogBufferModel::update()
|
|||
{
|
||||
did_update();
|
||||
}
|
||||
|
||||
void IRCLogBufferModel::activate(const GModelIndex&)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ public:
|
|||
virtual ColumnMetadata column_metadata(int column) const override;
|
||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual void activate(const GModelIndex&) override;
|
||||
|
||||
private:
|
||||
explicit IRCLogBufferModel(Retained<IRCLogBuffer>&&);
|
||||
|
|
|
@ -37,6 +37,7 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
|
|||
member_view->set_preferred_size({ 100, 0 });
|
||||
member_view->set_alternating_row_colors(false);
|
||||
member_view->set_model(channel().member_model());
|
||||
member_view->set_activates_on_selection(true);
|
||||
}
|
||||
|
||||
m_text_editor = new GTextEditor(GTextEditor::SingleLine, this);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
IRCWindowListModel::IRCWindowListModel(IRCClient& client)
|
||||
: m_client(client)
|
||||
{
|
||||
set_activates_on_selection(true);
|
||||
}
|
||||
|
||||
IRCWindowListModel::~IRCWindowListModel()
|
||||
|
@ -72,9 +71,3 @@ void IRCWindowListModel::update()
|
|||
{
|
||||
did_update();
|
||||
}
|
||||
|
||||
void IRCWindowListModel::activate(const GModelIndex& index)
|
||||
{
|
||||
if (on_activation)
|
||||
on_activation(m_client.window_at(index.row()));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ public:
|
|||
virtual ColumnMetadata column_metadata(int column) const override;
|
||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual void activate(const GModelIndex&) override;
|
||||
|
||||
Function<void(IRCWindow&)> on_activation;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue