<commit_before>/*
 * 0xor1  http://github.com/0xor1
 */


part of controls_and_panels;


class ContextMenuUsage{


  static bool _initialised = false;


  static ContextMenu _currentContextMenu;


  static Control _currentTarget;
  static int _targetMouseOffsetX;
  static int _targetMouseOffsetY;


  //for nested parent child controls to add creators to
  static List<List<Button>> _buttonGroups = new List<List<Button>>();

  //for inherited parent child controls to add creators to
  final List<Func_Control_List_t_Button_t> contextMenuButtonCreators = new List<Func_Control_List_t_Button_t>();


  void initialiseContextMenuUsage(Func_Control_List_t_Button_t itemCreators){

    _initialise();

    contextMenuButtonCreators.add(itemCreators);

    //only add the event listener once
    if(contextMenuButtonCreators.length == 1){
      (this as Control).html.onContextMenu.listen((MouseEvent event){
        if(_currentTarget == null){
          _currentTarget = this as Control;
          _targetMouseOffsetX = event.offsetX;
          _targetMouseOffsetY = event.offsetY;
        }
        for(var buttonListCreator in contextMenuButtonCreators){
          _buttonGroups.add(buttonListCreator(this));
        }
      });
    }
  }

  static void _initialise(){

    if(!_initialised){

      _initialised = true;

      var closeCurrentContextMenu = (){

        if(_currentContextMenu != null){

          _currentContextMenu.hide();

        }

      };

      window.onContextMenu.listen((MouseEvent event){

        closeCurrentContextMenu();

        if(_buttonGroups.length > 0){

          event.preventDefault();

          _currentContextMenu = new ContextMenu(_buttonGroups)
          ..show(_currentTarget, left:_targetMouseOffsetX, top: _targetMouseOffsetY );

          _currentTarget = null;

          _buttonGroups.clear();

        }<commit_msg>reset _currentContextMenu after close<commit_after>/*
 * 0xor1  http://github.com/0xor1
 */


part of controls_and_panels;


class ContextMenuUsage{


  static bool _initialised = false;


  static ContextMenu _currentContextMenu;


  static Control _currentTarget;
  static int _targetMouseOffsetX;
  static int _targetMouseOffsetY;


  //for nested parent child controls to add creators to
  static List<List<Button>> _buttonGroups = new List<List<Button>>();

  //for inherited parent child controls to add creators to
  final List<Func_Control_List_t_Button_t> contextMenuButtonCreators = new List<Func_Control_List_t_Button_t>();


  void initialiseContextMenuUsage(Func_Control_List_t_Button_t itemCreators){

    _initialise();

    contextMenuButtonCreators.add(itemCreators);

    //only add the event listener once
    if(contextMenuButtonCreators.length == 1){
      (this as Control).html.onContextMenu.listen((MouseEvent event){
        if(_currentTarget == null){
          _currentTarget = this as Control;
          _targetMouseOffsetX = event.offsetX;
          _targetMouseOffsetY = event.offsetY;
        }
        for(var buttonListCreator in contextMenuButtonCreators){
          _buttonGroups.add(buttonListCreator(this));
        }
      });
    }
  }

  static void _initialise(){

    if(!_initialised){

      _initialised = true;

      var closeCurrentContextMenu = (){

        if(_currentContextMenu != null){

          _currentContextMenu.hide();

          _currentContextMenu = null;

        }

      };

      window.onContextMenu.listen((MouseEvent event){

        closeCurrentContextMenu();

        if(_buttonGroups.length > 0){

          event.preventDefault();

          _currentContextMenu = new ContextMenu(_buttonGroups)
          ..show(_currentTarget, left:_targetMouseOffsetX, top: _targetMouseOffsetY );

          _currentTarget = null;

          _buttonGroups.clear();

        }
{'fraction_non_alphanumeric': 0.08624769918485406, 'fraction_numerical': 0.003155403628714173, 'mean_word_length': 3.0815450643776825, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '799087', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1026, 'n_words': 227}