예제 #1
0
        /// <summary>
        /// Shows the file open dialog, and then imports a file in StarDict format. Such files can be downloaded from various sources.
        /// </summary>
        /// <param name="controller">The dictionary controller.</param>
        /// <param name="mainWindow">The main window.</param>
        public static void OpenStarDictFile(DictionaryController controller, Window mainWindow)
        {
            var entryDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            var dir      = new System.IO.DirectoryInfo(entryDir + @"\Content\");

            var dlg = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "StarDict dictionary files|*.ifo" +
                         "|All Files|*.*",
                Multiselect      = false,
                InitialDirectory = dir.FullName,
            };

            if (true == dlg.ShowDialog(mainWindow))
            {
                controller.LoadDictionary(dlg.FileName);
            }
        }
예제 #2
0
        /// <summary>
        /// Shows the file open dialog, and then imports a plain text file coming from the BEOLINGUS dictionary of TU Chemnitz (see <see href="https://dict.tu-chemnitz.de/doc/faq.de.html"/>.
        /// Then a file save dialog is presented to store the imported data in the Slob format.
        /// </summary>
        /// <param name="controller">The dictionary controller.</param>
        /// <param name="mainWindow">The main window.</param>
        public static void ImportTUChemnitzFile(DictionaryController controller, Window mainWindow)
        {
            var entryDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            var dir      = new System.IO.DirectoryInfo(entryDir + @"\Content\");

            var dlg = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "Text files|*.txt" +
                         "|All Files|*.*",
                Multiselect      = false,
                InitialDirectory = dir.FullName,
                Title            = "Import from a text file"
            };



            if (true == dlg.ShowDialog(mainWindow))
            {
                var teiReader  = new Text.TextReader(dlg.FileName);
                var dictionary = teiReader.Read();


                var saveDlg = new Microsoft.Win32.SaveFileDialog
                {
                    Filter = "SLOB files|*.slob" +
                             "|All Files|*.*",

                    InitialDirectory = dir.FullName,

                    Title = "Save dictionary as .slob file"
                };

                if (true == saveDlg.ShowDialog(mainWindow))
                {
                    var slobWriter = new SlobReaderWriter(saveDlg.FileName);
                    slobWriter.Write(dictionary, "text/plain");

                    controller.LoadDictionary(saveDlg.FileName);
                }
            }
        }