<commit_before>module RAutomation
  module Adapter
    module MsUia
      class Control
        include WaitHelper
        include Locators

        # Creates the control object.
        # @note this method is not meant to be accessed directly
        # @param [RAutomation::Window] window this button belongs to.
        # @param [Hash] locators for searching the button.
        # @option locators [String, Regexp] :value Value (text) of the button
        # @option locators [String, Regexp] :class Internal class name of the button
        # @option locators [String, Fixnum] :id Internal ID of the button
        # @option locators [String, Fixnum] :index 0-based index to specify n-th button if all other criteria match
        # @see RAutomation::Window#button
        def initialize(window, locators)
          @window = window
          extract(locators)
        end

        #todo - replace with UIA version
        def hwnd
          Functions.control_hwnd(@window.hwnd, @locators)
        end

        def uia_element
#          puts "finding element with #{@locators.inspect}"

          case
            #Causes a bug for some reason
#            when @locators[:value]
#              uia_window = UiaDll::element_from_handle(@window.hwnd)
#              begin
#                uia_window.read_pointer
#              rescue FFI::NullPointerError => e
#                raise UnknownElementException, "Window with handle #{@window.hwnd} does not exist"
#              end
#              uia_control = UiaDll::find_child_by_name(uia_window, @locators[:value].to_s)
#              begin
#                uia_control.read_pointer
#              rescue FFI::NullPointerError => e
#                raise UnknownElementException, "#{@locators[:value]} does not exist"
#              end
            when @locators[:focus]
              uia_control = UiaDll::get_focused_element
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "Focused element does not exist"
              end
            when @locators[:id]
              uia_window = UiaDll::element_from_handle(@window.hwnd)
              uia_control = UiaDll::find_child_by_id(uia_window, @locators[:id].to_s)
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "#{@locators[:id]} does not exist"
              end
            when @locators[:point]
              uia_control = UiaDll::element_from_point(@locators[:point][0], @locators[:point][1])
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "#{@locators[:point]} does not exist"
              end<commit_msg>remove commented out code in MsUia::Control<commit_after>module RAutomation
  module Adapter
    module MsUia
      class Control
        include WaitHelper
        include Locators

        # Creates the control object.
        # @note this method is not meant to be accessed directly
        # @param [RAutomation::Window] window this button belongs to.
        # @param [Hash] locators for searching the button.
        # @option locators [String, Regexp] :value Value (text) of the button
        # @option locators [String, Regexp] :class Internal class name of the button
        # @option locators [String, Fixnum] :id Internal ID of the button
        # @option locators [String, Fixnum] :index 0-based index to specify n-th button if all other criteria match
        # @see RAutomation::Window#button
        def initialize(window, locators)
          @window = window
          extract(locators)
        end

        #todo - replace with UIA version
        def hwnd
          Functions.control_hwnd(@window.hwnd, @locators)
        end

        def uia_element
          case
            when @locators[:focus]
              uia_control = UiaDll::get_focused_element
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "Focused element does not exist"
              end
            when @locators[:id]
              uia_window = UiaDll::element_from_handle(@window.hwnd)
              uia_control = UiaDll::find_child_by_id(uia_window, @locators[:id].to_s)
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "#{@locators[:id]} does not exist"
              end
            when @locators[:point]
              uia_control = UiaDll::element_from_point(@locators[:point][0], @locators[:point][1])
              begin
                uia_control.read_pointer
              rescue FFI::NullPointerError => e
                raise UnknownElementException, "#{@locators[:point]} does not exist"
              end
{'fraction_non_alphanumeric': 0.07806841046277666, 'fraction_numerical': 0.0012072434607645875, 'mean_word_length': 1.9837935174069627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1071441', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1313, 'n_words': 373}