Skip to content

Commit

Permalink
Delete inactive row from ListView via Delete.
Browse files Browse the repository at this point in the history
fix: Delete from ListView: sync with table.
fix: BinarySearch: optional Next args.
  • Loading branch information
ZashIn committed May 2, 2020
1 parent b62aa6c commit 15ab880
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Lib/BinarySearch.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class BinarySearchClass {
return this
}

Next(ByRef k, ByRef v) {
if (++this.i <= 0)
Next(ByRef k := 0, ByRef v := "") {
if (++this.i <= 0 || this.i >= this.sortedArray.Length())
return false
isMatch := this.IsMatch(this.GetEntry(this.i))
if (isMatch) {
Expand Down
47 changes: 32 additions & 15 deletions PlanetSide2-kick-assistant.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ listViewHeaders := "Inactive?|Character Name|Last Login|Battle Rank (Prestige Le
inactiveColumn := 1
inactiveMark := "x" ; In the first column ("Inactive?")
searchColumn := 2 ; 0 to disable
addIndexColumn := true ; Add an index column to the table.
; Hotkeys: to be changed in the Hotkeys function below, accordingly
scrollHotkeyName = Forward
messageHotkeyName = Back
Expand Down Expand Up @@ -116,7 +117,9 @@ CreateGUI() {
; Menu after Paste

; ListView
Gui, Add, ListView, xm w%fullWidth% r%nListViewRowsVisible% Grid vListView hwndhListView, %listViewHeaders%|Index
Gui, Add, ListView, xm w%fullWidth% r%nListViewRowsVisible% Grid vListView hwndhListView gListViewHandler +AltSubmit, % listViewHeaders . (addIndexColumn ? "|Index" : "")
if (addIndexColumn)
LV_ModifyCol(LV_GetCount("Col"), "Integer")
resizeControls.wh.Push("ListView")

local buttonWidth := 100 + fontSize
Expand Down Expand Up @@ -157,7 +160,6 @@ CreateGUI() {
Gui, Add, Button, x%rightX% y%rightY% w%buttonWidth% vCancelButton gGuiClose, &Cancel
resizeControls.xy.Push("CancelButton")

LV_ModifyCol(LV_GetCount("Col"), "Integer")
GuiControl, Focus, ScrollToNextInactiveButton

; Menu
Expand Down Expand Up @@ -210,6 +212,13 @@ AlwaysOnTopToggle() {
Gui, Show
}

; ListView
ListViewHandler() {
If (A_GuiEvent = "K" && A_EventInfo = 0x2E) { ; Delete key
DeleteSelectedInactive()
}
}

; # Buttons

GuiClose() {
Expand Down Expand Up @@ -251,11 +260,11 @@ Search() {
static binSearch
Gui, Submit, NoHide
; Search case insensitive
if (!binSearch || binSearch.pattern != SearchEdit) {
if (!binSearch || table != binSearch.sortedArray || binSearch.pattern != SearchEdit) {
binSearch := BinarySearch(table, SearchEdit, searchColumn, tableOffset, true)
}
; Get next or first item if no more found (circular).
if (!binSearch.Next(i, v) && !((binSearch := binSearch._NewEnum()).Next(i, v))) {
if (!binSearch.Next(i) && !((binSearch := binSearch._NewEnum()).Next(i))) {
MsgBox, 0x40010, Search, %SearchEdit% not found!
return
}
Expand All @@ -278,8 +287,6 @@ ScrollToNextInactive() {

i := LV_GetNext()
if (DeleteSelectedInactive()) {
LV_Modify(i, "Focus Select Vis")
UpdateGuiCounter()
i := LV_GetNext()
}

Expand Down Expand Up @@ -361,7 +368,7 @@ PostIngameMessage() {

; Fill the ListView from clipboard
UpdateListViewFromClip() {
global listViewHeaders
global listViewHeaders, addIndexColumn
table := ParseListFromClipBoard()
if (table.Length() = 0) {
MsgBox, 0x40010, Clipboard parsing, Could not parse the clipboard!
Expand All @@ -370,8 +377,9 @@ UpdateListViewFromClip() {
; Check for header
withHeader := false
Loop, Parse, listViewHeaders, "|"
withHeader := table[1, A_Index] = A_LoopField
FillListView(table, withHeader)
if !(withHeader := table[1, A_Index] = A_LoopField)
break
FillListView(table, withHeader, addIndexColumn)
UpdateGuiCounter()
ShowGui()
}
Expand Down Expand Up @@ -412,8 +420,15 @@ FillListView(arr, withHeader := false, addRowIndex := true) {
enum.Next(, head)
if (addRowIndex)
head.Push("Index")
for r, h in head
LV_ModifyCol(r,, h)
; Delete all columns
nCols := LV_GetCount("Col")
while (nCols > 0)
LV_DeleteCol(nCols--)
; Insert columns (names)
for c, h in head
LV_InsertCol(c,, h)
if (addRowIndex)
LV_ModifyCol(LV_GetCount("Col"), "Integer")
table.Push(head)
tableOffset := 1
}
Expand All @@ -422,8 +437,8 @@ FillListView(arr, withHeader := false, addRowIndex := true) {

While enum[i, row]
{
;~ row := StrSplit(row, "|" )
row.Push(i - tableOffset) ; Add row index.
if (addRowIndex)
row.Push(i - tableOffset) ; Add row index.
LV_Add("", row*)
table.Push(row)
; Count inactive
Expand Down Expand Up @@ -462,14 +477,16 @@ FindNextInactive(i := 0) {

; Delete the selected row, if marked as inactive member
DeleteSelectedInactive() {
global inactiveColumn, inactiveMark, nInactive
global inactiveColumn, inactiveMark, nInactive, table, tableOffset
i := LV_GetNext()
LV_GetText(text, i, inactiveColumn)
if (text = inactiveMark) {
table.RemoveAt(tableOffset + i)
LV_Delete(i)
nInactive--
nKicks++
;~ nKicks++
UpdateGuiCounter()
LV_Modify(i, "Focus Select Vis")
return i
}
return 0
Expand Down

0 comments on commit 15ab880

Please sign in to comment.