Problem with ListView and INI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yugo
Posts: 24
Joined: 01 Mar 2018, 05:20

Problem with ListView and INI

26 Oct 2018, 09:17

hi, i'm trying to make a simple listview for add/delete some shortcuts(*exe files) but i'm actually struggeling.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


; jetzt > patchname ist in zweiter column und zweiini! > lösen später > alles aus  EINER ini section rauslesen, auch den patch!


#SingleInstance force







Gui, Add, ListView, x26 y32 w290 h540 gmylist  AltSubmit  , Progs ;AltSubmit
Gui, Add, Button, x216 y582 w100 h30 gdelete , Delete
Gui, Add, Button, x106 y582 w100 h30 gadd , Add

Gui, Show, x1000 y100 h635 w347, MyBar 0.1a


IniRead, content, settings.ini, Progs
Loop, parse, content, `n ;shows sections
{
[color=#FF0000]    sect := A_LoopField
    SplitPath, sect, name, dir, ext, name_no_ext, drive ;fetch all info
    LV_Add("", name_no_ext)[/color]


}

return



add:
FileSelectFile, file, 3, , open a file, 
if file =
    return
else
    SplitPath, file, name, dir, ext, name_no_ext, drive ;fetch all info
    LV_Add("", name_no_ext)
[color=#00BF40]    IniWrite, %file%, settings.ini, Progs, %name_no_ext%[/color]
return

delete:
if ! selectedrow
    return

selectedrow := LV_GetNext(0)
LV_Delete(selectedrow)
[color=#FF0000]IniDelete, settings.ini, Progs,[/color]
return

mylist:  
selectedrow := LV_GetNext(0)

if ! selectedrow
    return

if A_GuiEvent = DoubleClick

   {
   LV_GetText(filedir, A_EventInfo, 1)
   run, %filedir%
   }


return
GuiClose:
ExitApp



so i can create an ini like this: [Progs]
Desert=C:\Users\Public\Pictures\Sample Pictures\Desert.jpg
and i can also read the names! but i'm failing in run the variable keysaction and cannot delete them


thank you
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Problem with ListView and INI

26 Oct 2018, 09:57

REPLACE:

Code: Select all

if A_GuiEvent = DoubleClick

   {
   LV_GetText(filedir, A_EventInfo, 1)
   run, %filedir%
   }
WITH:

Code: Select all

If (A_GuiEvent = "DoubleClick") {
	LV_GetText(FileName, A_EventInfo, 1)
	IniRead, FilePath, settings.ini, Progs, % FileName
	Run, % FilePath
}
Yugo
Posts: 24
Joined: 01 Mar 2018, 05:20

Re: Problem with ListView and INI

26 Oct 2018, 12:04

wow!

works like a charm! can you maybe explain your code? what does this "filepatch" do? Is there a documentation on this?

whats about to delete the selected item from the ini? possible throught filepatch also?

thank you!

edit:
oh, sry this si the outputvar of course! still don't get how to delete a variable keyname in an ini file. :|
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Problem with ListView and INI

26 Oct 2018, 12:47

Code: Select all

#SingleInstance, Force

Gui, Margin, 10, 10
Gui, Add, ListView, w300 h540 gMyList +AltSubmit, Progs

Gui, Add, Button, x140 y+10 w80 h26 vDelete gDelete, Delete
Gui, Add, Button, x+10 yp wp hp vAdd gAdd, Add

Gui, Show, AutoSize, MyBar 0.1a

IniRead, Content, Settings.ini, Progs

Loop, Parse, Content, `n
{
	SplitPath, A_LoopField,,,, NameNoExt
	LV_Add("", NameNoExt)
}

ButtonCheck()
return

Add:
	FileSelectFile, File, 3,, Open File...

	If (ErrorLevel) {
		return
	} Else {
		SplitPath, File,,,, NameNoExt
		LV_Add("", NameNoExt)
		IniWrite, % File, Settings.ini, Progs, % NameNoExt
	}
	
	ButtonCheck()
return

Delete:
	SelectedRow := LV_GetNext(0)
	LV_GetText(FileName, SelectedRow)
	
	If (!SelectedRow) {
		return
	}

	LV_Delete(SelectedRow)
	IniDelete, Settings.ini, Progs, % FileName
	
	ButtonCheck()
return

MyList:
	SelectedRow := LV_GetNext(0)

	If (!SelectedRow) {
		return
	}

	If (A_GuiEvent = "DoubleClick") {
		LV_GetText(FileName, A_EventInfo, 1)
		IniRead, FilePath, Settings.ini, Progs, % FileName
		Run, % FilePath
	}
	
	ButtonCheck()
return

GuiClose:
	ExitApp
return

ButtonCheck() {
	Global
	GuiControl, % (!LV_GetCount() ? "Disable" : "Enable"), Delete
}
Yugo
Posts: 24
Joined: 01 Mar 2018, 05:20

Re: Problem with ListView and INI

26 Oct 2018, 13:01

wow, thank you I really appriciate it. Can you maybe explain? i will to learn
Yugo
Posts: 24
Joined: 01 Mar 2018, 05:20

Re: Problem with ListView and INI

26 Oct 2018, 13:14

sry but what is the difference between

IniDelete, settings.ini, Progs, %FileName%
;IniDelete, Settings.ini, Progs, % FileName

both is working!
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Problem with ListView and INI

26 Oct 2018, 13:15

Yugo wrote:
26 Oct 2018, 13:01
wow, thank you I really appriciate it. Can you maybe explain? i will to learn

See comments...

Code: Select all

#SingleInstance, Force ; Only Allow One Running Instance Of Script At A Time

Gui, Margin, 10, 10 ; Spacing Of Controls Within Gui Window
Gui, Add, ListView, w300 h540 gMyList +AltSubmit, Progs ; ListView
Gui, Add, Button, x140 y+10 w80 h26 vDelete gDelete, Delete ; Delete Button
Gui, Add, Button, x+10 yp wp hp vAdd gAdd, Add ; Add Button
Gui, Show, AutoSize, MyBar 0.1a ; Show Window

IniRead, Content, Settings.ini, Progs ; Read INI File

Loop, Parse, Content, `n ; Parse INI File
{
	SplitPath, A_LoopField,,,, NameNoExt ; Get File Name Without Extension From INI
	LV_Add("", NameNoExt) ; Add File Name Without Extension To ListView
}

ButtonCheck() ; Enable/Disable Button
return

Add: ; Add
	FileSelectFile, File, 3,, Open File... ; Select File From Explorer

	If (ErrorLevel) {
		return ; Window Closed/Open File Cancelled - Do Nothing...
	} Else {
		SplitPath, File,,,, NameNoExt ; Get File Name Without Extension
		LV_Add("", NameNoExt) ; Add File Name Without Extension To ListView
		IniWrite, % File, Settings.ini, Progs, % NameNoExt ; Write File Path To INI For Key Matching File Name
	}
	
	ButtonCheck() ; Enable/Disable Button
return

Delete: ; Delete
	SelectedRow := LV_GetNext(0) ; Get Selected Row Number From ListView
	LV_GetText(FileName, SelectedRow) ; Get Text Of Selected Row
	
	If (!SelectedRow) {
		return ; If No Row Selected, Do Nothing.
	}

	LV_Delete(SelectedRow) ; Delete Selected Row From ListView
	IniDelete, Settings.ini, Progs, % FileName ; Delete INI Key Matching Row Text
	
	ButtonCheck() ; Enable/Disable Button
return

MyList:
	SelectedRow := LV_GetNext(0)

	If (!SelectedRow) {
		return ; If No Row Selected, Do Nothing.
	}

	If (A_GuiEvent = "DoubleClick") { ; Double-Click ListView
		LV_GetText(FileName, A_EventInfo, 1) ; Get Row Text
		IniRead, FilePath, Settings.ini, Progs, % FileName ; Get Value From INI For Key Matching Row Text
		Run, % FilePath ; Open File Path From INI
	}
	
	ButtonCheck() ; Enable/Disable Button
return

GuiClose: ; Close Window
	ExitApp ; Exit Script
return

ButtonCheck() {
	Global ; Allow Functions To Read Outside Variables
	
	; Disable Button If No Rows In ListView. Enable Button If Rows In ListView.
	GuiControl, % (!LV_GetCount() ? "Disable" : "Enable"), Delete
}

Yugo wrote:
26 Oct 2018, 13:14
sry but what is the difference between

IniDelete, settings.ini, Progs, %FileName%
;IniDelete, Settings.ini, Progs, % FileName

both is working!
There is no difference. You can sometimes use variables without the ending percent symbol. It's personal preference of the script writer.

You will develop a personal preference for how you like to write code. I formatted your script to my own liking.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], haomingchen1998, mikeyww and 130 guests