Sha256: 8d998e1b12c529f6e02825f49559474138c923e5cd23e07347420e85e2583a87

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# 
# Some parts are
# Copyright 2004-2007, wxRuby development team
# released under the MIT-like wxRuby2 license

# Bottom-up implementation of a Directory lister

class Wx::GenericDirCtrl
  module DirCtrlTree 
    # The TreeCtrl contained in a GenericDirCtrl already has C++ data
    # associated with the items. If these are returned to Ruby crashes
    # will result. So this module sets the TreeCtrl to return the path
    # string.
    def get_item_data(tree_id)
      root_id = get_root_item
      return "" if tree_id == root_id

      path = item_text(tree_id)
      while tree_id = item_parent(tree_id) and tree_id != root_id
        path = item_text(tree_id) + "/#{path}" 
      end
      unless Wx::PLATFORM == 'WXMSW'
        path = "/" + path
      end
      path
    end

    alias :get_item_path :get_item_data

    # Not allowed
    def set_item_data(tree_id, data)
      Kernel.raise "Item data cannot be set for a GenericDirCtrl's Tree"
    end
  end
  
  wx_get_tree_ctrl = instance_method(:get_tree_ctrl)
  define_method(:get_tree_ctrl) do 
    tree = wx_get_tree_ctrl.bind(self).call
    tree.extend(DirCtrlTree)
    tree
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wxruby3-0.9.7-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.5-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.4-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.3-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.2-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.1-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb
wxruby3-0.9.0-x64-mingw-ucrt lib/wx/core/genericdirctrl.rb