Class: FilteredFileList

Inherits:
Fox::FXFileList
  • Object
show all
Includes:
Fox, Responder
Defined in:
lib/piggy-gui/filtered_file_list.rb

Overview

Allows to choose from a predefined set of files in the list. The definition of choosable files may be given as a block. Chosen, unchosen and unchoosable files are rendered differently.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ FilteredFileList

Returns a new instance of FilteredFileList.



16
17
18
19
20
21
22
23
# File 'lib/piggy-gui/filtered_file_list.rb', line 16

def initialize(parent)
  super(parent, nil, 0, ICONLIST_MINI_ICONS|ICONLIST_AUTOSIZE|ICONLIST_COLUMNS)
  @imageProcessor = ImageProcessor.new(getApp)
  @chosenFiles = Set.new
  @choosable = proc { |file| true }
  @shell = WinShell.instance
  init_icons
end

Instance Attribute Details

#choosable=(value) ⇒ Object (writeonly)

Sets the attribute choosable

Parameters:

  • value

    the value to set the attribute choosable to.



14
15
16
# File 'lib/piggy-gui/filtered_file_list.rb', line 14

def choosable=(value)
  @choosable = value
end

#chosenFilesObject (readonly)

Returns the value of attribute chosenFiles.



13
14
15
# File 'lib/piggy-gui/filtered_file_list.rb', line 13

def chosenFiles
  @chosenFiles
end

Instance Method Details

#add_index(i) ⇒ Object



122
123
124
125
126
127
# File 'lib/piggy-gui/filtered_file_list.rb', line 122

def add_index(i)
  long_name = get_item_ruby_pathname(i)
  short_name = get_item_ruby_filename(i)
  @chosenFiles.add(long_name)
  replace_file_icon(i, short_name, 'add')
end

#add_selected_filesObject



91
92
93
94
95
96
# File 'lib/piggy-gui/filtered_file_list.rb', line 91

def add_selected_files
  get_selected_image_files(true, 'add').each { |file|
    @chosenFiles.add(file)
    puts(file)
  }
end

#any_files_chosen?Boolean

Returns:

  • (Boolean)


241
242
243
# File 'lib/piggy-gui/filtered_file_list.rb', line 241

def any_files_chosen?
  return !@chosenFiles.empty?
end

#assume_selected(path) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/piggy-gui/filtered_file_list.rb', line 164

def assume_selected(path)
  index = get_index(path)
  unless index < 0 || itemSelected?(index)
    killSelection()
    selectItem(index)
  end
end

#choose(file) ⇒ Object



87
88
89
# File 'lib/piggy-gui/filtered_file_list.rb', line 87

def choose(file)
  @chosenFiles.add(@shell.os_path(file))
end

#choose_all_in_filelistObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/piggy-gui/filtered_file_list.rb', line 54

def choose_all_in_filelist
  (0..getNumItems-1).each do
    |i|
    if(isItemFile(i) && supports(get_item_ruby_filename(i)))
      shortName = get_item_ruby_filename(i)
      longName = get_item_ruby_pathname(i)
      @chosenFiles.add(longName)
      replace_file_icon(i, shortName, 'add')
    end
  end
end

#choose_saved_instead(original, saved) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/piggy-gui/filtered_file_list.rb', line 136

def choose_saved_instead(original, saved)
  original_index = get_index(original)
  saved_index = get_index(saved)
  remove_index(original_index) unless original_index < 0
  unless saved_index < 0
    add_index(saved_index)
    select_index(saved_index)
  end
end

#chosen_sequenceObject



172
173
174
175
176
# File 'lib/piggy-gui/filtered_file_list.rb', line 172

def chosen_sequence
  seq = Array.new
  @chosenFiles.each { |file| seq.push(file) }
  seq.sort! { |x, y| x <=> y }
end

#first_selected_indexObject



222
223
224
225
226
227
228
229
# File 'lib/piggy-gui/filtered_file_list.rb', line 222

def first_selected_index
  max = getNumItems-1
  (0..max).each do
    |i|
    return i if(isItemSelected(i)) 
  end
  -1
end

#get_current_directoryObject



183
184
185
# File 'lib/piggy-gui/filtered_file_list.rb', line 183

def get_current_directory
  fox_2_ruby(self.directory)
end

#get_icon(filename) ⇒ Object



30
31
32
33
# File 'lib/piggy-gui/filtered_file_list.rb', line 30

def get_icon(filename)
  icon_path = File.join(PIGGY_PATH, 'icons', filename)
  @imageProcessor.load_icon(icon_path)
end

#get_index(path) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/piggy-gui/filtered_file_list.rb', line 146

def get_index(path)
  ruby_path = ruby_path(path)
  (0..getNumItems-1).each do
    |i|
    if(isItemFile(i))
      longName = get_item_ruby_pathname(i)
      if(ruby_path(longName) == ruby_path)
        return i
      end
    end
  end
  return -1
end

#get_item_ruby_filename(index) ⇒ Object



35
36
37
# File 'lib/piggy-gui/filtered_file_list.rb', line 35

def get_item_ruby_filename(index)
  fox_2_ruby(getItemFilename(index))
end

#get_item_ruby_pathname(index) ⇒ Object



39
40
41
# File 'lib/piggy-gui/filtered_file_list.rb', line 39

def get_item_ruby_pathname(index)
  fox_2_ruby(getItemPathname(index))
end

#get_selected_image_files(full_path = false, modus = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/piggy-gui/filtered_file_list.rb', line 70

def get_selected_image_files(full_path = false, modus = nil)
  selected_ind = (0..getNumItems-1).select do
    |i|
    isItemSelected(i) and
      isItemFile(i) and
      supports(get_item_ruby_filename(i))
  end
  selected_files = selected_ind.collect do
    |i|
    shortName = get_item_ruby_filename(i)
    longName = get_item_ruby_pathname(i)
    replace_file_icon(i, shortName, modus)
    full_path ? longName : shortName
  end
  return selected_files
end

#go_to_directory(dirname) ⇒ Object



178
179
180
181
# File 'lib/piggy-gui/filtered_file_list.rb', line 178

def go_to_directory(dirname)
  self.directory = ruby_2_fox(ruby_path(dirname))
  @chosenFiles = Set.new
end

#init_iconsObject



25
26
27
28
# File 'lib/piggy-gui/filtered_file_list.rb', line 25

def init_icons
  @checkedIcon = get_icon("checked.ico")
  @uncheckedIcon = get_icon("unchecked.ico")
end

#last_selected_indexObject



231
232
233
234
235
236
237
238
239
# File 'lib/piggy-gui/filtered_file_list.rb', line 231

def last_selected_index
  max = getNumItems-1
  (0..max).each do
    |i|
    r = max - i
    return r if(isItemSelected(r)) 
  end
  -1
end

#num_files_chosenObject



245
246
247
# File 'lib/piggy-gui/filtered_file_list.rb', line 245

def num_files_chosen
  return @chosenFiles.size
end

#remove_index(i) ⇒ Object



129
130
131
132
133
134
# File 'lib/piggy-gui/filtered_file_list.rb', line 129

def remove_index(i)
  long_name = get_item_ruby_pathname(i)
  short_name = get_item_ruby_filename(i)
  @chosenFiles.delete(long_name)
  replace_file_icon(i, short_name, 'remove')
end

#remove_selected_filesObject



98
99
100
101
102
# File 'lib/piggy-gui/filtered_file_list.rb', line 98

def remove_selected_files
  get_selected_image_files(true, 'remove').each { |file|
    @chosenFiles.delete(file)
  }
end

#replace_file_icon(index, rubyfile, modus) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/piggy-gui/filtered_file_list.rb', line 43

def replace_file_icon(index, rubyfile, modus)
  return nil if modus == nil
  icon = (modus == 'add' ? @checkedIcon : @uncheckedIcon)
  if FOXVERSION_GE_1_2
    setItemMiniIcon(index, icon)
  else
    file = ruby_2_fox(rubyfile)
    replaceItem(index, file, icon, icon)
  end
end

#ruby_path(path) ⇒ Object



160
161
162
# File 'lib/piggy-gui/filtered_file_list.rb', line 160

def ruby_path(path)
  @shell.ruby_path(path)
end

#select_next_chosenObject

Return index or -1



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/piggy-gui/filtered_file_list.rb', line 188

def select_next_chosen
  block = proc { |i|
    if(isItemFile(i) &&
          @chosenFiles.include?(get_item_ruby_pathname(i)))
      killSelection
      makeItemVisible(i)
      selectItem(i)
      return i
    end
  }
  starting_point = last_selected_index + 1
  (starting_point..getNumItems-1).each(&block)
  (0..starting_point-1).each(&block)
  return -1
end

#select_previous_chosenObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/piggy-gui/filtered_file_list.rb', line 204

def select_previous_chosen
  max = getNumItems - 1
  starting_point = first_selected_index
  starting_point = max+1 if(starting_point < 0 || starting_point > max)
  (0..max).each do
    |index|
    i = (max - index + starting_point) % (max + 1)
    if(isItemFile(i) &&
          @chosenFiles.include?(get_item_ruby_pathname(i)))
      killSelection
      makeItemVisible(i)
      selectItem(i)
      return i
    end
  end
  return -1
end

#supports(filename) ⇒ Object



66
67
68
# File 'lib/piggy-gui/filtered_file_list.rb', line 66

def supports(filename)
  return @choosable.call(filename)
end

#update_file_listObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/piggy-gui/filtered_file_list.rb', line 104

def update_file_list
  scan(true)
  (0..getNumItems-1).each do
    |i|
    if(isItemFile(i))
      shortName = get_item_ruby_filename(i)
      if(supports(shortName))
        longName = get_item_ruby_pathname(i)
        if(@chosenFiles.include?(longName))
          replace_file_icon(i, shortName, 'add')
        else
          replace_file_icon(i, shortName, 'remove')
        end
      end
    end
  end
end