summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/AbstractView.cpp13
-rw-r--r--Libraries/LibGUI/AbstractView.h12
-rw-r--r--Libraries/LibGUI/FilePicker.cpp2
-rw-r--r--Libraries/LibGUI/IconView.cpp2
-rw-r--r--Libraries/LibGUI/MultiView.cpp16
-rw-r--r--Libraries/LibGUI/MultiView.h7
6 files changed, 28 insertions, 24 deletions
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp
index 53e01f8371..4bceeb3028 100644
--- a/Libraries/LibGUI/AbstractView.cpp
+++ b/Libraries/LibGUI/AbstractView.cpp
@@ -403,16 +403,21 @@ void AbstractView::drop_event(DropEvent& event)
on_drop(index, event);
}
-void AbstractView::set_multi_select(bool multi_select)
+void AbstractView::set_selection_mode(SelectionMode selection_mode)
{
- if (m_multi_select == multi_select)
+ if (m_selection_mode == selection_mode)
return;
- m_multi_select = multi_select;
- if (!multi_select && m_selection.size() > 1) {
+ m_selection_mode = selection_mode;
+
+ if (m_selection_mode == SelectionMode::NoSelection)
+ m_selection.clear();
+ else if (m_selection_mode != SelectionMode::SingleSelection && m_selection.size() > 1) {
auto first_selected = m_selection.first();
m_selection.clear();
m_selection.set(first_selected);
}
+
+ update();
}
void AbstractView::set_key_column_and_sort_order(int column, SortOrder sort_order)
diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h
index f29860b621..c543b39247 100644
--- a/Libraries/LibGUI/AbstractView.h
+++ b/Libraries/LibGUI/AbstractView.h
@@ -65,6 +65,12 @@ public:
SelectRows,
};
+ enum class SelectionMode {
+ SingleSelection,
+ MultiSelection,
+ NoSelection,
+ };
+
virtual void move_cursor(CursorMovement, SelectionUpdate) { }
void set_model(RefPtr<Model>);
@@ -96,8 +102,8 @@ public:
SelectionBehavior selection_behavior() const { return m_selection_behavior; }
void set_selection_behavior(SelectionBehavior behavior) { m_selection_behavior = behavior; }
- bool is_multi_select() const { return m_multi_select; }
- void set_multi_select(bool);
+ SelectionMode selection_mode() const { return m_selection_mode; }
+ void set_selection_mode(SelectionMode);
virtual void model_did_update(unsigned flags) override;
virtual void did_update_selection();
@@ -197,9 +203,9 @@ private:
RefPtr<Core::Timer> m_searching_timer;
ModelIndex m_cursor_index;
SelectionBehavior m_selection_behavior { SelectionBehavior::SelectItems };
+ SelectionMode m_selection_mode { SelectionMode::SingleSelection };
unsigned m_edit_triggers { EditTrigger::DoubleClicked | EditTrigger::EditKeyPressed };
bool m_activates_on_selection { false };
- bool m_multi_select { true };
bool m_tab_key_navigation_enabled { false };
bool m_is_dragging { false };
bool m_draw_item_text_with_shadow { false };
diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp
index c6feda202b..6a9d28c7ec 100644
--- a/Libraries/LibGUI/FilePicker.cpp
+++ b/Libraries/LibGUI/FilePicker.cpp
@@ -123,7 +123,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
m_location_textbox->set_text(path);
m_view = vertical_container.add<MultiView>();
- m_view->set_multi_select(m_mode == Mode::OpenMultiple);
+ m_view->set_selection_mode(m_mode == Mode::OpenMultiple ? GUI::AbstractView::SelectionMode::MultiSelection : GUI::AbstractView::SelectionMode::SingleSelection);
m_view->set_model(SortingProxyModel::create(*m_model));
m_view->set_model_column(FileSystemModel::Column::Name);
m_view->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);
diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp
index 7119e558d6..340df616fb 100644
--- a/Libraries/LibGUI/IconView.cpp
+++ b/Libraries/LibGUI/IconView.cpp
@@ -247,7 +247,7 @@ void IconView::mousedown_event(MouseEvent& event)
auto adjusted_position = to_content_position(event.position());
m_might_drag = false;
- if (is_multi_select()) {
+ if (selection_mode() == SelectionMode::MultiSelection) {
m_rubber_banding = true;
m_rubber_band_origin = adjusted_position;
m_rubber_band_current = adjusted_position;
diff --git a/Libraries/LibGUI/MultiView.cpp b/Libraries/LibGUI/MultiView.cpp
index 3123e74ae2..ce889fb833 100644
--- a/Libraries/LibGUI/MultiView.cpp
+++ b/Libraries/LibGUI/MultiView.cpp
@@ -97,7 +97,6 @@ MultiView::MultiView()
build_actions();
set_view_mode(ViewMode::Icon);
- apply_multi_select();
}
MultiView::~MultiView()
@@ -176,19 +175,16 @@ void MultiView::build_actions()
m_view_type_action_group->add_action(*m_view_as_columns_action);
}
-void MultiView::apply_multi_select()
+AbstractView::SelectionMode MultiView::selection_mode() const
{
- m_table_view->set_multi_select(m_multi_select);
- m_icon_view->set_multi_select(m_multi_select);
- m_columns_view->set_multi_select(m_multi_select);
+ return m_table_view->selection_mode();
}
-void MultiView::set_multi_select(bool multi_select)
+void MultiView::set_selection_mode(AbstractView::SelectionMode selection_mode)
{
- if (m_multi_select == multi_select)
- return;
- m_multi_select = multi_select;
- apply_multi_select();
+ m_table_view->set_selection_mode(selection_mode);
+ m_icon_view->set_selection_mode(selection_mode);
+ m_columns_view->set_selection_mode(selection_mode);
}
void MultiView::set_key_column_and_sort_order(int column, SortOrder sort_order)
diff --git a/Libraries/LibGUI/MultiView.h b/Libraries/LibGUI/MultiView.h
index 8ab093e9c2..e835bca6eb 100644
--- a/Libraries/LibGUI/MultiView.h
+++ b/Libraries/LibGUI/MultiView.h
@@ -97,14 +97,13 @@ public:
Action& view_as_icons_action() { return *m_view_as_icons_action; }
Action& view_as_columns_action() { return *m_view_as_columns_action; }
- bool is_multi_select() const { return m_multi_select; }
- void set_multi_select(bool);
+ AbstractView::SelectionMode selection_mode() const;
+ void set_selection_mode(AbstractView::SelectionMode);
private:
MultiView();
void build_actions();
- void apply_multi_select();
ViewMode m_view_mode { Invalid };
int m_model_column { 0 };
@@ -120,8 +119,6 @@ private:
RefPtr<Action> m_view_as_columns_action;
OwnPtr<ActionGroup> m_view_type_action_group;
-
- bool m_multi_select { true };
};
}