Example #1
0
        bool PostSaveToDiskChecksAndFixes(string newUxmlPath, bool needsFullRefresh)
        {
            var oldVTAReference = m_VisualTreeAsset;
            var oldUxmlPath     = uxmlPath;
            var hasNewUxmlPath  = !string.IsNullOrEmpty(newUxmlPath) && newUxmlPath != oldUxmlPath;
            var localUxmlPath   = !string.IsNullOrEmpty(newUxmlPath) ? newUxmlPath : oldUxmlPath;

            m_VisualTreeAsset = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(localUxmlPath);
            var newIsDifferentFromOld = m_VisualTreeAsset != oldVTAReference;

            // If we have a new uxmlPath, it means we're saving as and we need to reset the
            // original document to stock.
            if (hasNewUxmlPath && newIsDifferentFromOld && !string.IsNullOrEmpty(oldUxmlPath))
            {
                m_DocumentBeingSavedExplicitly = true;
                AssetDatabase.ImportAsset(oldUxmlPath, ImportAssetOptions.ForceUpdate);
                m_DocumentBeingSavedExplicitly = false;
            }

            needsFullRefresh |= newIsDifferentFromOld;

            // Check if the UXML asset has changed and reload it.
            if (needsFullRefresh)
            {
                // To get all the selection markers into the new assets.
                m_VisualTreeAssetBackup.DeepOverwrite(m_VisualTreeAsset);
                m_VisualTreeAsset.UpdateUsingEntries();

                // Update hash. Otherwise we end up with the old overwritten contentHash
                var hash = UXMLImporterImpl.GenerateHash(localUxmlPath);
                m_VisualTreeAsset.contentHash = hash.GetHashCode();
            }
            return(needsFullRefresh);
        }
Example #2
0
        public void PostLoadDocumentStyleSheetCleanup()
        {
            m_VisualTreeAsset.UpdateUsingEntries();

            m_OpenUSSFiles.Clear();

            // Load styles.
            var styleSheetsUsed = m_VisualTreeAsset.GetAllReferencedStyleSheets();

            for (int i = 0; i < styleSheetsUsed.Count; ++i)
            {
                AddStyleSheetToDocument(styleSheetsUsed[i], null);
            }

            // For the near to mid term, we have this code that cleans up any
            // existing root element stylesheets.
            RemoveLegacyStyleSheetsFromRootAssets();

            hasUnsavedChanges = false;
        }