You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Marco Mattila <marcom99@gmail.com>
  5. * Copyright (C) 2006 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
  6. * Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef DIALOG_FIND_BASE_H
  26. #define DIALOG_FIND_BASE_H
  27. #include <functional>
  28. #include <sys/types.h>
  29. #include <wx/event.h>
  30. #include <deque>
  31. #include <board_item.h>
  32. #include <dialog_find_base.h>
  33. using namespace std;
  34. class DIALOG_FIND : public DIALOG_FIND_BASE
  35. {
  36. public:
  37. DIALOG_FIND( PCB_BASE_FRAME* aParent );
  38. void Preload( const wxString& aFindString );
  39. /**
  40. * Return the currently found item or nullptr in the case of no items found.
  41. */
  42. inline BOARD_ITEM* GetItem() const
  43. {
  44. if( m_it != m_hitList.end() )
  45. return *m_it;
  46. else
  47. return nullptr;
  48. }
  49. /**
  50. * Function to be called on each found event.
  51. *
  52. * The callback function must be able to handle nullptr in the case where no item is found.
  53. */
  54. void SetCallback( std::function<void( BOARD_ITEM* )> aCallback )
  55. {
  56. m_highlightCallback = aCallback;
  57. }
  58. /**
  59. * Finds the next item
  60. */
  61. void FindNext( bool reverse ) { search( !reverse ); }
  62. /**
  63. * The Show method is overridden to make the search combobox
  64. * focused by default.
  65. * wxShowEvent is not suitable here because it supports MSW
  66. * and GTK only.
  67. */
  68. bool Show( bool show = true ) override;
  69. protected:
  70. void OnClose( wxCloseEvent& event ) override;
  71. void OnCloseButtonClick( wxCommandEvent& aEvent ) override;
  72. private:
  73. void onTextEnter( wxCommandEvent& event ) override;
  74. void onFindNextClick( wxCommandEvent& event ) override;
  75. void onFindPreviousClick( wxCommandEvent& event ) override;
  76. void onSearchAgainClick( wxCommandEvent& event ) override;
  77. void search( bool direction );
  78. PCB_BASE_FRAME* m_frame;
  79. std::deque<BOARD_ITEM*> m_hitList;
  80. std::deque<BOARD_ITEM*>::iterator m_it;
  81. bool m_upToDate;
  82. std::function<void( BOARD_ITEM* )> m_highlightCallback;
  83. };
  84. #endif /* DIALOG_FIND_BASE_H */