AntonyCorbett / JWLMerge

Utility to merge jwlibrary backup files
MIT License
194 stars 33 forks source link

Remove Highlights from Specific Publications #42

Closed owebeewan closed 3 years ago

owebeewan commented 3 years ago

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like I'd like an interface (or property file option) to remove yellow user marks from a specific publication type, such as "w", but not "nwt" or "nwtsty".

The use case is that once I study a WT, I don't want the clutter of old user marks in those older WT's and study publications. However, I DO want to retain marks in bibles and books where they are associated with notes.

Another related request is that I wish to delete all YELLOW user marks not associated with a note in a publication type. The reasoning here is that I may mark an answer in yellow (and not make a note) or I may create a note with a BLUE user mark, which I want to keep. I want to remove all YELLOW user marks in this case. Color can be a configurable option.

Describe alternatives you've considered I went into the JWLMerge code base and performed the operation to remove yellow user marks not attached to notes but I did it outside your structure. I merged and everything resulted as I wanted it. I am proposing a declarative solution for various publications. The code I used for my purposes is here:

    private HashSet<int> GetUserMarkIdsInUse()
    {
        var newUserMarkList = new List<UserMark>();
        var result = new HashSet<int>();

        //ADDED WW 3/28/2021 to remove yellow highlighting in bible not attached to notes
        var userMarkIdsWithNotes = _database.Notes.Where(n => n.UserMarkId.HasValue).Select(n => n.UserMarkId.Value).ToHashSet();
        var publicationByLocationId = _database.Locations.ToDictionary(l => l.LocationId, l => l.KeySymbol);

        foreach (var userMark in _database.UserMarks)
        {
            // if not yellow, keep it
            if (userMark.ColorIndex != 1)
            {
                result.Add(userMark.UserMarkId);
                newUserMarkList.Add(userMark);
                continue;
            }

            // if it has a note, keep it
            if (userMarkIdsWithNotes.Contains(userMark.UserMarkId))
            {
                result.Add(userMark.UserMarkId);
                newUserMarkList.Add(userMark);
                continue;
            }

            // if it is not in a bible, keep it. 
            var pub = publicationByLocationId[userMark.LocationId];
            if (!(pub == "nwt" || pub == "nwtsty"))
            {
                result.Add(userMark.UserMarkId);
                newUserMarkList.Add(userMark);
                continue;
            }
        }

        // you're not going to like this but it's fine for my purposes
        _database.UserMarks = newUserMarkList;
        return result;
    }

Additional context A UI idea here might be a page that lists the set of all key symbols in all Locations in the DB. Let the user check which symbols (i.e. publication types) they want to target.

AntonyCorbett commented 3 years ago

@owebeewan There is a new function to remove underlining (and associated notes) by publication and color. See the latest pre-release (v1..0.5)

githubllff commented 3 years ago

@AntonyCorbett . Good work as always. UI works well. Seems to work well with one exception. It does as described and removes the note if associated with an underlining. But it leaves notes for publications if it is not associated with an underline. For example a note on a paragraph, heading etc. If you need screenshots please let me know.