AutoHotkey Community

It is currently May 26th, 2012, 9:56 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: September 27th, 2009, 3:11 am 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 11:22 am 
The second script has no " gMyListView " in "Gui, Add, ListView..." lines


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 12:21 pm 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 1:16 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: re:
PostPosted: September 27th, 2009, 6:56 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 10:35 pm 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
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??


Report this post
Top
 Profile  
Reply with quote  
 Post subject: re:
PostPosted: September 28th, 2009, 9:47 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 28th, 2009, 9:53 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
@fromaroundhere
thank you for the nice example , works fine


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 2:26 am 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 12:52 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2009, 10:31 pm 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: bekihito, Bing [Bot], dra, Exabot [Bot], JSLover, Leef_me, patgenn123, rbrtryn and 55 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group