Jump to content

ListView text file preview in Edit


l3ill
 Share

Go to solution Solved by Melba23,

Recommended Posts

Hi All,

 

  I have been playing with this little problem for about a week now and just cant get it to work. I have tried literally 100 different variations and combed the forums for solutions....no luck.

 

  It is actually a very basic listView GUI that lists all files in the Directory it is placed (originally a snippet browser for .au3 files) with an edit box on the bottom to preview the selected txt / au3 file. 

 

   The preview function does not work. The RecFileListToArray (thanks M23) ! does an excellent job of giving me a list of full paths. A selected path is sent to the preview function which should show up in the edit box. 

  If I insert the full path (static) as a variable it works fine ( see commented out full path for testing ).

 

  Any help with this would be very cool...

 

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include "C:\Users\Badass\Desktop\RecFileListToArray\RecFileListToArray.au3"
Local $showText = ""
Local $sFolder = @ScriptDir ; works as browser in any folder you put the script in
$Form1 = GUICreate("SnippetBrowser", 810, 680, 246, 140, $WS_SIZEBOX, $WS_EX_ACCEPTFILES)
$Input1 = GUICtrlCreateInput("Dummy", 10, 16, 180, 21)
$sBlistView = GUICtrlCreateListView("Path", 10, 45, 790, 353, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
_GUICtrlListView_SetColumnWidth($sBlistView, 0, 300)
$getFiles = GUICtrlCreateButton("Get Files", 210, 14, 81, 25)
GUICtrlSetState($getFiles, $GUI_DEFBUTTON)
$ClearAll = GUICtrlCreateButton("Clear All", 310, 14, 81, 25)
$Dummy = GUICtrlCreateButton("Dummy", 410, 14, 81, 25)
$showSelected = GUICtrlCreateButton("Preview", 460, 405, 91, 25)
$label1 = GUICtrlCreateLabel($sFolder, 510, 20, 400, 25)
GUICtrlSetData($label1, $sFolder)
$openSelected = GUICtrlCreateButton("Open in SciTE", 360, 405, 91, 25)
$hEdit = GUICtrlCreateEdit("", 10, 440, 790, 235)
GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $getFiles
            _getFiles()
        Case $openSelected
            _openSelected()
        Case $ClearAll
            _GUICtrlListView_DeleteAllItems($sBlistView)
        Case $showSelected
            _showSelected()
    EndSwitch
WEnd

Func _getFiles()
    Global $FileList_A = _RecFileListToArray(@ScriptDir, "*", 1, 0, 0, 2)
    $rows = UBound($FileList_A)
    For $i = 0 To $rows - 1
        _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF)
        ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR)
    Next
EndFunc   ;==>_getFiles
;=====================================Problem Function
Func _showSelected()
Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
Local $sSelect = _GUICtrlListView_GetItemText($sBlistView, $iSelect[1])

; $sSelect = "C:\path to any text /file.txt"  ; when testing this turn ^^^^ these 2 off
_GUICtrlEdit_SetText($hEdit, FileRead($sSelect))

        ConsoleWrite("$sSelect: " & $sSelect & @CR)
        ConsoleWrite("$hEdit: " & $hEdit & @CR)

EndFunc   ;==>_showSelected
;=====================================Problem Function
Func _openSelected()
    $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
    $sSelect = _GUICtrlListView_GetItemText($sBlistView, $iSelect[1])
        Run("cmd.exe /c " & """" & $sSelect & """",@ScriptDir,@SW_HIDE)

EndFunc   ;==>_openSelected
 

 

Link to comment
Share on other sites

  • Moderators
  • Solution

billo,

I have seen this before - _GUICtrlListView_GetItemText has added an unseen extra character to the return so it is not recognised as a valid file. Just trim it and all works as you want: :)

Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)
And if you are wondering how I found it the first time - I used StringLen. ;)

Finall, a freebie. I coded _RecFileListToArray to return a count in the [0] element - so why not use it? :huh:

Global $FileList_A = _RecFileListToArray(@ScriptDir, "*", 1, 0, 0, 2)
For $i = 1 To $FileList_A[0]
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

  Well first off thanks for ending my torment! And yes you are right I do wonder how you found that. (Insider Information?)  I get the chr count issue but how do you know where the culprit was added? or is it just understood that it would be at the end?

 

 so why not use it?

  :rolleyes: A rhetorical question I assume...?   :ermm:

You Rock Melba! Thanks for your time!

Now I can go find something else that I cant figure out  :mad2:

Happy Holidays,

Bill

Edited by billo
Link to comment
Share on other sites

  • Moderators

billo,

As using ConsoleWrite to look at the path string compared to the literal string itself did not show any obvious errors, it was pretty clear that there had to be something at the end of the string. So I do not claim any supernatural powers - just common sense and understanding how to display strings as bytes. When you use StringToBinary you soon see that there is an 0x0A at the end of the string. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...