Exemplo n.º 1
0
        private void TriggerEvent(string cmd, object o)
        {
            try
            {
                switch (cmd)
                {
                case WindowsCmdConsts.Next_Image:
                    if (ImageLIst.SelectedIndex <
                        ImageLIst.Items.Count - 1)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind + 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Prev_Image:
                    if (ImageLIst.SelectedIndex > 0)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind - 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Like_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item = ServiceProvider.Settings.DefaultSession.GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsLiked = !item.IsLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Unlike_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item =
                                ServiceProvider.Settings.DefaultSession
                                .GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsUnLiked = !item.IsUnLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Del_Image:
                {
                    DeleteItem();
                }
                break;

                case WindowsCmdConsts.Select_Image:
                    FileItem fileItem = o as FileItem;
                    if (fileItem != null)
                    {
                        ImageLIst.SelectedValue = fileItem;
                        ImageLIst.ScrollIntoView(fileItem);
                    }
                    break;

                case WindowsCmdConsts.Refresh_Image:
                    RefreshImage();
                    break;

                case WindowsCmdConsts.Zoom_Image_Fit:
                    ZoomAndPanControl.AnimatedScaleToFit();
                    break;

                case WindowsCmdConsts.Zoom_Image_100:
                    ZoomToFocus();
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(1.0);
                    break;

                case WindowsCmdConsts.Zoom_Image_200:
                    ZoomToFocus();
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(2.0);
                    break;

                case WindowsCmdConsts.RotateLeft:
                {
                    FileItem item =
                        ImageLIst.SelectedItem as FileItem;
                    if (item != null)
                    {
                        item.Rotation--;
                    }
                }
                break;

                case WindowsCmdConsts.RotateRight:
                {
                    FileItem item =
                        ImageLIst.SelectedItem as FileItem;
                    if (item != null)
                    {
                        item.Rotation++;
                    }
                }
                break;
                }
                if (cmd.StartsWith(WindowsCmdConsts.ZoomPoint))
                {
                    if (ZoomAndPanControl != null && cmd.Contains("_"))
                    {
                        var vals = cmd.Split('_');
                        if (vals.Count() > 2)
                        {
                            double x;
                            double y;
                            double.TryParse(vals[1], out x);
                            double.TryParse(vals[2], out y);
                            if (cmd.EndsWith("!"))
                            {
                                ZoomAndPanControl.SnapToRation(x, y);
                            }
                            else
                            {
                                ZoomAndPanControl.AnimatedSnapToRation(x, y);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("Unable to process event ", exception);
            }
        }
Exemplo n.º 2
0
        private void Trigger_Event(string cmd, object o)
        {
            ImageLIst.Dispatcher.Invoke(new Action(delegate
            {
                switch (cmd)
                {
                case WindowsCmdConsts.Next_Image:
                    if (ImageLIst.SelectedIndex <
                        ImageLIst.Items.Count - 1)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind + 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Prev_Image:
                    if (ImageLIst.SelectedIndex > 0)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind - 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Like_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item = ServiceProvider.Settings.DefaultSession.GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsLiked = !item.IsLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Unlike_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item =
                                ServiceProvider.Settings.DefaultSession
                                .GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsUnLiked = !item.IsUnLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Del_Image:
                    {
                        DeleteItem();
                    }
                    break;

                case WindowsCmdConsts.Select_Image:
                    FileItem fileItem = o as FileItem;
                    if (fileItem != null)
                    {
                        ImageLIst.SelectedValue = fileItem;
                        ImageLIst.ScrollIntoView(fileItem);
                    }
                    break;

                case WindowsCmdConsts.Refresh_Image:
                    if (!_worker.IsBusy)
                    {
                        _worker.RunWorkerAsync(false);
                    }
                    break;

                case WindowsCmdConsts.Zoom_Image_Fit:
                    ZoomAndPanControl.AnimatedScaleToFit();
                    break;

                case WindowsCmdConsts.Zoom_Image_100:
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(1.0);
                    break;

                case WindowsCmdConsts.Zoom_Image_200:
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(2.0);
                    break;
                }
                if (cmd.StartsWith(WindowsCmdConsts.ZoomPoint))
                {
                    if (ZoomAndPanControl != null && cmd.Contains("_"))
                    {
                        var vals = cmd.Split('_');
                        if (vals.Count() > 2)
                        {
                            double x;
                            double y;
                            double.TryParse(vals[1], out x);
                            double.TryParse(vals[2], out y);
                            if (cmd.EndsWith("!"))
                            {
                                ZoomAndPanControl.SnapToRation(x, y);
                            }
                            else
                            {
                                ZoomAndPanControl.AnimatedSnapToRation(x, y);
                            }
                        }
                    }
                }
            }));
        }