<script sc_FindHistory>
	mydata.history.list.index 0
	.map.store_cursor_pos
	run sc_HistorySort
	NEXTSTATE st_FindHistory
</script>
<script sc_HistorySortChange>
	runif wSortHistoryBy "time" 'wSortHistoryBy.set "name"'
	else_runif wSortHistoryBy "name" 'wSortHistoryBy.set "time"'
	run sc_HistorySort
</script>
<script sc_History_SetFilter>
	NEXTSTATE st_HistoryFilter
</script>
<script sc_History_SetFilter_Done>
	inpHF_Text.GET "vTmp"
	mydata.history.name_filter vTmp
	PREVSTATE
</script>
<state st_FindHistory>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>

	<script init>
		runif %mydata.history.name_filter L"" 'Title.set "History"'
		else_run 'Title.COMBINED_TEXTMODEL "History - $mydata.history.name_filter:*$", Title.dropmodel'
		run sc_HistorySort
		runif vAddFromDoneScript 1 'btn_chhistmode.disable, ui_FindHistory_wr.hide, ui_FindHistory_wor.show'
		else_runif vAddFromDoneScript 3 'btn_chhistmode.disable, ui_FindHistory_wr.hide, ui_FindHistory_wor.show'
		else_runif dFindHistoryListType 0 'btn_chhistmode.enable, ui_FindHistory_wr.hide, ui_FindHistory_wor.show'
		else_run 'btn_chhistmode.enable, ui_FindHistory_wor.hide, ui_FindHistory_wr.show'
	</script>
	<script done>
		mydata.history.name_filter L""
	</script>
</state>

<script sc_SearchHistoryAndGo>
	SELECT_HISTORY %mydata.history.list.index
	run sc_OpenMapAfterFind
</script>

<state st_ManageHistory>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ManageHistory/>

	<script init>
		runif %mydata.history.name_filter L"" 'Title.set "Manage History"'
		else_run 'Title.COMBINED_TEXTMODEL "Manage History - $mydata.history.name_filter:*$", Title.dropmodel'
		run sc_HistorySort
		runif %mydata.history.list.size 0 'btnMH_ClearAll.disable'
		else_run 'btnMH_ClearAll.enable'
	</script>
	<script done>
		mydata.history.name_filter L""
	</script>
</state>

<script sc_btnMH_ClearAll_OnRelease>
	INITMESSAGEBOX 1 "Deleting all history entries." 'CLEARHISTORY, mydata.history.name_filter L"", STATE st_ManageHistory'
</script>

<script sc_et_ManageHistoryDel_OnRelease>
	INITMESSAGEBOX 1 "Deleting history entry." 'REMOVEHISTORYITEM %mydata.history.list.index, STATE st_ManageHistory'
</script>
<script d_ChandeModeListRouteHistory>
	runif dFindHistoryListType 0 'dFindHistoryListType.set 1'
	else_run 'dFindHistoryListType.set 0'
	runif $1 0 st_FindHistory_init
</script>
<state st_HistoryFilter>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_wFindHistorySearch/>

	<script init>
		LOADPANELTYPE 1
		KEY "RETURN" vKeyTableDone
		vInputDest.SET %mydata.history.name_filter
		inpHF_Text.VALUE vInputDest
		vKeyTableDone.SET sc_History_SetFilter_Done
		vInputDoneScript.SET sc_History_SetFilter_Done
		vInputDoneScriptSet.set 1		
		Title.SET "History name filter"
		inpHF_Text.SYNCKBPANEL
		run sc_HistoryINP_onchange
	</script>
	
	<script done>
		SAVEPANELTYPE 1
		KEY "RETURN"
		local.keyboard.on_close_panel
	</script>
<script sc_HistoryINP_onchange>
	vTmp.TEXTMODEL_WSTR "mydata.history.name_filter"
	inpHF_Text.GET "vTmp"
	vTmp.DROPMODEL
</script>
</state>

