private void MoveToResource(object sender, EventArgs e)
        {
            var entry = CompositionHost.GetExportedValue <IRefactorings>().MoveToResource(Dte.ActiveDocument);

            if (entry == null)
            {
                return;
            }

            // ReSharper disable once PossibleNullReferenceException
            if (!Properties.Settings.Default.MoveToResourceOpenInResXManager)
            {
                return;
            }

            var dispatcher = Dispatcher.CurrentDispatcher;

            dispatcher.BeginInvoke(DispatcherPriority.Background, () =>
            {
                ShowToolWindow();

                var resourceViewModel = CompositionHost.GetExportedValue <ResourceViewModel>();

                dispatcher.BeginInvoke(DispatcherPriority.Background, () =>
                {
                    if (!resourceViewModel.SelectedEntities.Contains(entry.Container))
                    {
                        resourceViewModel.SelectedEntities.Add(entry.Container);
                    }

                    resourceViewModel.SelectedTableEntries.Clear();
                    resourceViewModel.SelectedTableEntries.Add(entry);
                });
            });
        }
Example #2
0
        private void DocumentEvents_DocumentSaved(EnvDTE.Document document)
        {
            Tracer.WriteLine("DTE event: Document saved");

            if (!AffectsResourceFile(document))
            {
                return;
            }

            // Run custom tool (usually attached to neutral language) even if a localized language changes,
            // e.g. if custom tool is a text template, we might want not only to generate the designer file but also
            // extract some localization information.
            // => find the resource entity that contains the document and run the custom tool on the neutral project file.

            // ReSharper disable once PossibleNullReferenceException
            Func <ResourceEntity, bool> predicate = e => e.Languages
                                                    .Select(lang => lang.ProjectFile)
                                                    .OfType <DteProjectFile>()
                                                    .Any(projectFile => projectFile.ProjectItems.Any(p => p.Document == document));

            var entity = CompositionHost.GetExportedValue <ResourceManager>().ResourceEntities.FirstOrDefault(predicate);

            var neutralProjectFile = (DteProjectFile)entity?.NeutralProjectFile;

            // VS will run the custom tool on the project item only. Run the custom tool on any of the descendants, too.
            var projectItems = neutralProjectFile?.ProjectItems.SelectMany(projectItem => projectItem.Descendants());

            _customToolRunner.Enqueue(projectItems);

            ReloadSolution();
        }
        private void Solution_ContentChanged(object item)
        {
            Tracer.WriteLine("DTE event: Solution content changed");

            CompositionHost.GetExportedValue <ISourceFilesProvider>().Invalidate();

            ReloadSolution();
        }
Example #4
0
        private void Solution_ContentChanged([CanBeNull] object item)
        {
            using (PerformanceTracer.Start("DTE event: Solution content changed"))
            {
                CompositionHost.GetExportedValue <ISourceFilesProvider>().Invalidate();

                ReloadSolution();
            }
        }
        private void Solution_Opened()
        {
            Tracer.WriteLine("DTE event: Solution opened");

            ReloadSolution();

            var resourceManager = CompositionHost.GetExportedValue <ResourceManager>();

            resourceManager.ProjectFileSaved -= ResourceManager_ProjectFileSaved;
            resourceManager.ProjectFileSaved += ResourceManager_ProjectFileSaved;
        }
Example #6
0
        private void Solution_Opened()
        {
            //using (PerformanceTracer.Start("DTE event: Solution opened"))
            {
                ReloadSolution();

                var resourceManager = CompositionHost.GetExportedValue <ResourceManager>();

                resourceManager.ProjectFileSaved -= ResourceManager_ProjectFileSaved;
                resourceManager.ProjectFileSaved += ResourceManager_ProjectFileSaved;
            }
        }
Example #7
0
        private void TextEditorContextMenuCommand_BeforeQueryStatus([CanBeNull] object sender, [CanBeNull] EventArgs e)
        {
            if (!(sender is OleMenuCommand menuCommand))
            {
                return;
            }

            using (CompositionHost.GetExportedValue <PerformanceTracer>().Start("Can move to resource"))
            {
                menuCommand.Text    = Resources.MoveToResource;
                menuCommand.Visible = CompositionHost.GetExportedValue <IRefactorings>().CanMoveToResource(Dte.ActiveDocument);
            }
        }
Example #8
0
        private IEnumerable <ResourceEntity> GetSelectedResourceEntities([CanBeNull] string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(Enumerable.Empty <ResourceEntity>());
            }

            var resourceEntities = CompositionHost.GetExportedValue <ResourceManager>().ResourceEntities;

            return(resourceEntities
                   .Where(entity => ContainsFile(entity, fileName) || ContainsChildOfWinFormsDesignerItem(entity, fileName))
                   .ToArray());
        }
Example #9
0
        private void MoveToResource([CanBeNull] object sender, [CanBeNull] EventArgs e)
        {
            var entry = CompositionHost.GetExportedValue <IRefactorings>().MoveToResource(Dte.ActiveDocument);

            if (entry == null)
            {
                return;
            }

            if (!Properties.Settings.Default.MoveToResourceOpenInResXManager)
            {
                return;
            }

            CompositionHost.GetExportedValue <VsixShellViewModel>().SelectEntry(entry);
        }
        private void ShowSelectedResourceFiles(object sender, EventArgs e)
        {
            var selectedResourceEntites = GetSelectedResourceEntites()?.Distinct().ToArray();

            if (selectedResourceEntites == null)
            {
                return;
            }

            // if we open the window the first time, make sure it does not select all entities by default.
            Settings.Default.AreAllFilesSelected = false;

            var selectedEntities = CompositionHost.GetExportedValue <ResourceViewModel>().SelectedEntities;

            selectedEntities.Clear();
            selectedEntities.AddRange(selectedResourceEntites);

            ShowToolWindow();
        }
Example #11
0
        private void ShowSelectedResourceFiles(object sender, EventArgs e)
        {
            if (!ShowToolWindow())
            {
                return;
            }

            var resourceViewModel = CompositionHost.GetExportedValue <ResourceViewModel>();

            var selectedResourceEntites = GetSelectedResourceEntites()?.Distinct().ToArray();

            if (selectedResourceEntites == null)
            {
                return;
            }

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, () =>
            {
                resourceViewModel.SelectedEntities.Clear();
                resourceViewModel.SelectedEntities.AddRange(selectedResourceEntites);
            });
        }
Example #12
0
 private void ReloadSolution()
 {
     CompositionHost.GetExportedValue <ResourceViewModel>().Reload();
 }
Example #13
0
 private void Invalidate()
 {
     CompositionHost.GetExportedValue <ISourceFilesProvider>().Invalidate();
 }