From 43895de15a0e0924a480c9e93d97602673ce9fca Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 28 Dec 2009 18:45:08 +0000 Subject: [PATCH] 2009-12-28 10:43 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + contrib/hbide/ideeditor.prg + Added missing file from previous commit. --- harbour/ChangeLog | 4 + harbour/contrib/hbide/ideeditor.prg | 295 ++++++++++++++++++++++++++++ 2 files changed, 299 insertions(+) create mode 100644 harbour/contrib/hbide/ideeditor.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ada83fc266..0ab959f82d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,10 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-28 10:43 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + + contrib/hbide/ideeditor.prg + + Added missing file from previous commit. + 2009-12-28 10:37 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt_slots.cpp * contrib/hbqt/hbqt_slots.h diff --git a/harbour/contrib/hbide/ideeditor.prg b/harbour/contrib/hbide/ideeditor.prg new file mode 100644 index 0000000000..0a747bf6c0 --- /dev/null +++ b/harbour/contrib/hbide/ideeditor.prg @@ -0,0 +1,295 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2009 Pritpal Bedi + * www - http://www.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 + * 27Dec2009 + */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ + +#include "common.ch" +#include "hbclass.ch" + +#include "hbqt.ch" + +#include "hbide.ch" + +/*----------------------------------------------------------------------*/ + +CLASS IdeEditor + + DATA oIde + + DATA oTab + DATA qEdit + DATA qDocument + DATA qHiliter + DATA sourceFile + DATA qLayout + + DATA nBlock INIT -1 + DATA nColumn INIT -1 + DATA nBlocks INIT 0 + + DATA nPos INIT 0 + DATA nHPos INIT 0 + DATA nVPos INIT 0 + + ACCESS qTabWidget INLINE ::oIde:oDA:oTabWidget:oWidget + + DATA qCursor + + METHOD new() + METHOD create() + METHOD destroy() + + METHOD buildTabPage() + METHOD activateTab() + METHOD closeTab() + METHOD dispEditInfo() + METHOD onBlockCountChanged() + METHOD setTabImage() + + ENDCLASS + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:new( oIde, cSourceFile, nPos, nHPos, nVPos ) + + ::oIde := oIde + ::sourceFile := cSourceFile + ::nPos := nPos + ::nHPos := nHPos + ::nVPos := nVPos + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:create( oIde, cSourceFile, nPos, nHPos, nVPos ) + + DEFAULT oIde TO ::oIde + DEFAULT cSourceFile TO ::sourceFile + DEFAULT nPos TO ::nPos + DEFAULT nHPos TO ::nHPos + DEFAULT nVPos TO ::nVPos + + ::oIde := oIde + ::SourceFile := cSourceFile + ::nPos := nPos + ::nHPos := nHPos + ::nVPos := nVPos + + ::buildTabPage( ::sourceFile ) + + ::qEdit := QPlainTextEdit():new( ::oTab:oWidget ) + ::qEdit:setPlainText( hb_memoRead( ::sourceFile ) ) + ::qEdit:setLineWrapMode( QTextEdit_NoWrap ) + ::qEdit:setFont( ::oIde:oFont:oWidget ) + ::qEdit:ensureCursorVisible() + + ::qDocument := QTextDocument():configure( ::qEdit:document() ) + + ::qLayout := QBoxLayout():new() + ::qLayout:setDirection( 0 ) + ::qLayout:setContentsMargins( 0,0,0,0 ) + ::qLayout:addWidget( ::qEdit ) + + ::oTab:oWidget:setLayout( ::qLayout ) + + ::qHiliter := QSyntaxHighlighter():new( ::qEdit:document() ) + + Qt_Connect_Signal( ::qEdit , "textChanged()" , {|| ::setTabImage() } ) + Qt_Connect_Signal( ::qEdit , "cursorPositionChanged()", {|| ::dispEditInfo() } ) + + Qt_Connect_Signal( ::qDocument, "blockCountChanged(int)" , {|o,i| ::onBlockCountChanged( i, o ) } ) + + ::qEdit:show() + + /* Restore State */ + ::qCursor := QTextCursor():configure( ::qEdit:textCursor() ) + ::qCursor:setPosition( ::nPos ) + ::qEdit:setTextCursor( ::qCursor ) + // + QScrollBar():configure( ::qEdit:horizontalScrollBar() ):setValue( ::nHPos ) + // + QScrollBar():configure( ::qEdit:verticalScrollBar() ):setValue( ::nVPos ) + + /* Populate Tabs Array */ + aadd( ::oIde:aTabs, { ::oTab, ::qEdit, ::qHiliter, ::qLayout, ::sourceFile, ::qDocument, Self } ) + + ::oIde:nCurTab := len( ::oIde:aTabs ) + + ::oIde:aSources := { ::sourceFile } + ::oIde:createTags() + ::oIde:updateFuncList() + ::oIde:addSourceInTree( ::sourceFile ) + + ::oIde:manageFocusInEditor() + + ::nBlock := ::qCursor:blockNumber() + ::nColumn := ::qCursor:columnNumber() + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:destroy() + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:buildTabPage( cSource ) + LOCAL cPath, cFile, cExt + + hb_fNameSplit( cSource, @cPath, @cFile, @cExt ) + + ::oTab := XbpTabPage():new( ::oIde:oDA, , { 5,5 }, { 700,400 }, , .t. ) + ::oTab:caption := cFile + cExt + ::oTab:minimized := .F. + + ::oTab:create() + + ::qTabWidget:setCurrentIndex( ::qTabWidget:indexOf( ::oTab:oWidget ) ) + ::qTabWidget:setTabTooltip( ::qTabWidget:indexOf( ::oTab:oWidget ), cSource ) + + ::oTab:tabActivate := {|mp1,mp2,oXbp| ::activateTab( mp1, mp2, oXbp ) } + ::oTab:closeRequested := {|mp1,mp2,oXbp| ::closeTab( mp1, mp2, oXbp ) } + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:activateTab( mp1, mp2, oXbp ) + + HB_SYMBOL_UNUSED( mp1 ) + + IF ( mp2 := ascan( ::oIde:aTabs, {|e_| e_[ TAB_OTAB ] == oXbp } ) ) > 0 + ::oIde:nCurTab := mp2 + ::oIde:aSources := { ::oIde:aTabs[ ::oIde:nCurTab, TAB_SOURCEFILE ] } + ::oIde:createTags() + ::oIde:updateFuncList() + ::oIde:aTabs[ mp2, TAB_OEDITOR ]:dispEditInfo() + ::oIde:manageFocusInEditor() + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:closeTab( mp1, mp2, oXbp ) + + HB_SYMBOL_UNUSED( mp1 ) + + IF ( mp2 := ascan( ::aTabs, {|e_| e_[ 1 ] == oXbp } ) ) > 0 + ::oIde:closeSource( mp2, .t. ) + ENDIF + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:onBlockCountChanged( nNewBlocks ) + LOCAL nLine + + ::qCursor := QTextCursor():configure( ::qEdit:textCursor() ) + nLine := ::qCursor:blockNumber() + IF ::nBlock != nLine + HB_TRACE( HB_TR_ALWAYS, nNewBlocks, nLine, ::nBlock ) + ENDIF + ::nBlock := nLine + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:dispEditInfo() + LOCAL s + + ::qCursor := QTextCursor():configure( ::qEdit:textCursor() ) + + s := "Line "+ hb_ntos( ::qCursor:blockNumber() + 1 ) + " of " + ; + hb_ntos( ::qDocument:blockCount() ) + "" + + ::oIde:oSBar:getItem( SB_PNL_MAIN ):caption := "Success" + ::oIde:oSBar:getItem( SB_PNL_READY ):caption := "Ready" + ::oIde:oSBar:getItem( SB_PNL_LINE ):caption := s + ::oIde:oSBar:getItem( SB_PNL_COLUMN ):caption := "Col " + hb_ntos( ::qCursor:columnNumber() + 1 ) + ::oIde:oSBar:getItem( SB_PNL_INS ):caption := iif( ::qEdit:overwriteMode() , " ", "Ins" ) + ::oIde:oSBar:getItem( SB_PNL_MODIFIED ):caption := iif( ::qDocument:isModified(), "Modified", " " ) + ::oIde:oSBar:getItem( SB_PNL_STREAM ):caption := "Stream" + ::oIde:oSBar:getItem( SB_PNL_EDIT ):caption := "Edit" + + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD IdeEditor:setTabImage() + LOCAL nIndex := ::qTabWidget:indexOf( ::oTab:oWidget ) + LOCAL lModified := ::qDocument:isModified() + + ::qTabWidget:setTabIcon( nIndex, ::oIde:resPath + iif( lModified, "tabmodified.png", "tabunmodified.png" ) ) + + ::oIde:oSBar:getItem( SB_PNL_MODIFIED ):caption := iif( lModified, "Modified", " " ) + + RETURN Self + +/*----------------------------------------------------------------------*/