1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <sidebar/ContextList.hxx>
20 #include <sfx2/sidebar/Context.hxx>
22 namespace sfx2::sidebar
{
24 ContextList::ContextList()
28 const ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
) const
30 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
31 if (iEntry
!= maEntries
.end())
37 ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
)
39 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
40 if (iEntry
!= maEntries
.end())
41 return const_cast<Entry
*>(&*iEntry
);
46 ::std::vector
<ContextList::Entry
>::const_iterator
ContextList::FindBestMatch (const Context
& rContext
) const
48 sal_Int32
nBestMatch (Context::NoMatch
);
49 ::std::vector
<Entry
>::const_iterator
iBestMatch (maEntries
.end());
51 for (::std::vector
<Entry
>::const_iterator
52 iEntry(maEntries
.begin()),
53 iEnd(maEntries
.end());
57 const sal_Int32
nMatch (rContext
.EvaluateMatch(iEntry
->maContext
));
58 if (nMatch
< nBestMatch
)
63 if (nBestMatch
== Context::OptimalMatch
)
70 void ContextList::AddContextDescription (
71 const Context
& rContext
,
72 const bool bIsInitiallyVisible
,
73 const OUString
& rsMenuCommand
)
75 maEntries
.emplace_back();
76 maEntries
.back().maContext
= rContext
;
77 maEntries
.back().mbIsInitiallyVisible
= bIsInitiallyVisible
;
78 maEntries
.back().msMenuCommand
= rsMenuCommand
;
81 void ContextList::ToggleVisibilityForContext( const Context
&rContext
, const bool bVisible
)
83 ContextList::Entry
*pEntry
= GetMatch( rContext
);
88 const sal_Int32
nMatch( rContext
.EvaluateMatch( pEntry
->maContext
) );
90 if ( nMatch
& Context::ApplicationWildcardMatch
)
92 // Create a separate context list entry for this app if 'any'
93 // is the only context that matches. Toggling the visibility
94 // for 'any' would change it for all apps, not just this one
95 AddContextDescription( rContext
, bVisible
, OUString() );
97 else if ( nMatch
== Context::OptimalMatch
|| nMatch
== Context::ContextWildcardMatch
)
98 pEntry
->mbIsInitiallyVisible
= bVisible
;
101 } // end of namespace sfx2::sidebar
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */