From 57efc2cee14a30a2339439d1c5158e69af430399 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Sat, 13 Feb 2010 11:44:30 +0000 Subject: [PATCH] 2010-02-13 03:07 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt_hbqplaintextedit.cpp * contrib/hbqt/hbqt_hbqplaintextedit.h * contrib/hbqt/qtgui/HBQPlainTextEdit.cpp * contrib/hbqt/qtgui/THBQPlainTextEdit.prg * contrib/hbqt/qth/HBQPlainTextEdit.qth * contrib/hbide/resources/skeletons.ui * contrib/hbide/resources/skeletons.uic * contrib/hbide/hbide.prg * contrib/hbide/ideactions.prg * contrib/hbide/idedocks.prg * contrib/hbide/ideeditor.prg * contrib/hbide/ideobject.prg * contrib/hbide/idesaveload.prg + Implemented "Invert Case" feature. % All operations applied on selected text do not remove selections. However "undo/redo" does not respect selections. + Added main-menu option which presents toggling feature for all implemented docked windows. It facilitates clubbing all toggle actions at one convenient place. + Implemented "Code Skeletons". How to write ============ * Click main-menu option and select . * "Code Skeletons" window will open at the right-docking area. * Close other docks if open to make room for its components. * Click button, a dialog will appear requesting a "Name". * Enter recognizable name for this skeleton, i.e., "DO CASE 3", where "3" will represent that this case statement contains 3 iterations of CASE statement. It is just an example, follow your way of recognitions. * After you click the name will appear in "Identity" list-box. * Start writing in "Code Snippet" editor, like: DO CASE CASE x == CASE x == CASE x == ENDCASE * After you are done with it, click . * Repeat the process for some other skeletons. * Do not forget to click even after slightest modification. This will ensure that your skeleton is always in order. * If you wish to change the name, click on that "Name" in "Identity" list-box and click , follow next process. Click to save permanently. * is not working yet. * Navigate the skeletons by clicking on the prompts; you will find the attached code in the editor below. How to Call =========== * While in the editor tab, position your editing cursor at desired column. * Press Ctrl+K, a context menu will appear near left-upper part of the editing tab containing all skeletons you wrote. * Use arrow-up/down keys to desired skeleton and press . * The code skeleton will be inserted in the source aligned to the column you started with. The cursor will be anchored on the same place. * Alternativly you can use mouse, but keyboard navigation is simple in this context. * Note that alignment and indent of inserted code skeleton is perfect to starting column. Note: Your suggessions are welcome to enhance this feature. --- harbour/ChangeLog | 72 ++++++++ harbour/contrib/hbide/hbide.prg | 21 ++- harbour/contrib/hbide/ideactions.prg | 20 +++ harbour/contrib/hbide/idedocks.prg | 37 +++- harbour/contrib/hbide/ideeditor.prg | 60 +++++-- harbour/contrib/hbide/ideobject.prg | 2 + harbour/contrib/hbide/idesaveload.prg | 73 +++++++- harbour/contrib/hbide/resources/skeletons.ui | 23 +++ harbour/contrib/hbide/resources/skeletons.uic | 30 +++- .../contrib/hbqt/hbqt_hbqplaintextedit.cpp | 167 ++++++++++++------ harbour/contrib/hbqt/hbqt_hbqplaintextedit.h | 1 + .../contrib/hbqt/qtgui/HBQPlainTextEdit.cpp | 8 + .../contrib/hbqt/qtgui/THBQPlainTextEdit.prg | 5 + harbour/contrib/hbqt/qth/HBQPlainTextEdit.qth | 1 + 14 files changed, 446 insertions(+), 74 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6f502b18ea..2f7aabd8fd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,78 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-02-13 03:43 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbqt/hbqt_hbqplaintextedit.cpp + * contrib/hbqt/hbqt_hbqplaintextedit.h + * contrib/hbqt/qtgui/HBQPlainTextEdit.cpp + * contrib/hbqt/qtgui/THBQPlainTextEdit.prg + * contrib/hbqt/qth/HBQPlainTextEdit.qth + + * contrib/hbide/resources/skeletons.ui + * contrib/hbide/resources/skeletons.uic + + * contrib/hbide/hbide.prg + * contrib/hbide/ideactions.prg + * contrib/hbide/idedocks.prg + * contrib/hbide/ideeditor.prg + * contrib/hbide/ideobject.prg + * contrib/hbide/idesaveload.prg + + + Implemented "Invert Case" feature. + + % All operations applied on selected text do not remove selections. + However "undo/redo" does not respect selections. + + + Added main-menu option which presents toggling feature + for all implemented docked windows. It facilitates clubbing + all toggle actions at one convenient place. + + + Implemented "Code Skeletons". + How to write + ============ + * Click main-menu option and select . + * "Code Skeletons" window will open at the right-docking area. + * Close other docks if open to make room for its components. + * Click button, a dialog will appear requesting a "Name". + * Enter recognizable name for this skeleton, i.e., "DO CASE 3", + where "3" will represent that this case statement contains 3 + iterations of CASE statement. It is just an example, follow + your way of recognitions. + * After you click the name will appear in "Identity" list-box. + * Start writing in "Code Snippet" editor, like: + DO CASE + CASE x == + CASE x == + CASE x == + ENDCASE + * After you are done with it, click . + * Repeat the process for some other skeletons. + * Do not forget to click even after slightest modification. + This will ensure that your skeleton is always in order. + * If you wish to change the name, click on that "Name" in + "Identity" list-box and click , follow next process. + Click to save permanently. + * is not working yet. + * Navigate the skeletons by clicking on the prompts; you will + find the attached code in the editor below. + + How to Call + =========== + * While in the editor tab, position your editing cursor at + desired column. + * Press Ctrl+K, a context menu will appear near left-upper part + of the editing tab containing all skeletons you wrote. + * Use arrow-up/down keys to desired skeleton and press . + * The code skeleton will be inserted in the source aligned + to the column you started with. The cursor will be anchored + on the same place. + * Alternativly you can use mouse, but keyboard navigation is + simple in this context. + * Note that alignment and indent of inserted code skeleton is + perfect to starting column. + + Note: Your suggessions are welcome to enhance this feature. + 2010-02-13 12:36 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/strapi.c ! fixed hb_[w]strunshare() functions to always clone writable diff --git a/harbour/contrib/hbide/hbide.prg b/harbour/contrib/hbide/hbide.prg index 1e30f29dca..a440ec0a31 100644 --- a/harbour/contrib/hbide/hbide.prg +++ b/harbour/contrib/hbide/hbide.prg @@ -91,6 +91,14 @@ STATIC s_pathSep PROCEDURE Main( cProjIni ) LOCAL oIde + /* Testing paths */ + #ifdef __TESTING_PATHS__ +hbide_dbg( hbmk2_PathMakeRelative( "C:\dev_projects", "C:\dev_sources\vouch\myfile.prg", .f. ) ) +hbide_dbg( hbmk2_PathMakeRelative( "C:\dev_projects", "C:\dev_sources\vouch\myfile.prg", .t. ) ) +hbide_dbg( hbmk2_PathMakeRelative( "C:/dev_projects", "C:/dev_sources/vouch/myfile.prg", .t. ) ) +hbide_dbg( hbmk2_PathMakeRelative( "C:\dev_projects", "C:/dev_sources/vouch/myfile.prg", .t. ) ) + #endif + SET CENTURY ON SET EPOCH TO 1970 @@ -210,6 +218,7 @@ CLASS HbIde DATA oEnvironment + DATA cPathSkltns INIT "" DATA cSaveTo INIT "" DATA oOpenedSources DATA resPath INIT hb_DirBase() + "resources" + hb_OsPathSeparator() @@ -224,6 +233,7 @@ CLASS HbIde DATA aTags INIT {} DATA aText INIT {} + DATA aSkltns INIT {} DATA aSources INIT {} DATA aFuncList INIT {} DATA aLines INIT {} @@ -301,6 +311,10 @@ METHOD HbIde:create( cProjIni ) ::cWrkFolderFind := ::aINI[ INI_HBIDE, CurrentFolderFind ] ::cWrkReplace := ::aINI[ INI_HBIDE, CurrentReplace ] ::cWrkView := ::aINI[ INI_HBIDE, CurrentView ] + + /* Load Code Skeletons */ + hbide_loadSkltns( Self ) + /* Set Codec at the Begining */ HbXbp_SetCodec( ::cWrkCodec ) @@ -310,14 +324,13 @@ METHOD HbIde:create( cProjIni ) ::oDK:buildDialog() /* Actions */ ::oAC := IdeActions():new( Self ):create() + /* Docking Widgets */ + ::oDK:buildDockWidgets() /* Toolbar */ ::oAC:buildToolBar() /* Main Menu */ ::oAC:buildMainMenu() - /* Docking Widgets */ - ::oDK:buildDockWidgets() - /* Once create Find/Replace dialog */ ::oFR := IdeFindReplace():new( Self ):create() @@ -434,6 +447,8 @@ METHOD HbIde:create( cProjIni ) ::oFR:destroy() ::oEM:destroy() + ::oDK:destroy() +* ::oAC:destroy() /* GPF */ ::oDlg:destroy() ::oAC:destroy() diff --git a/harbour/contrib/hbide/ideactions.prg b/harbour/contrib/hbide/ideactions.prg index 8dc8f17492..401fcc323d 100644 --- a/harbour/contrib/hbide/ideactions.prg +++ b/harbour/contrib/hbide/ideactions.prg @@ -574,7 +574,27 @@ METHOD IdeActions:buildMainMenu() oSubMenu2 := hbide_buildCodecMenu( oIde, oSubMenu ) oSubMenu2:title := "~Codecs" oSubMenu:addItem( { oSubMenu2, NIL } ) + hbide_menuAddSep( oSubMenu ) oMenuBar:addItem( { oSubMenu, NIL } ) + oSubMenu:oWidget:addAction_4( ::oSkeltn:oWidget:toggleViewAction() ) + + /*----------------------------------------------------------------------------*/ + /* Docks */ + /*----------------------------------------------------------------------------*/ + oSubMenu := XbpMenu():new( oMenuBar ):create() + oSubMenu:title := "~Docks" + oMenuBar:addItem( { oSubMenu, NIL } ) + + oSubMenu:oWidget:addAction_4( ::oDockED:oWidget:toggleViewAction() ) + oSubMenu:oWidget:addAction_4( ::oDockPT:oWidget:toggleViewAction() ) + + oSubMenu:oWidget:addAction_4( ::oDockR:oWidget:toggleViewAction() ) + oSubMenu:oWidget:addAction_4( ::oHelp:oWidget:toggleViewAction() ) + oSubMenu:oWidget:addAction_4( ::oSkeltn:oWidget:toggleViewAction() ) + + oSubMenu:oWidget:addAction_4( ::oDockB2:oWidget:toggleViewAction() ) + oSubMenu:oWidget:addAction_4( ::oDockB1:oWidget:toggleViewAction() ) + oSubMenu:oWidget:addAction_4( ::oDockB:oWidget:toggleViewAction() ) /*----------------------------------------------------------------------------*/ /* Help */ diff --git a/harbour/contrib/hbide/idedocks.prg b/harbour/contrib/hbide/idedocks.prg index 07190bcfa4..5895eb5869 100644 --- a/harbour/contrib/hbide/idedocks.prg +++ b/harbour/contrib/hbide/idedocks.prg @@ -127,6 +127,19 @@ METHOD IdeDocks:create( oIde ) /*----------------------------------------------------------------------*/ METHOD IdeDocks:destroy() + LOCAL oUI := ::oIde:oSkeltnUI + + ::disconnect( oUI:q_buttonNew , "clicked()" ) + ::disconnect( oUI:q_buttonRename, "clicked()" ) + ::disconnect( oUI:q_buttonDelete, "clicked()" ) + ::disconnect( oUI:q_buttonClear , "clicked()" ) + ::disconnect( oUI:q_buttonGetSel, "clicked()" ) + ::disconnect( oUI:q_buttonUpdate, "clicked()" ) + ::disconnect( oUI:q_listNames , "itemSelectionChanged()" ) + + oUI:destroy() + + /* Initiate more destructors */ RETURN Self @@ -796,13 +809,14 @@ METHOD IdeDocks:buildSkeletonWidget() //::oSkeltnUI:q_editCode:setFontPointSize( 10 ) //::oSkeltnUI:q_editCode:setFont( ::oFont:oWidget ) + aeval( ::aSkltns, {|e_| ::oSkeltnUI:q_listNames:addItem( e_[ 1 ] ) } ) RETURN Self /*----------------------------------------------------------------------*/ METHOD IdeDocks:execSkeleton( nMode, p ) - LOCAL cName, qItem, cCode + LOCAL cName, cNewName, qItem, cCode, n HB_SYMBOL_UNUSED( p ) @@ -811,13 +825,17 @@ METHOD IdeDocks:execSkeleton( nMode, p ) CASE 1 IF !empty( cName := hbide_fetchAString( ::oSkeltnUI:q_listNames, "", "Name", "New Skeleton" ) ) ::oSkeltnUI:q_listNames:addItem( cName ) + aadd( ::oIde:aSkltns, { cName, "" } ) + ::oSkeltnUI:q_listNames:setCurrentRow( len( ::aSkltns ) - 1 ) ENDIF EXIT CASE 2 qItem := QListWidgetItem():configure( ::oSkeltnUI:q_listNames:currentItem() ) cName := qItem:text() - IF !empty( cName := hbide_fetchAString( ::oSkeltnUI:q_listNames, cName, "Name", "New Skeleton" ) ) - qItem:setText( cName ) + IF !empty( cNewName := hbide_fetchAString( ::oSkeltnUI:q_listNames, cName, "Name", "Change Skeleton's Name" ) ) + qItem:setText( cNewName ) + n := ascan( ::aSkltns, {|e_| e_[ 1 ] == cName } ) + ::aSkltns[ n, 1 ] := cNewName ENDIF EXIT CASE 3 @@ -830,15 +848,26 @@ METHOD IdeDocks:execSkeleton( nMode, p ) CASE 5 IF !empty( cCode := ::oEM:getSelectedText() ) // TODO: Format cCode + cCode := strtran( cCode, chr( 0x2029 ), chr( 10 ) ) ::oSkeltnUI:q_editCode:setPlainText( cCode ) ENDIF EXIT CASE 6 // Update the skeleton code and save the skeleton's buffer | file + qItem := QListWidgetItem():configure( ::oSkeltnUI:q_listNames:currentItem() ) + cName := qItem:text() + IF !empty( cName ) + n := ascan( ::aSkltns, {|e_| e_[ 1 ] == cName } ) + ::aSkltns[ n,2 ] := ::oSkeltnUI:q_editCode:toPlainText() + hbide_saveSkltns( ::oIde ) + ENDIF EXIT CASE 7 - + qItem := QListWidgetItem():configure( ::oSkeltnUI:q_listNames:currentItem() ) + cName := qItem:text() + n := ascan( ::aSkltns, {|e_| e_[ 1 ] == cName } ) + ::oSkeltnUI:q_editCode:setPlainText( ::aSkltns[ n,2 ] ) EXIT ENDSWITCH diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg index 446c8646ac..e1191bb47e 100644 --- a/harbour/contrib/hbide/ideeditor.prg +++ b/harbour/contrib/hbide/ideeditor.prg @@ -835,7 +835,7 @@ METHOD IdeEditsManager:getSelectedText() LOCAL qEdit IF !empty( qEdit := ::oEM:getEditCurrent() ) - RETURN QTextCursor():configure( qEdit:textCursor() ):selectedText() + RETURN qEdit:getSelectedText() ENDIF RETURN "" @@ -1135,7 +1135,6 @@ METHOD IdeEditor:setDocumentProperties() qCursor := QTextCursor():configure( ::qEdit:textCursor() ) IF !( ::lLoaded ) /* First Time */ -// ::qEdit:clear() ::qEdit:setPlainText( hb_memoRead( ::sourceFile ) ) qCursor:setPosition( ::nPos ) ::qEdit:setTextCursor( qCursor ) @@ -1376,6 +1375,7 @@ CLASS IdeEdit INHERIT IdeObject METHOD caseInvert() METHOD findLastIndent() METHOD reLayMarkButtons() + METHOD presentSkeletons() ENDCLASS @@ -1530,7 +1530,7 @@ METHOD IdeEdit:execEvent( nMode, oEdit, p, p1 ) ::relayMarkButtons() /* An experimental move but seems a lot is required to achieve column selection */ -* qEdit:highlightSelectedColumns( ::isColumnSelectionEnabled ) + qEdit:highlightSelectedColumns( ::isColumnSelectionEnabled ) ::oDK:setStatusText( SB_PNL_SELECTEDCHARS, len( qCursor:selectedText() ) ) @@ -1636,6 +1636,11 @@ METHOD IdeEdit:execKeyEvent( nMode, nEvent, p ) ::duplicateLine() ENDIF EXIT + CASE Qt_Key_K + IF lCtrl + ::presentSkeletons() + ENDIF + EXIT CASE Qt_Key_Backspace hbide_justACall( txt, lAlt, lShift, lCtrl, qEvent, nMode ) EXIT @@ -1667,6 +1672,43 @@ METHOD IdeEdit:execKeyEvent( nMode, nEvent, p ) /*----------------------------------------------------------------------*/ +METHOD IdeEdit:presentSkeletons() + LOCAL qCrs, qMenu, pAct, cAct, n, a_, qAct, nPos, nCol, s + + IF !empty( ::aSkltns ) + qCrs := QTextCursor():configure( ::qEdit:textCursor() ) + + //qRc := QRect():configure( ::qEdit:cursorRect() ) + + qMenu := QMenu():new( ::qEdit ) + FOR EACH a_ IN ::aSkltns + qMenu:addAction( a_[ 1 ] ) + NEXT + + pAct := qMenu:exec_1( ::qEdit:mapToGlobal( QPoint():new( 100,100 ) ) ) + IF !hbqt_isEmptyQtPointer( pAct ) + qAct := QAction():configure( pAct ) + cAct := qAct:text() + IF ( n := ascan( ::aSkltns, {|e_| e_[ 1 ] == cAct } ) ) > 0 + nPos := qCrs:position() + nCol := qCrs:columnNumber() + a_:= hbide_memoToArray( ::aSkltns[ n,2 ] ) + FOR EACH s IN a_ + IF s:__enumIndex() > 1 + s := space( nCol ) + s + ENDIF + NEXT + qCrs:insertText( hbide_arrayToMemo( a_ ) ) + qCrs:setPosition( nPos ) + ::qEdit:setTextCursor( qCrs ) + ENDIF + ENDIF + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + METHOD IdeEdit:gotoMark( nIndex ) IF len( ::aBookMarks ) >= nIndex ::qEdit:gotoBookmark( ::aBookMarks[ nIndex ] ) @@ -1760,23 +1802,21 @@ METHOD IdeEdit:caseLower() /*----------------------------------------------------------------------*/ METHOD IdeEdit:caseInvert() - LOCAL qCursor, i, c, s, cBuffer, nLen // qDoc, nBlock + LOCAL i, c, s, cBuffer, nLen - qCursor := QTextCursor():configure( ::qCurEdit:textCursor() ) - IF qCursor:hasSelection() .AND. ! empty( cBuffer := qCursor:selectedText() ) - //qDoc := QTextDocument()configure( ::qEdit:document() ) + IF !empty( cBuffer := ::oEM:getSelectedText() ) s := "" nLen := len( cBuffer ) - //nStart := qCursor:startSelection() + FOR i := 1 TO nLen c := substr( cBuffer, i, 1 ) - IF isAlpha( c ) //!( c $ CRLF ) .AND. + IF isAlpha( c ) s += iif( isUpper( c ), lower( c ), upper( c ) ) ELSE s += c ENDIF NEXT -hbide_dbg( s ) + ::qEdit:replaceSelection( s ) ENDIF diff --git a/harbour/contrib/hbide/ideobject.prg b/harbour/contrib/hbide/ideobject.prg index e0507ef857..ef037d62ec 100644 --- a/harbour/contrib/hbide/ideobject.prg +++ b/harbour/contrib/hbide/ideobject.prg @@ -135,11 +135,13 @@ CLASS IdeObject ACCESS aProjData INLINE ::oIde:aProjData ACCESS aTabs INLINE ::oIde:aTabs ACCESS aViews INLINE ::oIde:aViews + ACCESS aSkltns INLINE ::oIde:aSkltns ACCESS nCurView INLINE ::oIde:nCurView ACCESS nTabSpaces INLINE ::oIde:nTabSpaces ACCESS cTabSpaces INLINE ::oIde:cTabSpaces ACCESS cSeparator INLINE ::oIde:cSeparator + ACCESS cPathSkltns INLINE ::oIde:cPathSkltns ACCESS oDockPT INLINE ::oIde:oDockPT ACCESS oProjTree INLINE ::oIde:oProjTree diff --git a/harbour/contrib/hbide/idesaveload.prg b/harbour/contrib/hbide/idesaveload.prg index 56b15b9fb1..0091c63f85 100644 --- a/harbour/contrib/hbide/idesaveload.prg +++ b/harbour/contrib/hbide/idesaveload.prg @@ -214,7 +214,7 @@ FUNCTION hbide_loadINI( oIde, cHbideIni ) NEXT IF empty( cHbideIni ) - IF file( "hbide.ini" ) + IF hb_fileExists( "hbide.ini" ) cHbideIni := "hbide.ini" ELSE cHbideIni := hb_dirBase() + "hbide.ini" @@ -360,3 +360,74 @@ FUNCTION hbide_restSettings( oIde ) RETURN nil /*----------------------------------------------------------------------*/ + +FUNCTION hbide_loadSkltns( oIde, cPathSkltns ) + LOCAL cPath, s, n, cSkltn, cCode + + IF empty( cPathSkltns ) + hb_fNameSplit( oIde:cProjIni, @cPath ) + cPath += "hbide.skl" + + IF hb_fileExists( cPath ) + cPathSkltns := cPath + ELSE + cPathSkltns := hb_dirBase() + "hbide.skl" + ENDIF + ENDIF + oIde:cPathSkltns := cPathSkltns + + IF hb_fileExists( cPathSkltns ) + s := hb_memoread( cPathSkltns ) + + DO WHILE .t. + IF ( n := at( "<", s ) ) == 0 + EXIT + ENDIF + s := substr( s, n + 1 ) + IF ( n := at( ">", s ) ) == 0 + EXIT + ENDIF + cSkltn := substr( s, 1, n - 1 ) + s := substr( s, n + 1 ) + IF ( n := at( "", s ) ) > 0 + cCode := substr( s, 1, n - 1 ) + cCode := alltrim( cCode ) + IF left( cCode, 1 ) $ chr( 13 ) + chr( 10 ) + cCode := substr( cCode, 2 ) + ENDIF + IF left( cCode, 1 ) $ chr( 13 ) + chr( 10 ) + cCode := substr( cCode, 2 ) + ENDIF + IF right( cCode, 1 ) $ chr( 13 ) + chr( 10 ) + cCode := substr( cCode, 1, len( cCode ) - 1 ) + ENDIF + IF right( cCode, 1 ) $ chr( 13 ) + chr( 10 ) + cCode := substr( cCode, 1, len( cCode ) - 1 ) + ENDIF + + aadd( oIde:aSkltns, { cSkltn, cCode } ) + s := substr( s, n + len( "" ) ) + ELSE + EXIT + ENDIF + ENDDO + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +FUNCTION hbide_saveSkltns( oIde ) + LOCAL a_, txt_:= {} + + FOR EACH a_ IN oIde:aSkltns + aadd( txt_, "<" + a_[ 1 ] + ">" ) + aeval( hbide_memoToArray( a_[ 2 ] ), {|e| aadd( txt_, e ) } ) + aadd( txt_, "" ) + aadd( txt_, "" ) + NEXT + + RETURN hbide_createTarget( oIde:cPathSkltns, txt_ ) + +/*----------------------------------------------------------------------*/ + diff --git a/harbour/contrib/hbide/resources/skeletons.ui b/harbour/contrib/hbide/resources/skeletons.ui index 087c29d03f..1b1d4752ea 100644 --- a/harbour/contrib/hbide/resources/skeletons.ui +++ b/harbour/contrib/hbide/resources/skeletons.ui @@ -40,6 +40,29 @@ + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Code Skeletons in hbIDE are implemented in unique way. </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">It is assumed that, while writing the source, any control structure</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">must be aligned to the column editing cursor is resting. So the</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">&quot;skeleton&quot; is inserted aligned to this column spanning multiple lines.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Hence it is desired that you write code snippets aligned left without</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">any spaces for the left-most edge:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">IF x == </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;"> y := 12</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">ELSE</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;"> y := 32</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">ENDIF</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Then, suppose edit cursor is resting on column 10, </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">all these lines will align to column 10. Inner indents will </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">be respected.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> + QPlainTextEdit::NoWrap diff --git a/harbour/contrib/hbide/resources/skeletons.uic b/harbour/contrib/hbide/resources/skeletons.uic index 9943eb3444..218c59129a 100644 --- a/harbour/contrib/hbide/resources/skeletons.uic +++ b/harbour/contrib/hbide/resources/skeletons.uic @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'skeletons.ui' ** -** Created: Fri Feb 12 18:01:10 2010 -** by: Qt User Interface Compiler version 4.5.3 +** Created: Sat Feb 13 03:04:34 2010 +** by: Qt User Interface Compiler version 4.5.0 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ @@ -109,6 +109,32 @@ public: labelIdentity->setText(QApplication::translate("Form", "Identity", 0, QApplication::UnicodeUTF8)); buttonDelete->setText(QApplication::translate("Form", "Delete", 0, QApplication::UnicodeUTF8)); buttonRename->setText(QApplication::translate("Form", "Rename", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + editCode->setToolTip(QApplication::translate("Form", "\n" +"\n" +"

Code Skeletons in hbIDE are implemented in unique way.

\n" +"

It is assumed that, while writing the source, any control structure

\n" +"

must be aligned to the column editing cursor is resting. So the

\n" +"

"skeleton" is inserted aligned to this column spanning multiple lines.

\n" +"

Hence it is desired that you write code snippets aligned left without

\n" +"

any spaces for the left-most edge:

\n" +"

\n" +"

I" + "F x ==

\n" +"

y := 12

\n" +"

ELSE

\n" +"

y := 32

\n" +"

ENDIF

\n" +"

\n" +"

Then, suppose edit cursor is resting on column 10,

\n" +"

all these lines will align to column 10. Inner indents will

\n" +"

be respected.

\n" +"

", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP buttonClear->setText(QApplication::translate("Form", "Clear", 0, QApplication::UnicodeUTF8)); labelSnippets->setText(QApplication::translate("Form", "Code Snippet", 0, QApplication::UnicodeUTF8)); buttonGetSel->setText(QApplication::translate("Form", "Get Selection", 0, QApplication::UnicodeUTF8)); diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp index 8524a1fcf8..3461a95fab 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.cpp @@ -429,44 +429,6 @@ void HBQPlainTextEdit::showHighlighter( const QString &style, bool b ) styleHightlighter = style; } -void HBQPlainTextEdit::caseUpper() -{ - QTextCursor cursor( textCursor() ); - QString selTxt( cursor.selectedText() ); - if( selTxt.isEmpty() ) - { - return; - } - QString txt = selTxt.toUpper(); - insertPlainText( txt ); -} - -void HBQPlainTextEdit::caseLower() -{ - QTextCursor cursor( textCursor() ); - QString selTxt( cursor.selectedText() ); - if( selTxt.isEmpty() ) - { - return; - } - QString txt = selTxt.toLower(); - insertPlainText( txt ); -} - -void HBQPlainTextEdit::replaceSelection( const QString & txt ) -{ - HB_SYMBOL_UNUSED( txt ); - - QTextCursor cursor( textCursor() ); - QString selTxt( cursor.selectedText() ); - if( selTxt.isEmpty() ) - { - return; - } - QString text = selTxt.toCaseFolded(); - insertPlainText( text ); -} - void HBQPlainTextEdit::escapeQuotes() { QTextCursor cursor( textCursor() ); @@ -515,30 +477,136 @@ void HBQPlainTextEdit::unescapeDQuotes() insertPlainText( txt ); } -void HBQPlainTextEdit::convertQuotes() +void HBQPlainTextEdit::caseUpper() { - QTextCursor cursor( textCursor() ); + QTextCursor cursor = textCursor(); QString selTxt( cursor.selectedText() ); if( selTxt.isEmpty() ) { return; } - QString txt = selTxt.replace( QString( "\"" ), QString( "\'" ) ); - insertPlainText( txt ); + int b = cursor.selectionStart(); + int e = cursor.selectionEnd(); + cursor.beginEditBlock(); + + insertPlainText( selTxt.toUpper() ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, e-b ); + cursor.endEditBlock(); + setTextCursor( cursor ); +} + +void HBQPlainTextEdit::caseLower() +{ + QTextCursor cursor = textCursor(); + QString selTxt( cursor.selectedText() ); + if( selTxt.isEmpty() ) + { + return; + } + int b = cursor.selectionStart(); + int e = cursor.selectionEnd(); + cursor.beginEditBlock(); + + insertPlainText( selTxt.toLower() ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, e-b ); + cursor.endEditBlock(); + setTextCursor( cursor ); +} + +void HBQPlainTextEdit::convertQuotes() +{ + QTextCursor cursor = textCursor(); + QString selTxt( cursor.selectedText() ); + if( selTxt.isEmpty() ) + { + return; + } + int b = cursor.selectionStart(); + int e = cursor.selectionEnd(); + cursor.beginEditBlock(); + + insertPlainText( selTxt.replace( QString( "\"" ), QString( "\'" ) ) ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, e-b ); + cursor.endEditBlock(); + setTextCursor( cursor ); } void HBQPlainTextEdit::convertDQuotes() { - QTextCursor cursor( textCursor() ); + QTextCursor cursor = textCursor(); QString selTxt( cursor.selectedText() ); if( selTxt.isEmpty() ) { return; } - QString txt = selTxt.replace( QString( "\'" ), QString( "\"" ) ); - insertPlainText( txt ); + int b = cursor.selectionStart(); + int e = cursor.selectionEnd(); + cursor.beginEditBlock(); + + insertPlainText( selTxt.replace( QString( "\'" ), QString( "\"" ) ) ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, e-b ); + cursor.endEditBlock(); + setTextCursor( cursor ); } +void HBQPlainTextEdit::replaceSelection( const QString & txt ) +{ + QTextCursor cursor = textCursor(); + QString selTxt( cursor.selectedText() ); + if( selTxt.isEmpty() ) + { + return; + } + int b = cursor.selectionStart(); + cursor.beginEditBlock(); + + insertPlainText( txt ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, txt.length() ); + cursor.endEditBlock(); + setTextCursor( cursor ); +} + +void HBQPlainTextEdit::streamComment() +{ + QTextCursor cursor = textCursor(); + QString selTxt( cursor.selectedText() ); + if( selTxt.isEmpty() ) + { + return; + } + int b = cursor.selectionStart(); + int e = cursor.selectionEnd(); + cursor.beginEditBlock(); + + insertPlainText( "/*" + selTxt + "*/" ); + + cursor.setPosition( b ); + cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, e-b+4 ); + cursor.endEditBlock(); + setTextCursor( cursor ); +} + +QString HBQPlainTextEdit::getSelectedText() +{ + QTextCursor cursor( textCursor() ); + QString selTxt( cursor.selectedText() ); + if( selTxt.isEmpty() ) + { + return ""; + } + QString txt = selTxt.replace( 0x2029, QString( "\n" ) ); + return txt; +} void HBQPlainTextEdit::paintColumnSelection( QPaintEvent *event ) { @@ -769,15 +837,6 @@ void HBQPlainTextEdit::blockComment() setTextCursor( c ); } -void HBQPlainTextEdit::streamComment() -{ - QTextCursor cursor = textCursor(); - QString textUnderCursor = cursor.selectedText(); - if( textUnderCursor.isEmpty() ) - return; - insertPlainText( "/*" + textUnderCursor + "*/" ); -} - void HBQPlainTextEdit::duplicateLine() { QTextCursor cursor = textCursor(); diff --git a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h index afa854ec7e..708fba8b62 100644 --- a/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h +++ b/harbour/contrib/hbqt/hbqt_hbqplaintextedit.h @@ -149,6 +149,7 @@ public slots: void replaceSelection( const QString & txt ); void insertTab( int mode ); void highlightSelectedColumns( bool yes ); + QString getSelectedText(); private slots: void slotCursorPositionChanged(); diff --git a/harbour/contrib/hbqt/qtgui/HBQPlainTextEdit.cpp b/harbour/contrib/hbqt/qtgui/HBQPlainTextEdit.cpp index 7ce3efcd06..281266dfe2 100644 --- a/harbour/contrib/hbqt/qtgui/HBQPlainTextEdit.cpp +++ b/harbour/contrib/hbqt/qtgui/HBQPlainTextEdit.cpp @@ -395,6 +395,14 @@ HB_FUNC( QT_HBQPLAINTEXTEDIT_HIGHLIGHTSELECTEDCOLUMNS ) hbqt_par_HBQPlainTextEdit( 1 )->highlightSelectedColumns( hb_parl( 2 ) ); } +/* + * QString getSelectedText() + */ +HB_FUNC( QT_HBQPLAINTEXTEDIT_GETSELECTEDTEXT ) +{ + hb_retc( hbqt_par_HBQPlainTextEdit( 1 )->getSelectedText().toAscii().data() ); +} + /*----------------------------------------------------------------------*/ #endif /* #if QT_VERSION >= 0x040500 */ diff --git a/harbour/contrib/hbqt/qtgui/THBQPlainTextEdit.prg b/harbour/contrib/hbqt/qtgui/THBQPlainTextEdit.prg index a662e276a4..fb50fd333a 100644 --- a/harbour/contrib/hbqt/qtgui/THBQPlainTextEdit.prg +++ b/harbour/contrib/hbqt/qtgui/THBQPlainTextEdit.prg @@ -97,6 +97,7 @@ CREATE CLASS HBQPlainTextEdit INHERIT HbQtObjectHandler, QPlainTextEdit METHOD deleteLine() METHOD moveLine( nIDirection ) METHOD highlightSelectedColumns( lYes ) + METHOD getSelectedText() ENDCLASS @@ -229,3 +230,7 @@ METHOD HBQPlainTextEdit:moveLine( nIDirection ) METHOD HBQPlainTextEdit:highlightSelectedColumns( lYes ) RETURN Qt_HBQPlainTextEdit_highlightSelectedColumns( ::pPtr, lYes ) + +METHOD HBQPlainTextEdit:getSelectedText() + RETURN Qt_HBQPlainTextEdit_getSelectedText( ::pPtr ) + diff --git a/harbour/contrib/hbqt/qth/HBQPlainTextEdit.qth b/harbour/contrib/hbqt/qth/HBQPlainTextEdit.qth index e0147ac7f8..9c92c3d96f 100644 --- a/harbour/contrib/hbqt/qth/HBQPlainTextEdit.qth +++ b/harbour/contrib/hbqt/qth/HBQPlainTextEdit.qth @@ -128,6 +128,7 @@ HB_FUNC( QT_HBQPLAINTEXTEDIT ) void deleteLine() void moveLine( int iDirection ) void highlightSelectedColumns( bool yes ) + QString getSelectedText()