コード例 #1
0
ファイル: CreateProject.cs プロジェクト: yongaru/fuse-studio
 public static IControl Create(IValidatedProperty <string> value)
 {
     return(Layout.StackFromTop(
                TextBox.Create(value, foregroundColor: Theme.DefaultText)
                .WithHeight(20)
                .WithOverlay(Shapes.Rectangle(stroke: Theme.FieldStroke))
                .WithBackground(Theme.FieldBackground),                      // TODO Should show full path on mouse over if truncated?
                ErrorLabel.Create(value.ValidationError)
                ));
 }
コード例 #2
0
ファイル: CreateProject.cs プロジェクト: yongaru/fuse-studio
        IControl CreateContent(Template template, IDialog <bool> dialog)
        {
            var projectLocation =
                UserSettings.Folder("MostRecentlyUsedFolder")
                .Convert(v => v.Or(Optional.Some(_fuse.ProjectsDir)), d => d)
                .AutoInvalidate(TimeSpan.FromMilliseconds(100));
            var validatedLocation = projectLocation.Validate(v => v.NativePath, ValidateExistingDirectory);

            var projectName = Property.Create(
                Optional.Some(_shell.MakeUnique(projectLocation.Latest().First().Value / "App").Name));
            var validatedName =
                projectName.Validate(v => v.ToString(), DirectoryName.Validate);

            var possibleProjectName = projectLocation.CombineLatest(
                projectName,
                (loc, pro) => { return(loc.SelectMany(l => pro.Select(n => l / n))); })
                                      .Select(
                d => d.HasValue && Directory.Exists(d.Value.NativePath) ?
                Optional.Some("Project '" + d.Value.Name + "' already exists in " + d.Value.ContainingDirectory.NativePath) :
                Optional.None());

            return
                (Layout.Dock()
                 .Bottom(Layout.Dock()
                         .Right(
                             Buttons.DefaultButtonPrimary(
                                 text: "Create",
                                 cmd: Observable.CombineLatest(
                                     projectName, projectLocation,
                                     (name, location) =>
            {
                var projectDirectory =
                    location.SelectMany(l =>
                                        name.Select(n => l / n))
                    .Where(d => !_shell.Exists(d));

                return Command.Create(
                    isEnabled: projectDirectory.HasValue,
                    action: async() =>
                {
                    var spawnTemplate = new SpawnTemplate(_shell);
                    var resultPath = spawnTemplate.CreateProject(name.Value.ToString(), template, location.Value);
                    var projectPath = resultPath / new FileName(name.Value + ".unoproj");

                    await Application.OpenDocument(projectPath, showWindow: true);
                    dialog.Close(true);
                });
            }).Switch())
                             .WithWidth(104))
                         .Right(Buttons.DefaultButton(text: "Cancel", cmd: Command.Enabled(() => dialog.Close(false)))
                                .WithWidth(104)
                                .WithPadding(right: new Points(16)))
                         .Fill())

                 .Fill(
                     Layout.StackFromTop(
                         Label.Create("Name:", color: Theme.DefaultText)
                         .WithPadding(LabelThickness),
                         ValidatedTextBox.Create(validatedName)
                         .WithPadding(ControlPadding),
                         Control.Empty
                         .WithHeight(8),
                         Label.Create("Location:", color: Theme.DefaultText)
                         .WithPadding(LabelThickness),
                         Layout.Dock()
                         .Right(
                             Buttons.DefaultButton(text: "Browse", cmd: Command.Enabled(async() =>
            {
                var directory = await dialog.BrowseForDirectory(await projectLocation.FirstAsync().Or(DirectoryPath.GetCurrentDirectory()));
                if (directory.HasValue)
                {
                    projectLocation.Write(directory.Value, save: true);
                }
            }))
                             .WithWidth(80)
                             .WithHeight(22)
                             .CenterVertically()
                             .WithPadding(LabelThickness)
                             )
                         .Fill(ValidatedTextBox.Create(validatedLocation)
                               .WithPadding(ControlPadding)),
                         ErrorLabel.Create(possibleProjectName)
                         .WithPadding(ControlPadding)))
                 .WithPadding(ControlPadding)
                 .WithPadding(ControlPadding)
                 .WithBackground(Theme.PanelBackground));
        }