<commit_before>////////////////////////////////////////////////////////////////////////////////
// Name:      dirctrl.cpp
// Purpose:   Implementation of class 'wxExGenericDirCtrl'
// Author:    <NAME>
// Created:   2010-08-16
// RCS-ID:    $Id$
// Copyright: (c) 2010 <NAME>
////////////////////////////////////////////////////////////////////////////////

#include <wx/stockitem.h> // for wxGetStockLabel
#include <wx/extension/frame.h>
#include <wx/extension/menu.h>
#include <wx/extension/textfile.h>
#include <wx/extension/util.h>
#include <wx/extension/vcs.h>
#include <wx/extension/report/dirctrl.h>
#include <wx/extension/report/defs.h>
#include <wx/extension/report/frame.h>
#include <wx/extension/report/util.h>

#if wxUSE_DIRDLG

BEGIN_EVENT_TABLE(wxExGenericDirCtrl, wxGenericDirCtrl)
  EVT_MENU_RANGE(
    ID_EDIT_VCS_LOWEST, 
    ID_EDIT_VCS_HIGHEST, 
    wxExGenericDirCtrl::OnCommand)
  EVT_MENU_RANGE(ID_TREE_OPEN, ID_TREE_RUN_MAKE, wxExGenericDirCtrl::OnCommand)
  EVT_TREE_ITEM_ACTIVATED(wxID_TREECTRL, wxExGenericDirCtrl::OnTree)
  EVT_TREE_ITEM_RIGHT_CLICK(wxID_TREECTRL, wxExGenericDirCtrl::OnTree)
END_EVENT_TABLE()

wxExGenericDirCtrl::wxExGenericDirCtrl(
  wxWindow *parent, 
  wxExFrameWithHistory* frame,
  const wxWindowID id, 
  const wxPoint &pos, 
  const wxSize &size, 
  long style, 
  const wxString &filter, 
  int defaultFilter, 
  const wxString &name)
  : wxGenericDirCtrl(
      parent,
      id,
      wxFileName(frame->GetRecentFile()).GetFullPath(),
      pos,
      size,
      style,
      filter,
      defaultFilter,
      name)
  , m_Frame(frame)
{
}

void wxExGenericDirCtrl::OnCommand(wxCommandEvent& event)
{
  wxArrayString files;
  GetFilePaths(files);
    
  if (event.GetId() > ID_EDIT_VCS_LOWEST && 
      event.GetId() < ID_EDIT_VCS_HIGHEST)
  {
    wxExVCSExecute(m_Frame, event.GetId(), files);
  }
  else switch (event.GetId())
  {
  case ID_TREE_COPY: 
    {
    wxBusyCursor wait;
    wxString clipboard;
    for (
      auto it = files.begin();
      it != files.end();
      it++)
    {
      clipboard += *it + wxTextFile::GetEOL();
    }
    wxExClipboardAdd(clipboard);
    }
  break;
  
  case ID_TREE_OPEN: 
    wxExOpenFiles(m_Frame, files, 0, wxDIR_FILES); // only files in this dir
  break;
  
  case ID_TREE_RUN_MAKE: 
    wxExMake(m_Frame, files[0]);
    break;
    
  default: wxFAIL;
  }
}

void wxExGenericDirCtrl::OnTree(wxTreeEvent& event)
{
  wxArrayString files;
  GetFilePaths(files);

  if (files.empty()) 
  {
    event.Skip();
    return;
  }

  if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK)
  {
    wxExMenu menu;
    menu.Append(ID_TREE_OPEN, _("&Open"));
    menu.AppendSeparator();<commit_msg>used better event type for menu<commit_after>////////////////////////////////////////////////////////////////////////////////
// Name:      dirctrl.cpp
// Purpose:   Implementation of class 'wxExGenericDirCtrl'
// Author:    <NAME>
// Created:   2010-08-16
// RCS-ID:    $Id$
// Copyright: (c) 2010 <NAME>
////////////////////////////////////////////////////////////////////////////////

#include <wx/stockitem.h> // for wxGetStockLabel
#include <wx/extension/frame.h>
#include <wx/extension/menu.h>
#include <wx/extension/textfile.h>
#include <wx/extension/util.h>
#include <wx/extension/vcs.h>
#include <wx/extension/report/dirctrl.h>
#include <wx/extension/report/defs.h>
#include <wx/extension/report/frame.h>
#include <wx/extension/report/util.h>

#if wxUSE_DIRDLG

BEGIN_EVENT_TABLE(wxExGenericDirCtrl, wxGenericDirCtrl)
  EVT_MENU_RANGE(
    ID_EDIT_VCS_LOWEST, 
    ID_EDIT_VCS_HIGHEST, 
    wxExGenericDirCtrl::OnCommand)
  EVT_MENU_RANGE(ID_TREE_OPEN, ID_TREE_RUN_MAKE, wxExGenericDirCtrl::OnCommand)
  EVT_TREE_ITEM_ACTIVATED(wxID_TREECTRL, wxExGenericDirCtrl::OnTree)
  EVT_TREE_ITEM_MENU(wxID_TREECTRL, wxExGenericDirCtrl::OnTree)
END_EVENT_TABLE()

wxExGenericDirCtrl::wxExGenericDirCtrl(
  wxWindow *parent, 
  wxExFrameWithHistory* frame,
  const wxWindowID id, 
  const wxPoint &pos, 
  const wxSize &size, 
  long style, 
  const wxString &filter, 
  int defaultFilter, 
  const wxString &name)
  : wxGenericDirCtrl(
      parent,
      id,
      wxFileName(frame->GetRecentFile()).GetFullPath(),
      pos,
      size,
      style,
      filter,
      defaultFilter,
      name)
  , m_Frame(frame)
{
}

void wxExGenericDirCtrl::OnCommand(wxCommandEvent& event)
{
  wxArrayString files;
  GetFilePaths(files);
    
  if (event.GetId() > ID_EDIT_VCS_LOWEST && 
      event.GetId() < ID_EDIT_VCS_HIGHEST)
  {
    wxExVCSExecute(m_Frame, event.GetId(), files);
  }
  else switch (event.GetId())
  {
  case ID_TREE_COPY: 
    {
    wxBusyCursor wait;
    wxString clipboard;
    for (
      auto it = files.begin();
      it != files.end();
      it++)
    {
      clipboard += *it + wxTextFile::GetEOL();
    }
    wxExClipboardAdd(clipboard);
    }
  break;
  
  case ID_TREE_OPEN: 
    wxExOpenFiles(m_Frame, files, 0, wxDIR_FILES); // only files in this dir
  break;
  
  case ID_TREE_RUN_MAKE: 
    wxExMake(m_Frame, files[0]);
    break;
    
  default: wxFAIL;
  }
}

void wxExGenericDirCtrl::OnTree(wxTreeEvent& event)
{
  wxArrayString files;
  GetFilePaths(files);

  if (files.empty()) 
  {
    event.Skip();
    return;
  }

  if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_MENU)
  {
    wxExMenu menu;
    menu.Append(ID_TREE_OPEN, _("&Open"));
    menu.AppendSeparator();
{'fraction_non_alphanumeric': 0.17431532198371577, 'fraction_numerical': 0.0051813471502590676, 'mean_word_length': 2.774441340782123, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, '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': '4540008', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1933, 'n_words': 330}