コード例 #1
0
ファイル: VisualHints.cs プロジェクト: aologos/Citrus
 public static VisualHintsPanel Initialize(Panel panel)
 {
     if (Instance != null)
     {
         throw new InvalidOperationException();
     }
     Instance = new VisualHintsPanel(panel);
     Refresh();
     return(Instance);
 }
コード例 #2
0
ファイル: VisualHints.cs プロジェクト: aologos/Citrus
 private VisualHintsPanel(Panel panel)
 {
     if (Instance != null)
     {
         throw new InvalidOperationException();
     }
     Instance   = this;
     this.panel = panel;
     rootWidget = new ThemedScrollView();
     rootWidget.Content.Layout = new VBoxLayout {
         Spacing = 6
     };
     panel.ContentWidget.AddNode(rootWidget);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        public PreferencesDialog()
        {
            window = new Window(new WindowOptions {
                ClientSize           = new Vector2(800, 600),
                FixedSize            = false,
                Title                = "Preferences",
                MinimumDecoratedSize = new Vector2(400, 300),
                Visible              = false
            });
            Frame = new ThemedFrame {
                Padding    = new Thickness(8),
                LayoutCell = new LayoutCell {
                    StretchY = float.MaxValue
                },
                Layout = new StackLayout(),
            };
            Content = new ThemedTabbedWidget();
            Content.AddTab("General", CreateGeneralPane(), true);
            Content.AddTab("Appearance", CreateColorsPane());
            Content.AddTab("Theme", CreateThemePane());
            Content.AddTab("Keyboard shortcuts", CreateKeyboardPane());
            Content.AddTab("Toolbar", toolbarModelEditor = new ToolbarModelEditor());

            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    Content,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.LeftCenter),
                        Padding    = new Thickness {
                            Top = 5
                        },
                        Nodes =
                        {
                            (resetButton     = new ThemedButton {
                                Text         = "Reset To Defaults", MinMaxWidth    = 150f
                            }),
                            new Widget {
                                MinMaxHeight =        0
                            },
                            (okButton        = new ThemedButton {
                                Text         = "Ok"
                            }),
                            (cancelButton    = new ThemedButton {
                                Text         = "Cancel"
                            }),
                        }
                    }
                }
            };
            HotkeyRegistry.CurrentProfile.Save();
            okButton.Clicked += () => {
                saved = true;
                SaveAfterEdit();
                window.Close();
                VisualHintsPanel.Refresh();
                Core.UserPreferences.Instance.Save();
                if (themeEdited)
                {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Custom;
                }
                if (themeChanged)
                {
                    AlertDialog.Show("Color theme changes will be applied after Tangerine restart.");
                }
            };
            resetButton.Clicked += () => {
                if (new AlertDialog($"Are you sure you want to reset to defaults?", "Yes", "Cancel").Show() == 0)
                {
                    ResetToDefaults();
                }
            };
            cancelButton.Clicked += () => {
                window.Close();
                Core.UserPreferences.Instance.Load();
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    Core.UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();

            window.Closed += () => {
                if (saved)
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Save();
                    }
                    HotkeyRegistry.CurrentProfile = currentProfile;
                }
                else
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Load();
                    }
                    HotkeyRegistry.CurrentProfile = HotkeyRegistry.CurrentProfile;
                }
            };

            foreach (var command in HotkeyRegistry.CurrentProfile.Commands)
            {
                command.Command.Shortcut = new Shortcut(Key.Unknown);
            }
            window.ShowModal();
        }