Class: Rufio::SelectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/selection_manager.rb

Overview

Manages selected items (files/directories) for bulk operations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelectionManager

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_directoryObject (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

Parameters:

  • item_name (String)

    Item name



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/rufio/selection_manager.rb', line 60

def any?
  !@selected_items.empty?
end

#clearObject

Clear all selections



53
54
55
56
# File 'lib/rufio/selection_manager.rb', line 53

def clear
  @selected_items.clear
  @source_directory = nil
end

#countInteger

Get the count of selected items

Returns:

  • (Integer)


66
67
68
# File 'lib/rufio/selection_manager.rb', line 66

def count
  @selected_items.length
end

#empty?Boolean

Check if selection is empty

Returns:

  • (Boolean)


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

Parameters:

  • item_name (String)

    Item name



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

Parameters:

  • item_names (Array<String>)

    Item names



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

Parameters:

  • entry_name (String)

    Entry name

Returns:

  • (Boolean)


42
43
44
# File 'lib/rufio/selection_manager.rb', line 42

def selected?(entry_name)
  @selected_items.include?(entry_name)
end

#selected_itemsArray<String>

Get all selected items

Returns:

  • (Array<String>)

    Copy of 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

Parameters:

  • entry (Hash)

    Entry with :name key

  • current_directory (String, nil) (defaults to: nil)

    Current directory path (optional)

Returns:

  • (Boolean)

    true if now selected, false if unselected



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