Exemple #1
0
        public Build(IProject project, ProjectPreview preview, PreviewOnDevice previewOnDevice, Command enableUsbMode, BuildArgs args)
        {
            var buildLibraries = new BehaviorSubject <bool>(false);

            var rebuilt = new Subject <object>();

            Rebuilt = rebuilt;

            Rebuild = Command.Enabled(() =>
            {
                rebuilt.OnNext(new object());
                preview.Rebuild();
            });

            Refresh = Command.Enabled(preview.Refresh);

            var buildFlagsWindowVisible = new BehaviorSubject <bool>(false);

            BuildFlags = Command.Enabled(() => buildFlagsWindowVisible.OnNext(true));

            Application.Desktop.CreateSingletonWindow(
                isVisible: buildFlagsWindowVisible,
                window: window => BuildFlagsWindow.Create(buildFlagsWindowVisible, args));

            BuildArguments = Observable.CombineLatest(
                args.Defines, buildLibraries, args.Verbose, project.FilePath,
                (d, bl, vb, pp) => new BuildProject(pp.NativePath, List.Create(d.ToArray()), bl, vb));

            Menu =
                Menu.Item("Refresh", Refresh, hotkey: HotKey.Create(ModifierKeys.Meta, Key.R))
                + Menu.Item("Rebuild", Rebuild, hotkey: HotKey.Create(ModifierKeys.Meta | ModifierKeys.Shift, Key.R))
                + Menu.Separator
                + Menu.Item("Reconnect USB (Android)", enableUsbMode)
                + Menu.Separator
                + previewOnDevice.Menu
                + Menu.Separator
                + Menu.Item("Build flags", BuildFlags);
        }
Exemple #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);
        }