Exemplo n.º 1
0
        static IControl CreateClassItem(
            IElement classElement,
            IContext context,
            ElementContext elementContext,
            IObservable <string> searchString)
        {
            var className = classElement["ux:Class"].Or("");

            return(Layout
                   .StackFromLeft(
                       classElement.MediumIcon(Theme.Purple, Theme.IconSecondary).CenterVertically(),
                       Spacer.Small,
                       Label.Create(className.AsText(), font: Theme.DefaultFont, color: Theme.DefaultText).CenterVertically())
                   .WithPadding(new Thickness <Points>(5))
                   .WithBackground(Shapes
                                   .Rectangle(
                                       fill: Color.FromRgb(0xaaaaaa).WithAlpha(a: 0.2f),
                                       cornerRadius: Observable.Return(new CornerRadius(2)))
                                   .ShowWhen(context.IsSelected(classElement)))
                   .DockLeft()
                   .OnMouse(
                       entered: Command.Enabled(() => context.Preview(classElement)),
                       exited: Command.Enabled(() => context.Preview(Element.Empty)),
                       pressed: Command.Enabled(() => context.Select(classElement)),
                       dragged: className.Select(er => SourceFragment.FromString("<" + er + "/>")),
                       doubleClicked: Command.Enabled(() =>
                                                      context.SetScope(root: classElement, selection: classElement)))
                   .SetContextMenu(elementContext.CreateMenu(classElement))
                   .WithHeight(26)
                   .ShowWhen(
                       Observable.CombineLatest(
                           searchString,
                           className.AsText(),
                           (search, name) =>
            {
                if (search == "")
                {
                    return true;
                }
                return name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;                                         // case insensitive comparison
            })));
        }
Exemplo n.º 2
0
        public Window Execute(IDocument document, string[] args)
        {
            var hack    = new ReplaySubject <IObservable <BytecodeGenerated> >(1);
            var project = new LiveProject(document, _shell, hack.Switch().ObserveOn(Application.MainThread));
            var ignore  = RecentProjects.Bump(document, project.Name.ObserveOn(Application.MainThread));

            var preview = _previewService.StartPreview(project);

            hack.OnNext(preview.Bytecode);

                        #pragma warning disable 0219
            var garbage = ExternalSelection.UpdateProjectContext(_daemon, project);
                        #pragma warning restore 0219

            var inspector = Fuse.Inspector.Inspector.Create(project);

            var buildArgs = new BuildArgs(args);

            var usbMode         = new USBMode(new AndroidPortReverser(), Observable.Return(preview.Port), _previewService);
            var previewOnDevice = new PreviewOnDevice(_fuse, project, buildArgs);

            var build  = new Build(project, preview, previewOnDevice, usbMode.EnableUsbModeCommand, buildArgs);
            var export = new Export(project, _fuse, buildArgs);

            var projHost = new ProjectHost(build.BuildArguments, preview, project, self =>
                                           _projectsOpen.OnNext(_projectsOpen.Value.Remove(self)));
            _projectsOpen.OnNext(_projectsOpen.Value.Add(projHost));

            var codeView = new CodeView(preview.AccessCode, NetworkHelper
                                        .GetInterNetworkIps()
                                        .ToArray());

            // Viewport stuff

            var selectionEnabled = Property.Create(false);


            var glVersion = new Subject <OpenGlVersion>();

            var viewport = new ViewportFactory(
                preview,
                selectionEnabled,
                preview.Port,
                project,
                _fuse,
                glVersion);

            var mode           = UserSettings.Enum <Mode>("WindowMode").Or(Mode.Normal);
            var previewDevices = new PreviewDevices(project, _shell);
            var workspace      = new StageController(
                viewport,
                previewDevices,
                selectionEnabled);

            var topMost    = Property.Create(false);
            var windowMenu =
                Menu.Toggle(
                    name: "Compact mode",
                    toggle: mode.Convert(
                        convert: m => m == Mode.Compact,
                        convertBack: b => b ? Mode.Compact : Mode.Normal),
                    hotkey: HotKey.Create(ModifierKeys.Meta, Key.M))
                + Menu.Separator
                + Menu.Toggle(
                    name: "Keep window on top",
                    toggle: topMost,
                    hotkey: HotKey.Create((_fuse.Platform == OS.Windows ? ModifierKeys.Shift : ModifierKeys.Alt) | ModifierKeys.Meta, Key.T))
                + Menu.Separator
                + Menu.Option(
                    value: Themes.OriginalLight,
                    name: "Light theme",
                    property: Theme.CurrentTheme)
                + Menu.Option(
                    value: Themes.OriginalDark,
                    name: "Dark theme",
                    property: Theme.CurrentTheme);

            var messages = preview.Messages.Replay(TimeSpan.FromSeconds(2)).RefCount();

            project.FilePath.SubscribeUsing(projPath =>
                                            PushEventsToDaemon.Start(
                                                messages: messages,
                                                daemon: _daemon,
                                                projectPath: projPath,
                                                projectId: ProjectIdComputer.IdFor(projPath),
                                                target: BuildTarget.DotNetDll));

            var sketchConverter = new SketchWatcher(_fuse.Report, _shell);

            var classExtractor = new ClassExtractor(project);

            var buildStartedOrLicenseChanged = project.FilePath
                                               .CombineLatest(build.Rebuilt.StartWith(Unit.Default));

            var allLogMessages = messages.ToLogMessages()
                                 .Merge(_setupGuide.LogMessages)
                                 .Merge(export.LogMessages)
                                 .Merge(project.LogMessages)
                                 .Merge(previewOnDevice.LogMessages)
                                 .Merge(classExtractor.LogMessages)
                                 .Merge(_hostRequestMessages)
                                 .Merge(_errors.Select(e => e.Message))
                                 .Merge(AutoReload.Log.Select(msg => "[Fusion AutoReload]: " + msg)
                                        .Merge(glVersion.Take(1).ToLogMessages(_fuse.Report)))
                                 .Merge(preview.LogMessages)
                                 .Merge(_previewService.LogMessages)
                                 .Merge(sketchConverter.LogMessages)
                                 .Merge(previewDevices.LogMessages);

            var stopPreview = preview.Start(build.BuildArguments);

            // start with a viewport
            workspace.NewViewport.ExecuteOnce();

            var projectMenu =
                ProjectMenu.CommandItems(project.FilePath.Select(Optional.Some), _shell)
                + Menu.Separator
                + ProjectMenu.FileItems(project, _shell)
                + Menu.Separator
                + Menu.Item("Sketch import", sketchConverter.ShowDialog());

            var help = new Help();

            var debug = new Debug(project);


            var elementContext = new ElementContext(project.Context, project, _daemon);

            var errorView = new ErrorView(messages, project.FilePath, _daemon, preview.ClientRemoved);

            var logView     = new LogView(allLogMessages, messages, errorView);
            var sketchWatch = sketchConverter.Watch(project);
            var window      = MainWindow.Create(
                projectName: project.Name,
                search: Control.Empty,                //search.Control,
                outline: CreateLeftPane(project, elementContext, project.Context, _shell, classExtractor),
                bookmarks: Control.Empty,
                stage: workspace,
                notifications: Layout.StackFromTop(
                    SimulatorNotifications.CreateBusyIndicator(messages),
                    SimulatorNotifications.Create(messages, build.Rebuild, logView.IsExpanded)),
                inspector: inspector,
                attributes: Control.Empty,                //DataContext.Create(workspace.Viewport, selection.Element),
                logview: logView,
                menu: MainMenu.Create(
                    _fuse,
                    _shell,
                    workspace,
                    help,
                    elementContext.CreateMenu(project.Context.CurrentSelection),
                    projectMenu,
                    build,
                    export,
                    _setupGuide,
                    windowMenu,
                    debug),
                closed: Command.Enabled(() =>
            {
                stopPreview.Dispose();
                preview.Dispose();
                projHost.Dispose();
                project.FilePath.Take(1).Subscribe(path =>
                                                   _daemon.Broadcast(new ProjectClosed {
                    ProjectId = ProjectIdComputer.IdFor(path)
                }));
                project.Dispose();
                workspace.Dispose();
                sketchWatch.Dispose();
            }),
                selectionEnabled: selectionEnabled,
                topMost: topMost,
                mode: mode,
                mainWindowFocused: _mainWindowFocused.Update(Unit.Default),
                context: project.Context,
                codeView: codeView);

            return(window);
        }