Class: DirectoryDiffWidget

Inherits:
Fox::FXScrollWindow
  • Object
show all
Includes:
Fox
Defined in:
lib/piggy-gui/directory_diff_widget.rb

Direct Known Subclasses

FtpBrowserWidget

Constant Summary collapse

Placement =
PIGGY_WINDOW_PLACEMENT
MsgStyle =
MBOX_OK|DECOR_TITLE|DECOR_CLOSE|PIGGY_WINDOW_PLACEMENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, options = PiggyOptions.new) ⇒ DirectoryDiffWidget

Returns a new instance of DirectoryDiffWidget.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/piggy-gui/directory_diff_widget.rb', line 50

def initialize(window, options = PiggyOptions.new)
  super(window)
  @options = options
  @iconLoader = ImageProcessor.new(getApp)
  load_icons
  initialize_frames
  initialize_controls
  initialize_layout
  set_defaults
  connect_events
  @rightContents = DirectoryContents.new(right_path)
  @leftContents = DirectoryContents.new(left_path)
  @excludeFilters = @options.excludeFilters
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



48
49
50
# File 'lib/piggy-gui/directory_diff_widget.rb', line 48

def options
  @options
end

#quitButtonObject (readonly)

Returns the value of attribute quitButton.



48
49
50
# File 'lib/piggy-gui/directory_diff_widget.rb', line 48

def quitButton
  @quitButton
end

Instance Method Details

#basic_load_icon(filename) ⇒ Object



74
75
76
77
# File 'lib/piggy-gui/directory_diff_widget.rb', line 74

def basic_load_icon(filename)
  file_with_path = File.join(PIGGY_PATH, 'icons', filename)
  @iconLoader.load_icon(file_with_path)
end

#connect_eventsObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/piggy-gui/directory_diff_widget.rb', line 211

def connect_events
  @rightPathField.connect(SEL_COMMAND) {
    dir_changed('right')
  }
  @leftPathField.connect(SEL_COMMAND)  {
    dir_changed('left')
  }
  @dirLeftUpButton.connect(SEL_COMMAND, method(:on_dir_up_lef_list))
  @dirRightUpButton.connect(SEL_COMMAND, method(:on_dir_up_right_list))
  
  @leftFileList.connect(SEL_DOUBLECLICKED,
    method(:on_doubleclick_left_file_list))
  @rightFileList.connect(SEL_DOUBLECLICKED,
    method(:on_doubleclick_right_file_list))
  @leftFileList.connect(SEL_RIGHTBUTTONRELEASE,
    method(:on_menu_left_list))
  @rightFileList.connect(SEL_RIGHTBUTTONRELEASE,
    method(:on_menu_right_list))
end

#createObject



438
439
440
441
# File 'lib/piggy-gui/directory_diff_widget.rb', line 438

def create
  in_create
  super
end

#dir_changed(side) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/piggy-gui/directory_diff_widget.rb', line 199

def dir_changed(side)
  if(side == 'right')
    set_right_path(ruby_path(@rightPathField.getText))
    update_right_list
    update_status_icons
  else
    set_left_path(ruby_path(@leftPathField.getText))
    update_left_list
    update_status_icons
  end
end

#dir_chooser_for_field(field, side) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/piggy-gui/directory_diff_widget.rb', line 139

def dir_chooser_for_field(field, side)
  chooser_button = FXButton.new(field.parent, '...')
  chooser_button.connect(SEL_COMMAND) {
    dialog = FXDirDialog.new(self, "Choose directory")
    dialog.directory = field.getText
    unless dialog.execute == 0
      field.setText(dialog.directory)
      dir_changed(side)
    end
  }
end

#error(msg, title = 'Error') ⇒ Object

messages



366
367
368
369
# File 'lib/piggy-gui/directory_diff_widget.rb', line 366

def error(msg, title = 'Error')
  FXMessageBox::warning(self, MsgStyle, title, msg)
  return false
end

#fox_path(ruby_path) ⇒ Object



231
232
233
# File 'lib/piggy-gui/directory_diff_widget.rb', line 231

def fox_path(ruby_path)
  ruby_2_fox(WinShell.instance.os_path(ruby_path))
end

#h_sep_into(frame) ⇒ Object



84
85
86
87
# File 'lib/piggy-gui/directory_diff_widget.rb', line 84

def h_sep_into(frame)
  sep = FXHorizontalSeparator.new(frame, SEPARATOR_GROOVE)
  sep.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_Y) 
end

#in_createObject



431
432
433
434
435
436
# File 'lib/piggy-gui/directory_diff_widget.rb', line 431

def in_create
  update_left_list
  update_right_list
  update_status_icons
  @horizontal_splitter.setSplit(0, preferred_width/2)
end

#include_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


306
307
308
309
310
# File 'lib/piggy-gui/directory_diff_widget.rb', line 306

def include_file?(filename)
  @excludeFilters.select { |pattern|
    Regexp.compile(pattern) =~ filename
  }.empty?
end

#initialize_buttonsObject



171
172
173
# File 'lib/piggy-gui/directory_diff_widget.rb', line 171

def initialize_buttons
  @quitButton = FXButton.new(@buttonsFrame, "&Quit")
end

#initialize_controlsObject



108
109
110
111
112
113
114
115
# File 'lib/piggy-gui/directory_diff_widget.rb', line 108

def initialize_controls
  @labels = Array.new
  initialize_controls_top_left
  initialize_controls_top_right
  initialize_controls_bottom_left
  initialize_controls_bottom_right
  initialize_buttons
end

#initialize_controls_bottom_leftObject



151
152
153
154
155
156
157
158
159
# File 'lib/piggy-gui/directory_diff_widget.rb', line 151

def initialize_controls_bottom_left
  @dirLeftUpButton = FXButton.new(@leftButtonsFrame,
    "\tGo up to higher directory",
    @dirupIcon)
  @leftFileList = FXIconList.new(@leftListFrame)
  @leftFileList.setListStyle(ICONLIST_DETAILED)
  @leftFileList.appendHeader("Name", nil, 200)
  @leftFileList.appendHeader("Date", nil, 200)
end

#initialize_controls_bottom_rightObject



161
162
163
164
165
166
167
168
169
# File 'lib/piggy-gui/directory_diff_widget.rb', line 161

def initialize_controls_bottom_right
  @dirRightUpButton = FXButton.new(@rightButtonsFrame,
    "\tGo up to higher directory",
    @dirupIcon)
  @rightFileList = FXIconList.new(@rightListFrame)
  @rightFileList.setListStyle(ICONLIST_DETAILED)
  @rightFileList.appendHeader("Name", nil, 200)
  @rightFileList.appendHeader("Date", nil, 200)
end

#initialize_controls_top_leftObject



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

def initialize_controls_top_left
  @labels.push(FXLabel.new(@leftListPropFrame, "Dir:"))
  combo = new_hframe_without_padding(@leftListPropFrame)
  combo.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_COLUMN) 
  @leftPathField = FXTextField.new(combo, txt_field_num_chars)
  @leftPathField.setLayoutHints(LAYOUT_FILL_X)
  dir_chooser_for_field(@leftPathField, 'left')
end

#initialize_controls_top_rightObject



130
131
132
133
134
135
136
137
# File 'lib/piggy-gui/directory_diff_widget.rb', line 130

def initialize_controls_top_right
  @labels.push(FXLabel.new(@rightListPropFrame, "Dir:"))
  combo = new_hframe_without_padding(@rightListPropFrame)
  combo.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
  @rightPathField = FXTextField.new(combo, txt_field_num_chars)
  @rightPathField.setLayoutHints(LAYOUT_FILL_X)
  dir_chooser_for_field(@rightPathField, 'right')
end

#initialize_framesObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/piggy-gui/directory_diff_widget.rb', line 89

def initialize_frames
  @frame = FXVerticalFrame.new(self)
  @horizontal_splitter = FXSplitter.new(@frame, SPLITTER_HORIZONTAL)
  @left_frame = FXVerticalFrame.new(@horizontal_splitter)
  @right_frame = FXVerticalFrame.new(@horizontal_splitter)
  @splitOL = FXVerticalFrame.new(@left_frame)
  @splitOR = FXVerticalFrame.new(@right_frame)
  @splitUL = FXVerticalFrame.new(@left_frame)
  @splitUR = FXVerticalFrame.new(@right_frame)
  @leftListPropFrame = FXMatrix.new(@splitOL, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X)
  @rightListPropFrame = FXMatrix.new(@splitOR, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X)
  @leftButtonsFrame = FXHorizontalFrame.new(@splitUL)
  @rightButtonsFrame = FXHorizontalFrame.new(@splitUR)
  @leftListFrame = FXHorizontalFrame.new(@splitUL)
  @rightListFrame = FXHorizontalFrame.new(@splitUR)
  @separator = FXHorizontalSeparator.new(@frame, SEPARATOR_GROOVE)
  @buttonsFrame = FXHorizontalFrame.new(@frame)
end

#initialize_layoutObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/piggy-gui/directory_diff_widget.rb', line 175

def initialize_layout
  @labels.each { |label| label.setLayoutHints LAYOUT_CENTER_Y }
  [
    self, @frame,
    @horizontal_splitter, @left_frame, @right_frame,
    #      @leftListPropFrame, @rightListPropFrame,
    @splitUL, @splitUR,
    #      @leftButtonsFrame, @rightButtonsFrame,
    @leftListFrame, @rightListFrame, 
    #      @serverField, @userField, @passwordField, @leftPathField,
    #      @rightPathField,
    @leftFileList, @rightFileList
  ].each { |w| w.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_Y) }
  [
    @left_frame, @right_frame,
    @splitOL, @splitOR, @splitUL, @splitUR,
    @leftButtonsFrame, @rightButtonsFrame,
    @leftListFrame, @rightListFrame
  ].each { |w| w.setFrameStyle(FRAME_NONE) }
  @buttonsFrame.setLayoutHints(LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X)
  @buttonsFrame.setPackingHints(PACK_UNIFORM_WIDTH)
  @quitButton.setLayoutHints(LAYOUT_RIGHT)
end

#item_filename(list, index) ⇒ Object



271
272
273
274
# File 'lib/piggy-gui/directory_diff_widget.rb', line 271

def item_filename(list, index)
  txt = fox_2_ruby(list.getItemText(index))
  return txt.split(Regexp.compile("\t"))[0]
end

#left_pathObject



256
257
258
# File 'lib/piggy-gui/directory_diff_widget.rb', line 256

def left_path
  FilePath.intern_path(@leftPathField.getText)
end

#load_iconsObject



65
66
67
68
69
70
71
72
# File 'lib/piggy-gui/directory_diff_widget.rb', line 65

def load_icons
  @dirIcon = basic_load_icon('dir.ico')
  @fileIcon = basic_load_icon('file.ico')
  @dirupIcon = basic_load_icon('dirup.ico')
  @fileAbsentIcon = basic_load_icon('unchecked.ico')
  @dirAbsentIcon = basic_load_icon('unchecked-dir.ico')
  @newerFileIcon = basic_load_icon('newer-file.ico')
end

#on_dir_up_lef_list(sender, sel, ptr) ⇒ Object

events



375
376
377
378
379
380
381
382
383
# File 'lib/piggy-gui/directory_diff_widget.rb', line 375

def on_dir_up_lef_list(sender, sel, ptr)
  return false unless left_path
  suggestion = FilePath.one_dir_up(left_path)
  return false if left_path == suggestion
  set_left_path(suggestion)
  update_left_list
  update_status_icons
  return true
end

#on_dir_up_right_list(sender, sel, ptr) ⇒ Object



385
386
387
388
389
390
391
392
393
# File 'lib/piggy-gui/directory_diff_widget.rb', line 385

def on_dir_up_right_list(sender, sel, ptr)
  return false unless right_path
  suggestion = FilePath.one_dir_up(right_path)
  return false if right_path == suggestion
  set_right_path(suggestion)
  update_right_list
  update_status_icons
  return true
end

#on_doubleclick_left_file_list(sender, sel, index) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
# File 'lib/piggy-gui/directory_diff_widget.rb', line 395

def on_doubleclick_left_file_list(sender, sel, index)
  file_or_folder = ruby_path(@leftFileList.getItemText(index))
  file = file_or_folder.split(Regexp.compile("\t"))[0]
  info = @leftContents[file]
  return false unless info && info.directory?
  file_with_path = FilePath.join(left_path, file)
  set_left_path(file_with_path)
  update_left_list
  update_status_icons
  return true
end

#on_doubleclick_right_file_list(sender, sel, index) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/piggy-gui/directory_diff_widget.rb', line 407

def on_doubleclick_right_file_list(sender, sel, index)
  file_or_folder = ruby_path(@rightFileList.getItemText(index))
  file = file_or_folder.split(Regexp.compile("\t"))[0]
  info = @rightContents[file]
  return false unless info && info.directory?
  file_with_path = FilePath.join(right_path, file)
  set_right_path(file_with_path)
  update_right_list
  update_status_icons
  return true
end

#on_menu_left_list(sender, sel, event) ⇒ Object



419
420
# File 'lib/piggy-gui/directory_diff_widget.rb', line 419

def on_menu_left_list(sender, sel, event)
end

#on_menu_right_list(sender, sel, event) ⇒ Object



422
423
# File 'lib/piggy-gui/directory_diff_widget.rb', line 422

def on_menu_right_list(sender, sel, event)
end

#preferred_widthObject

open/close



427
428
429
# File 'lib/piggy-gui/directory_diff_widget.rb', line 427

def preferred_width
  780
end

#prepare_closureObject



443
444
# File 'lib/piggy-gui/directory_diff_widget.rb', line 443

def prepare_closure
end

#right_pathObject

accessing



247
248
249
# File 'lib/piggy-gui/directory_diff_widget.rb', line 247

def right_path
  @options.localDestinationPath
end

#ruby_path(fox_path) ⇒ Object



235
236
237
# File 'lib/piggy-gui/directory_diff_widget.rb', line 235

def ruby_path(fox_path)
  WinShell.instance.ruby_path(fox_2_ruby(fox_path))
end

#selection_in_list(list) ⇒ Object



264
265
266
267
268
269
# File 'lib/piggy-gui/directory_diff_widget.rb', line 264

def selection_in_list(list)
  selected_ind = (0..list.getNumItems-1).select { |i|
    list.isItemSelected(i)
  }
  return selected_ind.collect { |i| item_filename(list, i) }
end

#set_defaultsObject



239
240
241
242
243
# File 'lib/piggy-gui/directory_diff_widget.rb', line 239

def set_defaults
  p = fox_path(@options.localDestinationPath)
  @rightPathField.setText(@options.localDestinationPath)
  @leftPathField.setText(@options.localDestinationPath)
end

#set_left_path(p) ⇒ Object



260
261
262
# File 'lib/piggy-gui/directory_diff_widget.rb', line 260

def set_left_path(p)
  @leftPathField.setText(fox_path(p))
end

#set_right_path(p) ⇒ Object



251
252
253
254
# File 'lib/piggy-gui/directory_diff_widget.rb', line 251

def set_right_path(p)
  @options.localDestinationPath = FilePath.intern_path(p)
  @rightPathField.setText(fox_path(p))
end

#space_into(frame) ⇒ Object



79
80
81
82
# File 'lib/piggy-gui/directory_diff_widget.rb', line 79

def space_into(frame)
  space = FXHorizontalFrame.new(frame)
  space.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_Y) 
end

#txt_field_num_charsObject



117
118
119
# File 'lib/piggy-gui/directory_diff_widget.rb', line 117

def txt_field_num_chars
  32
end

#update_left_listObject

update



278
279
280
# File 'lib/piggy-gui/directory_diff_widget.rb', line 278

def update_left_list
  @leftContents = update_local_list(@leftFileList, left_path)
end

#update_list(dir_entries, list_widget, contents, &get_info_block) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/piggy-gui/directory_diff_widget.rb', line 312

def update_list(dir_entries, list_widget, contents, &get_info_block)
  list_widget.clearItems
  items = Hash.new
  dir_entries.each do
    |file|
    if include_file?(file)
      info = get_info_block.call(file, contents.path)
      text = ruby_2_fox("#{info.name}\t#{info.mtime_string}")
      if info.directory?
        items[file] = FXIconItem.new(text, nil, @dirIcon)
      else
        items[file] = FXIconItem.new(text, nil, @fileIcon)
      end
      contents.add(info)
    end
  end
  contents.directories.each { |n| list_widget.appendItem(items[n]) }
  contents.files.each { |n| list_widget.appendItem(items[n]) }
end

#update_local_list(listWidget, newPath) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/piggy-gui/directory_diff_widget.rb', line 286

def update_local_list(listWidget, newPath)
  listWidget.clearItems
  contents = DirectoryContents.new(newPath)
  return contents unless newPath && File.directory?(newPath)
  getApp.beginWaitCursor
  begin
    update_list(Dir.entries(newPath), listWidget, contents) do
      |file, path|
      info = FileInfo.new(file, path)
      info.mtime = File.stat(info.name_with_path).mtime
      info.directory! if File.directory?(info.name_with_path)
      info
    end
  rescue StandardError => ex
    error(ex.message)
  end
  getApp.endWaitCursor
  return contents
end

#update_right_listObject



282
283
284
# File 'lib/piggy-gui/directory_diff_widget.rb', line 282

def update_right_list
  @rightContents = update_local_list(@rightFileList, right_path)
end

#update_status_iconsObject



359
360
361
362
# File 'lib/piggy-gui/directory_diff_widget.rb', line 359

def update_status_icons
  update_status_icons_left
  update_status_icons_right
end

#update_status_icons_for(listWidget, myContents, otherContents) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/piggy-gui/directory_diff_widget.rb', line 332

def update_status_icons_for(listWidget, myContents, otherContents)
  (0..listWidget.getNumItems - 1).each do
    |index|
    file = item_filename(listWidget, index)
    myInfo = myContents[file]
    otherInfo = otherContents[file]
    icon = if myInfo.directory?
      otherInfo ? @dirIcon : @dirAbsentIcon
    else
      if otherInfo
        otherInfo.mtime < myInfo.mtime ? @newerFileIcon : @fileIcon
      else
        @fileAbsentIcon
      end
    end
    listWidget.setItemMiniIcon(index, icon)
  end
end

#update_status_icons_leftObject



351
352
353
# File 'lib/piggy-gui/directory_diff_widget.rb', line 351

def update_status_icons_left
  update_status_icons_for(@leftFileList, @leftContents, @rightContents)
end

#update_status_icons_rightObject



355
356
357
# File 'lib/piggy-gui/directory_diff_widget.rb', line 355

def update_status_icons_right
  update_status_icons_for(@rightFileList, @rightContents, @leftContents)
end