private void Button_Click(object sender, RoutedEventArgs e)
        {
            string p = DialogHelpers.OpenLoksimFile(FilePath, FileDialogFilters, null);

            if (!string.IsNullOrEmpty(p))
            {
                FilePath = L3dFilePath.CreateRelativeToFile(p, FilePath != null ? FilePath.ParentFile : null);
            }
        }
示例#2
0
        private void CommandOpen_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            string str = DialogHelpers.OpenLoksimFile(string.Empty, FileExtensions.AllLoksimFiles, this, MAIN_DLG_OPEN);

            if (!string.IsNullOrEmpty(str))
            {
                L3dFilePath p = new L3dFilePath(str);
                if (!L3dFilePath.IsNullOrEmpty(p))
                {
                    OpenFile(p);
                }
            }
        }
示例#3
0
        public SkyFileViewModel(SkyFile skyFile, Window parentWindow)
            : base(skyFile, parentWindow)
        {
            _skyFile         = skyFile;
            _selectedWeather = skyFile.WeatherSets.FirstOrDefault();

            RemoveFileCmd = new RelayCommand(obj =>
            {
                _skyFile.WeatherSets.Remove(_selectedWeather);
                SelectedWeatherFile = null;
            },
                                             obj =>
            {
                return(SelectedWeatherFile != null);
            });

            AddFileCmd = new RelayCommand(obj =>
            {
                string s = DialogHelpers.OpenLoksimFile(string.Empty, FileExtensions.WeatherFiles, parentWindow, WEATHER_DLG_GUID);
                if (!string.IsNullOrEmpty(s))
                {
                    Weather w = new Weather(SkyFile, new L3dFilePath(s));
                    _skyFile.WeatherSets.Add(w);
                    SelectedWeatherFile = w;
                }
            });

            CopyWeatherFile = new RelayCommand(arg =>
            {
                if (SelectedWeatherFile != null)
                {
                    try
                    {
                        Clipboard.SetText(SelectedWeatherFile.ConvertToXml().ToString(), TextDataFormat.UnicodeText);
                    }
                    catch (Exception)
                    {
                        SystemSounds.Exclamation.Play();
                    }
                }
            },
                                               arg =>
            {
                return(SelectedWeatherFile != null);
            }
                                               );

            CutWeatherFile = new RelayCommand(arg =>
            {
                if (SelectedWeatherFile != null)
                {
                    try
                    {
                        Clipboard.SetText(SelectedWeatherFile.ConvertToXml().ToString(), TextDataFormat.UnicodeText);
                        SkyFile.WeatherSets.Remove(SelectedWeatherFile);
                    }
                    catch (Exception)
                    {
                        SystemSounds.Exclamation.Play();
                    }
                }
            },
                                              arg =>
            {
                return(SelectedWeatherFile != null);
            }
                                              );

            PasteWeatherFile = new RelayCommand(arg =>
            {
                var w = Weather.ReadFromXml(Clipboard.GetText(), SkyFile);
                if (w != null)
                {
                    SkyFile.WeatherSets.Add(w);
                    SelectedWeatherFile = w;
                }
            },
                                                arg =>
            {
                return(Clipboard.ContainsText() && Weather.ReadFromXml(Clipboard.GetText(), SkyFile) != null);
            }
                                                );

            WeatherFileDown = new RelayCommand(arg =>
            {
                int ind = SelectedWeatherFileIndex;
                if (ind >= 0 && ind < SkyFile.WeatherSets.Count - 1)
                {
                    var w = SkyFile.WeatherSets[ind];
                    SkyFile.WeatherSets.RemoveAt(ind);
                    SkyFile.WeatherSets.Insert(ind + 1, w);
                }
            },
                                               arg =>
            {
                return(SelectedWeatherFileIndex >= 0 && SelectedWeatherFileIndex < SkyFile.WeatherSets.Count - 1);
            }
                                               );

            WeatherFileUp = new RelayCommand(arg =>
            {
                int ind = SelectedWeatherFileIndex;
                if (ind > 0 && ind < SkyFile.WeatherSets.Count)
                {
                    var w = SkyFile.WeatherSets[ind];
                    SkyFile.WeatherSets.RemoveAt(ind);
                    SkyFile.WeatherSets.Insert(ind - 1, w);
                }
            },
                                             arg =>
            {
                return(SelectedWeatherFileIndex > 0 && SelectedWeatherFileIndex < SkyFile.WeatherSets.Count);
            }
                                             );
        }
示例#4
0
        public FilePropertiesViewModel(LoksimFile file, Window parentWindow)
        {
            _fileAuthor = file.FileAuthor;
            _fileInfo   = file.FileInfo;
            _fileDoku   = file.FileDoku;

            _parentWindow = parentWindow;
            if (!L3dFilePath.IsNullOrEmpty(file.FilePicture))
            {
                SetFilePicSource(file.FilePicture);
            }

            OtherPictureCmd = new RelayCommand(obj =>
            {
                string s = DialogHelpers.OpenLoksimFile(file.FilePicture.AbsolutePath, FileExtensions.ImageFiles, _parentWindow);
                if (!string.IsNullOrEmpty(s))
                {
                    L3dFilePath p = new L3dFilePath(s);
                    RemovePictureCmd.Execute(null);
                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        SetFilePicSource(p);
                    }),
                                                             System.Windows.Threading.DispatcherPriority.Background);
                }
            },
                                               obj =>
            {
                return(!L3dFilePath.IsNullOrEmpty(file.OwnPath));
            });

            PictureFromClipboardCmd = new RelayCommand(obj =>
            {
                if (Clipboard.ContainsImage())
                {
                    FilePicture = Clipboard.GetImage();
                }
            },
                                                       obj =>
            {
                return(Clipboard.ContainsImage() && !L3dFilePath.IsNullOrEmpty(file.OwnPath));
            });

            RemovePictureCmd = new RelayCommand(obj =>
            {
                FilePicture = null;
            },
                                                obj =>
            {
                return(FilePicture != null);
            });

            OkCmd = new RelayCommand(obj =>
            {
                file.FileAuthor = FileAuthor;
                file.FileInfo   = FileInfo;
                file.FileDoku   = FileDoku;

                try
                {
                    if (_picChanged)
                    {
                        if (_filePicture != null)
                        {
                            Image bmp             = null;
                            JpegBitmapEncoder enc = new JpegBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(_filePicture));
                            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                            {
                                enc.Save(memStream);
                                bmp = new Bitmap(memStream);
                            }
                            using (Image img = ImageHelper.ScaleBitmap(bmp, 512, 512))
                            {
                                file.FilePicture = new L3dFilePath(file.OwnPath.AbsolutePath + ".jpg");
                                img.Save(file.FilePicture.AbsolutePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                            }
                            bmp.Dispose();
                        }
                        else
                        {
                            file.FilePicture = null;
                        }
                    }
                    FilePicture = null;
                } catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }

                if (RequestClose != null)
                {
                    RequestClose(true);
                }
            },
                                     obj =>
            {
                return(true);
            });

            CancelCmd = new RelayCommand(obj =>
            {
                if (RequestClose != null)
                {
                    RequestClose(false);
                }
            },
                                         obj =>
            {
                return(true);
            });

            _picChanged = false;
        }