예제 #1
0
        /// <summary>
        /// Starts the command
        /// </summary>
        public override void Run()
        {
            ITextEditor editor = SD.GetActiveViewContentService <ITextEditor>();

            if (editor == null)
            {
                return;
            }

            int beginLine = 1;
            int endLine   = editor.Document.LineCount;

            if (editor.SelectionLength != 0)
            {
                beginLine = editor.Document.GetLineByOffset(editor.SelectionStart).LineNumber;
                endLine   = editor.Document.GetLineByOffset(editor.SelectionStart + editor.SelectionLength).LineNumber;
            }

            using (editor.Document.OpenUndoGroup())
                editor.Language.FormattingStrategy.IndentLines(editor, beginLine, endLine);
        }
        /// <summary>
        /// Starts the command
        /// </summary>
        public override void Run()
        {
            ITextEditor editor = SD.GetActiveViewContentService <ITextEditor>();

            if (editor == null)
            {
                return;
            }

            CodeSnippetGroup group = SnippetManager.Instance.FindGroup(Path.GetExtension(editor.FileName));

            if (group == null)
            {
                return;
            }

            DefaultCompletionItemList list = new DefaultCompletionItemList();

            list.Items.AddRange(group.Snippets.Where(i => i.HasSelection).Select(item => item.CreateCompletionItem(editor)));

            new CodeSnippetCompletionWindow(editor, list).Show();
        }
        public override void Run()
        {
            ITextEditor    editor         = SD.GetActiveViewContentService <ITextEditor>();
            FoldingManager foldingManager = editor.GetService(typeof(FoldingManager)) as FoldingManager;

            if (foldingManager != null)
            {
                bool doFold = true;
                foreach (FoldingSection fm in foldingManager.AllFoldings)
                {
                    if (fm.IsFolded)
                    {
                        doFold = false;
                        break;
                    }
                }
                foreach (FoldingSection fm in foldingManager.AllFoldings)
                {
                    fm.IsFolded = doFold;
                }
            }
        }
예제 #4
0
 ITextEditor GetEditor()
 {
     return(SD.GetActiveViewContentService <ITextEditor>());
 }
예제 #5
0
        public virtual IEnumerable <FileName> GenerateFileList()
        {
            List <FileName> files = new List <FileName>();

            ITextEditor editor;

            switch (Target)
            {
            case SearchTarget.CurrentDocument:
            case SearchTarget.CurrentSelection:
                editor = SD.GetActiveViewContentService <ITextEditor>();
                if (editor != null)
                {
                    files.Add(editor.FileName);
                }
                break;

            case SearchTarget.AllOpenFiles:
                foreach (var vc in SD.Workbench.ViewContentCollection)
                {
                    editor = vc.GetService <ITextEditor>();
                    if (editor != null)
                    {
                        files.Add(editor.FileName);
                    }
                }
                break;

            case SearchTarget.WholeProject:
                if (ProjectService.CurrentProject == null)
                {
                    break;
                }
                foreach (FileProjectItem item in ProjectService.CurrentProject.Items.OfType <FileProjectItem>())
                {
                    files.Add(item.FileName);
                }
                break;

            case SearchTarget.WholeSolution:
                if (ProjectService.OpenSolution == null)
                {
                    break;
                }
                foreach (var item in ProjectService.OpenSolution.AllItems.OfType <ISolutionFileItem>())
                {
                    files.Add(item.FileName);
                }
                foreach (var item in ProjectService.OpenSolution.Projects.SelectMany(p => p.Items).OfType <FileProjectItem>())
                {
                    files.Add(item.FileName);
                }
                break;

            case SearchTarget.Directory:
                if (!Directory.Exists(BaseDirectory))
                {
                    break;
                }
                var options = SearchSubdirs ? DirectorySearchOptions.IncludeSubdirectories : DirectorySearchOptions.None;
                return(SD.FileSystem.GetFiles(DirectoryName.Create(BaseDirectory), Filter, options));

            default:
                throw new Exception("Invalid value for FileListType");
            }

            return(files.Distinct());
        }
예제 #6
0
        public override void Run()
        {
            // Here an example that shows how to access the current text document:

            var textEditor = SD.GetActiveViewContentService <ITextEditor>();

            if (textEditor == null)
            {
                // active content is not a text editor control
                return;
            }
            if (textEditor.SelectionLength == 0)
            {
                return;
            }
            // get the selected text:
            string text = textEditor.SelectedText;

            string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location),
                                            "../../../..");
            string resxFile = Path.Combine(sdSrcPath, "../data/Resources/StringResources.resx");

            using (ResXResourceReader r = new ResXResourceReader(resxFile)) {
                IDictionaryEnumerator en = r.GetEnumerator();
                // Goes through the enumerator, printing out the key and value pairs.
                while (en.MoveNext())
                {
                    if (object.Equals(en.Value, text))
                    {
                        SetText(textEditor, en.Key.ToString(), text);
                        return;
                    }
                }
            }

            string resourceName = MessageService.ShowInputBox("Add Resource", "Please enter the name for the new resource.\n" +
                                                              "This should be a namespace-like construct, please see what the names of resources in the same component are.", SD.PropertyService.Get("ResourceToolLastResourceName", ""));

            if (resourceName == null || resourceName.Length == 0)
            {
                return;
            }
            PropertyService.Set("ResourceToolLastResourceName", resourceName);

            string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", "");

            if (purpose == null)
            {
                return;
            }

            SetText(textEditor, resourceName, text);

            string           path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug"));
            ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe",
                                                         "\"" + resourceName + "\" "
                                                         + "\"" + text + "\" "
                                                         + "\"" + purpose + "\"");

            info.WorkingDirectory = path;
            try {
                Process.Start(info);
            } catch (Exception ex) {
                MessageService.ShowException(ex, "Error starting " + info.FileName);
            }
        }
        public string ProvideString(string tag)
        {
            switch (tag)
            {
            case "TaskService.Warnings":
                return(TaskService.GetCount(TaskType.Warning).ToString());

            case "TaskService.Errors":
                return(TaskService.GetCount(TaskType.Error).ToString());

            case "TaskService.Messages":
                return(TaskService.GetCount(TaskType.Message).ToString());

            case "CurrentProjectName":
                if (ProjectService.CurrentProject == null)
                {
                    return("<no current project>");
                }
                else
                {
                    return(ProjectService.CurrentProject.Name);
                }
            }
            switch (tag.ToUpperInvariant())
            {
            case "ITEMPATH":
                try {
                    return(GetCurrentItemPath() ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "ITEMDIR":
                try {
                    return(Path.GetDirectoryName(GetCurrentItemPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "ITEMFILENAME":
                try {
                    return(Path.GetFileName(GetCurrentItemPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "ITEMEXT":
                try {
                    return(Path.GetExtension(GetCurrentItemPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "ITEMNAMENOEXT":
                try {
                    return(Path.GetFileNameWithoutExtension(GetCurrentItemPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "CURLINE":
            {
                IPositionable positionable = SD.GetActiveViewContentService <IPositionable>();
                if (positionable != null)
                {
                    return(positionable.Line.ToString());
                }
                return(string.Empty);
            }

            case "CURCOL":
            {
                IPositionable positionable = SD.GetActiveViewContentService <IPositionable>();
                if (positionable != null)
                {
                    return(positionable.Column.ToString());
                }
                return(string.Empty);
            }

            case "CURTEXT":
            {
                ITextEditor editor = SD.GetActiveViewContentService <ITextEditor>();
                if (editor != null)
                {
                    return(editor.SelectedText);
                }
                return(string.Empty);
            }

            case "TARGETPATH":
                try {
                    return(GetCurrentTargetPath() ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "TARGETDIR":
                try {
                    return(Path.GetDirectoryName(GetCurrentTargetPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "TARGETNAME":
                try {
                    return(Path.GetFileName(GetCurrentTargetPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "TARGETEXT":
                try {
                    return(Path.GetExtension(GetCurrentTargetPath()) ?? string.Empty);
                } catch (Exception) {}
                return(string.Empty);

            case "PROJECTDIR":
                if (ProjectService.CurrentProject != null)
                {
                    return(ProjectService.CurrentProject.Directory);
                }
                return(string.Empty);

            case "PROJECTFILENAME":
                if (ProjectService.CurrentProject != null)
                {
                    try {
                        return(Path.GetFileName(ProjectService.CurrentProject.FileName));
                    } catch (Exception) {}
                }
                return(string.Empty);

            case "COMBINEDIR":
            case "SOLUTIONDIR":
                return(Path.GetDirectoryName(ProjectService.OpenSolution.FileName));

            case "SOLUTIONFILENAME":
            case "COMBINEFILENAME":
                try {
                    return(Path.GetFileName(ProjectService.OpenSolution.FileName));
                } catch (Exception) {}
                return(string.Empty);

            case "SHARPDEVELOPBINPATH":
                return(Path.GetDirectoryName(typeof(SharpDevelopStringTagProvider).Assembly.Location));

            case "STARTUPPATH":
                return(Application.StartupPath);

            default:
                return(null);
            }
        }