Exemple #1
0
        private void RemoveDictionaryMouseLeftButtonUp(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to completely remove the dictionary?", "Remove dictionary", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            DictionaryConfig dictionary = DictionariesDataGrid.SelectedItem as DictionaryConfig;

            if (dictionary == null)
            {
                return;
            }

            string dictionaryPath = FileSystemHelper.GetAbsolutePath(@"Dictionaries\" + dictionary.Name);

            if (!string.IsNullOrEmpty(dictionaryPath))
            {
                File.Delete(dictionaryPath);
            }

            DictionaryConfig removingDictionary = ConfigManager.WorkConfig.Dictionaries.FirstOrDefault(d => d.Name.Equals(dictionary.Name));

            if (removingDictionary != null)
            {
                ConfigManager.WorkConfig.Dictionaries.Remove(removingDictionary);
            }

            ConfigManager.SaveConfig();
            UpdateDictionariesList();
        }
Exemple #2
0
        private void EnableDictionaryCheckBoxClick(object sender, RoutedEventArgs e)
        {
            DictionaryConfig selectedDictionary = DictionariesDataGrid.SelectedItem as DictionaryConfig;

            if (selectedDictionary == null)
            {
                return;
            }

            selectedDictionary.Enabled = !selectedDictionary.Enabled;
        }
Exemple #3
0
        private void EditDictionaryItemClick(object sender, RoutedEventArgs e)
        {
            DictionaryConfig selectedDictionary = DictionariesDataGrid.SelectedItem as DictionaryConfig;

            if (selectedDictionary == null)
            {
                return;
            }

            _selectedDictionary = selectedDictionary;
            ShowDictionaryAndSelectWord(selectedDictionary.Name, null);
        }
Exemple #4
0
        /// <summary>
        /// Returns (or creates, if necessary), a scoped IConfig instance for the named component
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        private IConfig GetConfig(string name, IConfig parent)
        {
            if (!_componentConfigs.ContainsKey(name))
            {
                var componentModel  = _componentModels[name];
                var componentConfig = new DictionaryConfig(componentModel.Config, parent);

                _componentConfigs.Add(name, componentConfig);
            }

            return(_componentConfigs[name]);
        }
Exemple #5
0
        private void RenameDictionaryMenuItemClick(object sender, RoutedEventArgs e)
        {
            try
            {
                DictionaryConfig selectedDictionary = DictionariesDataGrid.SelectedItem as DictionaryConfig;
                if (selectedDictionary == null)
                {
                    return;
                }

                string currentName = Path.GetFileNameWithoutExtension(selectedDictionary.Name);

                RenameDictionaryWindow changeNameWindow = new RenameDictionaryWindow {
                    Owner = this, DictionaryName = currentName
                };
                changeNameWindow.ShowDialog();

                if (string.IsNullOrEmpty(changeNameWindow.DictionaryName))
                {
                    throw new Exception("Dictionary name is invalid: empty.");
                }

                if (changeNameWindow.DictionaryName == currentName)
                {
                    return;
                }

                var obsoleteDictionaryPath = FileSystemHelper.GetAbsolutePath(@"Dictionaries\" + selectedDictionary.Name, false);
                if (!File.Exists(obsoleteDictionaryPath))
                {
                    throw new FileNotFoundException(string.Format("Dictionary {0} not found. ", selectedDictionary.Name));
                }

                selectedDictionary.Name = changeNameWindow.DictionaryName + ".xml";
                var updatedDictionaryPath = FileSystemHelper.GetAbsolutePath(@"Dictionaries\" + selectedDictionary.Name, false);
                if (File.Exists(updatedDictionaryPath))
                {
                    throw new Exception(string.Format("Dictionary {0} already exists.", selectedDictionary.Name));
                }

                File.Move(obsoleteDictionaryPath, updatedDictionaryPath);
                ConfigManager.SaveConfig();
                UpdateDictionariesList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to rename dictionary. " + ex.Message, "Failure", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #6
0
        public void ShowDictionaryAndSelectWord(string dictionaryName, WordInfo wordToSelect)
        {
            var dictionaryPath = FileSystemHelper.GetAbsolutePath(@"Dictionaries\" + dictionaryName);

            var allWords = DictionariesManager.ReadOneDictionary(dictionaryPath);

            _wordsList = new ObservableCollection <WordInfo>(allWords.Words);
            WordsDataGrid.DataContext = _wordsList;

            DictionarySettingsTabItem.Visibility      = Visibility.Visible;
            DictionarySettingsButtonsPanel.Visibility = Visibility.Visible;

            TextBlock headerTextBlock = new TextBlock
            {
                FontSize = 14,
                Margin   = new Thickness(1, 1, 1, 1),
                Text     = dictionaryName,
            };

            Button headerCloseButton = new Button
            {
                Width           = 16,
                Height          = 16,
                Background      = new ImageBrush(new BitmapImage(new Uri(FileSystemHelper.GetAbsolutePath("Resources\\Close.png")))),
                BorderThickness = new Thickness(0, 0, 0, 0),
            };

            StackPanel headerStackPanel = new StackPanel {
                Orientation = Orientation.Horizontal
            };

            headerStackPanel.Children.Add(headerTextBlock);
            headerStackPanel.Children.Add(headerCloseButton);

            headerCloseButton.Click -= HideDictionary;
            headerCloseButton.Click += HideDictionary;

            DictionarySettingsTabItem.Header = headerStackPanel;
            SettingsTabControl.SelectedItem  = DictionarySettingsTabItem;
            if (wordToSelect != null)
            {
                _selectedDictionary = ConfigManager.WorkConfig.Dictionaries.FirstOrDefault(d => d.Name.Equals(App.ShowingWord.DictonaryName, StringComparison.InvariantCultureIgnoreCase));
            }

            PrepareWordSelectingInDataGrid(wordToSelect);
        }
Exemple #7
0
        private ISprite LoadSprite(string spriteName)
        {
            if (_models.TryGetValue(spriteName, out var spriteModel))
            {
                // create sprite-scoped container
                var spriteContainer = _container.CreateChildContainer();

                var spriteConfig = new DictionaryConfig(spriteModel.Config, _config);
                spriteContainer.RegisterInstance <IConfig>(spriteConfig);

                // create instance
                var sprite = spriteContainer.Resolve <ISprite>(spriteModel.Base);

                return(sprite);
            }
            else
            {
                throw new ArgumentException($"No such sprite named {spriteName} is defined");
            }
        }
Exemple #8
0
        private void SaveRootConfig()
        {
            try
            {
                List <DictionaryConfig> dictionariesList = new List <DictionaryConfig>();
                foreach (object dictionaryElement in DictionariesDataGrid.Items)
                {
                    DictionaryConfig dictionaryConfig = dictionaryElement as DictionaryConfig;

                    if (dictionaryConfig == null || string.IsNullOrEmpty(dictionaryConfig.Name))
                    {
                        continue;
                    }

                    if (dictionariesList.Select(d => d.Name).Contains(dictionaryConfig.Name))
                    {
                        continue;
                    }

                    dictionariesList.Add(dictionaryConfig);
                }

                foreach (DictionaryConfig dictionaryConfig in dictionariesList)
                {
                    var dictionaryPath = FileSystemHelper.GetAbsolutePath(@"Dictionaries\" + dictionaryConfig.Name);
                    if (!File.Exists(dictionaryPath))
                    {
                        DictionariesManager.SaveOneDictionary(dictionaryConfig.Name, new List <WordInfo>());
                    }
                }

                ConfigManager.WorkConfig.Dictionaries = new List <DictionaryConfig>(dictionariesList);
                ConfigManager.SaveConfig();
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to apply settings.\n\n" + e, "Failed to apply settings", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private DictionaryConfig getDictConfig()
        {
            log.Debug(">>Loading web dictionary config...");
            DictionaryConfig result = new DictionaryConfig();

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(DictionaryConfig));

                /* If the XML document has been altered with unknown
                 * nodes or attributes, handle them with the
                 * UnknownNode and UnknownAttribute events.*/
                serializer.UnknownNode += new

                                          XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new

                                               XmlAttributeEventHandler(serializer_UnknownAttribute);

                // A FileStream is needed to read the XML document.
                using (StreamReader fs = Eviroment.getR_fromAsset(DICT_CONF_FILE))
                {
                    result = (DictionaryConfig)serializer.Deserialize(fs);
                }
                // Declare an object variable of the type to be deserialized.

                /* Use the Deserialize method to restore the object's state with
                 * data from the XML document. */
                // Read the order date.
            }
            catch (Exception ex)
            {
                log.Debug(ex.StackTrace);
                log.Debug("Creating empty dictionary config");
                result = new DictionaryConfig();
            }
            return(result);
        }
Exemple #10
0
        public void UpdateDictionariesList()
        {
            Action action = delegate
            {
                var path            = FileSystemHelper.GetAbsolutePath("Dictionaries");
                var allDictionaries = Directory.GetFiles(path, "*.xml", SearchOption.TopDirectoryOnly).Select(Path.GetFileName);

                var addedDictionaries = allDictionaries.Where(x => !ConfigManager.WorkConfig.Dictionaries.Select(c => c.Name).Contains(x));
                foreach (var addedDictionary in addedDictionaries)
                {
                    var config = new DictionaryConfig {
                        Name = addedDictionary, Enabled = true
                    };
                    ConfigManager.WorkConfig.Dictionaries.Add(config);
                }

                DictionariesDataGrid.DataContext = null;

                _dictionariesList = new ObservableCollection <DictionaryConfig>(ConfigManager.WorkConfig.Dictionaries.OrderBy(x => x.Name));
                DictionariesDataGrid.DataContext = _dictionariesList;
            };

            Dispatcher.Invoke(DispatcherPriority.Send, action);
        }
Exemple #11
0
 public Bootstrapper()
 {
     Config = DictionaryConfig.FromJson("config.json", new EmptyConfig());
 }
Exemple #12
0
 public ConfigUpdateTests()
 {
     _config = new DictionaryConfig();
 }