/// <summary>
        /// Asks the user to choose an image from disk and adds it to the list
        /// </summary>
        private void AddImage()
        {
            if (CanAddImages)
            {
                // Move file types somewhere else
                var fileName = IoCServer.UI.ShowSingleFileDialog(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg|bmp files (*.bmp)|*.bm/p");

                // The user did not selected any files
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Bitmap image;
                try
                {
                    image = new Bitmap(fileName);

                    TaskContent.ValidateImage(image);
                }
                catch (FileNotFoundException ex)
                {
                    IoCServer.UI.ShowMessage(new MessageBoxDialogViewModel()
                    {
                        Message = $"Nie można wczytać pliku. Błąd: {ex.Message}",
                        OkText  = "OK",
                        Title   = "Nie można dodać obrazka",
                    });
                    return;
                }
                catch (Exception ex)
                {
                    IoCServer.UI.ShowMessage(new MessageBoxDialogViewModel()
                    {
                        Message = ex.Message,
                        OkText  = "OK",
                        Title   = "Nie można dodać obrazka",
                    });
                    return;
                }

                Items.Add(new ImagesEditorItemViewModel()
                {
                    ID            = Items.Count,
                    Thumbnail     = image.GetThumbnail(),
                    OriginalImage = image,
                });

                Images.Add(image);

                ImageAdded.Invoke(image);

                ListModified.Invoke();

                OnPropertyChanged(nameof(CanAddImages));
                OnPropertyChanged(nameof(CanGoForward));
                OnPropertyChanged(nameof(CanGoBack));
            }
        }
示例#2
0
        public void RemovePoint(LinkedListNode <CurvePoint> p)
        {
            int index = CurvePoints.IndexOf(p);

            CurvePoints.Remove(p);
            ListModified?.Invoke(this, new Tuple <bool, int>(false, index));
            SaveChanges?.Invoke();
        }
示例#3
0
        public void AddPoint(CurvePoint newPoint, LinkedListNode <CurvePoint> relTo, bool before = true)
        {
            newPoint.PropertyChanged += Point_PropertyChanged;
            LinkedListNode <CurvePoint> addedNode;

            if (relTo == null)
            {
                addedNode = CurvePoints.AddFirst(newPoint);
            }
            else if (before)
            {
                addedNode = CurvePoints.AddBefore(relTo, newPoint);
            }
            else
            {
                addedNode = CurvePoints.AddAfter(relTo, newPoint);
            }
            ListModified?.Invoke(this, new Tuple <bool, int>(true, CurvePoints.IndexOf(addedNode)));
            SaveChanges?.Invoke();
        }
        /// <summary>
        /// Deletes an immage from the list
        /// </summary>
        /// <param name="obj"></param>
        private void DeleteImage(object obj)
        {
            var index = GetIndex(obj);

            if (index == -1)
            {
                return;
            }

            var DeletedImage = Images[index];

            Items.RemoveAt(index);
            Images.RemoveAt(index);

            UpdateIndexes(index);

            ImageDeleted.Invoke(DeletedImage);

            ListModified.Invoke();

            OnPropertyChanged(nameof(CanAddImages));
            OnPropertyChanged(nameof(CanGoForward));
            OnPropertyChanged(nameof(CanGoBack));
        }