Class: RunnerManager

Inherits:
HinnerSplittedDialogTitled show all
Defined in:
lib/a-core.rb

Overview

class RunnerManager < TkFloatTitledFrame

Defined Under Namespace

Classes: RunnerMangerItem

Constant Summary collapse

ROW_GAP =
25

Instance Attribute Summary collapse

Attributes inherited from HinnerSplittedDialogTitled

#hinner_frame, #titled_frame

Attributes inherited from HinnerSplittedDialog

#frame, #splitter_frame

Instance Method Summary collapse

Methods inherited from HinnerSplittedDialogTitled

#on_close=

Methods inherited from HinnerSplittedDialog

#height

Methods inherited from HinnerDialog

#is_modal?, #make_scrollable_frame, #release, #show_modal

Constructor Details

#initialize(_parent) ⇒ RunnerManager

Returns a new instance of RunnerManager.


1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
# File 'lib/a-core.rb', line 1986

def initialize(_parent)
  super("Runners manager")
  @addb = @titled_frame.add_fixed_button('[Add Runner]',proc{do_add})
  @saveb = @titled_frame.add_fixed_button('[Save]',proc{do_save})

  @items = Hash.new
  @content = Hash.new
  @content_root = Tk::ScrollFrame.new(self.hinner_frame).place('x'=>0, 'y'=>0, 'relheight'=>1, 'relwidth'=>1)
  @content_root_frame = @content_root.baseframe

  #screen_width = TkWinfo.vrootwidth(self.hinner_frame) - 140
  #char_width = 8
  
  font_metrics = TkFont.new(Arcadia.conf('edit.font')).metrics
  screen_width = TkWinfo.vrootwidth(self.hinner_frame) - 140
  font_metrics_hash = {}
  font_metrics.each{|a| font_metrics_hash[a[0]] = a[1] }
  char_width = font_metrics_hash["ascent"] - font_metrics_hash["descent"] - 1
  
  screen_width_in_chars = screen_width.to_f/char_width
   
  #proporzioni
  ext_part = 1
  name_part = 3
  title_part = 4
  cmd_part = 8
  tot_part = ext_part+name_part+title_part+cmd_part
  one_part = screen_width_in_chars/tot_part

  @ext_width = (one_part*ext_part).round
  @name_width = (one_part*name_part).round
  @title_width = (one_part*title_part).round
  @cmd_width = (one_part*cmd_part).round
   
end

Instance Attribute Details

#cmd_widthObject (readonly)

Returns the value of attribute cmd_width


1807
1808
1809
# File 'lib/a-core.rb', line 1807

def cmd_width
  @cmd_width
end

#ext_widthObject (readonly)

Returns the value of attribute ext_width


1807
1808
1809
# File 'lib/a-core.rb', line 1807

def ext_width
  @ext_width
end

#name_widthObject (readonly)

Returns the value of attribute name_width


1807
1808
1809
# File 'lib/a-core.rb', line 1807

def name_width
  @name_width
end

#title_widthObject (readonly)

Returns the value of attribute title_width


1807
1808
1809
# File 'lib/a-core.rb', line 1807

def title_width
  @title_width
end

Instance Method Details

#add_gapObject


2051
2052
2053
2054
2055
2056
2057
2058
# File 'lib/a-core.rb', line 2051

def add_gap
  #p @content_root.y_scrolled?
  root_height = Arcadia.instance.root_height
  if self.height < root_height/2
    self.height(self.height + ROW_GAP)
    @content_root.vscroll(true) if !@content_root.y_scrolled?
  end
end

#clear_itemsObject


2112
2113
2114
2115
2116
2117
2118
# File 'lib/a-core.rb', line 2112

def clear_items
  @items.each_value{|i| 
    i.each_value{|j|  j.destroy }
    i.clear
  }
  #@items.clear
end

#del_gapObject


2060
2061
2062
# File 'lib/a-core.rb', line 2060

def del_gap
  self.height(self.height - ROW_GAP)
end

#do_add(_runner_from = nil) ⇒ Object


2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
# File 'lib/a-core.rb', line 2035

def do_add(_runner_from=nil)
  if _runner_from
    runner_hash = _runner_from.hash_value
    runner_hash[:name]="copy of #{runner_hash[:name]}"
  else
    runner_hash = {}
  end
  @items[:config]["item#{@items[:config].count}"]=RunnerMangerItem.new(self, @content[:config], runner_hash, @items[:config].count+1)
 # @content[:config].pack
#    root_height = Arcadia.instance.root_height
#    
#    self.height(self.height + ROW_GAP) if self.height < root_height
  add_gap
  @content_root.yview_moveto('1.0')
end

#do_closeObject


2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
# File 'lib/a-core.rb', line 2022

def do_close
  if something_has_changed?
    if Arcadia.dialog(self,
      'type'=>'yes_no',
      'msg'=> Arcadia.text("main.d.confirm_exit_runners_manager.msg"),
      'title' => Arcadia.text("main.d.confirm_exit_runners_manager.title"),
      'level' => 'question')!='yes'
      return
    end
  end
  super()
end

#do_delete_item(_item, _tyme = :config) ⇒ Object


2064
2065
2066
2067
2068
# File 'lib/a-core.rb', line 2064

def do_delete_item(_item, _tyme=:config)
  @items[:config].delete_if{|k,v| v == _item}
  del_gap
  #self.height(self.height - ROW_GAP)
end

#do_saveObject


2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
# File 'lib/a-core.rb', line 2082

def do_save
  items_saved = []
  @items.each_value{|i| 
    i.each_value{|j| 
      if !j.readonly && j.change?
        jhash = j.hash_value 
        name = jhash[:name].gsub(" ", "_")
        Arcadia.conf("runners.#{name}", jhash.to_s)
        j.reset_change
        items_saved << name
      end
    }
  }
  Arcadia.instance.update_local_config
  Arcadia.instance.reload_runners
  if items_saved.count >0
    Arcadia.dialog(self, 
      'type'=>'ok', 
      'title' => "Save info", 
          'msg'=>"Saved #{items_saved.to_s}!",
          'level'=>'info')
  else
    Arcadia.dialog(self, 
      'type'=>'ok', 
      'title' => "Save info", 
          'msg'=>"Nothing done!",
          'level'=>'info')
  end
end

#load_items(_kind = :runtime) ⇒ Object


2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
# File 'lib/a-core.rb', line 2172

def load_items(_kind = :runtime)
  items = @items[_kind]
  if items.nil?
    items = @items[_kind] = Hash.new
  end
  if _kind == :runtime
    runs_pers=Arcadia.pers_group('runners', true)
    runs = {}
    runs_pers.each{|k, v|
      runs[k]="#{v}|||runtime"
    }
  elsif _kind == :config
    runs_with_local=Arcadia.conf_group('runners', true)
    runs_without_local = Arcadia.conf_group_without_local('runners', false)
    runs = {}

    # loading extensions runners
    Arcadia.extensions.each{|ext|
      ext_runs = Arcadia.conf_group("#{ext}.runners", true)
      if ext_runs && !ext_runs.empty?
        ext_runs_enanched = {}
        ext_runs.each{|k, v|
          ext_runs_enanched[k]="#{v}|||#{ext}"
        }
        runs.update(ext_runs_enanched)
      end
    }      
    
    # loading main runners
    runs_with_local.each{|k,v|
      if runs_without_local.include?(k)
        runs[k]="#{v}|||main"
      else
        runs[k]=v
      end
    }
    
  end
  @content[_kind] = Arcadia.wf.frame(@content_root_frame){padding "3 3 12 12"}

  @content[_kind].pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
 
 
  #@content.extend(TkScrollableWidget).show
  # ICON
  TkGrid.columnconfigure(@content[_kind], 0, :weight => 0 , :uniform => 'a')
  # NAME
  TkGrid.columnconfigure(@content[_kind], 1, :weight => 1 )
  # TITLE
  TkGrid.columnconfigure(@content[_kind], 2, :weight => 2 )
  # CMD
  TkGrid.columnconfigure(@content[_kind], 3, :weight => 3 )
  # FILE EXTS
  TkGrid.columnconfigure(@content[_kind], 4, :weight => 1 )
  # COPY BUTTON
  TkGrid.columnconfigure(@content[_kind], 5, :weight => 0, :uniform => 'a' )
  # DELETE BUTTON
  TkGrid.columnconfigure(@content[_kind], 6, :weight => 0, :uniform => 'a' )
  TkGrid.propagate(@content[_kind], true)
  load_titles(@content[_kind])
  runs.keys.reverse.each{|name|
    hash_string = runs[name]
    hash_string, origin = hash_string.split("|||")
    item_hash = eval hash_string
    item_hash[:name]=name
    if item_hash[:runner] && Arcadia.runner(item_hash[:runner])
      item_hash = Hash.new.update(Arcadia.runner(item_hash[:runner])).update(item_hash)
    end
    if origin
      item_hash[:origin] = origin
      state_array = [] << :disabled
    end
    items[name]=RunnerMangerItem.new(self, @content[_kind], item_hash, items.count+1, state_array)
    #self.height(self.height + ROW_GAP)
    add_gap
 }
end

#load_tipsObject


2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
# File 'lib/a-core.rb', line 2120

def load_tips
  # Runners keywords related the current file => <<FILE>>, <<DIR>>, <<FILE_BASENAME>>, <<FILE_BASENAME_WITHOUT_EXT>>, <<INPUT>>, <<INPUT_FILE>>
  # INPUT is required to user
  text = Arcadia.wf.text(@content_root_frame,
            "height" => 2,
            "bg" => '#009999'  
         )
  text.pack('side' =>'top','anchor'=>'nw','fill'=>'x','padx'=>5, 'pady'=>5)
  text.insert("end", "Keywords => <<RUBY>>, <<FILE>>, <<DIR>>, <<FILE_BASENAME>>, <<FILE_BASENAME_WITHOUT_EXT>>, <<INPUT_FILE>>, <<INPUT_DIR>>, <<INPUT_STRING>>")
  add_gap
  #self.height(self.height + ROW_GAP)
end

#load_titles(_content) ⇒ Object


2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
# File 'lib/a-core.rb', line 2133

def load_titles(_content)
  bg = Arcadia.conf("titlelabel.background")
  fg = Arcadia.conf("titlelabel.foreground")
#    # ICON
#    Arcadia.wf.label(_content,
#      'text'=> "" ,
#      'background'=> bg,
#      'relief'=>'flat').grid(:column => 0, :row => 0, :sticky => "WE", :padx=>1, :pady=>1)

  # NAME
  Arcadia.wf.label(_content,
    'text'=> "Name",
    'background'=> bg,
    'foreground'=> fg,
    'relief'=>'flat').grid(:column => 1, :row => 0, :sticky => "WE", :padx=>1, :pady=>1)


  # TITLE
  Arcadia.wf.label(_content,
    'text'=> "Title" ,
    'background'=> bg,
    'foreground'=> fg,
    'relief'=>'flat').grid(:column => 2, :row => 0, :sticky => "WE", :padx=>1, :pady=>1)

  # CMD
  Arcadia.wf.label(_content,
    'text'=> "CMD" ,
    'background'=> bg,
    'foreground'=> fg,
    'relief'=>'flat').grid(:column => 3, :row => 0, :sticky => "WE", :padx=>1, :pady=>1)
  
  # FILE EXTS
  Arcadia.wf.label(_content,
    'text'=> "Exts" ,
    'background'=> bg,
    'foreground'=> fg,
    'relief'=>'flat').grid(:column => 4, :row => 0, :sticky => "WE", :padx=>1, :pady=>1)
end

#something_has_changed?Boolean

Returns:

  • (Boolean)

2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
# File 'lib/a-core.rb', line 2070

def something_has_changed?
  ret = false
  @items.each_value{|i|
    i.each_value{|j| 
      ret = ret || (!j.readonly && j.change?)
      break if ret
    }
    break if ret
  }
  ret 
end