File indexing completed on 2024-03-24 16:41:27
0001 /************************************************************************** 0002 * Copyright (C) 2009-2010 by Michel Ludwig (michel.ludwig@kdemail.net) * 0003 ***************************************************************************/ 0004 0005 /************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #ifndef ABBREVIATIONMANAGER_H 0015 #define ABBREVIATIONMANAGER_H 0016 0017 #include <QMap> 0018 #include <QObject> 0019 #include <QPair> 0020 #include <QString> 0021 0022 #include <KConfig> 0023 0024 class KileInfo; 0025 0026 namespace KileAbbreviation { 0027 0028 typedef QPair<QString, bool> StringBooleanPair; 0029 typedef QMap<QString, StringBooleanPair> AbbreviationMap; 0030 0031 /** 0032 * This manager class is responsible for handling abbreviations. 0033 **/ 0034 class Manager : public QObject { 0035 Q_OBJECT 0036 0037 public: 0038 /** 0039 * Constructs a new manager object. 0040 **/ 0041 explicit Manager(KileInfo* kileInfo, QObject *parent = Q_NULLPTR); 0042 virtual ~Manager(); 0043 0044 // the boolean value is 'true' iff the abbreviation is global 0045 const AbbreviationMap& getAbbreviationMap(); 0046 0047 void readAbbreviationFiles(); 0048 void saveLocalAbbreviations(); 0049 0050 void updateLocalAbbreviation(const QString& text, const QString& replacement); 0051 void removeLocalAbbreviation(const QString& text); 0052 0053 static inline bool isLocalAbbreviation(const StringBooleanPair& p) 0054 { 0055 return !p.second; 0056 } 0057 0058 static inline bool isGlobalAbbreviation(const StringBooleanPair& p) 0059 { 0060 return p.second; 0061 } 0062 0063 static inline StringBooleanPair createGlobalAbbreviationPair(const QString& s) 0064 { 0065 return StringBooleanPair(s, true); 0066 } 0067 0068 static inline StringBooleanPair createLocalAbbreviationPair(const QString& s) 0069 { 0070 return StringBooleanPair(s, false); 0071 } 0072 0073 /** 0074 * Returns the replacement strings of those strings that start with 'text'. 0075 **/ 0076 QStringList getAbbreviationTextMatches(const QString& text) const; 0077 0078 /** 0079 * Returns the replacement string for 'text'; an empty string is returned 0080 * is 'text' is not found 0081 **/ 0082 QString getAbbreviationTextMatch(const QString& text) const; 0083 0084 /** 0085 * Returns true iff there exists an abbreviation which starts with 'text'. 0086 **/ 0087 bool abbreviationStartsWith(const QString& text) const; 0088 0089 bool isAbbreviationDefined(const QString& text) const; 0090 0091 Q_SIGNALS: 0092 void abbreviationsChanged(); 0093 0094 protected: 0095 KileInfo *m_kileInfo; 0096 bool m_abbreviationsDirty; 0097 QString m_localAbbreviationFile; 0098 AbbreviationMap m_abbreviationMap; 0099 0100 void addAbbreviationListToMap(const QStringList& list, bool global); 0101 }; 0102 0103 0104 } 0105 0106 #endif