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

Projucer: Improved method for saving and restoring previously selected GUI component tabs

This commit is contained in:
ed 2017-08-03 14:37:47 +01:00
parent 39cb22cf5e
commit 0d1ed9ba99
4 changed files with 52 additions and 20 deletions

View file

@ -221,15 +221,6 @@ void JucerDocument::setInitialSize (int w, int h)
}
}
void JucerDocument::setLastSelectedTabIndex (int index)
{
if (index != lastTab)
{
lastTab = index;
flushChangesToDocuments (nullptr);
}
}
//==============================================================================
bool JucerDocument::isSnapActive (const bool disableIfCtrlKeyDown) const noexcept
{
@ -359,7 +350,6 @@ XmlElement* JucerDocument::createXml() const
doc->setAttribute ("fixedSize", fixedSize);
doc->setAttribute ("initialWidth", initialWidth);
doc->setAttribute ("initialHeight", initialHeight);
doc->setAttribute ("lastSelectedTab", lastTab);
if (activeExtraMethods.size() > 0)
{
@ -392,7 +382,6 @@ bool JucerDocument::loadFromXml (const XmlElement& xml)
fixedSize = xml.getBoolAttribute ("fixedSize", false);
initialWidth = xml.getIntAttribute ("initialWidth", 300);
initialHeight = xml.getIntAttribute ("initialHeight", 200);
lastTab = xml.getIntAttribute ("lastSelectedTab", 1);
snapGridPixels = xml.getIntAttribute ("snapPixels", snapGridPixels);
snapActive = xml.getBoolAttribute ("snapActive", snapActive);

View file

@ -93,9 +93,6 @@ public:
int getInitialWidth() const noexcept { return initialWidth; }
int getInitialHeight() const noexcept { return initialHeight; }
void setLastSelectedTabIndex (int index);
int getLastSelectedTabIndex() const noexcept { return lastTab; }
//==============================================================================
virtual int getNumPaintRoutines() const = 0;
virtual StringArray getPaintRoutineNames() const = 0;
@ -150,7 +147,6 @@ protected:
bool fixedSize = false;
int initialWidth = 600, initialHeight = 400;
int lastTab = 1;
BinaryResources resources;

View file

@ -347,8 +347,7 @@ JucerDocumentEditor::JucerDocumentEditor (JucerDocument* const doc)
document->getCppDocument()), true);
updateTabs();
tabbedComponent.setCurrentTabIndex (document->getLastSelectedTabIndex());
restoreLastSelectedTab();
document->addChangeListener (this);
@ -361,9 +360,7 @@ JucerDocumentEditor::JucerDocumentEditor (JucerDocument* const doc)
JucerDocumentEditor::~JucerDocumentEditor()
{
if (document != nullptr)
document->setLastSelectedTabIndex (tabbedComponent.getCurrentTabIndex());
saveLastSelectedTab();
tabbedComponent.clearTabs();
}
@ -597,6 +594,53 @@ void JucerDocumentEditor::addComponent (const int index)
document->beginTransaction();
}
}
//==============================================================================
void JucerDocumentEditor::saveLastSelectedTab() const
{
if (document != nullptr)
{
auto* project = document->getCppDocument().getProject();
if (project != nullptr)
{
auto& properties = project->getStoredProperties();
ScopedPointer<XmlElement> root (properties.getXmlValue ("GUIComponentsLastTab"));
if (root == nullptr)
root = new XmlElement ("FILES");
auto fileName = document->getCppFile().getFileName();
auto* child = root->getChildByName (fileName);
if (child == nullptr)
child = root->createNewChildElement (fileName);
child->setAttribute ("tab", tabbedComponent.getCurrentTabIndex());
properties.setValue ("GUIComponentsLastTab", root);
}
}
}
void JucerDocumentEditor::restoreLastSelectedTab()
{
if (document != nullptr)
{
auto* project = document->getCppDocument().getProject();
if (project != nullptr)
{
ScopedPointer<XmlElement> root (project->getStoredProperties().getXmlValue ("GUIComponentsLastTab"));
if (root != nullptr)
{
auto* child = root->getChildByName (document->getCppFile().getFileName());
if (child != nullptr)
tabbedComponent.setCurrentTabIndex (child->getIntAttribute ("tab"));
}
}
}
}
//==============================================================================
bool JucerDocumentEditor::isSomethingSelected() const

View file

@ -88,6 +88,9 @@ private:
int lastViewportX = 0, lastViewportY = 0;
double currentZoomLevel = 1.0;
void saveLastSelectedTab() const;
void restoreLastSelectedTab();
bool isSomethingSelected() const;
bool areMultipleThingsSelected() const;