コード例 #1
0
ファイル: Commands.cs プロジェクト: coreafive/XLE
        private void PerformExportToGame()
        {
            // Export operations are performed on nodes in the dom hierarchy
            // We need to search through our nodes to find those that implement
            // IExportable.
            //
            // Sometimes these nodes might be able to provide previews of the
            // export operation (though maybe only when exporting simple text
            // format files).

                // Awkward to get the root node from here... Technically, the context
                // should be an IGame. But we can cast that directly to a DomNodeAdapter.
            var rootNode = m_designView.ActiveView.DesignView.Context as DomNodeAdapter;
            if (rootNode==null) return;

            var queuedExports = new List<ControlsLibrary.ExportPreviewDialog.QueuedExport>();
            var exportNodes = new List<PendingExport>();
            foreach (var n in rootNode.DomNode.Subtree)     // LevelSubtree has a small bug "foreach (var child in Children)" -> "foreach (var child in node.Children)"
            {
                var exportable = n.As<IExportable>();
                if (exportable == null) continue;

                var exports = exportable.BuildPendingExports();
                foreach (var preview in exports)
                {
                    var e = new ControlsLibrary.ExportPreviewDialog.QueuedExport
                        {
                            DoExport = true,
                            TargetFile = preview.TargetFile,
                            Category = exportable.ExportCategory
                        };

                    if (preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.Text
                        || preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.MetricsText)
                    {
                        e.TextPreview = preview.Export._preview;
                        var comparisonFile = e.TargetFile;
                        if (preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.MetricsText)
                            comparisonFile += ".metrics";

                        try
                        {
                            e.ExistingText = System.IO.File.ReadAllText(comparisonFile);
                        }
                        catch
                        {
                            e.ExistingText = String.Format("<<Error while reading file {0}>>".Localize(), comparisonFile);
                        }
                    }
                    e.Messages = preview.Export._messages;
                    queuedExports.Add(e);
                    exportNodes.Add(preview);
                }
            }

            using (var dialog = new ControlsLibrary.ExportPreviewDialog())
            {
                dialog.QueuedExports = queuedExports;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                        // export now..
                        //  (for long export operations we could pop up a 
                        //  progress bar, or push this into a background thread)
                    for (int c = 0; c < queuedExports.Count; ++c)
                    {
                        if (queuedExports[c].DoExport)
                            exportNodes[c].Export.PerformExport(queuedExports[c].TargetFile);
                    }
                }
            } 
        }
コード例 #2
0
ファイル: Commands.cs プロジェクト: coreafive/XLE
        private void PerformExportToGame()
        {
            // Export operations are performed on nodes in the dom hierarchy
            // We need to search through our nodes to find those that implement
            // IExportable.
            //
            // Sometimes these nodes might be able to provide previews of the
            // export operation (though maybe only when exporting simple text
            // format files).

            // Awkward to get the root node from here... Technically, the context
            // should be an IGame. But we can cast that directly to a DomNodeAdapter.
            var rootNode = m_designView.ActiveView.DesignView.Context as DomNodeAdapter;

            if (rootNode == null)
            {
                return;
            }

            var queuedExports = new List <ControlsLibrary.ExportPreviewDialog.QueuedExport>();
            var exportNodes   = new List <PendingExport>();

            foreach (var n in rootNode.DomNode.Subtree)     // LevelSubtree has a small bug "foreach (var child in Children)" -> "foreach (var child in node.Children)"
            {
                var exportable = n.As <IExportable>();
                if (exportable == null)
                {
                    continue;
                }

                var exports = exportable.BuildPendingExports();
                foreach (var preview in exports)
                {
                    var e = new ControlsLibrary.ExportPreviewDialog.QueuedExport
                    {
                        DoExport   = true,
                        TargetFile = preview.TargetFile,
                        Category   = exportable.ExportCategory
                    };

                    if (preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.Text ||
                        preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.MetricsText)
                    {
                        e.TextPreview = preview.Export._preview;
                        var comparisonFile = e.TargetFile;
                        if (preview.Export._previewType == GUILayer.EditorSceneManager.PendingExport.Type.MetricsText)
                        {
                            comparisonFile += ".metrics";
                        }

                        try
                        {
                            e.ExistingText = System.IO.File.ReadAllText(comparisonFile);
                        }
                        catch
                        {
                            e.ExistingText = String.Format("<<Error while reading file {0}>>".Localize(), comparisonFile);
                        }
                    }
                    e.Messages = preview.Export._messages;
                    queuedExports.Add(e);
                    exportNodes.Add(preview);
                }
            }

            using (var dialog = new ControlsLibrary.ExportPreviewDialog())
            {
                dialog.QueuedExports = queuedExports;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // export now..
                    //  (for long export operations we could pop up a
                    //  progress bar, or push this into a background thread)
                    for (int c = 0; c < queuedExports.Count; ++c)
                    {
                        if (queuedExports[c].DoExport)
                        {
                            exportNodes[c].Export.PerformExport(queuedExports[c].TargetFile);
                        }
                    }
                }
            }
        }