2017-08-18 05:08:22 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "DebuggerUI.h"
|
|
|
|
|
|
|
|
CDebugScripts::CDebugScripts(CDebuggerUI* debugger) :
|
2020-12-18 19:57:50 +00:00
|
|
|
CDebugDialog<CDebugScripts>(debugger),
|
2020-12-18 20:15:16 +00:00
|
|
|
CToolTipDialog<CDebugScripts>(),
|
2020-12-18 19:57:50 +00:00
|
|
|
m_hQuitScriptDirWatchEvent(NULL),
|
|
|
|
m_hScriptDirWatchThread(NULL)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CDebugScripts::~CDebugScripts(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:53:07 +00:00
|
|
|
LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
DlgResize_Init(false, true);
|
2019-01-14 07:06:01 +00:00
|
|
|
DlgSavePos_Init(DebuggerUI_ScriptsPos);
|
2020-12-18 20:15:16 +00:00
|
|
|
DlgToolTip_Init();
|
2019-01-13 08:13:59 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
HFONT monoFont = CreateFont(-11, 0, 0, 0,
|
|
|
|
FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
|
|
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
2020-05-12 12:19:05 +00:00
|
|
|
CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas"
|
2017-09-13 12:00:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
m_ScriptList.Attach(GetDlgItem(IDC_SCRIPT_LIST));
|
2020-12-18 19:57:50 +00:00
|
|
|
m_ScriptList.AddColumn(L"Status", 0);
|
|
|
|
m_ScriptList.AddColumn(L"Script", 1);
|
|
|
|
m_ScriptList.SetColumnWidth(0, 16);
|
|
|
|
m_ScriptList.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
|
2017-09-13 12:00:53 +00:00
|
|
|
m_ScriptList.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
|
|
|
|
m_ScriptList.ModifyStyle(LVS_OWNERDRAWFIXED, 0, 0);
|
|
|
|
|
|
|
|
m_EvalEdit.Attach(GetDlgItem(IDC_EVAL_EDIT));
|
|
|
|
m_EvalEdit.SetScriptWindow(this);
|
|
|
|
m_EvalEdit.SetFont(monoFont);
|
|
|
|
m_EvalEdit.EnableWindow(FALSE);
|
|
|
|
|
|
|
|
m_ConsoleEdit.Attach(GetDlgItem(IDC_CONSOLE_EDIT));
|
|
|
|
m_ConsoleEdit.SetLimitText(0);
|
|
|
|
m_ConsoleEdit.SetFont(monoFont);
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
int statusPaneWidths[] = { -1 };
|
|
|
|
m_StatusBar.Attach(GetDlgItem(IDC_STATUSBAR));
|
|
|
|
m_StatusBar.SetParts(1, statusPaneWidths);
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
RefreshList();
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
LoadWindowPos();
|
|
|
|
WindowCreated();
|
2020-12-18 19:57:50 +00:00
|
|
|
|
|
|
|
m_hQuitScriptDirWatchEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
m_hScriptDirWatchThread = CreateThread(NULL, 0, ScriptDirWatchProc, (void*)this, 0, NULL);
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
LRESULT CDebugScripts::OnDestroy(void)
|
2019-01-14 05:52:11 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
SetEvent(m_hQuitScriptDirWatchEvent);
|
|
|
|
WaitForSingleObject(m_hScriptDirWatchThread, INFINITE);
|
|
|
|
CloseHandle(m_hQuitScriptDirWatchEvent);
|
|
|
|
CloseHandle(m_hScriptDirWatchThread);
|
|
|
|
return 0;
|
2019-01-14 05:52:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
LRESULT CDebugScripts::OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
HDC hDC = (HDC)wParam;
|
|
|
|
HWND hCtrl = (HWND)lParam;
|
|
|
|
WORD ctrlId = (WORD) ::GetWindowLong(hCtrl, GWL_ID);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
if (ctrlId == IDC_CONSOLE_EDIT)
|
|
|
|
{
|
|
|
|
SetBkColor(hDC, RGB(255, 255, 255));
|
|
|
|
SetDCBrushColor(hDC, RGB(255, 255, 255));
|
|
|
|
return (LRESULT)GetStockObject(DC_BRUSH);
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
DWORD WINAPI CDebugScripts::ScriptDirWatchProc(void* ctx)
|
|
|
|
{
|
|
|
|
CDebugScripts* _this = (CDebugScripts*)ctx;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
HANDLE hEvents[2];
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
hEvents[0] = FindFirstChangeNotification(L"Scripts", FALSE, FILE_NOTIFY_CHANGE_FILE_NAME);
|
|
|
|
|
|
|
|
if (hEvents[0] == INVALID_HANDLE_VALUE)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
return 0;
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
hEvents[1] = _this->m_hQuitScriptDirWatchEvent;
|
2019-04-29 06:28:12 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
while (true)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
DWORD status = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
if (FindNextChangeNotification(hEvents[0]) == FALSE)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
_this->PostMessage(WM_REFRESH_LIST, 0, 0);
|
|
|
|
break;
|
|
|
|
case WAIT_OBJECT_0 + 1:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
void CDebugScripts::OnExitSizeMove(void)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
SaveWindowPos(true);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugScripts::ConsoleCopy()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!OpenClipboard())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyClipboard();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
size_t nChars = m_ConsoleEdit.GetWindowTextLength() + 1;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, nChars * sizeof(wchar_t));
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t* memBuf = (wchar_t*)GlobalLock(hMem);
|
|
|
|
m_ConsoleEdit.GetWindowText(memBuf, nChars);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
GlobalUnlock(hMem);
|
2020-12-18 20:21:49 +00:00
|
|
|
SetClipboardData(CF_UNICODETEXT, hMem);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
GlobalFree(hMem);
|
|
|
|
CloseClipboard();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
void CDebugScripts::ConsolePrint(const char* text)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
if (m_hWnd != NULL)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
SendMessage(WM_CONSOLE_PRINT, (WPARAM)text);
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2020-12-18 19:57:50 +00:00
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
void CDebugScripts::ConsoleClear()
|
|
|
|
{
|
|
|
|
if (m_hWnd != NULL)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
SendMessage(WM_CONSOLE_CLEAR);
|
|
|
|
}
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
void CDebugScripts::RefreshList()
|
|
|
|
{
|
|
|
|
if (m_hWnd != NULL)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
PostMessage(WM_REFRESH_LIST);
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugScripts::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
switch (wID)
|
|
|
|
{
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(0);
|
|
|
|
break;
|
|
|
|
case ID_POPUP_RUN:
|
2020-12-18 19:57:50 +00:00
|
|
|
case IDC_RUN_BTN:
|
2017-09-13 12:00:53 +00:00
|
|
|
RunSelected();
|
|
|
|
break;
|
|
|
|
case ID_POPUP_STOP:
|
2020-12-18 19:57:50 +00:00
|
|
|
case IDC_STOP_BTN:
|
2017-09-13 12:00:53 +00:00
|
|
|
StopSelected();
|
|
|
|
break;
|
2020-01-07 03:58:43 +00:00
|
|
|
case ID_POPUP_SCRIPT_EDIT:
|
|
|
|
EditSelected();
|
|
|
|
break;
|
2017-09-13 12:00:53 +00:00
|
|
|
case IDC_CLEAR_BTN:
|
|
|
|
ConsoleClear();
|
|
|
|
break;
|
|
|
|
case IDC_COPY_BTN:
|
|
|
|
ConsoleCopy();
|
|
|
|
break;
|
2020-12-18 19:57:50 +00:00
|
|
|
case IDC_SCRIPTDIR_BTN:
|
|
|
|
ShellExecute(NULL, L"open", L"Scripts", NULL, NULL, SW_SHOW);
|
|
|
|
break;
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
LRESULT CDebugScripts::OnScriptListDblClicked(NMHDR* pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
// Run script on double click
|
|
|
|
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR);
|
|
|
|
int nItem = pIA->iItem;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
if (nItem == -1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-01-07 03:43:09 +00:00
|
|
|
ToggleSelected();
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugScripts::RefreshStatus()
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
stdstr statusText;
|
2021-01-19 05:58:59 +00:00
|
|
|
CPath(stdstr_f("Scripts\\%s", m_SelectedScriptName.c_str())).GetFullyQualified(statusText);
|
2020-12-18 19:57:50 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (state == STATE_RUNNING)
|
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
statusText += " (Running)";
|
2017-09-13 12:00:53 +00:00
|
|
|
m_EvalEdit.EnableWindow(TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
if (state == STATE_STARTED)
|
|
|
|
{
|
|
|
|
statusText += " (Started)";
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
m_EvalEdit.EnableWindow(FALSE);
|
|
|
|
}
|
2020-12-18 19:57:50 +00:00
|
|
|
|
|
|
|
m_StatusBar.SetText(0, statusText.ToUTF16().c_str());
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
LRESULT CDebugScripts::OnScriptListRClicked(NMHDR* pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR);
|
|
|
|
int nItem = pIA->iItem;
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
if (nItem == -1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_SCRIPT_POPUP));
|
|
|
|
HMENU hPopupMenu = GetSubMenu(hMenu, 0);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
if (state == STATE_STARTED || state == STATE_RUNNING)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2020-12-18 19:57:50 +00:00
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUP_RUN, MF_DISABLED | MF_GRAYED);
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2020-12-18 19:57:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUP_STOP, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
POINT mouse;
|
|
|
|
GetCursorPos(&mouse);
|
|
|
|
TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, mouse.x, mouse.y, 0, m_hWnd, NULL);
|
|
|
|
DestroyMenu(hMenu);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugScripts::OnScriptListCustomDraw(NMHDR* pNMHDR)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
|
|
|
|
DWORD drawStage = pLVCD->nmcd.dwDrawStage;
|
|
|
|
|
|
|
|
switch (drawStage)
|
|
|
|
{
|
|
|
|
case CDDS_PREPAINT:
|
|
|
|
return CDRF_NOTIFYITEMDRAW;
|
|
|
|
case CDDS_ITEMPREPAINT:
|
|
|
|
return CDRF_NOTIFYSUBITEMDRAW;
|
|
|
|
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD nItem = pLVCD->nmcd.dwItemSpec;
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t scriptName[MAX_PATH];
|
2020-12-18 19:57:50 +00:00
|
|
|
m_ScriptList.GetItemText(nItem, 1, scriptName, MAX_PATH);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(stdstr("").FromUTF16(scriptName).c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
if (state == STATE_STARTED)
|
|
|
|
{
|
|
|
|
pLVCD->clrTextBk = RGB(0xFF, 0xFF, 0xAA);
|
|
|
|
}
|
|
|
|
else if (state == STATE_RUNNING)
|
|
|
|
{
|
|
|
|
pLVCD->clrTextBk = RGB(0xAA, 0xFF, 0xAA);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CDRF_DODEFAULT;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
LRESULT CDebugScripts::OnScriptListItemChanged(NMHDR* pNMHDR)
|
|
|
|
{
|
|
|
|
NMLISTVIEW* lpStateChange = reinterpret_cast<NMLISTVIEW*>(pNMHDR);
|
|
|
|
if ((lpStateChange->uNewState ^ lpStateChange->uOldState) & LVIS_SELECTED)
|
|
|
|
{
|
|
|
|
if (lpStateChange->iItem == -1)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t ScriptName[MAX_PATH];
|
|
|
|
|
|
|
|
m_ScriptList.GetItemText(lpStateChange->iItem, 1, ScriptName, MAX_PATH);
|
2021-01-19 05:58:59 +00:00
|
|
|
m_SelectedScriptName = stdstr().FromUTF16(ScriptName).c_str();
|
2020-12-18 19:57:50 +00:00
|
|
|
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2020-12-18 19:57:50 +00:00
|
|
|
|
|
|
|
::EnableWindow(GetDlgItem(IDC_STOP_BTN), state == STATE_RUNNING || state == STATE_STARTED);
|
|
|
|
::EnableWindow(GetDlgItem(IDC_RUN_BTN), state == STATE_STOPPED || state == STATE_INVALID);
|
|
|
|
|
|
|
|
RefreshStatus();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugScripts::OnConsoleLog(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
const char *text = (const char*)wParam;
|
|
|
|
|
|
|
|
::ShowWindow(*this, SW_SHOWNOACTIVATE);
|
|
|
|
|
|
|
|
SCROLLINFO scroll;
|
|
|
|
scroll.cbSize = sizeof(SCROLLINFO);
|
|
|
|
scroll.fMask = SIF_ALL;
|
|
|
|
m_ConsoleEdit.GetScrollInfo(SB_VERT, &scroll);
|
|
|
|
|
|
|
|
m_ConsoleEdit.SetRedraw(FALSE);
|
|
|
|
m_ConsoleEdit.AppendText(stdstr(text).ToUTF16().c_str());
|
|
|
|
m_ConsoleEdit.SetRedraw(TRUE);
|
|
|
|
|
|
|
|
if ((scroll.nPage + scroll.nPos) - 1 == (uint32_t)scroll.nMax)
|
|
|
|
{
|
|
|
|
m_ConsoleEdit.ScrollCaret();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugScripts::OnConsoleClear(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
m_ConsoleEdit.SetWindowText(L"");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
int nIndex = m_ScriptList.GetSelectedIndex();
|
|
|
|
|
|
|
|
CPath SearchPath("Scripts", "*");
|
|
|
|
|
|
|
|
if (!SearchPath.FindFirst(CPath::FIND_ATTRIBUTE_ALLFILES))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ScriptList.SetRedraw(false);
|
|
|
|
m_ScriptList.DeleteAllItems();
|
|
|
|
|
|
|
|
size_t nItem = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
stdstr scriptFileName = SearchPath.GetNameExtension();
|
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(scriptFileName.c_str());
|
|
|
|
const wchar_t *statusIcon = L"";
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case STATE_STARTED:
|
|
|
|
statusIcon = L"*";
|
|
|
|
break;
|
|
|
|
case STATE_RUNNING:
|
|
|
|
statusIcon = L">";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusIcon = L"-";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ScriptList.AddItem(nItem, 0, statusIcon);
|
|
|
|
m_ScriptList.SetItemText(nItem, 1, scriptFileName.ToUTF16().c_str());
|
|
|
|
nItem++;
|
|
|
|
} while (SearchPath.FindNext());
|
|
|
|
|
|
|
|
m_ScriptList.SetRedraw(true);
|
|
|
|
m_ScriptList.Invalidate();
|
|
|
|
|
|
|
|
if (nIndex >= 0)
|
|
|
|
{
|
|
|
|
m_ScriptList.SelectItem(nIndex);
|
|
|
|
RefreshStatus();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
void CDebugScripts::EvaluateInSelectedInstance(const char* code)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
if (state == STATE_RUNNING || state == STATE_STARTED)
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
CScriptInstance* instance = m_Debugger->ScriptSystem()->GetInstance(m_SelectedScriptName.c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
instance->Eval(code);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 19:57:50 +00:00
|
|
|
void CDebugScripts::RunSelected()
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
if (m_SelectedScriptName.empty())
|
2020-12-18 20:15:16 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2020-12-18 19:57:50 +00:00
|
|
|
|
|
|
|
if (state == STATE_INVALID || state == STATE_STOPPED)
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
m_Debugger->ScriptSystem()->RunScript(m_SelectedScriptName.c_str());
|
2020-12-18 19:57:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Debugger->Debug_LogScriptsWindow("[Error: Script is already running]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugScripts::StopSelected()
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
m_Debugger->ScriptSystem()->StopScript(m_SelectedScriptName.c_str());
|
2020-12-18 19:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugScripts::ToggleSelected()
|
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
INSTANCE_STATE state = m_Debugger->ScriptSystem()->GetInstanceState(m_SelectedScriptName.c_str());
|
2020-12-18 19:57:50 +00:00
|
|
|
|
|
|
|
if (state == STATE_INVALID || state == STATE_STOPPED)
|
|
|
|
{
|
|
|
|
RunSelected();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StopSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugScripts::EditSelected()
|
|
|
|
{
|
|
|
|
ShellExecute(NULL, L"edit", stdstr(m_SelectedScriptName).ToUTF16().c_str(), NULL, L"Scripts", SW_SHOWNORMAL);
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
// Console input
|
2018-01-18 06:53:07 +00:00
|
|
|
LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (wParam == VK_UP)
|
|
|
|
{
|
|
|
|
if (m_HistoryIdx > 0)
|
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t* code = m_History[--m_HistoryIdx];
|
|
|
|
SetWindowText(code);
|
|
|
|
int selEnd = wcslen(code);
|
2017-09-13 12:00:53 +00:00
|
|
|
SetSel(selEnd, selEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wParam == VK_DOWN)
|
|
|
|
{
|
|
|
|
int size = m_History.size();
|
|
|
|
if (m_HistoryIdx < size - 1)
|
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t* code = m_History[++m_HistoryIdx];
|
|
|
|
SetWindowText(code);
|
|
|
|
int selEnd = wcslen(code);
|
2017-09-13 12:00:53 +00:00
|
|
|
SetSel(selEnd, selEnd);
|
|
|
|
}
|
|
|
|
else if (m_HistoryIdx < size)
|
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
SetWindowText(L"");
|
2017-09-13 12:00:53 +00:00
|
|
|
m_HistoryIdx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wParam == VK_RETURN)
|
|
|
|
{
|
|
|
|
if (m_ScriptWindow == NULL)
|
|
|
|
{
|
|
|
|
bHandled = FALSE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t codeLength = GetWindowTextLength() + 1;
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t* code = (wchar_t*)malloc(codeLength * sizeof(wchar_t));
|
|
|
|
GetWindowText(code, codeLength);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
m_ScriptWindow->EvaluateInSelectedInstance(stdstr().FromUTF16(code).c_str());
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
SetWindowText(L"");
|
2017-09-13 12:00:53 +00:00
|
|
|
int historySize = m_History.size();
|
|
|
|
|
|
|
|
// remove duplicate
|
|
|
|
for (int i = 0; i < historySize; i++)
|
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
if (wcscmp(code, m_History[i]) == 0)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
|
|
|
free(m_History[i]);
|
|
|
|
m_History.erase(m_History.begin() + i);
|
|
|
|
historySize--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove oldest if maxed
|
|
|
|
if (historySize >= HISTORY_MAX_ENTRIES)
|
|
|
|
{
|
|
|
|
m_History.erase(m_History.begin() + 0);
|
|
|
|
historySize--;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_History.push_back(code);
|
|
|
|
m_HistoryIdx = ++historySize;
|
|
|
|
}
|
|
|
|
bHandled = FALSE;
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|