Line data Source code
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 : #include "ContextList.hxx"
20 : #include "Context.hxx"
21 :
22 : using ::rtl::OUString;
23 :
24 : namespace sfx2 { namespace sidebar {
25 :
26 3686 : ContextList::ContextList()
27 3686 : : maEntries()
28 : {
29 3686 : }
30 :
31 3686 : ContextList::~ContextList()
32 : {
33 3686 : }
34 :
35 103083 : const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const
36 : {
37 103083 : const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
38 103083 : if (iEntry != maEntries.end())
39 8094 : return &*iEntry;
40 : else
41 94989 : return NULL;
42 : }
43 :
44 0 : ContextList::Entry* ContextList::GetMatch (const Context& rContext)
45 : {
46 0 : const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
47 0 : if (iEntry != maEntries.end())
48 0 : return const_cast<Entry*>(&*iEntry);
49 : else
50 0 : return NULL;
51 : }
52 :
53 103083 : ::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const
54 : {
55 103083 : sal_Int32 nBestMatch (Context::NoMatch);
56 103083 : ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end());
57 :
58 1655101 : for (::std::vector<Entry>::const_iterator
59 103083 : iEntry(maEntries.begin()),
60 103083 : iEnd(maEntries.end());
61 : iEntry!=iEnd;
62 : ++iEntry)
63 : {
64 1554232 : const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext));
65 1554232 : if (nMatch < nBestMatch)
66 : {
67 8094 : nBestMatch = nMatch;
68 8094 : iBestMatch = iEntry;
69 : }
70 1554232 : if (nBestMatch == Context::OptimalMatch)
71 2214 : return iEntry;
72 : }
73 :
74 100869 : return iBestMatch;
75 : }
76 :
77 29294 : void ContextList::AddContextDescription (
78 : const Context& rContext,
79 : const bool bIsInitiallyVisible,
80 : const OUString& rsMenuCommand)
81 : {
82 29294 : maEntries.push_back(Entry());
83 29294 : maEntries.back().maContext = rContext;
84 29294 : maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible;
85 29294 : maEntries.back().msMenuCommand = rsMenuCommand;
86 29294 : }
87 :
88 : } } // end of namespace sfx2::sidebar
89 :
90 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|