private TangerineApp(string[] args) { ChangeTangerineSettingsFolderIfNeed(); Orange.UserInterface.Instance = new OrangeInterface(); Orange.UserInterface.Instance.Initialize(); Widget.EnableViewCulling = false; WidgetInput.AcceptMouseBeyondWidgetByDefault = false; if (!UserPreferences.Initialize()) { UserPreferences.Instance.Clear(); UserPreferences.Instance.Add(new AppUserPreferences()); UserPreferences.Instance.Add(new UI.SceneView.SceneUserPreferences()); UserPreferences.Instance.Add(new UI.Timeline.TimelineUserPreferences()); UserPreferences.Instance.Add(new UI.FilesystemView.FilesystemUserPreferences()); UserPreferences.Instance.Add(new CoreUserPreferences()); } #if WIN TangerineSingleInstanceKeeper.Initialize(args); TangerineSingleInstanceKeeper.AnotherInstanceArgsRecieved += OpenDocumentsFromArgs; Application.Exited += () => { TangerineSingleInstanceKeeper.Instance.ReleaseInstance(); }; #endif switch (AppUserPreferences.Instance.ColorThemeKind) { case ColorTheme.ColorThemeKind.Light: SetColorTheme(ColorTheme.CreateLightTheme(), Theme.ColorTheme.CreateLightTheme()); break; case ColorTheme.ColorThemeKind.Dark: SetColorTheme(ColorTheme.CreateDarkTheme(), Theme.ColorTheme.CreateDarkTheme()); break; case ColorTheme.ColorThemeKind.Custom: { bool isDark = AppUserPreferences.Instance.ColorTheme.IsDark; ColorTheme theme = null; var flags = BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance; foreach (var category in typeof(ColorTheme).GetProperties(flags)) { var categoryValue = category.GetValue(AppUserPreferences.Instance.ColorTheme); if (categoryValue == null) { if (theme == null) { theme = isDark ? ColorTheme.CreateDarkTheme() : ColorTheme.CreateLightTheme(); } category.SetValue(AppUserPreferences.Instance.ColorTheme, category.GetValue(theme)); category.SetValue(theme, null); } } SetColorTheme(AppUserPreferences.Instance.ColorTheme, AppUserPreferences.Instance.LimeColorTheme); break; } } Application.InvalidateWindows(); LoadFont(); DockManager.Initialize(new Vector2(1024, 768)); DockManager.Instance.DocumentAreaDropFilesGesture.Recognized += new ScenesDropHandler { ShouldCreateContextMenu = false }.Handle; TangerineMenu.Create(); var mainWidget = DockManager.Instance.MainWindowWidget; mainWidget.Window.AllowDropFiles = true; mainWidget.AddChangeWatcher(() => Project.Current, _ => { SetupMainWindowTitle(mainWidget); TangerineMenu.RebuildCreateImportedTypeMenu(); }); mainWidget.AddChangeWatcher(() => CoreUserPreferences.Instance.AnimationMode, _ => Document.Current?.ForceAnimationUpdate()); mainWidget.AddChangeWatcher(() => Document.Current?.Container, _ => Document.Current?.ForceAnimationUpdate()); Application.Exiting += () => Project.Current.Close(); Application.Exited += () => { AppUserPreferences.Instance.DockState = DockManager.Instance.ExportState(); SceneUserPreferences.Instance.VisualHintsRegistry = VisualHintsRegistry.Instance; Core.UserPreferences.Instance.Save(); Orange.The.Workspace.Save(); }; var timelinePanel = new Panel("Timeline"); var inspectorPanel = new Panel("Inspector"); var searchPanel = new Panel("Hierarchy"); var animationsPanel = new Panel("Animations"); var filesystemPanel = new Panel("Filesystem"); var consolePanel = new Panel("Console"); var backupHistoryPanel = new Panel("Backups"); var documentPanel = new Panel(DockManager.DocumentAreaId, undockable: false); documentPanel.PanelWidget = documentPanel.ContentWidget; var visualHintsPanel = new Panel("Visual Hints"); var attachmentPanel = new Panel("Model3D Attachment"); var remoteScriptingPanel = new Panel("Remote Scripting"); var dockManager = DockManager.Instance; new UI.Console(consolePanel); var root = dockManager.Model.WindowPlacements.First(); var placement = new LinearPlacement(LinearPlacementDirection.Horizontal); dockManager.AddPanel(timelinePanel, root, DockSite.Top, 0.3f); dockManager.DockPlacementTo(placement, root, DockSite.Bottom, 0.6f); dockManager.AppendPanelTo(documentPanel, placement, 0.5f); var commandHandlerList = CommandHandlerList.Global; var commandsDictionary = new Dictionary <string, Command> { { animationsPanel.Id, new Command(animationsPanel.Title) }, { timelinePanel.Id, new Command(timelinePanel.Title) }, { inspectorPanel.Id, new Command(inspectorPanel.Title) }, { searchPanel.Id, new Command(searchPanel.Title) }, { filesystemPanel.Id, new Command(filesystemPanel.Title) }, { consolePanel.Id, new Command(consolePanel.Title) }, { backupHistoryPanel.Id, new Command(backupHistoryPanel.Title) }, { visualHintsPanel.Id, new Command(visualHintsPanel.Title) }, { attachmentPanel.Id, new Command(attachmentPanel.Title) }, { remoteScriptingPanel.Id, new Command(remoteScriptingPanel.Title) }, }; foreach (var pair in commandsDictionary) { commandHandlerList.Connect(pair.Value, new PanelCommandHandler(pair.Key)); TangerineMenu.PanelsMenu.Add(pair.Value); } dockManager.AddPanel(inspectorPanel, placement, DockSite.Left); var filesystemPlacement = dockManager.AddPanel(filesystemPanel, placement, DockSite.Right); dockManager.AddPanel(searchPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(animationsPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(backupHistoryPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(consolePanel, filesystemPlacement, DockSite.Bottom, 0.3f); dockManager.AddPanel(visualHintsPanel, placement, DockSite.Right, 0.3f).Hidden = true; dockManager.AddPanel(attachmentPanel, placement, DockSite.Bottom, 0.3f).Hidden = true; dockManager.AddPanel(remoteScriptingPanel, placement, DockSite.Right, 0.3f).Hidden = true; DockManagerInitialState = dockManager.ExportState(); var documentViewContainer = InitializeDocumentArea(dockManager); documentPanel.ContentWidget.Nodes.Add(dockManager.DocumentArea); dockManager.ImportState(AppUserPreferences.Instance.DockState); Document.CloseConfirmation += doc => { var alert = new AlertDialog($"Save the changes to document '{doc.Path}' before closing?", "Yes", "No", "Cancel"); switch (alert.Show()) { case 0: return(Document.CloseAction.SaveChanges); case 1: return(Document.CloseAction.DiscardChanges); case -1: default: return(Document.CloseAction.Cancel); } }; mainWidget.Tasks.Add(HandleMissingDocumentsTask); Project.HandleMissingDocuments += missingDocuments => { foreach (var d in missingDocuments) { missingDocumentsList.Add(d); } }; Project.DocumentReloadConfirmation += doc => { if (doc.IsModified) { var modifiedAlert = new AlertDialog($"{doc.Path}\n\nThis file has been modified by another program and has unsaved changes.\nDo you want to reload it from disk? ", "Yes", "No"); var res = modifiedAlert.Show(); if (res == 1 || res == -1) { doc.History.ExternalModification(); return(false); } return(true); } if (CoreUserPreferences.Instance.ReloadModifiedFiles) { return(true); } var alert = new AlertDialog($"{doc.Path}\n\nThis file has been modified by another program.\nDo you want to reload it from disk? ", "Yes, always", "Yes", "No"); var r = alert.Show(); if (r == 0) { CoreUserPreferences.Instance.ReloadModifiedFiles = true; return(true); } if (r == 2) { doc.History.ExternalModification(); return(false); } return(true); }; Project.TempFileLoadConfirmation += path => { var alert = new AlertDialog($"Do you want to load autosaved version of '{path}'?", "Yes", "No"); return(alert.Show() == 0); }; Project.OpenFileOutsideProjectAttempt += (string filePath) => { var projectFilePath = SearhForCitproj(filePath); if (projectFilePath != null && Project.Current.CitprojPath != projectFilePath) { var alert = new AlertDialog($"You're trying to open a document outside the project directory. Change the current project to '{Path.GetFileName(projectFilePath)}'?", "Yes", "No"); if (alert.Show() == 0) { if (FileOpenProject.Execute(projectFilePath)) { Project.Current.OpenDocument(filePath, true); } return; } } else if (projectFilePath == null) { AlertDialog.Show("Can't open a document outside the project directory"); } }; Project.Tasks = dockManager.MainWindowWidget.Tasks; Project.Tasks.Add(new AutosaveProcessor(() => AppUserPreferences.Instance.AutosaveDelay)); BackupManager.Instance.Activate(Project.Tasks); Document.NodeDecorators.AddFor <Spline>(n => n.CompoundPostPresenter.Add(new UI.SceneView.SplinePresenter())); Document.NodeDecorators.AddFor <Viewport3D>(n => n.CompoundPostPresenter.Add(new UI.SceneView.Spline3DPresenter())); Document.NodeDecorators.AddFor <Viewport3D>(n => n.CompoundPostPresenter.Add(new UI.SceneView.Animation3DPathPresenter())); Document.NodeDecorators.AddFor <Widget>(n => { if (n.AsWidget.SkinningWeights == null) { n.AsWidget.SkinningWeights = new SkinningWeights(); } }); Document.NodeDecorators.AddFor <PointObject>(n => { if ((n as PointObject).SkinningWeights == null) { (n as PointObject).SkinningWeights = new SkinningWeights(); } }); Animation.EasingEnabledChecker = (animation) => { var doc = Document.Current; return(doc == null || doc.PreviewScene || animation != doc.Animation); }; if (SceneUserPreferences.Instance.VisualHintsRegistry != null) { VisualHintsRegistry.Instance = SceneUserPreferences.Instance.VisualHintsRegistry; } VisualHintsRegistry.Instance.RegisterDefaultHints(); Document.NodeDecorators.AddFor <Node>(n => n.SetTangerineFlag(TangerineFlags.SceneNode, true)); dockManager.UnhandledExceptionOccurred += e => { AlertDialog.Show(e.Message + "\n" + e.StackTrace); var doc = Document.Current; if (doc != null) { while (doc.History.IsTransactionActive) { doc.History.EndTransaction(); } var closeConfirmation = Document.CloseConfirmation; try { Document.CloseConfirmation = d => { var alert = new AlertDialog($"Save the changes to document '{d.Path}' before closing?", "Yes", "No"); switch (alert.Show()) { case 0: return(Document.CloseAction.SaveChanges); default: return(Document.CloseAction.DiscardChanges); } }; var fullPath = doc.FullPath; if (!File.Exists(fullPath)) { doc.Save(); } var path = doc.Path; Project.Current.CloseDocument(doc); Project.Current.OpenDocument(path); } finally { Document.CloseConfirmation = closeConfirmation; } } }; Document.NodeDecorators.AddFor <ParticleEmitter>(n => n.CompoundPostPresenter.Add(new UI.SceneView.ParticleEmitterPresenter())); DocumentHistory.AddOperationProcessorTypes(new[] { typeof(Core.Operations.TimelineHorizontalShift.Processor), typeof(Core.Operations.TimelineColumnRemove.Processor), typeof(Core.Operations.RemoveKeyframeRange.Processor), typeof(Core.Operations.SelectRow.Processor), typeof(Core.Operations.RenameAnimationProcessor), typeof(Core.Operations.SetProperty.Processor), typeof(Core.Operations.SetIndexedProperty.Processor), typeof(Core.Operations.RemoveKeyframe.Processor), typeof(Core.Operations.SetKeyframe.Processor), typeof(Core.Operations.InsertFolderItem.Processor), typeof(Core.Operations.AddIntoCollection <,> .Processor), typeof(Core.Operations.RemoveFromCollection <,> .Processor), typeof(Core.Operations.InsertIntoList.Processor), typeof(Core.Operations.RemoveFromList.Processor), typeof(Core.Operations.InsertIntoList <,> .Processor), typeof(Core.Operations.RemoveFromList <,> .Processor), typeof(Core.Operations.UnlinkFolderItem.Processor), typeof(Core.Operations.MoveNodes.Processor), typeof(Core.Operations.SetMarker.Processor), typeof(Core.Operations.DeleteMarker.Processor), typeof(Core.Operations.SetComponent.Processor), typeof(Core.Operations.DeleteComponent.Processor), typeof(Core.Operations.DistortionMeshProcessor), typeof(Core.Operations.SyncFolderDescriptorsProcessor), typeof(UI.SceneView.ResolutionPreviewOperation.Processor), typeof(UI.Timeline.Operations.SelectGridSpan.Processor), typeof(UI.Timeline.Operations.DeselectGridSpan.Processor), typeof(UI.Timeline.Operations.ClearGridSelection.Processor), typeof(UI.Timeline.Operations.ShiftGridSelection.Processor), typeof(UI.Timeline.Operations.SetCurrentColumn.Processor), typeof(UI.Timeline.Operations.SelectCurveKey.Processor), typeof(TriggersValidatorOnSetProperty), typeof(TriggersValidatorOnSetKeyframe), typeof(UpdateNodesAndApplyAnimatorsProcessor), typeof(RowsSynchronizer), typeof(Core.Operations.ReplaceContents.Processor), typeof(Core.Operations.DeleteRuler.Processor), typeof(Core.Operations.CreateRuler.Processor), }); DocumentHistory.AddOperationProcessorTypes(UI.Timeline.Timeline.GetOperationProcessorTypes()); RegisterCommands(); InitializeHotkeys(); AppUserPreferences.Instance.ToolbarModel.RefreshAfterLoad(); Toolbar = new ToolbarView(dockManager.ToolbarArea, AppUserPreferences.Instance.ToolbarModel); RefreshCreateNodeCommands(); Document.AttachingViews += doc => { if (doc.Views.Count == 0) { doc.Views.AddRange(new IDocumentView[] { new UI.Inspector.Inspector(inspectorPanel.ContentWidget), new UI.Timeline.Timeline(timelinePanel), new UI.SceneView.SceneView(documentViewContainer), new Panels.HierarchyPanel(searchPanel.ContentWidget), new Panels.BackupHistoryPanel(backupHistoryPanel.ContentWidget), new Panels.AnimationsPanel(animationsPanel.ContentWidget), // Use VisualHintsPanel sigleton because we need preserve its state between documents. VisualHintsPanel.Instance ?? VisualHintsPanel.Initialize(visualHintsPanel), new AttachmentPanel(attachmentPanel), }); UI.SceneView.SceneView.ShowNodeDecorationsPanelButton.Clicked = () => dockManager.TogglePanel(visualHintsPanel); } }; var proj = AppUserPreferences.Instance.CurrentProject; if (proj != null) { try { new Project(proj).Open(); } catch { AlertDialog.Show($"Cannot open project '{proj}'. It may be deleted or be otherwise unavailable."); } } OpenDocumentsFromArgs(args); WidgetContext.Current.Root.AddChangeWatcher(() => Project.Current, project => TangerineMenu.OnProjectChanged(project)); WidgetContext.Current.Root.AddChangeWatcher(() => ProjectUserPreferences.Instance.RecentDocuments.Count == 0 ? null : ProjectUserPreferences.Instance.RecentDocuments[0], document => TangerineMenu.RebuildRecentDocumentsMenu()); WidgetContext.Current.Root.AddChangeWatcher(() => AppUserPreferences.Instance.RecentProjects.Count == 0 ? null : AppUserPreferences.Instance.RecentProjects[0], document => TangerineMenu.RebuildRecentProjectsMenu()); new UI.FilesystemView.FilesystemPane(filesystemPanel); new UI.RemoteScripting.RemoteScriptingPane(remoteScriptingPanel); RegisterGlobalCommands(); Documentation.Init(); DocumentationComponent.Clicked = page => Documentation.ShowHelp(page); }
private TangerineApp() { Orange.UserInterface.Instance = new OrangeInterface(); WidgetInput.AcceptMouseBeyondWidgetByDefault = false; Application.IsTangerine = true; Serialization.DeserializerBuilders.Insert(0, DeserializeHotStudioAssets); if (!UserPreferences.Initialize()) { UserPreferences.Instance.Clear(); UserPreferences.Instance.Add(new AppUserPreferences()); UserPreferences.Instance.Add(new UI.SceneView.SceneUserPreferences()); UserPreferences.Instance.Add(new UI.Timeline.TimelineUserPreferences()); UserPreferences.Instance.Add(new UI.FilesystemView.FilesystemUserPreferences()); UserPreferences.Instance.Add(new CoreUserPreferences()); } SetColorTheme(AppUserPreferences.Instance.Theme); LoadFont(); DockManager.Initialize(new Vector2(1024, 768), TangerineMenu.PadsMenu); TangerineMenu.Create(); var mainWidget = DockManager.Instance.MainWindowWidget; mainWidget.Window.AllowDropFiles = true; mainWidget.AddChangeWatcher(() => Project.Current, _ => { SetupMainWindowTitle(mainWidget); TangerineMenu.RebuildCreateImportedTypeMenu(); }); Application.Exiting += () => Project.Current.Close(); Application.Exited += () => { AppUserPreferences.Instance.DockState = DockManager.Instance.ExportState(); Core.UserPreferences.Instance.Save(); }; var timelinePanel = new DockPanel("Timeline"); var inspectorPanel = new DockPanel("Inspector"); var searchPanel = new DockPanel("Search"); var filesystemPanel = new DockPanel("Filesystem"); var consolePanel = new DockPanel("Console"); new UI.Console(consolePanel); var dockManager = DockManager.Instance; dockManager.AddPanel(timelinePanel, DockSite.Top, new Vector2(800, 300)); dockManager.AddPanel(inspectorPanel, DockSite.Left, new Vector2(300, 700)); dockManager.AddPanel(searchPanel, DockSite.Right, new Vector2(300, 700)); dockManager.AddPanel(filesystemPanel, DockSite.Right, new Vector2(300, 700)); dockManager.AddPanel(consolePanel, DockSite.Bottom, new Vector2(800, 200)); DockManagerInitialState = dockManager.ExportState(); var documentViewContainer = InitializeDocumentArea(dockManager); dockManager.ImportState(AppUserPreferences.Instance.DockState); Document.CloseConfirmation += doc => { var alert = new AlertDialog($"Save the changes to document '{doc.Path}' before closing?", "Yes", "No", "Cancel"); switch (alert.Show()) { case 0: return(Document.CloseAction.SaveChanges); case 1: return(Document.CloseAction.DiscardChanges); case -1: default: return(Document.CloseAction.Cancel); } }; Project.DocumentReloadConfirmation += doc => { var alert = new AlertDialog($"The file '{doc.Path}' has been changed outside of Tangerine.\nDo you want to keep your changes, or reload the file from disk?", "Keep", "Reload"); var res = alert.Show(); return(res == 0 || res == -1 ? false : true); }; Project.TempFileLoadConfirmation += path => { var alert = new AlertDialog($"Do you want to load autosaved version of '{path}'?", "Yes", "No"); return(alert.Show() == 0); }; Project.CookingOfModifiedAssetsStarted += () => { cookingOfModifiedAssetsDialog = new ModalOperationDialog(() => Project.CookingOfModifiedAssetsStatus, "Cooking of modified assets"); cookingOfModifiedAssetsDialog.Show(); }; Project.CookingOfModifiedAssetsEnded += () => { cookingOfModifiedAssetsDialog.Close(); cookingOfModifiedAssetsDialog = null; }; Project.OpenFileOutsideProjectAttempt += (string filePath) => { var path = filePath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); path[0] += '\\'; string projectFilePath = null; for (int i = path.Length - 2; i >= 0; i--) { var ppp = Path.Combine(path.Take(i + 1).ToArray()); var projectFileCandidates = Directory.GetFiles(ppp, "*.citproj", SearchOption.TopDirectoryOnly); if (projectFileCandidates.Length > 0) { projectFilePath = projectFileCandidates[0]; break; } } if (projectFilePath != null) { var alert = new AlertDialog($"You're trying to open a document outside the project directory. Change the current project to '{Path.GetFileName(projectFilePath)}'?", "Yes", "No"); if (alert.Show() == 0) { FileOpenProject.Execute(projectFilePath); Project.Current.OpenDocument(filePath, true); return; } } AlertDialog.Show("Can't open a document outside the project directory"); }; Project.Tasks = dockManager.MainWindowWidget.Tasks; Project.Tasks.Add(new AutosaveProcessor(() => AppUserPreferences.Instance.AutosaveDelay)); Document.NodeDecorators.AddFor <Spline>(n => n.CompoundPostPresenter.Add(new UI.SceneView.SplinePresenter())); Document.NodeDecorators.AddFor <Viewport3D>(n => n.CompoundPostPresenter.Add(new UI.SceneView.Spline3DPresenter())); Document.NodeDecorators.AddFor <Widget>(n => { if (n.AsWidget.SkinningWeights == null) { n.AsWidget.SkinningWeights = new SkinningWeights(); } }); Document.NodeDecorators.AddFor <PointObject>(n => { if ((n as PointObject).SkinningWeights == null) { (n as PointObject).SkinningWeights = new SkinningWeights(); } }); Document.NodeDecorators.AddFor <Node>(n => n.SetTangerineFlag(TangerineFlags.SceneNode, true)); dockManager.MainWindowWidget.Updated += delta => Document.Current?.History.NextBatch(); DocumentHistory.Processors.AddRange(new IOperationProcessor[] { new Core.Operations.SelectRow.Processor(), new Core.Operations.SetProperty.Processor(), new Core.Operations.RemoveKeyframe.Processor(), new Core.Operations.SetKeyframe.Processor(), new Core.Operations.SetAnimator.Processor(), new Core.Operations.InsertFolderItem.Processor(), new Core.Operations.UnlinkFolderItem.Processor(), new Core.Operations.MoveNodes.Processor(), new Core.Operations.SetMarker.Processor(), new Core.Operations.DeleteMarker.Processor(), new Core.Operations.DistortionMeshProcessor(), new Core.Operations.SyncFolderDescriptorsProcessor(), new Core.Operations.TimelineHorizontalShift.Processor(), new UI.Timeline.Operations.SelectGridSpan.Processor(), new UI.Timeline.Operations.DeselectGridSpan.Processor(), new UI.Timeline.Operations.ClearGridSelection.Processor(), new UI.Timeline.Operations.ShiftGridSelection.Processor(), new UI.Timeline.Operations.SetCurrentColumn.Processor(), new UI.Timeline.Operations.SelectCurveKey.Processor(), new UpdateNodesAndApplyAnimatorsProcessor(), new RowsSynchronizer(), }); DocumentHistory.Processors.AddRange(UI.Timeline.Timeline.GetOperationProcessors()); Toolbars.Add("Create", new Toolbar(dockManager.ToolbarArea)); Toolbars.Add("Tools", new Toolbar(dockManager.ToolbarArea)); foreach (var c in Application.MainMenu.FindCommand("Create").Menu) { Toolbars["Create"].Add(c); } CreateToolsToolbar(); Document.AttachingViews += doc => { if (doc.Views.Count == 0) { doc.Views.AddRange(new IDocumentView[] { new UI.Inspector.Inspector(inspectorPanel.ContentWidget), new UI.Timeline.Timeline(timelinePanel), new UI.SceneView.SceneView(documentViewContainer), new UI.SearchPanel(searchPanel.ContentWidget), }); } }; var proj = AppUserPreferences.Instance.RecentProjects.FirstOrDefault(); if (proj != null) { new Project(proj).Open(); } WidgetContext.Current.Root.AddChangeWatcher(() => Project.Current, project => TangerineMenu.OnProjectChanged(project)); new UI.FilesystemView.FilesystemPane(filesystemPanel); RegisterGlobalCommands(); }