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_DocumentEditorComponent.h"
27 #include "../Project/jucer_ProjectContentComponent.h"
30 //==============================================================================
31 DocumentEditorComponent::DocumentEditorComponent (OpenDocumentManager::Document
* document_
)
32 : document (document_
)
34 OpenDocumentManager::getInstance()->addListener (this);
37 DocumentEditorComponent::~DocumentEditorComponent()
39 OpenDocumentManager::getInstance()->removeListener (this);
42 void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Document
* closingDoc
)
44 if (document
== closingDoc
)
46 jassert (document
!= nullptr);
47 ProjectContentComponent
* pcc
= findParentComponentOfClass ((ProjectContentComponent
*) 0);
51 pcc
->hideDocument (document
);
59 ApplicationCommandTarget
* DocumentEditorComponent::getNextCommandTarget()
61 return findFirstTargetParentComponent();
64 void DocumentEditorComponent::getAllCommands (Array
<CommandID
>& commands
)
66 const CommandID ids
[] = { CommandIDs::saveDocument
,
67 CommandIDs::saveDocumentAs
,
68 CommandIDs::closeDocument
};
70 commands
.addArray (ids
, numElementsInArray (ids
));
73 void DocumentEditorComponent::getCommandInfo (const CommandID commandID
, ApplicationCommandInfo
& result
)
75 result
.setActive (document
!= nullptr);
78 if (document
!= nullptr)
79 name
= " '" + document
->getName().substring (0, 32) + "'";
83 case CommandIDs::saveDocument
:
84 result
.setInfo ("Save" + name
,
85 "Saves the current document",
86 CommandCategories::general
, 0);
87 result
.defaultKeypresses
.add (KeyPress ('s', ModifierKeys::commandModifier
, 0));
90 case CommandIDs::saveDocumentAs
:
91 result
.setInfo ("Save" + name
+ " As...",
92 "Saves the current document to a different filename",
93 CommandCategories::general
, 0);
94 result
.defaultKeypresses
.add (KeyPress ('s', ModifierKeys::commandModifier
| ModifierKeys::shiftModifier
, 0));
97 case CommandIDs::closeDocument
:
98 result
.setInfo ("Close" + name
,
99 "Closes the current document",
100 CommandCategories::general
, 0);
101 result
.defaultKeypresses
.add (KeyPress ('w', ModifierKeys::commandModifier
| ModifierKeys::shiftModifier
, 0));
109 bool DocumentEditorComponent::perform (const InvocationInfo
& info
)
111 switch (info
.commandID
)
113 case CommandIDs::saveDocument
:
117 case CommandIDs::saveDocumentAs
:
122 case CommandIDs::closeDocument
:
123 OpenDocumentManager::getInstance()->closeDocument (document
, true);