1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

Minor additions to OptionalScopedPointer. Internal introjucer tweaks.

This commit is contained in:
jules 2012-06-12 11:54:32 +01:00
parent 451046e990
commit f2426cc7de
7 changed files with 119 additions and 82 deletions

View file

@ -27,80 +27,9 @@
#include "jucer_FilePreviewComponent.h"
#include "../Code Editor/jucer_SourceCodeEditor.h"
//==============================================================================
class SourceCodeDocument : public OpenDocumentManager::Document
{
public:
//==============================================================================
SourceCodeDocument (Project* project_, const File& file_)
: modDetector (file_), project (project_)
{
codeDoc = new CodeDocument();
reloadFromFile();
}
Component* SourceCodeDocument::createEditor() { return SourceCodeEditor::createFor (this, *codeDoc); }
//==============================================================================
struct Type : public OpenDocumentManager::DocumentType
{
bool canOpenFile (const File& file) { return file.hasFileExtension ("cpp;h;hpp;mm;m;c;cc;cxx;txt;xml;plist;rtf;html;htm;php;py;rb;cs"); }
Document* openFile (Project* project, const File& file) { return new SourceCodeDocument (project, file); }
};
//==============================================================================
bool loadedOk() const { return true; }
bool isForFile (const File& file) const { return getFile() == file; }
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(); }
bool needsSaving() const { return codeDoc != nullptr && codeDoc->hasChangedSinceSavePoint(); }
bool hasFileBeenModifiedExternally() { return modDetector.hasBeenModified(); }
void fileHasBeenRenamed (const File& newFile) { modDetector.fileHasBeenRenamed (newFile); }
void reloadFromFile()
{
modDetector.updateHash();
ScopedPointer <InputStream> in (modDetector.getFile().createInputStream());
if (in != nullptr)
codeDoc->loadFromStream (*in);
}
bool save()
{
TemporaryFile temp (modDetector.getFile());
ScopedPointer <FileOutputStream> out (temp.getFile().createOutputStream());
if (out == nullptr || ! codeDoc->writeToStream (*out))
return false;
out = nullptr;
if (! temp.overwriteTargetFileWithTemporary())
return false;
modDetector.updateHash();
return true;
}
bool saveAs()
{
jassertfalse; //xxx todo
return false;
}
Component* createEditor() { return SourceCodeEditor::createFor (this, *codeDoc); }
Component* createViewer() { return createEditor(); }
private:
FileModificationDetector modDetector;
ScopedPointer <CodeDocument> codeDoc;
Project* project;
};
//==============================================================================
class UnknownDocument : public OpenDocumentManager::Document