#!/usr/bin/gtkbasic002
//include "/usr/lib/wxbasicscript/basefunctions.inc"

//-- make shure we find the gladefile

a = xwin_getdir(command(2))
xwin_cd(a)

'for n=32 to 128:print n & " "&chr(n):next
'end

//thepipe = argvtostring()
thepipe = command(3) 

gins_glade("GBdialog-infowindow01.glade")

debug = 0
if debug = 1 then
gtk_createobject("GtkWindow" , "NewWindow", 0 , 0)
gtk("gtk_widget_show" , ":NewWindow" , 0 ,0,0,0,0)
gtk_createobject("GtkHBox" , "NewHBox", "0" , "0")
gtk("gtk_container_add" , ":NewWindow" , ":NewHBox"  , "1","1","0",0 )
gtk("gtk_widget_show" , ":NewHBox" , 0 ,0,0,0,0)

gtk_createobject("GtkTextView" , "textview1", 0 , 0)
gtk("gtk_box_pack_start" , ":NewHBox" , ":textview1" , "1","1","0",0)
gtk("gtk_widget_show" , ":textview1" , 0 ,0,0,0,0)
gtk("gtk_window_move" ,":NewWindow" ,  "0" , "0", 0,0,0)

gtk("gtk_text_view_get_buffer" ,":textview1" ,  0 , 0, 0,0,0)
gtk_setobjectname("buf1")

end if


  gtk("gtk_window_move" ,"window1" ,  "0" , "30", 0,0,0)
  gtk("gtk_text_view_get_buffer" ,"textview1" ,  0 , 0, 0,0,0)
  gtk_setobjectname("buf1")


  buffer = "This box displays your selections" & chr(10) & chr(10)
  gtk("gtk_text_buffer_set_text" ,":buf1" , buffer , len(buffer), 0,0,0)


gins_main()


  if fileexists( thepipe ) then
     freeNum= freeFile()
     open thepipe For Input As #freeNum
  else
      gins_exit()
      end
  end if


//-- mainloop with eventhandling

tempbuffer = ""
while 1


     try:
     Line Input #freeNum, buffer
myline = buffer
     catch:
     end try

if buffer != Nothing then


  buffer = replace(buffer , "\\n" ,  chr(13))

  if right(buffer , 5) != "<EOM>" then
    tempbuffer = tempbuffer & buffer &  chr(13)
  else
    buffer = left(buffer , len(buffer)-5)
    buffer = tempbuffer & buffer
    tempbuffer = ""


//-- BUG: textview eats chars?
    //buffer = "xxMESSAGE: MESSAGE::::" & buffer
    index = instr(buffer , "E:")
    if index >=0 then
      buffer = left(buffer , index) & ":" & right(buffer , len(buffer)-index)
    end if
   'buffer = replace(buffer , "E:" , "E::")

    b=len(buffer)

    buffer = buffer & chr(10)& chr(13)

'   gtk("gtk_text_buffer_set_text" ,":buf1" , buffer , len(buffer)-10, 0,0,0)

    gtk("gtk_text_buffer_get_iter_at_line" ,":buf1" , "dummy" , "2" , 0, 0,0 ) 
    gtk("gtk_text_buffer_insert" ,":buf1" , "dummy" , buffer , b+1, 0,0)


'        gtk("gtk_text_buffer_get_bounds",":buf1" , "dummy" , "dummy" , 0, 0,0 )
'        gtk("gtk_text_buffer_get_selection_bounds",":buf1" , "dummy" , "dummy" , 0, 0,0 )
'        a = gtk("gtk_text_buffer_get_slice", ":buf1" , "dummy" , "dummy" , "0", 0,0)
'        print a
  end if

end if


	// JWM does not passthrough GDK_DELETE, so check by existence of windowname :-/
	a=gins_get("window1" , "name" , "<str>")
	if a = Nothing then
		print "window was closed, exiting..."
		close #freeNum
		xwin_system("rm -f " & thepipe)
		gins_exit()
		end
	end if

  widget , event , pdata = gins_event()

  if widget != Nothing then
   //-- uncomment these lines to see ALL events in the console
  '  print widget
  '  print event
  '  print pdata

    if event = "GDK_DELETE" then
      close #freeNum
      print "bye"
      xwin_system("rm -f " & thepipe)
      gins_exit()
      end
    end if

  end if


  xwin_usleep(100000)

wend
