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.

179 lines
6.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * This file is part of the common library
  26. * @file confirm.h
  27. * @see common.h
  28. */
  29. #ifndef __INCLUDE__CONFIRM_H__
  30. #define __INCLUDE__CONFIRM_H__
  31. #include <wx/richmsgdlg.h>
  32. #include <vector>
  33. #include <functional>
  34. class wxCheckBox;
  35. class wxStaticBitmap;
  36. /**
  37. * Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
  38. */
  39. class KIDIALOG : public wxRichMessageDialog
  40. {
  41. public:
  42. ///> Dialog type. Selects appropriate icon and default dialog title
  43. enum KD_TYPE { KD_NONE, KD_INFO, KD_QUESTION, KD_WARNING, KD_ERROR };
  44. KIDIALOG( wxWindow* aParent, const wxString& aMessage, const wxString& aCaption,
  45. long aStyle = wxOK );
  46. KIDIALOG( wxWindow* aParent, const wxString& aMessage, KD_TYPE aType,
  47. const wxString& aCaption = "" );
  48. ///> Shows the 'do not show again' checkbox
  49. void DoNotShowCheckbox( wxString file, int line );
  50. ///> Checks the 'do not show again' setting for the dialog
  51. bool DoNotShowAgain() const;
  52. void ForceShowAgain();
  53. bool Show( bool aShow = true ) override;
  54. int ShowModal() override;
  55. protected:
  56. ///> Unique identifier of the dialog
  57. unsigned long m_hash;
  58. // Helper functions for wxRichMessageDialog constructor
  59. static wxString getCaption( KD_TYPE aType, const wxString& aCaption );
  60. static long getStyle( KD_TYPE aType );
  61. };
  62. /**
  63. * Display a dialog with Save, Cancel and Discard Changes buttons.
  64. *
  65. * @param aParent = the parent window
  66. * @param aMessage = the main message to put in dialog
  67. * @param aSaveFunction = a function to save changes, if requested. Must return true if
  68. * the save was successful and false otherwise (which will result
  69. * in HandleUnsavedChanges() returning wxID_CANCEL).
  70. * @return wxID_YES, wxID_CANCEL, wxID_NO.
  71. */
  72. bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage,
  73. const std::function<bool()>& aSaveFunction );
  74. /**
  75. * A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
  76. *
  77. * @param aParent = the parent window
  78. * @param aMessage = the main message to put in dialog
  79. * @param aApplyToAll = if non-null an "Apply to all" checkbox will be shown and it's value
  80. * written back to the bool.
  81. * @return wxID_YES, wxID_CANCEL, wxID_NO.
  82. */
  83. int UnsavedChangesDialog( wxWindow* aParent, wxString aMessage, bool* aApplyToAll );
  84. int UnsavedChangesDialog( wxWindow* aParent, const wxString& aMessage );
  85. /**
  86. * Display a confirmation dialog for a revert action.
  87. */
  88. bool ConfirmRevertDialog( wxWindow* parent, const wxString& aMessage );
  89. /**
  90. * Display an error or warning message box with \a aMessage.
  91. *
  92. * @warning Setting \a displaytime does not work. Do not use it.
  93. */
  94. void DisplayError( wxWindow* aParent, const wxString& aText, int aDisplayTime = 0 );
  95. /**
  96. * Display an error message with \a aMessage
  97. *
  98. * @param aParent is the parent window
  99. * @param aMessage is the message text to display
  100. * @param aExtraInfo is extra data that can be optionally displayed in a collapsible pane
  101. */
  102. void DisplayErrorMessage( wxWindow* aParent, const wxString& aMessage,
  103. const wxString& aExtraInfo = wxEmptyString );
  104. /**
  105. * Display an informational message box with \a aMessage.
  106. *
  107. * @param aParent is the parent window
  108. * @param aMessage is the message text to display
  109. * @param aExtraInfo is the extra data that can be optionally displayed in a collapsible pane
  110. */
  111. void DisplayInfoMessage( wxWindow* parent, const wxString& aMessage,
  112. const wxString& aExtraInfo = wxEmptyString );
  113. /**
  114. * Display a yes/no dialog with \a aMessage and returns the user response.
  115. *
  116. * @param aParent is the parent window. NULL can be used if the parent is the top level window.
  117. * @param aMessage is the message to display in the dialog box.
  118. *
  119. * @return True if user selected the yes button, otherwise false.
  120. */
  121. bool IsOK( wxWindow* aParent, const wxString& aMessage );
  122. /**
  123. * Displays a warning dialog with \a aMessage and returns the user response.
  124. *
  125. * @param aParent is the parent window. NULL can be used if the parent is the top level window.
  126. * @param aWarning is the warning to display in the top part of the dialog box using a bold font.
  127. * @param aMessage is the message to display in the lower part of the dialog box using the
  128. * default system UI font.
  129. * @param aDetailedMessage is the message to display in the "Show detailed information" section.
  130. * Passing wxEmptyString will hide this portion of the dialog.
  131. * @param aOKLabel is the text to display in the OK button.
  132. * @param aCancelLabel is the text to display in the cancel button.
  133. *
  134. * @return wxID_OK or wxID_CANCEL depending on the button the user selected.
  135. */
  136. int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
  137. const wxString& aDetailedMessage, const wxString& aOKLabel,
  138. const wxString& aCancelLabel, bool* aApplyToAll );
  139. /**
  140. * Displays a dialog with radioboxes asking the user to select an option.
  141. *
  142. * @param aParent is the parent window.
  143. * @param aTitle is the dialog title.
  144. * @param aMessage is a text label displayed in the first row of the dialog.
  145. * @param aOptions is a vector of possible options.
  146. * @return Index of the selected option or -1 when the dialog has been canceled.
  147. */
  148. int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage,
  149. const wxArrayString& aOptions );
  150. #endif /* __INCLUDE__CONFIRM_H__ */