Example #1
0
        public bool CheckForUnsavedChanges(bool assetModifiedExternally = false)
        {
            if (!hasUnsavedChanges)
            {
                return(true);
            }

            if (assetModifiedExternally)
            {
                // TODO: Nothing can be done here yet, other than telling the user
                // what just happened. Adding the ability to save unsaved changes
                // after a file has been modified externally will require some
                // major changes to the document flow.
                var promptTitle = string.Format(BuilderConstants.SaveDialogExternalChangesPromptTitle,
                                                m_Document.uxmlPath);
                BuilderDialogsUtility.DisplayDialog(
                    promptTitle,
                    BuilderConstants.SaveDialogExternalChangesPromptMessage);

                return(true);
            }
            else
            {
                var option = BuilderDialogsUtility.DisplayDialogComplex(
                    BuilderConstants.SaveDialogSaveChangesPromptTitle,
                    BuilderConstants.SaveDialogSaveChangesPromptMessage,
                    BuilderConstants.DialogSaveActionOption,
                    BuilderConstants.DialogCancelOption,
                    BuilderConstants.DialogDontSaveActionOption);

                switch (option)
                {
                // Save
                case 0:
                    return(SaveUnsavedChanges());

                // Cancel
                case 1:
                    return(false);

                // Don't Save
                case 2:
                    RestoreAssetsFromBackup();
                    return(true);
                }
            }

            return(true);
        }
        public bool CheckForUnsavedChanges()
        {
            if (!hasUnsavedChanges)
            {
                return(true);
            }

            var option = BuilderDialogsUtility.DisplayDialogComplex(
                BuilderConstants.SaveDialogSaveChangesPromptTitle,
                BuilderConstants.SaveDialogSaveChangesPromptMessage,
                BuilderConstants.DialogSaveActionOption,
                BuilderConstants.DialogCancelOption,
                BuilderConstants.DialogDontSaveActionOption);

            switch (option)
            {
            // Save
            case 0:
                if (!string.IsNullOrEmpty(uxmlPath) && !string.IsNullOrEmpty(ussPath))
                {
                    SaveNewDocument(uxmlPath, ussPath, null, false);
                    return(true);
                }
                else
                {
                    var builderWindow = Builder.ActiveWindow;
                    if (builderWindow == null)
                    {
                        builderWindow = Builder.ShowWindow();
                    }

                    builderWindow.toolbar.PromptSaveDocumentDialog();
                    return(false);
                }

            // Cancel
            case 1:
                return(false);

            // Don't Save
            case 2:
                return(true);
            }

            return(true);
        }
Example #3
0
        StyleSheet GetOrCreateOrAddMainStyleSheet()
        {
            // Get StyleSheet.
            var mainStyleSheet = m_PaneWindow.document.activeStyleSheet;

            if (mainStyleSheet == null)
            {
                var option = BuilderDialogsUtility.DisplayDialogComplex(
                    BuilderConstants.ExtractInlineStylesNoUSSDialogTitle,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogMessage,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogNewUSSOption,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogExistingUSSOption,
                    BuilderConstants.DialogCancelOption);

                switch (option)
                {
                // New
                case 0:
                    if (!BuilderStyleSheetsUtilities.CreateNewUSSAsset(m_PaneWindow))
                    {
                        return(null);
                    }
                    break;

                // Existing
                case 1:
                    if (!BuilderStyleSheetsUtilities.AddExistingUSSToAsset(m_PaneWindow))
                    {
                        return(null);
                    }
                    break;

                // Cancel
                case 2:
                    return(null);
                }

                mainStyleSheet = m_PaneWindow.document.activeStyleSheet;
            }
            return(mainStyleSheet);
        }
        void ExtractLocalStylesToNewClass(string className)
        {
            // Get StyleSheet.
            var mainStyleSheet = m_PaneWindow.document.activeStyleSheet;

            if (mainStyleSheet == null)
            {
                var option = BuilderDialogsUtility.DisplayDialogComplex(
                    BuilderConstants.ExtractInlineStylesNoUSSDialogTitle,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogMessage,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogNewUSSOption,
                    BuilderConstants.ExtractInlineStylesNoUSSDialogExistingUSSOption,
                    BuilderConstants.DialogCancelOption);

                switch (option)
                {
                // New
                case 0:
                    if (!BuilderStyleSheetsUtilities.CreateNewUSSAsset(m_PaneWindow))
                    {
                        return;
                    }
                    break;

                // Existing
                case 1:
                    if (!BuilderStyleSheetsUtilities.AddExistingUSSToAsset(m_PaneWindow))
                    {
                        return;
                    }
                    break;

                // Cancel
                case 2:
                    return;
                }

                mainStyleSheet = m_PaneWindow.document.activeStyleSheet;
            }

            PreAddStyleClass(className);

            // Create new selector in main StyleSheet.
            var selectorString       = BuilderConstants.UssSelectorClassNameSymbol + className;
            var selectorsRootElement = BuilderSharedStyles.GetSelectorContainerElement(m_Selection.documentElement);
            var newSelector          = BuilderSharedStyles.CreateNewSelector(selectorsRootElement, mainStyleSheet, selectorString);

            // Transfer all properties from inline styles rule to new selector.
            mainStyleSheet.TransferRulePropertiesToSelector(
                newSelector, m_Inspector.styleSheet, m_Inspector.currentRule);

            // Update VisualTreeAsset.
            BuilderAssetUtilities.AddStyleClassToElementInAsset(
                m_PaneWindow.document, currentVisualElement, className);

            // Overwrite Undo Message.
            Undo.RegisterCompleteObjectUndo(
                new Object[] { m_PaneWindow.document.visualTreeAsset, mainStyleSheet },
                BuilderConstants.CreateStyleClassUndoMessage);

            // We actually want to get the notification back and refresh ourselves.
            m_Selection.NotifyOfStylingChange(null);
            m_Selection.NotifyOfHierarchyChange(null, currentVisualElement);
        }
Example #5
0
        public bool CheckForUnsavedChanges(bool assetModifiedExternally = false)
        {
            if (!hasUnsavedChanges)
            {
                return(true);
            }

            int option = -1;

            if (assetModifiedExternally)
            {
                // TODO: Nothing can be done here yet, other than telling the user
                // what just happened. Adding the ability to save unsaved changes
                // after a file has been modified externally will require some
                // major changes to the document flow.
                BuilderDialogsUtility.DisplayDialog(
                    BuilderConstants.SaveDialogExternalChangesPromptTitle,
                    BuilderConstants.SaveDialogExternalChangesPromptMessage);

                return(true);
            }
            else
            {
                option = BuilderDialogsUtility.DisplayDialogComplex(
                    BuilderConstants.SaveDialogSaveChangesPromptTitle,
                    BuilderConstants.SaveDialogSaveChangesPromptMessage,
                    BuilderConstants.DialogSaveActionOption,
                    BuilderConstants.DialogCancelOption,
                    BuilderConstants.DialogDontSaveActionOption);

                switch (option)
                {
                // Save
                case 0:
                    if (!string.IsNullOrEmpty(uxmlPath) && !string.IsNullOrEmpty(ussPath))
                    {
                        SaveNewDocument(uxmlPath, ussPath, null, false);
                        return(true);
                    }
                    else
                    {
                        var builderWindow = Builder.ActiveWindow;
                        if (builderWindow == null)
                        {
                            builderWindow = Builder.ShowWindow();
                        }

                        builderWindow.toolbar.PromptSaveDocumentDialog();
                        return(false);
                    }

                // Cancel
                case 1:
                    return(false);

                // Don't Save
                case 2:
                    RestoreAssetsFromBackup();
                    return(true);
                }
            }

            return(true);
        }