コード例 #1
0
        private string AddFileNameListItem(string fileName, ref Gdk.Pixbuf image)
        {
            image = null;
            Listview.ItemPadding = 6; // Restore padding if we have images to display

            List <string> resourceNames = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames().ToList();

            List <string> images = resourceNames.FindAll(r => r.EndsWith(".svg"));

            images.AddRange(resourceNames.FindAll(r => r.Contains(".LargeImages.")));

            string result     = $"<span>{Path.GetFileName(fileName)}</span>\n<small><i><span>{Path.GetDirectoryName(fileName)}</span></i></small>";
            string searchName = Path.GetFileNameWithoutExtension(fileName);

            (bool exists, string resourceName) = ExplorerPresenter.CheckIfIconExists(searchName);
            if (exists)
            {
                image = new Gdk.Pixbuf(null, resourceName);
            }
            else
            {
                // Add an image index.
                foreach (string imageName in images)
                {
                    string[] parts          = imageName.Split('.');
                    string   shortImageName = parts.Length > 1 ? parts[parts.Length - 2] : StringUtilities.GetAfter(imageName, ".LargeImages.").Replace(".png", "");
                    if (result.ToLower().Contains(shortImageName.ToLower()))
                    {
                        image = new Gdk.Pixbuf(null, imageName);
                        break;
                    }
                }
            }
            if (image == null)
            {
                image = new Gdk.Pixbuf(null, "ApsimNG.Resources.apsim logo32.png");
            }

            return(result);
        }