Пример #1
0
        /// <summary>
        /// Adds an action to the <see cref="EditorMenu"/> command entry.
        /// </summary>
        /// <remarks>
        /// <para>Specifying a value of <c>null</c> or simply omitting to specify an
        /// action will simply result in the <see cref="EditorMenu"/> command being
        /// disabled ("greyed out").</para>
        /// </remarks>
        /// <param name="action">The action to have the command invoke.</param>
        /// <returns>
        /// Fluid style API to further define the new command entry.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="action"/> is <c>null</c>.
        /// </exception>
        public EditorMenuCommandBinder Action(Action action)
        {
            ExceptionUtility.CheckArgumentNotNull(action, "action");

            this.Entry.Action += action;
            return(this);
        }
Пример #2
0
        /// <summary>
        /// Adds a parameterized action to the <see cref="EditorMenu"/> command entry.
        /// </summary>
        /// <remarks>
        /// <para>Specifying a value of <c>null</c> or simply omitting to specify an
        /// action will simply result in the <see cref="EditorMenu"/> command being
        /// disabled ("greyed out").</para>
        /// </remarks>
        /// <typeparam name="TParam">Type of command parameter.</typeparam>
        /// <param name="action">The action to have the command invoke.</param>
        /// <param name="param">Parameter for command.</param>
        /// <returns>
        /// Fluid style API to further define the new command entry.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="action"/> is <c>null</c>.
        /// </exception>
        public EditorMenuCommandBinder Action <TParam>(Action <TParam> action, TParam param)
        {
            ExceptionUtility.CheckArgumentNotNull(action, "action");

            this.Entry.Action += () => action(param);
            return(this);
        }
Пример #3
0
        /// <summary>
        /// Adds an arbitary parameter to the <see cref="IEditorMenuEntry"/> that can
        /// assist <see cref="IEditorMenuPresenter"/> implementations by providing them
        /// with additional per-entry information.
        /// </summary>
        /// <param name="parameter">Custom parameter.</param>
        /// <returns>
        /// Fluid style API to further define the new command entry.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="parameter"/> is <c>null</c>.
        /// </exception>
        public EditorMenuSeparatorBinder Parameter(IEditorMenuEntryParameter parameter)
        {
            ExceptionUtility.CheckArgumentNotNull(parameter, "parameter");

            this.Entry.Parameters.Add(parameter);
            return(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorMenuSeparatorEntry"/> class.
        /// </summary>
        /// <param name="path">Path of the separator.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="path"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// If <paramref name="path"/> is an invalid full command path.
        /// </exception>
        public EditorMenuSeparatorEntry(string path)
        {
            ExceptionUtility.CheckArgumentNotNull(path, "path");
            EditorMenuInternalUtility.CheckPathArgument(path, "path");

            this.Path = path;
        }
Пример #5
0
        public RelayCommand(Action <object> pObjExecute, Predicate <object> pBolCanExecute)
        {
            ExceptionUtility.CheckArgumentNotNull(pObjExecute, "Execute");

            this.mObjExecute    = pObjExecute;
            this.mBolCanExecute = pBolCanExecute;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageLanguage"/> class.
        /// </summary>
        /// <param name="packageName">Name of the package that the language is for.</param>
        /// <param name="rootCulture">Culture of the non-translated message text in code.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="packageName"/> or <paramref name="rootCulture"/> are <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// If <paramref name="packageName"/> is an empty string.
        /// </exception>
        protected PackageLanguage(string packageName, CultureInfo rootCulture)
        {
            ExceptionUtility.CheckExpectedStringArgument(packageName, "packageName");
            ExceptionUtility.CheckArgumentNotNull(rootCulture, "rootCulture");

            this.packageName = packageName;
            this.rootCulture = rootCulture;
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementAdderMenuPopulator{TContext}"/> class.
        /// </summary>
        /// <param name="elementContractType">Contract type of addable elements.</param>
        /// <param name="elementAdder">Object that is used to add new elements to some
        /// context object.</param>
        public ElementAdderMenuPopulator(Type elementContractType, IElementAdder <TContext> elementAdder)
        {
            ExceptionUtility.CheckArgumentNotNull(elementContractType, "contractType");

            this.ElementContractType = elementContractType;
            this.ElementAdder        = elementAdder;
            this.TypeFilters         = new List <Func <Type, bool> >();
        }
Пример #8
0
        /// <summary>
        /// Sets up the language domain instance.
        /// </summary>
        /// <param name="domain">The language domain instance.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="domain"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// If the runtime language has already been setup.
        /// </exception>
        public virtual void Setup(ILanguageDomain domain)
        {
            ExceptionUtility.CheckArgumentNotNull(domain, "domain");

            if (LocalizedStrings != null)
            {
                throw new InvalidOperationException("Runtime language has already been setup.");
            }

            LocalizedStrings = domain;
        }
        /// <summary>
        /// Initializes a new instance of <see cref="SerializedPropertyAdaptor"/>.
        /// </summary>
        /// <param name="arrayProperty">Serialized property for entire array.</param>
        /// <param name="fixedItemHeight">Non-zero height overrides property drawer height calculation.</param>
        public SerializedPropertyAdaptor(SerializedProperty arrayProperty, float fixedItemHeight)
        {
            ExceptionUtility.CheckArgumentNotNull(arrayProperty, "arrayProperty");

            if (!arrayProperty.isArray)
            {
                throw new InvalidOperationException("Specified serialized propery is not an array.");
            }

            this.arrayProperty   = arrayProperty;
            this.FixedItemHeight = fixedItemHeight;
        }
Пример #10
0
        /// <summary>
        /// Populates a menu with element adder commands.
        /// </summary>
        /// <param name="menu">Editor menu.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="menu"/> is <c>null</c>.
        /// </exception>
        public void PopulateWithCommands(EditorMenu menu)
        {
            ExceptionUtility.CheckArgumentNotNull(menu, "menu");

            menu.AddSeparator();

            foreach (var command in ElementAdderMenuCommandMeta.InstantiateAnnotatedCommands <TContext>(this.ElementContractType))
            {
                menu.AddCommand(command.FullPath)
                .Enabled(this.ElementAdder != null && command.CanExecute(this.ElementAdder))
                .Action(command.Execute, this.ElementAdder);
            }
        }
Пример #11
0
        /// <inheritdoc/>
        public void Load(CultureInfo culture)
        {
            ExceptionUtility.CheckArgumentNotNull(culture, "culture");

            if (culture == this.Culture)
            {
                return;
            }

            this.strings = this.repository.GetLocalizedStrings(culture);
            this.Culture = culture;

            this.OnLoaded();
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedStringsPathsRepository"/> class.
        /// </summary>
        /// <param name="paths">An array of paths where localization files can be found.
        /// Latter paths have precedence over former paths.</param>
        /// <param name="fileExtension">File extension; for instance, ".mo".</param>
        /// <param name="loader">Object for loading localized strings.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="paths"/> or <paramref name="loader"/> are <c>null</c>.
        /// </exception>
        public LocalizedStringsPathsRepository(string[] paths, string fileExtension, ILocalizedStringsLoader loader)
        {
            ExceptionUtility.CheckArgumentNotNull(paths, "paths");
            ExceptionUtility.CheckArgumentNotNull(fileExtension, "fileExtension");
            ExceptionUtility.CheckArgumentNotNull(loader, "loader");

            string filePattern = string.Format(
                @"^(?<Locale>[a-z]+([\-\\_][a-z]+)*){0}$",
                Regex.Escape(fileExtension)
                );

            this.paths                = paths.ToArray();
            this.fileExtension        = fileExtension;
            this.cultureFileNameRegex = new Regex(filePattern, RegexOptions.IgnoreCase);
            this.loader               = loader;
        }
Пример #13
0
        /// <summary>
        /// Gets an array of the <see cref="IElementAdderMenuCommand{TContext}"/> types
        /// that are associated with the specified <paramref name="elementContractType"/>.
        /// </summary>
        private static Type[] GetAnnotatedCommandTypes <TContext>(Type elementContractType)
        {
            ExceptionUtility.CheckArgumentNotNull(elementContractType, "contractType");

            var contractMap = GetContextElementContractCommandTypesMap <TContext>();

            if (!contractMap.ContainsKey(elementContractType))
            {
                contractMap[elementContractType] = (
                    from commandType in GetAnnotatedCommandTypes <TContext>()
                    let attributes = (ElementAdderMenuCommandAttribute[])Attribute.GetCustomAttributes(commandType, typeof(ElementAdderMenuCommandAttribute))
                                     where attributes.Any(attribute => attribute.ContractType == elementContractType)
                                     select commandType
                    ).ToArray();
            }

            return(contractMap[elementContractType].ToArray());
        }
Пример #14
0
        /// <summary>
        /// Populates a menu with concrete element types.
        /// </summary>
        /// <param name="menu">Editor menu.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="menu"/> is <c>null</c>.
        /// </exception>
        public void PopulateWithConcreteTypes(EditorMenu menu)
        {
            ExceptionUtility.CheckArgumentNotNull(menu, "menu");

            menu.AddSeparator();

            foreach (var concreteType in ApplyTypeFilter(TypeMeta.DiscoverImplementations(this.ElementContractType)))
            {
                menu.AddCommand(this.FormatTypeDisplayName(concreteType))
                .Enabled(this.ElementAdder != null && this.ElementAdder.CanAddElement(concreteType))
                .Action(() => {
                    if (this.ElementAdder.CanAddElement(concreteType))
                    {
                        this.ElementAdder.AddElement(concreteType);
                    }
                });
            }
        }
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LanguageDomain"/> class.
        /// </summary>
        /// <param name="repository">Repository for accessing localized strings within
        /// the language domain.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="repository"/> is <c>null</c>.
        /// </exception>
        public LanguageDomain(ILocalizedStringsRepository repository)
        {
            ExceptionUtility.CheckArgumentNotNull(repository, "repository");

            this.repository = repository;
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeLanguage{TImplementation}"/> class.
        /// </summary>
        /// <param name="rootCulture">Culture of the non-translated message text in code.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="rootCulture"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// If <paramref name="packageName"/> is an empty string.
        /// </exception>
        protected RuntimeLanguage(CultureInfo rootCulture)
        {
            ExceptionUtility.CheckArgumentNotNull(rootCulture, "rootCulture");

            this.rootCulture = rootCulture;
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorMenuSeparatorBinder"/> class.
        /// </summary>
        /// <param name="entry">The associated separator entry.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="entry"/> is <c>null</c>.
        /// </exception>
        public EditorMenuSeparatorBinder(EditorMenuSeparatorEntry entry)
        {
            ExceptionUtility.CheckArgumentNotNull(entry, "entry");

            this.Entry = entry;
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorMenuCommandBinder"/> class.
        /// </summary>
        /// <param name="entry">The associated command entry.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="entry"/> is <c>null</c>.
        /// </exception>
        public EditorMenuCommandBinder(EditorMenuCommandEntry entry)
        {
            ExceptionUtility.CheckArgumentNotNull(entry, "entry");

            this.Entry = entry;
        }