Exemplo n.º 1
0
        public CaptureWindow()
        {
            InitializeComponent();
            ViewModel = new CaptureWindowViewModel();

            this.BindCommand(ViewModel, x => x.ExitCommand, x => x.EscapeKey);
            this.WhenAnyObservable(x => x.ViewModel.ExitCommand).Subscribe(_ => Close());
            this.WhenAnyObservable(x => x.ViewModel.CaptureCommand).Subscribe(async r => {
                Close();
                var rect = r as Rectangle;
                var file =
                    await
                    CaptureScreen.Capture((int)Canvas.GetLeft(rect), (int)Canvas.GetTop(rect), (int)rect.Width, (int)rect.Height);

                if (string.IsNullOrEmpty(file))
                {
                    return;
                }

                var previewWindow = new PreviewWindow(file);
                previewWindow.Show();
            });

            EventsMixin.Events(this).MouseLeftButtonDown.Subscribe(e => {
                var point = e.GetPosition(this);
                Canvas.SetLeft(Target, point.X);
                Canvas.SetTop(Target, point.Y);
            });

            EventsMixin.Events(this).MouseMove.Where(x => x.LeftButton == MouseButtonState.Pressed).Subscribe(e => {
                var point  = e.GetPosition(this);
                var width  = point.X - Canvas.GetLeft(Target);
                var height = point.Y - Canvas.GetTop(Target);
                if (!(width > 0) || !(height > 0))
                {
                    return;
                }
                Target.Width  = width;
                Target.Height = height;
            });

            EventsMixin.Events(this).MouseLeftButtonUp.Subscribe(e => {
                Target.Visibility = Visibility.Collapsed;
                ViewModel.CaptureCommand.Execute(Target);
            });

            EventsMixin.Events(this).Unloaded.Subscribe(_ => MessageBus.Current.SendMessage <object>(null, "CaptureWindow"));
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            ViewModel = new MainWindowViewModel();

            WindowState = !App.Settings.StartMinimized ? WindowState.Normal : WindowState.Minimized;

            this.WhenAnyValue(x => x.WindowState).Where(x => x == WindowState.Minimized).Subscribe(x => Hide());
            this.WhenAnyObservable(x => x.ViewModel.VisiblityCommand).Subscribe(_ => {
                Show();
                WindowState = WindowState.Normal;
            });

            this.OneWayBind(ViewModel, x => x.Title, x => x.Title);
            this.OneWayBind(ViewModel, x => x.IsTopmost, x => x.Topmost);
            this.OneWayBind(ViewModel, x => x.Title, x => x.TaskbarIcon.ToolTipText);
            this.OneWayBind(ViewModel, x => x.VisiblityCommand, x => x.TaskbarIcon.DoubleClickCommand);
            this.OneWayBind(ViewModel, x => x.ImageHistory, x => x.HistoryList.ItemsSource);
            this.BindCommand(ViewModel, x => x.UploadCommand, x => x.MenuUpload);
            this.BindCommand(ViewModel, x => x.UploadCommand, x => x.TrayUpload);
            this.BindCommand(ViewModel, x => x.UploadCommand, x => x.ButtonBrowse);
            this.BindCommand(ViewModel, x => x.ScreenCommand, x => x.ButtonScreen);
            this.BindCommand(ViewModel, x => x.SelectionCommand, x => x.ButtonSelection);
            this.BindCommand(ViewModel, x => x.SettingsCommand, x => x.MenuSettings);
            this.BindCommand(ViewModel, x => x.SettingsCommand, x => x.TraySettings);

            this.WhenAnyObservable(x => x.ViewModel.UploadCommand).Subscribe(_ => {
                var dialog = new OpenFileDialog {
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    Filter           = "Image files (*.jpg, *.gif, *.png, *.bmp, *.tiff, *.pdf)|*.jpg;*.gif;*.png;*.bmp;*.tiff;*.pdf",
                    Title            = "Upload Images",
                    Multiselect      = true
                };
                dialog.ShowDialog();
                ViewModel.OpenCommand.Execute(dialog.FileNames);
            });

            this.WhenAnyObservable(x => x.ViewModel.ScreenCommand).Subscribe(async _ => {
                var file =
                    await
                    CaptureScreen.Capture(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                          Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

                var previewWindow = new PreviewWindow(file);
                previewWindow.Show();
            });

            this.WhenAnyObservable(x => x.ViewModel.SelectionCommand).Subscribe(_ => {
                var captureWindow = new CaptureWindow();
                captureWindow.Show();
            });

            this.WhenAnyObservable(x => x.ViewModel.SettingsCommand).Subscribe(_ => {
                var settingsWindow = new SettingsWindow {
                    Owner = this
                };
                settingsWindow.Show();
            });

            TrayShow.Events().Click.Subscribe(_ => ViewModel.VisiblityCommand.Execute(null));
            TrayExit.Events().Click.Subscribe(_ => Close());
            MenuExit.Events().Click.Subscribe(_ => Close());
            MenuWebsite.Events().Click.Subscribe(_ => Process.Start("https://github.com/vevix/Pixel"));
            HistoryList.Events().MouseDoubleClick.Subscribe(_ => Process.Start(HistoryList.SelectedValue.ToString()));
            Dropbox.Events().Drop.Subscribe(e => ViewModel.DropCommand.Execute(e));

            MessageBus.Current.Listen <NotificationMessage>()
            .Subscribe(e => TaskbarIcon.ShowBalloonTip(e.Title, e.Text, e.Icon));
        }