Ejemplo n.º 1
0
        public static IControl CreateContent(
            LogView logview,
            IControl outline,
            IControl search,
            IControl notifications,
            IControl attributes,
            IControl bookmarks,
            IControl inspector,
            StageView stage,
            IControl topBar,
            IObservable <Mode> mode)
        {
            Points inspectorWidth = 295;

            var right = Property.Constant(Fuse.Inspector.Inspector.Width);
            var left  = UserSettings.Point("LeftPanelWidth").Or(new Points(260));

            var inNormalMode = mode.Select(x => x == Mode.Normal);

            return(Layout.Layer(
                       Shapes.Rectangle(fill: Theme.WorkspaceBackground),
                       Layout.Dock()
                       .Top(topBar)
                       .Top(Separator.Medium)

                       .Panel(RectangleEdge.Right, right,
                              inNormalMode,
                              control: inspector,
                              minSize: inspectorWidth,
                              resizable: false)

                       .Panel(RectangleEdge.Left, left,
                              inNormalMode,
                              control: outline,
                              minSize: 10)

                       .Fill(stage.CreateStage(logview, notifications))));
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        public static Window Create(
            IObservable <string> projectName,
            IControl search,
            IControl outline,
            IControl bookmarks,
            StageController stage,
            IControl notifications,
            IControl inspector,
            IControl attributes,
            LogView logview,
            Menu menu,
            Command closed,
            IProperty <bool> selectionEnabled,
            IObservable <bool> topMost,
            IProperty <Mode> mode,
            Command mainWindowFocused,
            IContext context,
            CodeView codeView)
        {
            IControl topBar = null;

            var newView = stage.NewViewport;

            var content =
                Popover.Host(
                    popover =>
            {
                topBar = CreateTopBar(
                    popover,
                    selectionEnabled: selectionEnabled,
                    mode: mode,
                    addViewport: newView,
                    codeView: codeView);

                return(CreateContent(
                           logview: logview,
                           outline: outline,
                           search: search,
                           notifications: notifications,
                           attributes: attributes,
                           bookmarks: bookmarks,
                           inspector: inspector,
                           stage: new StageView(stage, context, mode),
                           topBar: topBar,
                           mode: mode));
            });

            var mainWindowSize     = UserSettings.Size("MainWindowSize");
            var mainWindowPosition = UserSettings.Position("MainWindowPosition");
            var mainWindowState    = UserSettings.Settings.Property <WindowState>("MainWindowState");

            var compactSize     = UserSettings.Size("CompactWindowSize");
            var compactPosition = UserSettings.Position("CompactWindowPosition");


            var compactContentSize =
                compactSize.With(value:
                                 compactSize.Merge(
                                     stage.DefaultViewportSize.Select(Optional.Some)
                                     .CombineLatest(
                                         topBar.DesiredSize.Height,
                                         (deviceSize, topBarHeight) =>
                                         deviceSize.Select(s =>
                                                           Size.Create(
                                                               s.Width + ResizeBorderSize * 2 /* padding */,
                                                               s.Height + topBarHeight + ResizeBorderSize * 2 + LogViewHeader.HeaderHeight /* padding */)))));


            var windowSize     = mode.Select(x => x == Mode.Normal ? mainWindowSize : compactContentSize).Switch();
            var windowState    = mode.Select(x => x == Mode.Normal ? mainWindowState : Property.Constant(Optional.Some(WindowState.Normal))).Switch();
            var windowPosition = mode.Select(x => x == Mode.Normal ? mainWindowPosition : compactPosition).Switch();


            return(new Window
            {
                Closed = closed,
                Title = projectName
                        .Select(Optional.Some)
                        .StartWith(Optional.None())
                        .Select(
                    maybePath => maybePath.MatchWith(
                        some: name => name + " - Fuse",
                        none: () => "Fuse")),
                Size = Optional.Some(windowSize),
                Position = Optional.Some(windowPosition),
                State = Optional.Some(windowState),
                Menu = menu,
                Content = content,
                TopMost = Optional.Some(topMost),
                Focused = mainWindowFocused,
                Foreground = Theme.DefaultText,
                Background = Theme.PanelBackground,
                Border = Separator.MediumStroke,
                Style = WindowStyle.Fat
            });
        }