Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/sfx2/sidebar/ResourceManager.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
#pragma once
20
21
#include <map>
22
#include <memory>
23
#include <vector>
24
#include <set>
25
26
#include <sfx2/dllapi.h>
27
#include <rtl/ustring.hxx>
28
29
namespace com::sun::star::frame { class XController; }
30
namespace com::sun::star::frame { class XModel; }
31
namespace com::sun::star::uno { template <class interface_type> class Reference; }
32
namespace sfx2::sidebar { class DeckDescriptor; }
33
namespace sfx2::sidebar { class PanelDescriptor; }
34
namespace utl { class OConfigurationNode; }
35
namespace utl { class OConfigurationTreeRoot; }
36
37
namespace sfx2::sidebar {
38
39
class Context;
40
class ContextList;
41
42
/** Read the content of the Sidebar.xcu file and provide access
43
    methods so that the sidebar can easily decide which content panels
44
    to display for a certain context.
45
*/
46
class SFX2_DLLPUBLIC ResourceManager
47
{
48
public:
49
50
     ResourceManager();
51
    ~ResourceManager();
52
53
    std::shared_ptr<DeckDescriptor> GetDeckDescriptor(std::u16string_view rsDeckId) const;
54
    std::shared_ptr<PanelDescriptor> GetPanelDescriptor(std::u16string_view rsPanelId) const;
55
56
    void UpdateModel(const css::uno::Reference<css::frame::XModel>& xModel);
57
58
    void InitDeckContext(const Context& rContex);
59
    void SaveDecksSettings(const Context& rContext);
60
    void SaveDeckSettings(const DeckDescriptor* pDeckDesc);
61
    void SaveLastActiveDeck(const Context& rContext, const OUString& rActiveDeck);
62
63
    void disposeDecks();
64
65
    class DeckContextDescriptor
66
    {
67
    public:
68
        OUString msId;
69
        bool mbIsEnabled;
70
    };
71
    typedef std::vector<DeckContextDescriptor> DeckContextDescriptorContainer;
72
73
    class PanelContextDescriptor
74
    {
75
    public:
76
        OUString msId;
77
        OUString msMenuCommand;
78
        bool mbIsInitiallyVisible;
79
        bool mbShowForReadOnlyDocuments;
80
    };
81
    typedef std::vector<PanelContextDescriptor> PanelContextDescriptorContainer;
82
83
    const DeckContextDescriptorContainer& GetMatchingDecks(
84
                                            DeckContextDescriptorContainer& rDeckDescriptors,
85
                                            const Context& rContext,
86
                                            const bool bIsDocumentReadOnly,
87
                                            const css::uno::Reference<css::frame::XController>& rxController);
88
89
    const PanelContextDescriptorContainer& GetMatchingPanels(
90
                                            PanelContextDescriptorContainer& rPanelDescriptors,
91
                                            const Context& rContext,
92
                                            std::u16string_view rsDeckId,
93
                                            const css::uno::Reference<css::frame::XController>& rxController);
94
95
    const OUString& GetLastActiveDeck( const Context& rContext );
96
0
    const std::map<OUString, OUString>& GetDeckOverrides() {
97
0
        if (maApplicationDeckOverrides.empty())
98
0
            SetupOverrides();
99
0
        return maApplicationDeckOverrides;
100
0
    }
101
    void SetLastActiveDeck( const Context& rContext, const OUString& rsDeckId );
102
103
    /** Remember the expansions state per panel and context.
104
    */
105
    void StorePanelExpansionState(std::u16string_view rsPanelId,
106
                                  const bool bExpansionState,
107
                                  const Context& rContext);
108
109
private:
110
111
112
    typedef std::vector<std::shared_ptr<DeckDescriptor>> DeckContainer;
113
    DeckContainer maDecks;
114
115
    typedef std::vector<std::shared_ptr<PanelDescriptor>> PanelContainer;
116
    PanelContainer maPanels;
117
    mutable std::set<OUString> maProcessedApplications;
118
    std::map<OUString, OUString> maLastActiveDecks;
119
    // always jump to Deck on Application type, override last used
120
    std::map<OUString, OUString> maApplicationDeckOverrides;
121
122
    void ReadDeckList();
123
    void ReadPanelList();
124
    void ReadLastActive();
125
    void SetupOverrides();
126
    static void ReadContextList(const utl::OConfigurationNode& rNode,
127
                         ContextList& rContextList,
128
                         const OUString& rsDefaultMenuCommand);
129
130
    void ReadLegacyAddons(const css::uno::Reference<css::frame::XController>& rxController);
131
    static utl::OConfigurationTreeRoot GetLegacyAddonRootNode(const OUString& rsModuleName);
132
    static void GetToolPanelNodeNames(std::vector<OUString>& rMatchingNames,
133
                               const utl::OConfigurationTreeRoot& aRoot);
134
    bool IsDeckEnabled(std::u16string_view rsDeckId,
135
                       const Context& rContext,
136
                       const css::uno::Reference<css::frame::XController>& rxController);
137
138
    std::shared_ptr<DeckDescriptor> ImplGetDeckDescriptor(std::u16string_view rsDeckId) const;
139
    std::shared_ptr<PanelDescriptor> ImplGetPanelDescriptor(std::u16string_view rsPanelId) const;
140
};
141
142
} // end of namespace sfx2::sidebar
143
144
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */