From 54e6a851ccec4be58087f8d90d4e04fb2623b4b5 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 8 Jan 2012 15:09:40 +0000 Subject: WinGui: (WPF) Further work on hooking up the various tabs on the Main Window. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4404 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrakeWPF/ViewModels/ChaptersViewModel.cs | 117 ++++++++++++++++----- 1 file changed, 88 insertions(+), 29 deletions(-) (limited to 'win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs') diff --git a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs index 672082b51..262d6585d 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.ViewModels using Caliburn.Micro; using HandBrake.ApplicationServices.Exceptions; + using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; @@ -32,10 +33,16 @@ namespace HandBrakeWPF.ViewModels [Export(typeof(IChaptersViewModel))] public class ChaptersViewModel : ViewModelBase, IChaptersViewModel { + #region Constants and Fields + /// - /// Gets or sets SourceChapterList. + /// The include chapter markers. /// - private ObservableCollection SourceChapterList { get; set; } + private bool includeChapterMarkers; + + #endregion + + #region Constructors and Destructors /// /// Initializes a new instance of the class. @@ -51,6 +58,10 @@ namespace HandBrakeWPF.ViewModels this.Chapters = new ObservableCollection(); } + #endregion + + #region Public Properties + /// /// Gets or sets State. /// @@ -59,25 +70,45 @@ namespace HandBrakeWPF.ViewModels /// /// Gets or sets a value indicating whether chapter markers are enabled. /// - public bool IncludeChapterMarkers { get; set; } + public bool IncludeChapterMarkers + { + get + { + return this.includeChapterMarkers; + } + set + { + this.includeChapterMarkers = value; + this.NotifyOfPropertyChange(() => this.IncludeChapterMarkers); + } + } + + #endregion + + #region Properties /// - /// Set the Source Chapters List + /// Gets or sets SourceChapterList. /// - /// - /// The source chapters. - /// - public void SetSourceChapters(IEnumerable sourceChapters) - { - // Cache the chapters in this screen - this.SourceChapterList = new ObservableCollection(sourceChapters); - this.Chapters.Clear(); + private ObservableCollection SourceChapterList { get; set; } - // Then Add new Chapter Markers. - foreach (Chapter chapter in SourceChapterList) + #endregion + + #region Public Methods + + /// + /// Export a CSV file. + /// + public void Export() + { + var saveFileDialog = new VistaSaveFileDialog + { + Filter = "Csv File|*.csv", DefaultExt = "csv", CheckPathExists = true + }; + saveFileDialog.ShowDialog(); + if (!string.IsNullOrEmpty(saveFileDialog.FileName)) { - ChapterMarker marker = new ChapterMarker(chapter.ChapterNumber, chapter.ChapterName); - this.Chapters.Add(marker); + this.ExportChaptersToCSV(saveFileDialog.FileName); } } @@ -103,23 +134,26 @@ namespace HandBrakeWPF.ViewModels csv += row.ChapterName.Replace(",", "\\,"); csv += Environment.NewLine; } - StreamWriter file = new StreamWriter(filename); + var file = new StreamWriter(filename); file.Write(csv); file.Close(); file.Dispose(); } catch (Exception exc) { - throw new GeneralApplicationException("Unable to save Chapter Makrers file! ", "Chapter marker names will NOT be saved in your encode.", exc); + throw new GeneralApplicationException( + "Unable to save Chapter Makrers file! ", + "Chapter marker names will NOT be saved in your encode.", + exc); } } /// /// Import a CSV file /// - private void Import() + public void Import() { - VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "CSV files (*.csv)|*.csv", CheckFileExists = true }; + var dialog = new VistaOpenFileDialog { Filter = "CSV files (*.csv)|*.csv", CheckFileExists = true }; dialog.ShowDialog(); string filename = dialog.FileName; @@ -131,7 +165,7 @@ namespace HandBrakeWPF.ViewModels IDictionary chapterMap = new Dictionary(); try { - StreamReader sr = new StreamReader(filename); + var sr = new StreamReader(filename); string csv = sr.ReadLine(); while (csv != null) { @@ -152,26 +186,51 @@ namespace HandBrakeWPF.ViewModels } // Now iterate over each chatper we have, and set it's name - foreach (ChapterMarker item in Chapters) + foreach (ChapterMarker item in this.Chapters) { string chapterName; chapterMap.TryGetValue(item.ChapterNumber, out chapterName); item.ChapterName = chapterName; + // TODO force a fresh of this property } } /// - /// Export a CSV file. + /// The set preset. /// - private void Export() + /// + /// The preset. + /// + /// + /// The current Title. + /// + public void Setup(Preset preset, Title currentTitle) { - VistaSaveFileDialog saveFileDialog = new VistaSaveFileDialog { Filter = "Csv File|*.csv", DefaultExt = "csv", CheckPathExists = true }; - saveFileDialog.ShowDialog(); - if (!string.IsNullOrEmpty(saveFileDialog.FileName)) + this.IncludeChapterMarkers = preset.Task.IncludeChapterMarkers; + this.SetSourceChapters(currentTitle.Chapters); + } + + /// + /// Set the Source Chapters List + /// + /// + /// The source chapters. + /// + public void SetSourceChapters(IEnumerable sourceChapters) + { + // Cache the chapters in this screen + this.SourceChapterList = new ObservableCollection(sourceChapters); + this.Chapters.Clear(); + + // Then Add new Chapter Markers. + foreach (Chapter chapter in this.SourceChapterList) { - this.ExportChaptersToCSV(saveFileDialog.FileName); + var marker = new ChapterMarker(chapter.ChapterNumber, chapter.ChapterName); + this.Chapters.Add(marker); } } + + #endregion } -} +} \ No newline at end of file -- cgit v1.2.3