| @@ -29,8 +29,8 @@ | |||
| //============================================================================== | |||
| DocumentEditorComponent::DocumentEditorComponent (OpenDocumentManager::Document* document_) | |||
| : document (document_) | |||
| DocumentEditorComponent::DocumentEditorComponent (OpenDocumentManager::Document* doc) | |||
| : document (doc) | |||
| { | |||
| IntrojucerApp::getApp().openDocumentManager.addListener (this); | |||
| } | |||
| @@ -55,3 +55,9 @@ void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Documen | |||
| jassertfalse | |||
| } | |||
| } | |||
| void DocumentEditorComponent::setEditedState (bool /*hasBeenEdited*/) | |||
| { | |||
| if (ProjectContentComponent* pcc = findParentComponentOfClass<ProjectContentComponent>()) | |||
| pcc->updateMainWindowTitle(); | |||
| } | |||
| @@ -46,6 +46,8 @@ public: | |||
| protected: | |||
| OpenDocumentManager::Document* document; | |||
| void setEditedState (bool hasBeenEdited); | |||
| private: | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DocumentEditorComponent) | |||
| }; | |||
| @@ -26,6 +26,7 @@ | |||
| #include "jucer_SourceCodeEditor.h" | |||
| #include "../Application/jucer_OpenDocumentManager.h" | |||
| //============================================================================== | |||
| SourceCodeDocument::SourceCodeDocument (Project* p, const File& f) | |||
| : modDetector (f), project (p) | |||
| @@ -104,6 +105,9 @@ SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* doc) | |||
| SourceCodeEditor::~SourceCodeEditor() | |||
| { | |||
| if (editor != nullptr) | |||
| editor->getDocument().removeListener (this); | |||
| getAppSettings().appearance.settings.removeListener (this); | |||
| if (SourceCodeDocument* doc = dynamic_cast <SourceCodeDocument*> (getDocument())) | |||
| @@ -120,6 +124,9 @@ void SourceCodeEditor::createEditor (CodeDocument& codeDocument) | |||
| void SourceCodeEditor::setEditor (CodeEditorComponent* newEditor) | |||
| { | |||
| if (editor != nullptr) | |||
| editor->getDocument().removeListener (this); | |||
| addAndMakeVisible (editor = newEditor); | |||
| editor->setFont (AppearanceSettings::getDefaultCodeFont()); | |||
| @@ -127,6 +134,8 @@ void SourceCodeEditor::setEditor (CodeEditorComponent* newEditor) | |||
| updateColourScheme(); | |||
| getAppSettings().appearance.settings.addListener (this); | |||
| editor->getDocument().addListener (this); | |||
| } | |||
| void SourceCodeEditor::scrollToKeepRangeOnScreen (const Range<int>& range) | |||
| @@ -160,6 +169,11 @@ void SourceCodeEditor::resized() | |||
| void SourceCodeEditor::updateColourScheme() { getAppSettings().appearance.applyToCodeEditor (*editor); } | |||
| void SourceCodeEditor::checkSaveState() | |||
| { | |||
| setEditedState (getDocument()->needsSaving()); | |||
| } | |||
| void SourceCodeEditor::valueTreePropertyChanged (ValueTree&, const Identifier&) { updateColourScheme(); } | |||
| void SourceCodeEditor::valueTreeChildAdded (ValueTree&, ValueTree&) { updateColourScheme(); } | |||
| void SourceCodeEditor::valueTreeChildRemoved (ValueTree&, ValueTree&) { updateColourScheme(); } | |||
| @@ -167,6 +181,8 @@ void SourceCodeEditor::valueTreeChildOrderChanged (ValueTree&) | |||
| void SourceCodeEditor::valueTreeParentChanged (ValueTree&) { updateColourScheme(); } | |||
| void SourceCodeEditor::valueTreeRedirected (ValueTree&) { updateColourScheme(); } | |||
| void SourceCodeEditor::codeDocumentTextInserted (const String&, int) { checkSaveState(); } | |||
| void SourceCodeEditor::codeDocumentTextDeleted (int, int) { checkSaveState(); } | |||
| //============================================================================== | |||
| GenericCodeEditorComponent::GenericCodeEditorComponent (const File& f, CodeDocument& codeDocument, | |||
| @@ -134,7 +134,8 @@ protected: | |||
| //============================================================================== | |||
| class SourceCodeEditor : public DocumentEditorComponent, | |||
| private ValueTree::Listener | |||
| private ValueTree::Listener, | |||
| private CodeDocument::Listener | |||
| { | |||
| public: | |||
| SourceCodeEditor (OpenDocumentManager::Document* document); | |||
| @@ -158,7 +159,11 @@ private: | |||
| void valueTreeParentChanged (ValueTree&); | |||
| void valueTreeRedirected (ValueTree&); | |||
| void codeDocumentTextInserted (const String&, int); | |||
| void codeDocumentTextDeleted (int, int); | |||
| void updateColourScheme(); | |||
| void checkSaveState(); | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SourceCodeEditor); | |||
| }; | |||
| @@ -368,7 +368,6 @@ bool ProjectContentComponent::showDocument (OpenDocumentManager::Document* doc, | |||
| contentView->grabKeyboardFocus(); | |||
| return opened; | |||
| } | |||
| void ProjectContentComponent::hideEditor() | |||
| @@ -426,6 +425,8 @@ void ProjectContentComponent::saveDocument() | |||
| currentDocument->save(); | |||
| else | |||
| saveProject(); | |||
| updateMainWindowTitle(); | |||
| } | |||
| bool ProjectContentComponent::goToPreviousFile() | |||
| @@ -493,7 +494,23 @@ void ProjectContentComponent::deleteSelectedTreeItems() | |||
| void ProjectContentComponent::updateMainWindowTitle() | |||
| { | |||
| if (MainWindow* mw = findParentComponentOfClass<MainWindow>()) | |||
| mw->updateTitle (currentDocument != nullptr ? currentDocument->getName() : String::empty); | |||
| { | |||
| String title; | |||
| bool edited = false; | |||
| if (currentDocument != nullptr) | |||
| { | |||
| title = currentDocument->getName(); | |||
| edited = currentDocument->needsSaving(); | |||
| } | |||
| if (ComponentPeer* peer = mw->getPeer()) | |||
| if (! peer->setDocumentEditedStatus (edited)) | |||
| if (edited) | |||
| title << "*"; | |||
| mw->updateTitle (title); | |||
| } | |||
| } | |||
| void ProjectContentComponent::showBubbleMessage (const Rectangle<int>& pos, const String& text) | |||