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 ) ...@@ -536,8 +536,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
HandleProcedureCompletition(); HandleProcedureCompletition();
} }
if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() )
(CodeCompleteOptions::IsCodeCompleteOn() || CodeCompleteOptions::IsExtendedTypeDeclaration()) )
{ {
HandleCodeCompletition(); HandleCodeCompletition();
} }
...@@ -602,9 +601,13 @@ void EditorWindow::HandleAutoCorrect() ...@@ -602,9 +601,13 @@ void EditorWindow::HandleAutoCorrect()
OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin); OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
if( !sStr.isEmpty() ) if( !sStr.isEmpty() )
{ {
//capitalize first letter and replace
sStr = sStr.toAsciiLowerCase(); 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() ); TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex())); TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex()));
...@@ -690,13 +693,17 @@ void EditorWindow::HandleProcedureCompletition() ...@@ -690,13 +693,17 @@ void EditorWindow::HandleProcedureCompletition()
return;// no sub/function keyword or there is no identifier return;// no sub/function keyword or there is no identifier
OUString sText("\nEnd "); OUString sText("\nEnd ");
aSel = GetEditView()->GetSelection();
if( sProcType.equalsIgnoreAsciiCase("function") ) if( sProcType.equalsIgnoreAsciiCase("function") )
sText += OUString( "Function\n" ); sText += OUString( "Function\n" );
if( sProcType.equalsIgnoreAsciiCase("sub") ) if( sProcType.equalsIgnoreAsciiCase("sub") )
sText += OUString( "Sub\n" ); sText += OUString( "Sub\n" );
if( nLine+1 == pEditEngine->GetParagraphCount() ) if( nLine+1 == pEditEngine->GetParagraphCount() )
{
pEditView->InsertText( sText );//append to the end pEditView->InsertText( sText );//append to the end
GetEditView()->SetSelection(aSel);
}
else else
{ {
for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i ) for( sal_uLong i = nLine+1; i < pEditEngine->GetParagraphCount(); ++i )
...@@ -714,7 +721,8 @@ void EditorWindow::HandleProcedureCompletition() ...@@ -714,7 +721,8 @@ void EditorWindow::HandleProcedureCompletition()
{ {
if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") ) if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") )
{ {
pEditView->InsertText( sText ); pEditView->InsertText( sText );//append to the end
GetEditView()->SetSelection(aSel);
break; break;
} }
if( sStr.equalsIgnoreAsciiCase("end") ) if( sStr.equalsIgnoreAsciiCase("end") )
...@@ -735,15 +743,16 @@ void EditorWindow::HandleCodeCompletition() ...@@ -735,15 +743,16 @@ void EditorWindow::HandleCodeCompletition()
std::vector< OUString > aVect; //vector to hold the base variable+methods for the nested reflection std::vector< OUString > aVect; //vector to hold the base variable+methods for the nested reflection
HighlightPortions aPortions; HighlightPortions aPortions;
aLine = aLine.copy(0, aSel.GetEnd().GetIndex());
aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
if( aPortions.size() > 0 ) if( aPortions.size() > 0 )
{//use the syntax highlighter to grab out nested reflection calls, eg. aVar.aMethod("aa").aOtherMethod .. {//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; 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; 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 /* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue
* here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!) * here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!)
* */ * */
...@@ -2609,19 +2618,43 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt ) ...@@ -2609,19 +2618,43 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
case KEY_ESCAPE: // hide, do nothing case KEY_ESCAPE: // hide, do nothing
HideAndRestoreFocus(); HideAndRestoreFocus();
break; 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: 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() ) if( !aFuncBuffer.isEmpty() )
{ {
sal_uInt16 nInd = GetSelectEntryPos(); sal_uInt16 nInd = GetSelectEntryPos();
if( nInd+1 != LISTBOX_ENTRY_NOTFOUND ) if( nInd != LISTBOX_ENTRY_NOTFOUND )
{//if there is something selected {//if there is something selected
bool bFound = false; bool bFound = false;
if( nInd == GetEntryCount() ) if( nInd == GetEntryCount() )
nInd = 0; nInd = 0;
for( sal_uInt16 i = nInd+1; i != GetEntryCount(); ++i ) for( sal_uInt16 i = nInd; i != GetEntryCount(); ++i )
{ {
OUString sEntry = (OUString) GetEntry(i); OUString sEntry = (OUString) GetEntry(i);
if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() ) ) if( sEntry.startsWithIgnoreAsciiCase( aFuncBuffer.toString() )
&& (aFuncBuffer.toString() != sTypedText) && (i != nInd) )
{ {
SelectEntry( sEntry ); SelectEntry( sEntry );
bFound = true; bFound = true;
...@@ -2638,6 +2671,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt ) ...@@ -2638,6 +2671,7 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& rKeyEvt )
} }
} }
break; break;
}
case KEY_SPACE: case KEY_SPACE:
HideAndRestoreFocus(); HideAndRestoreFocus();
break; break;
......
...@@ -29,7 +29,7 @@ namespace ...@@ -29,7 +29,7 @@ namespace
CodeCompleteOptions::CodeCompleteOptions() CodeCompleteOptions::CodeCompleteOptions()
{ {
bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrectKeywords::get(); bIsAutoCorrectKeywordsOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get(); bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get(); bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get(); bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
......
...@@ -1832,6 +1832,11 @@ SbxArrayRef SbModule::GetMethods() ...@@ -1832,6 +1832,11 @@ SbxArrayRef SbModule::GetMethods()
return pMethods; return pMethods;
} }
OUString SbModule::GetKeywordCase( const OUString& sKeyword ) const
{
return SbiParser::GetKeywordCase( sKeyword );
}
bool SbModule::HasExeCode() bool SbModule::HasExeCode()
{ {
// And empty Image always has the Global Chain set up // And empty Image always has the Global Chain set up
......
...@@ -155,7 +155,6 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm ) ...@@ -155,7 +155,6 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
} }
// part of the runtime-library? // part of the runtime-library?
SbiSymDef* SbiParser::CheckRTLForSym( const OUString& rSym, SbxDataType eType ) SbiSymDef* SbiParser::CheckRTLForSym( const OUString& rSym, SbxDataType eType )
{ {
......
...@@ -547,4 +547,25 @@ bool SbiTokenizer::MayBeLabel( bool bNeedsColon ) ...@@ -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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -167,6 +167,7 @@ public: ...@@ -167,6 +167,7 @@ public:
{ return t >= FIRSTKWD && t <= LASTKWD; } { return t >= FIRSTKWD && t <= LASTKWD; }
static bool IsExtra( SbiToken t ) static bool IsExtra( SbiToken t )
{ return t >= FIRSTEXTRA; } { return t >= FIRSTEXTRA; }
static OUString GetKeywordCase( const OUString& sKeyword );
}; };
......
...@@ -39,7 +39,7 @@ SvxBasicIDEOptionsPage::SvxBasicIDEOptionsPage( Window* pParent, const SfxItemSe ...@@ -39,7 +39,7 @@ SvxBasicIDEOptionsPage::SvxBasicIDEOptionsPage( Window* pParent, const SfxItemSe
get(pAutocloseProcChk, "autoclose_proc"); get(pAutocloseProcChk, "autoclose_proc");
get(pAutocloseParenChk, "autoclose_paren"); get(pAutocloseParenChk, "autoclose_paren");
get(pAutocloseQuotesChk, "autoclose_quotes"); get(pAutocloseQuotesChk, "autoclose_quotes");
get(pAutoCorrectKeywordsChk, "autocorrect_keywords"); get(pAutoCorrectChk, "autocorrect");
get(pUseExtendedTypesChk, "extendedtypes_enable"); get(pUseExtendedTypesChk, "extendedtypes_enable");
LoadConfig(); LoadConfig();
...@@ -57,13 +57,13 @@ void SvxBasicIDEOptionsPage::LoadConfig() ...@@ -57,13 +57,13 @@ void SvxBasicIDEOptionsPage::LoadConfig()
bool bCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get(); bool bCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
bool bParenClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get(); bool bParenClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
bool bQuoteClose = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::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 ); pCodeCompleteChk->Check( bCodeCompleteOn );
pAutocloseProcChk->Check( bProcClose ); pAutocloseProcChk->Check( bProcClose );
pAutocloseQuotesChk->Check( bQuoteClose ); pAutocloseQuotesChk->Check( bQuoteClose );
pAutocloseParenChk->Check( bParenClose ); pAutocloseParenChk->Check( bParenClose );
pAutoCorrectKeywordsChk->Check( bCorrect ); pAutoCorrectChk->Check( bCorrect );
pUseExtendedTypesChk->Check( bExtended ); pUseExtendedTypesChk->Check( bExtended );
} }
...@@ -75,7 +75,7 @@ void SvxBasicIDEOptionsPage::SaveConfig() ...@@ -75,7 +75,7 @@ void SvxBasicIDEOptionsPage::SaveConfig()
officecfg::Office::BasicIDE::Autocomplete::UseExtended::set( pUseExtendedTypesChk->IsChecked(), batch ); officecfg::Office::BasicIDE::Autocomplete::UseExtended::set( pUseExtendedTypesChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::set( pAutocloseParenChk->IsChecked(), batch ); officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::set( pAutocloseParenChk->IsChecked(), batch );
officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::set( pAutocloseQuotesChk->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(); batch->commit();
} }
...@@ -123,10 +123,10 @@ sal_Bool SvxBasicIDEOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ ) ...@@ -123,10 +123,10 @@ sal_Bool SvxBasicIDEOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
bModified = sal_True; bModified = sal_True;
} }
if( pAutoCorrectKeywordsChk->IsChecked() != pAutoCorrectKeywordsChk->GetSavedValue() ) if( pAutoCorrectChk->IsChecked() != pAutoCorrectChk->GetSavedValue() )
{ {
boost::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() ); 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(); batch->commit();
bModified = sal_True; bModified = sal_True;
} }
...@@ -145,7 +145,7 @@ void SvxBasicIDEOptionsPage::Reset( const SfxItemSet& /*rSet*/ ) ...@@ -145,7 +145,7 @@ void SvxBasicIDEOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
pAutocloseParenChk->SaveValue(); pAutocloseParenChk->SaveValue();
pAutoCorrectKeywordsChk->SaveValue(); pAutoCorrectChk->SaveValue();
pUseExtendedTypesChk->SaveValue(); pUseExtendedTypesChk->SaveValue();
} }
......
...@@ -31,7 +31,7 @@ private: ...@@ -31,7 +31,7 @@ private:
CheckBox* pAutocloseProcChk; CheckBox* pAutocloseProcChk;
CheckBox* pAutocloseParenChk; CheckBox* pAutocloseParenChk;
CheckBox* pAutocloseQuotesChk; CheckBox* pAutocloseQuotesChk;
CheckBox* pAutoCorrectKeywordsChk; CheckBox* pAutoCorrectChk;
CheckBox* pUseExtendedTypesChk; CheckBox* pUseExtendedTypesChk;
void LoadConfig(); void LoadConfig();
......
...@@ -126,11 +126,12 @@ ...@@ -126,11 +126,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkCheckButton" id="autocorrect_keywords"> <object class="GtkCheckButton" id="autocorrect">
<property name="label" translatable="yes">Autocorrect Keywords</property> <property name="label" translatable="yes">Autocorrection</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="relief">none</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</object> </object>
......
...@@ -136,6 +136,7 @@ public: ...@@ -136,6 +136,7 @@ public:
bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject ); bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache); void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache);
SbxArrayRef GetMethods(); SbxArrayRef GetMethods();
OUString GetKeywordCase( const OUString& sKeyword ) const;
}; };
SV_DECL_IMPL_REF(SbModule) SV_DECL_IMPL_REF(SbModule)
......
...@@ -56,9 +56,9 @@ ...@@ -56,9 +56,9 @@
</info> </info>
<value>false</value> <value>false</value>
</prop> </prop>
<prop oor:name="AutoCorrectKeywords" oor:type="xs:boolean" oor:nillable="false"> <prop oor:name="AutoCorrect" oor:type="xs:boolean" oor:nillable="false">
<info> <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> </info>
<value>false</value> <value>false</value>
</prop> </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