Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / Introjucer / Source / Application / jucer_MainWindow.cpp
blob9d2f6e880b2e23b94cf856615363560a303b2775
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-10 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucer_Headers.h"
27 #include "jucer_Application.h"
28 #include "jucer_MainWindow.h"
29 #include "jucer_OpenDocumentManager.h"
30 #include "../Code Editor/jucer_SourceCodeEditor.h"
31 #include "../Project/jucer_NewProjectWizard.h"
33 ApplicationCommandManager* commandManager = nullptr;
36 //==============================================================================
37 MainWindow::MainWindow()
38 : DocumentWindow (JUCEApplication::getInstance()->getApplicationName(),
39 Colour::greyLevel (0.6f),
40 DocumentWindow::allButtons,
41 false)
43 setUsingNativeTitleBar (true);
44 setContentOwned (new ProjectContentComponent(), false);
46 #if ! JUCE_MAC
47 JucerApplication* app = static_cast<JucerApplication*> (JUCEApplication::getInstance());
48 setMenuBar (app->menuModel);
49 #endif
51 setResizable (true, false);
53 centreWithSize (700, 600);
55 // Register all the app commands..
57 commandManager->registerAllCommandsForTarget (this);
59 // use a temporary one of these to harvest its commands..
60 ProjectContentComponent pcc;
61 commandManager->registerAllCommandsForTarget (&pcc);
63 DocumentEditorComponent dec (nullptr);
64 commandManager->registerAllCommandsForTarget (&dec);
67 commandManager->getKeyMappings()->resetToDefaultMappings();
69 ScopedPointer <XmlElement> keys (StoredSettings::getInstance()->getProps().getXmlValue ("keyMappings"));
71 if (keys != nullptr)
72 commandManager->getKeyMappings()->restoreFromXml (*keys);
74 addKeyListener (commandManager->getKeyMappings());
76 // don't want the window to take focus when the title-bar is clicked..
77 setWantsKeyboardFocus (false);
79 //getPeer()->setCurrentRenderingEngine (0);
80 getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
82 setVisible (true);
83 addToDesktop();
85 getContentComponent()->grabKeyboardFocus();
88 MainWindow::~MainWindow()
90 #if ! JUCE_MAC
91 setMenuBar (nullptr);
92 #endif
94 removeKeyListener (commandManager->getKeyMappings());
96 // save the current size and position to our settings file..
97 StoredSettings::getInstance()->getProps()
98 .setValue ("lastMainWindowPos", getWindowStateAsString());
100 clearContentComponent();
101 currentProject = nullptr;
104 ProjectContentComponent* MainWindow::getProjectContentComponent() const
106 return dynamic_cast <ProjectContentComponent*> (getContentComponent());
109 void MainWindow::closeButtonPressed()
111 if (! closeCurrentProject())
112 return;
114 JucerApplication* jucer = static_cast<JucerApplication*> (JUCEApplication::getInstance());
115 jucer->closeWindow (this);
118 bool MainWindow::closeProject (Project* project)
120 jassert (project == currentProject && project != nullptr);
122 if (project == nullptr)
123 return true;
125 StoredSettings::getInstance()->getProps()
126 .setValue (getProjectWindowPosName(), getWindowStateAsString());
128 if (! OpenDocumentManager::getInstance()->closeAllDocumentsUsingProject (*project, true))
129 return false;
131 FileBasedDocument::SaveResult r = project->saveIfNeededAndUserAgrees();
133 if (r == FileBasedDocument::savedOk)
135 setProject (nullptr);
136 return true;
139 return false;
142 bool MainWindow::closeCurrentProject()
144 return currentProject == nullptr || closeProject (currentProject);
147 void MainWindow::setProject (Project* newProject)
149 getProjectContentComponent()->setProject (newProject);
150 currentProject = newProject;
151 commandManager->commandStatusChanged();
153 // (mustn't do this when the project is 0, because that'll happen on shutdown,
154 // which will erase the list of recent projects)
155 if (newProject != nullptr)
156 static_cast<JucerApplication*> (JUCEApplication::getInstance())->updateRecentProjectList();
159 void MainWindow::restoreWindowPosition()
161 String windowState;
163 if (currentProject != nullptr)
164 windowState = StoredSettings::getInstance()->getProps().getValue (getProjectWindowPosName());
166 if (windowState.isEmpty())
167 windowState = StoredSettings::getInstance()->getProps().getValue ("lastMainWindowPos");
169 restoreWindowStateFromString (windowState);
172 bool MainWindow::canOpenFile (const File& file) const
174 return file.hasFileExtension (Project::projectFileExtension)
175 || OpenDocumentManager::getInstance()->canOpenFile (file);
178 bool MainWindow::openFile (const File& file)
180 if (file.hasFileExtension (Project::projectFileExtension))
182 ScopedPointer <Project> newDoc (new Project (file));
184 if (file == File::nonexistent ? newDoc->loadFromUserSpecifiedFile (true)
185 : newDoc->loadFrom (file, true))
187 if (closeCurrentProject())
189 setProject (newDoc.release());
190 return true;
194 else if (file.exists())
196 return getProjectContentComponent()->showEditorForFile (file);
199 return false;
202 bool MainWindow::isInterestedInFileDrag (const StringArray& filenames)
204 for (int i = filenames.size(); --i >= 0;)
205 if (canOpenFile (filenames[i]))
206 return true;
208 return false;
211 void MainWindow::filesDropped (const StringArray& filenames, int mouseX, int mouseY)
213 for (int i = filenames.size(); --i >= 0;)
215 const File f (filenames[i]);
217 if (canOpenFile (f) && openFile (f))
218 break;
222 void MainWindow::activeWindowStatusChanged()
224 DocumentWindow::activeWindowStatusChanged();
226 if (getProjectContentComponent() != nullptr)
227 getProjectContentComponent()->updateMissingFileStatuses();
229 OpenDocumentManager::getInstance()->reloadModifiedFiles();
232 void MainWindow::updateTitle (const String& documentName)
234 String name (JUCEApplication::getInstance()->getApplicationName());
235 if (documentName.isNotEmpty())
236 name = documentName + " - " + name;
238 setName (name);
242 //==============================================================================
243 ApplicationCommandTarget* MainWindow::getNextCommandTarget()
245 return 0;
248 void MainWindow::getAllCommands (Array <CommandID>& commands)
250 const CommandID ids[] = { CommandIDs::closeWindow };
252 commands.addArray (ids, numElementsInArray (ids));
255 void MainWindow::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
257 switch (commandID)
259 case CommandIDs::closeWindow:
260 result.setInfo ("Close Window", "Closes the current window", CommandCategories::general, 0);
261 result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier, 0));
262 break;
264 default:
265 break;
269 bool MainWindow::perform (const InvocationInfo& info)
271 switch (info.commandID)
273 case CommandIDs::closeWindow:
274 closeButtonPressed();
275 break;
277 default:
278 return false;
281 return true;