/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 <unotools/confignode.hxx> |
22 | | #include <map> |
23 | | #include <vector> |
24 | | #include <set> |
25 | | |
26 | | #include <sfx2/dllapi.h> |
27 | | |
28 | | namespace com::sun::star::frame { class XController; } |
29 | | namespace com::sun::star::frame { class XModel; } |
30 | | namespace sfx2::sidebar { class DeckDescriptor; } |
31 | | namespace sfx2::sidebar { class PanelDescriptor; } |
32 | | |
33 | | namespace sfx2::sidebar { |
34 | | |
35 | | class Context; |
36 | | class ContextList; |
37 | | |
38 | | /** Read the content of the Sidebar.xcu file and provide access |
39 | | methods so that the sidebar can easily decide which content panels |
40 | | to display for a certain context. |
41 | | */ |
42 | | class SFX2_DLLPUBLIC ResourceManager |
43 | | { |
44 | | public: |
45 | | |
46 | | ResourceManager(); |
47 | | ~ResourceManager(); |
48 | | |
49 | | std::shared_ptr<DeckDescriptor> GetDeckDescriptor(std::u16string_view rsDeckId) const; |
50 | | std::shared_ptr<PanelDescriptor> GetPanelDescriptor(std::u16string_view rsPanelId) const; |
51 | | |
52 | | void UpdateModel(const css::uno::Reference<css::frame::XModel>& xModel); |
53 | | |
54 | | void InitDeckContext(const Context& rContex); |
55 | | void SaveDecksSettings(const Context& rContext); |
56 | | void SaveDeckSettings(const DeckDescriptor* pDeckDesc); |
57 | | void SaveLastActiveDeck(const Context& rContext, const OUString& rActiveDeck); |
58 | | |
59 | | void disposeDecks(); |
60 | | |
61 | | class DeckContextDescriptor |
62 | | { |
63 | | public: |
64 | | OUString msId; |
65 | | bool mbIsEnabled; |
66 | | }; |
67 | | typedef std::vector<DeckContextDescriptor> DeckContextDescriptorContainer; |
68 | | |
69 | | class PanelContextDescriptor |
70 | | { |
71 | | public: |
72 | | OUString msId; |
73 | | OUString msMenuCommand; |
74 | | bool mbIsInitiallyVisible; |
75 | | bool mbShowForReadOnlyDocuments; |
76 | | }; |
77 | | typedef std::vector<PanelContextDescriptor> PanelContextDescriptorContainer; |
78 | | |
79 | | const DeckContextDescriptorContainer& GetMatchingDecks( |
80 | | DeckContextDescriptorContainer& rDeckDescriptors, |
81 | | const Context& rContext, |
82 | | const bool bIsDocumentReadOnly, |
83 | | const css::uno::Reference<css::frame::XController>& rxController); |
84 | | |
85 | | const PanelContextDescriptorContainer& GetMatchingPanels( |
86 | | PanelContextDescriptorContainer& rPanelDescriptors, |
87 | | const Context& rContext, |
88 | | std::u16string_view rsDeckId, |
89 | | const css::uno::Reference<css::frame::XController>& rxController); |
90 | | |
91 | | const OUString& GetLastActiveDeck( const Context& rContext ); |
92 | 0 | const std::map<OUString, OUString>& GetDeckOverrides() { |
93 | 0 | if (maApplicationDeckOverrides.empty()) |
94 | 0 | SetupOverrides(); |
95 | 0 | return maApplicationDeckOverrides; |
96 | 0 | } |
97 | | void SetLastActiveDeck( const Context& rContext, const OUString& rsDeckId ); |
98 | | |
99 | | /** Remember the expansions state per panel and context. |
100 | | */ |
101 | | void StorePanelExpansionState(std::u16string_view rsPanelId, |
102 | | const bool bExpansionState, |
103 | | const Context& rContext); |
104 | | |
105 | | private: |
106 | | |
107 | | |
108 | | typedef std::vector<std::shared_ptr<DeckDescriptor>> DeckContainer; |
109 | | DeckContainer maDecks; |
110 | | |
111 | | typedef std::vector<std::shared_ptr<PanelDescriptor>> PanelContainer; |
112 | | PanelContainer maPanels; |
113 | | mutable std::set<OUString> maProcessedApplications; |
114 | | std::map<OUString, OUString> maLastActiveDecks; |
115 | | // always jump to Deck on Application type, override last used |
116 | | std::map<OUString, OUString> maApplicationDeckOverrides; |
117 | | |
118 | | void ReadDeckList(); |
119 | | void ReadPanelList(); |
120 | | void ReadLastActive(); |
121 | | void SetupOverrides(); |
122 | | static void ReadContextList(const utl::OConfigurationNode& rNode, |
123 | | ContextList& rContextList, |
124 | | const OUString& rsDefaultMenuCommand); |
125 | | |
126 | | void ReadLegacyAddons(const css::uno::Reference<css::frame::XController>& rxController); |
127 | | static utl::OConfigurationTreeRoot GetLegacyAddonRootNode(const OUString& rsModuleName); |
128 | | static void GetToolPanelNodeNames(std::vector<OUString>& rMatchingNames, |
129 | | const utl::OConfigurationTreeRoot& aRoot); |
130 | | bool IsDeckEnabled(std::u16string_view rsDeckId, |
131 | | const Context& rContext, |
132 | | const css::uno::Reference<css::frame::XController>& rxController); |
133 | | |
134 | | std::shared_ptr<DeckDescriptor> ImplGetDeckDescriptor(std::u16string_view rsDeckId) const; |
135 | | std::shared_ptr<PanelDescriptor> ImplGetPanelDescriptor(std::u16string_view rsPanelId) const; |
136 | | }; |
137 | | |
138 | | } // end of namespace sfx2::sidebar |
139 | | |
140 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |