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.

156 lines
4.6KB

  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 resaveJucerFile (const File file)
  34. {
  35. if (! file.exists())
  36. {
  37. std::cout << "The file doesn't exist!" << std::endl;
  38. return;
  39. }
  40. if (! file.hasFileExtension (Project::projectFileExtension))
  41. {
  42. std::cout << "Not a valid jucer project file!" << std::endl;
  43. return;
  44. }
  45. ScopedPointer <Project> newDoc (new Project (file));
  46. if (! newDoc->loadFrom (file, true))
  47. {
  48. std::cout << "Failed to load the project file!" << std::endl;
  49. return;
  50. }
  51. String error (newDoc->saveDocument (file));
  52. if (error.isNotEmpty())
  53. {
  54. std::cout << "Error when writing project: " << error << std::endl;
  55. return;
  56. }
  57. }
  58. void initialise (const String& commandLine)
  59. {
  60. /* Running a command-line of the form "Jucer --resave foobar.jucer" will try to load that
  61. jucer file and re-export all of its projects.
  62. */
  63. if (commandLine.startsWithIgnoreCase (T("-resave ")) || commandLine.startsWithIgnoreCase (T("--resave ")))
  64. {
  65. resaveJucerFile (File::getCurrentWorkingDirectory()
  66. .getChildFile (commandLine.fromFirstOccurrenceOf (T(" "), false, false).unquoted()));
  67. quit();
  68. return;
  69. }
  70. commandManager = new ApplicationCommandManager();
  71. theMainWindow = new MainWindow();
  72. theMainWindow->setVisible (true);
  73. ImageCache::setCacheTimeout (30 * 1000);
  74. if (commandLine.trim().isNotEmpty()
  75. && ! commandLine.trim().startsWithChar ('-'))
  76. anotherInstanceStarted (commandLine);
  77. theMainWindow->reloadLastProject();
  78. }
  79. void shutdown()
  80. {
  81. theMainWindow = 0;
  82. OpenDocumentManager::deleteInstance();
  83. deleteAndZero (commandManager);
  84. }
  85. //==============================================================================
  86. void systemRequestedQuit()
  87. {
  88. if (theMainWindow == 0 || theMainWindow->closeCurrentProject())
  89. {
  90. theMainWindow = 0;
  91. StoredSettings::deleteInstance();
  92. quit();
  93. }
  94. }
  95. //==============================================================================
  96. const String getApplicationName()
  97. {
  98. return "The Jucer V" + getApplicationVersion();
  99. }
  100. const String getApplicationVersion()
  101. {
  102. return ProjectInfo::versionString;
  103. }
  104. bool moreThanOneInstanceAllowed()
  105. {
  106. #ifndef JUCE_LINUX
  107. return false;
  108. #else
  109. return true; //xxx should be false but doesn't work on linux..
  110. #endif
  111. }
  112. void anotherInstanceStarted (const String& commandLine)
  113. {
  114. if (theMainWindow != 0)
  115. theMainWindow->openFile (commandLine.unquoted());
  116. }
  117. private:
  118. ScopedPointer <MainWindow> theMainWindow;
  119. };
  120. START_JUCE_APPLICATION(JucerApplication)