Пример #1
0
        public LookupForm(IBilingualDictionary dictionary)
            : this()
        {
            components.Add(new DisposableComponent(new LookupFormFileIsInUse(this, dictionary.Path)));
            components.Add(new DisposableComponent(dictionary));

            Dictionary = dictionary;

            var mru = GuiConfiguration.RecentDictionaries ?? new MruList <DictionaryInfo>(10);

            mru.Update(dictionary.Info);
            GuiConfiguration.RecentDictionaries = mru;

            Font listFont = GuiConfiguration.GetListFont();

            if (listFont != null)
            {
                components.Add(listFontComponent = new DisposableComponent(listFont));
                defaultGridFont = grid.Font;
                grid.Font       = listFont;
            }

            // TODO: This really needs testing. It could make things completely unusable...
            // I can't even remember if they're used...
            try {
                if (dictionary.FirstLanguageCode != null && dictionary.SecondLanguage != null)
                {
                    sourceCulture = new CultureInfo(dictionary.FirstLanguageCode);
                    targetCulture = new CultureInfo(dictionary.SecondLanguageCode);
                }
            } catch (ArgumentException) {
                // One of the cultures wasn't supported. In that case, set both cultures to null,
                // because it isn't worth having only one.
                sourceCulture = targetCulture = null;
            }

            InitialiseView();

            Load += delegate {
                UpdateResults();
            };
            Show();
        }
Пример #2
0
		public DictionaryInfoEditor(IBilingualDictionary dict, bool saveOnClose) {
			InitializeComponent();

			initialTitle = Text;			

			name.Text = dict.Name;
			author.Text = dict.Author;
			url.Text = dict.Url;
			firstLanguage.Text = dict.FirstLanguage;
			secondLanguage.Text = dict.SecondLanguage;

			this.dict = dict;
			this.saveOnClose = saveOnClose;

			save.Click += save_Click;
			cancel.Click += delegate { Close(); };

			name.TextChanged += delegate { UpdateNames(); };
			UpdateNames();
		}
Пример #3
0
        public DictionaryInfoEditor(IBilingualDictionary dict, bool saveOnClose)
        {
            InitializeComponent();

            initialTitle = Text;

            name.Text           = dict.Name;
            author.Text         = dict.Author;
            url.Text            = dict.Url;
            firstLanguage.Text  = dict.FirstLanguage;
            secondLanguage.Text = dict.SecondLanguage;

            this.dict        = dict;
            this.saveOnClose = saveOnClose;

            save.Click   += new EventHandler(save_Click);
            cancel.Click += delegate { Close(); };

            name.TextChanged += delegate { UpdateNames(); };
            UpdateNames();
        }
Пример #4
0
        public LookupForm(IBilingualDictionary dictionary)
            : this()
        {
            components.Add(new DisposableComponent(new LookupFormFileIsInUse(this, dictionary.Path)));
            components.Add(new DisposableComponent(dictionary));

            Dictionary = dictionary;

            var mru = GuiConfiguration.RecentDictionaries ?? new MruList<DictionaryInfo>(10);
            mru.Update(dictionary.Info);
            GuiConfiguration.RecentDictionaries = mru;

            Font listFont = GuiConfiguration.GetListFont();
            if (listFont != null) {
                components.Add(listFontComponent = new DisposableComponent(listFont));
                defaultGridFont = grid.Font;
                grid.Font = listFont;
            }

            // TODO: This really needs testing. It could make things completely unusable...
            // I can't even remember if they're used...
            try {
                if (dictionary.FirstLanguageCode != null && dictionary.SecondLanguage != null) {
                    sourceCulture = new CultureInfo(dictionary.FirstLanguageCode);
                    targetCulture = new CultureInfo(dictionary.SecondLanguageCode);
                }
            } catch (ArgumentException) {
                // One of the cultures wasn't supported. In that case, set both cultures to null,
                // because it isn't worth having only one.
                sourceCulture = targetCulture = null;
            }

            InitialiseView();

            Load += delegate {
                UpdateResults();
            };
            Show();
        }
Пример #5
0
		private void ImportCompleted(IBilingualDictionary result) {
			Debug.Assert(!InvokeRequired, "ImportCompleted called on a secondary thread");

			try {
				if (CurrentUI is Controls.ProgressUI) {
					Controls.ProgressUI prog = (Controls.ProgressUI)CurrentUI;
					prog.Percent = 100;
					prog.Message = Properties.Resources.ImportFinished;
				}

				this.imported = result;

				// Modal dialog simplifies things slightly.
				new DictionaryInfoEditor(imported, false).ShowDialog();

				string root = DataStore.UserDataStore.Path;
				string name = imported.Name ?? Properties.Resources.DefaultDictionaryName;

				DataStore.UserDataStore.EnsureDirectoryExists(Configuration.DictionariesFolderName);

				// Attempt to save with a sane name; failing that, use a GUID as the name; otherwise report the error.
				var ipc = Path.GetInvalidPathChars();
				if (name.IndexOfAny(ipc) >= 0) {
					// TODO: Sanitize file name!
				}

				string newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict";

				// We don't want to overwrite an existing dictionary.
				if (File.Exists(newPath)) {
					name = Guid.NewGuid().ToString("D");
					newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict";
				}

				imported.Path = newPath;

				// If the dictionary can't save, we should delete the half-written file.
				// TODO: this should probably avoid deleting the file if the error was caused
				// by the file already existing (say, if it was created between calls). It would be
				// kind of rare though.
				try {
					imported.Save();
				} catch (SystemException) { // XXX Lazy.
					File.Delete(imported.Path);
					throw;
				}

				new LookupForm(imported).Show();
				Close();
			} catch (ApplicationException ex) {
				ReportException(ex);
			} catch (IOException ex) {
				ReportException(ex);
			} catch (InvalidOperationException ex) {
				ReportException(ex);
			} catch (ArgumentException ex) {
				ReportException(ex);
			}
		}
Пример #6
0
        private void ImportCompleted(IBilingualDictionary result)
        {
            Debug.Assert(!InvokeRequired, "ImportCompleted called on a secondary thread");

            try {
                if (CurrentUI is Controls.ProgressUI)
                {
                    Controls.ProgressUI prog = (Controls.ProgressUI)CurrentUI;
                    prog.Percent = 100;
                    prog.Message = Properties.Resources.ImportFinished;
                }

                this.imported = result;

                // Modal dialog simplifies things slightly.
                new DictionaryInfoEditor(imported, false).ShowDialog();

                string root = DataStore.UserDataStore.Path;
                string name = imported.Name ?? Properties.Resources.DefaultDictionaryName;

                DataStore.UserDataStore.EnsureDirectoryExists(Configuration.DictionariesFolderName);

                // Attempt to save with a sane name; failing that, use a GUID as the name; otherwise report the error.
                var ipc = Path.GetInvalidPathChars();
                if (name.IndexOfAny(ipc) >= 0)
                {
                    // TODO: Sanitize file name!
                }

                string newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict";

                // We don't want to overwrite an existing dictionary.
                if (File.Exists(newPath))
                {
                    name    = Guid.NewGuid().ToString("D");
                    newPath = Path.Combine(Path.Combine(root, Configuration.DictionariesFolderName), name) + ".dict";
                }

                imported.Path = newPath;

                // If the dictionary can't save, we should delete the half-written file.
                // TODO: this should probably avoid deleting the file if the error was caused
                // by the file already existing (say, if it was created between calls). It would be
                // kind of rare though.
                try {
                    imported.Save();
                } catch (SystemException) {                 // XXX Lazy.
                    File.Delete(imported.Path);
                    throw;
                }

                new LookupForm(imported).Show();
                Close();
            } catch (ApplicationException ex) {
                ReportException(ex);
            } catch (IOException ex) {
                ReportException(ex);
            } catch (InvalidOperationException ex) {
                ReportException(ex);
            } catch (ArgumentException ex) {
                ReportException(ex);
            }
        }