Sub Niveles en Treeview ( SOLUCIONADO )

Sub Niveles en Treeview ( SOLUCIONADO )

Postby cuatecatl82 » Tue Nov 03, 2015 4:11 am

Saludos a todos:

Estoy trabajando en base a la idea del Editor de Recursos RC de Fivewin, lo ando retocando un poco pero estoy detenido con el uso del control TTreeView en el uso de SubMenus, necesito saber como obtener el numero de item seleccionado, en este ejemplo se muestran 12, pero solo me indica el numero en el item raiz (0) y del primer nivel del item (1), para poder obtener la ubicación desde de origen del recurso con la función StrToken(oTxtFile:cLine, 3) desde el archivo.RC

New BITMAP "Z:\FWH\bitmaps\32x32\new.bmp"
New2 BITMAP "Z:\FWH\bitmaps\16x16\new.bmp"
Dialog BITMAP "Z:\FWH\bitmaps\16x16\form.bmp"
DlgMask BITMAP "Z:\FWH\bitmaps\16x16\frmmask.bmp"


Image

Les dejo el archivo fuente y el ejemplo para que puedan darle una revisada..

http://www.mediafire.com/download/scgq5advd3nia0z/RcEdit.zip

Saludos..
Last edited by cuatecatl82 on Tue Nov 03, 2015 7:38 pm, edited 1 time in total.
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Sub Niveles en Treeview

Postby Antonio Linares » Tue Nov 03, 2015 11:59 am

Victor,

Prueba con:

oTree:GetSelected()

devuelve el item seleccionado en el treeview

Tienes un ejemplo de uso en FWH\samples\classtree.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sub Niveles en Treeview

Postby cuatecatl82 » Tue Nov 03, 2015 1:15 pm

Maestro Antonio:

Así es como lo estoy probando en el ejemplo que envie, pero solo devuelve el numero del primer nivel:

Code: Select all  Expand view

IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "ICON"
            AADD(aIcoItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oIcoItem == Nil
               oIcoItem = oTree:Add("ICONOS",3)
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ELSE
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ENDIF
ENDIF

STATIC FUNCTION Nivel()

LOCAL oItem:= oTree:GetSelected()
   MSGInfo( "Item Numero: " + STR( oItem:ItemLevel() ) )
     
RETURN oItem:ItemLevel()


Pero necesito saber en que numero de subitem estoy en base al contenido de archivo .rc para poder mostrar el texto en el get a partir de un array de contenidos que ya fue creado.

Alguna idea..? gracias.
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Sub Niveles en Treeview

Postby hmpaquito » Tue Nov 03, 2015 1:43 pm

Por si sirviera:

Hace años que no toco nada de tree. Pero en aquel tiempo recuerdo que modifique la clase para añadir una Data de usuario donde almacenar la informacion necesaria y evitarme el tener que extraerla de los item padre.
Se trataria, pues que en el momento de la carga del tree, recoger en esa data la informacion necesaria y asi evitar recurrir a buscar en otros niveles. Con aquel cambio todo el trabajo posterior con el tree se me hizo mas facil.

Es una vaga idea que me queda de aquello, solo por si servia.

Saludos.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Sub Niveles en Treeview

Postby horacio » Tue Nov 03, 2015 3:57 pm

Puedes usar la data 'cargo' para almacenar lo que quieras, entre ellos un array con los niveles de profundidad de cada elemento.

Saludos
horacio
 
Posts: 1358
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Sub Niveles en Treeview

Postby cuatecatl82 » Tue Nov 03, 2015 6:43 pm

Saludos de Nuevo y gracias por su colaboración:

La idea es obtener el numero de item seleccionado de un item padre, he intentado lo que me han comentado sin exito, solo logro obtener el numero del primer subitem, más no así de los que estan acontinuación, el número de items esta armado conforme este estructurado el archivo .rc

Image

Si alguien más tiene otras ideas se agradece..

Gracias,..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Sub Niveles en Treeview

Postby cnavarro » Tue Nov 03, 2015 7:11 pm

Hola
Has mirado tu mail?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Sub Niveles en Treeview

Postby cuatecatl82 » Tue Nov 03, 2015 7:36 pm

Cristobal:

Revisado y verificado, es presisamente lo que necesito..

Muchas gracias..

Dejo aqui el código que complementas para que le pueda servir a alguien más..

Code: Select all  Expand view
#Include "FiveWin.ch"

STATIC oImageList,oTree,oFile,cSave,lOpen,oGet,oTxt

//----------------------------------------------------------------------------//

FUNCTION Main(cFile)

LOCAL oDlg,oIco,oBtn1,oBtn2,oBtn3,oBtn4,oCur
LOCAL cOrigen:= ""

lOpen:= .F.
   
     DEFINE CURSOR oCur RESOURCE "MANO"
     DEFINE ICON   oIco RESOURCE "00"
     DEFINE DIALOG oDlg RESOURCE "EDITOR" TITLE "Editor de Recursos RC" ICON oIco
   
   REDEFINE SAY    oFile  ID 201 OF oDlg
   
   oImageList:= TImageList():New(24,24)            
 
   oImageList:Add(TBitmap():DEFINE("RCFILE1",,oDlg),   TBitmap():DEFINE("RCFILE2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("BITMAP1",,oDlg),   TBitmap():DEFINE("BITMAP2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("DIALOG1",,oDlg),   TBitmap():DEFINE("DIALOG2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("ICON1",,oDlg),     TBitmap():DEFINE("ICON2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("SPEAKER1",,oDlg),  TBitmap():DEFINE("SPEAKER2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("VIDEO1",,oDlg),    TBitmap():DEFINE("VIDEO2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CURSOR1",,oDlg),   TBitmap():DEFINE("CURSOR2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUSTOM1",,oDlg),   TBitmap():DEFINE("CUSTOM2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("MENU1",,oDlg),     TBitmap():DEFINE("MENU2",,oDlg))  
   oImageList:Add(TBitmap():DEFINE("MANIFEST1",,oDlg), TBitmap():DEFINE("MANIFEST2",,oDlg))
   
   oImageList:Add(TBitmap():DEFINE("BMP1",,oDlg), TBitmap():DEFINE("BMP2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("DLG1",,oDlg), TBitmap():DEFINE("DLG2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("ICO1",,oDlg), TBitmap():DEFINE("ICO2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("WAV1",,oDlg), TBitmap():DEFINE("WAV2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("VID1",,oDlg), TBitmap():DEFINE("VID2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUR1",,oDlg), TBitmap():DEFINE("CUR2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUS1",,oDlg), TBitmap():DEFINE("CUS2",,oDlg))
   
   oTree:= TTreeView():REDEFINE(100, oDlg, 0, , .F. ,"" )
   
   REDEFINE GET       oTxt                                  ID 300 OF oDlg UPDATE
   REDEFINE GET       oGet   VAR cOrigen                    ID 301 OF oDlg UPDATE
   REDEFINE BUTTONBMP oBtn1  TEXTRIGHT RESOURCE "ABRIR"     ID 400 OF oDlg ACTION AnalizaRC(AbrirRC(.F.,cFile))
   REDEFINE BUTTONBMP oBtn2  TEXTRIGHT RESOURCE "EDITAR"    ID 401 OF oDlg ACTION MSGInfo("Editar")
   REDEFINE BUTTONBMP oBtn3  TEXTRIGHT RESOURCE "GUARDAR"   ID 402 OF oDlg ACTION MSGInfo(cSave)//IF( cFileName != Nil .AND. FILE( cFileName ), MEMOWRIT( cFileName, oEditor:GetText() ),), oBtnSave:Disable()
   REDEFINE BUTTONBMP oBtn4  TEXTRIGHT RESOURCE "SALIR"     ID 403 OF oDlg ACTION oImageList:END(), oDlg:END()
   
    oDlg:lHelpIcon:= .F.
    oDlg:bInit:= {|| AnalizaRC(AbrirRC(.T.,cFile))}
   oBtn1:oCursor:= oCur
   oBtn2:oCursor:= oCur
   oBtn3:oCursor:= oCur
   oBtn4:oCursor:= oCur
   
   ACTIVATE DIALOG oDlg CENTERED
 
RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION AbrirRC(lAuto,cFile)

IF EMPTY(cFile) .AND. lAuto == .F.
   cFile:= cGetFile("Archivo de Recursos en texto     (*.rc)|*.rc|", "Agregar Archivo Recurso", 1,)
ENDIF

IF !EMPTY(cFile)
IF LEN(ALLTRIM(cFileNoPath(cFile))) > 3 .AND. cFileExt(cFile) == "rc"

IF lOpen == .T.
    CierraRC()
ENDIF

   cSave:= cFile
   lOpen:= .T.
   oFile:VarPut(cFile)
   oFile:Refresh()
   RETURN ALLTRIM(cFile)
   
ENDIF
ENDIF

RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION AnalizaRC(cRCFile)

LOCAL oTxtFile
LOCAL oBmpItem, oDlgItem, oIcoItem, oWavItem, oVidItem, oCurItem, oCusItem
LOCAL aBmpItem,           aIcoItem, aWavItem, aVidItem, aCurItem, aCusItem

IF !EMPTY(cRCFile)
 
  oTree:SetImageList( oImageList )
  oTree:Add( cFileNoExt(cRCFile) )
  oTree:bChanged := {|| Nivel() }

  oTxtFile = TTxtFile():New(cRCFile)
  aBmpItem:= {}
  aIcoItem:= {}
  aWavItem:= {}
  aVidItem:= {}
  aCurItem:= {}
  aCusItem:= {}

   
      WHILE oTxtFile:SKIP()
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "BITMAP"
            AADD(aBmpItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oBmpItem == Nil
               oBmpItem = oTree:Add("MAPA DE BITS",1)
               oBmpItem:Add( StrToken( oTxtFile:cLine, 1 ), 10, {|| oGet:VarPut(aBmpItem[Nivel()]), oGet:Refresh() })
            ELSE
               oBmpItem:Add( StrToken( oTxtFile:cLine, 1 ), 10, {|| oGet:VarPut(aBmpItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF

         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "DIALOG"
            IF oDlgItem == Nil
               oDlgItem = oTree:Add("DIALOGOS",2)
               oDlgItem:Add( StrToken( oTxtFile:cLine, 1 ), 11, {|| oGet:VarPut("Construir Dialogo"), oGet:Refresh() })
            ELSE
               oDlgItem:Add( StrToken( oTxtFile:cLine, 1 ), 11, {|| oGet:VarPut("con Bwcc32.dll"), oGet:Refresh() })
            ENDIF
         ENDIF

         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "ICON"
            AADD(aIcoItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oIcoItem == Nil
               oIcoItem = oTree:Add("ICONOS",3)
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ELSE
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "WAVE"
            AADD(aWavItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oWavItem == Nil
               oWavItem = oTree:Add("SONIDOS",4)
               oWavItem:Add( StrToken( oTxtFile:cLine, 1 ), 13, {|| oGet:VarPut(aWavItem[Nivel()]), oGet:Refresh() })
            ELSE
               oWavItem:Add( StrToken( oTxtFile:cLine, 1 ), 13, {|| oGet:VarPut(aWavItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
       
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "AVI"
            AADD(aVidItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oVidItem == Nil
               oVidItem = oTree:Add("VIDEOS",5)
               oVidItem:Add( StrToken( oTxtFile:cLine, 1 ), 14, {|| oGet:VarPut(aVidItem[Nivel()]), oGet:Refresh() })
            ELSE
               oVidItem:Add( StrToken( oTxtFile:cLine, 1 ), 14, {|| oGet:VarPut(aVidItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "CURSOR"
            AADD(aCurItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oCurItem == Nil
               oCurItem = oTree:Add("CURSORES",6)
               oCurItem:Add( StrToken( oTxtFile:cLine, 1 ), 15, {|| oGet:VarPut(aCurItem[Nivel()]), oGet:Refresh() })
            ELSE
               oCurItem:Add( StrToken( oTxtFile:cLine, 1 ), 15, {|| oGet:VarPut(aCurItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "CUSTOM"
            AADD(aCusItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oCusItem == Nil
               oCusItem = oTree:Add("PERSONALIZADO",7)
               oCusItem:Add( StrToken( oTxtFile:cLine, 1 ), 16, {|| oGet:VarPut(aCusItem[Nivel()]), oGet:Refresh() })
            ELSE
               oCusItem:Add( StrToken( oTxtFile:cLine, 1 ), 16, {|| oGet:VarPut(aCusItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
      END
         
      oTree:nDlgCode:= DLGC_WANTALLKEYS
      oTree:bChanged := {|oTree,oItem| oItem:= oTree:GetSelected(),  IF( oItem # nil .and. ValType( oItem:cargo ) == "B", Eval( oItem:cargo ), nil ) }      
      oTxtFile:END()
             
ENDIF

RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION CierraRC()

oTree:DeleteAll()
oTree:Cargo = Nil
oTree:Refresh()

RETURN Nil

//----------------------------------------------------------------------------//
STATIC FUNCTION Nivel()

LOCAL nSel
LOCAL oItem:= oTree:GetSelected()
   /*MSGInfo( "Item Numero: " + STR( oItem:ItemLevel() ) + CRLF + ;
            "Prompt: " + oItem:cPrompt + CRLF + ;
            "Posicion: " + STR( SearchItemAt( oItem:cPrompt, .F., oItem ) ) + CRLF + ;
            "Encontrado: " + IF( SearchItemAt( oItem:cPrompt, .T., oItem )," SI", " NO" ) )*/


nSel:= SearchItemAt( oItem:cPrompt, .F., oItem )
     
RETURN nSel

//----------------------------------------------------------------------------//
STATIC FUNCTION SearchItemAt( cItem, lItem, oTr )

   LOCAL nPos    := 0
   LOCAL lSw     := .F.
   DEFAULT lItem := .F.

   IF !EMPTY( oTr )
      nPos  := ASCAN( oTr:oParent:aItems, { | o | UPPER( cItem ) $ UPPER( o:cPrompt ) } )
      IF nPos > 0
         lSw:= .T.
      ENDIF  
   ENDIF

RETURN IF( lItem, lSw, nPos )


Gracias de nuevo..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Sub Niveles en Treeview ( SOLUCIONADO )

Postby cnavarro » Tue Nov 03, 2015 7:39 pm

Ok, me alegro
Gracias
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: VitalJavier and 81 guests