summaryrefslogtreecommitdiffstats
blob: a35e253865fad26a14f2565d08b0e8bd050d3782 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright (c) 2012 Maciej Niedzielski
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2014-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <string>
#include <vector>

#include <boost/signals2.hpp>

#include <Swift/Controllers/HighlightRule.h>

namespace Swift {

    class SettingsProvider;
    class Highlighter;

    class HighlightManager {
        public:

            class HighlightRulesList {
            public:
                friend class HighlightManager;
                size_t getSize() const { return list_.size(); }
                const HighlightRule& getRule(const size_t index) const { return list_[index]; }
                void addRule(const HighlightRule& rule) { list_.push_back(rule); }
                void combineRules(const HighlightRulesList& rhs) {
                    list_.insert(list_.end(), rhs.list_.begin(), rhs.list_.end());
                }
                void setRule(const size_t index, const HighlightRule& rule) {
                    list_[index] = rule;
                }
            private:
                std::vector<HighlightRule> list_;
            };

            HighlightManager(SettingsProvider* settings);

            Highlighter* createHighlighter();

            std::shared_ptr<const HighlightManager::HighlightRulesList> getRules() const { return rules_; }

            bool isDefaultRulesList() const;
            void resetToDefaultRulesList();

            HighlightRule getRule(int index) const;
            void setRule(int index, const HighlightRule& rule);
            void insertRule(int index, const HighlightRule& rule);
            void removeRule(int index);
            void swapRules(const size_t first, const size_t second);
            void storeSettings();
            void loadSettings();

            boost::signals2::signal<void (const HighlightAction&)> onHighlight;

        private:
            void handleSettingChanged(const std::string& settingPath);

            std::string rulesToString() const;
            static std::vector<HighlightRule> getDefaultRules();

        private:
            SettingsProvider* settings_;
            bool storingSettings_;

            std::shared_ptr<HighlightManager::HighlightRulesList> rules_;
            boost::signals2::scoped_connection handleSettingChangedConnection_;
    };

    typedef std::shared_ptr<const HighlightManager::HighlightRulesList> HighlightRulesListPtr;

}