Kaydet (Commit) 9b534193 authored tarafından Gergo Mocsi's avatar Gergo Mocsi

GSOC work, behavior fixes

Code completition: left/right arrow keys handled. Left arrow dismisses the dialog when reaches the dot. Right arrow dismissed the dialog when reaches the next line.
ListBox appearance fixed.
TAB key can insert the first matching entry.
Autocorrect:
"Autocorrect Keywords" has been renamed to "Autcorrect" (in the UI, and the config file, after this patch a make dev-install is needed). Keyword case correction is not just capitalizing the first letter ( eg. Elseif -> ElseIf ).
Autoclose procedures:
cursor is being placed inside the preocedure.

Change-Id: Ie7e9ae96b49bd94562db83f96e1c4ad63ab3f3d6
üst 8a1e19f4
......@@ -536,8 +536,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
HandleProcedureCompletition();
}
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT &&
(CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() )
{
HandleCodeCompletition();
}
......@@ -602,9 +601,13 @@ void EditorWindow::HandleAutoCorrect()
OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
if( !sStr.isEmpty() )
{
//capitalize first letter and replace
sStr = sStr.toAsciiLowerCase();
sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() );
if( !rModulWindow.GetSbModule()->GetKeywordCase(sStr).isEmpty() )
// if it is a keyword, get its correct case
sStr = rModulWindow.GetSbModule()->GetKeywordCase(sStr);
else
// else capitalize first letter/select the correct one, and replace
sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() );
TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex()));
......@@ -690,13 +693,17 @@ void EditorWindow::HandleProcedureCompletition()
return;// no sub/function keyword or there is no identifier
OUString sText("\nEnd ");
aSel = GetEditView()->GetSelection();
if( sProcType.equalsIgnoreAsciiCase("function") )
sText += OUString( "Function\n" );
if( sProcType.equalsIgnoreAsciiCase("sub") )
sText += OUString( "Sub\n" );
if( nLine+1 == pEditEngine->GetParagraphCount() )
{
pEditView->InsertText( sText );//append to the end
GetEditView()->SetSelection(aSel);
}
else
{
for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i )
......@@ -714,7 +721,8 @@ void EditorWindow::HandleProcedureCompletition()
{
if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") )
{
pEditView->InsertText( sText );
pEditView->InsertText( sText );//append to the end
GetEditView()->SetSelection(aSel);
break;
}
if( sStr.equalsIgnoreAsciiCase("end") )
......@@ -735,15 +743,16 @@ void EditorWindow::HandleCodeCompletition()
std::vector< OUString > aVect; //vector to hold the base variable+methods for the nested reflection
HighlightPortions aPortions;
aLine = aLine.copy(0, aSel.GetEnd().GetIndex());
aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
if( aPortions.size() > 0 )
{//use the syntax highlighter to grab out nested reflection calls, eg. aVar.aMethod("aa").aOtherMethod ..
for( auto aIt = aPortions.crbegin(); aIt != aPortions.crend(); ++aIt )
for( HighlightPortions::reverse_iterator aIt = aPortions.rbegin(); aIt != aPortions.rend(); ++aIt )
{
HighlightPortion r = *aIt;
if( r.tokenType == 2 ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line
if( r.tokenType == TT_WHITESPACE ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line
break;
if( r.tokenType == 1 || r.tokenType == 9 ) // extract the identifers(methods, base variable)
if( r.tokenType == TT_IDENTIFIER || r.tokenType == TT_KEYWORDS ) // extract the identifers(methods, base variable)
/* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue
* here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!)
* */
......@@ -2609,19 +2618,43 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
case KEY_ESCAPE: // hide, do nothing
HideAndRestoreFocus();
break;
case KEY_RIGHT:
{
TextSelection aTextSelection( GetParentEditView()->GetSelection() );
if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara() )
{
HideAndRestoreFocus();
}
break;
}
case KEY_LEFT:
{
TextSelection aTextSelection( GetParentEditView()->GetSelection() );
if( aTextSelection.GetStart().GetIndex()-1 < pCodeCompleteWindow->GetTextSelection().GetStart().GetIndex() )
{//leave the cursor where it is
pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GrabFocus();
}
break;
}
case KEY_TAB:
{
TextPaM aTextEnd( GetParentEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetEnd()) );
TextSelection aTextSelection( pCodeCompleteWindow->GetTextSelection().GetStart(), aTextEnd );
OUString sTypedText = pCodeCompleteWindow->pParent->GetEditEngine()->GetText(aTextSelection);
if( !aFuncBuffer.isEmpty() )
{
sal_uInt16 nInd = GetSelectEntryPos();
if( nInd+1 != LISTBOX_ENTRY_NOTFOUND )
if( nInd != LISTBOX_ENTRY_NOTFOUND )
{//if there is something selected
bool bFound = false;
if( nInd == GetEntryCount() )
nInd = 0;
for( sal_uInt16 i = nInd+1; i != GetEntryCount(); ++i )
for( sal_uInt16 i = nInd; i != GetEntryCount(); ++i )
{
OUString sEntry = (OUString) GetEntry(i);
if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() ) )
if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() )
&& (aFuncBuffer.toString() != sTypedText) && (i != nInd) )
{
SelectEntry( sEntry );
bFound = true;
......@@ -2638,6 +2671,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
}
}
break;
}
case KEY_SPACE:
HideAndRestoreFocus();
break;
......
......@@ -29,7 +29,7 @@ namespace
CodeCompleteOptions::CodeCompleteOptions()
{
bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::get();
bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
......
......@@ -1832,6 +1832,11 @@ SbxArrayRef SbModule::GetMethods()
return pMethods;
}
OUString SbModule::GetKeywordCase( const OUString& sKeyword ) const
{
return SbiParser::GetKeywordCase( sKeyword );
}
bool SbModule::HasExeCode()
{
// And empty Image always has the Global Chain set up
......
......@@ -155,7 +155,6 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
}
// part of the runtime-library?
SbiSymDef* SbiParser::CheckRTLForSym( const OUString& rSym, SbxDataType eType )
{
......
......@@ -547,4 +547,25 @@ bool SbiTokenizer::MayBeLabel( bool bNeedsColon )
}
}
OUString SbiTokenizer::GetKeywordCase( const OUString& sKeyword )
{
if( !nToken )
{
TokenTable *tp;
for( nToken = 0, tp = pTokTable; tp->t; nToken++, tp++ )
{}
}
TokenTable* tp = pTokTable;
for( short i = 0; i < nToken; i++, tp++ )
{
OUString sStr = OStringToOUString(tp->s, RTL_TEXTENCODING_ASCII_US);
if( sStr.equalsIgnoreAsciiCase(sKeyword) )
{
return sStr;
}
}
return OUString("");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -167,6 +167,7 @@ public:
{ return t >= FIRSTKWD && t <= LASTKWD; }
static bool IsExtra( SbiToken t )
{ return t >= FIRSTEXTRA; }
static OUString GetKeywordCase( const OUString& sKeyword );
};
......
......@@ -39,7 +39,7 @@ SvxBasicIDEOptionsPage::SvxBasicIDEOptionsPage( Window* pParent, const SfxItemSe
get(pAutocloseProcChk, "autoclose_proc");
get(pAutocloseParenChk, "autoclose_paren");
get(pAutocloseQuotesChk, "autoclose_quotes");
get(pAutoCorrectKeywordsChk, "autocorrect_keywords");
get(pAutoCorrectChk, "autocorrect");
get(pUseExtendedTypesChk, "extendedtypes_enable");
LoadConfig();
......@@ -57,13 +57,13 @@ void SvxBasicIDEOptionsPage::LoadConfig()
bool bCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
bool bParenClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
bool bQuoteClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
bool bCorrect = officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::get();
bool bCorrect = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
pCodeCompleteChk->Check( bCodeCompleteOn );
pAutocloseProcChk->Check( bProcClose );
pAutocloseQuotesChk->Check( bQuoteClose );
pAutocloseParenChk->Check( bParenClose );
pAutoCorrectKeywordsChk->Check( bCorrect );
pAutoCorrectChk->Check( bCorrect );
pUseExtendedTypesChk->Check( bExtended );
}
......@@ -75,7 +75,7 @@ void SvxBasicIDEOptionsPage::SaveConfig()
officecfg::Office::BasicIDE::Autocomplete::UseExtended::set( pUseExtendedTypesChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::set( pAutocloseParenChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::set( pAutocloseQuotesChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::set( pAutoCorrectKeywordsChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::set( pAutoCorrectChk->IsChecked(), batch );
batch->commit();
}
......@@ -123,10 +123,10 @@ sal_Bool SvxBasicIDEOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
bModified = sal_True;
}
if( pAutoCorrectKeywordsChk->IsChecked() != pAutoCorrectKeywordsChk->GetSavedValue() )
if( pAutoCorrectChk->IsChecked() != pAutoCorrectChk->GetSavedValue() )
{
boost::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() );
officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::set( pAutoCorrectKeywordsChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::set( pAutoCorrectChk->IsChecked(), batch );
batch->commit();
bModified = sal_True;
}
......@@ -145,7 +145,7 @@ void SvxBasicIDEOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
pAutocloseParenChk->SaveValue();
pAutoCorrectKeywordsChk->SaveValue();
pAutoCorrectChk->SaveValue();
pUseExtendedTypesChk->SaveValue();
}
......
......@@ -31,7 +31,7 @@ private:
CheckBox* pAutocloseProcChk;
CheckBox* pAutocloseParenChk;
CheckBox* pAutocloseQuotesChk;
CheckBox* pAutoCorrectKeywordsChk;
CheckBox* pAutoCorrectChk;
CheckBox* pUseExtendedTypesChk;
void LoadConfig();
......
......@@ -126,11 +126,12 @@
</packing>
</child>
<child>
<object class="GtkCheckButton" id="autocorrect_keywords">
<property name="label" translatable="yes">Autocorrect Keywords</property>
<object class="GtkCheckButton" id="autocorrect">
<property name="label" translatable="yes">Autocorrection</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="relief">none</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
......
......@@ -136,6 +136,7 @@ public:
bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache);
SbxArrayRef GetMethods();
OUString GetKeywordCase( const OUString& sKeyword ) const;
};
SV_DECL_IMPL_REF(SbModule)
......
......@@ -56,9 +56,9 @@
</info>
<value>false</value>
</prop>
<prop oor:name="AutoCorrectKeywords" oor:type="xs:boolean" oor:nillable="false">
<prop oor:name="AutoCorrect" oor:type="xs:boolean" oor:nillable="false">
<info>
<desc>Sets the auto correction of keywords on/off. Default is false.</desc>
<desc>Sets the auto correction of keywords, variables, etc. on/off. Default is false.</desc>
</info>
<value>false</value>
</prop>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment