private void buttonOK_Click(object sender, EventArgs e) { ExportedProfiles = new List <RulesProfile>(); foreach (ListViewItem item in listViewExportStyles.Items) { if (item.Checked) { ExportedProfiles.Add(item.Tag as RulesProfile); } } if (ExportedProfiles.Count == 0) { return; } saveFileDialogStyle.Title = Configuration.Settings.Language.Settings.ExportProfiles; saveFileDialogStyle.InitialDirectory = Configuration.DataDirectory; saveFileDialogStyle.Filter = Configuration.Settings.Language.Settings.Profiles + "|*.profile"; saveFileDialogStyle.FileName = "SE_Profiles.profile"; if (saveFileDialogStyle.ShowDialog(this) != DialogResult.OK) { return; } File.WriteAllText(saveFileDialogStyle.FileName, RulesProfile.Serialize(ExportedProfiles)); DialogResult = DialogResult.OK; }
private void buttonImport_Click(object sender, EventArgs e) { openFileDialogImport.Title = LanguageSettings.Current.Settings.ImportProfiles; openFileDialogImport.InitialDirectory = Configuration.DataDirectory; openFileDialogImport.Filter = LanguageSettings.Current.Settings.Profiles + "|*.profile"; if (openFileDialogImport.ShowDialog(this) != DialogResult.OK) { return; } try { var importProfiles = RulesProfile.Deserialize(FileUtil.ReadAllTextShared(openFileDialogImport.FileName, Encoding.UTF8)); foreach (var profile in importProfiles) { var name = profile.Name; if (RulesProfiles.Any(p => p.Name == profile.Name)) { profile.Name = name + "_2"; } if (RulesProfiles.Any(p => p.Name == profile.Name)) { profile.Name = name + "_" + Guid.NewGuid(); } RulesProfiles.Add(profile); ShowRulesProfiles(profile, false); } } catch { MessageBox.Show("Unable to import profiles"); } }
private void buttonAdd_Click(object sender, EventArgs e) { var gs = new GeneralSettings(); var profile = new RulesProfile(gs.Profiles.First()) { Name = "New", Id = Guid.NewGuid() }; RulesProfiles.Add(profile); ShowRulesProfiles(profile, false); textBoxName.Focus(); }
private void buttonCopy_Click(object sender, EventArgs e) { var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1; if (idx < 0) { return; } var source = RulesProfiles[idx]; var profile = new RulesProfile(source) { Name = "Copy of " + source.Name, Id = Guid.NewGuid() }; RulesProfiles.Add(profile); ShowRulesProfiles(profile, false); }
private void ShowRulesProfiles(RulesProfile itemToFocus, bool sort) { _editOn = false; var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1; if (sort) { RulesProfiles = RulesProfiles.OrderBy(p => p.Name).ToList(); } listViewProfiles.BeginUpdate(); listViewProfiles.Items.Clear(); foreach (var profile in RulesProfiles) { var item = new ListViewItem { Text = profile.Name }; item.SubItems.Add(profile.SubtitleLineMaximumLength.ToString(CultureInfo.InvariantCulture)); item.SubItems.Add(profile.SubtitleOptimalCharactersPerSeconds.ToString(CultureInfo.CurrentCulture)); item.SubItems.Add(profile.SubtitleMaximumCharactersPerSeconds.ToString(CultureInfo.CurrentCulture)); item.SubItems.Add(profile.MinimumMillisecondsBetweenLines.ToString(CultureInfo.CurrentCulture)); listViewProfiles.Items.Add(item); if (itemToFocus == profile) { listViewProfiles.Items[listViewProfiles.Items.Count - 1].Selected = true; } } listViewProfiles.EndUpdate(); if (itemToFocus == null && listViewProfiles.Items.Count > 0) { if (idx < 0) { idx = 0; } else if (idx >= listViewProfiles.Items.Count) { idx = listViewProfiles.Items.Count - 1; } listViewProfiles.Items[idx].Selected = true; } _editOn = true; }