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.

157 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. }
  54. void shutdown()
  55. {
  56. theMainWindow = 0;
  57. OpenDocumentManager::deleteInstance();
  58. deleteAndZero (commandManager);
  59. }
  60. //==============================================================================
  61. void systemRequestedQuit()
  62. {
  63. if (theMainWindow == 0 || theMainWindow->closeCurrentProject())
  64. {
  65. theMainWindow = 0;
  66. StoredSettings::deleteInstance();
  67. quit();
  68. }
  69. }
  70. //==============================================================================
  71. const String getApplicationName()
  72. {
  73. return "The Jucer V" + getApplicationVersion();
  74. }
  75. const String getApplicationVersion()
  76. {
  77. return ProjectInfo::versionString;
  78. }
  79. bool moreThanOneInstanceAllowed()
  80. {
  81. #ifndef JUCE_LINUX
  82. return false;
  83. #else
  84. return true; //xxx should be false but doesn't work on linux..
  85. #endif
  86. }
  87. void anotherInstanceStarted (const String& commandLine)
  88. {
  89. if (theMainWindow != 0)
  90. theMainWindow->openFile (commandLine.unquoted());
  91. }
  92. private:
  93. ScopedPointer <MainWindow> theMainWindow;
  94. void resaveJucerFile (const File& file)
  95. {
  96. if (! file.exists())
  97. {
  98. std::cout << "The file " << file.getFullPathName() << " doesn't exist!" << std::endl;
  99. return;
  100. }
  101. if (! file.hasFileExtension (Project::projectFileExtension))
  102. {
  103. std::cout << file.getFullPathName() << " isn't a valid jucer project file!" << std::endl;
  104. return;
  105. }
  106. ScopedPointer <Project> newDoc (new Project (file));
  107. if (! newDoc->loadFrom (file, true))
  108. {
  109. std::cout << "Failed to load the project file: " << file.getFullPathName() << std::endl;
  110. return;
  111. }
  112. std::cout << "The Jucer - Re-saving file: " << file.getFullPathName() << std::endl;
  113. String error (newDoc->saveDocument (file));
  114. if (error.isNotEmpty())
  115. {
  116. std::cout << "Error when writing project: " << error << std::endl;
  117. return;
  118. }
  119. }
  120. };
  121. START_JUCE_APPLICATION(JucerApplication)