public void CreateFileWithinProject([NotNull] TestCopProjectItem projectItem, [NotNull] string targetFile)
        {
            var desiredTemplateName = LookupTemplateName(projectItem.Project);
            var boundSettingsStore  = _settingsStore.BindToContextTransient(ContextRange.ApplicationWide);

            var context = _dataContexts.CreateOnActiveControl(_lifetime);

            var applicableFileTemplateScopes = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(projectItem.Project)));

            applicableFileTemplateScopes = applicableFileTemplateScopes.Distinct().Where(s => s is InLanguageSpecificProject).ToList();

            var classTemplate = _storedTemplatesProvider.EnumerateTemplates(boundSettingsStore, TemplateApplicability.File)
                                .Where(x => x.Description == desiredTemplateName &&
                                       TemplateScopeManager.TemplateIsAvailable(x, applicableFileTemplateScopes))
                                .Select(x => x)
                                .FirstOrDefault();

            if (classTemplate == null)
            {
                ResharperHelper.AppendLineToOutputWindow(string.Format("File Template for '{0}' not found with default to 'Class'", desiredTemplateName));
                classTemplate = LoadTemplateFromQuickList(context, "Class");
            }
            IProjectFolder folder = (IProjectFolder)projectItem.Project.FindProjectItemByLocation(projectItem.SubNamespaceFolder)
                                    ?? GetOrCreateProjectFolder(projectItem);

            if (folder == null)
            {
                ResharperHelper.AppendLineToOutputWindow("Error failed to create/location project folder" + projectItem.SubNamespaceFolder);
                return;
            }

            string extension = Enumerable.First(_fileExtensions.GetExtensions(projectItem.Project.ProjectProperties.DefaultLanguage.DefaultProjectFileType));

            FileTemplatesManager.Instance.CreateFileFromTemplate(targetFile + extension, new ProjectFolderWithLocation(folder), classTemplate);
        }
Exemple #2
0
        public void Execute(ISolution solution, ITextControl textControl)
        {
            ISettingsStore store = Shell.Instance.GetComponent <ISettingsStore>();

            // Get the dictionary
            CustomDictionary dictionary =
                _settingsStore.GetIndexedValue <CustomDictionarySettings, string, CustomDictionary>(
                    settings => settings.CustomDictionaries, _dictName);

            if (dictionary == null)
            {
                dictionary = new CustomDictionary()
                {
                    Name = _dictName
                }
            }
            ;

            string words = dictionary.DecodedUserWords.Trim();

            if (words.Length > 0)
            {
                dictionary.DecodedUserWords = words + "\n";
            }
            dictionary.DecodedUserWords += _word;

            IContextBoundSettingsStore boundStore = store.BindToContextTransient(ContextRange.ApplicationWide);

            boundStore.SetIndexedValue <CustomDictionarySettings, string, CustomDictionary>(x => x.CustomDictionaries, _dictName, dictionary);
            SpellCheckManager.Reset(); // Clear the cache.
            solution.SaveSettings();
            Daemon.GetInstance(solution).ForceReHighlight(_documentRange.Document);
        }
 public UnityImplicitUsageHighlightingContributor(ISolution solution, ISettingsStore settingsStore,
                                                  ITextControlManager textControlManager)
 {
     Solution           = solution;
     TextControlManager = textControlManager;
     SettingsStore      = settingsStore.BindToContextTransient(ContextRange.Smart(solution.ToDataContext()));
 }
        public void Commit(bool shouldAddFormerlySerializedAs)
        {
            ShouldAddFormerlySerializedAs = shouldAddFormerlySerializedAs;
            var store = mySettingsStore.BindToContextTransient(ContextRange.ApplicationWide);

            store.SetValue((SerializedFieldRenameRefactoringSettings s) => s.ShouldAddFormerlySerializedAs,
                           ShouldAddFormerlySerializedAs);
        }
        public SerializedFieldRenameModel(ISettingsStore settingsStore)
        {
            mySettingsStore = settingsStore;
            var store = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);

            ShouldAddFormerlySerializedAs = store.GetValue((SerializedFieldRenameRefactoringSettings s) =>
                                                           s.ShouldAddFormerlySerializedAs);
        }
Exemple #6
0
 public UnityHighlightingContributor(ISolution solution, ISettingsStore settingsStore,
                                     ITextControlManager textControlManager, SolutionAnalysisService swa,
                                     PerformanceCriticalCodeCallGraphAnalyzer performanceCriticalCodeCallGraphAnalyzer)
 {
     Swa = swa;
     PerformanceAnalyzerId = performanceCriticalCodeCallGraphAnalyzer.AnalyzerId;
     Solution           = solution;
     TextControlManager = textControlManager;
     SettingsStore      = settingsStore.BindToContextTransient(ContextRange.Smart(solution.ToDataContext()));
 }
Exemple #7
0
        public NameSuffixLinkedTypesProvider(ISolution solution, ISettingsStore settingsStore, ISettingsOptimization settingsOptimization)
        {
            var contextBoundSettingsStore = settingsStore.BindToContextTransient(ContextRange.Smart(solution.ToDataContext()));
            var settings = contextBoundSettingsStore.GetKey <TestLinkerSettings>(settingsOptimization);

            _namingStyle    = settings.NamingStyle;
            _namingSuffixes = settings.NamingSuffixes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                              .Select(x => Pair.Of(x, x.Length))
                              .ToList();
        }
Exemple #8
0
        public TypeofAttributeLinkedTypesProvider(ISolution solution, ISettingsStore settingsStore, ISettingsOptimization settingsOptimization)
        {
            var contextBoundSettingsStore = settingsStore.BindToContextTransient(ContextRange.Smart(solution.ToDataContext()));
            var settings = contextBoundSettingsStore.GetKey <TestLinkerSettings>(settingsOptimization);

            var attributeNameLong = settings.TypeofAttributeName;

            if (!attributeNameLong.EndsWith("Attribute"))
            {
                attributeNameLong += "Attribute";
            }

            _attributeNameLong  = attributeNameLong;
            _attributeNameShort = attributeNameLong.Substring(startIndex: 0, length: attributeNameLong.Length - "Attribute".Length);
        }
 public SettingsUpgrader(ISettingsStore settingsStore, IApplicationDescriptor applicationDescriptor, IShellLocks locks, ProductSettingsLocation productSettingsLocation, RunsProducts.ProductConfigurations productConfigurations)
 {
   var boundSettingsStore = settingsStore.BindToContextTransient(ContextRange.ManuallyRestrictWritesToOneContext((l, contexts) => contexts.Empty));
   Expression<Func<ZenCodingSettings, bool>> isUpgradedProperty = settings => settings.IsUpgraded;
   if (!boundSettingsStore.GetValue(isUpgradedProperty))
   {
     var settingsComponent = new ShellSettingsComponent(applicationDescriptor, locks, productSettingsLocation, productConfigurations);
     var oldSettings = new Settings();
     settingsComponent.LoadSettings(oldSettings, XmlExternalizationScope.UserSettings, oldSettings.GetType().Name);
     for (int i = 0; i < oldSettings.FileAssociations.Count; i++)
     {
       var association = oldSettings.FileAssociations[i];
       boundSettingsStore.SetIndexedValue((ZenCodingSettings settings) => settings.FileAssociations, i, association);
     }
     
     boundSettingsStore.SetValue(isUpgradedProperty, true);
   }
 }
        public GitHubClient GetClient([NotNull] IDataContext context)
        {
            var boundSettings = mySettingsStore.BindToContextTransient(ContextRange.Smart((lt, _) => context));

            var proxy    = myProxySettingsReader.GetProxySettings(boundSettings);
            var settings = boundSettings.GetKey <GitHubSettings>(SettingsOptimization.DoMeSlowly);

            var client = new GitHubClient {
                Proxy = proxy
            };

            if (!settings.IsAnonymous)
            {
                client.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);
            }

            return(client);
        }
        public SettingsUpgrader(ISettingsStore settingsStore, IApplicationDescriptor applicationDescriptor, IShellLocks locks, ProductSettingsLocation productSettingsLocation, RunsProducts.ProductConfigurations productConfigurations)
        {
            var boundSettingsStore = settingsStore.BindToContextTransient(ContextRange.ManuallyRestrictWritesToOneContext((l, contexts) => contexts.Empty));
            Expression <Func <ZenCodingSettings, bool> > isUpgradedProperty = settings => settings.IsUpgraded;

            if (!boundSettingsStore.GetValue(isUpgradedProperty))
            {
                var settingsComponent = new ShellSettingsComponent(applicationDescriptor, locks, productSettingsLocation, productConfigurations);
                var oldSettings       = new Settings();
                settingsComponent.LoadSettings(oldSettings, XmlExternalizationScope.UserSettings, oldSettings.GetType().Name);
                for (int i = 0; i < oldSettings.FileAssociations.Count; i++)
                {
                    var association = oldSettings.FileAssociations[i];
                    boundSettingsStore.SetIndexedValue((ZenCodingSettings settings) => settings.FileAssociations, i, association);
                }

                boundSettingsStore.SetValue(isUpgradedProperty, true);
            }
        }
Exemple #12
0
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="solution">
        /// The current solution.
        /// </param>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ISolution solution, ViolationEventArgs violation, DocumentRange documentRange)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            if (ruleID == "SA0102") // Syntax error from parser
            {
                return(new StyleCopErrorHighlighting(violation, documentRange));
            }

            ISettingsStore             settingsStore             = solution.GetSettingsStore().SettingsStore;
            IContextBoundSettingsStore contextBoundSettingsStore =
                settingsStore.BindToContextTransient(ContextRange.Smart(documentRange.Document.ToDataContext()));

            Severity severity = HighlightingSettingsManager.Instance.GetConfigurableSeverity(
                highlightID,
                sourceFile: null,
                storeBoundToSourceFile: contextBoundSettingsStore);

            return(new StyleCopHighlighting(violation, documentRange, severity, highlightID));
        }
 // This seems to be the earliest place from which we can get a settings store. We use
 // this to push in settings without having to use a real settings file. (It looks like
 // you can actually provide a test-local settings file, but for now, just providing it
 // programmatically is easiest.)
 protected override void WithProject(IProject project, ISettingsStore settingsStore, Action action)
 {
     // The docs all say to use plain BindToContext, but that has been marked as [Obsolete].
     // This appears to be what that obsolete method actually does. (And teh DataContexts.Empty
     // just copies what the test code uses when it creates a bound settings store to pass to the
     // code under test.)
     IContextBoundSettingsStore boundStore = settingsStore.BindToContextTransient(
         ContextRange.ManuallyRestrictWritesToOneContext(
         (lifetime, contexts) => settingsStore.DataContexts.Empty));
     boundStore.SetValue<OrderUsingsSettings, string>(
         settings => settings.OrderSpecificationXml,
         "<Groups xmlns=\"http://schemas.interact-sw.co.uk/OrderUsings/2014\">" +
         "<Group Priority='1' NamespacePattern='System*' />" +
         "<Group Priority='1' NamespacePattern='Microsoft*' />" +
         "<Space />" +
         "<Group Priority='9999' NamespacePattern='*' />" +
         "<Space />" +
         "<Group Priority='9999' NamespacePattern='*' AliasPattern='*' Type='Alias' />" +
         "</Groups>");
     base.WithProject(project, settingsStore, action);
 }
Exemple #14
0
        // This seems to be the earliest place from which we can get a settings store. We use
        // this to push in settings without having to use a real settings file. (It looks like
        // you can actually provide a test-local settings file, but for now, just providing it
        // programmatically is easiest.)
        protected override void WithProject(IProject project, ISettingsStore settingsStore, Action action)
        {
            // The docs all say to use plain BindToContext, but that has been marked as [Obsolete].
            // This appears to be what that obsolete method actually does. (And teh DataContexts.Empty
            // just copies what the test code uses when it creates a bound settings store to pass to the
            // code under test.)
            IContextBoundSettingsStore boundStore = settingsStore.BindToContextTransient(
                ContextRange.ManuallyRestrictWritesToOneContext(
                    (lifetime, contexts) => settingsStore.DataContexts.Empty));

            boundStore.SetValue <OrderUsingsSettings, string>(
                settings => settings.OrderSpecificationXml,
                "<Groups xmlns=\"http://schemas.interact-sw.co.uk/OrderUsings/2014\">" +
                "<Group Priority='1' NamespacePattern='System*' />" +
                "<Group Priority='1' NamespacePattern='Microsoft*' />" +
                "<Space />" +
                "<Group Priority='9999' NamespacePattern='*' />" +
                "<Space />" +
                "<Group Priority='9999' NamespacePattern='*' AliasPattern='*' Type='Alias' />" +
                "</Groups>");
            base.WithProject(project, settingsStore, action);
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="lifetime">
        /// The lifetime.
        /// </param>
        /// <param name="settingsStore">The settings store.</param>
        /// <param name="fileSystemTracker">
        /// The file System Tracker.
        /// </param>
        /// <returns>
        /// A new StyleCopCore object.
        /// </returns>
        public static StyleCopCore Create(Lifetime lifetime, ISettingsStore settingsStore, IFileSystemTracker fileSystemTracker)
        {
            StyleCopTrace.In();

            ProjectSettingsFactory projectSettingsFactory = new ProjectSettingsFactory(lifetime, fileSystemTracker);
            SourceCodeFactory      sourceCodeFactory      = new SourceCodeFactory();

            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(
                sourceCodeFactory.Create,
                projectSettingsFactory.Create);

            IContextBoundSettingsStore settings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);
            bool   pluginsEnabled = settings.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsEnabled);
            string pluginsPath    = settings.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsPath);

            // TODO: Is there a nicer way of finding out the ReSharper install location?
            string standardPath =
                FileSystemPath.Parse(Assembly.GetCallingAssembly().Location)
                .Directory.Combine(@"Extensions\StyleCop.StyleCop\StyleCopAddins")
                .FullPath;

            var paths = new List <string> {
                standardPath
            };

            if (pluginsEnabled && !string.IsNullOrEmpty(pluginsPath))
            {
                paths.Add(pluginsPath);
            }

            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, paths, false);

            projectSettingsFactory.StyleCopCore = styleCop.Core;

            return(StyleCopTrace.Out(styleCop.Core));
        }
        private IContextBoundSettingsStore BindSettingsStore()
        {
            var store = settingsStore.BindToContextTransient(ContextRange.Smart((l, _) => dataContexts.CreateOnSelection(l)));

            return(store);
        }
 public GenerateUnityEventFunctionsBuilder(ISolution solution, ISettingsStore settingsStore, UnityApi unityApi)
 {
     mySolution = solution;
     myUnityApi = unityApi;
     mySettings = settingsStore.BindToContextTransient(ContextRange.Smart(solution.ToDataContext()));
 }
Exemple #18
0
        public UnitySolutionHelper(ISettingsStore settingsStore)
        {
            IContextBoundSettingsStore boundSettings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);

            m_unitySettings = boundSettings.GetKey <UnitySettings>(SettingsOptimization.DoMeSlowly);
        }
Exemple #19
0
 public LtgConfigWatcher(ISettingsStore settingsStore)
 {
     _boundSettings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);
     Initialize();
 }
 public LtgConfigWatcher(ISettingsStore settingsStore)
 {
     _boundSettings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);
     Initialize();
 }
Exemple #21
0
 public ShellSpellCheckResources([NotNull] ISettingsStore settingsStore)
     : this(settingsStore.BindToContextTransient(ContextRange.Smart((lifetime, contexts) => contexts.Empty)))
 {
 }