Class: Rufio::SelectionManager
- Inherits:
-
Object
- Object
- Rufio::SelectionManager
- Defined in:
- lib/rufio/selection_manager.rb
Overview
Manages selected items (files/directories) for bulk operations
Instance Attribute Summary collapse
-
#source_directory ⇒ Object
readonly
Returns the value of attribute source_directory.
Instance Method Summary collapse
-
#add(item_name) ⇒ Object
Add an item to selection.
-
#any? ⇒ Boolean
Check if any items are selected.
-
#clear ⇒ Object
Clear all selections.
-
#count ⇒ Integer
Get the count of selected items.
-
#empty? ⇒ Boolean
Check if selection is empty.
-
#initialize ⇒ SelectionManager
constructor
A new instance of SelectionManager.
-
#remove(item_name) ⇒ Object
Remove an item from selection.
-
#select_multiple(item_names) ⇒ Object
Select multiple items.
-
#selected?(entry_name) ⇒ Boolean
Check if an entry is selected.
-
#selected_items ⇒ Array<String>
Get all selected items.
-
#toggle_selection(entry, current_directory = nil) ⇒ Boolean
Toggle selection for an entry.
Constructor Details
#initialize ⇒ SelectionManager
Returns a new instance of SelectionManager.
8 9 10 11 |
# File 'lib/rufio/selection_manager.rb', line 8 def initialize @selected_items = [] @source_directory = nil end |
Instance Attribute Details
#source_directory ⇒ Object (readonly)
Returns the value of attribute source_directory.
6 7 8 |
# File 'lib/rufio/selection_manager.rb', line 6 def source_directory @source_directory end |
Instance Method Details
#add(item_name) ⇒ Object
Add an item to selection
72 73 74 |
# File 'lib/rufio/selection_manager.rb', line 72 def add(item_name) @selected_items << item_name unless @selected_items.include?(item_name) end |
#any? ⇒ Boolean
Check if any items are selected
60 61 62 |
# File 'lib/rufio/selection_manager.rb', line 60 def any? !@selected_items.empty? end |
#clear ⇒ Object
Clear all selections
53 54 55 56 |
# File 'lib/rufio/selection_manager.rb', line 53 def clear @selected_items.clear @source_directory = nil end |
#count ⇒ Integer
Get the count of selected items
66 67 68 |
# File 'lib/rufio/selection_manager.rb', line 66 def count @selected_items.length end |
#empty? ⇒ Boolean
Check if selection is empty
90 91 92 |
# File 'lib/rufio/selection_manager.rb', line 90 def empty? @selected_items.empty? end |
#remove(item_name) ⇒ Object
Remove an item from selection
78 79 80 |
# File 'lib/rufio/selection_manager.rb', line 78 def remove(item_name) @selected_items.delete(item_name) end |
#select_multiple(item_names) ⇒ Object
Select multiple items
84 85 86 |
# File 'lib/rufio/selection_manager.rb', line 84 def select_multiple(item_names) item_names.each { |name| add(name) } end |
#selected?(entry_name) ⇒ Boolean
Check if an entry is selected
42 43 44 |
# File 'lib/rufio/selection_manager.rb', line 42 def selected?(entry_name) @selected_items.include?(entry_name) end |
#selected_items ⇒ Array<String>
Get all selected items
48 49 50 |
# File 'lib/rufio/selection_manager.rb', line 48 def selected_items @selected_items.dup end |
#toggle_selection(entry, current_directory = nil) ⇒ Boolean
Toggle selection for an entry
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rufio/selection_manager.rb', line 17 def toggle_selection(entry, current_directory = nil) return false unless entry # 異なるディレクトリで選択した場合、古い選択をクリアしてリセット if current_directory && @source_directory && current_directory != @source_directory @selected_items.clear @source_directory = nil end if @selected_items.include?(entry[:name]) @selected_items.delete(entry[:name]) # Clear source_directory if no items are selected @source_directory = nil if @selected_items.empty? false else # Set source directory on first selection @source_directory = current_directory if @selected_items.empty? && current_directory @selected_items << entry[:name] true end end |