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 "ContextList.hxx"
20 #include "Context.hxx"
22 using ::rtl::OUString
;
24 namespace sfx2
{ namespace sidebar
{
26 ContextList::ContextList()
31 ContextList::~ContextList()
35 const ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
) const
37 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
38 if (iEntry
!= maEntries
.end())
44 ContextList::Entry
* ContextList::GetMatch (const Context
& rContext
)
46 const ::std::vector
<Entry
>::const_iterator iEntry
= FindBestMatch(rContext
);
47 if (iEntry
!= maEntries
.end())
48 return const_cast<Entry
*>(&*iEntry
);
53 ::std::vector
<ContextList::Entry
>::const_iterator
ContextList::FindBestMatch (const Context
& rContext
) const
55 sal_Int32
nBestMatch (Context::NoMatch
);
56 ::std::vector
<Entry
>::const_iterator
iBestMatch (maEntries
.end());
58 for (::std::vector
<Entry
>::const_iterator
59 iEntry(maEntries
.begin()),
60 iEnd(maEntries
.end());
64 const sal_Int32
nMatch (rContext
.EvaluateMatch(iEntry
->maContext
));
65 if (nMatch
< nBestMatch
)
70 if (nBestMatch
== Context::OptimalMatch
)
77 void ContextList::AddContextDescription (
78 const Context
& rContext
,
79 const bool bIsInitiallyVisible
,
80 const OUString
& rsMenuCommand
)
82 maEntries
.push_back(Entry());
83 maEntries
.back().maContext
= rContext
;
84 maEntries
.back().mbIsInitiallyVisible
= bIsInitiallyVisible
;
85 maEntries
.back().msMenuCommand
= rsMenuCommand
;
88 } } // end of namespace sfx2::sidebar
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */