Ejemplo n.º 1
0
 public static void Save(WorkspaceConfig config)
 {
     using (FileStream stream = new FileStream(GetConfigPath(), FileMode.Create, FileAccess.Write, FileShare.None)) {
         var js = new Yuzu.Json.JsonSerializer();
         js.ToStream(config, stream);
     }
 }
Ejemplo n.º 2
0
        public override void Execute()
        {
            var dlg = new FileDialog {
                AllowedFileTypes = new string[] { "layout" },
                Mode             = FileDialogMode.Save
            };

            if (dlg.RunModal())
            {
                string path = dlg.FileName;
                try {
                    var state = DockManager.Instance.ExportState();
                    using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) {
                        serializer.ToStream(state, fileStream);
                    }
                }
                catch (System.Exception e) {
                    AlertDialog.Show(e.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public static void SaveCodeCookerCache(CodeCookerCache codeCookerCache)
        {
            codeCookerCache.GeneratedProjectFileToModificationDate.Clear();
            using (new DirectoryChanger(The.Workspace.ProjectDirectory)) {
                var projectName = The.Workspace.ProjectName;
                foreach (var platform in Enum.GetValues(typeof(TargetPlatform)))
                {
                    var platformName = Enum.GetName(typeof(TargetPlatform), platform);
                    var projectPath  = $"{projectName}.{The.Workspace.GeneratedScenesPath}/{projectName}.GeneratedScenes.{platformName}.csproj";
                    if (File.Exists(projectPath))
                    {
                        CsprojSynchronization.SynchronizeProject(projectPath);
                        codeCookerCache.GeneratedProjectFileToModificationDate.Add(projectPath, File.GetLastWriteTime(projectPath));
                    }
                }
            }
            var codeCookerCachePath = GetCodeCachePath();

            Directory.CreateDirectory(Path.GetDirectoryName(codeCookerCachePath));
            using (FileStream stream = new FileStream(codeCookerCachePath, FileMode.Create, FileAccess.Write, FileShare.None)) {
                var js = new Yuzu.Json.JsonSerializer();
                js.ToStream(codeCookerCache, stream);
            }
        }
Ejemplo n.º 4
0
        private Widget CreateThemeEditor()
        {
            var pane = new Widget {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };
            var themeEditor = new ColorThemeEditor()
            {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };
            bool firstCall = true;

            pane.AddChangeWatcher(() => themeEditor.Version, _ => {
                if (firstCall)
                {
                    firstCall = false;
                    return;
                }
                themeChanged = true;
                themeEdited  = true;
            });
            var darkIcons      = CreateDarkIconsSwitch(pane);
            var loadDarkButton = new ThemedButton("Dark preset")
            {
                Clicked = () => {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Dark;
                    AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateDarkTheme();
                    AppUserPreferences.Instance.ColorTheme     = ColorTheme.CreateDarkTheme();
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var loadLightButton = new ThemedButton("Light preset")
            {
                Clicked = () => {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Light;
                    AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateLightTheme();
                    AppUserPreferences.Instance.ColorTheme     = ColorTheme.CreateLightTheme();
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var saveButton = new ThemedButton("Save theme")
            {
                Clicked = () => {
                    var dlg = new FileDialog {
                        AllowedFileTypes = new string[] { "theme" },
                        Mode             = FileDialogMode.Save
                    };
                    if (dlg.RunModal())
                    {
                        string path       = dlg.FileName;
                        var    serializer = new Yuzu.Json.JsonSerializer();
                        try {
                            var limeTheme = AppUserPreferences.Instance.LimeColorTheme;
                            var theme     = AppUserPreferences.Instance.ColorTheme;
                            using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) {
                                serializer.ToStream(new List <object> {
                                    limeTheme, theme
                                }, fileStream);
                            }
                        } catch (System.Exception e) {
                            AlertDialog.Show(e.Message);
                        }
                    }
                }
            };
            var loadButton = new ThemedButton("Load theme")
            {
                Clicked = () => {
                    var dlg = new FileDialog {
                        AllowedFileTypes = new string[] { "theme" },
                        Mode             = FileDialogMode.Open
                    };
                    if (dlg.RunModal())
                    {
                        string path         = dlg.FileName;
                        var    deserializer = new Yuzu.Json.JsonDeserializer();
                        try {
                            using (var fs = new FileStream(path, FileMode.OpenOrCreate)) {
                                var read = deserializer.FromStream(new List <object>(), fs) as List <object>;
                                AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Custom;
                                AppUserPreferences.Instance.LimeColorTheme = (Theme.ColorTheme)read[0];
                                AppUserPreferences.Instance.ColorTheme     = (ColorTheme)read[1];
                            }
                        } catch (System.Exception e) {
                            AlertDialog.Show(e.Message);
                        }
                    }
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var buttons = new Widget {
                Layout = new HBoxLayout {
                    Spacing = 4
                },
                Nodes = { loadDarkButton, loadLightButton, saveButton, loadButton }
            };

            pane.AddNode(buttons);
            pane.AddNode(themeEditor);
            return(pane);
        }