Class: RunnerManager::RunnerMangerItem

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

Overview

< TkFrame

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_runner_manager, _parent = nil, _runner_hash = nil, _row = 0, _state_array = nil, *args) ⇒ RunnerMangerItem

Returns a new instance of RunnerMangerItem.



1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
# File 'lib/a-core.rb', line 1810

def initialize(_runner_manager, _parent=nil, _runner_hash=nil, _row=0, _state_array=nil, *args)
  #super(_parent, Arcadia.style('panel'))
  @runner_hash = _runner_hash
  @readonly = _state_array && _state_array.include?(:disabled)
  @enable_close_button = !@readonly || _runner_hash[:origin] == 'runtime'
  
  @h_hash = {}
        
  p_update_height = proc{|tktext|
    index = tktext.index('end -1 chars')
    r,c = index.split('.')
    if tktext.cget('wrap') != 'none'
      w = tktext.width
      h = ((c.to_i-1)/w.to_i).round + 1
    else
      h = r.to_i
    end
    h_to_set = h
    @h_hash.each{|k,v|  h_to_set = v if k != tktext && v > h_to_set }
    @h_hash[tktext] = h
    if tktext.height != h_to_set
      tktext.height(h_to_set)
      @h_hash.each{|k,v|
        p_update_height.call(k) if k != tktext
      }
      
    end
  }

  row_fill = false

  # ICON
  @ttklicon = Arcadia.wf.label(_parent,
    'image'=> _runner_hash[:image].nil? ? Arcadia.file_icon(_runner_hash[:file_exts]) : Arcadia.image_res(_runner_hash[:image]) ,
    'relief'=>'flat').grid(:column => 0, :row => _row, :sticky => "W", :padx=>1, :pady=>1)
  @ttklicon.state(:disabled) if @readonly

  # NAME
  @ename_old = _runner_hash[:name]  
  @ttkename = Arcadia.wf.text(_parent, 'width' => _runner_manager.name_width,
    "height" => 1).hint(_runner_hash[:file]).grid(:column => 1, :row => _row, :sticky => "WE", :padx=>1, :pady=>1)
  @ttkename.insert('end', _runner_hash[:name])
  @ttkename.state(:disabled) && @ttkename.fg('darkgray') if @readonly
  
  row_fill = row_fill || @ttkename.value.strip.length > 0

  # TITLE
  @etitle_old = _runner_hash[:title]  
  @ttketitle = Arcadia.wf.text(_parent, 'width' => _runner_manager.title_width,
    "height" => 1).hint(_runner_hash[:file]).grid(:column => 2, :row => _row, :sticky => "WE", :padx=>1, :pady=>1)
  @ttketitle.insert('end', _runner_hash[:title])
  @ttketitle.state(:disabled) && @ttketitle.fg('darkgray') if @readonly

  row_fill = row_fill || @ttketitle.value.strip.length > 0

  # CMD
  @ecmd_old = _runner_hash[:cmd]
  @ttkecmd = Arcadia.wf.text(_parent,  'width' => _runner_manager.cmd_width, 'wrap'=>'word',
    "height" => 1).grid(:column => 3, :row => _row, :sticky => "WE", :padx=>1, :pady=>1)
  @ttkecmd.insert('end', _runner_hash[:cmd])
  @ttkecmd.state(:disabled) && @ttkecmd.fg('darkgray') if @readonly

  row_fill = row_fill || @ttkecmd.value.strip.length > 0
  
  # FILE EXTS
  @eexts_old = _runner_hash[:file_exts]  
  @ttkeexts = Arcadia.wf.text(_parent,  'width' => _runner_manager.ext_width,
    "height" => 1).grid(:column => 4, :row => _row, :sticky => "WE", :padx=>1, :pady=>1)
  @ttkeexts.insert('end', _runner_hash[:file_exts])
  @ttkeexts.state(:disabled) && @ttkeexts.fg('darkgray') if @readonly

  row_fill = row_fill || @ttkeexts.value.strip.length > 0

  # COPY BUTTON
  copy_command = proc{ _runner_manager.do_add(self) }
  @ttkbcopy = Arcadia.wf.toolbutton(_parent,
    'command'=> copy_command,
    'image'=> Arcadia.image_res(COPY_GIF)
  ).grid(:column => 5, :row => _row, :sticky => "W", :padx=>1, :pady=>1)
    
  # DELETE BUTTON
  close_command = proc{
    if (Arcadia.hinner_dialog(self, 'type'=>'yes_no',
      'msg'=> Arcadia.text("main.d.confirm_delete_runner.msg", [_runner_hash[:name]]),
      'title' => Arcadia.text("main.d.confirm_delete_runner.title"),
      'level' => 'question')=='yes')

      if _runner_hash[:origin] == 'runtime'
        Arcadia.unpersistent("runners.#{_runner_hash[:name]}")
      else
        Arcadia.del_conf("runners.#{_runner_hash[:name]}")
      end
      mr = Arcadia.menu_root('runcurr')
      index_to_delete = -1
      i_end = mr.index('end')
      if i_end
        0.upto(i_end){|j|
          type = mr.menutype(j)
          if type != 'separator'
            l = mr.entrycget(j,'label')
            if l == _runner_hash[:title]
              index_to_delete = j
              break
            end
          end
        }
      end
      if index_to_delete > -1
        mr.delete(index_to_delete)
      end
      _runner_manager.do_delete_item(self)
      self.destroy
    end
  }
  @ttkbclose = Arcadia.wf.toolbutton(_parent,
    'command'=> close_command,
    'image'=> Arcadia.image_res(CLOSE_FRAME_GIF)
    ).grid(:column => 6, :row => _row, :sticky => "W", :padx=>1, :pady=>1)
  @ttkbclose.hint=@runner_hash[:file]
  @ttkbclose.state(:disabled) if !@enable_close_button

  [@ttkename, @ttketitle, @ttkecmd, @ttkeexts].each{|tktext|
    p_update_height.call(tktext) if row_fill
    tktext.bind_append("KeyRelease"){p_update_height.call(tktext)}
  }

end

Instance Attribute Details

#readonlyObject (readonly)

Returns the value of attribute readonly.



1809
1810
1811
# File 'lib/a-core.rb', line 1809

def readonly
  @readonly
end

#runner_hashObject (readonly)

Returns the value of attribute runner_hash.



1809
1810
1811
# File 'lib/a-core.rb', line 1809

def runner_hash
  @runner_hash
end

Instance Method Details

#change?Boolean

Returns:

  • (Boolean)


1974
1975
1976
# File 'lib/a-core.rb', line 1974

def change?
  title_change? || cmd_change? || exts_change? || exts_change? || name_change?
end

#cmd_change?Boolean

Returns:

  • (Boolean)


1966
1967
1968
# File 'lib/a-core.rb', line 1966

def cmd_change?
  @ecmd_old != @ttkecmd.value
end

#destroyObject



1938
1939
1940
1941
1942
1943
1944
1945
1946
# File 'lib/a-core.rb', line 1938

def destroy
  @ttklicon.destroy
  @ttkename.destroy
  @ttketitle.destroy
  @ttkecmd.destroy
  @ttkeexts.destroy
  @ttkbcopy.destroy
  @ttkbclose.destroy
end

#exts_change?Boolean

Returns:

  • (Boolean)


1970
1971
1972
# File 'lib/a-core.rb', line 1970

def exts_change?
  @eexts_old != @ttkeexts.value
end

#hash_valueObject



1948
1949
1950
1951
1952
1953
1954
1955
1956
# File 'lib/a-core.rb', line 1948

def hash_value
  ret = {}
  ret[:name]=@ttkename.value
  ret[:title]=@ttketitle.value
  ret[:cmd]=@ttkecmd.value
  ret[:file_exts]=@ttkeexts.value
  ret[:image]=@runner_hash[:image] if @runner_hash[:image] 
  ret  
end

#name_change?Boolean

Returns:

  • (Boolean)


1958
1959
1960
# File 'lib/a-core.rb', line 1958

def name_change?
  @ename_old != @ttkename.value
end

#reset_changeObject



1978
1979
1980
1981
1982
1983
# File 'lib/a-core.rb', line 1978

def reset_change
  @ename_old = @ttkename.value
  @etitle_old = @ttketitle.value
  @ecmd_old = @ttkecmd.value
  @eexts_old = @ttkeexts.value
end

#title_change?Boolean

Returns:

  • (Boolean)


1962
1963
1964
# File 'lib/a-core.rb', line 1962

def title_change?
  @etitle_old != @ttketitle.value
end