From 00e5973632c6ce80db6efd3bbb7d5d755ac0dcd5 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 21 Jan 2010 02:34:31 +0000 Subject: [PATCH] 2010-01-20 18:33 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/hbide.prg * contrib/hbide/ideactions.prg * contrib/hbide/ideeditor.prg + Implemented: Formatting - ; These formatting actions are initiated from the fact that code examples scattered on the net about Qt examples are written in such a way that I was unable to grasp the contents. I found it usual to include such functionality into hbIDE. Hopefully it will be useful to all. --- harbour/ChangeLog | 12 +++++++ harbour/contrib/hbide/hbide.prg | 2 ++ harbour/contrib/hbide/ideactions.prg | 2 ++ harbour/contrib/hbide/ideeditor.prg | 53 ++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 862844c005..e153402a9c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,18 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-20 18:33 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbide/hbide.prg + * contrib/hbide/ideactions.prg + * contrib/hbide/ideeditor.prg + + Implemented: Formatting - + + ; These formatting actions are initiated from the fact that + code examples scattered on the net about Qt examples are + written in such a way that I was unable to grasp the contents. + I found it usual to include such functionality into hbIDE. + Hopefully it will be useful to all. + 2010-01-20 17:16 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/hbide.prg * contrib/hbide/ideactions.prg diff --git a/harbour/contrib/hbide/hbide.prg b/harbour/contrib/hbide/hbide.prg index cb214f72bf..43dd659f45 100644 --- a/harbour/contrib/hbide/hbide.prg +++ b/harbour/contrib/hbide/hbide.prg @@ -515,6 +515,8 @@ METHOD HbIde:execAction( cKey ) CASE cKey == "ZoomOut" ::oEM:zoom( 0 ) + CASE cKey == "FormatBraces" + ::oEM:formatBraces() CASE cKey == "RemoveTabs" ::oEM:removeTabs() CASE cKey == "RemoveTrailingSpaces" diff --git a/harbour/contrib/hbide/ideactions.prg b/harbour/contrib/hbide/ideactions.prg index 7cecabbf38..1ad3fd9076 100644 --- a/harbour/contrib/hbide/ideactions.prg +++ b/harbour/contrib/hbide/ideactions.prg @@ -288,6 +288,7 @@ METHOD IdeActions:loadActions() aadd( aAct, { "RemoveTabs" , "Replace Tabs with Spaces" , "RemoveTabs" , "" , "No", "Yes" } ) aadd( aAct, { "RemoveTrailingSpaces" , "Remove Trailing Spaces" , "RemoveTrailingSpaces", "" , "No", "Yes" } ) + aadd( aAct, { "FormatBraces" , "Format Braces" , "FormatBraces" , "" , "No", "Yes" } ) RETURN aAct @@ -461,6 +462,7 @@ METHOD IdeActions:buildMainMenu() oSubMenu2:addItem( { ::getAction( "RemoveTabs" ), {|| oIde:execAction( "RemoveTabs" ) } } ) hbide_menuAddSep( oSubMenu ) oSubMenu2:addItem( { ::getAction( "RemoveTrailingSpaces"), {|| oIde:execAction( "RemoveTrailingSpaces" ) } } ) + oSubMenu2:addItem( { ::getAction( "FormatBraces" ), {|| oIde:execAction( "FormatBraces" ) } } ) oMenuBar:addItem( { oSubMenu2, _T( "~Format" ) } ) hbide_menuAddSep( oSubMenu ) diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg index 289fc57958..e8ed6efa06 100644 --- a/harbour/contrib/hbide/ideeditor.prg +++ b/harbour/contrib/hbide/ideeditor.prg @@ -130,6 +130,7 @@ CLASS IdeEditsManager INHERIT IdeObject METHOD setMark() METHOD gotoMark() METHOD goto() + METHOD formatBraces() METHOD removeTabs() METHOD RemoveTrailingSpaces() METHOD getSelectedText() @@ -604,6 +605,58 @@ METHOD IdeEditsManager:insertText( cKey ) /*----------------------------------------------------------------------*/ +METHOD IdeEditsManager:formatBraces() + LOCAL qEdit, qDoc, cText + + IF empty( qEdit := ::getEditCurrent() ) + RETURN Self + ENDIF + + qDoc := QTextDocument():configure( qedit:document() ) + + IF !( qDoc:isEmpty() ) + qDoc:setUndoRedoEnabled( .f. ) + + cText := qDoc:toPlainText() + + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, "( ", "(" ) + cText := strtran( cText, " (", "(" ) + cText := strtran( cText, " (", "(" ) + cText := strtran( cText, " (", "(" ) + cText := strtran( cText, " (", "(" ) + cText := strtran( cText, " (", "(" ) + + cText := strtran( cText, " )", ")" ) + cText := strtran( cText, " )", ")" ) + cText := strtran( cText, " )", ")" ) + cText := strtran( cText, " )", ")" ) + cText := strtran( cText, " )", ")" ) + cText := strtran( cText, " )", ")" ) + + cText := strtran( cText, "(", "( " ) + cText := strtran( cText, ")", " )" ) + + cText := strtran( cText, "( )", "()" ) + cText := strtran( cText, "( )", "()" ) + cText := strtran( cText, "( )", "()" ) + cText := strtran( cText, "( )", "()" ) + cText := strtran( cText, "( )", "()" ) + + qDoc:clear() + qDoc:setPlainText( cText ) + + qDoc:setUndoRedoEnabled( .t. ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeEditsManager:RemoveTabs() LOCAL qEdit, qDoc, cText, cSpaces