Exemple #1
0
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var projects = SolutionActions.FindProjects(DteServiceProvider.Instance);

                for (var i = 0; i < projects.Count; i++)
                {
                    var currentProject = projects[i];
                    if (currentProject.ProjectItems == null)
                    {
                        continue;
                    }
                    if (currentProject.FullName.ToLower().EndsWith(".shproj"))
                    {
                        continue;
                    }

                    for (var j = 1; j < currentProject.ProjectItems.Count; j++)
                    {
                        ActionCSharpOnProjectItem.Action(currentProject.ProjectItems.Item(j), action, cleanupOptions);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
        public override void Run(DTE2 app)
        {
            try
            {
                var basePaths = Utils.FindSolutionDirectories(app);

                if (basePaths == null || basePaths.Count() == 0)
                {
                    return;
                }

                var repository = new Repository(/*basePath*/);
                var loader     = GetLoaderAgent(basePaths, repository);
                var filterer   = new Filterer(basePaths, repository);
                var form       = new FinderForm(GetTitle(), GetColor(), loader, filterer, defaultSearchTerm: app.GetSelectedText());

                if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var foundItem = form.GetSelectedItem();
                    FoundItemsBank.Items = filterer.FoundItems;
                    GotoItem(app, basePaths, foundItem);
                }

                else
                {
                    app.StatusBar.Text = "Ready";
                }
            }
            catch (Exception e) { ErrorNotification.EmailError(e); }
        }
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var projects       = DteServiceProvider.Instance.ActiveSolutionProjects as Array;
                var currentProject = projects.GetValue(0) as Project;

                if (currentProject.ProjectItems == null)
                {
                    return;
                }
                if (currentProject.FullName.ToLower().EndsWith(".shproj"))
                {
                    MessageBox.Show("Clean up can't be called direlctly on Shared Project", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                for (var i = 1; i <= currentProject.ProjectItems.Count; i++)
                {
                    ActionCSharpOnProjectItem.Action(currentProject.ProjectItems.Item(i), action, cleanupOptions);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
Exemple #4
0
        public override void Run(DTE2 app)
        {
            try
            {
                if (app.ActiveDocument == null)
                {
                    app.StatusBar.Text = "No Active Document";
                    return;
                }

                var sisterFile = app.ActiveDocument.FullName.FindSisterFile();

                if (sisterFile.HasValue() && File.Exists(sisterFile))
                {
                    sisterFile = sisterFile.WrapInQuatation(); // handle white spaces in the path
                    app.ExecuteCommand("File.OpenFile", sisterFile);
                    app.StatusBar.Text = "Ready";
                }
                else
                {
                    app.StatusBar.Text = "File Not found: " + sisterFile;
                }
            }
            catch (Exception err)
            {
                ErrorNotification.EmailError(err);
            }
        }
Exemple #5
0
        public static void DoCleanup(ProjectItem item, CodeCleanerType[] actionType, bool fileWindowMustBeOpend = false)
        {
            if (!item.IsCsharpFile() || item.IsCSharpDesignerFile())
            {
                return;
            }

            try
            {
                var path = item.Properties.Item("FullPath").Value.ToString();
                if (path.EndsWithAny(new[] { "AssemblyInfo.cs", "TheApplication.cs" }))
                {
                    return;
                }

                var window = item.Open(Constants.vsViewKindCode);

                window.Activate();
                foreach (var actionTypeItem in actionType)
                {
                    CodeCleanerHost.Run(item, actionTypeItem);
                }
                if (fileWindowMustBeOpend == false)
                {
                    window.Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
        public static void GotoItem(DTE2 app, string[] basePaths, Item item)
        {
            if (item != null)
            {
                try
                {
                    if (!item.FileName.HasValue())
                    {
                        return;
                    }

                    app.ItemOperations.OpenFile(item.FullPath, EnvDTE.Constants.vsViewKindAny);
                    var selection = app.ActiveDocument.Selection as TextSelection;

                    selection?.MoveTo(item.LineNumber, item.Column, Extend: false);

                    if (Settings.Default.TrackItemInSolutionExplorer)
                    {
                        TrackInSolutionExplorer(app, item);
                    }
                }
                catch (Exception err)
                {
                    ErrorNotification.EmailError(err);
                }
            }
        }
        public override void Run(DTE2 app)
        {
            try
            {
                var currentSelectedFilepath = GetSourceFilePath(app) ?? "";

                var basePathsList = Utils.FindSolutionDirectories(app).ToList();

                if (!basePathsList.Any())
                {
                    return;
                }

                var basePath = basePathsList.FirstOrDefault(p => currentSelectedFilepath.StartsWith(p, StringComparison.OrdinalIgnoreCase)) ??
                               basePathsList.FirstOrDefault(p => p.EndsWith($"{currentSelectedFilepath}\\".Replace("#", null), StringComparison.OrdinalIgnoreCase));

                if (basePath.HasValue())
                {
                    basePathsList.Remove(basePath);
                    basePathsList.Insert(0, basePath);
                }

                var basePaths  = basePathsList.ToArray();
                var repository = new Repository(/*basePath*/);
                var loader     = GetLoaderAgent(basePaths, repository);
                var filterer   = new Filterer(basePaths, repository);
                var form       = new FinderForm(GetTitle(),
                                                GetColor(),
                                                loader,
                                                filterer,
                                                defaultSearchTerm: app.GetSelectedText());

                if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var foundItem = form.GetSelectedItem();
                    FoundItemsBank.Items = filterer.FoundItems;
                    GotoItem(app, basePaths, foundItem);
                }

                else
                {
                    app.StatusBar.Text = "Ready ...";
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
            }
        }
        async void OpenInMSharpMenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var url = await GeeksAddin.Utils.FindMSharpProjectUrl(App.DTE);

                var properPath = GetProperFilePathCapitalization(App.DTE.ActiveDocument.FullName);
                url = BuildCompleteUrl(url, properPath);
                Process.Start(url);
            }
            catch (Exception err)
            {
                ErrorNotification.EmailError(err);
            }
        }
Exemple #9
0
        public override void Run(DTE2 app)
        {
            try
            {
                if (app.ActiveDocument == null)
                {
                    app.StatusBar.Text = "No Active Document";
                    return;
                }

                var thisFile     = app.ActiveDocument.FullName;
                var thisFilePath = Path.GetDirectoryName(thisFile);
                var otherFile    = "";

                if (thisFile.Contains("\\Test\\@Logic\\") && thisFile.EndsWith("Fixture.cs"))
                {
                    // switch back from Fixture to logic
                    otherFile = FileToggleGadget.GetFixtureFileInModelProject(thisFile);
                }
                else
                {
                    var otherFilePath = thisFilePath.Replace("\\Model\\", "\\Test\\").Replace("\\Entities", "\\@Logic").Replace("\\@Entities", "\\@Logic");
                    otherFile = Path.Combine(
                        otherFilePath,
                        Path.GetFileNameWithoutExtension(thisFile) + "Fixture.cs");
                }

                if (File.Exists(otherFile))
                {
                    app.ExecuteCommand("File.OpenFile", otherFile.WrapInQuatation());
                    return;
                }

                app.StatusBar.Text = "File Not found: " + otherFile;
            }
            catch (Exception err)
            {
                ErrorNotification.EmailError(err);
            }
        }
Exemple #10
0
        public static void Run(ProjectItem item, CodeCleanerType command)
        {
            if (!ActiveDocument.IsValid(item))
            {
                ErrorNotification.EmailError(Resources.PrivateModifierCleanUpFailed);
            }

            else
            {
                var invoker = new CleanerActionInvoker(item);
                switch (command)
                {
                case CodeCleanerType.All:
                    invoker.InvokeAll();
                    break;

                default:
                    invoker.Invoke(command);
                    break;
                }
            }
        }
Exemple #11
0
        public override SyntaxNode CleanUp(SyntaxNode initialSourceNode)
        {
            try
            {
                Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

                var window = ProjectItemDetails.ProjectItem.Open(Constants.vsViewKindCode);
                //window = ProjectItemDetails.ProjectItem.Document.DTE
                //    .ItemOperations.OpenFile(ProjectItemDetails.ProjectItem.Document.Path
                //    , Constants.vsViewKindCode);
                //window.Activate();
                ProjectItemDetails.ProjectItem.Document.Activate();
                ProjectItemDetails.ProjectItem.Document.DTE.ExecuteCommand(UsingsCommands.REMOVE_AND_SORT_COMMAND_NAME);
                ProjectItemDetails.ProjectItem.Document.Save();
                //window.Document.Save();
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }

            return(ProjectItemDetails.ProjectItem.ToSyntaxNode());
        }
Exemple #12
0
        public static void DoCleanup(ProjectItem item, CleanupOptions cleanupOptions, bool fileWindowMustBeOpend = false)
        {
            if (!item.IsCsharpFile() || item.IsCSharpDesignerFile())
            {
                return;
            }

            try
            {
                var path = item.Properties.Item("FullPath").Value.ToString();
                if (path.EndsWithAny(new[] { "AssemblyInfo.cs", "TheApplication.cs" }))
                {
                    return;
                }

                var window = item.Open(Constants.vsViewKindCode);

                window.Activate();

                foreach (var actionTypeItem in cleanupOptions.ActionTypes)
                {
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces)
                    {
                        continue;
                    }
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives)
                    {
                        continue;
                    }

                    CodeCleanerHost.Run(item, actionTypeItem, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces))
                {
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives))
                {
                    window.Document.Close(vsSaveChanges.vsSaveChangesYes);

                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives, cleanupOptions);

                    if (fileWindowMustBeOpend == false)
                    {
                        window = item.Open(Constants.vsViewKindCode);

                        window.Activate();
                    }
                }
                else
                {
                    window.Document.Save();
                }

                if (fileWindowMustBeOpend == false)
                {
                    window.Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }