<script sc_FindHistory>
	mydata.history.list.index 0
	.map.store_cursor_pos
	run sc_HistorySort
	NEXTSTATE st_FindHistory
</script>
<script sc_HistorySort>
	runif wSortHistoryBy "time" 'btnH_Sort_wr.TEXT "By Name", btnH_Sort_wor.TEXT "By Name", btnH_SortM.TEXT "By Name", exec "mydata.history.sort_by_time"'
	else_runif wSortHistoryBy "name" 'btnH_Sort_wr.TEXT "By Time", btnH_Sort_wor.TEXT "By Time", btnH_SortM.TEXT "By Time", exec "mydata.history.sort_by_name"'
</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/>
	<uselayer ui_FindHistory_wr/>
	<uselayer ui_FindHistory_wor/>

	<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 dFindHistoryListType 0 'ui_FindHistory_wr.hide, ui_FindHistory_wor.show'
		else_run '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>
		inpHF_Text.VALUE %mydata.history.name_filter
		vKeyTableDone.SET sc_History_SetFilter_Done
		LOADPANELTYPE 1
		Title.SET "History name filter"
		run sc_HistoryINP_onchange
		inpHF_Text.SYNCKBPANEL
	</script>
	
	<script done>
		SAVEPANELTYPE 1
	</script>
<script sc_HistoryINP_onchange>
	vTmp.TEXTMODEL_WSTR "mydata.history.name_filter"
	inpHF_Text.GET "vTmp"
	vTmp.DROPMODEL
</script>
</state>

