From e72c4aa9f1641bf692278fae392ba2e8d2a32682 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Wed, 25 Jan 2012 02:03:18 +0000 Subject: [PATCH] 2012-01-24 18:00 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/idefindreplace.prg * contrib/hbide/idesources.prg + Implemented: option in protocol. Please test and forward your suggessions as to what can be improved hereunder. --- harbour/ChangeLog | 7 ++ harbour/contrib/hbide/idefindreplace.prg | 100 ++++++++++++++++++++--- harbour/contrib/hbide/idesources.prg | 16 ++-- 3 files changed, 104 insertions(+), 19 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 022f4c5cb5..05e84fbcd2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,13 @@ The license applies to all entries newer than 2009-04-28. */ +2012-01-24 18:00 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbide/idefindreplace.prg + * contrib/hbide/idesources.prg + + Implemented: option in protocol. + Please test and forward your suggessions as to what can be + improved hereunder. + 2012-01-24 15:19 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/idedocks.prg * contrib/hbide/idemain.prg diff --git a/harbour/contrib/hbide/idefindreplace.prg b/harbour/contrib/hbide/idefindreplace.prg index 435ecd8b16..ae6fe9a805 100644 --- a/harbour/contrib/hbide/idefindreplace.prg +++ b/harbour/contrib/hbide/idefindreplace.prg @@ -203,7 +203,7 @@ METHOD IdeUpDown:destroy() RETURN Self /*----------------------------------------------------------------------*/ -// +// IdeSearchReplace - Extended Window at the bottom /*----------------------------------------------------------------------*/ CLASS IdeSearchReplace INHERIT IdeObject @@ -420,7 +420,7 @@ CLASS IdeFindReplace INHERIT IdeObject METHOD create( oIde ) METHOD destroy() METHOD show() - METHOD onClickReplace() + METHOD onClickReplace( nFrom ) METHOD replaceSelection( cReplWith ) METHOD replace() METHOD onClickFind( nFrom ) @@ -470,21 +470,20 @@ METHOD IdeFindReplace:create( oIde ) ::oUI:connect( QEvent_Close, {|| ::oIde:oINI:cFindDialogGeometry := hbide_posAndSize( ::oUI:oWidget ) } ) - ::oUI:q_buttonFind :connect( "clicked()", {|| ::onClickFind() } ) - ::oUI:q_buttonReplace:connect( "clicked()", {|| ::onClickReplace() } ) - ::oUI:q_buttonClose :connect( "clicked()", {|| ::oIde:oINI:cFindDialogGeometry := hbide_posAndSize( ::oUI:oWidget ), ::oUI:hide() } ) - ::oUI:q_comboFindWhat:connect( "editTextChanged(QString)", {|| ::oUI:q_radioEntire:setChecked( .t. ) } ) + ::oUI:q_buttonFind :connect( "clicked()" , {| | ::onClickFind() } ) + ::oUI:q_buttonReplace:connect( "clicked()" , {| | ::onClickReplace() } ) + ::oUI:q_buttonClose :connect( "clicked()" , {| | ::oIde:oINI:cFindDialogGeometry := hbide_posAndSize( ::oUI:oWidget ), ::oUI:hide() } ) + ::oUI:q_comboFindWhat:connect( "editTextChanged(QString)" , {| | ::oUI:q_radioEntire:setChecked( .t. ) } ) ::oUI:q_comboFindWhat:connect( "currentIndexChanged(QString)", {|p| ::oIde:oSBar:getItem( SB_PNL_SEARCH ):caption := "FIND: " + p } ) - ::oUI:q_checkListOnly:connect( "stateChanged(int)", {|p| ; - ::oUI:q_comboReplaceWith:setEnabled( p == 0 ), ; - iif( p == 1, ::oUI:q_buttonReplace:setEnabled( .f. ), NIL ) } ) + ::oUI:q_checkListOnly:connect( "stateChanged(int)" , {|p| ::oUI:q_comboReplaceWith:setEnabled( p == 0 ), ; + iif( p == 1, ::oUI:q_buttonReplace:setEnabled( .f. ), NIL ) } ) ::qLineEdit := ::oUI:q_comboFindWhat:lineEdit() ::qLineEdit:connect( "returnPressed()", {|| iif( empty( ::cText ), NIL, ; - ::qLineEdit:setText( ::cText ) ), ::cText := "", ::onClickFind( 1 ) } ) + ::qLineEdit:setText( ::cText ) ), ::cText := "", ::onClickFind( 1 ) } ) ::qReplaceEdit := ::oUI:q_comboReplaceWith:lineEdit() - ::qReplaceEdit:connect( "returnPressed()", {|| ::onClickReplace() } ) + ::qReplaceEdit:connect( "returnPressed()", {|| ::onClickReplace( 1 ) } ) RETURN Self @@ -581,9 +580,12 @@ METHOD IdeFindReplace:find( lWarn ) /*----------------------------------------------------------------------*/ -METHOD IdeFindReplace:onClickReplace() +METHOD IdeFindReplace:onClickReplace( nFrom ) - ::updateFindReplaceData( "replace" ) + DEFAULT nFrom TO 0 // Click on Find Button + IF nFrom == 0 + ::updateFindReplaceData( "replace" ) + ENDIF IF ::oUI:q_comboReplaceWith:isEnabled() ::replace() @@ -609,6 +611,7 @@ METHOD IdeFindReplace:replaceSelection( cReplWith ) qCursor:setPosition( nB + len( cReplWith ) ) ::qCurEdit:setTextCursor( qCursor ) ::oEM:getEditObjectCurrent():clearSelection() + qCursor:endEditBlock() ENDIF RETURN Self @@ -741,6 +744,7 @@ CLASS IdeFindInFiles INHERIT IdeObject METHOD execEvent( cEvent, p ) METHOD execContextMenu( p ) METHOD buildUI() + METHOD replaceAll() ENDCLASS @@ -899,6 +903,7 @@ METHOD IdeFindInFiles:execEvent( cEvent, p ) EXIT CASE "buttonRepl" + ::replaceAll() EXIT CASE "buttonStop" @@ -960,6 +965,75 @@ METHOD IdeFindInFiles:execEvent( cEvent, p ) /*----------------------------------------------------------------------*/ +METHOD IdeFindInFiles:replaceAll() + LOCAL nL, nB, qCursor, aFind + LOCAL isOpen := .f. + LOCAL isModified := .f. + LOCAL cSource := "" + + IF empty( ::cReplWith := ::oUI:q_comboRepl:currentText() ) + RETURN Self + ENDIF + nL := len( ::cReplWith ) + + IF ! hbide_getYesNo( "Starting REPLACE operation", "No way to interrupt", "Critical" ) + RETURN Self + ENDIF + + FOR EACH aFind IN ::aInfo + IF aFind[ 1 ] == -2 + IF ! ( cSource == aFind[ 2 ] ) + IF ! empty( cSource ) + IF ! isOpen + ::oSM:closeSource( , .f., .f., .f. ) + ELSE + IF ! isModified + ::oSM:saveSource() + ENDIF + ENDIF + ENDIF + cSource := aFind[ 2 ] + IF ( isOpen := ::oEM:isOpen( cSource ) ) + ::oEM:setSourceVisible( cSource ) + isModified := ::oEM:getEditorCurrent():qDocument:isModified() + ELSE + ::oSM:editSource( cSource, 0, 0, 0, NIL, NIL, .f., .t. ) + ENDIF + ENDIF + + qCursor := ::oIde:qCurEdit:textCursor() + qCursor:setPosition( 0 ) + qCursor:movePosition( QTextCursor_Down, QTextCursor_MoveAnchor, aFind[ 3 ] - 1 ) + qCursor:movePosition( QTextCursor_Right, QTextCursor_MoveAnchor, aFind[ 4 ] - 1 ) + qCursor:movePosition( QTextCursor_Right, QTextCursor_KeepAnchor, len( aFind[ 5 ] ) ) + ::qCurEdit:setTextCursor( qCursor ) + + nB := qCursor:position() + + qCursor:beginEditBlock() + qCursor:removeSelectedText() + qCursor:insertText( ::cReplWith ) + qCursor:setPosition( nB + nL ) + ::qCurEdit:setTextCursor( qCursor ) + ::oEM:getEditObjectCurrent():clearSelection() + qCursor:endEditBlock() + ENDIF + NEXT + + IF ! empty( cSource ) + IF ! isOpen + ::oSM:closeSource( , .f., .f., .f. ) + ELSE + IF ! isModified + ::oSM:saveSource() + ENDIF + ENDIF + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeFindInFiles:execContextMenu( p ) LOCAL nLine, qCursor, qMenu, qAct, cAct, cFind diff --git a/harbour/contrib/hbide/idesources.prg b/harbour/contrib/hbide/idesources.prg index 75250181a4..036ceb5ec0 100644 --- a/harbour/contrib/hbide/idesources.prg +++ b/harbour/contrib/hbide/idesources.prg @@ -80,7 +80,7 @@ CLASS IdeSourcesManager INHERIT IdeObject METHOD saveSource( nTab, lCancel, lAs ) METHOD saveNamedSource( cSource ) METHOD editSource( cSourceFile, nPos, nHPos, nVPos, cTheme, cView, lAlert, lVisible, aBookMarks ) - METHOD closeSource( nTab, lCanCancel, lCanceled ) + METHOD closeSource( nTab, lCanCancel, lCanceled, lAsk ) METHOD closeAllSources( lCanCancel ) METHOD closeAllOthers( nTab ) METHOD saveAllSources() @@ -215,7 +215,7 @@ METHOD IdeSourcesManager:saveSource( nTab, lCancel, lAs ) LOCAL oEdit, lNew, cBuffer, qDocument, nIndex, cSource, cFileTemp LOCAL cFileToSave, cFile, cExt, cNewFile, oItem - DEFAULT nTab TO ::EM:getTabCurrent() + DEFAULT nTab TO ::oEM:getTabCurrent() DEFAULT lAs TO .F. lCancel := .F. @@ -293,11 +293,12 @@ METHOD IdeSourcesManager:saveSource( nTab, lCancel, lAs ) /*----------------------------------------------------------------------*/ -METHOD IdeSourcesManager:closeSource( nTab, lCanCancel, lCanceled ) +METHOD IdeSourcesManager:closeSource( nTab, lCanCancel, lCanceled, lAsk ) LOCAL lSave, n, oEditor DEFAULT nTab TO ::oEM:getTabCurrent() - + DEFAULT lAsk TO .t. + IF !empty( oEditor := ::oEM:getEditorByTabPosition( nTab ) ) DEFAULT lCanCancel TO .F. @@ -314,8 +315,11 @@ METHOD IdeSourcesManager:closeSource( nTab, lCanCancel, lCanceled ) lSave := ( n == QMessageBox_Yes ) ELSE - lSave := hbide_getYesNo( oEditor:oTab:Caption, "has been modified, save this source?", 'Save?' ) - + IF lAsk + lSave := hbide_getYesNo( oEditor:oTab:Caption, "has been modified, save this source?", 'Save?' ) + ELSE + lSave := .t. + ENDIF ENDIF IF lSave .AND. !( ::saveSource( nTab, @lCanceled ) )