From 83cd26eed463059aa8e64317a2ee7e61df54f533 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 28 Jun 2010 08:19:55 +0000 Subject: [PATCH] 2010-06-28 01:12 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/hbide.hbp * contrib/hbide/hbide.prg * contrib/hbide/ideactions.prg + contrib/hbide/idebrowse.prg * contrib/hbide/idedocks.prg * contrib/hbide/ideeditor.prg * contrib/hbide/ideobject.prg * contrib/hbxbp/xbpbrowse.prg + Implemented: database tables manager ( dbu ). A work-in-progress but you can have a feel of it. 1. "View"->"Browser Widget"->Select a Table. 2. Hide the widget and repeat process 1, select another table. 3. The widget will now contain both browsers. NOTE: many surprises may be there, just bear with me, it is a quick commit. Refinements are scheduled for this whole week. --- harbour/ChangeLog | 21 ++ harbour/contrib/hbide/hbide.hbp | 1 + harbour/contrib/hbide/hbide.prg | 7 + harbour/contrib/hbide/ideactions.prg | 3 +- harbour/contrib/hbide/idebrowse.prg | 537 +++++++++++++++++++++++++++ harbour/contrib/hbide/idedocks.prg | 8 +- harbour/contrib/hbide/ideeditor.prg | 7 +- harbour/contrib/hbide/ideobject.prg | 1 + harbour/contrib/hbxbp/xbpbrowse.prg | 2 + 9 files changed, 579 insertions(+), 8 deletions(-) create mode 100644 harbour/contrib/hbide/idebrowse.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cef1964019..d52a3cba93 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,27 @@ The license applies to all entries newer than 2009-04-28. */ +2010-06-28 01:12 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbide/hbide.hbp + + * contrib/hbide/hbide.prg + * contrib/hbide/ideactions.prg + + contrib/hbide/idebrowse.prg + * contrib/hbide/idedocks.prg + * contrib/hbide/ideeditor.prg + * contrib/hbide/ideobject.prg + * contrib/hbxbp/xbpbrowse.prg + + + Implemented: database tables manager ( dbu ). + A work-in-progress but you can have a feel of it. + 1. "View"->"Browser Widget"->Select a Table. + 2. Hide the widget and repeat process 1, select another table. + 3. The widget will now contain both browsers. + + NOTE: many surprises may be there, just bear with me, + it is a quick commit. Refinements are scheduled for + this whole week. + 2010-06-27 19:34 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/toolsutilities.ui + Added "Plugin" "Init at startup" slots. diff --git a/harbour/contrib/hbide/hbide.hbp b/harbour/contrib/hbide/hbide.hbp index 9c1b9d120f..9318c18285 100644 --- a/harbour/contrib/hbide/hbide.hbp +++ b/harbour/contrib/hbide/hbide.hbp @@ -48,6 +48,7 @@ ideshortcuts.prg ideedit.prg ideplugins.prg idedict.prg +idebrowse.prg -pi=*.ui -plugin=resources/hbmk2_plugin_ui.prg diff --git a/harbour/contrib/hbide/hbide.prg b/harbour/contrib/hbide/hbide.prg index 665bd8fee5..323dcb496d 100644 --- a/harbour/contrib/hbide/hbide.prg +++ b/harbour/contrib/hbide/hbide.prg @@ -85,6 +85,9 @@ REQUEST HB_QT +REQUEST DBFCDX +REQUEST DBFNTX + STATIC s_resPath STATIC s_pathSep @@ -130,6 +133,7 @@ CLASS HbIde DATA cProjIni DATA oAC /* Actions Manager */ + DATA oBM /* Database Browser Manager */ DATA oDK /* Main Window Components Manager */ DATA oDW /* Document Writer Manager */ DATA oEM /* Editor Tabs Manager */ @@ -466,6 +470,9 @@ METHOD HbIde:create( aParams ) /* Home Implementation */ ::oHM := IdeHome():new():create( Self ) + /* Browser Manager */ + ::oBM := IdeBrowseManager():new():create( Self ) + /* Fill various elements of the IDE */ ::oPM:populate() ::oSM:loadSources() diff --git a/harbour/contrib/hbide/ideactions.prg b/harbour/contrib/hbide/ideactions.prg index 5e6f9948d1..64510dac1e 100644 --- a/harbour/contrib/hbide/ideactions.prg +++ b/harbour/contrib/hbide/ideactions.prg @@ -547,9 +547,8 @@ METHOD IdeActions:buildMainMenu() oSubMenu:oWidget:addAction_4( ::oThemesDock:oWidget:toggleViewAction() ) oSubMenu:oWidget:addAction_4( ::oFindDock:oWidget:toggleViewAction() ) oSubMenu:oWidget:addAction_4( ::oSourceThumbnailDock:oWidget:toggleViewAction() ) - #ifdef QT_WITH_SCINTILLA oSubMenu:oWidget:addAction_4( ::oQScintillaDock:oWidget:toggleViewAction() ) - #endif + oSubMenu:oWidget:addSeparator() oSubMenu:oWidget:addAction_4( ::oDockB2:oWidget:toggleViewAction() ) * oSubMenu:oWidget:addAction_4( ::oDockB1:oWidget:toggleViewAction() ) diff --git a/harbour/contrib/hbide/idebrowse.prg b/harbour/contrib/hbide/idebrowse.prg new file mode 100644 index 0000000000..d3f13154cd --- /dev/null +++ b/harbour/contrib/hbide/idebrowse.prg @@ -0,0 +1,537 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2009-2010 Pritpal Bedi + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/* + * EkOnkar + * ( The LORD is ONE ) + * + * Harbour-Qt IDE + * + * Pritpal Bedi + * 27Jun2010 + */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ + +#include "common.ch" +#include "hbclass.ch" +#include "hbqt.ch" +#include "hbide.ch" +#include "xbp.ch" + +/*----------------------------------------------------------------------*/ + +#define BRW_TYPE_DBF 1 +#define BRW_TYPE_ARRAY 2 + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION hbide_getNewAlias( cTable ) + LOCAL cFile + + STATIC n := 0 + n++ + hb_fNameSplit( cTable, , @cFile ) + + RETURN cFile + "_" + hb_ntos( n ) + +/*----------------------------------------------------------------------*/ + +FUNCTION hbide_browseSome( oIde ) + LOCAL cTable, cPath + + IF !empty( cTable := hbide_fetchAFile( oIde:oDlg, "Select a Table", { { "Database File", "*.dbf" } }, oIde:cWrkFolderLast ) ) + hb_fNameSplit( cTable, @cPath ) + oIde:cWrkFolderLast := cPath + oIde:oBM:addTable( cTable ) + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +CLASS IdeBrowseManager INHERIT IdeObject + + DATA aItems INIT {} + DATA oPanel + DATA qLayout + + METHOD new( oIde ) + METHOD create( oIde ) + METHOD destroy() + METHOD addTable( cFileDBF, cAlias, nRow, nCol ) + METHOD addArray( aData, aAttr, nRow, nCol ) + + ENDCLASS + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowseManager:new( oIde ) + + ::oIde := oIde + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowseManager:create( oIde ) + + DEFAULT oIde TO ::oIde + ::oIde := oIde + + ::oPanel := QWidget():new() + + ::oIde:oEM:oQScintillaDock:oWidget:setWidget( ::oPanel ) + + ::qLayout := QVBoxLayout():new() + ::oPanel:setLayout( ::qLayout ) + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowseManager:destroy() + LOCAL oBrw + + // Close tables and clear variables + FOR EACH oBrw IN ::aItems + Select( oBrw:cAlias ) + DbCloseArea() + NEXT + ::aItems := {} + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowseManager:addArray( aData, aAttr, nRow, nCol ) + + HB_SYMBOL_UNUSED( aData ) + HB_SYMBOL_UNUSED( aAttr ) + HB_SYMBOL_UNUSED( nRow ) + HB_SYMBOL_UNUSED( nCol ) + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowseManager:addTable( cFileDBF, cAlias, nRow, nCol ) + LOCAL oBrw + + HB_SYMBOL_UNUSED( nRow ) + HB_SYMBOL_UNUSED( nCol ) + + oBrw := IdeBrowse():new() + oBrw:cTable := cFileDBF + oBrw:cAlias := cAlias + oBrw:create() + + ::qLayout:addWidget( oBrw:oWnd:oWidget ) + + aadd( ::aItems, oBrw ) + + RETURN Self + +/*----------------------------------------------------------------------*/ +// +// Class IdeBrowse +// +/*----------------------------------------------------------------------*/ + +CLASS IdeBrowse INHERIT IdeObject + + DATA oWnd + DATA oBrw + DATA qLayout + + DATA nType INIT BRW_TYPE_DBF + DATA cAlias INIT "" + DATA cTable INIT "" + DATA aData INIT {} + DATA aStruct INIT {} + DATA aAttr INIT {} + DATA nIndex INIT 0 + DATA cDriver INIT "DBFCDX" + DATA cIndex INIT "" + DATA nOrder INIT 0 + DATA nArea INIT 0 + DATA nCursorType INIT XBPBRW_CURSOR_CELL + + METHOD new( oIde ) + METHOD create( oIde ) + METHOD destroy() + METHOD buildBrowser() + METHOD buildColumns() + METHOD dataLink( nField ) + METHOD getPP( aStruct ) + + METHOD skipBlock( nHowMany ) + METHOD goTop() + METHOD goBottom() + METHOD goTo( nRec ) + METHOD recNo() + METHOD lastRec() + METHOD next() + METHOD previous() + + ENDCLASS + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:new( oIde ) + + ::oIde := oIde + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:create( oIde ) + LOCAL xVrb, cT + LOCAL lMissing := .t. + + DEFAULT oIde TO ::oIde + ::oIde := oIde + + IF !empty( ::aData ) + ::nType := BRW_TYPE_ARRAY + ENDIF + + IF ::nType == BRW_TYPE_DBF + IF !empty( ::cAlias ) .AND. empty( ::cTable ) + IF select( ::cAlias ) > 0 + lMissing := .f. + ENDIF + ENDIF + + IF lMissing .AND. !empty( ::cTable ) + IF empty( ::cAlias ) + USE ( ::cTable ) SHARED NEW VIA ( ::cDriver ) + ELSE + USE ( ::cTable ) SHARED NEW ALIAS ( ::cAlias ) VIA ( ::cDriver ) + ENDIF + IF NetErr() + MsgBox( ::cTable, "Could not been opened!" ) + RETURN Self + ENDIF + IF empty( ::cAlias ) + ::cAlias := alias() + ENDIF + ENDIF + + ::aStruct := DbStruct() + ELSE + FOR EACH xVrb IN ::aData[ 1 ] + cT := valtype( xVrb ) + aadd( ::aStruct, "Fld_" + hb_ntos( xVrb:__enumIndex() ) ) + aadd( ::aStruct, cT ) + IF cT == "N" + aadd( ::aStruct, 12 ) + aadd( ::aStruct, 2 ) + ELSEIF cT == "D" + aadd( ::aStruct, 8 ) + aadd( ::aStruct, 0 ) + ELSEIF cT == "L" + aadd( ::aStruct, 1 ) + aadd( ::aStruct, 0 ) + ELSE + aadd( ::aStruct, len( xVrb ) ) + aadd( ::aStruct, 0 ) + ENDIF + NEXT + ENDIF + + ::buildBrowser() + ::buildColumns() + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:buildBrowser() + LOCAL qLayout, oWnd, oXbpBrowse + + oWnd := XbpWindow():new() + oWnd:oWidget := QWidget():new() + //oWnd:oWidget:resize( 600,300 ) + //oWnd:oWidget:setWindowFlags( Qt_Sheet ) + + qLayout := QVBoxLayout():new() + oWnd:oWidget:setLayout( qLayout ) + + oXbpBrowse := XbpBrowse():new():create( oWnd, , { 0,0 }, oWnd:currentSize() ) + oXbpBrowse:setFontCompoundName( "10.Courier" ) + + qLayout:addWidget( oXbpBrowse:oWidget ) + + oXbpBrowse:cursorMode := ::nCursorType + + oXbpBrowse:skipBlock := {|n| ::skipBlock( n ) } + oXbpBrowse:goTopBlock := {| | ::goTop() } + oXbpBrowse:goBottomBlock := {| | ::goBottom() } + // + oXbpBrowse:firstPosBlock := {| | 1 } + oXbpBrowse:lastPosBlock := {| | ::lastRec() } + + oXbpBrowse:posBlock := {| | ::recNo() } + oXbpBrowse:goPosBlock := {|n| ::goto( n ) } + oXbpBrowse:phyPosBlock := {| | ::recNo() } + + ::qLayout := qLayout + ::oWnd := oWnd + ::oBrw := oXbpBrowse + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:dataLink( nField ) + LOCAL bBlock + + IF ::nType == BRW_TYPE_DBF + bBlock := {|| (::cAlias)->( fieldget( nField ) ) } + ELSE + bBlock := {|| ::aData[ ::nIndex, nField ] } + ENDIF + + RETURN bBlock + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:buildColumns() + LOCAL oXbpColumn, aPresParam, a_ + + IF ::nType == BRW_TYPE_DBF + FOR EACH a_ IN ::aStruct + aPresParam := ::getPP( a_ ) + + oXbpColumn := XbpColumn():new() + oXbpColumn:dataLink := ::dataLink( a_:__enumIndex() ) + oXbpColumn:create( , , , , aPresParam ) + + ::oBrw:addColumn( oXbpColumn ) + NEXT + ELSE + FOR EACH a_ IN ::aStruct + ::getPP( a_, a_:__enumIndex() ) + + oXbpColumn := XbpColumn():new() + oXbpColumn:dataLink := ::dataLink( a_:__enumIndex() ) + oXbpColumn:create( , , , , aPresParam ) + + ::oBrw:addColumn( oXbpColumn ) + NEXT + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:getPP( aStruct ) + LOCAL aPresParam := {} + + aadd( aPresParam, { XBP_PP_COL_HA_CAPTION , aStruct[ 1 ] } ) + aadd( aPresParam, { XBP_PP_COL_DA_ROWHEIGHT , 20 } ) + + RETURN aPresParam + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:destroy() + IF !empty( ::oWnd ) + ::oWnd:destroy() + ENDIF + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:skipBlock( nHowMany ) + LOCAL nRecs, nCurPos + LOCAL nSkipped := 0 + + IF ::nType == BRW_TYPE_DBF + IF nHowMany == 0 + DBSkip( 0 ) + + ELSEIF nHowMany > 0 + DO WHILE nSkipped != nHowMany .AND. ::next() + nSkipped++ + ENDDO + ELSE + DO WHILE nSkipped != nHowMany .AND. ::previous() + nSkipped-- + ENDDO + ENDIF + + ELSE + nRecs := len( ::aData ) + nCurPos := ::nIndex + + IF nHowMany >= 0 + IF ( nCurpos + nHowMany ) > nRecs + nSkipped := nRecs - nCurpos + ::nIndex := nRecs + ELSE + nSkipped := nHowMany + ::nIndex += nHowMany + ENDIF + + ELSE + IF ( nCurpos + nHowMany ) < 1 + nSkipped := 1 - nCurpos + ::nIndex := 1 + ELSE + nSkipped := nHowMany + ::nIndex += nHowMany + ENDIF + + ENDIF + + ENDIF + + RETURN nSkipped + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:goTop() + + IF ::nType == BRW_TYPE_DBF + DbGotop() + ELSE + ::nIndex := 1 + ENDIF + RETURN NIL + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:goBottom() + + IF ::nType == BRW_TYPE_DBF + DbGoBottom() + ELSE + ::nIndex := len( ::aData ) + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:recNo() + + IF ::nType == BRW_TYPE_DBF + RETURN RecNo() + ELSE + RETURN ::nIndex + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:lastRec() + + IF ::nType == BRW_TYPE_DBF + RETURN LastRec() + ELSE + RETURN len( ::aData ) + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:goTo( nRec ) + + IF ::nType == BRW_TYPE_DBF + DbGoto( nRec ) + ELSE + ::nIndex := nRec + ENDIF + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:next() + LOCAL nSaveRecNum := recno() + LOCAL lMoved := .T. + + IF Eof() + lMoved := .F. + ELSE + DBSkip( 1 ) + IF Eof() + lMoved := .F. + DBGoTo( nSaveRecNum ) + ENDIF + ENDIF + + RETURN lMoved + +/*----------------------------------------------------------------------*/ + +METHOD IdeBrowse:previous() + LOCAL nSaveRecNum := Recno() + LOCAL lMoved := .T. + + DBSkip( -1 ) + + IF Bof() + DBGoTo( nSaveRecNum ) + lMoved := .F. + ENDIF + + RETURN lMoved + +/*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbide/idedocks.prg b/harbour/contrib/hbide/idedocks.prg index 3d42053bbd..ecd6bc204b 100644 --- a/harbour/contrib/hbide/idedocks.prg +++ b/harbour/contrib/hbide/idedocks.prg @@ -326,7 +326,11 @@ METHOD IdeDocks:execEvent( nMode, p ) hbide_popupBrwContextMenu( ::qHelpBrw, p ) CASE nMode == dockQScintilla_visibilityChanged - IF p; ::oEM:qscintilla(); ENDIF + IF p + ::oEM:qscintilla() + ELSE + ::oBM:destroy() + ENDIF CASE nMode == dockSourceThumbnail_visibilityChanged IF p; ::oEM:showThumbnail(); ENDIF @@ -1167,7 +1171,7 @@ METHOD IdeDocks:buildSourceThumbnail() METHOD IdeDocks:buildQScintilla() LOCAL nAreas := Qt_LeftDockWidgetArea + Qt_RightDockWidgetArea + Qt_TopDockWidgetArea + Qt_BottomDockWidgetArea - ::oIde:oQScintillaDock := ::getADockWidget( nAreas, "dockQScintilla", "QScintilla Widget", QDockWidget_DockWidgetFloatable ) + ::oIde:oQScintillaDock := ::getADockWidget( nAreas, "dockQScintilla", "Browser Widget", QDockWidget_DockWidgetFloatable ) ::oDlg:oWidget:addDockWidget_1( Qt_RightDockWidgetArea, ::oQScintillaDock:oWidget, Qt_Horizontal ) ::connect( ::oQScintillaDock:oWidget, "visibilityChanged(bool)", {|p| ::execEvent( dockQScintilla_visibilityChanged, p ) } ) diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg index e1231a2c8f..14dd457c3d 100644 --- a/harbour/contrib/hbide/ideeditor.prg +++ b/harbour/contrib/hbide/ideeditor.prg @@ -1640,15 +1640,14 @@ METHOD IdeEditor:scrollThumbnail() RETURN Self /*----------------------------------------------------------------------*/ -// QScintilla Test +// Generic Tests /*----------------------------------------------------------------------*/ METHOD IdeEditor:qscintilla() - // hbide_browseSome( Self ) - - // hbide_qtDesigner() + hbide_browseSome( ::oIde ) + // hbide_qtDesigner() #ifdef HB_WITH_QSCINTILLA #include "hbqscintilla.ch" diff --git a/harbour/contrib/hbide/ideobject.prg b/harbour/contrib/hbide/ideobject.prg index c5a9565d4f..178a6454a9 100644 --- a/harbour/contrib/hbide/ideobject.prg +++ b/harbour/contrib/hbide/ideobject.prg @@ -84,6 +84,7 @@ CLASS IdeObject DATA qContextMenu ACCESS oFR INLINE ::oIde:oFR + ACCESS oBM INLINE ::oIde:oBM ACCESS oEM INLINE ::oIde:oEM ACCESS oPM INLINE ::oIde:oPM ACCESS oDK INLINE ::oIde:oDK diff --git a/harbour/contrib/hbxbp/xbpbrowse.prg b/harbour/contrib/hbxbp/xbpbrowse.prg index 58b937ad61..4d2815a697 100644 --- a/harbour/contrib/hbxbp/xbpbrowse.prg +++ b/harbour/contrib/hbxbp/xbpbrowse.prg @@ -663,6 +663,8 @@ METHOD XbpBrowse:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) /* Viewport */ ::oViewport:configure( ::oTableView:viewport() ) + ::oFooterView:hide() + RETURN Self /*----------------------------------------------------------------------*/