From c1542c45f3c16d21da46ec99a001dc6d1d644eae Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 21 Jan 2010 01:32:59 +0000 Subject: [PATCH] 2010-01-20 17:16 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/hbide.prg * contrib/hbide/ideactions.prg * contrib/hbide/ideeditor.prg * contrib/hbide/idefindreplace.prg * contrib/hbide/idesaveload.prg + Implemented: Formatting - This can be achieved via Mainmenu option. ! New: Find/Replace: Current selelcted text in "Find what:" control in selected state. % Changed: The way hbide.ini is loaded. cHbideIni := hb_argv( 0 ) IF empty( cHbideIni ) IF file( "hbide.ini" ) cHbideIni := "hbide.ini" ELSE cHbideIni := hb_dirBase() + "hbide.ini" ENDIF ENDIF oIde:cProjIni := cHbideIni ! Improved qTextDocument:isModified() handelling. ; TO CONSIDER: QPlainTextEdit() class by itself is not providing enough methods to have finest of the editing experience. So, it may be necessary to subclass it for extended features. --- harbour/ChangeLog | 30 +++++++ harbour/contrib/hbide/hbide.prg | 11 ++- harbour/contrib/hbide/ideactions.prg | 10 +++ harbour/contrib/hbide/ideeditor.prg | 99 +++++++++++++++++++++--- harbour/contrib/hbide/idefindreplace.prg | 8 ++ harbour/contrib/hbide/idesaveload.prg | 19 +++-- 6 files changed, 158 insertions(+), 19 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7ce029d188..862844c005 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,36 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-20 17:16 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbide/hbide.prg + * contrib/hbide/ideactions.prg + * contrib/hbide/ideeditor.prg + * contrib/hbide/idefindreplace.prg + * contrib/hbide/idesaveload.prg + + Implemented: Formatting - + + This can be achieved via Mainmenu option. + ! New: Find/Replace: Current selelcted text in "Find what:" control + in selected state. + % Changed: The way hbide.ini is loaded. + + cHbideIni := hb_argv( 0 ) + + IF empty( cHbideIni ) + IF file( "hbide.ini" ) + cHbideIni := "hbide.ini" + ELSE + cHbideIni := hb_dirBase() + "hbide.ini" + ENDIF + ENDIF + oIde:cProjIni := cHbideIni + + ! Improved qTextDocument:isModified() handelling. + + ; TO CONSIDER: QPlainTextEdit() class by itself is not providing + enough methods to have finest of the editing experience. + So, it may be necessary to subclass it for extended features. + 2010-01-21 01:09 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbnetio/netiocli.c * harbour/contrib/hbnetio/readme.txt diff --git a/harbour/contrib/hbide/hbide.prg b/harbour/contrib/hbide/hbide.prg index 313dae04f7..cb214f72bf 100644 --- a/harbour/contrib/hbide/hbide.prg +++ b/harbour/contrib/hbide/hbide.prg @@ -96,7 +96,7 @@ PROCEDURE Main( cProjIni ) s_resPath := hb_DirBase() + "resources" + hb_OsPathSeparator() s_pathSep := hb_OsPathSeparator() - +hbide_dbg( cProjIni ) oIde := HbIde():new( cProjIni ):create() oIde:destroy() @@ -242,6 +242,10 @@ METHOD HbIde:new( cProjIni ) /*----------------------------------------------------------------------*/ METHOD HbIde:create( cProjIni ) + + DEFAULT cProjIni TO ::cProjIni + ::cProjIni := cProjIni + /* Setup GUI Error Reporting System*/ hbqt_errorsys() @@ -511,6 +515,11 @@ METHOD HbIde:execAction( cKey ) CASE cKey == "ZoomOut" ::oEM:zoom( 0 ) + CASE cKey == "RemoveTabs" + ::oEM:removeTabs() + CASE cKey == "RemoveTrailingSpaces" + ::oEM:removeTrailingSpaces() + CASE cKey == "ToggleProjectTree" ::oDK:toggleLeftDocks() CASE cKey == "ToggleBuildInfo" diff --git a/harbour/contrib/hbide/ideactions.prg b/harbour/contrib/hbide/ideactions.prg index 6f81c56cc6..7cecabbf38 100644 --- a/harbour/contrib/hbide/ideactions.prg +++ b/harbour/contrib/hbide/ideactions.prg @@ -286,6 +286,9 @@ METHOD IdeActions:loadActions() aadd( aAct, { "RebuildQt" , "Rebuild Project" , "rebuild" , "" , "No", "Yes" } ) aadd( aAct, { "RebuildLaunchQt" , "Rebuild and Launch" , "rebuildlaunch" , "" , "No", "Yes" } ) + aadd( aAct, { "RemoveTabs" , "Replace Tabs with Spaces" , "RemoveTabs" , "" , "No", "Yes" } ) + aadd( aAct, { "RemoveTrailingSpaces" , "Remove Trailing Spaces" , "RemoveTrailingSpaces", "" , "No", "Yes" } ) + RETURN aAct /*----------------------------------------------------------------------*/ @@ -453,6 +456,13 @@ METHOD IdeActions:buildMainMenu() oSubMenu2:addItem( { ::getAction( "InsertExternalFile" ), {|| oIde:execAction( "InsertExternalFile" ) } } ) oMenuBar:addItem( { oSubMenu2, _T( "~Insert" ) } ) + hbide_menuAddSep( oSubMenu ) + oSubMenu2 := XbpMenu():new( oSubMenu ):create() + oSubMenu2:addItem( { ::getAction( "RemoveTabs" ), {|| oIde:execAction( "RemoveTabs" ) } } ) + hbide_menuAddSep( oSubMenu ) + oSubMenu2:addItem( { ::getAction( "RemoveTrailingSpaces"), {|| oIde:execAction( "RemoveTrailingSpaces" ) } } ) + oMenuBar:addItem( { oSubMenu2, _T( "~Format" ) } ) + hbide_menuAddSep( oSubMenu ) oSubMenu:addItem( { ::getAction( "switchReadOnly" ), {|| oIde:execAction( "switchReadOnly" ) } } ) oMenuBar:addItem( { oSubMenu, NIL } ) diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg index a72a223777..289fc57958 100644 --- a/harbour/contrib/hbide/ideeditor.prg +++ b/harbour/contrib/hbide/ideeditor.prg @@ -130,6 +130,9 @@ CLASS IdeEditsManager INHERIT IdeObject METHOD setMark() METHOD gotoMark() METHOD goto() + METHOD removeTabs() + METHOD RemoveTrailingSpaces() + METHOD getSelectedText() ENDCLASS @@ -601,6 +604,61 @@ METHOD IdeEditsManager:insertText( cKey ) /*----------------------------------------------------------------------*/ +METHOD IdeEditsManager:RemoveTabs() + LOCAL qEdit, qDoc, cText, cSpaces + + IF empty( qEdit := ::getEditCurrent() ) + RETURN Self + ENDIF + + qDoc := QTextDocument():configure( qedit:document() ) + + IF !( qDoc:isEmpty() ) + cSpaces := space( ::nTabSpaces ) + + qDoc:setUndoRedoEnabled( .f. ) + + cText := qDoc:toPlainText() + qDoc:clear() + qDoc:setPlainText( strtran( cText, chr( 9 ), cSpaces ) ) + + qDoc:setUndoRedoEnabled( .t. ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditsManager:RemoveTrailingSpaces() + LOCAL qEdit, qDoc, cText, a_, s + + IF empty( qEdit := ::getEditCurrent() ) + RETURN Self + ENDIF + + qDoc := QTextDocument():configure( qedit:document() ) + + IF !( qDoc:isEmpty() ) + qDoc:setUndoRedoEnabled( .f. ) + + cText := qDoc:toPlainText() + + a_:= hbide_memoToArray( cText ) + FOR EACH s IN a_ + s := trim( s ) + NEXT + cText := hbide_arrayToMemo( a_ ) + + qDoc:clear() + qDoc:setPlainText( cText ) + + qDoc:setUndoRedoEnabled( .t. ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeEditsManager:zoom( nKey ) LOCAL nPointSize, qFont, oEdit, oEditor @@ -647,6 +705,17 @@ METHOD IdeEditsManager:printPreview() /*----------------------------------------------------------------------*/ +METHOD IdeEditsManager:getSelectedText() + LOCAL qEdit + + IF !empty( qEdit := ::oEM:getEditCurrent() ) + RETURN QTextCursor():configure( qEdit:textCursor() ):selectedText() + ENDIF + + RETURN "" + +/*----------------------------------------------------------------------*/ + METHOD IdeEditsManager:paintRequested( pPrinter ) LOCAL qPrinter @@ -1182,8 +1251,12 @@ METHOD IdeEditor:setDocumentProperties() ::qEdit:setPlainText( hb_memoRead( ::sourceFile ) ) qCursor:setPosition( ::nPos ) ::qEdit:setTextCursor( qCursor ) + QScrollBar():configure( ::qEdit:horizontalScrollBar() ):setValue( ::nHPos ) QScrollBar():configure( ::qEdit:verticalScrollBar() ):setValue( ::nVPos ) + + QTextDocument():configure( ::qEdit:document() ):setModified( .f. ) + ::qTabWidget:setTabIcon( ::qTabWidget:indexOf( ::oTab:oWidget ), ::resPath + "tabunmodified.png" ) ::lLoaded := .T. ENDIF @@ -1339,6 +1412,7 @@ CLASS IdeEdit INHERIT IdeObject DATA qSlots DATA lCursorPosChanging INIT .F. + DATA lModified INIT .F. METHOD new( oEditor, nMode ) METHOD create( oEditor, nMode ) @@ -1489,18 +1563,21 @@ METHOD IdeEdit:deHighlightPreviousLine() /*----------------------------------------------------------------------*/ METHOD IdeEdit:highlightCurrentLine() - LOCAL nCurLine, nLastLine, qCursor, lModified, qDoc, qEdit, qBlockFmt, qB + LOCAL nCurLine, nLastLine, qCursor, qDoc, qEdit, qBlockFmt, qB, lOldModified qEdit := ::qEdit qCursor := QTextCursor():new( qEdit:textCursor() ) + + qDoc := QTextDocument():configure( qEdit:document() ) + lOldModified := ::lModified + ::lModified := qDoc:isModified() + qCursor:beginEditBlock() nCurLine := qCursor:blockNumber() nLastLine := ::nLastLine IF !( nCurLine == nLastLine ) - qDoc := QTextDocument():configure( qEdit:document() ) - lModified := qDoc:isModified() ::deHighlightPreviousLine() @@ -1511,13 +1588,6 @@ METHOD IdeEdit:highlightCurrentLine() qCursor:setBlockFormat( qBlockFmt ) ENDIF ENDIF - - /* Infact these must not be called from here but because changing the format */ - /* Qt consider that document has been modified, hence I need to put them here */ - qDoc:setModified( lModified ) - ::qTabWidget:setTabIcon( ::qTabWidget:indexOf( ::oEditor:oTab:oWidget ), ; - ::resPath + iif( lModified, "tabmodified.png", "tabunmodified.png" ) ) - ::oDK:setStatusText( SB_PNL_MODIFIED, lModified ) ENDIF qCursor:endEditBlock() @@ -1527,6 +1597,15 @@ METHOD IdeEdit:highlightCurrentLine() ::qLastCursor := qCursor ENDIF + /* Infact these must not be called from here but because changing the format */ + /* Qt consider that document has been modified, hence I need to put them here */ + IF ( lOldModified != ::lModified ) + qDoc:setModified( ::lModified ) + ::qTabWidget:setTabIcon( ::qTabWidget:indexOf( ::oEditor:oTab:oWidget ), ; + ::resPath + iif( ::lModified, "tabmodified.png", "tabunmodified.png" ) ) + ::oDK:setStatusText( SB_PNL_MODIFIED, ::lModified ) + ENDIF + RETURN Self /*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbide/idefindreplace.prg b/harbour/contrib/hbide/idefindreplace.prg index 386b338b80..b5808e4c59 100644 --- a/harbour/contrib/hbide/idefindreplace.prg +++ b/harbour/contrib/hbide/idefindreplace.prg @@ -138,6 +138,7 @@ METHOD IdeFindReplace:destroy() /*----------------------------------------------------------------------*/ METHOD IdeFindReplace:show() + LOCAL cText, qLineEdit ::oUI:q_buttonReplace:setEnabled( .f. ) ::oUI:q_checkGlobal:setEnabled( .f. ) @@ -145,6 +146,13 @@ METHOD IdeFindReplace:show() ::oUI:q_checkListOnly:setChecked( .f. ) ::oIde:setPosByIni( ::oUI:oWidget, FindDialogGeometry ) ::oUI:q_comboFindWhat:setFocus() + + IF !empty( cText := ::oEM:getSelectedText() ) + qLineEdit := QLineEdit():configure( ::oUI:q_comboFindWhat:lineEdit() ) + qLineEdit:setText( cText ) + qLineEdit:selectAll() + //QLineEdit( ::oUI:q_comboFindWhat:lineEdit() ):setText( cText ):selectAll() + ENDIF ::oUI:show() RETURN Self diff --git a/harbour/contrib/hbide/idesaveload.prg b/harbour/contrib/hbide/idesaveload.prg index 65eab989fe..dfbcca85ab 100644 --- a/harbour/contrib/hbide/idesaveload.prg +++ b/harbour/contrib/hbide/idesaveload.prg @@ -164,20 +164,23 @@ FUNCTION hbide_loadINI( oIde, cHbideIni ) "finddialoggeometry" , "themesdialoggeometry", "currenttheme", ; "currentcodec" } - DEFAULT cHbideIni TO "hbide.ini" - - IF ! hb_FileExists( cHbideIni ) - cHbideIni := hb_dirBase() + "hbide.ini" - ENDIF - oIde:cProjIni := cHbideIni - + /* Initiate the place holders */ oIde:aIni := Array( INI_SECTIONS_COUNT ) oIde:aIni[ 1 ] := afill( array( INI_HBIDE_VRBLS ), "" ) // FOR n := 2 TO INI_SECTIONS_COUNT - oIde:aIni[ n ] := Array( 0 ) + oIde:aIni[ n ] := Array( 0 ) NEXT + IF empty( cHbideIni ) + IF file( "hbide.ini" ) + cHbideIni := "hbide.ini" + ELSE + cHbideIni := hb_dirBase() + "hbide.ini" + ENDIF + ENDIF + oIde:cProjIni := cHbideIni + IF hb_FileExists( oIde:cProjIni ) aElem := hbide_readSource( oIde:cProjIni )