public EditStringResourceDialog(IResourceFileContent content, string key, string value, bool allowEditKey) : base()
        {
            this.content = content;
            key          = key ?? String.Empty;
            value        = value ?? String.Empty;

            InitializeComponent();

            if (allowEditKey)
            {
                this.Get <TextBox>("key").Validating += this.KeyValidating;
            }
            else
            {
                this.Get <TextBox>("key").ReadOnly = true;
            }

            this.Get <TextBox>("key").Text   = key;
            this.Get <TextBox>("value").Text = value;

            if (allowEditKey)
            {
                this.Get <TextBox>("key").Select();
                this.Get <TextBox>("key").Select(key.Length, 0);
            }
            else
            {
                this.Get <TextBox>("value").Select();
                this.Get <TextBox>("value").Select(value.Length, 0);
            }
        }
        public EditStringResourceDialog(IResourceFileContent content, string key, string value, bool allowEditKey)
            : base()
        {
            this.content = content;
            key = key ?? String.Empty;
            value = value ?? String.Empty;

            InitializeComponent();

            if (allowEditKey) {
                this.Get<TextBox>("key").Validating += this.KeyValidating;
            } else {
                this.Get<TextBox>("key").ReadOnly = true;
            }

            this.Get<TextBox>("key").Text = key;
            this.Get<TextBox>("value").Text = value;

            if (allowEditKey) {
                this.Get<TextBox>("key").Select();
                this.Get<TextBox>("key").Select(key.Length, 0);
            } else {
                this.Get<TextBox>("value").Select();
                this.Get<TextBox>("value").Select(value.Length, 0);
            }
        }
        public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch)
        {
            if (this.CompletionPossible(editor, ch))
            {
                ResourceResolveResult result = ResourceResolverService.Resolve(editor, ch);
                if (result != null)
                {
                    IResourceFileContent content;
                    if ((content = result.ResourceFileContent) != null)
                    {
                        // If the resolved resource set is the local ICSharpCode.Core resource set
                        // (this may happen through the ICSharpCodeCoreNRefactoryResourceResolver),
                        // we will have to merge in the host resource set (if available)
                        // for the code completion window.
                        if (result.ResourceSetReference.ResourceSetName == ICSharpCodeCoreResourceResolver.ICSharpCodeCoreLocalResourceSetName)
                        {
                            IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent;
                            if (hostContent != null)
                            {
                                content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent });
                            }
                        }

                        editor.ShowCompletionWindow(new ResourceCodeCompletionDataProvider(content, this.OutputVisitor, result.CallingClass != null ? result.CallingClass.Name + "." : null), ch);
                        return(true);
                    }
                }
            }

            return(false);
        }
		/// <summary>
		/// Generates the completion items.
		/// </summary>
		private void GenerateCompletionItems(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
		{
			this.Items.Add(new NewResourceCodeCompletionItem(content, outputVisitor, preEnteredName));
			
			foreach (KeyValuePair<string, object> entry in content.Data) {
				this.Items.Add(new ResourceCodeCompletionItem(entry.Key, ResourceResolverService.FormatResourceDescription(content, entry.Key), outputVisitor));
			}
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="ResourceCodeCompletionItemList" /> class.
		/// </summary>
		/// <param name="content">The resource file content to be presented to the user.</param>
		/// <param name="outputVisitor">The NRefactory output visitor to be used to generate the inserted code. If <c>null</c>, the key is inserted literally.</param>
		/// <param name="preEnteredName">The type name which should be pre-entered in the 'add new' dialog box if the user selects the 'add new' entry.</param>
		public ResourceCodeCompletionItemList(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
		{
			if (content == null) {
				throw new ArgumentNullException("content");
			}
			
			this.GenerateCompletionItems(content, outputVisitor, preEnteredName);
		}
        /// <summary>
        /// Generates the completion items.
        /// </summary>
        private void GenerateCompletionItems(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
        {
            this.Items.Add(new NewResourceCodeCompletionItem(content, outputVisitor, preEnteredName));

            foreach (KeyValuePair <string, object> entry in content.Data)
            {
                this.Items.Add(new ResourceCodeCompletionItem(entry.Key, ResourceResolverService.FormatResourceDescription(content, entry.Key), outputVisitor));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceCodeCompletionItemList" /> class.
        /// </summary>
        /// <param name="content">The resource file content to be presented to the user.</param>
        /// <param name="outputVisitor">The NRefactory output visitor to be used to generate the inserted code. If <c>null</c>, the key is inserted literally.</param>
        /// <param name="preEnteredName">The type name which should be pre-entered in the 'add new' dialog box if the user selects the 'add new' entry.</param>
        public ResourceCodeCompletionItemList(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            this.GenerateCompletionItems(content, outputVisitor, preEnteredName);
        }
        // ********************************************************************************************************************************

        /// <summary>
        /// Builds the formatted description string for the specified resource.
        /// </summary>
        public static string FormatResourceDescription(IResourceFileContent content, string key)
        {
            StringBuilder sb = new StringBuilder();

            IMultiResourceFileContent mrfc;

            if (key != null && (mrfc = (content as IMultiResourceFileContent)) != null)
            {
                string file = mrfc.GetFileNameForKey(key);
                if (file == null)
                {
                    file = content.FileName;
                }
                sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.PlaceMessage}"), file);
            }
            else
            {
                sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.PlaceMessage}"), content.FileName);
            }

            sb.AppendLine();
            sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.KeyLabel}"));
            sb.Append(' ');

            if (key != null)
            {
                sb.AppendLine(key);
                sb.AppendLine();
                sb.AppendLine(StringParser.Parse("${res:Hornung.ResourceToolkit.ValueLabel}"));

                object value;
                if (content.TryGetValue(key, out value))
                {
                    if (value is string)
                    {
                        sb.Append(value);
                    }
                    else
                    {
                        sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.TypeMessage}"), value.GetType().ToString());
                        sb.Append(' ');
                        sb.Append(value.ToString());
                    }
                }
                else
                {
                    sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.KeyNotFound}"));
                }
            }
            else
            {
                sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.UnknownKey}"));
            }

            return(sb.ToString());
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="ResourceCodeCompletionDataProvider" /> class.
		/// </summary>
		/// <param name="content">The resource file content to be presented to the user.</param>
		/// <param name="outputVisitor">The NRefactory output visitor to be used to generate the inserted code. If <c>null</c>, the key is inserted literally.</param>
		/// <param name="preEnteredName">The type name which should be pre-entered in the 'add new' dialog box if the user selects the 'add new' entry.</param>
		public ResourceCodeCompletionDataProvider(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
		{
			if (content == null) {
				throw new ArgumentNullException("content");
			}
			this.content = content;
			this.outputVisitor = outputVisitor;
			this.preEnteredName = preEnteredName;
			this.InsertSpace = false;
		}
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceCodeCompletionDataProvider" /> class.
 /// </summary>
 /// <param name="content">The resource file content to be presented to the user.</param>
 /// <param name="outputVisitor">The NRefactory output visitor to be used to generate the inserted code. If <c>null</c>, the key is inserted literally.</param>
 /// <param name="preEnteredName">The type name which should be pre-entered in the 'add new' dialog box if the user selects the 'add new' entry.</param>
 public ResourceCodeCompletionDataProvider(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
 {
     if (content == null)
     {
         throw new ArgumentNullException("content");
     }
     this.content        = content;
     this.outputVisitor  = outputVisitor;
     this.preEnteredName = preEnteredName;
     this.InsertSpace    = false;
 }
        public MergedResourceFileContent(IResourceFileContent masterContent, IResourceFileContent[] otherContents)
        {
            this.masterContent = masterContent;
            this.otherContents = otherContents;

            // Ensure that all contents are for the same culture
            foreach (IResourceFileContent c in this.otherContents) {
                if (!c.Culture.Equals(this.masterContent.Culture)) {
                    throw new ArgumentException("The cultures of the specified resource file contents do not match.");
                }
            }
        }
Exemple #12
0
        public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
        {
            if (ch == ':')
            {
                if (editor.Caret.Offset >= 5 && editor.Document.GetText(editor.Caret.Offset - 5, 5) == "${res")
                {
                    IResourceFileContent content = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent;
                                        #if DEBUG
                    if (content != null)
                    {
                        LoggingService.Debug("ResourceToolkit: Found local ICSharpCode.Core resource file: " + content.FileName);
                    }
                                        #endif

                    IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent;
                    if (hostContent != null)
                    {
                                                #if DEBUG
                        LoggingService.Debug("ResourceToolkit: Found host ICSharpCode.Core resource file: " + hostContent.FileName);
                                                #endif
                        if (content != null)
                        {
                            content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent });
                        }
                        else
                        {
                            content = hostContent;
                        }
                    }

                    if (content != null)
                    {
                        editor.ShowCompletionWindow(new ResourceCodeCompletionItemList(content, null, null));
                        return(CodeCompletionKeyPressResult.Completed);
                    }
                }
            }
            else if (ch == '$')
            {
                // Provide ${res: as code completion
                // in an ICSharpCode.Core application
                if (ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent != null ||
                    ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent != null)
                {
                    editor.ShowCompletionWindow(new ICSharpCodeCoreTagCompletionItemList(editor));
                    return(CodeCompletionKeyPressResult.Completed);
                }
            }

            return(CodeCompletionKeyPressResult.None);
        }
Exemple #13
0
        public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch)
        {
            if (ch == ':')
            {
                if (editor.ActiveTextAreaControl.Caret.Offset >= 5 && editor.Document.GetText(editor.ActiveTextAreaControl.Caret.Offset - 5, 5) == "${res")
                {
                    IResourceFileContent content = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent;
                                        #if DEBUG
                    if (content != null)
                    {
                        LoggingService.Debug("ResourceToolkit: Found local ICSharpCode.Core resource file: " + content.FileName);
                    }
                                        #endif

                    IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent;
                    if (hostContent != null)
                    {
                                                #if DEBUG
                        LoggingService.Debug("ResourceToolkit: Found host ICSharpCode.Core resource file: " + hostContent.FileName);
                                                #endif
                        if (content != null)
                        {
                            content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent });
                        }
                        else
                        {
                            content = hostContent;
                        }
                    }

                    if (content != null)
                    {
                        editor.ShowCompletionWindow(new ResourceCodeCompletionDataProvider(content, null, null), ch);
                        return(true);
                    }
                }
            }
            else if (ch == '$')
            {
                // Provide ${res: as code completion
                // in an ICSharpCode.Core application
                if (ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent != null ||
                    ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent != null)
                {
                    editor.ShowCompletionWindow(new ICSharpCodeCoreTagCompletionDataProvider(), ch);
                    return(true);
                }
            }

            return(false);
        }
Exemple #14
0
        public MergedResourceFileContent(IResourceFileContent masterContent, IResourceFileContent[] otherContents)
        {
            this.masterContent = masterContent;
            this.otherContents = otherContents;

            // Ensure that all contents are for the same culture
            foreach (IResourceFileContent c in this.otherContents)
            {
                if (!c.Culture.Equals(this.masterContent.Culture))
                {
                    throw new ArgumentException("The cultures of the specified resource file contents do not match.");
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Finds all localized resource files that follow the pattern
        /// &lt;<paramref name="fileNameWithoutExtension"/>&gt;.&lt;culture&gt;&lt;<paramref name="extension"/>&gt;.
        /// </summary>
        /// <param name="fileNameWithoutExtension">The full path and name of the master resource file without extension.</param>
        /// <param name="extension">The extension of the master resource file (with leading dot).</param>
        /// <returns>A dictionary of culture names and associated resource file contents.</returns>
        public static IDictionary <string, IResourceFileContent> FindLocalizedResourceFiles(string fileNameWithoutExtension, string extension)
        {
            Dictionary <string, IResourceFileContent> list = new Dictionary <string, IResourceFileContent>();

                        #if DEBUG
            LoggingService.Debug("ResourceToolkit: Finding localized resource files (DefaultFileLocalizedResourcesFinder.FindLocalizedResourceFiles).");
            LoggingService.Debug(" -> fileNameWithoutExtension: '" + fileNameWithoutExtension + "'");
            LoggingService.Debug(" -> extension:                '" + extension + "'");
                        #endif

            foreach (string fileName in Directory.GetFiles(Path.GetDirectoryName(fileNameWithoutExtension), Path.GetFileName(fileNameWithoutExtension) + ".*" + extension))
            {
                                #if DEBUG
                LoggingService.Debug(" -> possible file: '" + fileName + "'");
                                #endif

                string culture = Path.GetExtension(Path.GetFileNameWithoutExtension(fileName));
                                #if DEBUG
                LoggingService.Debug("    -> culture = '" + (culture ?? "<null>") + "'");
                                #endif

                if (!String.IsNullOrEmpty(culture))
                {
                    try {
                        CultureInfo          ci      = CultureInfo.GetCultureInfo(culture.Substring(1));                // need to remove leading dot from culture
                        IResourceFileContent content = ResourceFileContentRegistry.GetResourceFileContent(fileName);
                        if (content != null)
                        {
                                                        #if DEBUG
                            LoggingService.Debug("    -> culture name: '" + ci.Name + "'");
                                                        #endif
                            list.Add(ci.Name, content);
                        }
                    } catch (ArgumentException) {
                        continue;
                    }
                }
            }

            return(list);
        }
Exemple #16
0
        /// <summary>
        /// Deletes the specified resource key in the resource file and all dependent localized
        /// resource files permanently.
        /// </summary>
        /// <param name="fileName">The master resource file that contains the key to be deleted.</param>
        /// <param name="key">The key to be deleted.</param>
        protected static void DeleteResourceKey(string fileName, string key)
        {
            try {
                IResourceFileContent content = ResourceFileContentRegistry.GetResourceFileContent(fileName);
                if (content != null)
                {
                    if (content.ContainsKey(key))
                    {
                        LoggingService.Debug("ResourceToolkit: Remove key '" + key + "' from resource file '" + fileName + "'");
                        content.RemoveKey(key);
                    }
                    else
                    {
                        MessageService.ShowWarningFormatted("${res:Hornung.ResourceToolkit.KeyNotFoundWarning}", key, fileName);
                    }
                }
                else
                {
                    MessageService.ShowWarning("ResoureToolkit: Could not get ResourceFileContent for '" + fileName + "' key +'" + key + "'.");
                }
            } catch (Exception ex) {
                MessageService.ShowWarningFormatted("${res:Hornung.ResourceToolkit.ErrorProcessingResourceFile}" + Environment.NewLine + ex.Message, fileName);
                return;
            }

            foreach (KeyValuePair <string, IResourceFileContent> entry in ResourceFileContentRegistry.GetLocalizedContents(fileName))
            {
                LoggingService.Debug("ResourceToolkit: Looking in localized resource file: '" + entry.Value.FileName + "'");
                try {
                    if (entry.Value.ContainsKey(key))
                    {
                        LoggingService.Debug("ResourceToolkit:   -> Key found, removing.");
                        entry.Value.RemoveKey(key);
                    }
                } catch (Exception ex) {
                    MessageService.ShowWarningFormatted("${res:Hornung.ResourceToolkit.ErrorProcessingResourceFile}" + Environment.NewLine + ex.Message, entry.Value.FileName);
                }
            }
        }
        // ********************************************************************************************************************************

        /// <summary>
        /// Determines the file which contains the resources referenced by the specified manifest resource name.
        /// </summary>
        /// <param name="sourceFileName">The name of the source code file which the reference occurs in.</param>
        /// <param name="resourceName">The manifest resource name to find the resource file for.</param>
        /// <returns>A <see cref="ResourceSetReference"/> with the specified resource set name and the name of the file that contains the resources with the specified manifest resource name, or <c>null</c> if the file name cannot be determined.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="resourceName"/> parameter is <c>null</c>.</exception>
        public static ResourceSetReference GetResourceSetReference(string sourceFileName, string resourceName)
        {
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }

            IProject p = ProjectFileDictionaryService.GetProjectForFile(sourceFileName);

            if (p != null)
            {
                string fileName;

                if ((fileName = TryGetResourceFileNameFromProjectDirect(resourceName, p)) != null)
                {
                    return(new ResourceSetReference(resourceName, fileName));
                }

                // SharpDevelop silently strips the (hard-coded) folder names
                // "src" and "source" when generating the default namespace name
                // for new files.
                // When MSBuild generates the manifest resource names for the
                // forms designer resources, it uses the type name of the
                // first class in the file. So we should find all files
                // that contain a type with the name in resourceName
                // and then look for dependent resource files or resource files
                // with the same name in the same directory as the source files.

                // Find all source files that contain a type with the same
                // name as the resource we are looking for.
                List <string>   possibleSourceFiles = new List <string>();
                IProjectContent pc = ResourceResolverService.GetProjectContent(p);
                if (pc != null)
                {
                    IClass resourceClass = pc.GetClass(resourceName, 0);

                    if (resourceClass != null)
                    {
                        CompoundClass cc = resourceClass.GetCompoundClass() as CompoundClass;

                        foreach (IClass c in (cc == null ? (IList <IClass>) new IClass[] { resourceClass } : cc.Parts))
                        {
                            if (c.CompilationUnit != null && c.CompilationUnit.FileName != null)
                            {
                                                                #if DEBUG
                                LoggingService.Debug("ResourceToolkit: NRefactoryResourceResolver found file '" + c.CompilationUnit.FileName + "' to contain the type '" + resourceName + "'");
                                                                #endif

                                possibleSourceFiles.Add(c.CompilationUnit.FileName);
                            }
                        }
                    }
                }

                foreach (string possibleSourceFile in possibleSourceFiles)
                {
                    string possibleSourceFileName = Path.GetFileName(possibleSourceFile);

                    // Find resource files dependent on these source files.
                    foreach (ProjectItem pi in p.Items)
                    {
                        FileProjectItem fpi = pi as FileProjectItem;
                        if (fpi != null)
                        {
                            if (fpi.DependentUpon != null &&
                                (fpi.ItemType == ItemType.EmbeddedResource || fpi.ItemType == ItemType.Resource || fpi.ItemType == ItemType.None) &&
                                FileUtility.IsEqualFileName(fpi.DependentUpon, possibleSourceFileName))
                            {
                                                                #if DEBUG
                                LoggingService.Debug("ResourceToolkit: NRefactoryResourceResolver trying to use dependent file '" + fpi.FileName + "' as resource file");
                                                                #endif

                                if ((fileName = FindResourceFileName(fpi.FileName)) != null)
                                {
                                    // Prefer culture-invariant resource file
                                    // over localized resource file
                                    IResourceFileContent rfc = ResourceFileContentRegistry.GetResourceFileContent(fileName);
                                    if (rfc.Culture.Equals(CultureInfo.InvariantCulture))
                                    {
                                        return(new ResourceSetReference(resourceName, fileName));
                                    }
                                }
                            }
                        }
                    }

                    // Fall back to any found resource file
                    // if no culture-invariant resource file was found
                    if (fileName != null)
                    {
                        return(new ResourceSetReference(resourceName, fileName));
                    }

                    // Find resource files with the same name as the source file
                    // and in the same directory.
                    if ((fileName = FindResourceFileName(possibleSourceFile)) != null)
                    {
                        return(new ResourceSetReference(resourceName, fileName));
                    }
                }
            }
            else
            {
                                #if DEBUG
                LoggingService.Info("ResourceToolkit: NRefactoryResourceResolver.GetResourceSetReference could not determine the project for the source file '" + (sourceFileName ?? "<null>") + "'.");
                                #endif

                if (sourceFileName != null)
                {
                    // The project could not be determined.
                    // Try a simple file search.

                    string directory    = Path.GetDirectoryName(sourceFileName);
                    string resourcePart = resourceName;
                    string fileName;

                    while (true)
                    {
                                                #if DEBUG
                        LoggingService.Debug("ResourceToolkit: NRefactoryResourceResolver.GetResourceSetReference: looking for a resource file like '" + Path.Combine(directory, resourcePart) + "'");
                                                #endif

                        if ((fileName = FindResourceFileName(Path.Combine(directory, resourcePart.Replace('.', Path.DirectorySeparatorChar)))) != null)
                        {
                            return(new ResourceSetReference(resourceName, fileName));
                        }
                        if ((fileName = FindResourceFileName(Path.Combine(directory, resourcePart))) != null)
                        {
                            return(new ResourceSetReference(resourceName, fileName));
                        }

                        if (resourcePart.Contains("."))
                        {
                            resourcePart = resourcePart.Substring(resourcePart.IndexOf('.') + 1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

                        #if DEBUG
            LoggingService.Info("ResourceToolkit: NRefactoryResourceResolver.GetResourceSetReference is unable to find a suitable resource file for '" + resourceName + "'");
                        #endif

            return(new ResourceSetReference(resourceName, null));
        }
        // ********************************************************************************************************************************
        /// <summary>
        /// Builds the formatted description string for the specified resource.
        /// </summary>
        public static string FormatResourceDescription(IResourceFileContent content, string key)
        {
            StringBuilder sb = new StringBuilder();

            IMultiResourceFileContent mrfc;
            if (key != null && (mrfc = (content as IMultiResourceFileContent)) != null) {
                string file = mrfc.GetFileNameForKey(key);
                if (file == null) {
                    file = content.FileName;
                }
                sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.PlaceMessage}"), file);
            } else {
                sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.PlaceMessage}"), content.FileName);
            }

            sb.AppendLine();
            sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.KeyLabel}"));
            sb.Append(' ');

            if (key != null) {

                sb.AppendLine(key);
                sb.AppendLine();
                sb.AppendLine(StringParser.Parse("${res:Hornung.ResourceToolkit.ValueLabel}"));

                object value;
                if (content.TryGetValue(key, out value)) {
                    if (value is string) {
                        sb.Append(value);
                    } else {
                        sb.AppendFormat(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.TypeMessage}"), value.GetType().ToString());
                        sb.Append(' ');
                        sb.Append(value.ToString());
                    }
                } else {
                    sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.KeyNotFound}"));
                }

            } else {
                sb.Append(StringParser.Parse("${res:Hornung.ResourceToolkit.ToolTips.UnknownKey}"));
            }

            return sb.ToString();
        }
		public NewResourceCodeCompletionData(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
			: base(StringParser.Parse("${res:Hornung.ResourceToolkit.CodeCompletion.AddNewEntry}"), String.Format(CultureInfo.CurrentCulture, StringParser.Parse("${res:Hornung.ResourceToolkit.CodeCompletion.AddNewDescription}"), content.FileName), outputVisitor)
		{
			this.content = content;
			this.preEnteredName = preEnteredName;
		}
Exemple #20
0
 public NewResourceCodeCompletionData(IResourceFileContent content, IOutputAstVisitor outputVisitor, string preEnteredName)
     : base(StringParser.Parse("${res:Hornung.ResourceToolkit.CodeCompletion.AddNewEntry}"), String.Format(CultureInfo.CurrentCulture, StringParser.Parse("${res:Hornung.ResourceToolkit.CodeCompletion.AddNewDescription}"), content.FileName), outputVisitor)
 {
     this.content        = content;
     this.preEnteredName = preEnteredName;
 }
Exemple #21
0
        /// <summary>
        /// Fills the list view with all unused resource keys that match the current filter.
        /// </summary>
        void FillListViewInternal()
        {
            Application.DoEvents();
            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try {
                this.ListView.Items.Clear();
                this.ListView.Groups.Clear();
                // Suspend sorting to improve performance
                System.Collections.IComparer comparer = this.ListView.ListViewItemSorter;
                this.ListView.ListViewItemSorter = null;
                this.ListView.BeginUpdate();

                Dictionary <string, ListViewGroup> fileGroups = new Dictionary <string, ListViewGroup>();

                // Create the ListViewItems.
                foreach (ResourceItem entry in this.UnusedKeys)
                {
                    // Skip if any filter rejects this item.
                    if (!this.ItemMatchesCurrentFilter(entry))
                    {
                        continue;
                    }

                    IResourceFileContent c = ResourceFileContentRegistry.GetResourceFileContent(entry.FileName);
                    object o;

                    // only add the file name to save space
                    // and show the full path as tooltip
                    ListViewItem item = new ListViewItem(Path.GetFileName(entry.FileName));
                    item.ToolTipText = entry.FileName;
                    item.SubItems.Add(entry.Key);
                    if (c.TryGetValue(entry.Key, out o))
                    {
                        item.SubItems.Add((o ?? (object)"<<null>>").ToString());
                    }
                    else
                    {
                        throw new InvalidOperationException("The key '" + entry.Key + "' in file '" + entry.FileName + "' does not exist although it was reported as unused.");
                    }

                    // Use ListViewGroups to group by file names
                    ListViewGroup grp;
                    if (!fileGroups.TryGetValue(entry.FileName, out grp))
                    {
                        grp = new ListViewGroup(entry.FileName);
                        fileGroups.Add(entry.FileName, grp);
                        this.ListView.Groups.Add(grp);
                    }
                    grp.Items.Add(item);

                    this.ListView.Items.Add(item);
                }

                this.ListView.ListViewItemSorter = comparer;
                this.ListView.EndUpdate();
            } finally {
                this.fillListViewQueued = false;
                Cursor.Current          = oldCursor;
            }
        }