mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-07 04:10:08 +00:00
Introjucer: tidied up some document saving behaviour.
This commit is contained in:
parent
f2426cc7de
commit
d2aa3a666b
9 changed files with 53 additions and 143 deletions
|
|
@ -199,11 +199,9 @@ public:
|
|||
menu.addSeparator();
|
||||
menu.addCommandItem (commandManager, CommandIDs::closeDocument);
|
||||
menu.addCommandItem (commandManager, CommandIDs::saveDocument);
|
||||
menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs);
|
||||
menu.addSeparator();
|
||||
menu.addCommandItem (commandManager, CommandIDs::closeProject);
|
||||
menu.addCommandItem (commandManager, CommandIDs::saveProject);
|
||||
menu.addCommandItem (commandManager, CommandIDs::saveProjectAs);
|
||||
menu.addSeparator();
|
||||
menu.addCommandItem (commandManager, CommandIDs::openInIDE);
|
||||
menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,9 @@ namespace CommandIDs
|
|||
static const int open = 0x200020;
|
||||
static const int closeDocument = 0x200030;
|
||||
static const int saveDocument = 0x200040;
|
||||
static const int saveDocumentAs = 0x200050;
|
||||
|
||||
static const int closeProject = 0x200051;
|
||||
static const int saveProject = 0x200060;
|
||||
static const int saveProjectAs = 0x200070;
|
||||
static const int openInIDE = 0x200072;
|
||||
static const int saveAndOpenInIDE = 0x200073;
|
||||
static const int showProjectSettings = 0x200074;
|
||||
|
|
|
|||
|
|
@ -55,81 +55,3 @@ void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Documen
|
|||
jassertfalse
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationCommandTarget* DocumentEditorComponent::getNextCommandTarget()
|
||||
{
|
||||
return findFirstTargetParentComponent();
|
||||
}
|
||||
|
||||
void DocumentEditorComponent::getAllCommands (Array <CommandID>& commands)
|
||||
{
|
||||
const CommandID ids[] = { CommandIDs::saveDocument,
|
||||
CommandIDs::saveDocumentAs,
|
||||
CommandIDs::closeDocument };
|
||||
|
||||
commands.addArray (ids, numElementsInArray (ids));
|
||||
}
|
||||
|
||||
void DocumentEditorComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
|
||||
{
|
||||
result.setActive (document != nullptr);
|
||||
String name;
|
||||
|
||||
if (document != nullptr)
|
||||
name = " '" + document->getName().substring (0, 32) + "'";
|
||||
|
||||
switch (commandID)
|
||||
{
|
||||
case CommandIDs::saveDocument:
|
||||
result.setInfo ("Save" + name,
|
||||
"Saves the current document",
|
||||
CommandCategories::general, 0);
|
||||
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
|
||||
break;
|
||||
|
||||
case CommandIDs::saveDocumentAs:
|
||||
result.setInfo ("Save" + name + " As...",
|
||||
"Saves the current document to a different filename",
|
||||
CommandCategories::general, 0);
|
||||
result.setActive (document != nullptr && document->canSaveAs());
|
||||
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
|
||||
break;
|
||||
|
||||
case CommandIDs::closeDocument:
|
||||
result.setInfo ("Close" + name,
|
||||
"Closes the current document",
|
||||
CommandCategories::general, 0);
|
||||
#if JUCE_MAC
|
||||
result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0));
|
||||
#else
|
||||
result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool DocumentEditorComponent::perform (const InvocationInfo& info)
|
||||
{
|
||||
switch (info.commandID)
|
||||
{
|
||||
case CommandIDs::saveDocument:
|
||||
document->save();
|
||||
return true;
|
||||
|
||||
case CommandIDs::saveDocumentAs:
|
||||
document->saveAs();
|
||||
return true;
|
||||
|
||||
case CommandIDs::closeDocument:
|
||||
OpenDocumentManager::getInstance()->closeDocument (document, true);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
/**
|
||||
*/
|
||||
class DocumentEditorComponent : public Component,
|
||||
public ApplicationCommandTarget,
|
||||
public OpenDocumentManager::DocumentCloseListener
|
||||
{
|
||||
public:
|
||||
|
|
@ -44,12 +43,6 @@ public:
|
|||
OpenDocumentManager::Document* getDocument() const { return document; }
|
||||
void documentAboutToClose (OpenDocumentManager::Document* document);
|
||||
|
||||
//==============================================================================
|
||||
ApplicationCommandTarget* getNextCommandTarget();
|
||||
void getAllCommands (Array <CommandID>& commands);
|
||||
void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result);
|
||||
bool perform (const InvocationInfo& info);
|
||||
|
||||
protected:
|
||||
OpenDocumentManager::Document* document;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,14 +51,8 @@ MainWindow::MainWindow()
|
|||
centreWithSize (800, 600);
|
||||
|
||||
// Register all the app commands..
|
||||
{
|
||||
commandManager->registerAllCommandsForTarget (this);
|
||||
commandManager->registerAllCommandsForTarget (getProjectContentComponent());
|
||||
|
||||
// use some temporary objects to harvest their commands..
|
||||
DocumentEditorComponent dec (nullptr);
|
||||
commandManager->registerAllCommandsForTarget (&dec);
|
||||
}
|
||||
commandManager->registerAllCommandsForTarget (this);
|
||||
commandManager->registerAllCommandsForTarget (getProjectContentComponent());
|
||||
|
||||
// update key mappings..
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,8 +56,6 @@ public:
|
|||
Project* getProject() const { return project; }
|
||||
bool needsSaving() const { return false; }
|
||||
bool save() { return true; }
|
||||
bool canSaveAs() const { return false; }
|
||||
bool saveAs() { return false; }
|
||||
bool hasFileBeenModifiedExternally() { return fileModificationTime != file.getLastModificationTime(); }
|
||||
void reloadFromFile() { fileModificationTime = file.getLastModificationTime(); }
|
||||
String getName() const { return file.getFileName(); }
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ public:
|
|||
virtual File getFile() const = 0;
|
||||
virtual bool needsSaving() const = 0;
|
||||
virtual bool save() = 0;
|
||||
virtual bool canSaveAs() const = 0;
|
||||
virtual bool saveAs() = 0;
|
||||
virtual bool hasFileBeenModifiedExternally() = 0;
|
||||
virtual void reloadFromFile() = 0;
|
||||
virtual Component* createEditor() = 0;
|
||||
|
|
@ -144,7 +142,6 @@ public:
|
|||
bool isForNode (const ValueTree& node) const { return false; }
|
||||
bool refersToProject (Project& p) const { return project == &p; }
|
||||
Project* getProject() const { return project; }
|
||||
bool canSaveAs() const { return true; }
|
||||
String getName() const { return getFile().getFileName(); }
|
||||
String getType() const { return getFile().getFileExtension() + " file"; }
|
||||
File getFile() const { return modDetector.getFile(); }
|
||||
|
|
@ -178,12 +175,6 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool saveAs()
|
||||
{
|
||||
jassertfalse; //xxx todo
|
||||
return false;
|
||||
}
|
||||
|
||||
Component* createEditor();
|
||||
Component* createViewer() { return createEditor(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -215,19 +215,24 @@ ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget()
|
|||
|
||||
void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
|
||||
{
|
||||
const CommandID ids[] = { CommandIDs::saveProject,
|
||||
CommandIDs::saveProjectAs,
|
||||
const CommandID ids[] = { CommandIDs::saveDocument,
|
||||
CommandIDs::closeDocument,
|
||||
CommandIDs::saveProject,
|
||||
CommandIDs::closeProject,
|
||||
CommandIDs::openInIDE,
|
||||
CommandIDs::saveAndOpenInIDE,
|
||||
CommandIDs::showProjectSettings,
|
||||
StandardApplicationCommandIDs::del};
|
||||
StandardApplicationCommandIDs::del };
|
||||
|
||||
commands.addArray (ids, numElementsInArray (ids));
|
||||
}
|
||||
|
||||
void ProjectContentComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
|
||||
{
|
||||
String documentName;
|
||||
if (currentDocument != nullptr)
|
||||
documentName = " '" + currentDocument->getName().substring (0, 32) + "'";
|
||||
|
||||
switch (commandID)
|
||||
{
|
||||
case CommandIDs::saveProject:
|
||||
|
|
@ -235,15 +240,6 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica
|
|||
"Saves the current project",
|
||||
CommandCategories::general, 0);
|
||||
result.setActive (project != nullptr);
|
||||
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
|
||||
break;
|
||||
|
||||
case CommandIDs::saveProjectAs:
|
||||
result.setInfo ("Save Project As...",
|
||||
"Saves the current project to a different filename",
|
||||
CommandCategories::general, 0);
|
||||
result.setActive (project != nullptr);
|
||||
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
|
||||
break;
|
||||
|
||||
case CommandIDs::closeProject:
|
||||
|
|
@ -253,6 +249,26 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica
|
|||
result.setActive (project != nullptr);
|
||||
break;
|
||||
|
||||
case CommandIDs::saveDocument:
|
||||
result.setInfo ("Save" + documentName,
|
||||
"Saves the current document",
|
||||
CommandCategories::general, 0);
|
||||
result.setActive (currentDocument != nullptr || project != nullptr);
|
||||
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
|
||||
break;
|
||||
|
||||
case CommandIDs::closeDocument:
|
||||
result.setInfo ("Close" + documentName,
|
||||
"Closes the current document",
|
||||
CommandCategories::general, 0);
|
||||
result.setActive (currentDocument != nullptr);
|
||||
#if JUCE_MAC
|
||||
result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0));
|
||||
#else
|
||||
result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CommandIDs::openInIDE:
|
||||
#if JUCE_MAC
|
||||
result.setInfo ("Open in XCode...",
|
||||
|
|
@ -310,36 +326,37 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
|
|||
switch (info.commandID)
|
||||
{
|
||||
case CommandIDs::saveProject:
|
||||
if (project != nullptr)
|
||||
{
|
||||
if (! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
project->save (true, true);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CommandIDs::saveProjectAs:
|
||||
if (project != nullptr)
|
||||
{
|
||||
if (! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
project->saveAsInteractive (true);
|
||||
}
|
||||
if (project != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
project->save (true, true);
|
||||
|
||||
break;
|
||||
|
||||
case CommandIDs::closeProject:
|
||||
{
|
||||
MainWindow* mw = findParentComponentOfClass<MainWindow>();
|
||||
MainWindow* const mw = findParentComponentOfClass<MainWindow>();
|
||||
|
||||
if (mw != nullptr)
|
||||
{
|
||||
if (! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
mw->closeCurrentProject();
|
||||
}
|
||||
if (mw != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
mw->closeCurrentProject();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CommandIDs::saveDocument:
|
||||
if (! reinvokeCommandAfterClosingPropertyEditors (info))
|
||||
{
|
||||
if (currentDocument != nullptr)
|
||||
currentDocument->save();
|
||||
else if (project != nullptr)
|
||||
project->save (true, true);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CommandIDs::closeDocument:
|
||||
if (currentDocument != nullptr)
|
||||
OpenDocumentManager::getInstance()->closeDocument (currentDocument, true);
|
||||
break;
|
||||
|
||||
case CommandIDs::openInIDE:
|
||||
if (project != nullptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -273,8 +273,7 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault
|
|||
|
||||
doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < mappings.size(); ++i)
|
||||
for (int i = 0; i < mappings.size(); ++i)
|
||||
{
|
||||
const CommandMapping* const cm = mappings.getUnchecked(i);
|
||||
|
||||
|
|
@ -294,7 +293,7 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault
|
|||
|
||||
if (defaultSet != nullptr)
|
||||
{
|
||||
for (i = 0; i < defaultSet->mappings.size(); ++i)
|
||||
for (int i = 0; i < defaultSet->mappings.size(); ++i)
|
||||
{
|
||||
const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue