Class: CDK::FSELECT
- Includes:
- ListSupport
- Defined in:
- lib/cdk/components/fselect.rb
Instance Attribute Summary collapse
-
#dir_attribute ⇒ Object
readonly
Returns the value of attribute dir_attribute.
-
#dir_contents ⇒ Object
readonly
Returns the value of attribute dir_contents.
-
#entry_field ⇒ Object
readonly
Returns the value of attribute entry_field.
-
#field_attribute ⇒ Object
readonly
Returns the value of attribute field_attribute.
-
#file_attribute ⇒ Object
readonly
Returns the value of attribute file_attribute.
-
#file_counter ⇒ Object
readonly
Returns the value of attribute file_counter.
-
#filler_character ⇒ Object
readonly
Returns the value of attribute filler_character.
-
#highlight ⇒ Object
readonly
Returns the value of attribute highlight.
-
#link_attribute ⇒ Object
readonly
Returns the value of attribute link_attribute.
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
-
#scroll_field ⇒ Object
readonly
Returns the value of attribute scroll_field.
-
#sock_attribute ⇒ Object
readonly
Returns the value of attribute sock_attribute.
Attributes included from HasTitle
Attributes included from HasScreen
#is_visible, #screen, #screen_index
Attributes included from ExitConditions
Attributes included from Bindings
Attributes included from Focusable
Attributes included from Borders
#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box
Class Method Summary collapse
-
.expandTilde(filename) ⇒ Object
Currently a wrapper for File.expand_path.
- .isFullWidth(width) ⇒ Object
-
.make_pathname(directory, filename) ⇒ Object
Currently a wrapper for File.expand_path.
Instance Method Summary collapse
-
#activate(actions) ⇒ Object
This means you want to use the given file selector.
-
#contentToPath(content) ⇒ Object
Return the plain string that corresponds to an item in dir_contents.
- #createList(list, list_size) ⇒ Object
-
#destroy ⇒ Object
This destroys the file selector.
- #destroyInfo ⇒ Object
-
#draw(box) ⇒ Object
This draws the file selector widget.
- #drawMyScroller ⇒ Object
-
#erase ⇒ Object
This erases the file selector from the screen.
- #focus ⇒ Object
- #getContents(size) ⇒ Object
-
#getCurrentItem ⇒ Object
Get/set the current position in the scroll wiget.
- #getDirAttribute ⇒ Object
- #getDirContents(count) ⇒ Object
- #getDirectory ⇒ Object
- #getFileAttribute ⇒ Object
- #getFillerChar ⇒ Object
- #getHighlight ⇒ Object
- #getLinkAttribute ⇒ Object
- #getSocketAttribute ⇒ Object
-
#initialize(cdkscreen, xplace, yplace, height, width, title, label, field_attribute, filler_char, highlight, d_attribute, f_attribute, l_attribute, s_attribute, box, shadow) ⇒ FSELECT
constructor
A new instance of FSELECT.
-
#inject(input) ⇒ Object
This injects a single character into the file selector.
- #injectMyScroller(key) ⇒ Object
-
#move(xplace, yplace, relative, refresh_flag) ⇒ Object
This moves the fselect field to the given location.
- #object_type ⇒ Object
- #position ⇒ Object
- #restoreFocus ⇒ Object
-
#saveFocus ⇒ Object
The fselect’s focus resides in the entry widget.
-
#set(directory, field_attrib, filler, highlight, dir_attribute, file_attribute, link_attribute, sock_attribute, box) ⇒ Object
This function sets the information inside the file selector.
-
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
-
#setContents(list, list_size) ⇒ Object
this sets the contents of the widget.
- #setCurrentItem(item) ⇒ Object
-
#setDirAttribute(attribute) ⇒ Object
This sets the attribute of the directory attribute in the scrolling list.
-
#setDirContents ⇒ Object
This creates a list of the files in the current directory.
-
#setDirectory(directory) ⇒ Object
This sets the current directory of the file selector.
-
#setFileAttribute(attribute) ⇒ Object
This sets the attribute of the file attribute in the scrolling list.
-
#setFillerChar(filler) ⇒ Object
This sets the filler character of the entry field.
-
#setHighlight(highlight) ⇒ Object
This sets the highlight bar of the scrolling list.
-
#setLinkAttribute(attribute) ⇒ Object
This sets the attribute of the link attribute in the scrolling list.
- #setMyBXattr(character) ⇒ Object
- #setMyHZchar(character) ⇒ Object
- #setMyLLchar(character) ⇒ Object
- #setMyLRchar(character) ⇒ Object
-
#setMyULchar(character) ⇒ Object
These functions set the draw characters of the widget.
- #setMyURchar(character) ⇒ Object
- #setMyVTchar(character) ⇒ Object
-
#setSocketAttribute(attribute) ⇒ Object
This sets the attribute of the socket attribute in the scrolling list.
- #unfocus ⇒ Object
Methods included from ListSupport
Methods inherited from CDKOBJS
#setBackgroundColor, #timeout, #validCDKObject, #validObjType
Methods included from WindowHooks
Methods included from WindowInput
#getc, #getch, #setPostProcess, #setPreProcess
Methods included from HasTitle
#cleanTitle, #drawTitle, #init_title, #setTitle
Methods included from HasScreen
#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh
Methods included from ExitConditions
#init_exit_conditions, #resetExitType, #setExitType
Methods included from Bindings
#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind
Methods included from Focusable
Methods included from Borders
#getBox, #init_borders, #setBXattr, #setBox, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar
Methods included from Movement
Methods included from Converters
#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute
Methods included from Justifications
Methods included from Alignments
Constructor Details
#initialize(cdkscreen, xplace, yplace, height, width, title, label, field_attribute, filler_char, highlight, d_attribute, f_attribute, l_attribute, s_attribute, box, shadow) ⇒ FSELECT
Returns a new instance of FSELECT.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/cdk/components/fselect.rb', line 13 def initialize(cdkscreen, xplace, yplace, height, width, title, label, field_attribute, filler_char, highlight, d_attribute, f_attribute, l_attribute, s_attribute, box, shadow) super() parent_width = cdkscreen.window.getmaxx parent_height = cdkscreen.window.getmaxy bindings = { CDK::BACKCHAR => Ncurses::KEY_PPAGE, CDK::FORCHAR => Ncurses::KEY_NPAGE, } self.setBox(box) # If the height is a negative value the height will be ROWS-height, # otherwise the height will be the given height box_height = CDK.setWidgetDimension(parent_height, height, 0) # If the width is a negative value, the width will be COLS-width, # otherwise the width will be the given width. box_width = CDK.setWidgetDimension(parent_width, width, 0) # Rejustify the x and y positions if we need to. xtmp = [xplace] ytmp = [yplace] alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height) xpos = xtmp[0] ypos = ytmp[0] # Make sure the box isn't too small. box_width = [box_width, 15].max box_height = [box_height, 6].max # Make the file selector window. @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos) # is the window nil? if @win.nil? fselect.destroy return nil end @win.keypad(true) # Set some variables. @screen = cdkscreen @parent = cdkscreen.window @dir_attribute = d_attribute.clone @file_attribute = f_attribute.clone @link_attribute = l_attribute.clone @sock_attribute = s_attribute.clone @highlight = highlight @filler_character = filler_char @field_attribute = field_attribute @box_height = box_height @box_width = box_width @file_counter = 0 @pwd = '' @input_window = @win @shadow = shadow @shadow_win = nil # Get the present working directory. # XXX need error handling (set to '.' on error) @pwd = Dir.getwd # Get the contents of the current directory self.setDirContents # Create the entry field in the selector label_len = [] char2Chtype(label, label_len, []) label_len = label_len[0] temp_width = if CDK::FSELECT.isFullWidth(width) then CDK::FULL else box_width - 2 - label_len end @entry_field = CDK::ENTRY.new(cdkscreen, @win.getbegx, @win.getbegy, title, label, field_attribute, filler_char, :MIXED, temp_width, 0, 512, box, false) # Make sure the widget was created. if @entry_field.nil? self.destroy return nil end # Set the lower left/right characters of the entry field. @entry_field.setLLchar(Ncurses::ACS_LTEE) @entry_field.setLRchar(Ncurses::ACS_RTEE) # This is a callback to the scrolling list which displays information # about the current file. (and the whole directory as well) display_file_info_cb = lambda do |object_type, entry, fselect, key| # Get the file name. filename = fselect.entry_field.info # Get specific information about the files. # lstat (filename, &fileStat); file_stat = File.stat(filename) # Determine the file type filetype = case when file_stat.symlink? 'Symbolic Link' when file_stat.socket? 'Socket' when file_stat.file? 'Regular File' when file_stat.directory? 'Directory' when file_stat.chardev? 'Character Device' when file_stat.blockdev? 'Block Device' when file_stat.ftype == 'fif' 'FIFO Device' else 'Unknown' end # Get the user name and group name. pw_ent = Etc.getpwuid(file_stat.uid) gr_ent = Etc.getgrgid(file_stat.gid) # Convert the mode to both string and int # intMode = mode2Char (stringMode, fileStat.st_mode); # Create the message. mesg = [ 'Directory : </U>%s' % [fselect.pwd], 'Filename : </U>%s' % [filename], 'Owner : </U>%s<!U> (%d)' % [pw_ent.name, file_stat.uid], 'Group : </U>%s<!U> (%d)' % [gr_ent.name, file_stat.gid], 'Permissions: </U>%s<!U> (%o)' % [string_mode, int_mode], 'Size : </U>%ld<!U> bytes' % [file_stat.size], 'Last Access: </U>%s' % [file_stat.atime], 'Last Change: </U>%s' % [file_stat.ctime], 'File Type : </U>%s' % [filetype] ] # Create the pop up label. info_label = CDK::LABEL.new(entry.screen, CDK::CENTER, CDK::CENTER, mesg, 9, true, false) info_label.draw(true) info_label.getch([]) info_label.destroy # Redraw the file selector. fselect.draw(fselect.box) return true end # This tries to complete the filename complete_filename_cb = lambda do |object_type, object, fselect, key| scrollp = fselect.scroll_field entry = fselect.entry_field filename = entry.info.clone mydirname = CDK.dirName(filename) current_index = 0 # Make sure the filename is not nil/empty. if filename.nil? || filename.size == 0 CDK.Beep return true end # Try to expand the filename if it starts with a ~ unless (new_filename = CDK::FSELECT.(filename)).nil? filename = new_filename entry.setValue(filename) entry.draw(entry.box) end # Make sure we can change into the directory. is_directory = Dir.exists?(filename) # if (chdir (fselect->pwd) != 0) # return FALSE; #Dir.chdir(fselect.pwd) # XXX original: isDirectory ? mydirname : filename fselect.set(if is_directory then filename else mydirname end, fselect.field_attribute, fselect.filler_character, fselect.highlight, fselect.dir_attribute, fselect.file_attribute, fselect.link_attribute, fselect.sock_attribute, fselect.box) # If we can, change into the directory. # XXX original: if isDirectory (with 0 as success result) if is_directory entry.setValue(filename) entry.draw(entry.box) end # Create the file list. list = [] (0...fselect.file_counter).each do |x| list << fselect.contentToPath(fselect.dir_contents[x]) end # Look for a unique filename match. index = search_list(list, fselect.file_counter, filename) # If the index is less than zero, return we didn't find a match. if index < 0 CDK.Beep else # Move to the current item in the scrolling list. # difference = Index - scrollp->currentItem; # absoluteDifference = abs (difference); # if (difference < 0) # { # for (x = 0; x < absoluteDifference; x++) # { # injectMyScroller (fselect, KEY_UP); # } # } # else if (difference > 0) # { # for (x = 0; x < absoluteDifferene; x++) # { # injectMyScroller (fselect, KEY_DOWN); # } # } scrollp.setPosition(index) fselect.drawMyScroller # Ok, we found a match, is the next item similar? if index + 1 < fselect.file_counter && index + 1 < list.size && list[index + 1][0..([filename.size, list[index + 1].size].min)] == filename current_index = index base_chars = filename.size matches = 0 # Determine the number of files which match. while current_index < fselect.file_counter if current_index + 1 < list.size if list[current_index][0..( [filename.size, list[current_index].size].max)] == filename matches += 1 end end current_index += 1 end # Start looking for the common base characters. while true secondary_matches = 0 (index...index + matches).each do |x| if list[index][base_chars] == list[x][base_chars] secondary_matches += 1 end end if secondary_matches != matches CDK.Beep break end # Inject the character into the entry field. fselect.entry_field.inject(list[index][base_chars]) base_chars += 1 end else # Set the entry field with the found item. entry.setValue(list[index]) entry.draw(entry.box) end end return true end # This allows the user to delete a file. delete_file_cb = lambda do |object_type, fscroll, fselect| = ['No', 'Yes'] # Get the filename which is to be deleted. filename = chtype2Char(fscroll.item[fscroll.current_item]) filename = filename[0...-1] # Create the dialog message. mesg = [ '<C>Are you sure you want to delete the file:', '<C></U>"%s"?' % [filename] ] # Create the dialog box. question = CDK::DIALOG.new(fselect.screen, CDK::CENTER, CDK::CENTER, mesg, 2, , 2, Ncurses::A_REVERSE, true, true, false) # If the said yes then try to nuke it. if question.activate([]) == 1 # If we were successful, reload the scrolling list. if File.unlink(filename) == 0 # Set the file selector information. fselect.set(fselect.pwd, fselect.field_attribute, fselect.filler_character, fselect.highlight, fselect.dir_attribute, fselect.file_attribute, fselect.link_attribute, fselect.sock_attribute, fselect.box) else # Pop up a message. # mesg[0] = copyChar (errorMessage ("<C>Cannot delete file: %s")); # mesg[1] = copyChar (" "); # mesg[2] = copyChar("<C>Press any key to continue."); # popupLabel(ScreenOf (fselect), (CDK_CSTRING2) mesg, 3); # freeCharList (mesg, 3); end end # Clean up. question.destroy # Redraw the file seoector. fselect.draw(fselect.box) end # Start of callback functions. adjust_scroll_cb = lambda do |object_type, object, fselect, key| scrollp = fselect.scroll_field entry = fselect.entry_field if scrollp.list_size > 0 # Move the scrolling list. fselect.injectMyScroller(key) # Get the currently highlighted filename. current = chtype2Char(scrollp.item[scrollp.current_item]) #current = chtype2String(scrollp.item[scrollp.current_item]) current = current[0...-1] temp = CDK::FSELECT.make_pathname(fselect.pwd, current) # Set the value in the entry field. entry.setValue(temp) entry.draw(entry.box) return true end CDK.Beep return false end # Define the callbacks for the entry field. @entry_field.bind(:ENTRY, Ncurses::KEY_UP, adjust_scroll_cb, self) @entry_field.bind(:ENTRY, Ncurses::KEY_PPAGE, adjust_scroll_cb, self) @entry_field.bind(:ENTRY, Ncurses::KEY_DOWN, adjust_scroll_cb, self) @entry_field.bind(:ENTRY, Ncurses::KEY_NPAGE, adjust_scroll_cb, self) @entry_field.bind(:ENTRY, CDK::KEY_TAB, complete_filename_cb, self) @entry_field.bind(:ENTRY, CDK.CTRL('^'), display_file_info_cb, self) # Put the current working directory in the entry field. @entry_field.setValue(@pwd) # Create the scrolling list in the selector. temp_height = @entry_field.win.getmaxy - @border_size temp_width = if CDK::FSELECT.isFullWidth(width) then CDK::FULL else box_width - 1 end @scroll_field = CDK::SCROLL.new(cdkscreen, @win.getbegx, @win.getbegy + temp_height, CDK::RIGHT, box_height - temp_height, temp_width, '', @dir_contents, @file_counter, false, @highlight, box, false) # Set the lower left/right characters of the entry field. @scroll_field.setULchar(Ncurses::ACS_LTEE) @scroll_field.setURchar(Ncurses::ACS_RTEE) # Do we want a shadow? if shadow @shadow_win = Ncurses::WINDOW.new(box_height, box_width, ypos + 1, xpos + 1) end # Setup the key bindings bindings.each do |from, to| self.bind(:FSELECT, from, :getc, to) end cdkscreen.register(:FSELECT, self) end |
Instance Attribute Details
#dir_attribute ⇒ Object (readonly)
Returns the value of attribute dir_attribute.
9 10 11 |
# File 'lib/cdk/components/fselect.rb', line 9 def dir_attribute @dir_attribute end |
#dir_contents ⇒ Object (readonly)
Returns the value of attribute dir_contents.
11 12 13 |
# File 'lib/cdk/components/fselect.rb', line 11 def dir_contents @dir_contents end |
#entry_field ⇒ Object (readonly)
Returns the value of attribute entry_field.
8 9 10 |
# File 'lib/cdk/components/fselect.rb', line 8 def entry_field @entry_field end |
#field_attribute ⇒ Object (readonly)
Returns the value of attribute field_attribute.
10 11 12 |
# File 'lib/cdk/components/fselect.rb', line 10 def field_attribute @field_attribute end |
#file_attribute ⇒ Object (readonly)
Returns the value of attribute file_attribute.
9 10 11 |
# File 'lib/cdk/components/fselect.rb', line 9 def file_attribute @file_attribute end |
#file_counter ⇒ Object (readonly)
Returns the value of attribute file_counter.
11 12 13 |
# File 'lib/cdk/components/fselect.rb', line 11 def file_counter @file_counter end |
#filler_character ⇒ Object (readonly)
Returns the value of attribute filler_character.
10 11 12 |
# File 'lib/cdk/components/fselect.rb', line 10 def filler_character @filler_character end |
#highlight ⇒ Object (readonly)
Returns the value of attribute highlight.
9 10 11 |
# File 'lib/cdk/components/fselect.rb', line 9 def highlight @highlight end |
#link_attribute ⇒ Object (readonly)
Returns the value of attribute link_attribute.
9 10 11 |
# File 'lib/cdk/components/fselect.rb', line 9 def link_attribute @link_attribute end |
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
11 12 13 |
# File 'lib/cdk/components/fselect.rb', line 11 def pathname @pathname end |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
11 12 13 |
# File 'lib/cdk/components/fselect.rb', line 11 def pwd @pwd end |
#scroll_field ⇒ Object (readonly)
Returns the value of attribute scroll_field.
8 9 10 |
# File 'lib/cdk/components/fselect.rb', line 8 def scroll_field @scroll_field end |
#sock_attribute ⇒ Object (readonly)
Returns the value of attribute sock_attribute.
10 11 12 |
# File 'lib/cdk/components/fselect.rb', line 10 def sock_attribute @sock_attribute end |
Class Method Details
.expandTilde(filename) ⇒ Object
Currently a wrapper for File.expand_path
886 887 888 |
# File 'lib/cdk/components/fselect.rb', line 886 def self.(filename) return File.(filename) end |
.isFullWidth(width) ⇒ Object
931 932 933 |
# File 'lib/cdk/components/fselect.rb', line 931 def self.isFullWidth(width) width == CDK::FULL || (Ncurses.COLS != 0 && width >= Ncurses.COLS) end |
.make_pathname(directory, filename) ⇒ Object
Currently a wrapper for File.expand_path
864 865 866 867 868 869 870 |
# File 'lib/cdk/components/fselect.rb', line 864 def self.make_pathname(directory, filename) if filename == '..' return File.(directory) + '/..' else return File.(filename, directory) end end |
Instance Method Details
#activate(actions) ⇒ Object
This means you want to use the given file selector. It takes input from the keyboard and when it’s done it fills the entry info element of the structure with what was typed.
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/cdk/components/fselect.rb', line 457 def activate(actions) input = 0 ret = 0 # Draw the widget. self.draw(@box) if actions.nil? || actions.size == 0 while true input = @entry_field.getch([]) # Inject the character into the widget. ret = self.inject(input) if @exit_type != :EARLY_EXIT return ret end end else # Inject each character one at a time. actions.each do |action| ret = self.inject(action) if @exit_type != :EARLY_EXIT return ret end end end # Set the exit type and exit. self.setExitType(0) return 0 end |
#contentToPath(content) ⇒ Object
Return the plain string that corresponds to an item in dir_contents
873 874 875 876 877 878 879 880 881 882 883 |
# File 'lib/cdk/components/fselect.rb', line 873 def contentToPath(content) # XXX direct translation of original but might be redundant temp_chtype = char2Chtype(content, [], []) temp_char = chtype2Char(temp_chtype) temp_char = temp_char[0..-1] # Create the pathname. result = CDK::FSELECT.make_pathname(@pwd, temp_char) return result end |
#createList(list, list_size) ⇒ Object
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
# File 'lib/cdk/components/fselect.rb', line 895 def createList(list, list_size) status = false if list_size >= 0 newlist = [] # Copy in the new information status = true (0...list_size).each do |x| newlist << list[x] if newlist[x] == 0 status = false break end end if status self.destroyInfo @file_counter = list_size @dir_contents = newlist end else self.destroyInfo status = true end return status end |
#destroy ⇒ Object
This destroys the file selector.
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/cdk/components/fselect.rb', line 847 def destroy self.cleanBindings(:FSELECT) # Destroy the other CDK objects @scroll_field.destroy @entry_field.destroy # Free up the windows CDK.deleteCursesWindow(@shadow_win) CDK.deleteCursesWindow(@win) # Clean the key bindings. # Unregister the object. CDK::SCREEN.unregister(:FSELECT, self) end |
#destroyInfo ⇒ Object
890 891 892 893 |
# File 'lib/cdk/components/fselect.rb', line 890 def destroyInfo @dir_contents = [] @file_counter = 0 end |
#draw(box) ⇒ Object
This draws the file selector widget.
441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/cdk/components/fselect.rb', line 441 def draw(box) # Draw in the shadow if we need to. unless @shadow_win.nil? Draw.drawShadow(@shadow_win) end # Draw in the entry field. @entry_field.draw(@entry_field.box) # Draw in the scroll field. self.drawMyScroller end |
#drawMyScroller ⇒ Object
428 429 430 431 432 |
# File 'lib/cdk/components/fselect.rb', line 428 def drawMyScroller self.saveFocus @scroll_field.draw(@scroll_field.box) self.restoreFocus end |
#erase ⇒ Object
This erases the file selector from the screen.
397 398 399 400 401 402 403 |
# File 'lib/cdk/components/fselect.rb', line 397 def erase if self.validCDKObject @scroll_field.erase @entry_field.erase CDK.eraseCursesWindow(@win) end end |
#focus ⇒ Object
923 924 925 |
# File 'lib/cdk/components/fselect.rb', line 923 def focus @entry_field.focus end |
#getContents(size) ⇒ Object
789 790 791 792 |
# File 'lib/cdk/components/fselect.rb', line 789 def getContents(size) size << @file_counter return @dir_contents end |
#getCurrentItem ⇒ Object
Get/set the current position in the scroll wiget.
795 796 797 |
# File 'lib/cdk/components/fselect.rb', line 795 def getCurrentItem return @scroll_field.getCurrent end |
#getDirAttribute ⇒ Object
724 725 726 |
# File 'lib/cdk/components/fselect.rb', line 724 def getDirAttribute return @dir_attribute end |
#getDirContents(count) ⇒ Object
655 656 657 658 |
# File 'lib/cdk/components/fselect.rb', line 655 def getDirContents(count) count << @file_counter return @dir_contents end |
#getDirectory ⇒ Object
690 691 692 |
# File 'lib/cdk/components/fselect.rb', line 690 def getDirectory return @pwd end |
#getFileAttribute ⇒ Object
763 764 765 |
# File 'lib/cdk/components/fselect.rb', line 763 def getFileAttribute return @file_attribute end |
#getFillerChar ⇒ Object
700 701 702 |
# File 'lib/cdk/components/fselect.rb', line 700 def getFillerChar return @filler_character end |
#getHighlight ⇒ Object
710 711 712 |
# File 'lib/cdk/components/fselect.rb', line 710 def getHighlight return @highlight end |
#getLinkAttribute ⇒ Object
737 738 739 |
# File 'lib/cdk/components/fselect.rb', line 737 def getLinkAttribute return @link_attribute end |
#getSocketAttribute ⇒ Object
750 751 752 |
# File 'lib/cdk/components/fselect.rb', line 750 def getSocketAttribute return @sock_attribute end |
#inject(input) ⇒ Object
This injects a single character into the file selector.
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/cdk/components/fselect.rb', line 490 def inject(input) ret = -1 @complete = false # Let the user play. filename = @entry_field.inject(input) # Copy the entry field exit_type to the file selector. @exit_type = @entry_field.exit_type # If we exited early, make sure we don't interpret it as a file. if @exit_type == :EARLY_EXIT return 0 end # Can we change into the directory #file = Dir.chdir(filename) #if Dir.chdir(@pwd) != 0 # return 0 #end # If it's not a directory, return the filename. if !Dir.exists?(filename) # It's a regular file, create the full path @pathname = filename.clone # Return the complete pathname. ret = @pathname @complete = true else # Set the file selector information. self.set(filename, @field_attribute, @filler_character, @highlight, @dir_attribute, @file_attribute, @link_attribute, @sock_attribute, @box) # Redraw the scrolling list. self.drawMyScroller end if !@complete self.setExitType(0) end @result_data = ret return ret end |
#injectMyScroller(key) ⇒ Object
434 435 436 437 438 |
# File 'lib/cdk/components/fselect.rb', line 434 def injectMyScroller(key) self.saveFocus @scroll_field.inject(key) self.restoreFocus end |
#move(xplace, yplace, relative, refresh_flag) ⇒ Object
This moves the fselect field to the given location.
406 407 408 409 410 411 412 |
# File 'lib/cdk/components/fselect.rb', line 406 def move(xplace, yplace, relative, refresh_flag) windows = [@win, @shadow_win] = [@entry_field, @scroll_field] self.move_specific(xplace, yplace, relative, refresh_flag, windows, ) end |
#object_type ⇒ Object
939 940 941 |
# File 'lib/cdk/components/fselect.rb', line 939 def object_type :FSELECT end |
#position ⇒ Object
935 936 937 |
# File 'lib/cdk/components/fselect.rb', line 935 def position super(@win) end |
#restoreFocus ⇒ Object
424 425 426 |
# File 'lib/cdk/components/fselect.rb', line 424 def restoreFocus @scroll_field.has_focus = @save end |
#saveFocus ⇒ Object
The fselect’s focus resides in the entry widget. But the scroll widget will not draw items highlighted unless it has focus. Temporarily adjust the focus of the scroll widget when drawing on it to get the right highlighting.
419 420 421 422 |
# File 'lib/cdk/components/fselect.rb', line 419 def saveFocus @save = @scroll_field.has_focus @scroll_field.has_focus = @entry_field.has_focus end |
#set(directory, field_attrib, filler, highlight, dir_attribute, file_attribute, link_attribute, sock_attribute, box) ⇒ Object
This function sets the information inside the file selector.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/cdk/components/fselect.rb', line 538 def set(directory, field_attrib, filler, highlight, dir_attribute, file_attribute, link_attribute, sock_attribute, box) fscroll = @scroll_field fentry = @entry_field new_directory = '' # keep the info sent to us. @field_attribute = field_attrib @filler_character = filler @highlight = highlight # Set the attributes of the entry field/scrolling list. self.setFillerChar(filler) self.setHighlight(highlight) # Only do the directory stuff if the directory is not nil. if !(directory.nil?) && directory.size > 0 # Try to expand the directory if it starts with a ~ if (temp_dir = CDK::FSELECT.(directory)).size > 0 new_directory = temp_dir else new_directory = directory.clone end # Change directories. if Dir.chdir(new_directory) != 0 CDK.Beep # Could not get into the directory, pop up a little message. mesg = [ '<C>Could not change into %s' % [new_directory], '<C></U>%s' % ['Unknown reason.'], # errorMessage(format) ' ', '<C>Press Any Key To Continue.' ] # Pop up a message. @screen.popupLabel(mesg, 4) # Get out of here. self.erase self.draw(@box) return end end # if the information coming in is the same as the information # that is already there, there is no need to destroy it. if @pwd != directory @pwd = Dir.getwd end @file_attribute = file_attribute.clone @dir_attribute = dir_attribute.clone @link_attribute = link_attribute.clone @sock_attribute = sock_attribute.clone # Set the contents of the entry field. fentry.setValue(@pwd) fentry.draw(fentry.box) # Get the directory contents. unless self.setDirContents CDK.Beep return end # Set the values in the scrolling list. fscroll.setItems(@dir_contents, @file_counter, false) end |
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
841 842 843 844 |
# File 'lib/cdk/components/fselect.rb', line 841 def setBKattr(attrib) @entry_field.setBKattr(attrib) @scroll_field.setBKattr(attrib) end |
#setContents(list, list_size) ⇒ Object
this sets the contents of the widget
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
# File 'lib/cdk/components/fselect.rb', line 768 def setContents(list, list_size) scrollp = @scroll_field entry = @entry_field if !self.createList(list, list_size) return end # Set the information in the scrolling list. scrollp.set(@dir_contents, @file_counter, false, scrollp.highlight, scrollp.box) # Clean out the entry field. self.setCurrentItem(0) entry.clean # Redraw the widget. self.erase self.draw(@box) end |
#setCurrentItem(item) ⇒ Object
799 800 801 802 803 804 805 806 |
# File 'lib/cdk/components/fselect.rb', line 799 def setCurrentItem(item) if @file_counter != 0 @scroll_field.setCurrent(item) data = self.contentToPath(@dir_contents[@scroll_field.getCurrentItem]) @entry_field.setValue(data) end end |
#setDirAttribute(attribute) ⇒ Object
This sets the attribute of the directory attribute in the scrolling list.
716 717 718 719 720 721 722 |
# File 'lib/cdk/components/fselect.rb', line 716 def setDirAttribute(attribute) # Make sure they are not the same. if @dir_attribute != attribute @dir_attribute = attribute self.setDirContents end end |
#setDirContents ⇒ Object
This creates a list of the files in the current directory.
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/cdk/components/fselect.rb', line 610 def setDirContents dir_list = [] # Get the directory contents file_count = CDK.getDirectoryContents(@pwd, dir_list) if file_count <= 0 # We couldn't read the directory. Return. return false end @dir_contents = dir_list @file_counter = file_count # Set the properties of the files. (0...@file_counter).each do |x| attr = '' mode = '?' # FIXME(original): access() would give a more correct answer # TODO: add error handling file_stat = File.stat(dir_list[x]) if file_stat.executable? mode = '*' else mode = ' ' end case when file_stat.symlink? attr = @link_attribute mode = '@' when file_stat.socket? attr = @sock_attribute mode = '&' when file_stat.file? attr = @file_attribute when file_stat.directory? attr = @dir_attribute mode = '/' end @dir_contents[x] = '%s%s%s' % [attr, dir_list[x], mode] end return true end |
#setDirectory(directory) ⇒ Object
This sets the current directory of the file selector.
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/cdk/components/fselect.rb', line 661 def setDirectory(directory) fentry = @entry_field fscroll = @scroll_field result = 1 # If the directory supplied is the same as what is already there, return. if @pwd != directory # Try to chdir into the given directory. if Dir.chdir(directory) != 0 result = 0 else @pwd = Dir.getwd # Set the contents of the entry field. fentry.setValue(@pwd) fentry.draw(fentry.box) # Get the directory contents. if self.setDirContents # Set the values in the scrolling list. fscroll.setItems(@dir_contents, @file_counter, false) else result = 0 end end end return result end |
#setFileAttribute(attribute) ⇒ Object
This sets the attribute of the file attribute in the scrolling list.
755 756 757 758 759 760 761 |
# File 'lib/cdk/components/fselect.rb', line 755 def setFileAttribute(attribute) # Make sure they are not the same. if @file_attribute != attribute @file_attribute = attribute self.setDirContents end end |
#setFillerChar(filler) ⇒ Object
This sets the filler character of the entry field.
695 696 697 698 |
# File 'lib/cdk/components/fselect.rb', line 695 def setFillerChar(filler) @filler_character = filler @entry_field.setFillerChar(filler) end |
#setHighlight(highlight) ⇒ Object
This sets the highlight bar of the scrolling list.
705 706 707 708 |
# File 'lib/cdk/components/fselect.rb', line 705 def setHighlight(highlight) @highlight = highlight @scroll_field.setHighlight(highlight) end |
#setLinkAttribute(attribute) ⇒ Object
This sets the attribute of the link attribute in the scrolling list.
729 730 731 732 733 734 735 |
# File 'lib/cdk/components/fselect.rb', line 729 def setLinkAttribute(attribute) # Make sure they are not the same. if @link_attribute != attribute @link_attribute = attribute self.setDirContents end end |
#setMyBXattr(character) ⇒ Object
835 836 837 838 |
# File 'lib/cdk/components/fselect.rb', line 835 def setMyBXattr(character) @entry_field.setBXattr(character) @scroll_field.setBXattr(character) end |
#setMyHZchar(character) ⇒ Object
830 831 832 833 |
# File 'lib/cdk/components/fselect.rb', line 830 def setMyHZchar(character) @entry_field.setHZchar(character) @scroll_field.setHZchar(character) end |
#setMyLLchar(character) ⇒ Object
817 818 819 |
# File 'lib/cdk/components/fselect.rb', line 817 def setMyLLchar(character) @scroll_field.setLLchar(character) end |
#setMyLRchar(character) ⇒ Object
821 822 823 |
# File 'lib/cdk/components/fselect.rb', line 821 def setMyLRchar(character) @scroll_field.setLRchar(character) end |
#setMyULchar(character) ⇒ Object
These functions set the draw characters of the widget.
809 810 811 |
# File 'lib/cdk/components/fselect.rb', line 809 def setMyULchar(character) @entry_field.setULchar(character) end |
#setMyURchar(character) ⇒ Object
813 814 815 |
# File 'lib/cdk/components/fselect.rb', line 813 def setMyURchar(character) @entry_field.setURchar(character) end |
#setMyVTchar(character) ⇒ Object
825 826 827 828 |
# File 'lib/cdk/components/fselect.rb', line 825 def setMyVTchar(character) @entry_field.setVTchar(character) @scroll_field.setVTchar(character) end |
#setSocketAttribute(attribute) ⇒ Object
This sets the attribute of the socket attribute in the scrolling list.
742 743 744 745 746 747 748 |
# File 'lib/cdk/components/fselect.rb', line 742 def setSocketAttribute(attribute) # Make sure they are not the same. if @sock_attribute != attribute @sock_attribute = attribute self.setDirContents end end |
#unfocus ⇒ Object
927 928 929 |
# File 'lib/cdk/components/fselect.rb', line 927 def unfocus @entry_field.unfocus end |