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_ProjectContentComponent.h"
27 #include "../Application/jucer_MainWindow.h"
28 #include "../Code Editor/jucer_SourceCodeEditor.h"
29 #include "jucer_ProjectInformationComponent.h"
30 #include "jucer_TreeViewTypes.h"
31 #include "jucer_ProjectExporter.h"
34 //==============================================================================
35 ProjectContentComponent::ProjectContentComponent()
37 currentDocument (nullptr)
40 setWantsKeyboardFocus (true);
42 treeSizeConstrainer
.setMinimumWidth (100);
43 treeSizeConstrainer
.setMaximumWidth (500);
46 ProjectContentComponent::~ProjectContentComponent()
49 contentView
= nullptr;
50 jassert (getNumChildComponents() == 0);
53 void ProjectContentComponent::paint (Graphics
& g
)
55 g
.fillAll (Colour::greyLevel (0.8f
));
58 void ProjectContentComponent::setProject (Project
* newProject
)
60 if (project
!= newProject
)
62 if (project
!= nullptr)
63 project
->removeChangeListener (this);
65 contentView
= nullptr;
68 if (projectTree
!= nullptr)
70 StoredSettings::getInstance()->getProps().setValue ("projectTreeviewWidth", projectTree
->getWidth());
71 projectTree
->deleteRootItem();
72 projectTree
= nullptr;
77 if (project
!= nullptr)
79 addAndMakeVisible (projectTree
= new TreeView());
80 projectTree
->setComponentID ("tree");
81 projectTree
->setRootItemVisible (true);
82 projectTree
->setMultiSelectEnabled (true);
83 projectTree
->setDefaultOpenness (true);
84 projectTree
->setColour (TreeView::backgroundColourId
, Colour::greyLevel (0.93f
));
85 projectTree
->setIndentSize (14);
87 projectTree
->setRootItem (new GroupTreeViewItem (project
->getMainGroup()));
88 projectTree
->getRootItem()->setOpen (true);
90 String
lastTreeWidth (StoredSettings::getInstance()->getProps().getValue ("projectTreeviewWidth"));
91 if (lastTreeWidth
.getIntValue() < 150)
92 lastTreeWidth
= "250";
94 projectTree
->setBounds ("0, 0, left + " + lastTreeWidth
+ ", parent.height");
96 addAndMakeVisible (resizerBar
= new ResizableEdgeComponent (projectTree
, &treeSizeConstrainer
,
97 ResizableEdgeComponent::rightEdge
));
98 resizerBar
->setComponentID ("resizer");
99 resizerBar
->setBounds ("tree.right, 0, tree.right + 4, parent.height");
101 project
->addChangeListener (this);
103 if (currentDocument
== nullptr)
104 invokeDirectly (CommandIDs::showProjectSettings
, true);
106 updateMissingFileStatuses();
111 void ProjectContentComponent::changeListenerCallback (ChangeBroadcaster
*)
113 updateMissingFileStatuses();
116 void ProjectContentComponent::updateMissingFileStatuses()
118 if (projectTree
!= nullptr)
120 ProjectTreeViewBase
* p
= dynamic_cast <ProjectTreeViewBase
*> (projectTree
->getRootItem());
122 p
->checkFileStatus();
126 bool ProjectContentComponent::showEditorForFile (const File
& f
)
128 return showDocument (OpenDocumentManager::getInstance()
129 ->getDocumentForFile (project
, f
));
132 bool ProjectContentComponent::showDocument (OpenDocumentManager::Document
* doc
)
137 OpenDocumentManager::getInstance()->moveDocumentToTopOfStack (doc
);
139 if (doc
->hasFileBeenModifiedExternally())
140 doc
->reloadFromFile();
142 return setEditorComponent (doc
->createEditor(), doc
);
145 void ProjectContentComponent::hideDocument (OpenDocumentManager::Document
* doc
)
147 if (doc
== currentDocument
)
149 currentDocument
= nullptr;
150 contentView
= nullptr;
151 updateMainWindowTitle();
152 commandManager
->commandStatusChanged();
156 bool ProjectContentComponent::setEditorComponent (Component
* editor
, OpenDocumentManager::Document
* doc
)
158 if (editor
!= nullptr)
160 contentView
= editor
;
161 currentDocument
= doc
;
162 addAndMakeVisible (editor
);
163 editor
->setBounds ("resizer.right, 0, parent.right, parent.height");
165 updateMainWindowTitle();
166 commandManager
->commandStatusChanged();
171 updateMainWindowTitle();
175 void ProjectContentComponent::updateMainWindowTitle()
177 MainWindow
* mw
= Component::findParentComponentOfClass ((MainWindow
*) 0);
180 mw
->updateTitle (currentDocument
!= nullptr ? currentDocument
->getName() : String::empty
);
183 ApplicationCommandTarget
* ProjectContentComponent::getNextCommandTarget()
185 return findFirstTargetParentComponent();
188 void ProjectContentComponent::getAllCommands (Array
<CommandID
>& commands
)
190 const CommandID ids
[] = { CommandIDs::saveProject
,
191 CommandIDs::saveProjectAs
,
192 CommandIDs::closeProject
,
193 CommandIDs::openInIDE
,
194 CommandIDs::saveAndOpenInIDE
,
195 CommandIDs::showProjectSettings
,
196 StandardApplicationCommandIDs::del
};
198 commands
.addArray (ids
, numElementsInArray (ids
));
201 void ProjectContentComponent::getCommandInfo (const CommandID commandID
, ApplicationCommandInfo
& result
)
205 case CommandIDs::saveProject
:
206 result
.setInfo ("Save Project",
207 "Saves the current project",
208 CommandCategories::general
, 0);
209 result
.setActive (project
!= nullptr);
210 result
.defaultKeypresses
.add (KeyPress ('s', ModifierKeys::commandModifier
, 0));
213 case CommandIDs::saveProjectAs
:
214 result
.setInfo ("Save Project As...",
215 "Saves the current project to a different filename",
216 CommandCategories::general
, 0);
217 result
.setActive (project
!= nullptr);
218 result
.defaultKeypresses
.add (KeyPress ('s', ModifierKeys::commandModifier
| ModifierKeys::shiftModifier
, 0));
221 case CommandIDs::closeProject
:
222 result
.setInfo ("Close Project",
223 "Closes the current project",
224 CommandCategories::general
, 0);
225 result
.setActive (project
!= nullptr);
226 result
.defaultKeypresses
.add (KeyPress ('w', ModifierKeys::commandModifier
| ModifierKeys::shiftModifier
, 0));
229 case CommandIDs::openInIDE
:
231 result
.setInfo ("Open in XCode...",
233 result
.setInfo ("Open in Visual Studio...",
235 result
.setInfo ("Open as a Makefile...",
237 "Launches the project in an external IDE",
238 CommandCategories::general
, 0);
239 result
.setActive (project
!= nullptr);
242 case CommandIDs::saveAndOpenInIDE
:
244 result
.setInfo ("Save Project and Open in XCode...",
246 result
.setInfo ("Save Project and Open in Visual Studio...",
248 result
.setInfo ("Save Project and Open as a Makefile...",
250 "Saves the project and launches it in an external IDE",
251 CommandCategories::general
, 0);
252 result
.setActive (project
!= nullptr);
253 result
.defaultKeypresses
.add (KeyPress ('l', ModifierKeys::commandModifier
, 0));
256 case CommandIDs::showProjectSettings
:
257 result
.setInfo ("Show Project Build Settings",
258 "Shows the build options for the project",
259 CommandCategories::general
, 0);
260 result
.setActive (project
!= nullptr);
261 result
.defaultKeypresses
.add (KeyPress ('i', ModifierKeys::commandModifier
| ModifierKeys::shiftModifier
, 0));
264 case StandardApplicationCommandIDs::del
:
265 result
.setInfo ("Delete", String::empty
, CommandCategories::general
, 0);
266 result
.defaultKeypresses
.add (KeyPress (KeyPress::deleteKey
, 0, 0));
267 result
.defaultKeypresses
.add (KeyPress (KeyPress::backspaceKey
, 0, 0));
268 result
.setActive (projectTree
!= nullptr);
276 bool ProjectContentComponent::isCommandActive (const CommandID commandID
)
278 return project
!= nullptr;
281 bool ProjectContentComponent::perform (const InvocationInfo
& info
)
283 switch (info
.commandID
)
285 case CommandIDs::saveProject
:
286 if (project
!= nullptr)
287 project
->save (true, true);
291 case CommandIDs::saveProjectAs
:
292 if (project
!= nullptr)
293 project
->saveAsInteractive (true);
297 case CommandIDs::closeProject
:
299 MainWindow
* mw
= Component::findParentComponentOfClass ((MainWindow
*) 0);
302 mw
->closeCurrentProject();
307 case CommandIDs::openInIDE
:
308 if (project
!= nullptr)
310 ScopedPointer
<ProjectExporter
> exporter (ProjectExporter::createPlatformDefaultExporter (*project
));
311 exporter
->launchProject();
315 case CommandIDs::saveAndOpenInIDE
:
316 if (project
!= nullptr && project
->save (true, true) == FileBasedDocument::savedOk
)
318 ScopedPointer
<ProjectExporter
> exporter (ProjectExporter::createPlatformDefaultExporter (*project
));
319 exporter
->launchProject();
323 case CommandIDs::showProjectSettings
:
324 if (projectTree
!= nullptr)
325 projectTree
->getRootItem()->setSelected (true, true);
329 case StandardApplicationCommandIDs::del
:
330 if (projectTree
!= nullptr)
332 ProjectTreeViewBase
* p
= dynamic_cast <ProjectTreeViewBase
*> (projectTree
->getRootItem());
334 p
->deleteAllSelectedItems();