Ejemplo n.º 1
0
        private void Import(bool useOrder)
        {
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = System.IO.File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            string key;
                            string value;
                            if (useOrder)
                            {
                                key   = string.Concat(table.Rows[i][0].ToString(), "|", table.Rows[i][1].ToString());
                                value = table.Rows[i][3].ToString();
                            }
                            else
                            {
                                key   = table.Rows[i][2].ToString();
                                value = table.Rows[i][3].ToString();
                            }

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var column in _data.Columns)
                {
                    column.SetUniqueValues(strings, useOrder);
                }

                SubtitleGridView.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void Import(bool useOffset)
        {
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = System.IO.File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            var key = useOffset ? table.Rows[i][0].ToString() : table.Rows[i][1].ToString();

                            var value = string.Concat(table.Rows[i][2].ToString(), "\t", table.Rows[i][3].ToString(), "\t", table.Rows[i][4].ToString());

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var subtitle in _subtitles)
                {
                    var key = useOffset ? subtitle.Offset.ToString() : subtitle.Text;

                    if (!string.IsNullOrEmpty(key) && strings.ContainsKey(key))
                    {
                        var values = strings[key].Split('\t');
                        subtitle.Translation = values[0];
                        subtitle.Width       = float.Parse(values[1]);
                        subtitle.Height      = float.Parse(values[2]);
                    }
                }

                SubtitleGridView.Invalidate();
                UpdateLabel();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void DisplaySubtitle(int index)
        {
            if (index == -1)
            {
                return;
            }

            SubtitleGridView.ClearSelection();
            SubtitleGridView.Rows[index].Cells["colTranslation"].Selected = true;
        }
Ejemplo n.º 4
0
        public void DisplaySubtitle(int index)
        {
            if (index == -1)
            {
                return;
            }

            SubtitleGridView.ClearSelection();
            SubtitleGridView.Rows[index].Cells[0].Selected   = true;
            SubtitleGridView.FirstDisplayedScrollingRowIndex = index;
        }
Ejemplo n.º 5
0
        private void SubtitleGridView_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            var isTranslationColumn = (e.ColumnIndex % 2) == 1;
            var column = (Column)SubtitleGridView.Columns[e.ColumnIndex].Tag;

            if (isTranslationColumn)
            {
                column.SetTranslatedValue(e.RowIndex, e.Value.ToString());
                SubtitleGridView.InvalidateColumn(e.ColumnIndex);
            }
        }
 private void Scintilla2_TextChanged(object sender, EventArgs e)
 {
     if (_selectedSubtitle != null)
     {
         if (scintilla2.Modified)
         {
             _selectedSubtitle.Translation = scintilla2.Text.Replace(_file.LineEnding.RealLineEnding, _file.LineEnding.ShownLineEnding);
             SubtitleGridView.Invalidate();
             UpdateLabel();
         }
     }
 }
        private void btnImportPo_Click(object sender, EventArgs e)
        {
            ImportFileDialog.Filter   = "Archivos Po|*.po";
            ImportFileDialog.FileName = string.Concat(Path.GetFileNameWithoutExtension(_file.Path), ".po");
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            _file.ImportPo(ImportFileDialog.FileName, false);

            _selectedSubtitle = null;
            SubtitleGridView.Invalidate();
            DisplaySubtitle(_selectedSubtitleIndex);
            UpdateLabel();
        }
        private void Import(bool useOffset)
        {
            ImportFileDialog.Filter   = "Archivos Excel|*.xlsx";
            ImportFileDialog.FileName = string.Concat(Path.GetFileNameWithoutExtension(_file.Path), ".xlsx");
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            string key;
                            string value;
                            if (useOffset)
                            {
                                key   = table.Rows[i][0].ToString();
                                value = table.Rows[i][2].ToString();
                            }
                            else
                            {
                                key   = table.Rows[i][1].ToString();
                                value = table.Rows[i][2].ToString();
                            }

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var subtitle in _subtitles)
                {
                    var key = useOffset ? subtitle.Offset.ToString() : subtitle.Text;

                    if (!string.IsNullOrEmpty(key) && strings.ContainsKey(key))
                    {
                        subtitle.Translation = strings[key];
                    }
                }

                _selectedSubtitle = null;
                SubtitleGridView.Invalidate();
                DisplaySubtitle(_selectedSubtitleIndex);
                UpdateLabel();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 9
0
 private void SubtitleGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     SubtitleGridView.BeginEdit(false);
 }