Пример #1
0
        // This is called to perform a search (and replace)
        // Returns a list of items to show in the results list
        // replacewith is null when not replacing
        public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
        {
            List <FindReplaceObject> objs = new List <FindReplaceObject>();

            // Interpret the replacement
            if (replace && (string.IsNullOrEmpty(replacewith) || replacewith.Length > General.Map.Config.MaxTextureNameLength))
            {
                MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(objs.ToArray());
            }

            // Interpret the find
            bool isregex           = (value.IndexOf('*') != -1 || value.IndexOf('?') != -1);   //mxd
            MatchingTextureSet set = new MatchingTextureSet(new Collection <string> {
                value.Trim()
            });                                                                                                   //mxd

            // Where to search?
            ICollection <Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors;

            // Go for all sectors
            foreach (Sector s in list)
            {
                // Flat matches?
                if (set.IsMatch(s.CeilTexture))
                {
                    // Replace and add to list
                    if (replace)
                    {
                        s.SetCeilTexture(replacewith);
                    }
                    objs.Add(new FindReplaceObject(s, "Sector " + s.Index + " (ceiling)" + (isregex ? " - " + s.CeilTexture : null)));
                }

                if (set.IsMatch(s.FloorTexture))
                {
                    // Replace and add to list
                    if (replace)
                    {
                        s.SetFloorTexture(replacewith);
                    }
                    objs.Add(new FindReplaceObject(s, "Sector " + s.Index + " (floor)" + (isregex ? " - " + s.FloorTexture : null)));
                }
            }

            // When replacing, make sure we keep track of used textures
            if (replace)
            {
                General.Map.Data.UpdateUsedTextures();
                General.Map.Map.Update();                 //mxd. And don't forget to update the view itself
                General.Map.IsChanged = true;
            }

            return(objs.ToArray());
        }
        // This is called to perform a search (and replace)
        // Returns a list of items to show in the results list
        // replacewith is null when not replacing
        public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
        {
            List <FindReplaceObject> objs = new List <FindReplaceObject>();

            // Interpret the replacement
            if (replace && (string.IsNullOrEmpty(replacewith) || replacewith.Length > General.Map.Config.MaxTextureNameLength))
            {
                MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(objs.ToArray());
            }

            // Interpret the find
            bool isregex           = (value.IndexOf('*') != -1 || value.IndexOf('?') != -1);   //mxd
            MatchingTextureSet set = new MatchingTextureSet(new Collection <string> {
                value.Trim()
            });                                                                                                   //mxd

            // Where to search?
            ICollection <Sidedef> sidelist = withinselection ? General.Map.Map.GetSidedefsFromSelectedLinedefs(true) : General.Map.Map.Sidedefs;

            // Go for all sidedefs
            foreach (Sidedef sd in sidelist)
            {
                if (set.IsMatch(sd.MiddleTexture) && (value != "-" || sd.MiddleRequired()))
                {
                    // Replace and add to list
                    if (replace)
                    {
                        sd.SetTextureMid(replacewith);
                    }
                    objs.Add(new FindReplaceObject(sd, "Sidedef " + sd.Index + " (" + (sd.IsFront ? "front" : "back") + ", middle)" + (isregex ? " - " + sd.MiddleTexture : null)));
                }
            }

            // When replacing, make sure we keep track of used textures
            if (replace)
            {
                General.Map.Data.UpdateUsedTextures();
            }

            return(objs.ToArray());
        }
Пример #3
0
        // This removes empty items and makes others uppercase
        private void filterstimer_Tick(object sender, EventArgs e)
        {
            // Stop timer
            filterstimer.Stop();

            // Update labels
            for (int i = filters.Items.Count - 1; i >= 0; i--)
            {
                // Empty label?
                if ((filters.Items[i].Text == null) ||
                    (filters.Items[i].Text.Trim().Length == 0))
                {
                    // Remove it
                    filters.Items.RemoveAt(i);
                }
                else
                {
                    // Make uppercase
                    filters.Items[i].Text = filters.Items[i].Text.ToUpperInvariant();
                }
            }

            // Show example results if when we can
            if (General.Map != null)
            {
                Cursor.Current = Cursors.AppStarting;

                // Make a set for comparing
                List <string> filterslist = new List <string>(filters.Items.Count);
                foreach (ListViewItem i in filters.Items)
                {
                    filterslist.Add(i.Text);
                }
                MatchingTextureSet set = new MatchingTextureSet(filterslist);

                // Determine tooltip text
                string tooltiptext = null;
                if (nomatchesbutton.Checked)
                {
                    tooltiptext = "Double-click to include this texture";
                }

                // Start adding
                matcheslist.PreventSelection = matchesbutton.Checked;
                matcheslist.BeginAdding(true);

                // Go for all textures
                foreach (ImageData img in General.Map.Data.Textures)
                {
                    bool ismatch = set.IsMatch(img);
                    if ((ismatch && matchesbutton.Checked) || (!ismatch && nomatchesbutton.Checked))
                    {
                        matcheslist.AddItem(img, tooltiptext);
                    }
                }

                // If not already mixed, add flats as well
                if (!General.Map.Config.MixTexturesFlats)
                {
                    // Go for all flats
                    foreach (ImageData img in General.Map.Data.Flats)
                    {
                        bool ismatch = set.IsMatch(img);
                        if ((ismatch && matchesbutton.Checked) || (!ismatch && nomatchesbutton.Checked))
                        {
                            matcheslist.AddItem(img, tooltiptext);
                        }
                    }
                }

                // Done adding
                matcheslist.EndAdding();
                Cursor.Current = Cursors.Default;
            }
        }