Browse Source

Introjucer: tidied up some document saving behaviour.

tags/2021-05-28
jules 13 years ago
parent
commit
d2aa3a666b
9 changed files with 50 additions and 140 deletions
  1. +0
    -2
      extras/Introjucer/Source/Application/jucer_Application.h
  2. +0
    -2
      extras/Introjucer/Source/Application/jucer_CommandIDs.h
  3. +0
    -78
      extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp
  4. +0
    -7
      extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h
  5. +2
    -8
      extras/Introjucer/Source/Application/jucer_MainWindow.cpp
  6. +0
    -2
      extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp
  7. +0
    -9
      extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h
  8. +46
    -29
      extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp
  9. +2
    -3
      modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp

+ 0
- 2
extras/Introjucer/Source/Application/jucer_Application.h View File

@@ -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);


+ 0
- 2
extras/Introjucer/Source/Application/jucer_CommandIDs.h View File

@@ -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;


+ 0
- 78
extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp View File

@@ -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;
}

+ 0
- 7
extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h View File

@@ -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;


+ 2
- 8
extras/Introjucer/Source/Application/jucer_MainWindow.cpp View File

@@ -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..
{


+ 0
- 2
extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp View File

@@ -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(); }


+ 0
- 9
extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h View File

@@ -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(); }


+ 46
- 29
extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp View File

@@ -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);
}
if (project != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info))
project->save (true, true);
break;
case CommandIDs::saveProjectAs:
if (project != nullptr)
case CommandIDs::closeProject:
{
if (! reinvokeCommandAfterClosingPropertyEditors (info))
project->saveAsInteractive (true);
MainWindow* const mw = findParentComponentOfClass<MainWindow>();
if (mw != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info))
mw->closeCurrentProject();
}
break;
case CommandIDs::closeProject:
case CommandIDs::saveDocument:
if (! reinvokeCommandAfterClosingPropertyEditors (info))
{
MainWindow* mw = findParentComponentOfClass<MainWindow>();
if (mw != nullptr)
{
if (! reinvokeCommandAfterClosingPropertyEditors (info))
mw->closeCurrentProject();
}
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)
{


+ 2
- 3
modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp View File

@@ -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…
Cancel
Save