Browse Source

Introjucer: added "save as"

tags/2021-05-28
jules 12 years ago
parent
commit
12c28fd882
9 changed files with 67 additions and 30 deletions
  1. +1
    -0
      extras/Introjucer/Source/Application/jucer_Application.h
  2. +1
    -0
      extras/Introjucer/Source/Application/jucer_CommandIDs.h
  3. +1
    -0
      extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp
  4. +1
    -0
      extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h
  5. +26
    -9
      extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp
  6. +3
    -1
      extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h
  7. +26
    -4
      extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp
  8. +1
    -0
      extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h
  9. +7
    -16
      modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp

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

@@ -250,6 +250,7 @@ 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);


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

@@ -34,6 +34,7 @@ namespace CommandIDs
open = 0x200020,
closeDocument = 0x200030,
saveDocument = 0x200040,
saveDocumentAs = 0x200041,
closeProject = 0x200051,
saveProject = 0x200060,


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

@@ -54,6 +54,7 @@ public:
Project* getProject() const { return project; }
bool needsSaving() const { return false; }
bool save() { return true; }
bool saveAs() { return false; }
bool hasFileBeenModifiedExternally() { return fileModificationTime != file.getLastModificationTime(); }
void reloadFromFile() { fileModificationTime = file.getLastModificationTime(); }
String getName() const { return file.getFileName(); }


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

@@ -55,6 +55,7 @@ public:
virtual File getFile() const = 0;
virtual bool needsSaving() const = 0;
virtual bool save() = 0;
virtual bool saveAs() = 0;
virtual bool hasFileBeenModifiedExternally() = 0;
virtual void reloadFromFile() = 0;
virtual Component* createEditor() = 0;


+ 26
- 9
extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp View File

@@ -63,27 +63,44 @@ void SourceCodeDocument::reloadInternal()
{
jassert (codeDoc != nullptr);
modDetector.updateHash();
codeDoc->applyChanges (modDetector.getFile().loadFileAsString());
codeDoc->applyChanges (getFile().loadFileAsString());
codeDoc->setSavePoint();
}
bool SourceCodeDocument::save()
static bool writeCodeDocToFile (const File& file, CodeDocument& doc)
{
TemporaryFile temp (modDetector.getFile());
TemporaryFile temp (file);
{
FileOutputStream fo (temp.getFile());
if (! (fo.openedOk() && getCodeDocument().writeToStream (fo)))
if (! (fo.openedOk() && doc.writeToStream (fo)))
return false;
}
if (! temp.overwriteTargetFileWithTemporary())
return false;
return temp.overwriteTargetFileWithTemporary();
}
getCodeDocument().setSavePoint();
modDetector.updateHash();
return true;
bool SourceCodeDocument::save()
{
if (writeCodeDocToFile (getFile(), getCodeDocument()))
{
getCodeDocument().setSavePoint();
modDetector.updateHash();
return true;
}
return false;
}
bool SourceCodeDocument::saveAs()
{
FileChooser fc (TRANS("Save As..."), getFile(), "*");
if (! fc.browseForFileToSave (true))
return true;
return writeCodeDocToFile (fc.getResult(), getCodeDocument());
}
void SourceCodeDocument::updateLastState (CodeEditorComponent& editor)


+ 3
- 1
extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h View File

@@ -59,7 +59,8 @@ public:
const char* extensions[] = { "h", "hpp", nullptr };
return findCounterpart (file, extensions);
}
else if (file.hasFileExtension ("h;hpp"))
if (file.hasFileExtension ("h;hpp"))
{
const char* extensions[] = { "cpp", "mm", "cc", "cxx", "c", "m", nullptr };
return findCounterpart (file, extensions);
@@ -83,6 +84,7 @@ public:
void reloadFromFile();
bool save();
bool saveAs();
Component* createEditor();
Component* createViewer() { return createEditor(); }


+ 26
- 4
extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp View File

@@ -419,15 +419,20 @@ void ProjectContentComponent::closeDocument()
hideEditor();
}
static void showSaveWarning (OpenDocumentManager::Document* currentDocument)
{
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
TRANS("Save failed!"),
TRANS("Couldn't save the file:")
+ "\n" + currentDocument->getFile().getFullPathName());
}
void ProjectContentComponent::saveDocument()
{
if (currentDocument != nullptr)
{
if (! currentDocument->save())
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
TRANS("Save failed!"),
TRANS("Couldn't save the file:")
+ "\n" + currentDocument->getFile().getFullPathName());
showSaveWarning (currentDocument);
}
else
saveProject();
@@ -435,6 +440,12 @@ void ProjectContentComponent::saveDocument()
updateMainWindowTitle();
}
void ProjectContentComponent::saveAs()
{
if (currentDocument != nullptr && ! currentDocument->saveAs())
showSaveWarning (currentDocument);
}
bool ProjectContentComponent::goToPreviousFile()
{
OpenDocumentManager::Document* doc = recentDocumentList.getCurrentDocument();
@@ -544,6 +555,7 @@ ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget()
void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
{
const CommandID ids[] = { CommandIDs::saveDocument,
CommandIDs::saveDocumentAs,
CommandIDs::closeDocument,
CommandIDs::saveProject,
CommandIDs::closeProject,
@@ -595,6 +607,14 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
break;
case CommandIDs::saveDocumentAs:
result.setInfo ("Save As...",
"Saves the current document to a new location",
CommandCategories::general, 0);
result.setActive (currentDocument != nullptr || project != nullptr);
result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
break;
case CommandIDs::closeDocument:
result.setInfo ("Close" + documentName,
"Closes the current document",
@@ -688,6 +708,7 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
case CommandIDs::saveProject:
case CommandIDs::closeProject:
case CommandIDs::saveDocument:
case CommandIDs::saveDocumentAs:
case CommandIDs::closeDocument:
case CommandIDs::goToPreviousDoc:
case CommandIDs::goToNextDoc:
@@ -710,6 +731,7 @@ bool ProjectContentComponent::perform (const InvocationInfo& info)
case CommandIDs::saveProject: saveProject(); break;
case CommandIDs::closeProject: closeProject(); break;
case CommandIDs::saveDocument: saveDocument(); break;
case CommandIDs::saveDocumentAs: saveAs(); break;
case CommandIDs::closeDocument: closeDocument(); break;
case CommandIDs::goToPreviousDoc: goToPreviousFile(); break;


+ 1
- 0
extras/Introjucer/Source/Project/jucer_ProjectContentComponent.h View File

@@ -58,6 +58,7 @@ public:
OpenDocumentManager::Document* getCurrentDocument() const { return currentDocument; }
void closeDocument();
void saveDocument();
void saveAs();
void hideEditor();
bool setEditorComponent (Component* editor, OpenDocumentManager::Document* doc);


+ 7
- 16
modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp View File

@@ -137,15 +137,11 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
if (newFile == File::nonexistent)
{
if (askUserForFileIfNotSpecified)
{
return saveAsInteractive (true);
}
else
{
// can't save to an unspecified file
jassertfalse;
return failedToWriteToFile;
}
// can't save to an unspecified file
jassertfalse;
return failedToWriteToFile;
}
if (warnAboutOverwritingExistingFiles && newFile.exists())
@@ -208,16 +204,11 @@ FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
TRANS("discard changes"),
TRANS("cancel"));
if (r == 1)
{
// save changes
if (r == 1) // save changes
return save (true, true);
}
else if (r == 2)
{
// discard changes
if (r == 2) // discard changes
return savedOk;
}
return userCancelledSave;
}


Loading…
Cancel
Save