Exemplo n.º 1
0
        private void ExecuteSave(object sender, ExecutedRoutedEventArgs e)
        {
            var cbm = this.CbmFile;

            if (cbm == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(cbm.FileName))
            {
                this.ExecuteSaveAs(null, null);
                return;
            }

            this.RunBusyAction(disp =>
            {
                try
                {
                    cbm.Save(cbm.FileName);

                    disp(() => this.CbmFile = cbm);
                }
                catch (Exception ex)
                {
                    disp(() => MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
Exemplo n.º 2
0
        private void ExecuteOpen(object sender, ExecutedRoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.DefaultExt      = ".cbm";
            dialog.CheckFileExists = true;
            dialog.Filter          = "CBM files (*.cbm)|*.cbm";

            string fileName;

            if (dialog.ShowDialog(this) == true)
            {
                fileName = dialog.FileName;
            }
            else
            {
                return;
            }

            this.RunBusyAction(disp =>
            {
                try
                {
                    var cbm = CbmFile.FromFile(fileName);
                    disp(() => this.CbmFile = cbm);
                }
                catch (Exception ex)
                {
                    disp(() => MessageBox.Show(this, fileName + "\n" + ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
Exemplo n.º 3
0
        private void ExecuteNew(object sender, ExecutedRoutedEventArgs e)
        {
            this.RunBusyAction(disp =>
            {
                var cbm = new CbmFile();

                disp(() => this.CbmFile = cbm);
            });
        }
Exemplo n.º 4
0
        private void SetImageColorKey_Click(object sender, RoutedEventArgs e)
        {
            var image = this.ImagesList.SelectedItem as CbmImage;

            if (image == null)
            {
                return;
            }

            Color colorKey = this.DatImageColorKey.SelectedColor;

            this.RunBusyAction(disp =>
            {
                image.MakeColorTransparent(colorKey.R, colorKey.G, colorKey.B);
                disp(() => this.CbmFile = this.CbmFile);
            });
        }
Exemplo n.º 5
0
        private void NewImage_Click(object sender, RoutedEventArgs e)
        {
            var cbm = this.CbmFile;

            if (cbm == null)
            {
                return;
            }

            this.RunBusyAction(disp =>
            {
                var image = new CbmImage();
                cbm.Images.Add(image);

                disp(() => this.CbmFile = this.CbmFile);
                disp(() => this.ImagesList.SelectedIndex = this.ImagesList.Items.Count - 1);
            });
        }
Exemplo n.º 6
0
        private void AddImage_Click(object sender, RoutedEventArgs e)
        {
            var cbm = this.CbmFile;

            if (cbm == null)
            {
                return;
            }

            var dialog = new OpenFileDialog();

            dialog.CheckFileExists = true;
            dialog.DefaultExt      = ".png";
            dialog.Filter          = "Images (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg|PNG files (*.png)|*.png|BMP files (*.bmp)|*.bmp|JPG files (*.jpg)|*.jpg";

            string fileName;

            if (dialog.ShowDialog(this) == true)
            {
                fileName = dialog.FileName;
            }
            else
            {
                return;
            }

            this.RunBusyAction(disp =>
            {
                try
                {
                    var image = CbmImage.FromFile(fileName);

                    cbm.Images.Add(image);

                    disp(() => this.CbmFile = this.CbmFile);
                    disp(() => this.ImagesList.SelectedIndex = this.ImagesList.Items.Count - 1);
                }
                catch (Exception ex)
                {
                    disp(() => MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
Exemplo n.º 7
0
        private void ExecuteOpen(object sender, ExecutedRoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Title           = "Select a folder";
            dialog.DefaultExt      = ".cbm";
            dialog.CheckFileExists = true;
            dialog.Filter          = "CBM files (*.cbm)|*.cbm";

            string directory;

            if (dialog.ShowDialog(this) == true)
            {
                directory = System.IO.Path.GetDirectoryName(dialog.FileName);
                directory = System.IO.Path.GetDirectoryName(directory);
            }
            else
            {
                return;
            }

            this.DataContext = null;

            this.RunBusyAction(disp =>
            {
                try
                {
                    var cbmFiles = System.IO.Directory.EnumerateFiles(directory, "*.CBM", System.IO.SearchOption.AllDirectories)
                                   .Select(file => CbmFile.FromFile(file))
                                   .ToDictionary(
                        t => string.Concat(System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(t.FileName)), "-", System.IO.Path.GetFileNameWithoutExtension(t.FileName)).ToUpperInvariant(),
                        t => t);

                    disp(() => this.DataContext = cbmFiles);
                }
                catch (Exception ex)
                {
                    disp(() => MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
Exemplo n.º 8
0
        private void ExecuteSaveAs(object sender, ExecutedRoutedEventArgs e)
        {
            var cbm = this.CbmFile;

            if (cbm == null)
            {
                return;
            }

            var dialog = new SaveFileDialog();

            dialog.AddExtension = true;
            dialog.DefaultExt   = ".cbm";
            dialog.Filter       = "CBM files (*.cbm)|*.cbm";
            dialog.FileName     = System.IO.Path.GetFileName(cbm.FileName);

            string fileName;

            if (dialog.ShowDialog(this) == true)
            {
                fileName = dialog.FileName;
            }
            else
            {
                return;
            }

            this.RunBusyAction(disp =>
            {
                try
                {
                    cbm.Save(fileName);
                    disp(() => this.CbmFile = cbm);
                }
                catch (Exception ex)
                {
                    disp(() => MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
Exemplo n.º 9
0
        private void DeleteImage_Click(object sender, RoutedEventArgs e)
        {
            var cbm = this.CbmFile;

            if (cbm == null)
            {
                return;
            }

            int index = this.ImagesList.SelectedIndex;

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

            this.RunBusyAction(disp =>
            {
                cbm.Images.RemoveAt(index);

                disp(() => this.ImagesList.SelectedIndex = -1);
                disp(() => this.CbmFile = this.CbmFile);
            });
        }