Skip to content

Commit

Permalink
fix: skip sets by name during import (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Nov 18, 2024
1 parent e34ea72 commit bf78979
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ui/include/highlighterset.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class HighlighterSetCollection final : public Persistable<HighlighterSetCollecti
HighlighterSet currentActiveSet() const;

bool hasSet( const QString& setId ) const;
bool hasSetByName( const QString& name ) const;

QStringList activeSetIds() const;
void activateSet( const QString& setId );
Expand Down
10 changes: 8 additions & 2 deletions src/ui/src/highlightersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,21 @@ void HighlightersDialog::importHighlighters()
this, tr( "Select one or more files to open" ), "", tr( "Highlighters (*.conf)" ) );

for ( const auto& file : files ) {
LOG_DEBUG << "Loading highlighters from " << file;
LOG_INFO << "Loading highlighters from " << file;
QSettings settings{ file, QSettings::IniFormat };
HighlighterSetCollection collection;
collection.retrieveFromStorage( settings );
for ( const auto& set : klogg::as_const( collection.highlighters_ ) ) {
if ( highlighterSetCollection_.hasSet( set.id() ) ) {
if ( highlighterSetCollection_.hasSet( set.id() )
|| highlighterSetCollection_.hasSetByName( set.name() ) ) {

LOG_INFO << "Skipping set " << set.name() << " (" << set.id() << ")";

continue;
}

LOG_INFO << "Adding set " << set.name() << " (" << set.id() << ")";

highlighterSetCollection_.highlighters_.append( set );
highlighterListWidget->addItem( set.name() );
}
Expand Down
6 changes: 6 additions & 0 deletions src/ui/src/highlighterset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ bool HighlighterSetCollection::hasSet( const QString& setId ) const
[ setId ]( const auto& s ) { return s.id() == setId; } );
}

bool HighlighterSetCollection::hasSetByName( const QString& setName ) const
{
return std::any_of( highlighters_.begin(), highlighters_.end(),
[ setName ]( const auto& s ) { return s.name() == setName; } );
}

QList<QuickHighlighter> HighlighterSetCollection::quickHighlighters() const
{
return quickHighlighters_;
Expand Down

0 comments on commit bf78979

Please sign in to comment.