 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
rootey
Joined: 06 Sep 2009 Posts: 20
|
Posted: Sun Sep 27, 2009 2:11 am Post subject: ListView of folders, with doubleclick action & filter |
|
|
I'm working on a script that shows the folders in a specified directory. When you double click a a folder in a ListView, some action happens.
Also to filter the displayed list, there is a Search box.
I have two versions of the script v.04, has the action on double click working, but the search is broken.
v0.5 has the search working, but the double click action is broken.
| Code: | ;searchDIR_v0.4
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, Text,,Search:
Gui, Add, Edit, w160 vA_SearchTerm gSearch
Gui, Add, ListView, Checked grid r20 w450 gMyListView Hidden, FileName ;this is the search view
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w450 gMyListView xp yp, FileName ;this is the list view
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
Gui, Show
return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
msgbox, %RowText%
}
return
Search:
Gui, Submit, NoHide
If (A_SearchTerm != "")
{
Gui, ListView, LV1
LV_Delete()
Gui, ListView, LV2
Loop,% LV_GetCount()
{
LV_GetText(RetrievedText, A_Index)
If InStr(RetrievedText, A_SearchTerm)
{
Gui, ListView, LV1
LV_Add("",RetrievedText)
Gui, ListView, LV2
}
}
GuiControl, Hide, LV2
GuiControl, Show, LV1
}
Else
{
GuiControl, Hide, LV1
GuiControl, Show, LV2
}
return
GuiClose:
ExitApp |
It is something to do with my naming in lines 10,19; gMyListView, vLV1, vLV2, MyListView. Could someone show me what is wrong please?
| Code: | ;searchDIR_v0.5
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, Text,,Search:
Gui, Add, Edit, BackgroundFFDD99 w160 vA_SearchTerm gSearch
Gui, Add, ListView, Checked grid r20 w450 vLV1 Hidden, FileName ;this is the search view
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w450 vLV2 xp yp, FileName ;this is the list view
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
Gui, Show
return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
msgbox, %RowText%
}
return
Search:
Gui, Submit, NoHide
If (A_SearchTerm != "")
{
Gui, ListView, LV1
LV_Delete()
Gui, ListView, LV2
Loop,% LV_GetCount()
{
LV_GetText(RetrievedText, A_Index)
If InStr(RetrievedText, A_SearchTerm)
{
Gui, ListView, LV1
LV_Add("",RetrievedText)
Gui, ListView, LV2
}
}
GuiControl, Hide, LV2
GuiControl, Show, LV1
}
Else
{
GuiControl, Hide, LV1
GuiControl, Show, LV2
}
return
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
!Guest Guest
|
Posted: Sun Sep 27, 2009 10:22 am Post subject: |
|
|
| The second script has no " gMyListView " in "Gui, Add, ListView..." lines |
|
| Back to top |
|
 |
rootey
Joined: 06 Sep 2009 Posts: 20
|
Posted: Sun Sep 27, 2009 11:21 am Post subject: |
|
|
Ok, so here is the first problem fixed, I changed to this:
| Code: | Gui, Add, ListView, Checked grid r20 w450 vLV1 gMyListView Hidden, FileName ;this is the search view
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w450 vLV2 gMyListView xp yp, FileName |
Here is the full working code v0.7 below:
| Code: | ;searchDIR_v0.7
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, Text,,Search:
Gui, Add, Edit, BackgroundFFDD99 w160 vA_SearchTerm gSearch
Gui, Add, ListView, Checked grid r20 w450 vLV1 gMyListView Hidden, FileName ;this is the search view
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w450 vLV2 gMyListView xp yp, FileName ;this is the list view
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
Gui, Show
return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
msgbox, %RowText%
}
return
Search:
Gui, Submit, NoHide
If (A_SearchTerm != "")
{
Gui, ListView, LV1
LV_Delete()
Gui, ListView, LV2
Loop,% LV_GetCount()
{
LV_GetText(RetrievedText, A_Index)
If InStr(RetrievedText, A_SearchTerm)
{
Gui, ListView, LV1
LV_Add("",RetrievedText)
Gui, ListView, LV2
}
}
GuiControl, Hide, LV2
GuiControl, Show, LV1
}
Else
{
GuiControl, Hide, LV1
GuiControl, Show, LV2
}
return
GuiClose:
ExitApp |
So it appears to work, apart from the double click now doesn't work after doing a filter search.
Any suggestions, please? |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
|
| Back to top |
|
 |
fromaroundhere Guest
|
Posted: Sun Sep 27, 2009 5:56 pm Post subject: re: |
|
|
Does this not work?
| Code: | ;searchDIR_v0.7
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, Text,,Search:
Gui, Add, Edit, BackgroundFFDD99 w160 vA_SearchTerm gSearch
Gui, Add, ListView, Checked grid r20 w450 vLV1 gMyListView Hidden, FileName ;this is the search view
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w450 vLV2 gMyListView xp yp, FileName ;this is the list view
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
Gui, Show
return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
msgbox, %RowText%
}
return
Search:
Gui, Submit, NoHide
If (A_SearchTerm)
{
Gui, ListView, LV1
LV_Delete()
Gui, ListView, LV2
Loop,% LV_GetCount()
{
LV_GetText(RetrievedText, A_Index)
If InStr(RetrievedText, A_SearchTerm)
{
Gui, ListView, LV1
LV_Add("",RetrievedText)
Gui, ListView, LV2
}
}
GuiControl, Hide, LV2
GuiControl, Show, LV1
Gui, ListView, LV1
}
Else
{
GuiControl, Hide, LV1
GuiControl, Show, LV2
Gui, ListView, LV2
}
return
GuiClose:
ExitApp
|
|
|
| Back to top |
|
 |
rootey
Joined: 06 Sep 2009 Posts: 20
|
Posted: Sun Sep 27, 2009 9:35 pm Post subject: |
|
|
Thanks fromaroundhere;
so you added:
at the end of If.
and
at the end of Else.
So i guess that reloads the values currently displayed, for the full & filtered list? So when I double click, it is doing a LV_GetText on the current ListView.
I guess that is why it'snow working?? |
|
| Back to top |
|
 |
fromaroundhere Guest
|
Posted: Mon Sep 28, 2009 8:47 am Post subject: re: |
|
|
No problem.
Basically when you call a listview function (lv_gettext for example), it always operates on the default listview.
Since LV2 was set as default even when filtering was active, lv_gettext sent its queries to LV2. When you double clicked say the fourth row, it retrieved the content of the fourth row of LV2, not LV1.
You can change the default listview with "gui, listview, ...".
With those two lines added, when you type in the search field, it sets the search listview as default, when you delete everything from the search field, it sets the other the listview with the full list as the default. This way when filtering is active lv_gettext will operate on the filtered list, when inactive, it will operate on the full list. |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Mon Sep 28, 2009 8:53 am Post subject: |
|
|
@fromaroundhere
thank you for the nice example , works fine |
|
| Back to top |
|
 |
rootey
Joined: 06 Sep 2009 Posts: 20
|
Posted: Tue Sep 29, 2009 1:26 am Post subject: |
|
|
Thanks to the help from you guys, this script is starting to go somewhere.
Here is the working code v0.9 , with some added features:
rightClick menu operates in current row.
create folders or multi-sub folders in current row.
| Code: | ;searchDIR_v0.9
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, Text,,Search:
Gui, Add, Edit, BackgroundFFDD99 w160 vA_SearchTerm gSearch
Gui, Add, ListView, Checked grid r20 w180 vLV1 gMyListView Hidden, FileName ;this is the searchView
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w180 vLV2 gMyListView xp yp, FileName ;this is the listView
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
;Create a popup menu for the rightClick context menu:
Menu, MyContextMenu, Add, Create New Folder, ContextCreateFolder
Gui, Show
Return
;the doubleClick action
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
selectedFolder=%searchDIR%\%RowText%
InputBox, newFolderName, Create a New Folder here:,You have selected %selectedFolder% `nWhat would you like to name the New folder???`n`nYou can also create subFolders life this:`nfolder1\folder2\folder3
fullPath=%selectedFolder%\%newFolderName%
FileCreateDir, %fullPath%
}
Return
GuiContextMenu: ;Launched in response to a rightClick
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
ContextCreateFolder: ;popUp menu to create a folder
if A_GuiEvent = RightClick
{
LV_GetText(RowText, A_EventInfo)
selectedFolder=%searchDIR%\%RowText%
InputBox, newFolderName, Create a New Folder here:,You have selected %selectedFolder% `nWhat would you like to name the New folder???`n`nYou can also create subFolders life this:`nfolder1\folder2\folder3
fullPath=%selectedFolder%\%newFolderName%
FileCreateDir, %fullPath%
}
Return
;the filtering/search
Search:
Gui, Submit, NoHide
If (A_SearchTerm)
{
Gui, ListView, LV1
LV_Delete()
Gui, ListView, LV2
Loop,% LV_GetCount()
{
LV_GetText(RetrievedText, A_Index)
If InStr(RetrievedText, A_SearchTerm)
{
Gui, ListView, LV1
LV_Add("",RetrievedText)
Gui, ListView, LV2
}
}
GuiControl, Hide, LV2
GuiControl, Show, LV1
Gui, ListView, LV1
}
Else
{
GuiControl, Hide, LV1
GuiControl, Show, LV2
Gui, ListView, LV2
}
Return
GuiClose:
ExitApp |
I would like to change the doubleClick so that it opens a new column, containg a list of sub folders for the doubled clicked item.
I haven't got a clue where to start, can you suggest a method to do this? |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
|
| Back to top |
|
 |
rootey
Joined: 06 Sep 2009 Posts: 20
|
Posted: Wed Sep 30, 2009 9:31 pm Post subject: |
|
|
I'm stuck trying to display a subFolder in a new listView.
I've cut the code down, and just added a MsgBox to see if I can get the subFolders to list.
When I double click an entry it just displays the command I'm trying to run:
Loop, %selectedFolder%\*.*,2
Obviously, I don't know what I'm doing. I'd appreciate a litttle help, please.
| Code: | ;displaySubFolder_v0.1
#SingleInstance force
#NoEnv
SetBatchLines, -1
searchDIR=C:\
Gui, Add, ListView, Checked grid BackgroundFFDD99 r20 w180 gMyListView xp yp, FileName ;this is the top level directory listView
Loop, %searchDIR%\*.*,2
LV_Add("",A_LoopFileName)
LV_ModifyCol()
;Create a popup menu for the rightClick context menu:
Menu, MyContextMenu, Add, Create New Folder, ContextCreateFolder
Gui, Show
Return
;this is the part that doesn't work
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo)
selectedFolder=%searchDIR%\%RowText%
subfolderList=Loop, %selectedFolder%\*.*,2
MsgBox, %subfolderList%
}
Return
GuiContextMenu: ;Launched in response to a rightClick
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
ContextCreateFolder: ;popUp menu to create a folder
if A_GuiEvent = RightClick
{
LV_GetText(RowText, A_EventInfo)
selectedFolder=%searchDIR%\%RowText%
InputBox, newFolderName, Create a New Folder here:,You have selected %selectedFolder% `nWhat would you like to name the New folder???`n`nYou can also create subFolders life this:`nfolder1\folder2\folder3
fullPath=%selectedFolder%\%newFolderName%
FileCreateDir, %fullPath%
}
Return
GuiClose:
ExitApp |
If the MsgBox can return the list of subFolders, then I hope from there I can then get the subFolders to display in a new column(ListView), next to the 1st one |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|