The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

159 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_Headers.h"
  19. #include "ui/jucer_MainWindow.h"
  20. ApplicationCommandManager* commandManager = 0;
  21. //==============================================================================
  22. class JucerApplication : public JUCEApplication
  23. {
  24. public:
  25. //==============================================================================
  26. JucerApplication()
  27. {
  28. }
  29. ~JucerApplication()
  30. {
  31. }
  32. //==============================================================================
  33. void initialise (const String& commandLine)
  34. {
  35. /* Running a command-line of the form "Jucer --resave foobar.jucer" will try to load that
  36. jucer file and re-export all of its projects.
  37. */
  38. if (commandLine.startsWithIgnoreCase ("-resave ") || commandLine.startsWithIgnoreCase ("--resave "))
  39. {
  40. resaveJucerFile (File::getCurrentWorkingDirectory()
  41. .getChildFile (commandLine.fromFirstOccurrenceOf (" ", false, false).unquoted()));
  42. quit();
  43. return;
  44. }
  45. commandManager = new ApplicationCommandManager();
  46. theMainWindow = new MainWindow();
  47. theMainWindow->setVisible (true);
  48. ImageCache::setCacheTimeout (30 * 1000);
  49. if (commandLine.trim().isNotEmpty()
  50. && ! commandLine.trim().startsWithChar ('-'))
  51. anotherInstanceStarted (commandLine);
  52. theMainWindow->reloadLastProject();
  53. theMainWindow->getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  54. }
  55. void shutdown()
  56. {
  57. theMainWindow = 0;
  58. OpenDocumentManager::deleteInstance();
  59. deleteAndZero (commandManager);
  60. }
  61. //==============================================================================
  62. void systemRequestedQuit()
  63. {
  64. if (theMainWindow == 0 || theMainWindow->closeCurrentProject())
  65. {
  66. theMainWindow = 0;
  67. StoredSettings::deleteInstance();
  68. quit();
  69. }
  70. }
  71. //==============================================================================
  72. const String getApplicationName()
  73. {
  74. return "The Jucer V" + getApplicationVersion();
  75. }
  76. const String getApplicationVersion()
  77. {
  78. return ProjectInfo::versionString;
  79. }
  80. bool moreThanOneInstanceAllowed()
  81. {
  82. #ifndef JUCE_LINUX
  83. return false;
  84. #else
  85. return true; //xxx should be false but doesn't work on linux..
  86. #endif
  87. }
  88. void anotherInstanceStarted (const String& commandLine)
  89. {
  90. if (theMainWindow != 0)
  91. theMainWindow->openFile (commandLine.unquoted());
  92. }
  93. private:
  94. ScopedPointer <MainWindow> theMainWindow;
  95. void resaveJucerFile (const File& file)
  96. {
  97. if (! file.exists())
  98. {
  99. std::cout << "The file " << file.getFullPathName() << " doesn't exist!" << std::endl;
  100. return;
  101. }
  102. if (! file.hasFileExtension (Project::projectFileExtension))
  103. {
  104. std::cout << file.getFullPathName() << " isn't a valid jucer project file!" << std::endl;
  105. return;
  106. }
  107. ScopedPointer <Project> newDoc (new Project (file));
  108. if (! newDoc->loadFrom (file, true))
  109. {
  110. std::cout << "Failed to load the project file: " << file.getFullPathName() << std::endl;
  111. return;
  112. }
  113. std::cout << "The Jucer - Re-saving file: " << file.getFullPathName() << std::endl;
  114. String error (newDoc->saveDocument (file));
  115. if (error.isNotEmpty())
  116. {
  117. std::cout << "Error when writing project: " << error << std::endl;
  118. return;
  119. }
  120. }
  121. };
  122. START_JUCE_APPLICATION(JucerApplication)