AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ListView of folders, with doubleclick action & filter

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
rootey



Joined: 06 Sep 2009
Posts: 20

PostPosted: Sun Sep 27, 2009 2:11 am    Post subject: ListView of folders, with doubleclick action & filter Reply with quote

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
View user's profile Send private message
!Guest
Guest





PostPosted: Sun Sep 27, 2009 10:22 am    Post subject: Reply with quote

The second script has no " gMyListView " in "Gui, Add, ListView..." lines
Back to top
rootey



Joined: 06 Sep 2009
Posts: 20

PostPosted: Sun Sep 27, 2009 11:21 am    Post subject: Reply with quote

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
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 2214
Location: switzerland

PostPosted: Sun Sep 27, 2009 12:16 pm    Post subject: Reply with quote

sorry no time for right answer,
maybe can use this
have listview example here with search (3rd example)
http://www.autohotkey.com/forum/topic4526.html
Back to top
View user's profile Send private message
fromaroundhere
Guest





PostPosted: Sun Sep 27, 2009 5:56 pm    Post subject: re: Reply with quote

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

PostPosted: Sun Sep 27, 2009 9:35 pm    Post subject: Reply with quote

Thanks fromaroundhere;
so you added:
Code:
 Gui, ListView, LV1

at the end of If.

and
Code:
 Gui, ListView, LV2

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
View user's profile Send private message
fromaroundhere
Guest





PostPosted: Mon Sep 28, 2009 8:47 am    Post subject: re: Reply with quote

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

PostPosted: Mon Sep 28, 2009 8:53 am    Post subject: Reply with quote

@fromaroundhere
thank you for the nice example , works fine
Back to top
View user's profile Send private message
rootey



Joined: 06 Sep 2009
Posts: 20

PostPosted: Tue Sep 29, 2009 1:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Delusion



Joined: 16 Jul 2008
Posts: 210
Location: Greece/Rhodos

PostPosted: Tue Sep 29, 2009 11:52 am    Post subject: Reply with quote

you could check out my script here : http://www.autohotkey.com/forum/viewtopic.php?t=36364

iv got alot of work done with listview so you may find something in there to help you
_________________
Popcorn Movie Db
Simple Apnea Trainer
Back to top
View user's profile Send private message Visit poster's website
rootey



Joined: 06 Sep 2009
Posts: 20

PostPosted: Wed Sep 30, 2009 9:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group