;on *:dialog:triv.hlp:init:0: { loadbuf -o triv.hlp 1 $scriptdirtrivia-readme.txt | did -c triv.hlp 1 1 }
;alias  -l triv.hlp { dialog -m triv.hlp triv.hlp }
;alias triv.hlp.ask { if ($input(Yardım Dosyasını Okumak istiyormusunuz?,8) == $true) { triv.hlp } }
;----========================================================
;alias -l triv.numQuestions { return $lines($scriptdirtrivia.txt)  } 

dialog triv {
  option dbu
  title "TriviaBot v5.0 Soru Dosyalarını Düzenleme Diyalogu --- ( Kısayol : F5 )"
  size -1 -1 385 220

  tab "Soru Düzenleme", 70, 5 5 365 210
  tab "Dosya Yönetimi", 71, 5 5 365 210

  list 1, 10 30 350 80
  list 6,40 130 60 80,tab71

  button "&Yukarı", 91, 270 110 20 10,tab70
  button "&Aşağı", 92, 247 110 20 10,tab70
  button "&Soruları Sil", 99, 190 110 50 10,tab70

  text "", 20, 40 112 90 10
  text "", 26, 155 112 200 10,tab71
  text "Soru:",21, 10 120 35 10,tab70
  text "Cevap 1:", 22, 15 147 35 10,tab70
  text "Cevap 2:", 23, 15 157 35 10,tab70
  text "Cevap 3:", 323, 15 167 35 10,tab70
  text "Cevap 4:", 324, 15 177 35 10,tab70
  text "Cevap 5:", 325, 15 187 35 10,tab70

  text "Cevap 6:", 326, 190 147 35 10,tab70
  text "Cevap 7:", 327, 190 157 35 10,tab70
  text "Cevap 8:", 328, 190 167 35 10,tab70
  text "Cevap 9:", 329, 190 177 35 10,tab70
  text "Cevap 10:", 330, 190 187 35 10,tab70

  edit "", 11, 10 130 350 10,tab70,autohs,limit 400

  edit "", 12, 45 145 130 10,tab70,autohs
  edit "", 13, 45 155 130 10,tab70,autohs
  edit "", 14, 45 165 130 10,tab70,autohs
  edit "", 15, 45 175 130 10,tab70,autohs
  edit "", 16, 45 185 130 10,tab70,autohs

  edit "", 17, 220 145 130 10,tab70,autohs
  edit "", 18, 220 155 130 10,tab70,autohs
  edit "", 19, 220 165 130 10,tab70,autohs
  edit "", 24, 220 175 130 10,tab70,autohs
  edit "", 25, 220 185 130 10,tab70,autohs

  button "&Soruyu Kaydet", 93, 45 200 55 10,tab70
  button "&Soruları Temizle", 94, 110 200 55 10,tab70
  button "&Soru Ekle", 95, 175 200 55 10,tab70

  button "İsim Değiştir", 7, 150 130 55 10,tab71
  button "Dosyayı Sil", 8, 150 150 55 10,tab71
  button "Yeni Dosya Aç", 9, 150 170 55 10,tab71
  ;--
  button "Kapat", 90, 240 200 55 10, cancel
}

alias -l triv.status { did -ra triv 20 $1- }
alias -l triv.status2 { did -ra triv 26 $1- }
alias triv.dlg { dialog -dm triv triv }
;-----------------------------------

on *:DIALOG:triv:sclick:6: { triv.switchfile } 

on *:dialog:triv:init:0: {  
  if (%compfile != $null) && ($read(%compfile,1) != $null) { loadbuf -o triv 1 %compfile }
  else {  if (0 == $findfile($mircdirlst,*,0)) { /write lst/trivia.txt Bu Scriptin Adı Nedir*TriviaBot v5.0 | %compfile = lst/trivia.txt | loadbuf -o triv 1 %compfile  }
  else { %compfile = lst\ $+ $nopath($findfile($mircdirlst,*,1)) | loadbuf -o triv 1 %compfile } } 
  gview 
}
on *:dialog:triv:sclick:*: {
  if ($did == 1) { triv.showQuestion $did(triv,1).sel }
  if ($did == 7) { triv.renamefile $did(triv,6).sel }
  if ($did == 8) { triv.deletefile $did(triv,6).sel }
  if ($did == 9) { triv.newfile $did(triv,6).sel }
  if ($did == 91) { triv.moveUp $did(triv,1).sel }
  if ($did == 92) { triv.moveDown $did(triv,1).sel }
  if ($did == 93) { triv.saveQuestion $did(triv,1).sel }
  if ($did == 94) { triv.clearQuestion }
  if ($did == 95) { triv.addQuestion }
  if ($did == 99) { triv.delQuestion $did(triv,1).sel }
}
;---
alias -l triv.moveUp {
  var %temp = $did(triv,1).seltext
  if ($$1 <= 1 || %temp == $null) { return }
  var %new = $calc($$1 - 1)
  write -l $+ [ $$1 ] %compfile $did(triv,1,%new)
  write -l $+ [ %new ] %compfile %temp
  did -o triv 1 $$1 $did(triv,1,%new)
  did -o triv 1 %new %temp 
  did -c triv 1 %new
  triv.status Soru Numarası %new Son $did(triv,1).lines $+ .
}
;--
alias -l triv.moveDown {
  var %temp = $did(triv,1).seltext
  if ($$1 > $did(triv,1).lines || %temp == $null) return
  var %new = $calc($$1 + 1)
  write -l $+ [ $$1 ] %compfile $did(triv,1,%new)
  write -l $+ [ %new ] %compfile %temp
  did -o triv 1 $$1 $did(triv,1,%new)
  did -o triv 1 %new %temp 
  did -c triv 1 %new
  triv.status Soru Numarası %new Son $did(triv,1).lines $+ .

}
alias -l triv.showQuestion {
  triv.status Soru Numarası $$1 Son $did(triv,1).lines $+ .
  triv.editQuestionVars $$1
  did -ra triv 11 %triv.edit.question
  did -ra triv 12 %triv.edit.answer1
  did -ra triv 13 %triv.edit.answer2
  did -ra triv 14 %triv.edit.answer3
  did -ra triv 15 %triv.edit.answer4
  did -ra triv 16 %triv.edit.answer5
  did -ra triv 17 %triv.edit.answer6
  did -ra triv 18 %triv.edit.answer7
  did -ra triv 19 %triv.edit.answer8
  did -ra triv 24 %triv.edit.answer9
  did -ra triv 25 %triv.edit.answer10

}
alias -l triv.deletefile {
  triv.status2 Soru Dosyası %compfile Kaldırıldı!!
  remove -b %compfile
  did -d triv 6 $$1
}
alias -l triv.switchfile {
  %compfile = lst\ $+ $did(triv,6,$did(triv,6).sel).text
  triv.status2 %compfile
  did -r triv 1
  loadbuf -o triv 1 %compfile
  triv.status
}
alias -l triv.renamefile {
  var %oldcompfile = %compfile 
  var %newfilename = $$?"Dosyanın ismi ne olsun?"
  rename %compfile lst\ $+ %newfilename
  %compfile = lst\ $+ %newfilename
  did -o triv 6 $$1 %newfilename
  triv.status2 %oldcompfile Dosyanın ismi değiştirildi  %compfile
}

alias -l triv.newfile {
  inc %nf 1
  var %newfile = lst/newfile $+ %nf $+ .txt
  write %newfile Bu Scriptin Adı Nedir*TriviaBot v5.0
  triv.status2 %newfile Yeni Dosya Oluşturuldu!!
  did -r triv 6
  loadbuf -o triv 6 $gview
}

alias -l triv.saveQuestion {
  if ($did(triv,11) != $null) && ($did(triv,12) != $null) { %questiontosave = $did(triv,11) $+ $chr(42) $+ $did(triv,12) }
  if ($did(triv,13) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,13) }
  if ($did(triv,14) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,14) }
  if ($did(triv,15) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,15) }
  if ($did(triv,16) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,16) }
  if ($did(triv,17) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,17) }
  if ($did(triv,18) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,18) }
  if ($did(triv,19) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,19) }
  if ($did(triv,24) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,24) }
  if ($did(triv,25) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,25) }
  write -l $+ [ $$1 ] %compfile %questiontosave
  did -o triv 1 $$1 %questiontosave

  triv.status Sorular Kaydedildi!
  unset %questiontosave
}
alias -l triv.addQuestion {
  if ($did(triv,11) != $null) && ($did(triv,12) != $null) { %questiontosave = $did(triv,11) $+ $chr(42) $+ $did(triv,12) }
  if ($did(triv,13) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,13) }
  if ($did(triv,14) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,14) }
  if ($did(triv,15) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,15) }
  if ($did(triv,16) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,16) }
  if ($did(triv,17) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,17) }
  if ($did(triv,18) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,18) }
  if ($did(triv,19) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,19) }
  if ($did(triv,24) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,24) }
  if ($did(triv,25) != $null) { %questiontosave = %questiontosave $+ $chr(42) $+ $did(triv,25) }
  write %compfile %questiontosave
  did -a triv 1 %questiontosave

  triv.clearQuestion
  triv.status Soru Eklendi!
  unset %questiontosave
}
alias -l triv.delQuestion {
  write -dl $+ [ $$1 ] %compfile 
  did -d triv 1 $$1
  triv.status Soru Silindi..
}
alias -l triv.clearQuestion { did -r triv 11,12,13,14,15,16,17,18,19,24,25 | triv.status }
;--

alias triv.editQuestionVars {
  %triv.line = $read(%compfile, $$1)
  %triv.edit.question = $gettok(%triv.line,1,42)
  %triv.edit.answer1 = $gettok(%triv.line,2,42)
  %triv.edit.answer2 = $gettok(%triv.line,3,42)
  %triv.edit.answer3 = $gettok(%triv.line,4,42)
  %triv.edit.answer4 = $gettok(%triv.line,5,42)
  %triv.edit.answer5 = $gettok(%triv.line,6,42)
  %triv.edit.answer6 = $gettok(%triv.line,7,42)
  %triv.edit.answer7 = $gettok(%triv.line,8,42)
  %triv.edit.answer8 = $gettok(%triv.line,9,42)
  %triv.edit.answer9 = $gettok(%triv.line,10,42)
  %triv.edit.answer10 = $gettok(%triv.line,11,42)
}

alias gview {
  unset %cttf
  :fetch
  inc %cttf
  did -a triv 6 $nopath($findfile($mircdirlst,*,%cttf))
  if (%cttf == $findfile($mircdirlst,*,0)) { halt } | else { goto fetch }
}
