1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Projucer: Show the option to remove references or move to trash when deleting file groups and hide the file group information after deleting

This commit is contained in:
ed 2017-10-31 11:10:06 +00:00
parent 141be27dab
commit fedbb67452
5 changed files with 54 additions and 26 deletions

View file

@ -56,41 +56,52 @@ public:
void deleteItem() override { item.removeItemFromProject(); }
virtual void deleteAllSelectedItems() override
void deleteAllSelectedItems() override
{
TreeView* tree = getOwnerView();
const int numSelected = tree->getNumSelectedItems();
OwnedArray<File> filesToTrash;
OwnedArray<Project::Item> itemsToRemove;
auto* tree = getOwnerView();
Array<File> filesToTrash;
Array<Project::Item> itemsToRemove;
for (int i = 0; i < numSelected; ++i)
for (auto i = 0; i < tree->getNumSelectedItems(); ++i)
{
if (auto* p = dynamic_cast<FileTreeItemBase*> (tree->getSelectedItem (i)))
{
itemsToRemove.add (new Project::Item (p->item));
itemsToRemove.add (p->item);
if (p->getFile().existsAsFile())
filesToTrash.add (new File (p->getFile()));
if (p->item.isGroup())
{
for (auto j = 0; j < p->item.getNumChildren(); ++j)
{
auto associatedFile = p->item.getChild (j).getFile();
if (associatedFile.existsAsFile())
filesToTrash.addIfNotAlreadyThere (associatedFile);
}
}
else if (p->getFile().existsAsFile())
{
filesToTrash.addIfNotAlreadyThere (p->getFile());
}
}
}
if (filesToTrash.size() > 0)
{
String fileList;
const int maxFilesToList = 10;
for (int i = jmin (maxFilesToList, filesToTrash.size()); --i >= 0;)
fileList << filesToTrash.getUnchecked(i)->getFullPathName() << "\n";
auto maxFilesToList = 10;
for (auto i = jmin (maxFilesToList, filesToTrash.size()); --i >= 0;)
fileList << filesToTrash.getUnchecked(i).getFullPathName() << "\n";
if (filesToTrash.size() > maxFilesToList)
fileList << "\n...plus " << (filesToTrash.size() - maxFilesToList) << " more files...";
int r = AlertWindow::showYesNoCancelBox (AlertWindow::NoIcon, "Delete Project Items",
"As well as removing the selected item(s) from the project, do you also want to move their files to the trash:\n\n"
+ fileList,
"Just remove references",
"Also move files to Trash",
"Cancel",
tree->getTopLevelComponent());
auto r = AlertWindow::showYesNoCancelBox (AlertWindow::NoIcon, "Delete Project Items",
"As well as removing the selected item(s) from the project, do you also want to move their files to the trash:\n\n"
+ fileList,
"Just remove references",
"Also move files to Trash",
"Cancel",
tree->getTopLevelComponent());
if (r == 0)
return;
@ -105,7 +116,7 @@ public:
for (int i = filesToTrash.size(); --i >= 0;)
{
const File f (*filesToTrash.getUnchecked(i));
auto f = filesToTrash.getUnchecked(i);
om.closeFile (f, false);
@ -115,10 +126,17 @@ public:
}
}
for (int i = itemsToRemove.size(); --i >= 0;)
for (auto i = itemsToRemove.size(); --i >= 0;)
{
if (auto* itemToRemove = treeRootItem->findTreeViewItem (*itemsToRemove.getUnchecked(i)))
if (auto itemToRemove = treeRootItem->findTreeViewItem (itemsToRemove.getUnchecked (i)))
{
if (auto* pcc = getProjectContentComponent())
{
if (auto* fileInfoComp = dynamic_cast<FileGroupInformationComponent*> (pcc->getEditorComponentContent()))
if (fileInfoComp->getGroupPath() == itemToRemove->getFile().getFullPathName())
pcc->hideEditor();
}
om.closeFile (itemToRemove->getFile(), false);
itemToRemove->deleteItem();
}

View file

@ -46,11 +46,9 @@ struct ProjectTreeItemBase : public JucerTreeViewBase,
void closeSettingsPage()
{
if (auto* pcc = getProjectContentComponent())
{
if (auto* content = dynamic_cast<Viewport*> (pcc->getEditorComponent()->getChildComponent (0)))
if (content->getViewedComponent()->getComponentID() == getUniqueName())
if (auto* content = pcc->getEditorComponentContent())
if (content->getComponentID() == getUniqueName())
pcc->hideEditor();
}
}
void deleteAllSelectedItems() override

View file

@ -106,6 +106,8 @@ public:
return existing.release();
}
String getGroupPath() const { return item.getFile().getFullPathName(); }
//==============================================================================
void valueTreePropertyChanged (ValueTree&, const Identifier&) override { itemChanged(); }
void valueTreeChildAdded (ValueTree&, ValueTree&) override { itemChanged(); }

View file

@ -447,6 +447,15 @@ bool ProjectContentComponent::setEditorComponent (Component* editor,
return false;
}
Component* ProjectContentComponent::getEditorComponentContent() const
{
if (contentView != nullptr)
if (auto* vp = dynamic_cast<ContentViewport*> (contentView.get()))
return vp->viewport.getViewedComponent();
return nullptr;
}
void ProjectContentComponent::closeDocument()
{
if (currentDocument != nullptr)

View file

@ -66,6 +66,7 @@ public:
void hideEditor();
bool setEditorComponent (Component* editor, OpenDocumentManager::Document* doc);
Component* getEditorComponentContent() const;
Component* getEditorComponent() const { return contentView; }
Component& getSidebarComponent() { return sidebarTabs; }