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.

60 lines
2.0KB

  1. #include "PluginSelectorWindow.h"
  2. namespace {
  3. const juce::Colour BACKGROUND_COLOUR(0, 0, 0);
  4. constexpr int TITLE_BAR_BUTTONS {
  5. juce::DocumentWindow::TitleBarButtons::minimiseButton |
  6. juce::DocumentWindow::TitleBarButtons::closeButton
  7. };
  8. }
  9. PluginSelectorWindow::PluginSelectorWindow(std::function<void()> onCloseCallback,
  10. PluginSelectorListParameters selectorListParameters,
  11. std::unique_ptr<SelectorComponentStyle> style,
  12. juce::String title) :
  13. juce::DocumentWindow(title, BACKGROUND_COLOUR, TITLE_BAR_BUTTONS),
  14. _onCloseCallback(onCloseCallback),
  15. _content(nullptr),
  16. _style(std::move(style)),
  17. _state(selectorListParameters.state) {
  18. if (_state.bounds.has_value()) {
  19. // Use the previous bounds if we have them
  20. setBounds(_state.bounds.value());
  21. } else {
  22. // Default to the centre
  23. constexpr int DEFAULT_WIDTH {900};
  24. constexpr int DEFAULT_HEIGHT {550};
  25. centreWithSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
  26. }
  27. setVisible(true);
  28. setResizable(true, true);
  29. setAlwaysOnTop(true);
  30. _content = new PluginSelectorComponent(selectorListParameters, onCloseCallback, *(_style.get()));
  31. setContentOwned(_content, false);
  32. _content->setBounds(0, getTitleBarHeight(), getWidth(), getHeight() - getTitleBarHeight());
  33. _content->restoreScrollPosition();
  34. selectorListParameters.scanner.clearMissingPlugins();
  35. juce::Logger::writeToLog("Created PluginSelectorWindow");
  36. }
  37. PluginSelectorWindow::~PluginSelectorWindow() {
  38. juce::Logger::writeToLog("Closing PluginSelectorWindow");
  39. _state.bounds = getBounds();
  40. clearContentComponent();
  41. }
  42. void PluginSelectorWindow::closeButtonPressed() {
  43. _onCloseCallback();
  44. }
  45. void PluginSelectorWindow::takeFocus() {
  46. if (_content != nullptr) {
  47. _content->grabKeyboardFocus();
  48. }
  49. }