Example #1
0
        public FileWatcher(Lifetime lifetime, string directory, string fileMask, NotifyFilters notifyFilter, WatchFile watchFile)
        {
            OnWatchedEvent = new Signal <FileSystemEventArgs>(lifetime,
                                                              "FileWatcher.OnWatchedEvent");

            var watcher = new FileSystemWatcher()
            {
                Path         = directory,
                Filter       = fileMask,
                NotifyFilter = notifyFilter
            };

            var handler = new FileSystemEventHandler(OnChanged);

            switch (watchFile)
            {
            case WatchFile.Create:
                lifetime.AddBracket(() => watcher.Created += handler, () => watcher.Created -= handler);
                break;

            case WatchFile.Change:
                lifetime.AddBracket(() => watcher.Changed += handler, () => watcher.Changed -= handler);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(watchFile), watchFile, null);
            }
        }
Example #2
0
        private void SubscribeEvents()
        {
            var events = dte.Events;

            if (events == null)
            {
                return;
            }

            var buildEvents = events.BuildEvents;

            if (buildEvents == null)
            {
                return;
            }

            lifetime.AddBracket(() =>
            {
                buildEvents.OnBuildBegin += OnBuildBegin;
            }, () =>
            {
                buildEvents.OnBuildBegin -= OnBuildBegin;
            });

            lifetime.AddBracket(() =>
            {
                buildEvents.OnBuildDone += OnBuildDone;
            }, () =>
            {
                buildEvents.OnBuildDone -= OnBuildDone;
            });
        }
Example #3
0
        public void Open(Lifetime lifetime, IShellLocks shellLocks, ChangeManager changeManager, ISolution solution, DocumentManager documentManager, IActionManager actionManager, ICommandProcessor commandProcessor, TextControlChangeUnitFactory changeUnitFactory, JetPopupMenus jetPopupMenus)
        {
            Debug.Assert(!IsOpened);

            _solution       = solution;
            DocumentManager = documentManager;
            _jetPopupMenus  = jetPopupMenus;
            changeManager.Changed2.Advise(lifetime, Handler);
            lifetime.AddAction(Close);
            var expandAction = actionManager.Defs.TryGetActionDefById(GotoDeclarationAction.ACTION_ID);

            if (expandAction != null)
            {
                var postfixHandler = new GotoDeclarationHandler(lifetime, shellLocks, commandProcessor, changeUnitFactory, this);

                lifetime.AddBracket(
                    FOpening: () => actionManager.Handlers.AddHandler(expandAction, postfixHandler),
                    FClosing: () => actionManager.Handlers.RemoveHandler(expandAction, postfixHandler));
            }

            var findUsagesAction  = actionManager.Defs.GetActionDef <FindUsagesAction>();
            var findUsagesHandler = new FindUsagesHandler(lifetime, shellLocks, commandProcessor, changeUnitFactory, this);

            lifetime.AddBracket(
                FOpening: () => actionManager.Handlers.AddHandler(findUsagesAction, findUsagesHandler),
                FClosing: () => actionManager.Handlers.RemoveHandler(findUsagesAction, findUsagesHandler));
        }
Example #4
0
    public void Open(Lifetime lifetime, IShellLocks shellLocks, ChangeManager changeManager, ISolution solution, DocumentManager documentManager, IActionManager actionManager, ICommandProcessor commandProcessor, TextControlChangeUnitFactory changeUnitFactory, JetPopupMenus jetPopupMenus)
    {
      Debug.Assert(!IsOpened);

      _solution = solution;
      DocumentManager = documentManager;
      _jetPopupMenus = jetPopupMenus;
      changeManager.Changed2.Advise(lifetime, Handler);
      lifetime.AddAction(Close);
      var expandAction = actionManager.Defs.TryGetActionDefById(GotoDeclarationAction.ACTION_ID);
      if (expandAction != null)
      {
        var postfixHandler = new GotoDeclarationHandler(lifetime, shellLocks, commandProcessor, changeUnitFactory, this);

        lifetime.AddBracket(
          FOpening: () => actionManager.Handlers.AddHandler(expandAction, postfixHandler),
          FClosing: () => actionManager.Handlers.RemoveHandler(expandAction, postfixHandler));
      }
      
      var findUsagesAction = actionManager.Defs.GetActionDef<FindUsagesAction>();
      var findUsagesHandler = new FindUsagesHandler(lifetime, shellLocks, commandProcessor, changeUnitFactory, this);

      lifetime.AddBracket(
        FOpening: () => actionManager.Handlers.AddHandler(findUsagesAction, findUsagesHandler),
        FClosing: () => actionManager.Handlers.RemoveHandler(findUsagesAction, findUsagesHandler));
    }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T4FileDataCache"/> class.
        /// </summary>
        /// <param name="lifetime">The lifetime of this class.</param>
        /// <param name="psiFiles">The PSI manager.</param>
        /// <param name="directiveInfoManager">An instance of <see cref="DirectiveInfoManager"/>.</param>
        public T4FileDataCache([NotNull] Lifetime lifetime, [NotNull] PsiFiles psiFiles, [NotNull] DirectiveInfoManager directiveInfoManager)
        {
            _directiveInfoManager = directiveInfoManager;
            _fileDataChanged      = new Signal <Pair <IPsiSourceFile, T4FileDataDiff> >(lifetime, "T4FileDataCache.FileDataChanged");

            lifetime.AddBracket(
                () => psiFiles.PsiFileCreated += OnPsiFileChanged,
                () => psiFiles.PsiFileCreated -= OnPsiFileChanged);
            lifetime.AddBracket(
                () => psiFiles.AfterPsiChanged += OnPsiChanged,
                () => psiFiles.AfterPsiChanged -= OnPsiChanged);
            lifetime.AddDispose(_fileDataBySourceFile);
        }
Example #6
0
        public TutorialStepPresenter(IStepView view, string contentPath, Lifetime lifetime, ISolution solution, IPsiFiles psiFiles,
                                     TextControlManager textControlManager, IShellLocks shellLocks, IEditorManager editorManager,
                                     DocumentManager documentManager, IUIApplication environment, IActionManager actionManager,
                                     IPsiServices psiServices, IActionShortcuts shortcutManager)
        {
            _stepView          = view;
            Lifetime           = lifetime;
            Solution           = solution;
            PsiFiles           = psiFiles;
            TextControlManager = textControlManager;
            ShellLocks         = shellLocks;
            EditorManager      = editorManager;
            DocumentManager    = documentManager;
            Environment        = environment;
            ActionManager      = actionManager;
            _contentPath       = contentPath;
            _codeNavigator     = new SourceCodeNavigator(lifetime, solution, psiFiles, textControlManager, shellLocks, editorManager,
                                                         documentManager, environment);
            _steps = new Dictionary <int, TutorialStep>();
            _steps = TutorialXmlReader.ReadTutorialSteps(contentPath);

            _currentStepId = TutorialXmlReader.ReadCurrentStep(contentPath);
            CurrentStep    = _steps[_currentStepId];

            lifetime.AddBracket(
                () => { _stepView.NextStep += GoNext; },
                () => { _stepView.NextStep -= GoNext; });

            ProcessStep();
        }
 public NancyReferenceProviderFactory(Lifetime lifetime, ISolution solution, ISettingsStore settingsStore, MvcReferenceProviderValidator providerValidator)
 {
     this.solution = solution;
     
     lifetime.AddBracket(() => providerValidator.OnChanged += FireOnChanged,
                         () => providerValidator.OnChanged -= FireOnChanged);
 }
Example #8
0
        private static void AdviseUnityActions(EditorPluginModel model, Lifetime connectionLifetime)
        {
            var isPlayingAction = new Action(() =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var isPlayOrWillChange = EditorApplication.isPlayingOrWillChangePlaymode;
                    var isPlaying          = isPlayOrWillChange && EditorApplication.isPlaying;
                    if (!model.Play.HasValue() || model.Play.HasValue() && model.Play.Value != isPlaying)
                    {
                        model.Play.SetValue(isPlaying);
                    }

                    var isPaused = EditorApplication.isPaused;
                    if (!model.Pause.HasValue() || model.Pause.HasValue() && model.Pause.Value != isPaused)
                    {
                        model.Pause.SetValue(isPaused);
                    }
                });
            });

            isPlayingAction(); // get Unity state
            model.Play.AdviseNotNull(connectionLifetime, play =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var res = EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying;
                    if (res != play)
                    {
                        EditorApplication.isPlaying = play;
                    }
                });
            });

            model.Pause.AdviseNotNull(connectionLifetime, pause =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    EditorApplication.isPaused = pause;
                });
            });

            model.Step.AdviseNotNull(connectionLifetime, x =>
            {
                MainThreadDispatcher.Instance.Queue(EditorApplication.Step);
            });

            var isPlayingHandler = new EditorApplication.CallbackFunction(() => isPlayingAction());

// left for compatibility with Unity <= 5.5
#pragma warning disable 618
            connectionLifetime.AddBracket(() => { EditorApplication.playmodeStateChanged += isPlayingHandler; },
                                          () => { EditorApplication.playmodeStateChanged -= isPlayingHandler; });
#pragma warning restore 618
            // new api - not present in Unity 5.5
            // private static Action<PauseState> IsPauseStateChanged(UnityModel model)
            //    {
            //      return state => model?.Pause.SetValue(state == PauseState.Paused);
            //    }
        }
Example #9
0
        public PostfixTemplatesTracker([NotNull] Lifetime lifetime,
                                       [NotNull] IActionManager manager,
                                       [NotNull] ICommandProcessor commandProcessor,
                                       [NotNull] ILookupWindowManager lookupWindowManager,
                                       [NotNull] PostfixTemplatesManager templatesManager,
                                       [NotNull] LookupItemsOwnerFactory lookupItemsFactory,
                                       [NotNull] TextControlChangeUnitFactory changeUnitFactory)
        {
            // override live templates expand action
#if RESHARPER8
            var expandAction = manager.TryGetAction(TextControlActions.TAB_ACTION_ID) as IUpdatableAction;
#elif RESHARPER9
            var expandAction = manager.Defs.TryGetActionDefById(TextControlActions.TAB_ACTION_ID);
#endif
            if (expandAction != null)
            {
                var postfixHandler = new ExpandPostfixTemplateHandler(
                    lifetime, commandProcessor, lookupWindowManager, templatesManager, lookupItemsFactory, changeUnitFactory);

#if RESHARPER8
                expandAction.AddHandler(lifetime, postfixHandler);
#elif RESHARPER9
                lifetime.AddBracket(
                    FOpening: () => manager.Handlers.AddHandler(expandAction, postfixHandler),
                    FClosing: () => manager.Handlers.RemoveHandler(expandAction, postfixHandler));
#endif
            }
        }
        public PatternManagerCache(Lifetime lifetime, CacheManagerEx cacheManager, PsiProjectFileTypeCoordinator projectFileTypeCoordinator, SolutionAnalyzer solutionAnalyzer)
        {
            this.projectFileTypeCoordinator = projectFileTypeCoordinator;
            this.solutionAnalyzer = solutionAnalyzer;

            lifetime.AddBracket(() => cacheManager.RegisterCache(this), () => cacheManager.UnregisterCache(this));
        }
Example #11
0
        public void ShowTutorialWindow(int tutorialId, Lifetime lifetime,
                                       ISolution solution, IPsiFiles psiFiles, ChangeManager changeManager, TextControlManager textControlManager,
                                       IShellLocks shellLocks, IEditorManager editorManager, DocumentManager documentManager,
                                       IUIApplication environment,
                                       IActionManager actionManager, WindowsHookManager windowsHookManager, IPsiServices psiServices,
                                       IActionShortcuts shortcutManager, IColorThemeManager colorThemeManager, IThreading threading)
        {
            var contentPath = _globalSettings.GetPath(tutorialId, PathType.WorkCopyContentFile);

            _runningTutorial = tutorialId;

            threading.ExecuteOrQueue("RunTutorialWindow", () =>
            {
                _tutorialWindow = new TutorialWindow(contentPath, lifetime, this, solution, psiFiles, changeManager,
                                                     textControlManager,
                                                     shellLocks, editorManager, documentManager, environment, actionManager, _toolWindowClass,
                                                     windowsHookManager, colorThemeManager);

                lifetime.AddBracket(
                    () =>
                {
                    _tutorialWindow.Show();
                    _homeWindow.HideLoadingImages();
                },
                    () =>
                {
                    _tutorialWindow.Close();
                    _tutorialWindow  = null;
                    _runningTutorial = 0;
                    _homeWindow.EnableButtons(true);
                });
            });
        }
Example #12
0
 public UnityCustomOptionsPage(Lifetime lifetime, OptionsSettingsSmartContext optionsSettingsSmartContext)
     : base(lifetime, optionsSettingsSmartContext)
 {
     myUnityKey         = (SettingsIndexedKey)optionsSettingsSmartContext.Schema.GetKey <UnityCustomSettings>();
     myCustomUnityItems = new ObservableCollection <UnityClassItem>();
     foreach (GuidIndex id in ((IContextBoundSettingsStore)OptionsSettingsSmartContext).
              EnumIndexedKey(myUnityKey, null))
     {
         Dictionary <SettingsKey, object> unityKeyIndices = new Dictionary <SettingsKey, object>
         {
             {
                 myUnityKey,
                 id
             }
         };
         if (OptionsSettingsSmartContext.IsIndexedKeyDefined(myUnityKey, unityKeyIndices))
         {
             string unityClass = UnitySettingsUtil.ReadCustomPattern(optionsSettingsSmartContext, unityKeyIndices);
             if (unityClass != null)
             {
                 myCustomUnityItems.Add(new UnityClassItem(id, unityClass, this.OptionsSettingsSmartContext));
             }
         }
     }
     lifetime.AddBracket((Action)(() => this.myCustomUnityItems.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnCustomPatternItemsCollectionChanged)), (Action)(() => this.myCustomUnityItems.CollectionChanged -= new NotifyCollectionChangedEventHandler(this.OnCustomPatternItemsCollectionChanged)));
     this.AddCustomOption((IAutomation) new CustomPatternsViewModel2(locks, engine, psiProjectFileTypeCoordinator, mainWindow, windowBranding, formValidators, windowsHookManager, documentMarkupManager, solution, this.OptionsSettingsSmartContext, documentManager, structuralSearchActionManager, searchDomainFactory, languages, this.myCustomUnityItems));
 }
Example #13
0
        public PatternManagerCache(Lifetime lifetime, CacheManagerEx cacheManager, PsiProjectFileTypeCoordinator projectFileTypeCoordinator, SolutionAnalyzer solutionAnalyzer)
        {
            this.projectFileTypeCoordinator = projectFileTypeCoordinator;
            this.solutionAnalyzer           = solutionAnalyzer;

            lifetime.AddBracket(() => cacheManager.RegisterCache(this), () => cacheManager.UnregisterCache(this));
        }
Example #14
0
        public NancyReferenceProviderFactory(Lifetime lifetime, ISolution solution, ISettingsStore settingsStore, MvcReferenceProviderValidator providerValidator)
        {
            this.solution = solution;

            lifetime.AddBracket(() => providerValidator.OnChanged += FireOnChanged,
                                () => providerValidator.OnChanged -= FireOnChanged);
        }
Example #15
0
 public static void TemporaryEnableNukeProjectBuild(Lifetime lifetime, IProject buildProject, ISolution solution, _DTE dte)
 {
     lifetime.AddBracket(() => SetEnableBuild(shouldBuild: true, project: buildProject, solution: solution, dte: dte),
                         () =>
     {
         SetEnableBuild(shouldBuild: false, project: buildProject, solution: solution, dte: dte);
         dte.Solution.SaveAs(solution.SolutionFilePath.FullPath);
     });
 }
        private void InitControls()
        {
            using (new LayoutSuspender(this))
            {
                var tablePanel = new TableLayoutPanel
                {
                    AutoSizeMode = AutoSizeMode.GrowAndShrink,
                    Margin       = Padding.Empty,
                    Padding      = Padding.Empty,
                    Size         = ClientSize
                };
                tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50f));
                Controls.Add(tablePanel);

                GroupingEvent sizeEvent = Environment.Threading.GroupingEvents[Rgc.Invariant].CreateEvent(
                    _lifetime,
                    Pid + ".SizeChanged",
                    TimeSpan.FromMilliseconds(300.0), () =>
                {
                    var clientSize = new Size(ClientSize.Width - _margin, ClientSize.Height - _margin);
                    if (!clientSize.Equals(tablePanel.Size))
                    {
                        using (new LayoutSuspender(this))
                        {
                            tablePanel.Size = clientSize;
                        }
                    }
                });
                EventHandler handler = (sender, args) => sizeEvent.FireIncoming();
                _lifetime.AddBracket(() => SizeChanged += handler, () => SizeChanged -= handler);

                string titleCaption = "Specify external file and directory paths to include in the code inspection. " +
                                      "Relative paths are relative to the directory containing the project. " +
                                      "Exclusions specified in the Generated Code settings apply." +
                                      System.Environment.NewLine +
                                      "NOTE: Changes do not take affect until project is loaded." +
                                      System.Environment.NewLine;
                var titleLabel = new Controls.Label(titleCaption)
                {
                    AutoSize = true, Dock = DockStyle.Top
                };
                tablePanel.Controls.Add(titleLabel);

                string[] externalCodePaths = _settings.EnumIndexedValues(ExternalCodeSettingsAccessor.Paths).ToArray();
                _externalCodePathsCollectionEdit = new StringCollectionEdit(Environment, "External files and directories:", null, _mainWindow, _windowsHookManager, _formValidators)
                {
                    Dock = DockStyle.Fill
                };
                _externalCodePathsCollectionEdit.Items.Value = externalCodePaths;
                tablePanel.Controls.Add(_externalCodePathsCollectionEdit, 0, 1);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReferencedAnalyzersCache"/> class.
        /// </summary>
        /// <param name="lifetime">The lifetime of the component</param>
        /// <param name="solution">The current solution</param>
        /// <param name="threading">The threading API</param>
        /// <param name="solutionLoadTasksScheduler">Solution load task scheduler</param>
        /// <param name="projectModelSynchronizer">The project model synchronizer</param>
        /// <param name="packageInstallerServices">NuGet installer services API</param>
        /// <param name="packageInstallerEvents">NuGet installer events API</param>
        public ReferencedAnalyzersCache(
            Lifetime lifetime,
            ISolution solution,
            IThreading threading,
            ISolutionLoadTasksScheduler solutionLoadTasksScheduler,
            ProjectModelSynchronizer projectModelSynchronizer,
            Lazy <Optional <IVsPackageInstallerServices> > packageInstallerServices,
            Lazy <Optional <IVsPackageInstallerEvents> > packageInstallerEvents)
        {
            this.solution  = solution;
            this.threading = threading;
            this.projectModelSynchronizer = projectModelSynchronizer;
            this.packageInstallerEvents   = packageInstallerEvents.Value.CanBeNull;
            this.packageInstallerServices = packageInstallerServices.Value.CanBeNull;

            this.syncObject = new object();

            this.referencedAnalyzers = new OneToSetMap <string, string>();

            this.groupingEvent = threading.GroupingEvents.CreateEvent(
                lifetime,
                "StyleCop::AnalyzersCache",
                TimeSpan.FromSeconds(2),
                Rgc.Guarded,
                this.DoResetAnalyzersCache);

            if (!this.IsNuGetAvailable)
            {
                Logger.LogMessage(
                    LoggingLevel.VERBOSE,
                    "[StyleCop::AnalyzersCache] Unable to get NuGet interfaces. No exception thrown");
            }
            else
            {
                lifetime.AddBracket(
                    () =>
                {
                    this.packageInstallerEvents.PackageInstalled   += this.ResetAnalyzersCache;
                    this.packageInstallerEvents.PackageUninstalled += this.ResetAnalyzersCache;
                },
                    () =>
                {
                    this.packageInstallerEvents.PackageInstalled   -= this.ResetAnalyzersCache;
                    this.packageInstallerEvents.PackageUninstalled -= this.ResetAnalyzersCache;
                });
                solutionLoadTasksScheduler.EnqueueTask(new SolutionLoadTask("StyleCop.ReferencedAnalyzersCache", SolutionLoadTaskKinds.AfterDone,
                                                                            () =>
                {
                    this.ResetAnalyzersCache(null);
                }));
            }
        }
Example #18
0
        public WindowFocusTracker(Lifetime lifetime)
        {
            var dte = VsIntegration.GetCurrentVsInstance();

            ActiveWindow    = new Property <Window>(lifetime, "WindowsFocusTracker.ActiveWindow");
            IsFocusOnEditor = new Property <bool>(lifetime, "WindowsFocusTracker.IsFocusOnEditor")
            {
                Value = dte.ActiveWindow.Document != null
            };

            lifetime.AddBracket(() => dte.Events.WindowEvents.WindowActivated += OnWindowActivated,
                                () => dte.Events.WindowEvents.WindowActivated -= OnWindowActivated);
        }
Example #19
0
 public PsiCache(Lifetime lifetime,
                 IPsiServices psiServices,
                 IShellLocks shellLocks,
                 CacheManager cacheManager,
                 IPsiConfiguration psiConfiguration, IPersistentIndexManager persistentIdIndex)
 {
     myPsiConfiguration  = psiConfiguration;
     myPersistentIdIndex = persistentIdIndex;
     myShellLocks        = shellLocks;
     //using (ReadLockCookie.Create())
     //{
     lifetime.AddBracket(() => cacheManager.RegisterCache(this), () => cacheManager.UnregisterCache(this));
     //}
 }
Example #20
0
        private static void RunTutorial(string contentPath, Lifetime lifetime, ISolution solution, IPsiFiles psiFiles,
                                        TextControlManager textControlManager, IShellLocks shellLocks, IEditorManager editorManager,
                                        DocumentManager documentManager, IUIApplication environment, IActionManager actionManager,
                                        ToolWindowManager toolWindowManager, TutorialWindowDescriptor tutorialWindowDescriptor,
                                        IWindowsHookManager windowsHookManager, IPsiServices psiServices, IActionShortcuts shortcutManager,
                                        IColorThemeManager colorThemeManager)
        {
            var tutorialWindow = new TutorialWindow(contentPath, lifetime, solution, psiFiles, textControlManager, shellLocks, editorManager,
                                                    documentManager, environment, actionManager, toolWindowManager, tutorialWindowDescriptor, windowsHookManager,
                                                    psiServices, shortcutManager, colorThemeManager);

            lifetime.AddBracket(
                () => { tutorialWindow.Show(); },
                () => { tutorialWindow.Close(); });
        }
Example #21
0
        public TripleGoToEverythingActionHandler([NotNull] IActionManager actionManager, Lifetime lifetime)
        {
            myActionManager = actionManager;

            const string gotoTypeActionId = "GotoType";

            var gotoTypeAction = actionManager.Defs.TryGetActionDefById(gotoTypeActionId);

            if (gotoTypeAction != null)
            {
                lifetime.AddBracket(
                    () => actionManager.Handlers.AddHandler(gotoTypeAction, this),
                    () => actionManager.Handlers.RemoveHandler(gotoTypeAction, this));
            }
        }
Example #22
0
        public StepPsiChecker(Lifetime lifetime, ISolution solution, IPsiFiles psiFiles, IShellLocks shellLocks)
        {
            Solution    = solution;
            _psiFiles   = psiFiles;
            _shellLocks = shellLocks;

            Action <ITreeNode, PsiChangedElementType> psiChanged =
                (_, __) => OnPsiChanged();

            lifetime.AddBracket(
                () => psiFiles.AfterPsiChanged += psiChanged,
                () => psiFiles.AfterPsiChanged -= psiChanged);

            OnCheckPass = new Signal <bool>(lifetime, "StepPsiChecker.AfterPsiChangesDone");
        }
Example #23
0
        public PostfixTemplatesTabTracker(
            [NotNull] Lifetime lifetime,
            [NotNull] IActionManager manager,
            [NotNull] ICommandProcessor commandProcessor,
            [NotNull] TextControlChangeUnitFactory changeUnitFactory)
        {
            // override live templates expand action
            var expandAction = manager.Defs.TryGetActionDefById(TextControlActions.TAB_ACTION_ID);

            if (expandAction != null)
            {
                var postfixHandler = new ExpandPostfixTemplateHandler(commandProcessor, changeUnitFactory);

                lifetime.AddBracket(
                    FOpening: () => manager.Handlers.AddHandler(expandAction, postfixHandler),
                    FClosing: () => manager.Handlers.RemoveHandler(expandAction, postfixHandler));
            }
        }
Example #24
0
        public StepActionChecker(Lifetime lifetime, IShellLocks shellLocks, IPsiFiles psiFiles)
        {
            _shellLocks = shellLocks;
            _psiFiles   = psiFiles;
            _vsInstance = VsIntegration.GetCurrentVsInstance();
            var events2 = _vsInstance.Events as Events2;

            if (events2 == null)
            {
                return;
            }

            var commandEvents = events2.CommandEvents;

            lifetime.AddBracket(
                () => commandEvents.AfterExecute += CommandEventsOnAfterExecute,
                () => commandEvents.AfterExecute -= CommandEventsOnAfterExecute);

            OnCheckPass = new Signal <bool>(lifetime, "StepActionChecker.AfterActionApplied");
        }
Example #25
0
        public NextStepShortcutChecker(Lifetime lifetime, TutorialStep step, string nextStepActionName)
        {
            _step = step;
            _nextStepActionName = nextStepActionName;
            _vsInstance         = VsIntegration.GetCurrentVsInstance();
            var events2 = _vsInstance.Events as Events2;

            if (events2 == null)
            {
                return;
            }

            var commandEvents = events2.CommandEvents;

            lifetime.AddBracket(
                () => commandEvents.BeforeExecute += CommandEventsOnBeforeExecute,
                () =>
            {
                commandEvents.BeforeExecute -= CommandEventsOnBeforeExecute;
            });
        }
Example #26
0
        public StepPsiChecker(Lifetime lifetime, ISolution solution, IPsiFiles psiFiles,
                              TextControlManager textControlManager, IShellLocks shellLocks,
                              IEditorManager editorManager, DocumentManager documentManager, IUIApplication environment)
        {
            _lifetime           = lifetime;
            _solution           = solution;
            _psiFiles           = psiFiles;
            _textControlManager = textControlManager;
            _shellLocks         = shellLocks;
            _documentManager    = documentManager;
            _environment        = environment;
            _editorManager      = editorManager;

            Action <ITreeNode, PsiChangedElementType> psiChanged =
                (_, __) => OnPsiChanged();

            _lifetime.AddBracket(
                () => psiFiles.AfterPsiChanged += psiChanged,
                () => psiFiles.AfterPsiChanged -= psiChanged);

            AfterPsiChangesDone = new Signal <bool>(lifetime, "StepPsiChecker.AfterPsiChangesDone");
        }
Example #27
0
        protected void AttachEvents(PopupWindowManager popupWindowManager)
        {
            lifetime.AddAction(DetachEvents);

            var context = Context;

            if (context != null)
            {
                lifetime.AddBracket(() => Layouter = context.CreateLayouter(lifetime), () => Layouter = null);
                Layouter?.Layout.Change.Advise_HasNew(lifetime, OnLayouterResultChanged);

                context.AnyOtherAction   += OnContextOwnerAnyActionPerformed;
                context.Scroll           += OnContextOwnerScroll;
                context.SelectionChanged += OnContextOwnerSelectionChanged;
                context.Deactivated      += OnContextOwnerDeactivated;
                context.EscapePressed    += OnContextOwnerEscapePressed;
            }

            AttachWindowEvents();

            popupWindowManager?.PopupWindows.Add(lifetime, this);
        }
Example #28
0
        public TutorialStepPresenter(IStepView view, string contentPath, Lifetime lifetime, ISolution solution,
                                     IPsiFiles psiFiles,
                                     ChangeManager changeManager, TextControlManager textControlManager, IShellLocks shellLocks,
                                     IEditorManager editorManager,
                                     DocumentManager documentManager, IUIApplication environment, IActionManager actionManager)
        {
            _stepView          = view;
            _lifetime          = lifetime;
            Solution           = solution;
            PsiFiles           = psiFiles;
            ChangeManager      = changeManager;
            TextControlManager = textControlManager;
            ShellLocks         = shellLocks;
            EditorManager      = editorManager;
            DocumentManager    = documentManager;
            Environment        = environment;
            ActionManager      = actionManager;
            _codeNavigator     = new SourceCodeNavigator(lifetime, solution, psiFiles, shellLocks,
                                                         editorManager,
                                                         documentManager);
            _steps = new Dictionary <int, TutorialStep>();

            var tutorialXmlReader = new TutorialXmlReader(actionManager);

            _steps = tutorialXmlReader.ReadTutorialSteps(contentPath);

            Title = TutorialXmlReader.ReadTitle(contentPath);

            //TODO: get rid of _currentStepId
            _currentStepId      = 1;
            CurrentStep         = _steps[_currentStepId];
            _stepView.StepCount = _steps.Count;

            lifetime.AddBracket(
                () => { _stepView.NextStep += StepOnStepIsDone; },
                () => { _stepView.NextStep -= StepOnStepIsDone; });

            ProcessCurrentStep();
        }
        private void SubscribeEvents()
        {
            var events = dte.Events;

            if (events == null)
            {
                return;
            }

            var documentEvents = events.DocumentEvents;

            if (documentEvents == null)
            {
                return;
            }

            lifetime.AddBracket(() =>
            {
                documentEvents.DocumentSaved += OnDocumentSaved;
            }, () =>
            {
                documentEvents.DocumentSaved -= OnDocumentSaved;
            });
        }
Example #30
0
        public StepNavigationChecker(Lifetime lifetime, ISolution solution, IPsiFiles psiFiles,
                                     TextControlManager textControlManager, IShellLocks shellLocks,
                                     IEditorManager editorManager, DocumentManager documentManager, IUIApplication environment)
        {
            _lifetime           = lifetime;
            _solution           = solution;
            _psiFiles           = psiFiles;
            _textControlManager = textControlManager;
            _shellLocks         = shellLocks;
            _documentManager    = documentManager;
            _environment        = environment;
            _editorManager      = editorManager;

            EventHandler caretMoved = (sender, args) =>
            {
                _shellLocks.QueueReadLock(_lifetime, "StepNavigationChecker.CheckOnCaretChange", CheckCode);
            };

            _lifetime.AddBracket(
                () => textControlManager.Legacy.CaretMoved += caretMoved,
                () => textControlManager.Legacy.CaretMoved -= caretMoved);

            AfterNavigationDone = new Signal <bool>(lifetime, "StepNavigationChecker.AfterNavigationDone");
        }
        public NodeUnderCaretDetector(Lifetime lifetime, ISolution solution,
                                      DocumentManager documentManager,
                                      ITextControlManager textControlManager, IShellLocks shellLocks)


        {
            Solution               = solution;
            _lifetime              = lifetime;
            _documentManager       = documentManager;
            _textControlManager    = textControlManager;
            _shellLocks            = shellLocks;
            NodeUnderCaret         = new Property <ITreeNode>("NodeUnderCaretDetector.NodeUnderCaret");
            NodeReferencedElements =
                new Property <IEnumerable <IDeclaredElement> >("NodeUnderCaretDetector.NodeReferencedElements");

            EventHandler caretMoved = (sender, args) =>
            {
                _shellLocks.QueueReadLock("NodeUnderCaretDetector.CaretMoved", Refresh);
            };

            lifetime.AddBracket(
                () => _textControlManager.Legacy.CaretMoved += caretMoved,
                () => _textControlManager.Legacy.CaretMoved -= caretMoved);
        }
        private static void AdviseUnityActions(EditorPluginModel model, Lifetime connectionLifetime)
        {
            var syncPlayState = new Action(() =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var isPlaying = EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying;

                    if (!model.Play.HasValue() || model.Play.HasValue() && model.Play.Value != isPlaying)
                    {
                        ourLogger.Verbose("Reporting play mode change to model: {0}", isPlaying);
                        model.Play.SetValue(isPlaying);
                        if (isPlaying)
                        {
                            model.ClearOnPlay(DateTime.UtcNow.Ticks);
                        }
                    }

                    var isPaused = EditorApplication.isPaused;
                    if (!model.Pause.HasValue() || model.Pause.HasValue() && model.Pause.Value != isPaused)
                    {
                        ourLogger.Verbose("Reporting pause mode change to model: {0}", isPaused);
                        model.Pause.SetValue(isPaused);
                    }
                });
            });

            syncPlayState();

            model.Play.Advise(connectionLifetime, play =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var current = EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying;
                    if (current != play)
                    {
                        ourLogger.Verbose("Request to change play mode from model: {0}", play);
                        EditorApplication.isPlaying = play;
                    }
                });
            });

            model.Pause.Advise(connectionLifetime, pause =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    ourLogger.Verbose("Request to change pause mode from model: {0}", pause);
                    EditorApplication.isPaused = pause;
                });
            });

            model.Step.Advise(connectionLifetime, x =>
            {
                MainThreadDispatcher.Instance.Queue(EditorApplication.Step);
            });

            var onPlaymodeStateChanged = new EditorApplication.CallbackFunction(() => syncPlayState());

// left for compatibility with Unity <= 5.5
#pragma warning disable 618
            connectionLifetime.AddBracket(() => { EditorApplication.playmodeStateChanged += onPlaymodeStateChanged; },
                                          () => { EditorApplication.playmodeStateChanged -= onPlaymodeStateChanged; });
#pragma warning restore 618
            // new api - not present in Unity 5.5
            // private static Action<PauseState> IsPauseStateChanged(UnityModel model)
            //    {
            //      return state => model?.Pause.SetValue(state == PauseState.Paused);
            //    }
        }
Example #33
0
 private void RegisterPsiChanged([NotNull] Lifetime lifetime, [NotNull] PsiFiles psiFiles)
 {
     lifetime.AddBracket(
         () => psiFiles.AfterPsiChanged += OnPsiChanged,
         () => psiFiles.AfterPsiChanged -= OnPsiChanged);
 }
 public ReflectedReferenceProviderFactory(Lifetime lifetime, ISolution solution, ISettingsStore settingsStore, ReflectedReferenceProviderValidator validator)
 {
     lifetime.AddBracket(() => validator.OnChanged += FireOnChanged, () => validator.OnChanged -= FireOnChanged);
 }
Example #35
0
        private ILookup<string, FileSystemPath> installedPackages; // there can be several versions of one package (different versions)

        #endregion Fields

        #region Constructors

        public NuGetApi(ISolution solution, Lifetime lifetime, IComponentModel componentModel, IThreading threading, ProjectModelSynchronizer projectModelSynchronizer)
        {
            this.solution = solution;
            this.threading = threading;
            this.projectModelSynchronizer = projectModelSynchronizer;
            try
            {
                vsPackageInstallerServices = componentModel.GetExtensions<IVsPackageInstallerServices>().SingleOrDefault();
                vsPackageInstaller = componentModel.GetExtensions<IVsPackageInstaller>().SingleOrDefault();
                vsPackageInstallerEvents = componentModel.GetExtensions<IVsPackageInstallerEvents>().SingleOrDefault();
            }
            catch (Exception e)
            {
                Logger.LogException("Unable to get NuGet interfaces.", e);
            }

            if (!IsNuGetAvailable)
            {
                Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Unable to get NuGet interfaces. No exception thrown");
                return;
            }

            lifetime.AddBracket(
              () => vsPackageInstallerEvents.PackageInstalled += RecalcInstalledPackages,
              () => vsPackageInstallerEvents.PackageInstalled -= RecalcInstalledPackages);

              lifetime.AddBracket(
              () => vsPackageInstallerEvents.PackageUninstalled += RecalcInstalledPackages,
              () => vsPackageInstallerEvents.PackageUninstalled -= RecalcInstalledPackages);

              RecalcInstalledPackages(null);
        }