Exemple #1
0
 public static void Open(
     this IModalHost modalHost,
     Command confirm,
     IControl fill,
     Command?cancel      = null,
     Text?confirmText    = null,
     Text?cancelText     = null,
     Text?confirmTooltip = null)
 {
     modalHost.OpenModal(
         close => Layout.Dock()
         .Top(
             ConfirmCancelControl.Create(close, confirm, fill, cancel, confirmText, cancelText, confirmTooltip)
             .WithBackground(Theme.PanelBackground)
             .MakeHittable()
             .Control)
         .Fill(Control.Empty.WithBackground(Color.FromRgba(0x00000066))));
 }
Exemple #2
0
        public IControl View(IProject project, IDialog <object> dialog)
        {
            var newFile = Property.Create("");
            var files   = new ListBehaviorSubject <IFilePath>();

            project.FilePath.Select(SketchImportUtils.SketchListFilePath)
            .Where(path => File.Exists(path.NativePath))
            .Select(SketchFilePaths).Do(paths =>
            {
                foreach (var absoluteFilePath in paths)
                {
                    files.OnAdd(absoluteFilePath);
                }
            })
            .Subscribe();

            var addNewSketchFileCommand =
                Command.Create(newFile
                               .CombineLatest(project.RootDirectory,
                                              (pathString, rootDir) =>
            {
                if (!string.IsNullOrWhiteSpace(pathString))
                {
                    var path = FilePath.Parse(pathString);

                    if (_fileSystem.Exists((path as IAbsolutePath) ?? rootDir.Combine((RelativeFilePath)path)))
                    {
                        return(Optional.Some(path));
                    }
                }
                return(Optional.None());
            })
                               .WherePerElement(path => SketchImportUtils.IsSketchFile(path) && !files.Value.Contains(path))
                               .SelectPerElement(
                                   path => (Action)(() =>
            {
                _logger.Info("Adding sketch file to watch: " + path);
                files.OnAdd(path);
                newFile.Write("");
            })));

            var content = Layout.Dock()
                          .Top(
                Layout.StackFromLeft(
                    Label.Create(
                        "Add sketch files to import symbols from",
                        font: Theme.DefaultFont,
                        textAlignment: TextAlignment.Left,
                        color: Theme.DescriptorText))
                .CenterHorizontally())
                          .Top(Spacer.Medium)
                          .Bottom(
                Layout.Dock()
                .Right(
                    AddButton(addNewSketchFileCommand)
                    .SetToolTip("Import sketch symbols from this file")
                    .Center())
                .Right(Spacer.Small)
                .Fill(
                    FilePathControl.Create(
                        newFile,
                        project.RootDirectory,
                        new[] { new FileFilter("Sketch files", SketchImportUtils.SketchExtention) },
                        "Add sketch file",
                        "Enter path of new sketch file to add here, or click browse button",
                        "Open")))
                          .Fill(
                files
                .ToObservableImmutableList()
                .SelectPerElement(
                    filePath =>
            {
                var highlightSketchFileControl = new BehaviorSubject <bool>(false);
                var fileExists = project.RootDirectory.Select(
                    root => File.Exists(FilePath.ParseAndMakeAbsolute(filePath, root).NativePath));

                return(highlightSketchFileControl
                       .DistinctUntilChanged()
                       .CombineLatest(fileExists,
                                      (highlight, exists) =>
                {
                    return Layout.Dock()
                    .Bottom(Spacer.Smaller)
                    .Right(
                        RemoveButton(Command.Enabled(() => { files.OnRemove(files.Value.IndexOf(filePath)); }))
                        .SetToolTip("Remove sketch file from watch list"))
                    .Right(Spacer.Small)
                    .Fill(
                        Label.Create(
                            Observable.Return(filePath.ToString()).AsText(),
                            color: exists?Theme.DefaultText: Theme.ErrorColor,
                            font: Theme.DefaultFont)
                        .CenterVertically()).SetToolTip(exists ? default(Text) : "Can't find file " + filePath)
                    .OnMouse(
                        entered: Command.Enabled(() => { highlightSketchFileControl.OnNext(true); }),
                        exited: Command.Enabled(() => highlightSketchFileControl.OnNext(false)))
                    .WithPadding(new Points(2))
                    .WithBackground(highlight ? Theme.FaintBackground : Theme.PanelBackground);
                })
                       .Switch());
            })
                .StackFromTop()
                .MakeScrollable());

            return
                (ConfirmCancelControl.Create(
                     close: Command.Enabled(() => { _isVisible.OnNext(false); }),
                     confirm: Command.Enabled(
                         () => { project.FilePath.Select(SketchImportUtils.SketchListFilePath).Do(path => { WriteSketchFilePaths(path, files.Value); }).Subscribe(); }),
                     fill: content.WithMediumPadding(), cancel: null, confirmText: null, cancelText: null, confirmTooltip: null)
                 .WithMacWindowStyleCompensation()                        // order of window style compensation and with background is important
                 .WithBackground(Theme.PanelBackground));
        }