LibreOffice Module sfx2 (master) 1
ContextList.cxx
Go to the documentation of this file.
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 */
21
22namespace sfx2::sidebar {
23
25{
26}
27
28const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const
29{
30 const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
31 if (iEntry != maEntries.end())
32 return &*iEntry;
33 else
34 return nullptr;
35}
36
38{
39 const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
40 if (iEntry != maEntries.end())
41 return const_cast<Entry*>(&*iEntry);
42 else
43 return nullptr;
44}
45
46::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const
47{
48 sal_Int32 nBestMatch (Context::NoMatch);
49 ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end());
50
51 for (::std::vector<Entry>::const_iterator
52 iEntry(maEntries.begin()),
53 iEnd(maEntries.end());
54 iEntry!=iEnd;
55 ++iEntry)
56 {
57 const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext));
58 if (nMatch < nBestMatch)
59 {
60 nBestMatch = nMatch;
61 iBestMatch = iEntry;
62 }
63 if (nBestMatch == Context::OptimalMatch)
64 return iEntry;
65 }
66
67 return iBestMatch;
68}
69
71 const Context& rContext,
72 const bool bIsInitiallyVisible,
73 const OUString& rsMenuCommand)
74{
75 maEntries.emplace_back();
76 maEntries.back().maContext = rContext;
77 maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible;
78 maEntries.back().msMenuCommand = rsMenuCommand;
79}
80
81void ContextList::ToggleVisibilityForContext( const Context &rContext, const bool bVisible)
82{
83 ContextList::Entry *pEntry = GetMatch( rContext );
84
85 if ( !pEntry )
86 return;
87
88 const sal_Int32 nMatch( rContext.EvaluateMatch( pEntry->maContext ) );
89
91 {
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() );
96 }
97 else if ( nMatch == Context::OptimalMatch || nMatch == Context::ContextWildcardMatch )
99}
100
101} // end of namespace sfx2::sidebar
102
103/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< Entry > maEntries
Definition: ContextList.hxx:56
void AddContextDescription(const Context &rContext, const bool bIsInitiallyVisible, const OUString &rsMenuCommand)
Definition: ContextList.cxx:70
void ToggleVisibilityForContext(const Context &rContext, const bool bIsInitiallyVisible)
Definition: ContextList.cxx:81
const Entry * GetMatch(const Context &rContext) const
Return <TRUE> when the given context matches any of the stored contexts.
Definition: ContextList.cxx:28
::std::vector< Entry >::const_iterator FindBestMatch(const Context &rContext) const
Definition: ContextList.cxx:46
static const sal_Int32 ContextWildcardMatch
Definition: Context.hxx:44
static const sal_Int32 ApplicationWildcardMatch
Definition: Context.hxx:43
static const sal_Int32 NoMatch
When two contexts are matched against each other, then application or context name may have the wildc...
Definition: Context.hxx:41
sal_Int32 EvaluateMatch(const Context &rOther) const
Return the numeric value that describes how good the match between two contexts is.
Definition: Context.cxx:47
static const sal_Int32 OptimalMatch
Definition: Context.hxx:42
bool bVisible