Sha256: e185dd6afad715a0162cd50a76883c03bb6e3a6a1d17297f91fdee71e7e49200

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 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)
  wx_redefine_method(:get_tree_ctrl) do 
    tree = wx_get_tree_ctrl.bind(self).call
    tree.extend(DirCtrlTree)
    tree
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wxruby3-1.5.1 lib/wx/core/genericdirctrl.rb
wxruby3-1.5.0 lib/wx/core/genericdirctrl.rb
wxruby3-1.4.2 lib/wx/core/genericdirctrl.rb
wxruby3-1.4.1 lib/wx/core/genericdirctrl.rb
wxruby3-1.4.0 lib/wx/core/genericdirctrl.rb