idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
13,500
def sign_in ( resource_or_scope , * args ) options = args . extract_options! scope = Devise :: Mapping . find_scope! ( resource_or_scope ) resource = args . last || resource_or_scope expire_session_data_after_sign_in! warden . set_user ( resource , options . merge! ( :scope => scope ) ) post_signin resource , options e...
Sign in an user that already was authenticated . This helper is useful for logging users in after sign up .
13,501
def sign_out ( resource_or_scope ) scope = Devise :: Mapping . find_scope! ( resource_or_scope ) warden . user ( scope ) warden . raw_session . inspect warden . logout ( scope ) post_signout scope end
Sign out a given user or scope . This helper is useful for signing out an user after deleting accounts .
13,502
def insert off0 , data _maxlen = @maxlen || @width - @internal_width if data . length > _maxlen data = wrap_text data data = data . split ( "\n" ) data [ - 1 ] << "\r" data . each do | row | @list . insert off0 , row off0 += 1 end else data << "\r" if data [ - 1 , 1 ] != "\r" @list . insert off0 , data end end
trying to wrap and insert
13,503
def << data _maxlen = @maxlen || @width - @internal_width if data . length > _maxlen data = wrap_text data data = data . split ( "\n" ) data . each { | line | @list << line } @list [ - 1 ] << "\r" else data << "\r" if data [ - 1 , 1 ] != "\r" @list << data end set_modified goto_end if @auto_scroll self end
wraps line sent in if longer than _maxlen Typically a line is sent in . We wrap and put a hard return at end .
13,504
def undo_delete return if @delete_buffer . nil? $log . warn "undo_delete is broken! perhaps cannot be used . textarea 347 " case @delete_buffer when Array str = @delete_buffer . first else str = @delete_buffer end @buffer . insert @curpos , str set_modified fire_handler :CHANGE , InputDataEvent . new ( @curpos , @curpo...
this is broken delete_buffer could be a line or a string or array of lines
13,505
def insert_break return - 1 unless @editable $log . debug "ENTER PRESSED at #{@curpos}, on row #{@current_index}" @delete_buffer = ( delete_eol || "" ) @list [ @current_index ] << "\r" $log . debug "DELETE BUFFER #{@delete_buffer}" @list . insert @current_index + 1 , @delete_buffer @curpos = 0 down col = @orig_col + @...
FIXME - fire event not correct not undo ing correctly check row and also slash r append
13,506
def set_form_col col1 = @curpos @curpos = col1 @cols_panned ||= 0 cursor_bounds_check win_col = 0 col = win_col + @col + @col_offset + @curpos + @cols_panned $log . debug "sfc: wc:#{win_col} col:#{@col}, coff:#{@col_offset}. cp:#{@curpos} colsp:#{@cols_panned} . " $log . debug " TA calling setformrow col nil, #{col} "...
set cursor on correct column
13,507
def insert_wrap lineno , pos , lastchars _maxlen = @maxlen || @width - @internal_width @list [ lineno ] . insert pos , lastchars len = @list [ lineno ] . length if len > _maxlen push_last_word lineno end end
this attempts to recursively insert into a row seeing that any stuff exceeding is pushed down further . Yes it should check for a para end and insert . Currently it could add to next para .
13,508
def putch char _maxlen = @maxlen || @width - @internal_width @buffer ||= @list [ @current_index ] return - 1 if ! @editable raise "putch expects only one char" if char . length != 1 oldcurpos = @curpos if @overwrite_mode @buffer [ @curpos ] = char else @buffer . insert ( @curpos , char ) end @curpos += 1 if @curpos - 1...
add one char . careful i shoved a string in yesterday .
13,509
def remove_last_word lineno @list [ lineno ] . chomp! line = @list [ lineno ] lastspace = line . rindex ( " " ) if ! lastspace . nil? lastchars = line [ lastspace + 1 .. - 1 ] @list [ lineno ] . slice! ( lastspace .. - 1 ) $log . debug " remove_last: lastspace #{lastspace},#{lastchars},#{@list[lineno]}" fire_handler :C...
removes and returns last word in given line number or nil if no whitespace
13,510
def move_chars_up oldprow = @current_index oldcurpos = @curpos _maxlen = @maxlen || @width - @internal_width space_left = _maxlen - @buffer . length can_move = [ space_left , next_line . length ] . min carry_up = @list [ @current_index + 1 ] . slice! ( 0 , can_move ) @list [ @current_index ] << carry_up delete_line ( @...
tries to move up as many as possible should not be called if line ends in \ r
13,511
def get_text l = getvalue str = "" old = " " l . each_with_index do | line , i | tmp = line . gsub ( "\n" , "" ) tmp . gsub! ( "\r" , "\n" ) if old [ - 1 , 1 ] !~ / \s / and tmp [ 0 , 1 ] !~ / \s / str << " " end str << tmp old = tmp end str end
def to_s this was just annoying in debugs
13,512
def root node = nil , asks_allow_children = false , & block if @treemodel return @treemodel . root unless node raise ArgumentError , "Root already set" end raise ArgumentError , "root: node cannot be nil" unless node @treemodel = Canis :: DefaultTreeModel . new ( node , asks_allow_children , & block ) end
Sets the given node as root and returns treemodel . Returns root if no argument given . Now we return root if already set Made node nillable so we can return root .
13,513
def select_default_values return if @default_value . nil? raise "list has not yet been created" unless @list index = node_to_row @default_value raise "could not find node #{@default_value}, #{@list} " unless index return unless index @current_index = index toggle_row_selection @default_value = nil end
thanks to shoes not sure how this will impact since widget has text . show default value as selected and fire handler for it This is called in repaint so can raise an error if called on creation or before repaint . Just set
13,514
def node_to_row node crow = nil @list . each_with_index { | e , i | if e == node crow = i break end } crow end
convert a given node to row
13,515
def expand_parents node _path = node . tree_path _path . each do | e | expand_node ( e ) end end
goes up to root of this node and expands down to this node this is often required to make a specific node visible such as in a dir listing when current dir is deep in heirarchy .
13,516
def expand_children node = :current_index $multiplier = 999 if ! $multiplier || $multiplier == 0 node = row_to_node if node == :current_index return if node . children . empty? node . breadth_each ( $multiplier ) do | e | expand_node e end $multiplier = 0 _structure_changed true end
this expands all the children of a node recursively we can t use multiplier concept here since we are doing a preorder enumeration we need to do a breadth first enumeration to use a multiplier
13,517
def sort return unless @model return if @sort_keys . empty? $log . debug "TABULAR SORT KEYS #{sort_keys} " header = @model . delete_at 0 begin @model . sort! { | x , y | res = 0 @sort_keys . each { | ee | e = ee . abs - 1 abse = e . abs if ee < 0 xx = x [ abse ] yy = y [ abse ] if xx . nil? && yy . nil? res = 0 elsif x...
sorts the model based on sort keys and reverse flags
13,518
def toggle_sort_order index index += 1 @sort_keys ||= [ ] if @sort_keys . first && index == @sort_keys . first . abs @sort_keys [ 0 ] *= - 1 else @sort_keys . delete index @sort_keys . delete ( index * - 1 ) @sort_keys . unshift index if @sort_keys . size > 3 @sort_keys . pop end end end
toggle the sort order if given column offset is primary sort key Otherwise insert as primary sort key ascending .
13,519
def convert_value_to_text r str = [ ] fmt = nil field = nil each_column { | c , i | e = r [ c . index ] w = c . width l = e . to_s . length if l > w fmt = "%.#{w}s " else case c . align when :right fmt = "%#{w}s " else fmt = "%-#{w}s " end end field = fmt % e str << field } return str end
Takes the array of row data and formats it using column widths and returns an array which is used for printing
13,520
def render_data pad , lineno , text text = text . join cp = @color_pair att = @attrib if @source . is_row_selected? lineno att = REVERSE end FFI :: NCurses . wattron ( pad , FFI :: NCurses . COLOR_PAIR ( cp ) | att ) FFI :: NCurses . mvwaddstr ( pad , lineno , 0 , text ) FFI :: NCurses . wattroff ( pad , FFI :: NCurses...
passes padded data for final printing or data row this allows user to do row related coloring without having to tamper with the headers or other internal workings . This will not be called if column specific colorign is in effect .
13,521
def check_colors each_column { | c , i | if c . color || c . bgcolor || c . attrib @_check_coloring = true return end @_check_coloring = false } end
check if we need to individually color columns or we can do the entire row in one shot
13,522
def get_column index return @chash [ index ] if @chash [ index ] c = ColumnInfo . new c . index = index @chash [ index ] = c return c end
retrieve the column info structure for the given offset . The offset pertains to the visible offset not actual offset in data model . These two differ when we move a column .
13,523
def content_cols total = 0 each_column { | c , i | w = c . width total += w + 1 } return total end
calculate pad width based on widths of columns
13,524
def fire_column_event eve require 'canis/core/include/ractionevent' aev = TextActionEvent . new self , eve , get_column ( @column_pointer . current_index ) , @column_pointer . current_index , @column_pointer . last_index fire_handler eve , aev end
a column traversal has happened . FIXME needs to be looked into . is this consistent naming wise and are we using the correct object In old system it was TABLE_TRAVERSAL_EVENT
13,525
def _init_model array @chash . clear array . each_with_index { | e , i | c = get_column ( i ) c . width ||= 10 } @column_pointer = Circular . new array . size ( ) - 1 end
size each column based on widths of this row of data . Only changed width if no width for that column
13,526
def model_row index array = @list [ index ] array . each_with_index { | c , i | ch = get_column ( i ) ch . width = c . to_s . length + 2 } @column_pointer = Circular . new array . size ( ) - 1 self end
size each column based on widths of this row of data .
13,527
def save_as outfile _t = "(all rows)" if @selected_indices . size > 0 _t = "(selected rows)" end unless outfile outfile = get_string "Enter file name to save #{_t} as " return unless outfile end l = nil if @selected_indices . size > 0 l = [ ] @list . each_with_index { | v , i | l << v if @selected_indices . include? i ...
save the table as a file
13,528
def delete_at ix return unless @list raise ArgumentError , "Argument must be within 0 and #{@list.length}" if ix < 0 or ix >= @list . length fire_dimension_changed @list . delete_at ( ix ) end
delete a data row at index
13,529
def set_value_at row , col , val actrow = row + @_header_adjustment @list [ actrow , col ] = val fire_row_changed actrow self end
set value at the cell at row and col
13,530
def move_column ix , newix acol = @chash . delete_at ix @chash . insert newix , acol _invalidate_width_cache end
should all this move into table column model or somepn move a column from offset ix to offset newix
13,531
def fire_action_event if header_row? if @table_row_sorter x = _convert_curpos_to_column c = @chash [ x ] index = c . index @table_row_sorter . toggle_sort_order index @table_row_sorter . sort fire_dimension_changed end end super end
called when ENTER is pressed . Takes into account if user is on header_row
13,532
def matching_indices raise "block required for matching_indices" unless block_given? @indices = [ ] @list . each_with_index do | fields , ix | flag = yield ix , fields if flag @indices << ix end end if @indices . count > 0 fire_dimension_changed init_vars else @indices = nil end end
yields each column to caller method if yield returns true collects index of row into array and returns the array
13,533
def render_all if @indices && @indices . count > 0 @indices . each_with_index do | ix , jx | render @pad , jx , @list [ ix ] end else @list . each_with_index { | line , ix | render @pad , ix , line } end end
calls the renderer for all rows of data giving them pad lineno and line data
13,534
def reset! self . base_url = nil self . secure_base_url = nil self . backdrop_sizes = [ ] self . logo_sizes = [ ] self . logo_sizes = [ ] self . poster_sizes = [ ] self . profile_sizes = [ ] self . still_sizes = [ ] self . include_image_language = "en" self end
Reset or nullify all image configurations .
13,535
def valid? ! base_url . nil? && ! secure_base_url . nil? && backdrop_sizes . any? && logo_sizes . any? && poster_sizes . any? && profile_sizes . any? && still_sizes . any? end
Returns a boolean indicating whether the Image configurations are valid or not .
13,536
def lint ( commit = nil ) files = pronto ( commit ) return if files . empty? markdown offenses_message ( files ) end
Runs files through Pronto . Generates a markdown list of warnings .
13,537
def path ( pathname , relative_to = Pathname . pwd ) if pathname path = Pathname ( pathname ) . relative_path_from ( relative_to ) "`#{path}`" else '' end end
The returned path is quoted . If the argument is nil it returns an empty string .
13,538
def labeled ( label , value , justification = 12 ) if value title = "- #{label}:" if value . is_a? ( Enumerable ) lines = [ wrap_string ( title , indentation_level ) ] lines += value . map do | v | wrap_string ( "- #{v}" , indentation_level + 2 ) end puts lines . join ( "\n" ) else string = title . ljust ( justificatio...
Prints a message with a label .
13,539
def info ( message ) indentation = verbose? ? @indentation_level : 0 indented = wrap_string ( message , indentation ) puts ( indented ) if block_given? @indentation_level += 2 @treat_titles_as_messages = true yield @treat_titles_as_messages = false @indentation_level -= 2 end end
Prints an info to the user . The info is always displayed . It respects the current indentation level only in verbose mode .
13,540
def title ( title , verbose_prefix = '' , relative_indentation = 2 ) if @treat_titles_as_messages message ( title , verbose_prefix ) else puts_title ( title , verbose_prefix ) end if block_given? @indentation_level += relative_indentation @title_level += 1 yield @indentation_level -= relative_indentation @title_level -...
A title opposed to a section is always visible
13,541
def message ( message , verbose_prefix = '' , relative_indentation = 2 ) message = verbose_prefix + message if verbose? puts_indented message if verbose? @indentation_level += relative_indentation yield if block_given? @indentation_level -= relative_indentation end
Prints a verbose message taking an optional verbose prefix and a relative indentation valid for the UI action in the passed block .
13,542
def correct_component c raise "Form is still not set in Container" unless @form attach_form ( c ) unless c . form @last_row ||= @row + 1 inset = 2 if @positioning == :stack c . row = @last_row c . col = @col + inset @last_row += 1 elsif @positioning == :relative if ( c . row || 0 ) <= 0 $log . warn "c.row in CONTAINER ...
what of by_name correct coordinates of comp esp if App has stacked them after this container It is best to use the simple stack feature . The rest could change at any time and is quite arbitrary . Some folks may set absolute locations if container is directly on a form others may set relative locations if it is inside ...
13,543
def start ( gui = true ) if gui require 'rtanque/gui' window = RTanque :: Gui :: Window . new ( self . match ) trap ( :INT ) { window . close } window . show else trap ( :INT ) { self . match . stop } self . match . start end end
Starts the match
13,544
def loop & block @form . repaint @window . wrefresh Ncurses :: Panel . update_panels @break_key = ?\C-q . getbyte ( 0 ) while true catch :close do while ( ( ch = @window . getchar ( ) ) != 999 ) if ch == @break_key || ch == @quit_key break end begin if @keyblock str = keycode_tos ch ret = @keyblock . call ( str ) if re...
This method is called by run and thus in most cases this is what is used . + run + calls this without a block not sure but user shuld be able to trap keystrokes if he wants but do i still call handle_key if he does or give him total control . But loop is already called by framework
13,545
def safe_loop & block begin loop & block rescue => ex $log . debug ( "APP.rb rescue reached " ) $log . debug ( ex ) if ex $log . debug ( ex . backtrace . join ( "\n" ) ) if ex ensure close if ex puts "========== EXCEPTION ==========" p ex puts "===============================" puts ( ex . backtrace . join ( "\n" ) ) en...
if calling loop separately better to call this since it will shut off ncurses and print error on screen . UNUSED
13,546
def field_help_text f = @form . get_current_field if f . respond_to? ( 'help_text' ) h = f . help_text h = "No help text defined for this field.\nTry F1, or press '?' for key-bindings." unless h textdialog "#{h}" , :title => "Widget Help Text" else alert "Could not get field #{f} or does not respond to helptext. Try F1...
displays help_text associated with field . 2011 - 10 - 15
13,547
def longest_in_list list longest = list . inject ( 0 ) do | memo , word | memo >= word . length ? memo : word . length end longest end
returns length of longest
13,548
def _resolve_command opts , cmd return cmd if opts . include? cmd matches = opts . grep Regexp . new ( "^#{cmd}" ) end
if partial command entered then returns matches
13,549
def run & block begin @window = Canis :: Window . root_window awin = @window catch ( :close ) do @form = Form . new @window @form . bind_key ( [ ?q , ?q ] , 'quit' ) { throw :close } if $log . debug? $status_message ||= Variable . new $status_message . value = "" if block begin yield_or_eval & block if block_given? loo...
This is the method that is called by all apps usually that define an App block
13,550
def _process_args args , config , block_event , events raise "FIXME seems uncalled _process_args, remove it this does not come up within a month 2014-08-19 " args . each do | arg | case arg when Array row , col , width , height = arg config [ :row ] = row config [ :col ] = col config [ :width ] = width if width config ...
process args all widgets should call this
13,551
def print comp config = @config row = comp . row + comp . height - 1 col = comp . col + 2 len = comp . width - col g = comp . form . window @color_pair ||= get_color ( $datacolor , config [ :color ] , config [ :bgcolor ] ) @attrib ||= config [ :attrib ] || Ncurses :: A_REVERSE ftext = nil if @command_text ftext = text ...
supply a default print function . The user program need not call this . It may be overridden The idea of passing a component at this stage is that one footer can be created for several tables or text components each will pass + self + when calling print .
13,552
def set_layout ( layout ) case layout when Array $log . error "NIL in window constructor" if layout . include? nil raise ArgumentError , "Nil in window constructor" if layout . include? nil @height , @width , @top , @left = * layout raise ArgumentError , "Nil in window constructor" if @top . nil? || @left . nil? @layou...
Creating variables case of array we still create the hash
13,553
def destroy $global_windows . delete self Ncurses :: Panel . del_panel ( @panel . pointer ) if @panel delwin ( ) if @window Ncurses :: Panel . update_panels @pads . each { | pad | FFI :: NCurses . delwin ( pad ) if pad pad = nil } if @pads Window . refresh_all end
destroy window panel and any pads that were requested
13,554
def get_pad content_rows , content_cols pad = FFI :: NCurses . newpad ( content_rows , content_cols ) @pads ||= [ ] @pads << pad return pad end
Widgets can get window to create a pad for them . This way when the window is destroyed it will delete all the pads . A widget wold not be able to do this . The destroy method of the widget will be called .
13,555
def print_border_mb row , col , height , width , color , attr att = get_attrib attr len = width len = Ncurses . COLS - 0 if len == 0 space_char = " " . codepoints . first ( row - 1 ) . upto ( row + height - 1 ) do | r | mvwhline ( r , col , space_char , len ) end mvwaddch row , col , Ncurses :: ACS_ULCORNER mvwhline ( ...
prints the border for message boxes
13,556
def print_border row , col , height , width , color , att = Ncurses :: A_NORMAL raise "height needs to be supplied." if height . nil? raise "width needs to be supplied." if width . nil? att ||= Ncurses :: A_NORMAL ww = width - 2 clr = " " * ww ( row + 1 ) . upto ( row + height - 1 ) do | r | printstring ( r , col + 1 ,...
prints a border around a widget CLEARING the area . If calling with a pad you would typically use 0 0 h - 1 w - 1 . FIXME can this be moved to module Bordertitle ?
13,557
def print_border_only row , col , height , width , color , att = Ncurses :: A_NORMAL if att . nil? att = Ncurses :: A_NORMAL else att = get_attrib att end wattron ( Ncurses . COLOR_PAIR ( color ) | att ) mvwaddch row , col , Ncurses :: ACS_ULCORNER mvwhline ( row , col + 1 , Ncurses :: ACS_HLINE , width - 2 ) mvwaddch ...
print just the border no cleanup + Earlier we would clean up . Now in some cases i d like + to print border over what s been done . XXX this reduces 1 from width but not height !!! FIXME FIXME can this be moved to module Bordertitle ?
13,558
def goto_last_item bc = @buttons . count f = nil @components [ bc .. - 1 ] . each { | c | if c . focusable f = c end } if f leave_current_component @current_component = f set_form_row end end
takes focus to last item
13,559
def goto_next_component if @current_component != nil leave_current_component if on_last_component? @_entered = false return :UNHANDLED end @current_index = @components . index ( @current_component ) index = @current_index + 1 index . upto ( @components . length - 1 ) do | i | f = @components [ i ] if f . focusable @cur...
take focus to the next component or item Called from DOWN RIGHT or Tab
13,560
def goto_prev_component if @current_component != nil leave_current_component if on_first_component? @_entered = false return :UNHANDLED end @current_index = @components . index ( @current_component ) index = @current_index -= 1 index . downto ( 0 ) do | i | f = @components [ i ] if f . focusable @current_index = i @cur...
take focus to prev component or item Called from LEFT UP or Back Tab
13,561
def make_buttons names @action_buttons = [ ] $log . debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} " total = names . inject ( 0 ) { | total , item | total + item . length + 4 } bcol = center_column total brow = @row + @height - 2 brow = FFI :: NCurses . LINES - 2 if brow < 0 $log . debug "XXX:...
actually creates the action buttons
13,562
def handle_key ( ch ) @current_index ||= 0 if ! @editable if ch == KEY_LEFT or ch == KEY_RIGHT return :UNHANDLED end end case @arrow_key_policy when :ignore if ch == KEY_DOWN or ch == KEY_UP return :UNHANDLED end when :popup if ch == KEY_DOWN or ch == KEY_UP popup end end case ch when 32 , KEY_DOWN + META_KEY popup els...
combo edit box key handling removed UP and DOWN and bound it so it can be unbound
13,563
def putc c if c >= 0 and c <= 127 ret = putch c . chr if ret == 0 addcol 1 if @editable set_modified end end return - 1 end
Field putc advances cursor when it gives a char so we override this
13,564
def putch char @current_index ||= 0 if @editable raise "how is it editable here in combo" super return 0 else match = next_match ( char ) text match unless match . nil? fire_handler :ENTER_ROW , self end @modified = true fire_handler :CHANGE , self 0 end
field does not give char to non - editable fields so we override
13,565
def next_match char start = @current_index start . upto ( @list . length - 1 ) do | ix | if @list [ ix ] [ 0 , 1 ] . casecmp ( char ) == 0 return @list [ ix ] unless @list [ ix ] == @buffer end @current_index += 1 end @current_index = 0 start = [ @list . length ( ) - 1 , start ] . min 0 . upto ( start ) do | ix | if @l...
the sets the next match in the edit field
13,566
def choose_file_and_view glob = nil , startdir = "." glob ||= "**/*.rb" str = choose_file glob , :title => "Select a file" , :directory => startdir , :help_text => "Enter pattern, use UP DOWN to traverse, Backspace to delete, ENTER to select. Esc-Esc to quit" if str and str != "" code_browse str end end
this should be available to view also .
13,567
def view_properties_as_tree field = @form . get_current_field alert "Nil field" unless field return unless field text = [ ] tree = { } field . instance_variables . each do | v | val = field . instance_variable_get ( v ) klass = val . class if val . is_a? Array text << { v . to_s => val } val = val . size elsif val . is...
place instance_vars of current or given object into a hash and view in a treedialog .
13,568
def repaint acolor = get_color ( $reversecolor , @color , @bgcolor ) @parent . window . mvwhline ( @row , 1 , Ncurses :: ACS_HLINE , @width ) @parent . window . mvaddch ( @row , 0 , Ncurses :: ACS_LTEE ) @parent . window . mvaddch ( @row , @width + 1 , Ncurses :: ACS_RTEE ) end
2011 - 09 - 25 V1 . 3 . 1
13,569
def select_item ix0 return if @items . nil? or @items . empty? if ! @active_index . nil? @items [ @active_index ] . on_leave end previtem = @active_index @active_index = ix0 if @items [ ix0 ] . enabled @items [ ix0 ] . on_enter else if @active_index > previtem select_next_item else select_prev_item end end @window . re...
recursive if given one not enabled goes to next enabled
13,570
def array_width a longest = a . max { | a , b | a . to_s . length <=> b . to_s . length } longest . to_s . length end
private returns length of longest item in array
13,571
def handle_key ch if ! @current_menu . empty? cmenu = @current_menu . last else cmenu = self end if ! @@menus . empty? cmenu = @@menus . last else cmenu = self end case ch when KEY_DOWN cmenu . select_next_item if cmenu . is_a? Canis :: Menu end when KEY_UP cmenu . select_prev_item when KEY_ENTER , 10 , 13 , 32 return ...
menu LEFT RIGHT DOWN UP ENTER item could be menuitem or another menu
13,572
def set_menu index menu = @items [ @active_index ] menu . on_leave @active_index = index menu = @items [ @active_index ] menu . on_enter @window . wmove menu . row , menu . col end
set the given menu index as the current or active menu after closing the active menu .
13,573
def handle_keys @selected = false @repaint_required = true @toggle_key ||= 27 set_menu 0 begin catch ( :menubarclose ) do while ( ( ch = @window . getchar ( ) ) != @toggle_key ) case ch when - 1 next when KEY_DOWN if ! @selected current_menu . fire else current_menu . handle_key ch end @selected = true when KEY_ENTER ,...
menubar LEFT RIGHT DOWN
13,574
def update_application_key_label ( display_code , new_display_code , text ) @repaint_required = true labels = key_labels ( ) raise "labels are nil !!!" unless labels labels . each_index do | ix | lab = labels [ ix ] next if lab . nil? if lab [ 0 ] == display_code labels [ ix ] = [ new_display_code , text ] $log . debug...
updates existing label with a new one .
13,575
def handle_key ch $log . debug " STACKFLOW handle_key #{ch} " return if @components . empty? _multiplier = ( $multiplier == 0 ? 1 : $multiplier ) unless @_entered $log . warn "XXX WARN: calling ON_ENTER since in this situation it was not called" on_enter end if ch == KEY_TAB $log . debug "STACKFLOW GOTO NEXT TAB" retur...
called by parent or form otherwise its private
13,576
def leave_current_component begin @current_component . on_leave rescue FieldValidationException => fve alert fve . to_s end @current_component . repaint_required true $log . debug " after on_leave STACKFLOW XXX #{@current_component.focussed} #{@current_component.name}" @current_component . repaint end
leave the component we are on . This should be followed by all containers so that the on_leave action of earlier comp can be displayed such as dimming components selections
13,577
def add_to_selection crow = @current_index - @_header_adjustment @last_clicked ||= crow min = [ @last_clicked , crow ] . min max = [ @last_clicked , crow ] . max case @selection_mode when :multiple @widget_scrolled = true if @selected_indices . include? crow min . upto ( max ) { | i | @selected_indices . delete i } lse...
Only for multiple mode . add an item to selection if selection mode is multiple if item already selected it is deselected else selected typically bound to Ctrl - Space
13,578
def list_bindings bind_key ( $row_selector || 32 , 'toggle selection' ) { toggle_row_selection } if @selection_mode == :multiple bind_key ( 0 , 'range select' ) { add_to_selection } bind_key ( ?+ , :ask_select ) bind_key ( ?- , :ask_unselect ) bind_key ( ?a , :select_all ) bind_key ( ?* , :invert_selection ) bind_key (...
mod Applications may call this or just copy and modify
13,579
def add nodechild , allows_children = true , & block $log . debug " XXX def add of DTM #{nodechild} to root " node = @root . add nodechild , allows_children , & block if @handler tme = TreeModelEvent . new ( row , row , :ALL_COLUMNS , self , :INSERT ) fire_handler :TREE_MODEL_EVENT , tme end return node end
add a node to root passing a block optionally
13,580
def undo where raise "not yet used" return unless @delete_buffer case @delete_buffer [ 0 ] when Array @delete_buffer . each do | r | insert where , r end else insert where , @delete_buffer end end
a quick method to undo deletes onto given row . More like paste
13,581
def data = ( data ) raise "not yet used" raise "Data nil or invalid" if data . nil? or data . size == 0 delete_all @data = data tme = TreeModelEvent . new ( 0 , @data . length - 1 , :ALL_COLUMNS , self , :INSERT ) fire_handler :TREE_MODEL_EVENT , tme end
for those quick cases when you wish to replace all the data and not have an event per row being generated
13,582
def add node , allows_children = true , & block raise IllegalStateException , "Cannot add a child to this node" unless @allows_children $log . debug " XXX def add of TreeNode #{node} parent #{self} " case node when Array node . each do | e | add e , allows_children , & block end when Hash node . each_pair { | name , v...
add a node to this node optionally passing a block for further adding add a node as child to existing node If node is not a TreeNode it will be converted to one .
13,583
def user_object_path arr = [ ] arr << self . user_object . to_s traverse_up do | e | arr << e . user_object . to_s end arr . reverse! end
returns an array of user_objects for the current node starting from root ending in the current one . The last node represents this node .
13,584
def say statement , config = { } @window ||= _create_footer_window $log . debug "XXX: inside say win #{@window} !" case statement when Question if config . has_key? :color_pair $log . debug "INSIDE QUESTION 2 " if $log . debug? else $log . debug "XXXX SAY using colorpair: #{statement.color_pair} " if $log . debug? conf...
The basic output method for HighLine objects .
13,585
def say_with_pause statement , config = { } @window ||= _create_footer_window say statement , config @window . wrefresh Ncurses :: Panel . update_panels ch = @window . getchar ( ) hide_bottomline return ch end
display some text at bottom and wait for a key before hiding window
13,586
def say_with_wait statement , config = { } @window ||= _create_footer_window say statement , config @window . wrefresh Ncurses :: Panel . update_panels sleep 0.5 hide_bottomline end
since say does not leave the screen it is not exactly recommended as it will hide what s below . It s better to call pause or this which will quickly go off . If the message is not important enough to ask for a pause the will flicker on screen but not for too long .
13,587
def explain_error ( error ) say_with_pause ( @question . responses [ error ] ) unless error . nil? if @question . responses [ :ask_on_error ] == :question say ( @question ) elsif @question . responses [ :ask_on_error ] say ( @question . responses [ :ask_on_error ] ) end end
A helper method for sending the output stream and error and repeat of the question .
13,588
def print_str ( text , config = { } ) win = config . fetch ( :window , @window ) x = config . fetch :x , 0 y = config . fetch :y , 0 $log . debug "XXX: print_str #{win} with text : #{text} at #{x} #{y} " color = config [ :color_pair ] || $datacolor raise "no window for ask print in #{self.class} name: #{name} " unless...
Internal method for printing a string
13,589
def display_text_interactive text , config = { } require 'canis/core/util/rcommandwindow' ht = config [ :height ] || 15 layout = { :height => ht , :width => Ncurses . COLS - 1 , :top => Ncurses . LINES - ht + 1 , :left => 0 } rc = CommandWindow . new nil , :layout => layout , :box => true , :title => config [ :title ] ...
XXX FIXME this uses only rcommand so what is it doing here .
13,590
def list ( items , mode = :rows , option = nil ) items = items . to_ary . map do | item | ERB . new ( item , nil , "%" ) . result ( binding ) end case mode when :inline option = " or " if option . nil? case items . size when 0 "" when 1 items . first when 2 "#{items.first}#{option}#{items.last}" else items [ 0 .. - 2 ]...
Each member of the _items_ Array is passed through ERb and thus can contain their own expansions . Color escape expansions do not contribute to the final field width .
13,591
def construct_field_tag ( name , value , options = { } ) options [ :name ] = name . to_s use_cdata = options . delete ( :cdata ) return "<field#{options.to_xml_attribute_string}>#{use_cdata ? cdata(value) : value}</field>\n" end
creates xml field for given inputs
13,592
def goto_next_selection return if selected_rows ( ) . length == 0 row = selected_rows ( ) . sort . find { | i | i > @obj . current_index } row ||= @obj . current_index @obj . goto_line row end
after selecting traverse selections forward
13,593
def goto_prev_selection return if selected_rows ( ) . length == 0 row = selected_rows ( ) . sort { | a , b | b <=> a } . find { | i | i < @obj . current_index } row ||= @obj . current_index @obj . goto_line row end
after selecting traverse selections backward
13,594
def remove_row_selection_interval ix0 , ix1 @anchor_selection_index = ix0 @lead_selection_index = ix1 arr = @selected_indices . dup @selected_indices . delete_if { | x | x >= ix0 and x <= ix1 } arr . each { | i | @obj . fire_row_changed ( i ) } lse = ListSelectionEvent . new ( ix0 , ix1 , @obj , :DELETE ) @obj . fire_h...
remove selected indices between given indices inclusive
13,595
def ask_select prompt = "Enter selection pattern: " ret = get_string prompt return if ret . nil? || ret == "" indices = get_matching_indices ret return if indices . nil? || indices . empty? indices . each { | e | add_row_selection_interval e , e } end
Asks user to enter a string or pattern for selecting rows Selects rows based on pattern leaving other selections as - is
13,596
def ask_unselect prompt = "Enter selection pattern: " ret = get_string prompt return if ret . nil? || ret == "" indices = get_matching_indices ret return if indices . nil? || indices . empty? indices . each { | e | remove_row_selection_interval e , e } end
Asks user to enter a string or pattern for UNselecting rows UNSelects rows based on pattern leaving other selections as - is
13,597
def list_bindings @obj . bind_key ( $row_selector || 'v' . ord , 'toggle selection' ) { toggle_row_selection } if @obj . selection_mode == :multiple @obj . bind_key ( $range_selector || 'V' . ord , 'range select' ) { range_select } @obj . bind_key ( ?+ , 'ask_select' ) { ask_select } @obj . bind_key ( ?- , 'ask_unselec...
bindings related to selection
13,598
def item_for widget each do | e | if e . is_a? Item if e . widget == widget return e end end end return nil end
given an widget return the item so we can change weight or some other config
13,599
def print_center ( htext , r = 0 , c = 0 ) win = @window len = win . getmaxx len = Ncurses . COLS - 0 if len == 0 || len > Ncurses . COLS win . printstring r , ( ( len - htext . length ) / 2 ) . floor , htext , @color_pair , @attr end
internal method called by repaint to print text_center in the center