/// <summary> /// Create a new model /// </summary> /// <param name="file"></param> public TranslationEditorViewModel(TranslationFileViewModel file) { this.Translations = new ObservableCollection<TranslationViewModel>(); this.File = file; SaveCommand = new RelayCommand( async () => await SaveAsync(), () => IsDirty ); MoveToPreviousTranslationCommand = new RelayCommand( () => MoveToPreviousTranslation(), () => { int idx = Translations.IndexOf(CurrentTranslation); return idx > 0; } ); MoveToNextTranslationCommand = new RelayCommand( () => MoveToNextTranslation(), () => { int idx = Translations.IndexOf(CurrentTranslation); return idx >= 0 && idx < Translations.Count - 1; } ); }
/// <summary> /// Open a translation /// </summary> public async Task<TranslationEditorViewModel> OpenTranslationAsync(TranslationFileViewModel file) { if (file == null) return null; TranslationEditorViewModel trans = Editors.FirstOrDefault(e => e.File == file); if (trans == null) { if (Loading) return null; Loading = true; try { trans = new TranslationEditorViewModel(file); Editors.Add(trans); await trans.LoadAsync(); } finally { Loading = false; } } CurrentEditor = trans; return trans; }
internal void UpdateFiles(IEnumerable<TranslationFile> files) { var currentFiles = Files.ToList(); foreach (var file in files) { var cFile = currentFiles.FirstOrDefault(f => String.Equals(file.File, f.File.File, StringComparison.OrdinalIgnoreCase)); if(cFile== null) { cFile = new TranslationFileViewModel(this, file); this.Files.Add(cFile); } currentFiles.Remove(cFile); } NeutralFile = Files.FirstOrDefault(f => f.File.IsNeutral); }