public void OpenFile(L3dFilePath p) { if (!L3dFilePath.IsNullOrEmpty(p)) { var w = _openAppWindows.FirstOrDefault(m => m._currentViewModel != null && m._currentViewModel.CurrentFile != null && L3dFilePath.Equals(m._currentViewModel.CurrentFile.OwnPath, p)); if (w != null) { //w.BringIntoView(); if (w.WindowState == System.Windows.WindowState.Minimized) { w.WindowState = System.Windows.WindowState.Normal; } w.Activate(); } else { if (_currentViewModel == null) { Mouse.OverrideCursor = Cursors.Wait; LoksimFile file = LoadFile(p); SetCtrlAndViewModel(file); Mouse.OverrideCursor = null; } else { new MainWindow(p.AbsolutePath).Show(); } } SetRecentFilesMenu(); } }
public FilePropertiesWindow(LoksimFile file) { InitializeComponent(); viewModel = new FilePropertiesViewModel(file, this); viewModel.RequestClose += viewModel_RequestClose; this.DataContext = viewModel; }
private void CommandNew_Executed(object sender, ExecutedRoutedEventArgs e) { NewFileWindow dlg = new NewFileWindow(); dlg.Owner = this; if (dlg.ShowDialog().GetValueOrDefault(false)) { LoksimFile file = dlg.SelectedFile; if (_currentViewModel != null) { if (file is WeatherFile) { new MainWindow("-l3dwth").Show(); } else if (file is SkyFile) { new MainWindow("-l3dsky").Show(); } else if (file is DrivingCabFile) { new MainWindow("-l3dfst").Show(); } else { Debug.Assert(false, "Unknown File Type"); } } else { SetCtrlAndViewModel(file); } } }
private void SetCtrlAndViewModel(LoksimFile file) { UserControl ctrl = null; if (file is WeatherFile) { _currentViewModel = new WeatherViewModel(file as WeatherFile, this); ctrl = new WeatherFileEdit(); } else if (file is SkyFile) { _currentViewModel = new SkyFileViewModel(file as SkyFile, this); ctrl = new SkyFileEdit(); } else if (file is DrivingCabFile) { _currentViewModel = new DrivingCabViewModel(file as DrivingCabFile, this); ctrl = new DrivingCabFileEdit(); } if (ctrl != null) { ctrl.DataContext = _currentViewModel; mainDock.Children.Add(ctrl); } }
private LoksimFile LoadFile(L3dFilePath path) { LoksimFile file = null; try { switch (System.IO.Path.GetExtension(path.AbsolutePath).ToLower()) { case ".l3dwth": { WeatherFile f = new WeatherFile(); f.LoadFromFile(path); file = f; } break; case ".l3dsky": { SkyFile f = new SkyFile(); f.LoadFromFile(path); file = f; } break; case ".l3dfst": { DrivingCabFile f = new DrivingCabFile(); f.LoadFromFile(path); file = f; } break; default: Debug.Assert(false, "Unknown File Type"); break; } this.Title = Loksim3D.WetterEdit.Resources.Strings.AppName + " [" + path.Filename + "]"; Settings.RegistrySettings.Default.AddRecentFile(path); } catch (Exception ex) { Mouse.OverrideCursor = null; MessageBox.Show(String.Format(Loksim3D.WetterEdit.Resources.Strings.ErrorLoadingFile_0_Msg_1_, path.Filename, ex.Message), Loksim3D.WetterEdit.Resources.Strings.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } return(file); }
internal void CreateNewFile(string fileToOpen) { if (fileToOpen != null) { string arg0 = _fileToOpen.Trim(); LoksimFile file = null; switch (arg0.ToLower()) { case "-l3dsky": file = new SkyFile(); break; case "-l3dwth": file = WeatherFile.CreateNewDefaultFile(); break; case "-l3dfst": file = new DrivingCabFile(); break; default: file = LoadFile(new L3dFilePath(arg0)); break; } if (file != null) { SetCtrlAndViewModel(file); } } #if DEBUG //TODO Just for driving cab dev /* * else * { * LoksimFile f = new DrivingCabFile(); * SetCtrlAndViewModel(f); * } */ #endif }
protected BaseL3dFileViewModel(LoksimFile openFile, Window parentWindow) { CurrentFile = openFile; ParentWindow = parentWindow; _fileSaveCmd = new RelayCommand(obj => { SaveOrSaveAs(false); }, obj => { return(CurrentFile != null && !L3dFilePath.IsNullOrEmpty(CurrentFile.OwnPath)); } ); _fileSaveAsCmd = new RelayCommand(obj => { SaveOrSaveAs(true); }, obj => { return(CurrentFile != null); } ); FilePropertiesCmd = new RelayCommand(obj => { Window dlg = new FilePropertiesWindow(CurrentFile); dlg.Owner = ParentWindow; dlg.ShowDialog(); }, obj => { return(CurrentFile != null); } ); UndoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Undo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.UndoPossible); } ); RedoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Redo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.RedoPossible); } ); }
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; }