From bfa7f4b450c7f46e6d3f619389afa6941c106582 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Fri, 12 Aug 2011 22:54:18 +0000 Subject: [PATCH] 2011-08-12 15:49 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/ideactions.prg * contrib/hbide/ideedit.prg * contrib/hbide/ideeditor.prg * contrib/hbide/idemain.prg * contrib/hbide/idethemes.prg + Added: option. When applied to an editing instance, Harbour keywords are capitalized. It is a useful utility for old sources where we were lazy on readable importance of our sources. --- harbour/ChangeLog | 11 ++++++ harbour/contrib/hbide/ideactions.prg | 2 ++ harbour/contrib/hbide/ideedit.prg | 54 ++++++++++++++++++++++++++-- harbour/contrib/hbide/ideeditor.prg | 10 ++++++ harbour/contrib/hbide/idemain.prg | 4 +++ harbour/contrib/hbide/idethemes.prg | 2 +- 6 files changed, 80 insertions(+), 3 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 1c325c22d8..b60d882cc5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,17 @@ The license applies to all entries newer than 2009-04-28. */ +2011-08-12 15:49 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbide/ideactions.prg + * contrib/hbide/ideedit.prg + * contrib/hbide/ideeditor.prg + * contrib/hbide/idemain.prg + * contrib/hbide/idethemes.prg + + Added: option. + When applied to an editing instance, Harbour keywords are + capitalized. It is a useful utility for old sources where + we were lazy on readable importance of our sources. + 2011-08-12 17:53 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbtip/sendmail.prg * contrib/hbtip/httpcli.prg diff --git a/harbour/contrib/hbide/ideactions.prg b/harbour/contrib/hbide/ideactions.prg index 6c9293b19a..3ec3592c9b 100644 --- a/harbour/contrib/hbide/ideactions.prg +++ b/harbour/contrib/hbide/ideactions.prg @@ -289,6 +289,7 @@ METHOD IdeActions:loadActions() aadd( aAct, { "Spaces2Tabs" , "Replace Spaces with Tabs" , "" , "" , "No", "Yes" } ) aadd( aAct, { "RemoveTrailingSpaces" , "Remove Trailing Spaces" , "removetrailingspaces", "", "No", "Yes" } ) aadd( aAct, { "FormatBraces" , "Format Braces" , "ormatbraces" , "" , "No", "Yes" } ) + aadd( aAct, { "UpperCaseKeywords" , "UpperCase Harbour Keywords" , "ormatbraces" , "" , "No", "Yes" } ) aadd( aAct, { "StreamComment" , "Stream Comment" , "streamcomment" , "" , "No", "Yes" } ) aadd( aAct, { "BlockComment" , "Block Comment" , "blockcomment" , "" , "No", "Yes" } ) @@ -496,6 +497,7 @@ METHOD IdeActions:buildMainMenu() hbide_menuAddSep( oSubMenu ) oSubMenu2:addItem( { ::getAction( "RemoveTrailingSpaces"), {|| oIde:execAction( "RemoveTrailingSpaces" ) } } ) oSubMenu2:addItem( { ::getAction( "FormatBraces" ), {|| oIde:execAction( "FormatBraces" ) } } ) + oSubMenu2:addItem( { ::getAction( "UpperCaseKeywords" ), {|| oIde:execAction( "UpperCaseKeywords" ) } } ) oMenuBar:addItem( { oSubMenu2, _T( "~Format" ) } ) hbide_menuAddSep( oSubMenu ) diff --git a/harbour/contrib/hbide/ideedit.prg b/harbour/contrib/hbide/ideedit.prg index 92eae0ff38..50698d9afa 100644 --- a/harbour/contrib/hbide/ideedit.prg +++ b/harbour/contrib/hbide/ideedit.prg @@ -241,6 +241,7 @@ CLASS IdeEdit INHERIT IdeObject METHOD spaces2tabs() METHOD removeTrailingSpaces() METHOD formatBraces() + METHOD upperCaseKeywords() METHOD findEx( cText, nFlags, nStart ) METHOD highlightAll( cText ) METHOD unHighlight() @@ -1883,6 +1884,49 @@ METHOD IdeEdit:paintRequested( qPrinter ) /*----------------------------------------------------------------------*/ +METHOD IdeEdit:upperCaseKeywords() + LOCAL qDoc, cText, cRegEx, aMatches, aMatch, b_ + + qDoc := ::qEdit:document() + + IF !( qDoc:isEmpty() ) + qDoc:setUndoRedoEnabled( .f. ) + + cText := qDoc:toPlainText() + + b_:= { 'function','procedure','thread','return','static','local','default', ; + 'if','else','elseif','endif','end', ; + 'docase','case','endcase','otherwise', ; + 'switch','endswitch', ; + 'do','while','exit','enddo','loop',; + 'for','each','next','step','to','in',; + 'with','replace','object','endwith','request',; + 'nil','and','or','in','not','self',; + 'class','endclass','method','data','var','destructor','inline','assign','access',; + 'inherit','init','create','virtual','message', 'from', 'setget',; + 'begin','sequence','try','catch','always','recover','hb_symbol_unused', ; + 'error','handler','private','public' } + cRegEx := "" + aeval( b_, {|e| cRegEx += iif( empty( cRegEx ), "", "|" ) + "\b" + e + "\b" } ) + + aMatches := hb_regExAll( cRegEx, cText, .f., .f., 0, 1, .f. ) + + IF ! empty( aMatches ) + FOR EACH aMatch IN aMatches + cText := stuff( cText, aMatch[ 2 ], aMatch[ 3 ] - aMatch[ 2 ] + 1, upper( aMatch[ 1 ] ) ) + NEXT + ENDIF + + qDoc:clear() + qDoc:setPlainText( cText ) + + qDoc:setUndoRedoEnabled( .t. ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeEdit:formatBraces() LOCAL qDoc, cText @@ -2537,7 +2581,7 @@ FUNCTION hbide_isIndentableKeyword( cWord, oIde ) /*----------------------------------------------------------------------*/ -FUNCTION hbide_isHarbourKeyword( cWord, oIde ) +FUNCTION hbide_harbourKeywords() STATIC s_b_ := { ; 'function' => NIL,; 'procedure' => NIL,; @@ -2600,9 +2644,15 @@ FUNCTION hbide_isHarbourKeyword( cWord, oIde ) 'not' => NIL,; 'and' => NIL } + RETURN s_b_ + +/*----------------------------------------------------------------------*/ + +FUNCTION hbide_isHarbourKeyword( cWord, oIde ) + HB_SYMBOL_UNUSED( oIde ) - RETURN Lower( cWord ) $ s_b_ + RETURN Lower( cWord ) $ hbide_harbourKeywords() /*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg index 1a9ab39808..026e8f73cc 100644 --- a/harbour/contrib/hbide/ideeditor.prg +++ b/harbour/contrib/hbide/ideeditor.prg @@ -126,6 +126,7 @@ CLASS IdeEditsManager INHERIT IdeObject METHOD gotoMark( nIndex ) METHOD goto( nLine ) METHOD formatBraces() + METHOD upperCaseKeywords() METHOD removeTabs() METHOD RemoveTrailingSpaces() METHOD getSelectedText() @@ -979,6 +980,15 @@ METHOD IdeEditsManager:insertText( cKey ) /*----------------------------------------------------------------------*/ +METHOD IdeEditsManager:upperCaseKeywords() + LOCAL oEdit + IF !empty( oEdit := ::getEditObjectCurrent() ) + oEdit:upperCaseKeywords() + ENDIF + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeEditsManager:formatBraces() LOCAL oEdit IF !empty( oEdit := ::getEditObjectCurrent() ) diff --git a/harbour/contrib/hbide/idemain.prg b/harbour/contrib/hbide/idemain.prg index 37fd872e95..ecc1dc6c52 100644 --- a/harbour/contrib/hbide/idemain.prg +++ b/harbour/contrib/hbide/idemain.prg @@ -947,6 +947,7 @@ METHOD HbIde:execAction( cKey ) CASE "InsertExternalFile" CASE "ZoomIn" CASE "ZoomOut" + CASE "UpperCaseKeywords" CASE "FormatBraces" CASE "RemoveTabs" CASE "Spaces2Tabs" @@ -1078,6 +1079,9 @@ METHOD HbIde:execEditorAction( cKey ) CASE "ZoomOut" ::oEM:zoom( -1 ) EXIT + CASE "UpperCaseKeywords" + ::oEM:upperCaseKeywords() + EXIT CASE "FormatBraces" ::oEM:formatBraces() EXIT diff --git a/harbour/contrib/hbide/idethemes.prg b/harbour/contrib/hbide/idethemes.prg index 0b064e7188..7a5f3028ec 100644 --- a/harbour/contrib/hbide/idethemes.prg +++ b/harbour/contrib/hbide/idethemes.prg @@ -226,7 +226,7 @@ METHOD IdeThemes:create( oIde, cThemesFile ) 'class','endclass','method','data','var','destructor','inline','assign','access',; 'inherit','init','create','virtual','message', 'from', 'setget',; 'begin','sequence','try','catch','always','recover','hb_symbol_unused', ; - 'error','handler' } + 'error','handler','private','public' } s := ""; aeval( b_, {|e| s += iif( empty( s ), "", "|" ) + "\b" + e + "\b" } ) aadd( ::aPatterns, { "HarbourKeywords" , s, .f. } )