/// <summary>
        /// Executes the add key command.
        /// </summary>
        private void ExecuteAddKeyCommand()
        {
            var newObject = new Key();
            var viewModel = new KeyEditViewModel(newObject, (RHSStringTableTools.Model.Container)this.SelectedNode);

            var view = new KeyEditView { DataContext = viewModel };

            view.ShowDialog();
        }
        /// <summary>
        /// The search and replace key with string.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="properties">
        /// The properties.
        /// </param>
        /// <param name="searchString">
        /// The search string.
        /// </param>
        /// <param name="replaceString">
        /// The replace string.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool searchAndReplaceKeyWithString(Key key, IEnumerable<PropertyInfo> properties, string searchString, string replaceString)
        {
            var propertyInfos = properties as IList<PropertyInfo> ?? properties.ToList();
            var foundPropertiesEnumerable = propertyInfos.Select(property => property.GetValue(key))
                .OfType<string>();

            var contains =
                foundPropertiesEnumerable
                    .Any(value => value.Contains(searchString));

            if (!contains) return false;

            foreach (var property in propertyInfos.Where(property => property.GetValue(key) is string))
            {
                property.SetValue(key, ((string)property.GetValue(key)).Replace(searchString, replaceString));
            }

            return true;
        }
        /// <summary>
        /// Adds the property to the stringtable
        /// </summary>
        private void AddCommandExecute()
        {
            this.ConsoleWriteLine(string.Format("Adding {0} to the stringtable.", this.SelectedProperty.Key.Value));

            var newObject = new Key
            {
                Id = string.Format("STR_{0}_{1}", this.AllProperties[this.SelectedProperty.Key].Name.ToUpper(),
                        this.SelectedProperty.Key.Name.ToUpper()),
                AutoFillFromOriginal = true,
                Original = this.SelectedProperty.Key.Value.Trim('"'),
                English = this.SelectedProperty.Key.Value.Trim('"')
            };

            //newObject.FillEmptyKeysWithEnglishOrOriginal();

            var viewModel = new KeyEditViewModel(newObject, (Container)this.ParentViewModel.SelectedNode);

            var view = new KeyEditView { DataContext = viewModel };

            view.ShowDialog();
        }
 /// <summary>
 /// Search key with string string.
 /// </summary>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <param name="properties">
 /// The properties.
 /// </param>
 /// <param name="searchString">
 /// The search string.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/> specifying whether a match is found.
 /// </returns>
 public static bool searchKeyWithString(Key key, IEnumerable<PropertyInfo> properties, string searchString)
 {
     return properties.Select(property => property.GetValue(key)).OfType<string>().Any(value => value.Contains(searchString));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyEditViewModel"/> class.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="container">
        /// The container.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        public KeyEditViewModel(Key item, Container container = null, int position = -1)
        {
            this.Templates = TemplateMaster.Instance.KeyTemplates;

            this.Thing = item;
            this.Thing.Parent = container;
            this.Parent = container;
            this.InsertAfter = position;

            var canOk = this.WhenAny(x => x.Id, y => y.Original, z => z.English, (x, y, z) => !string.IsNullOrWhiteSpace(x.Value) && !string.IsNullOrWhiteSpace(y.Value) && !string.IsNullOrWhiteSpace(z.Value));
            this.OkCommand = ReactiveCommand.Create(canOk);
            this.OkCommand.Subscribe(this.OkCommandExecute);

            this.WhenAnyValue(vm => vm.Original).Subscribe(_ => this.FillLanguages());
            this.WhenAnyValue(vm => vm.Russian).Subscribe(_ => this.Transliterate());
            this.WhenAny(vm => vm.SelectedTemplate, vm => vm.Value != null).Subscribe(_ => this.ApplyTemplate());

            this.SetProperties();
        }