Esempio n. 1
0
        public MainWindowViewModel()
        {
            var hotKey = HotKey.Create(Key.Left, ModifierKeys.None);

            hotKey.Register();
            hotKey.Pressed += HotKeyOnPressed;
        }
Esempio n. 2
0
 public static Menu Create(
     IProperty <VirtualDevice> currentDevice,
     PreviewDevices previewDevices)
 {
     return(Menu.Submenu(
                "Device",
                Menu.Item(
                    "Flip aspect",
                    command: Command.Enabled(() =>
                                             currentDevice
                                             .Select(device => device.With(
                                                         orientation: device.Orientation == DeviceOrientation.Landscape
                                                                         ? DeviceOrientation.Portrait
                                                                         : DeviceOrientation.Landscape))
                                             .Take(1)
                                             .Subscribe(device => currentDevice.Write(device))),
                    hotkey: HotKey.Create(ModifierKeys.Meta, Key.F))
                + Menu.Separator
                + previewDevices.Devicess.Select(devices => devices.Select((dev, j) =>
                                                                           Menu.Option(
                                                                               name: dev.Name,
                                                                               value: dev,
                                                                               hotkey: GetHotKey(j),
                                                                               property: currentDevice.Convert(
                                                                                   convert: info => info.Screen,
                                                                                   convertBack: screen => new VirtualDevice(screen, screen.DefaultOrientation)))))
                .Concat()
                + Menu.Separator
                + Menu.Item("Customize...", previewDevices.CustomizeDevices())));
 }
Esempio n. 3
0
 static Menu CreateSplashScreenItem()
 {
     return(Menu.Item(
                "New...",
                hotkey: HotKey.Create(ModifierKeys.Meta, Key.N),
                action: () => Application.LaunchedWithoutDocuments()));
 }
Esempio n. 4
0
 static Menu CreateOpenItem()
 {
     return(Menu.Item(
                "Open...",
                hotkey: HotKey.Create(ModifierKeys.Meta, Key.O),
                action: () => Application.ShowOpenDocumentDialog(new FileFilter("Fuse Project", "unoproj"))));
 }
Esempio n. 5
0
        public void UnregisteredHotKeyShoudNotReact()
        {
            var hotKey = HotKey.Create(Key.Escape, ModifierKeys.None);

            hotKey.Register();
            hotKey.Unregister();

            var toSend = new[]
            {
                new KeyEventArgs(Key.Escape, KeyState.KeyDown),
                new KeyEventArgs(Key.Escape, KeyState.KeyUp)
            };

            var actual = EventWaiter.WaitEvent(
                handler => hotKey.Pressed += handler,
                handler => hotKey.Pressed -= handler,
                () =>
            {
                _sender.Send(toSend);
            });

            hotKey.Unregister();

            Assert.False(actual);
            hotKey.Dispose();
        }
Esempio n. 6
0
        public void RegisteredHotKeyBlocksApplicationFromReceivingInput()
        {
            var hotKey = HotKey.Create(Key.Left, ModifierKeys.None);

            hotKey.Register();

            var wasReceived = false;
            var are         = new AutoResetEvent(false);

            _receiver.KeyReceived += (sender, args) =>
            {
                if (args.Key == Key.Left)
                {
                    wasReceived = true;
                    are.Set();
                }
            };

            _sender.Send(new[]
            {
                new KeyEventArgs(Key.Left, KeyState.KeyDown),
                new KeyEventArgs(Key.Left, KeyState.KeyUp)
            });

            are.WaitOne(100);
            Assert.IsFalse(wasReceived);
        }
Esempio n. 7
0
        static HotKey GetHotKey(int index)
        {
            if (index > 9)
            {
                return(HotKey.None);
            }

            return(HotKey.Create(ModifierKeys.Meta, GetNumberKeyFromInt(index)));
        }
Esempio n. 8
0
        static Menu CreateQuitItem(IFuse fuse)
        {
            var quitOrExit = fuse.Platform == OS.Mac ? "Quit" : "Exit";
            var quitItem   = Menu.Item(
                quitOrExit + " " + "Fuse",
                hotkey: fuse.Platform == OS.Windows ? HotKey.Create(ModifierKeys.Alt, Key.F4) : HotKey.Create(ModifierKeys.Command, Key.Q),
                action: () => { Application.Exit(0); });

            return(quitItem);
        }
Esempio n. 9
0
 Menu CreateMenu(IObservable <Optional <IViewport> > viewport)
 {
     return(Menu.Toggle("Selection", _selectionEnabled, HotKey.Create(ModifierKeys.Meta, Key.I))
            + Menu.Separator
            + Menu.Item("New viewport", NewViewport, hotkey: HotKey.Create(ModifierKeys.Meta, Key.T))
            + Menu.Item("Close viewport", CloseFocusedViewport, hotkey: HotKey.Create(ModifierKeys.Meta, Key.W))
            + Menu.Separator
            + Menu.Item("Restart", RestartViewport(viewport))
            + Menu.Separator
            + DevicesMenu.Create(_latestDevice, _previewDevices)
            + Menu.Item("Go back", GoBack, hotkey: HotKey.Create(ModifierKeys.Meta, Key.B)));
 }
Esempio n. 10
0
        public void MultipleRegistrationsAndUnregistrationsShouldNotRiseException()
        {
            var hotKey = HotKey.Create(Key.Escape, ModifierKeys.None);

            Assert.That(() =>
            {
                hotKey.Register();
                hotKey.Register();
                hotKey.Register();
                hotKey.Unregister();
                hotKey.Unregister();
                hotKey.Unregister();
            }, Throws.Nothing);
        }
Esempio n. 11
0
        public Menu CreateMenu(IElement element)
        {
            return(Menu.Item(
                       name: "Locate in editor",
                       command: FocusEditorCommand.Create(_context, _project, _daemon),
                       hotkey: HotKey.Create(ModifierKeys.Meta | ModifierKeys.Alt, Key.L))

                   + Menu.Separator

                   // Edit class element we're currently not editing
                   + Menu.Item(
                       name: element.UxClass().Select(n => "Edit " + n.Or("class")).AsText(),
                       isDefault: true,
                       action: async() => await _context.PushScope(element, element))
                   .ShowWhen(element.UxClass().Select(n => n.HasValue)
                             .And(_context.CurrentScope.IsSameAs(element).IsFalse()))

                   // Edit base
                   + Menu.Item(
                       name: element.Base.UxClass().Select(n => "Edit " + n.Or("class")).AsText(),
                       isEnabled: element.Base.IsReadOnly.IsFalse(),
                       action: async() => await _context.PushScope(element.Base, element.Base))

                   + Menu.Item(
                       name: "Deselect",
                       hotkey: HotKey.Create(ModifierKeys.Meta, Key.D),
                       action: async() => await _context.Select(Element.Empty))

                   + Menu.Separator

                   + Menu.Item(
                       name: "Remove element",
                       command: Command.Create(
                           element.Parent
                           .IsEmpty
                           // Only allow remova; of non-root elements for now
                           // Removing a root element could mean
                           .Select(isRoot => isRoot ?
                                   Optional.None <Action>() :
                                   (Action)(async() =>
            {
                await element.Cut();

                if (await _context.IsSelected(element).FirstAsync())
                {
                    await _context.Select(Element.Empty);
                }
            })))));
        }
Esempio n. 12
0
        public static HotKey ToHotKey(this InputGestureCollection gestures)
        {
            if (gestures.Count < 1)
            {
                return(HotKey.None);
            }

            var gesture = gestures[0] as KeyGesture;

            if (gesture == null)
            {
                return(HotKey.None);
            }

            return(HotKey.Create(gesture.Modifiers.ToFusion(), gesture.Key.ToFusion()));
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        public MainViewModel()
        {
            //アプリの設定
            StaticValues.SystemSetting = new SystemSetting().Load(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            //管理者アイコン取得
            ShieldImage             = ShieldIcon.GetBitmapSource(true);
            PageNavigatorVisibility = Visibility.Collapsed;

            //ホットキー登録
            _hotKey = HotKey.Create();

            //登録情報取得
            _buttonInfo = new ButtonInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            //ドラッグアンドドロップでの移動
            _description           = new DragAcceptDescription();
            _description.DragOver += (e) => {
                if (e.AllowedEffects.HasFlag(e.Effects))
                {
                    if (e.Data.GetDataPresent(typeof(string)))
                    {
                        return;
                    }
                }
                e.Effects = DragDropEffects.None;
            };
            _description.DragDrop += (e) => {
                MovePagePanelZIndex = -1;
                if (!_buttonInfo.GetButtonInfoAllPage().ContainsKey(e.FromPageNo))
                {
                    return;
                }
                if (!_buttonInfo.GetButtonInfoAllPage()[e.FromPageNo].ContainsKey(e.FromButtonNo))
                {
                    return;
                }
                var befInfo = _buttonInfo.GetButtonInfoAllPage()[e.FromPageNo][e.FromButtonNo];
                _buttonInfo.Move(e.FromPageNo, e.FromButtonNo, e.ToPageNo, e.ToButtonNo, befInfo);
                RaisePropertyChanged(nameof(ButtonInfo));
            };
            //透過度
            Opacity = StaticValues.SystemSetting.ToReactivePropertyAsSynchronized(x => x.Opacity);
            //SearchTextBoxBackground = new ReactiveProperty<Drawing>(DrawMyText("Search"));

            //コマンド作成
            CreateCommand();

            //ショートカット登録
            Shortcuts = new Dictionary <KeyData, ICommand>()
            {
                {
                    new KeyData()
                    {
                        KeyCode = Key.Right, Modifier = ModifierKeys.Alt
                    },
                    new RelayCommand(() => {
                        _buttonInfo.NextPage();
                        RaisePropertyChanged(nameof(ButtonInfo));
                    })
                },
                {
                    new KeyData()
                    {
                        KeyCode = Key.Left, Modifier = ModifierKeys.Alt
                    },
                    new RelayCommand(() => {
                        _buttonInfo.PreviousPage();
                        RaisePropertyChanged(nameof(ButtonInfo));
                    })
                },
                {
                    new KeyData()
                    {
                        KeyCode = Key.N, Modifier = ModifierKeys.Control
                    },
                    AddPageCommand
                },
                {
                    new KeyData()
                    {
                        KeyCode = Key.D, Modifier = ModifierKeys.Control
                    },
                    DeletePageCommand
                },
            };

            //SystemMenu
            SystemMenuItems = new List <SystemMenuItem>()
            {
                new SystemMenuItem()
                {
                    MenuID   = 0x0001,
                    MenuName = "ホットキー設定",
                    Command  = HotKeyCommand
                },
                new SystemMenuItem()
                {
                    IsSeparator = true
                },
                new SystemMenuItem()
                {
                    MenuID   = 0x0002,
                    MenuName = "新しいページを追加",
                    Command  = AddPageCommand
                },
                new SystemMenuItem()
                {
                    MenuID   = 0x0003,
                    MenuName = "現在のページを削除",
                    Command  = DeletePageCommand
                },
                new SystemMenuItem()
                {
                    MenuID   = 0x0004,
                    MenuName = "前ページ",
                    Command  = new RelayCommand(() => {
                        _buttonInfo.PreviousPage();
                        RaisePropertyChanged(nameof(ButtonInfo));
                    })
                },
                new SystemMenuItem()
                {
                    MenuID   = 0x0005,
                    MenuName = "次ページ",
                    Command  = new RelayCommand(() => {
                        _buttonInfo.NextPage();
                        RaisePropertyChanged(nameof(ButtonInfo));
                    })
                }
            };
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void Initialize(IList <string> args, bool isDocumentApp)
        {
            Console.CancelKeyPress += (sender, e) => Exit(0);

            NSApplication.Init();

            _dispatcher = _dispatcher ?? new Dispatcher(Thread.CurrentThread);
            Fusion.Application.MainThread = _dispatcher;

            Fusion.Application.PerFrame = Observable.Interval(
                TimeSpan.FromSeconds(1.0 / 60.0),
                new SynchronizationContextScheduler(SynchronizationContext.Current));

            var app = new AppDelegate(isDocumentApp);

            NSApplication.SharedApplication.Delegate = app;

            //TODO do we really need to retain this object?
                        #pragma warning disable 0219
            var documentController = new NSDocumentController();
                        #pragma warning restore 0219

            NSApplication.CheckForIllegalCrossThreadCalls = false;
            AppDelegate.ThrowOnTerminate = false;

            Desktop = new MacDialog <object>();

            EffectsImplementation.Initialize(_dispatcher);

            // Make so that the window popups with focus.
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);

            MacEnvironment.Initialize(new MacEnvironmentImpl());
            DraggingImplementation.Initialize(_dispatcher);
            MenuBuilder.Initialize(_dispatcher);
            LayeringImplementation.Initialize(_dispatcher);
            LabelImplementation.Initialize(_dispatcher);
            SliderImplementation.Initialize(_dispatcher);
            LineImplementation.Initialize(_dispatcher);
            CircleImplementation.Initialize(_dispatcher);
            RectangleImplementation.Initialize(_dispatcher);
            TextBoxImplementation.Initialize(_dispatcher);
            CursorsImplementation.Initialize(_dispatcher);
            ToolTipImplementation.Initialize(_dispatcher);
            ContextMenuImplementation.Initialize(_dispatcher);
            DropDownImplementation.Initialize(_dispatcher);
            ButtonImplementation.Initialize(_dispatcher);
            ColorPickerImplementation.Initialize(_dispatcher);
            ScrollingImplementation.Initialize(_dispatcher);
            LogViewImplementation.Initialize(_dispatcher);
            Transformation.Initialize();
            ImageImplementation.Initialize(_dispatcher);
            OverlayImplementation.Initialize(_dispatcher);
            PointerImplementation.Initialize(_dispatcher);
            KeyboardImplementation.Initialize(_dispatcher);
            WebViewImplementation.Initialize(_dispatcher);
            LayoutTrackerImplementation.Initialize();
            FileDialogs.Initialize();

            // TODO: Fix this!!!
            Clipping.Initialize((control, clip) => control);

            // This notification occurs a _lot_, but is the most specific one I was able to find that would
            //  allow us to be notified when the first responder changes consistently
            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSApplicationDidUpdateNotification"), _ => {
                var keyWindow = NSApplication.SharedApplication.KeyWindow;
                _firstResponder.OnNext(keyWindow != null ? keyWindow.FirstResponder : null);
            });

            app.Terminates.Subscribe(_ =>
            {
                if (Terminating != null)
                {
                    Terminating();
                }
            });

            EditMenu =

                /*CreateFirstResponderMenuItem(name: "Undo", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.Z), selectorName: "undo:")
                 + CreateFirstResponderMenuItem(name: "Redo", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta | Fusion.ModifierKeys.Shift, Key.Z), selectorName: "redo:")
                 + MenuItem.CreateSeparator()
                 + */CreateFirstResponderMenuItem(name: "Cut", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.X), selectorName: "cut:")
                + CreateFirstResponderMenuItem(name: "Copy", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.C), selectorName: "copy:")
                + CreateFirstResponderMenuItem(name: "Paste", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.V), selectorName: "paste:")
                + CreateFirstResponderMenuItem(name: "Paste and Match Style", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta | Fusion.ModifierKeys.Shift, Key.V), selectorName: "pasteAsPlainText:")
                + CreateFirstResponderMenuItem(name: "Delete", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.Backspace), selectorName: "delete:")
                + CreateFirstResponderMenuItem(name: "Select All", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.A), selectorName: "selectAll:");
        }