cmCursesMainForm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCursesMainForm_h
  4. #define cmCursesMainForm_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmCursesCacheEntryComposite.h"
  7. #include "cmCursesForm.h"
  8. #include "cmCursesStandardIncludes.h"
  9. #include "cmStateTypes.h"
  10. #include <cstddef>
  11. #include <memory>
  12. #include <string>
  13. #include <vector>
  14. class cmake;
  15. /** \class cmCursesMainForm
  16. * \brief The main page of ccmake
  17. *
  18. * cmCursesMainForm is the main page of ccmake.
  19. */
  20. class cmCursesMainForm : public cmCursesForm
  21. {
  22. public:
  23. cmCursesMainForm(std::vector<std::string> args, int initwidth);
  24. ~cmCursesMainForm() override;
  25. cmCursesMainForm(cmCursesMainForm const&) = delete;
  26. cmCursesMainForm& operator=(cmCursesMainForm const&) = delete;
  27. /**
  28. * Set the widgets which represent the cache entries.
  29. */
  30. void InitializeUI();
  31. /**
  32. * Handle user input.
  33. */
  34. void HandleInput() override;
  35. /**
  36. * Display form. Use a window of size width x height, starting
  37. * at top, left.
  38. */
  39. void Render(int left, int top, int width, int height) override;
  40. /**
  41. * Returns true if an entry with the given key is in the
  42. * list of current composites.
  43. */
  44. bool LookForCacheEntry(const std::string& key);
  45. enum
  46. {
  47. MIN_WIDTH = 65,
  48. MIN_HEIGHT = 6,
  49. IDEAL_WIDTH = 80,
  50. MAX_WIDTH = 512
  51. };
  52. /**
  53. * This method should normally be called only by the form. The only
  54. * exception is during a resize. The optional argument specifies the
  55. * string to be displayed in the status bar.
  56. */
  57. void UpdateStatusBar() override { this->UpdateStatusBar(nullptr); }
  58. virtual void UpdateStatusBar(const char* message);
  59. /**
  60. * Display current commands and their keys on the toolbar. This
  61. * method should normally called only by the form. The only
  62. * exception is during a resize. If the optional argument process is
  63. * specified and is either 1 (configure) or 2 (generate), then keys
  64. * will be displayed accordingly.
  65. */
  66. void PrintKeys(int process = 0);
  67. /**
  68. * During a CMake run, an error handle should add errors
  69. * to be displayed afterwards.
  70. */
  71. void AddError(const std::string& message, const char* title) override;
  72. /**
  73. * Used to do a configure. If argument is specified, it does only the check
  74. * and not configure.
  75. */
  76. int Configure(int noconfigure = 0);
  77. /**
  78. * Used to generate
  79. */
  80. int Generate();
  81. /**
  82. * Used by main program
  83. */
  84. int LoadCache(const char* dir);
  85. /**
  86. * Progress callback
  87. */
  88. void UpdateProgress(const std::string& msg, float prog);
  89. protected:
  90. // Copy the cache values from the user interface to the actual
  91. // cache.
  92. void FillCacheManagerFromUI();
  93. // Fix formatting of values to a consistent form.
  94. void FixValue(cmStateEnums::CacheEntryType type, const std::string& in,
  95. std::string& out) const;
  96. // Re-post the existing fields. Used to toggle between
  97. // normal and advanced modes. Render() should be called
  98. // afterwards.
  99. void RePost();
  100. // Remove an entry from the interface and the cache.
  101. void RemoveEntry(const char* value);
  102. // Jump to the cache entry whose name matches the string.
  103. void JumpToCacheEntry(const char* str);
  104. // Copies of cache entries stored in the user interface
  105. std::vector<cmCursesCacheEntryComposite> Entries;
  106. // Errors produced during last run of cmake
  107. std::vector<std::string> Errors;
  108. // Command line arguments to be passed to cmake each time
  109. // it is run
  110. std::vector<std::string> Args;
  111. // Message displayed when user presses 'h'
  112. // It is: Welcome + info about current entry + common help
  113. std::vector<std::string> HelpMessage;
  114. // Common help
  115. static const char* s_ConstHelpMessage;
  116. // Fields displayed. Includes labels, new entry markers, entries
  117. std::vector<FIELD*> Fields;
  118. // Number of entries shown (depends on mode -normal or advanced-)
  119. size_t NumberOfVisibleEntries;
  120. bool AdvancedMode;
  121. // Did the iteration converge (no new entries) ?
  122. bool OkToGenerate;
  123. // Number of pages displayed
  124. int NumberOfPages;
  125. int InitialWidth;
  126. std::unique_ptr<cmake> CMakeInstance;
  127. std::string SearchString;
  128. std::string OldSearchString;
  129. bool SearchMode;
  130. };
  131. #endif // cmCursesMainForm_h