From f8a1d2746e0f8dbb71a1447a257c44f668e8edbe Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 2 Apr 2019 14:43:56 +0200 Subject: FileManager: Rename DirectoryTableView => DirectoryView. --- Applications/FileManager/DirectoryTableView.cpp | 80 ------------------------- Applications/FileManager/DirectoryTableView.h | 40 ------------- Applications/FileManager/DirectoryView.cpp | 80 +++++++++++++++++++++++++ Applications/FileManager/DirectoryView.h | 40 +++++++++++++ Applications/FileManager/Makefile | 2 +- Applications/FileManager/main.cpp | 2 +- 6 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 Applications/FileManager/DirectoryTableView.cpp delete mode 100644 Applications/FileManager/DirectoryTableView.h create mode 100644 Applications/FileManager/DirectoryView.cpp create mode 100644 Applications/FileManager/DirectoryView.h (limited to 'Applications') diff --git a/Applications/FileManager/DirectoryTableView.cpp b/Applications/FileManager/DirectoryTableView.cpp deleted file mode 100644 index ca27e54932..0000000000 --- a/Applications/FileManager/DirectoryTableView.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "DirectoryTableView.h" -#include - -DirectoryView::DirectoryView(GWidget* parent) - : GStackWidget(parent) - , m_model(DirectoryModel::create()) -{ - set_active_widget(nullptr); - m_item_view = new GItemView(this); - m_item_view->set_model(model()); - - m_table_view = new GTableView(this); - m_table_view->set_model(GSortingProxyModel::create(m_model.copy_ref())); - - m_table_view->model()->set_key_column_and_sort_order(DirectoryModel::Column::Name, GSortOrder::Ascending); - - m_item_view->set_model_column(DirectoryModel::Column::Name); - - m_item_view->on_model_notification = [this] (const GModelNotification& notification) { - if (notification.type() == GModelNotification::Type::ModelUpdated) { - set_status_message(String::format("%d item%s (%u byte%s)", - model().row_count(), - model().row_count() != 1 ? "s" : "", - model().bytes_in_files(), - model().bytes_in_files() != 1 ? "s" : "")); - - if (on_path_change) - on_path_change(model().path()); - } - }; - - m_model->on_thumbnail_progress = [this] (int done, int total) { - if (on_thumbnail_progress) - on_thumbnail_progress(done, total); - }; - - set_view_mode(ViewMode::Icon); -} - -DirectoryView::~DirectoryView() -{ -} - -void DirectoryView::set_view_mode(ViewMode mode) -{ - if (m_view_mode == mode) - return; - m_view_mode = mode; - update(); - if (mode == ViewMode::List) { - set_active_widget(m_table_view); - return; - } - if (mode == ViewMode::Icon) { - set_active_widget(m_item_view); - return; - } - ASSERT_NOT_REACHED(); -} - -void DirectoryView::open(const String& path) -{ - model().open(path); -} - -void DirectoryView::set_status_message(const String& message) -{ - if (on_status_message) - on_status_message(message); -} - -void DirectoryView::open_parent_directory() -{ - model().open(String::format("%s/..", model().path().characters())); -} - -void DirectoryView::refresh() -{ - model().update(); -} diff --git a/Applications/FileManager/DirectoryTableView.h b/Applications/FileManager/DirectoryTableView.h deleted file mode 100644 index 564d859237..0000000000 --- a/Applications/FileManager/DirectoryTableView.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include "DirectoryModel.h" - -class DirectoryView final : public GStackWidget { -public: - explicit DirectoryView(GWidget* parent); - virtual ~DirectoryView() override; - - void open(const String& path); - String path() const { return model().path(); } - void open_parent_directory(); - - void refresh(); - - Function on_path_change; - Function on_status_message; - Function on_thumbnail_progress; - - enum ViewMode { Invalid, List, Icon }; - void set_view_mode(ViewMode); - ViewMode view_mode() const { return m_view_mode; } - -private: - DirectoryModel& model() { return *m_model; } - const DirectoryModel& model() const { return *m_model; } - - void set_status_message(const String&); - - ViewMode m_view_mode { Invalid }; - - Retained m_model; - - GTableView* m_table_view { nullptr }; - GItemView* m_item_view { nullptr }; -}; diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp new file mode 100644 index 0000000000..6d9204862c --- /dev/null +++ b/Applications/FileManager/DirectoryView.cpp @@ -0,0 +1,80 @@ +#include "DirectoryView.h" +#include + +DirectoryView::DirectoryView(GWidget* parent) + : GStackWidget(parent) + , m_model(DirectoryModel::create()) +{ + set_active_widget(nullptr); + m_item_view = new GItemView(this); + m_item_view->set_model(model()); + + m_table_view = new GTableView(this); + m_table_view->set_model(GSortingProxyModel::create(m_model.copy_ref())); + + m_table_view->model()->set_key_column_and_sort_order(DirectoryModel::Column::Name, GSortOrder::Ascending); + + m_item_view->set_model_column(DirectoryModel::Column::Name); + + m_item_view->on_model_notification = [this] (const GModelNotification& notification) { + if (notification.type() == GModelNotification::Type::ModelUpdated) { + set_status_message(String::format("%d item%s (%u byte%s)", + model().row_count(), + model().row_count() != 1 ? "s" : "", + model().bytes_in_files(), + model().bytes_in_files() != 1 ? "s" : "")); + + if (on_path_change) + on_path_change(model().path()); + } + }; + + m_model->on_thumbnail_progress = [this] (int done, int total) { + if (on_thumbnail_progress) + on_thumbnail_progress(done, total); + }; + + set_view_mode(ViewMode::Icon); +} + +DirectoryView::~DirectoryView() +{ +} + +void DirectoryView::set_view_mode(ViewMode mode) +{ + if (m_view_mode == mode) + return; + m_view_mode = mode; + update(); + if (mode == ViewMode::List) { + set_active_widget(m_table_view); + return; + } + if (mode == ViewMode::Icon) { + set_active_widget(m_item_view); + return; + } + ASSERT_NOT_REACHED(); +} + +void DirectoryView::open(const String& path) +{ + model().open(path); +} + +void DirectoryView::set_status_message(const String& message) +{ + if (on_status_message) + on_status_message(message); +} + +void DirectoryView::open_parent_directory() +{ + model().open(String::format("%s/..", model().path().characters())); +} + +void DirectoryView::refresh() +{ + model().update(); +} diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h new file mode 100644 index 0000000000..564d859237 --- /dev/null +++ b/Applications/FileManager/DirectoryView.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include +#include +#include "DirectoryModel.h" + +class DirectoryView final : public GStackWidget { +public: + explicit DirectoryView(GWidget* parent); + virtual ~DirectoryView() override; + + void open(const String& path); + String path() const { return model().path(); } + void open_parent_directory(); + + void refresh(); + + Function on_path_change; + Function on_status_message; + Function on_thumbnail_progress; + + enum ViewMode { Invalid, List, Icon }; + void set_view_mode(ViewMode); + ViewMode view_mode() const { return m_view_mode; } + +private: + DirectoryModel& model() { return *m_model; } + const DirectoryModel& model() const { return *m_model; } + + void set_status_message(const String&); + + ViewMode m_view_mode { Invalid }; + + Retained m_model; + + GTableView* m_table_view { nullptr }; + GItemView* m_item_view { nullptr }; +}; diff --git a/Applications/FileManager/Makefile b/Applications/FileManager/Makefile index 4306a7ecf3..5da4851114 100644 --- a/Applications/FileManager/Makefile +++ b/Applications/FileManager/Makefile @@ -1,6 +1,6 @@ OBJS = \ DirectoryModel.o \ - DirectoryTableView.o \ + DirectoryView.o \ main.o APP = FileManager diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 6be5e242ef..fd52be97f1 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -17,7 +17,7 @@ #include #include #include -#include "DirectoryTableView.h" +#include "DirectoryView.h" int main(int argc, char** argv) { -- cgit v1.2.3