本文整理汇总了C#中ITextBuffer.GetFilename方法的典型用法代码示例。如果您正苦于以下问题:C# ITextBuffer.GetFilename方法的具体用法?C# ITextBuffer.GetFilename怎么用?C# ITextBuffer.GetFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextBuffer
的用法示例。
在下文中一共展示了ITextBuffer.GetFilename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateConfiguration
//=====================================================================
/// <summary>
/// Generate the configuration to use when spell checking the given text buffer
/// </summary>
/// <param name="buffer">The text buffer for which to generate a configuration</param>
/// <returns>The generated configuration to use</returns>
/// <remarks>The configuration is a merger of the global settings plus any solution, project, folder, and
/// file settings related to the text buffer.</remarks>
private SpellCheckerConfiguration GenerateConfiguration(ITextBuffer buffer)
{
ProjectItem projectItem, fileItem;
string bufferFilename, filename, projectPath, projectFilename = null;
// Start with the global configuration
var config = new SpellCheckerConfiguration();
try
{
config.Load(SpellingConfigurationFile.GlobalConfigurationFilename);
var dte2 = (globalServiceProvider == null) ? null :
globalServiceProvider.GetService(typeof(SDTE)) as DTE2;
if(dte2 != null && dte2.Solution != null && !String.IsNullOrWhiteSpace(dte2.Solution.FullName))
{
var solution = dte2.Solution;
// Clear the global dictionary cache when a change in solution is detected. This handles
// cases where only the MEF components are loaded and not the package (i.e. a configuration
// has not been edited). See VSSpellCheckerPackage.solutionEvents_AfterClosing().
if(lastSolutionName == null || !lastSolutionName.Equals(solution.FullName,
StringComparison.OrdinalIgnoreCase))
{
GlobalDictionary.ClearDictionaryCache();
lastSolutionName = solution.FullName;
}
// See if there is a solution configuration
filename = solution.FullName + ".vsspell";
projectItem = solution.FindProjectItem(filename);
if(projectItem != null)
config.Load(filename);
// Find the project item for the file we are opening
bufferFilename = buffer.GetFilename();
projectItem = (bufferFilename != null) ? solution.FindProjectItem(bufferFilename) : null;
if(projectItem != null)
{
fileItem = projectItem;
// If we have a project (we should), see if it has settings
if(projectItem.ContainingProject != null &&
!String.IsNullOrWhiteSpace(projectItem.ContainingProject.FullName))
{
projectFilename = projectItem.ContainingProject.FullName;
filename = projectFilename + ".vsspell";
projectItem = solution.FindProjectItem(filename);
if(projectItem != null)
config.Load(filename);
// Get the full path based on the project. The buffer filename will refer to the actual
// path which may be to a linked file outside the project's folder structure.
projectPath = Path.GetDirectoryName(filename);
filename = Path.GetDirectoryName((string)fileItem.Properties.Item("FullPath").Value);
// Search for folder-specific configuration files
if(filename.StartsWith(projectPath, StringComparison.OrdinalIgnoreCase))
{
// Then check subfolders. No need to check the root folder as the project
// settings cover it.
if(filename.Length > projectPath.Length)
foreach(string folder in filename.Substring(projectPath.Length + 1).Split('\\'))
{
projectPath = Path.Combine(projectPath, folder);
filename = Path.Combine(projectPath, folder + ".vsspell");
projectItem = solution.FindProjectItem(filename);
if(projectItem != null)
config.Load(filename);
}
}
// If the item looks like a dependent file item, look for a settings file related to
// the parent file item.
if(fileItem.Collection != null && fileItem.Collection.Parent != null)
{
projectItem = fileItem.Collection.Parent as ProjectItem;
if(projectItem != null && projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
{
filename = (string)projectItem.Properties.Item("FullPath").Value + ".vsspell";
projectItem = solution.FindProjectItem(filename);
if(projectItem != null)
config.Load(filename);
}
}
//.........这里部分代码省略.........