Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.chooseStyle = ChooseStyle.TimeSpan;
            try
            {
                this.tempDateTime_1 = this.tempDateTime_0;  //  Initialize the temp datetime.
                this.tempDateTime_1 = this.tempDateTime_1.AddHours(Convert.ToDouble(HourBox.Text));
                this.tempDateTime_1 = this.tempDateTime_1.AddMinutes(Convert.ToDouble(MinBox.Text));
                this.tempDateTime_1 = this.tempDateTime_1.AddSeconds(Convert.ToDouble(SecBox.Text));    //  Add time duration to the time.
                if (this.option == TimerOption.CycleCount || this.option == TimerOption.Interval)
                {
                    this.Cycle_limit = Convert.ToInt32(CountBox.Text);
                }
                else
                {
                    this.Cycle_limit = 0;
                }                           //  Try to get the inputs if they're valid.
            }
            catch (System.FormatException)  //  Got the wrong input.
            {
                Console.WriteLine("Warning! Haven't input the duration yet.");
                MessageBox.Show("请输入正确格式", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.duration = this.tempDateTime_1.Subtract(this.tempDateTime_0);      //  Got the input time duration.

            if (this.option == TimerOption.Timing)
            {
                this.duration = new System.TimeSpan(0); //  If it is a timing timer, the duration should be cleared.
            }
            this.OnChosen();
        }
Ejemplo n.º 2
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            openFileDialogImport.Title = Configuration.Settings.Language.SubStationAlphaStyles.ImportStyleFromFile;
            openFileDialogImport.InitialDirectory = Configuration.DataDirectory;
            if (_isSubStationAlpha)
            {
                openFileDialogImport.Filter = SubStationAlpha.NameOfFormat + "|*.ssa|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ssa";
            }
            else
            {
                openFileDialogImport.Filter = AdvancedSubStationAlpha.NameOfFormat + "|*.ass|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ass";
            }

            if (openFileDialogImport.ShowDialog(this) == DialogResult.OK)
            {
                Encoding encoding = null;
                var s = new Subtitle();
                var format = s.LoadSubtitle(openFileDialogImport.FileName, out encoding, null);
                if (format != null && format.HasStyleSupport)
                {
                    var styles = AdvancedSubStationAlpha.GetStylesFromHeader(s.Header);
                    if (styles.Count > 0)
                    {
                        var cs = new ChooseStyle(s, format.GetType() == typeof(SubStationAlpha));
                        if (cs.ShowDialog(this) == DialogResult.OK && cs.SelectedStyleName != null)
                        {
                            SsaStyle style = AdvancedSubStationAlpha.GetSsaStyle(cs.SelectedStyleName, s.Header);
                            if (GetSsaStyle(style.Name).LoadedFromHeader)
                            {
                                int count = 2;
                                bool doRepeat = GetSsaStyle(style.Name + count).LoadedFromHeader;
                                while (doRepeat)
                                {
                                    doRepeat = GetSsaStyle(style.Name + count).LoadedFromHeader;
                                    count++;
                                }
                                style.RawLine = style.RawLine.Replace(" " + style.Name + ",", " " + style.Name + count + ",");
                                style.Name = style.Name + count;
                            }

                            _doUpdate = false;
                            AddStyle(listViewStyles, style, Subtitle, _isSubStationAlpha);
                            SsaStyle oldStyle = GetSsaStyle(listViewStyles.Items[0].Text);
                            _header = _header.Trim();
                            if (_header.EndsWith("[Events]"))
                            {
                                _header = _header.Substring(0, _header.Length - "[Events]".Length).Trim();
                                _header += Environment.NewLine + style.RawLine;
                                _header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine;
                            }
                            else
                            {
                                _header = _header.Trim() + Environment.NewLine + style.RawLine + Environment.NewLine;
                            }

                            listViewStyles.Items[listViewStyles.Items.Count - 1].Selected = true;
                            listViewStyles.Items[listViewStyles.Items.Count - 1].EnsureVisible();
                            listViewStyles.Items[listViewStyles.Items.Count - 1].Focused = true;
                            textBoxStyleName.Text = style.Name;
                            textBoxStyleName.Focus();
                            _doUpdate = true;
                            SetControlsFromStyle(style);
                            listViewStyles_SelectedIndexChanged(null, null);

                            labelStatus.Text = string.Format(Configuration.Settings.Language.SubStationAlphaStyles.StyleXImportedFromFileY, style.Name, openFileDialogImport.FileName);
                            timerClearStatus.Start();
                        }
                    }
                }
            }
        }