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()
29 const ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
) const
31 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
32 if (iEntry
!= maEntries
.end())
38 ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
)
40 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
41 if (iEntry
!= maEntries
.end())
42 return const_cast<Entry
*>(&*iEntry
);
47 ::std::vector
<ContextList::Entry
>::const_iterator
ContextList::FindBestMatch (const Context
& rContext
) const
49 sal_Int32
nBestMatch (Context::NoMatch
);
50 ::std::vector
<Entry
>::const_iterator
iBestMatch (maEntries
.end());
52 for (::std::vector
<Entry
>::const_iterator
53 iEntry(maEntries
.begin()),
54 iEnd(maEntries
.end());
58 const sal_Int32
nMatch (rContext
.EvaluateMatch(iEntry
->maContext
));
59 if (nMatch
< nBestMatch
)
64 if (nBestMatch
== Context::OptimalMatch
)
71 void ContextList::AddContextDescription (
72 const Context
& rContext
,
73 const bool bIsInitiallyVisible
,
74 const OUString
& rsMenuCommand
)
76 maEntries
.emplace_back();
77 maEntries
.back().maContext
= rContext
;
78 maEntries
.back().mbIsInitiallyVisible
= bIsInitiallyVisible
;
79 maEntries
.back().msMenuCommand
= rsMenuCommand
;
82 void ContextList::ToggleVisibilityForContext( const Context
&rContext
, const bool bVisible
)
84 ContextList::Entry
*pEntry
= GetMatch( rContext
);
89 const sal_Int32
nMatch( rContext
.EvaluateMatch( pEntry
->maContext
) );
91 if ( nMatch
& Context::ApplicationWildcardMatch
)
93 // Create a separate context list entry for this app if 'any'
94 // is the only context that matches. Toggling the visibility
95 // for 'any' would change it for all apps, not just this one
96 AddContextDescription( rContext
, bVisible
, OUString() );
98 else if ( nMatch
== Context::OptimalMatch
|| nMatch
== Context::ContextWildcardMatch
)
99 pEntry
->mbIsInitiallyVisible
= bVisible
;
102 } // end of namespace sfx2::sidebar
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */