2013-07-19 22:00:29 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <basic/codecompletecache.hxx>
|
2013-07-22 14:44:56 +01:00
|
|
|
#include <iostream>
|
2013-07-23 12:42:37 +02:00
|
|
|
#include <rtl/instance.hxx>
|
2013-07-31 17:08:18 +02:00
|
|
|
#include <officecfg/Office/BasicIDE.hxx>
|
2013-07-19 22:00:29 +02:00
|
|
|
|
2013-07-23 12:42:37 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class theCodeCompleteOptions: public ::rtl::Static< CodeCompleteOptions, theCodeCompleteOptions >{};
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeCompleteOptions::CodeCompleteOptions()
|
|
|
|
{
|
2013-08-14 12:56:39 +02:00
|
|
|
bIsAutoCorrectOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
|
2013-07-31 17:08:18 +02:00
|
|
|
bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
|
|
|
|
bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
|
|
|
|
bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
|
|
|
|
bIsCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
|
2013-08-01 13:59:10 +02:00
|
|
|
bExtendedTypeDeclarationOn = officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
|
2013-07-23 12:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CodeCompleteOptions::IsCodeCompleteOn()
|
|
|
|
{
|
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsCodeCompleteOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteOptions::SetCodeCompleteOn( const bool& b )
|
|
|
|
{
|
2013-07-23 23:00:55 +02:00
|
|
|
theCodeCompleteOptions::get().bIsCodeCompleteOn = b;
|
2013-07-23 12:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CodeCompleteOptions::IsExtendedTypeDeclaration()
|
|
|
|
{
|
2013-08-01 13:59:10 +02:00
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bExtendedTypeDeclarationOn;
|
2013-07-23 12:42:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-31 17:08:18 +02:00
|
|
|
void CodeCompleteOptions::SetExtendedTypeDeclaration( const bool& b )
|
|
|
|
{
|
2013-08-01 13:59:10 +02:00
|
|
|
theCodeCompleteOptions::get().bExtendedTypeDeclarationOn = b;
|
2013-07-31 17:08:18 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 23:00:55 +02:00
|
|
|
bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
|
|
|
|
{
|
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteOptions::SetProcedureAutoCompleteOn( const bool& b )
|
|
|
|
{
|
|
|
|
theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn = b;
|
|
|
|
}
|
|
|
|
|
2013-07-25 20:15:45 +02:00
|
|
|
bool CodeCompleteOptions::IsAutoCloseQuotesOn()
|
|
|
|
{
|
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseQuotesOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteOptions::SetAutoCloseQuotesOn( const bool& b )
|
|
|
|
{
|
|
|
|
theCodeCompleteOptions::get().bIsAutoCloseQuotesOn = b;
|
|
|
|
}
|
|
|
|
|
2013-07-26 13:57:29 +02:00
|
|
|
bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
|
|
|
|
{
|
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteOptions::SetAutoCloseParenthesisOn( const bool& b )
|
|
|
|
{
|
|
|
|
theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn = b;
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:56:39 +02:00
|
|
|
bool CodeCompleteOptions::IsAutoCorrectOn()
|
2013-07-29 22:27:41 +02:00
|
|
|
{
|
2013-08-14 12:56:39 +02:00
|
|
|
return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCorrectOn;
|
2013-07-29 22:27:41 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:56:39 +02:00
|
|
|
void CodeCompleteOptions::SetAutoCorrectOn( const bool& b )
|
2013-07-29 22:27:41 +02:00
|
|
|
{
|
2013-08-14 12:56:39 +02:00
|
|
|
theCodeCompleteOptions::get().bIsAutoCorrectOn = b;
|
2013-07-29 22:27:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-20 13:03:42 +02:00
|
|
|
std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache)
|
|
|
|
{
|
2013-07-24 17:27:02 +02:00
|
|
|
aStream << "Global variables" << std::endl;
|
|
|
|
for(CodeCompleteVarTypes::const_iterator aIt = aCache.aGlobalVars.begin(); aIt != aCache.aGlobalVars.end(); ++aIt )
|
|
|
|
{
|
|
|
|
aStream << aIt->first << "," << aIt->second << std::endl;
|
|
|
|
}
|
|
|
|
aStream << "Local variables" << std::endl;
|
2013-07-20 13:03:42 +02:00
|
|
|
for( CodeCompleteVarScopes::const_iterator aIt = aCache.aVarScopes.begin(); aIt != aCache.aVarScopes.end(); ++aIt )
|
|
|
|
{
|
|
|
|
aStream << aIt->first << std::endl;
|
|
|
|
CodeCompleteVarTypes aVarTypes = aIt->second;
|
|
|
|
for( CodeCompleteVarTypes::const_iterator aOtherIt = aVarTypes.begin(); aOtherIt != aVarTypes.end(); ++aOtherIt )
|
|
|
|
{
|
|
|
|
aStream << "\t" << aOtherIt->first << "," << aOtherIt->second << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aStream << "-----------------" << std::endl;
|
|
|
|
return aStream;
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:00:29 +02:00
|
|
|
const CodeCompleteVarScopes& CodeCompleteDataCache::GetVars() const
|
|
|
|
{
|
|
|
|
return aVarScopes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteDataCache::SetVars( const CodeCompleteVarScopes& aScopes )
|
|
|
|
{
|
|
|
|
aVarScopes = aScopes;
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:27:02 +02:00
|
|
|
void CodeCompleteDataCache::print() const
|
2013-07-19 22:00:29 +02:00
|
|
|
{
|
2013-07-24 17:27:02 +02:00
|
|
|
std::cerr << *this << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteDataCache::Clear()
|
|
|
|
{
|
|
|
|
aVarScopes.clear();
|
2013-08-20 13:29:18 +02:00
|
|
|
aGlobalVars.clear();
|
2013-07-24 17:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCompleteDataCache::InsertGlobalVar( const OUString& sVarName, const OUString& sVarType )
|
|
|
|
{
|
|
|
|
aGlobalVars.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
|
|
|
|
}
|
2013-07-19 22:00:29 +02:00
|
|
|
|
2013-07-24 17:27:02 +02:00
|
|
|
void CodeCompleteDataCache::InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType )
|
|
|
|
{
|
|
|
|
CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName );
|
|
|
|
if( aIt == aVarScopes.end() ) //new procedure
|
|
|
|
{
|
|
|
|
CodeCompleteVarTypes aTypes;
|
|
|
|
aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
|
|
|
|
aVarScopes.insert( CodeCompleteVarScopes::value_type(sProcName, aTypes) );
|
|
|
|
}
|
2013-07-19 22:00:29 +02:00
|
|
|
else
|
2013-07-24 17:27:02 +02:00
|
|
|
{
|
|
|
|
CodeCompleteVarTypes aTypes = aVarScopes[ sProcName ];
|
|
|
|
aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
|
|
|
|
aVarScopes[ sProcName ] = aTypes;
|
|
|
|
}
|
2013-07-19 22:00:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-29 16:08:13 +02:00
|
|
|
OUString CodeCompleteDataCache::GetVarType( const OUString& sVarName ) const
|
2013-07-20 13:03:42 +02:00
|
|
|
{
|
2013-07-24 17:27:02 +02:00
|
|
|
for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt )
|
|
|
|
{
|
|
|
|
CodeCompleteVarTypes aTypes = aIt->second;
|
2013-07-29 16:08:13 +02:00
|
|
|
for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt )
|
|
|
|
{
|
|
|
|
if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) )
|
|
|
|
{
|
|
|
|
return aOtherIt->second;
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 17:27:02 +02:00
|
|
|
}
|
|
|
|
//not a local, search global scope
|
|
|
|
for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt )
|
|
|
|
{
|
2013-07-29 16:08:13 +02:00
|
|
|
if( aIt->first.equalsIgnoreAsciiCase( sVarName ) )
|
2013-07-24 17:27:02 +02:00
|
|
|
return aIt->second;
|
|
|
|
}
|
|
|
|
return OUString(""); //not found
|
2013-07-20 13:03:42 +02:00
|
|
|
}
|
|
|
|
|
2013-08-19 13:53:38 +02:00
|
|
|
OUString CodeCompleteDataCache::GetCorrectCaseVarName( const OUString& sVarName, const OUString& sActProcName ) const
|
2013-07-29 22:27:41 +02:00
|
|
|
{
|
|
|
|
for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt )
|
|
|
|
{
|
|
|
|
CodeCompleteVarTypes aTypes = aIt->second;
|
|
|
|
for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt )
|
|
|
|
{
|
2013-08-19 13:53:38 +02:00
|
|
|
if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) && aIt->first.equalsIgnoreAsciiCase( sActProcName ) )
|
2013-07-29 22:27:41 +02:00
|
|
|
{
|
|
|
|
return aOtherIt->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-19 13:53:38 +02:00
|
|
|
// search global scope
|
2013-07-29 22:27:41 +02:00
|
|
|
for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt )
|
|
|
|
{
|
|
|
|
if( aIt->first.equalsIgnoreAsciiCase( sVarName ) )
|
|
|
|
return aIt->first;
|
|
|
|
}
|
|
|
|
return OUString(""); //not found
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:00:29 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|