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 .
20 #include <basic/codecompletecache.hxx>
22 #include <rtl/instance.hxx>
23 #include <officecfg/Office/BasicIDE.hxx>
27 class theCodeCompleteOptions
: public ::rtl::Static
< CodeCompleteOptions
, theCodeCompleteOptions
>{};
30 CodeCompleteOptions::CodeCompleteOptions()
32 bIsAutoCorrectOn
= officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
33 bIsAutoCloseParenthesisOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
34 bIsAutoCloseQuotesOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
35 bIsProcedureAutoCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
36 bIsCodeCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
37 bExtendedTypeDeclarationOn
= officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
40 bool CodeCompleteOptions::IsCodeCompleteOn()
42 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsCodeCompleteOn
;
45 void CodeCompleteOptions::SetCodeCompleteOn( const bool& b
)
47 theCodeCompleteOptions::get().bIsCodeCompleteOn
= b
;
50 bool CodeCompleteOptions::IsExtendedTypeDeclaration()
52 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
;
55 void CodeCompleteOptions::SetExtendedTypeDeclaration( const bool& b
)
57 theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
= b
;
60 bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
62 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
;
65 void CodeCompleteOptions::SetProcedureAutoCompleteOn( const bool& b
)
67 theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
= b
;
70 bool CodeCompleteOptions::IsAutoCloseQuotesOn()
72 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
;
75 void CodeCompleteOptions::SetAutoCloseQuotesOn( const bool& b
)
77 theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
= b
;
80 bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
82 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
;
85 void CodeCompleteOptions::SetAutoCloseParenthesisOn( const bool& b
)
87 theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
= b
;
90 bool CodeCompleteOptions::IsAutoCorrectOn()
92 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCorrectOn
;
95 void CodeCompleteOptions::SetAutoCorrectOn( const bool& b
)
97 theCodeCompleteOptions::get().bIsAutoCorrectOn
= b
;
100 std::ostream
& operator<< (std::ostream
& aStream
, const CodeCompleteDataCache
& aCache
)
102 aStream
<< "Global variables" << std::endl
;
103 for(CodeCompleteVarTypes::const_iterator aIt
= aCache
.aGlobalVars
.begin(); aIt
!= aCache
.aGlobalVars
.end(); ++aIt
)
105 aStream
<< aIt
->first
<< "," << aIt
->second
<< std::endl
;
107 aStream
<< "Local variables" << std::endl
;
108 for( CodeCompleteVarScopes::const_iterator aIt
= aCache
.aVarScopes
.begin(); aIt
!= aCache
.aVarScopes
.end(); ++aIt
)
110 aStream
<< aIt
->first
<< std::endl
;
111 CodeCompleteVarTypes aVarTypes
= aIt
->second
;
112 for( CodeCompleteVarTypes::const_iterator aOtherIt
= aVarTypes
.begin(); aOtherIt
!= aVarTypes
.end(); ++aOtherIt
)
114 aStream
<< "\t" << aOtherIt
->first
<< "," << aOtherIt
->second
<< std::endl
;
117 aStream
<< "-----------------" << std::endl
;
121 void CodeCompleteDataCache::Clear()
127 void CodeCompleteDataCache::InsertGlobalVar( const OUString
& sVarName
, const OUString
& sVarType
)
129 aGlobalVars
.insert( CodeCompleteVarTypes::value_type(sVarName
, sVarType
) );
132 void CodeCompleteDataCache::InsertLocalVar( const OUString
& sProcName
, const OUString
& sVarName
, const OUString
& sVarType
)
134 CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.find( sProcName
);
135 if( aIt
== aVarScopes
.end() ) //new procedure
137 CodeCompleteVarTypes aTypes
;
138 aTypes
.insert( CodeCompleteVarTypes::value_type(sVarName
, sVarType
) );
139 aVarScopes
.insert( CodeCompleteVarScopes::value_type(sProcName
, aTypes
) );
143 CodeCompleteVarTypes aTypes
= aVarScopes
[ sProcName
];
144 aTypes
.insert( CodeCompleteVarTypes::value_type(sVarName
, sVarType
) );
145 aVarScopes
[ sProcName
] = aTypes
;
149 OUString
CodeCompleteDataCache::GetVarType( const OUString
& sVarName
) const
151 for( CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.begin(); aIt
!= aVarScopes
.end(); ++aIt
)
153 CodeCompleteVarTypes aTypes
= aIt
->second
;
154 for( CodeCompleteVarTypes::const_iterator aOtherIt
= aTypes
.begin(); aOtherIt
!= aTypes
.end(); ++aOtherIt
)
156 if( aOtherIt
->first
.equalsIgnoreAsciiCase( sVarName
) )
158 return aOtherIt
->second
;
162 //not a local, search global scope
163 for( CodeCompleteVarTypes::const_iterator aIt
= aGlobalVars
.begin(); aIt
!= aGlobalVars
.end(); ++aIt
)
165 if( aIt
->first
.equalsIgnoreAsciiCase( sVarName
) )
168 return OUString(""); //not found
171 OUString
CodeCompleteDataCache::GetCorrectCaseVarName( const OUString
& sVarName
, const OUString
& sActProcName
) const
173 for( CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.begin(); aIt
!= aVarScopes
.end(); ++aIt
)
175 CodeCompleteVarTypes aTypes
= aIt
->second
;
176 for( CodeCompleteVarTypes::const_iterator aOtherIt
= aTypes
.begin(); aOtherIt
!= aTypes
.end(); ++aOtherIt
)
178 if( aOtherIt
->first
.equalsIgnoreAsciiCase( sVarName
) && aIt
->first
.equalsIgnoreAsciiCase( sActProcName
) )
180 return aOtherIt
->first
;
184 // search global scope
185 for( CodeCompleteVarTypes::const_iterator aIt
= aGlobalVars
.begin(); aIt
!= aGlobalVars
.end(); ++aIt
)
187 if( aIt
->first
.equalsIgnoreAsciiCase( sVarName
) )
190 return OUString(""); //not found
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */