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.5 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-2017 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, long aStyle = wxOK );
  45. KIDIALOG( wxWindow* aParent, const wxString& aMessage, KD_TYPE aType, const wxString& aCaption = "" );
  46. ///> Shows the 'do not show again' checkbox
  47. void DoNotShowCheckbox( wxString file, int line );
  48. ///> Checks the 'do not show again' setting for the dialog
  49. bool DoNotShowAgain() const;
  50. void ForceShowAgain();
  51. bool Show( bool aShow = true ) override;
  52. int ShowModal() override;
  53. protected:
  54. ///> Unique identifier of the dialog
  55. unsigned long m_hash;
  56. // Helper functions for wxRichMessageDialog constructor
  57. static wxString getCaption( KD_TYPE aType, const wxString& aCaption );
  58. static long getStyle( KD_TYPE aType );
  59. };
  60. /**
  61. * Function HandleUnsavedChanges
  62. * displays a dialog with Save, Cancel and Discard Changes buttons.
  63. *
  64. * @param aParent = the parent window
  65. * @param aMessage = the main message to put in dialog
  66. * @param aSaveFunction = a function to save changes, if requested. Must return true if
  67. * the save was successful and false otherwise (which will result
  68. * in HandleUnsavedChanges() returning wxID_CANCEL).
  69. * @return wxID_YES, wxID_CANCEL, wxID_NO.
  70. */
  71. bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage,
  72. const std::function<bool()>& aSaveFunction );
  73. /**
  74. * Function UnsavedChangesDialog
  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, const wxString& aMessage, bool* aApplyToAll );
  84. /**
  85. * Function ConfirmRevertDialog
  86. * displays a confirmation for a revert action
  87. */
  88. bool ConfirmRevertDialog( wxWindow* parent, const wxString& aMessage );
  89. /**
  90. * Function DisplayError
  91. * displays an error or warning message box with \a aMessage.
  92. *
  93. * @warning Setting \a displaytime does not work. Do not use it.
  94. */
  95. void DisplayError( wxWindow* parent, const wxString& aMessage, int displaytime = 0 );
  96. /**
  97. * Function DisplayErrorMessage
  98. * displays an error message with \a aMessage
  99. *
  100. * @param aParent is the parent window
  101. * @param aMessage is the message text to display
  102. * @param aExtraInfo is extra data that can be optionally displayed in a collapsible pane
  103. */
  104. void DisplayErrorMessage( wxWindow* aParent, const wxString& aMessage, const wxString& aExtraInfo = wxEmptyString );
  105. /**
  106. * Function DisplayInfoMessage
  107. * displays an informational message box with \a aMessage.
  108. *
  109. * @param aParent is the parent window
  110. * @param aMessage is the message text to display
  111. * @param aExtraInfo is the extra data that can be optionally displayed in a collapsible pane
  112. */
  113. void DisplayInfoMessage( wxWindow* parent, const wxString& aMessage, const wxString& aExtraInfo = wxEmptyString );
  114. /**
  115. * Function IsOK
  116. * displays a yes/no dialog with \a aMessage and returns the user response.
  117. *
  118. * @param aParent is the parent window. NULL can be used if the parent is the top level window.
  119. * @param aMessage is the message to display in the dialog box.
  120. *
  121. * @return True if user selected the yes button, otherwise false.
  122. */
  123. bool IsOK( wxWindow* aParent, const wxString& aMessage );
  124. /**
  125. * Function YesOrCancelDialog
  126. * displays a warning dialog with \a aMessage and returns the user response.
  127. *
  128. * @param aParent is the parent window. NULL can be used if the parent is the top level window.
  129. * @param aWarning is the warning to display in the top part of the dialog box using a bold font.
  130. * @param aMessage is the message to display in the lower part of the dialog box using the
  131. * default system UI font.
  132. * @param aOKLabel is the text to display in the OK button.
  133. * @param aCancelLabel is the text to display in the cancel button.
  134. *
  135. * @return wxID_YES or wxID_CANCEL depending on the button the user selected.
  136. */
  137. int YesOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
  138. const wxString& aOKLabel, const wxString& aCancelLabel,
  139. bool* aApplyToAll = nullptr );
  140. /**
  141. * Displays a dialog with radioboxes asking the user to select an option.
  142. *
  143. * @param aParent is the parent window.
  144. * @param aTitle is the dialog title.
  145. * @param aMessage is a text label displayed in the first row of the dialog.
  146. * @param aOptions is a vector of possible options.
  147. * @return Index of the selected option or -1 when the dialog has been cancelled.
  148. */
  149. int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage,
  150. const wxArrayString& aOptions );
  151. #endif /* __INCLUDE__CONFIRM_H__ */