Skip to content
Permalink
Browse files

Projucer: Mark modified files with an asterisk in the file tree panel

  • Loading branch information...
ed95 committed May 21, 2018
1 parent c967a39 commit eed45b7462cb983ce741d4fde7b90b2df4d2a98f
@@ -1055,7 +1055,7 @@ bool ProjucerApplication::perform (const InvocationInfo& info)
case CommandIDs::newPIP: createNewPIP(); break;
case CommandIDs::open: askUserToOpenFile(); break;
case CommandIDs::launchDemoRunner: launchDemoRunner(); break;
case CommandIDs::saveAll: openDocumentManager.saveAll(); break;
case CommandIDs::saveAll: saveAllDocuments(); break;
case CommandIDs::closeAllWindows: closeAllMainWindowsAndQuitIfNeeded(); break;
case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
case CommandIDs::clearRecentFiles: clearRecentFiles(); break;
@@ -1120,6 +1120,15 @@ bool ProjucerApplication::openFile (const File& file)
return mainWindowList.openFile (file);
}

void ProjucerApplication::saveAllDocuments()
{
openDocumentManager.saveAll();

for (int i = 0; i < mainWindowList.windows.size(); ++i)
if (auto* pcc = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
pcc->refreshProjectTreeFileStatuses();
}

bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
{
return openDocumentManager.closeAll (askUserToSave);
@@ -96,6 +96,7 @@ class ProjucerApplication : public JUCEApplication,
void createNewPIP();
void askUserToOpenFile();
bool openFile (const File&);
void saveAllDocuments();
bool closeAllDocuments (bool askUserToSave);
bool closeAllMainWindows();
void closeAllMainWindowsAndQuitIfNeeded();
@@ -47,13 +47,20 @@ bool DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Documen
{
jassert (document != nullptr);

if (ProjectContentComponent* pcc = findParentComponentOfClass<ProjectContentComponent>())
if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
pcc->hideDocument (document);
}

return true;
}

void DocumentEditorComponent::setEditedState (bool /*hasBeenEdited*/)
void DocumentEditorComponent::setEditedState (bool hasBeenEdited)
{
if (hasBeenEdited != lastEditedState)
{
if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
pcc->refreshProjectTreeFileStatuses();

lastEditedState = hasBeenEdited;
}
}
@@ -43,6 +43,7 @@ class DocumentEditorComponent : public Component,

protected:
OpenDocumentManager::Document* document;
bool lastEditedState = false;

void setEditedState (bool hasBeenEdited);

@@ -465,6 +465,21 @@ class SourceFileItem : public FileTreeItemBase
return getFile().getFileName();
}

void paintItem (Graphics& g, int width, int height) override
{
JucerTreeViewBase::paintItem (g, width, height);

if (item.needsSaving())
{
auto bounds = g.getClipBounds().withY (0).withHeight (height);

g.setFont (getFont());
g.setColour (getContentColour (false));

g.drawFittedText ("*", bounds.removeFromLeft (height), Justification::centred, 1);
}
}

static File findCorrespondingHeaderOrCpp (const File& f)
{
if (f.hasFileExtension (sourceFileExtensions)) return f.withFileExtension (".h");
@@ -334,6 +334,13 @@ void ProjectContentComponent::changeListenerCallback (ChangeBroadcaster*)
updateMissingFileStatuses();
}

void ProjectContentComponent::refreshProjectTreeFileStatuses()
{
if (auto* projectTab = getProjectTab())
if (auto* fileTree = projectTab->getFileTreePanel())
fileTree->repaint();
}

void ProjectContentComponent::updateMissingFileStatuses()
{
if (auto* pTab = getProjectTab())
@@ -482,6 +489,8 @@ void ProjectContentComponent::saveDocument()
{
if (! currentDocument->save())
showSaveWarning (currentDocument);

refreshProjectTreeFileStatuses();
}
else
{
@@ -491,8 +500,13 @@ void ProjectContentComponent::saveDocument()

void ProjectContentComponent::saveAs()
{
if (currentDocument != nullptr && ! currentDocument->saveAs())
showSaveWarning (currentDocument);
if (currentDocument != nullptr)
{
if (! currentDocument->saveAs())
showSaveWarning (currentDocument);

refreshProjectTreeFileStatuses();
}
}

bool ProjectContentComponent::goToPreviousFile()
@@ -97,6 +97,7 @@ class ProjectContentComponent : public Component,

void deleteSelectedTreeItems();

void refreshProjectTreeFileStatuses();
void updateMissingFileStatuses();
void createProjectTabs();
void deleteProjectTabs();
@@ -1574,6 +1574,23 @@ bool Project::Item::isIconCrossedOut() const
|| getFile().hasFileExtension (headerFileExtensions));
}

bool Project::Item::needsSaving() const noexcept
{
auto& odm = ProjucerApplication::getApp().openDocumentManager;

if (odm.anyFilesNeedSaving())
{
for (int i = 0; i < odm.getNumOpenDocuments(); ++i)
{
auto* doc = odm.getOpenDocument (i);
if (doc->needsSaving() && doc->getFile() == getFile())
return true;
}
}

return false;
}

//==============================================================================
ValueTree Project::getConfigNode()
{
@@ -300,6 +300,8 @@ class Project : public FileBasedDocument,
Icon getIcon (bool isOpen = false) const;
bool isIconCrossedOut() const;

bool needsSaving() const noexcept;

Project& project;
ValueTree state;

0 comments on commit eed45b7

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.