[GME-commit] GMESRC/GME/Console Console.vcproj, 1.5, 1.6 Resource.h, 1.2, 1.3 ConsoleCtl.cpp, 1.6, 1.7 ConsoleCtl.h, 1.4, 1.5 ScriptEdit.cpp, 1.7, 1.8 ScriptEdit.h, 1.6, 1.7 ScriptHost.cpp, 1.2, 1.3

Log messages of CVS commits gme-commit at list.isis.vanderbilt.edu
Tue Apr 15 15:04:59 CDT 2008


Update of /project/gme-repository/GMESRC/GME/Console
In directory escher:/tmp/cvs-serv30420

Modified Files:
	Console.vcproj Resource.h ConsoleCtl.cpp ConsoleCtl.h 
	ScriptEdit.cpp ScriptEdit.h ScriptHost.cpp 
Log Message:
Fixing the history behaviour.
Multiline, external script execution capability.



CVS User: Zoltan Molnar, ISIS (zolmol)

Index: Console.vcproj
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/Console.vcproj,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Console.vcproj	8 Apr 2008 21:30:45 -0000	1.5
--- Console.vcproj	15 Apr 2008 20:04:57 -0000	1.6
***************
*** 429,432 ****
--- 429,435 ----
  			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
  			<File
+ 				RelativePath=".\cleancon.bmp">
+ 			</File>
+ 			<File
  				RelativePath="Console.ico">
  			</File>
***************
*** 441,445 ****
--- 444,454 ----
  			</File>
  			<File
+ 				RelativePath=".\execscr.bmp">
+ 			</File>
+ 			<File
  				RelativePath="res\info.gif">
+ 			</File>
+ 			<File
+ 				RelativePath=".\loadscr.bmp">
  			</File>
  			<File

Index: ScriptHost.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/ScriptHost.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ScriptHost.cpp	15 Apr 2005 18:24:10 -0000	1.2
--- ScriptHost.cpp	15 Apr 2008 20:04:57 -0000	1.3
***************
*** 64,67 ****
--- 64,68 ----
  	catch(hresult_exception &e) 
  	{ 
+ 		m_console->Message( "Input parsing failed!", MSG_ERROR);
  		return e.hr;
  	}

Index: ScriptEdit.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/ScriptEdit.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ScriptEdit.h	21 Sep 2006 21:12:42 -0000	1.6
--- ScriptEdit.h	15 Apr 2008 20:04:57 -0000	1.7
***************
*** 27,31 ****
  	void SetGMEApp(IDispatch *disp);
  	void SetGMEProj(IDispatch *dsp);
! 	
  protected:
  	static const char* defPrompt;
--- 27,35 ----
  	void SetGMEApp(IDispatch *disp);
  	void SetGMEProj(IDispatch *dsp);
! 	void ExecuteScript( CString& p_str);
! 	inline void SetLoadedScript( const CString& p_script)  { m_loadedScript   = p_script; }
! 	inline void SetScriptFileName( const CString& p_fname) { m_loadedFileName = p_fname;  }
! 	inline CString& GetLoadedScript()                      { return m_loadedScript;       }
! 	inline CString& GetLoadedScriptFileName()              { return m_loadedFileName;     }
  protected:
  	static const char* defPrompt;
***************
*** 35,38 ****
--- 39,44 ----
  	typedef std::vector<CString> Strings;
  	Strings m_inputlist;
+ 	CString m_loadedScript;
+ 	CString m_loadedFileName;
  
  	DECLARE_MESSAGE_MAP()

Index: ConsoleCtl.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/ConsoleCtl.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ConsoleCtl.h	15 Apr 2005 18:24:10 -0000	1.4
--- ConsoleCtl.h	15 Apr 2008 20:04:57 -0000	1.5
***************
*** 22,26 ****
  	CConsoleCtrl();
  
! // Overrides
  	// ClassWizard generated virtual function overrides
  	//{{AFX_VIRTUAL(CConsoleCtrl)
--- 22,26 ----
  	CConsoleCtrl();
  
! 	// Overrides
  	// ClassWizard generated virtual function overrides
  	//{{AFX_VIRTUAL(CConsoleCtrl)
***************
*** 34,40 ****
--- 34,50 ----
  // protected:
  	~CConsoleCtrl();
+ 	void LoadScript( const CString& fileName);
+ 	void RunScript();
  
  	CHtmlCtrl   m_browser;
  	CScriptEdit	m_edit;
+ 	CButton	    m_cmdButton;
+ 	CButton	    m_exeButton;
+ 	CButton     m_clrButton;
+ 	CString     m_recent1;
+ 	CString     m_recent2;
+ 	CString     m_recent3;
+ 	CString     m_recent4;
+ 	CString     m_recent5;
  
  	DECLARE_OLECREATE_EX(CConsoleCtrl)    // Class factory and guid
***************
*** 46,49 ****
--- 56,66 ----
  	//{{AFX_MSG(CConsoleCtrl)
  	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ 	afx_msg void OnShowMenu();
+ 	afx_msg void LoadScriptDlg();
+ 	afx_msg void runScript();
+ 	afx_msg void relScript();
+ 	afx_msg void rlrScript();
+ 	afx_msg void selectEngine();
+ 	afx_msg void loadRecent( UINT);
  	//}}AFX_MSG
  	DECLARE_MESSAGE_MAP()

Index: Resource.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/Resource.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Resource.h	2 Dec 2004 21:58:55 -0000	1.2
--- Resource.h	15 Apr 2008 20:04:57 -0000	1.3
***************
*** 1,4 ****
  //{{NO_DEPENDENCIES}}
! // Microsoft Developer Studio generated include file.
  // Used by Console.rc
  //
--- 1,4 ----
  //{{NO_DEPENDENCIES}}
! // Microsoft Visual C++ generated include file.
  // Used by Console.rc
  //
***************
*** 12,17 ****
--- 12,33 ----
  #define IDR_CONSOLE                     103
  #define IDR_SCRIPTHOST                  104
+ #define IDC_MENU_COMMAND                105
+ #define IDC_EDITOR_COMMAND              106
+ #define IDC_LOADSCRIPT_COMMAND          107
+ #define IDC_RUNSCRIPT_COMMAND           108
+ #define IDC_CLEARCONSOLE_COMMAND        109
+ #define IDC_SELECTENGINE_COMMAND        113
+ #define IDC_RELOADRUN_COMMAND           114
+ #define IDC_RELOAD_COMMAND              115
+ #define IDC_RECENT_SCRIPT1              116
+ #define IDC_RECENT_SCRIPT2              117
+ #define IDC_RECENT_SCRIPT3              118
+ #define IDC_RECENT_SCRIPT4              119
+ #define IDC_RECENT_SCRIPT5              120
  #define IDS_CONSOLE_PPG_CAPTION         200
  #define IDD_PROPPAGE_CONSOLE            200
+ #define IDB_LOADSCR                     211
+ #define IDB_EXECSCR                     212
+ #define IDB_CLEANCON                    213
  
  // Next default values for new objects
***************
*** 19,26 ****
  #ifdef APSTUDIO_INVOKED
  #ifndef APSTUDIO_READONLY_SYMBOLS
! #define _APS_NEXT_RESOURCE_VALUE        207
  #define _APS_NEXT_COMMAND_VALUE         32768
  #define _APS_NEXT_CONTROL_VALUE         201
! #define _APS_NEXT_SYMED_VALUE           106
  #endif
  #endif
--- 35,42 ----
  #ifdef APSTUDIO_INVOKED
  #ifndef APSTUDIO_READONLY_SYMBOLS
! #define _APS_NEXT_RESOURCE_VALUE        214
  #define _APS_NEXT_COMMAND_VALUE         32768
  #define _APS_NEXT_CONTROL_VALUE         201
! #define _APS_NEXT_SYMED_VALUE           121
  #endif
  #endif

Index: ConsoleCtl.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/ConsoleCtl.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ConsoleCtl.cpp	30 Jan 2006 20:51:12 -0000	1.6
--- ConsoleCtl.cpp	15 Apr 2008 20:04:57 -0000	1.7
***************
*** 10,14 ****
  #include <mshtml.h>         //IWeb objects
  #include <limits.h>
! 
  
  
--- 10,14 ----
  #include <mshtml.h>         //IWeb objects
  #include <limits.h>
! #include <afx.h>
  
  
***************
*** 23,26 ****
--- 23,40 ----
  
  
+ #define IDC_MENU_COMMAND				105
+ #define IDC_EDITOR_COMMAND				106
+ #define IDC_LOADSCRIPT_COMMAND			107
+ #define IDC_RUNSCRIPT_COMMAND			108
+ #define IDC_CLEARCONSOLE_COMMAND        109
+ #define IDC_SELECTENGINE_COMMAND        113
+ #define IDC_RELOADRUN_COMMAND           114
+ #define IDC_RELOAD_COMMAND              115
+ #define IDC_RECENT_SCRIPT1              121
+ #define IDC_RECENT_SCRIPT2              122
+ #define IDC_RECENT_SCRIPT3              123
+ #define IDC_RECENT_SCRIPT4              124
+ #define IDC_RECENT_SCRIPT5              125
+ 
  /////////////////////////////////////////////////////////////////////////////
  // Message map
***************
*** 31,34 ****
--- 45,56 ----
  	//}}AFX_MSG_MAP
  	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
+ 	ON_COMMAND( IDC_MENU_COMMAND, OnShowMenu)
+ 	ON_COMMAND( IDC_LOADSCRIPT_COMMAND, LoadScriptDlg)
+ 	ON_COMMAND( IDC_RUNSCRIPT_COMMAND, runScript)
+ 	ON_COMMAND( IDC_RELOAD_COMMAND, relScript)
+ 	ON_COMMAND( IDC_RELOADRUN_COMMAND, rlrScript)
+ 	ON_COMMAND( IDC_CLEARCONSOLE_COMMAND, Clear)
+ 	ON_COMMAND( IDC_SELECTENGINE_COMMAND, selectEngine)
+ 	ON_COMMAND_RANGE( IDC_RECENT_SCRIPT1, IDC_RECENT_SCRIPT5, loadRecent)
  END_MESSAGE_MAP()
  
***************
*** 136,139 ****
--- 158,166 ----
  
  CConsoleCtrl::CConsoleCtrl()
+ : m_recent1("")
+ , m_recent2("")
+ , m_recent3("")
+ , m_recent4("")
+ , m_recent5("")
  {
  	InitializeIIDs(&IID_DConsole, &IID_DConsoleEvents);
***************
*** 159,169 ****
  {
  	if (m_browser.GetSafeHwnd()) {
  		CRect rect = rcBounds;
  		rect.bottom -= 20; 
! 		// move input control too 
  		m_browser.MoveWindow(rect, TRUE);
  		CRect erect = rcBounds;
  		erect.top = rect.bottom;
  		m_edit.MoveWindow(erect, TRUE);
  	}
  	else {
--- 186,221 ----
  {
  	if (m_browser.GetSafeHwnd()) {
+ 		bool  anything_loaded = !m_edit.GetLoadedScript().IsEmpty();
  		CRect rect = rcBounds;
  		rect.bottom -= 20; 
! 		// move browser
  		m_browser.MoveWindow(rect, TRUE);
  		CRect erect = rcBounds;
  		erect.top = rect.bottom;
+ 		// place 'Clear'
+ 		CRect crect = erect;
+ 		crect.left = crect.right - 16;
+ 		m_clrButton.MoveWindow( crect, TRUE);
+ 
+ 		erect.right -= 16;
+ 		erect.left += anything_loaded? 40: 20;
+ 		// move input control too 
  		m_edit.MoveWindow(erect, TRUE);
+ 
+ 		if( anything_loaded) {
+ 			erect.right = erect.left;
+ 			erect.left -= 20;
+ 			// place and show 'Execute' button
+ 			m_exeButton.MoveWindow( erect, TRUE);
+ 			m_exeButton.ShowWindow(SW_SHOW);
+ 		}
+ 		else {
+ 			m_exeButton.ShowWindow(SW_HIDE);
+ 		}
+ 
+ 		erect.right = erect.left;
+ 		erect.left -= 20;
+ 		// place the generic command button
+ 		m_cmdButton.MoveWindow( erect, TRUE);
  	}
  	else {
***************
*** 265,268 ****
--- 317,352 ----
  	bool ret = m_edit.Init(this);
  
+ 	CBitmap bm1, bm2, bm3;
+ 	bm1.LoadMappedBitmap(IDB_LOADSCR);//IDB_CONSOLE);
+ 	bm2.LoadMappedBitmap(IDB_EXECSCR);
+ 	bm3.LoadMappedBitmap(IDB_CLEANCON);
+ 
+ 	CSize bm1Size, bm2Size, bm3Size;
+ 	BITMAP bmStruct;
+ 	if (bm1.GetBitmap(&bmStruct)) bm1Size.cx = bmStruct.bmWidth, bm1Size.cy = bmStruct.bmHeight;
+ 	if (bm2.GetBitmap(&bmStruct)) bm2Size.cx = bmStruct.bmWidth, bm2Size.cy = bmStruct.bmHeight;
+ 	if (bm3.GetBitmap(&bmStruct)) bm3Size.cx = bmStruct.bmWidth, bm3Size.cy = bmStruct.bmHeight;
+ 
+ 	rect.bottom = rect.right = 100;
+ 	rect.left = rect.right - bm1Size.cx;
+ 	rect.bottom = rect.top - bm1Size.cy;
+ 
+ 	m_cmdButton.Create( _T("MenuButton"), WS_CHILD|WS_VISIBLE|BS_BITMAP, rect, this, IDC_MENU_COMMAND);
+ 	m_cmdButton.SetBitmap(bm1);
+ 
+ 	rect.right += bm2Size.cx;
+ 	rect.left  += bm2Size.cx;
+ 	m_exeButton.Create( _T("ExecButton"), WS_CHILD/*|WS_VISIBLE*/|BS_BITMAP, rect, this, IDC_RUNSCRIPT_COMMAND);
+ 	m_exeButton.SetBitmap(bm2);
+ 
+ 	rect.left  += bm3Size.cx;
+ 	rect.right += bm3Size.cx;
+ 	m_clrButton.Create( _T("ClearConsButton"), WS_CHILD|WS_VISIBLE|BS_BITMAP, rect, this, IDC_CLEARCONSOLE_COMMAND);
+ 	m_clrButton.SetBitmap(bm3);
+ 
+ 	bm1.Detach();
+ 	bm2.Detach();
+ 	bm3.Detach();
+ 
  	return 0;
  }
***************
*** 379,380 ****
--- 463,626 ----
  	SetModifiedFlag();
  }
+ 
+ void CConsoleCtrl::OnShowMenu()
+ {
+ 	if( 0 > ::GetKeyState( VK_CONTROL))
+ 	{
+ 		runScript();
+ 		return;
+ 	}
+ 	else if( 0 > ::GetKeyState( VK_SHIFT))
+ 	{
+ 		LoadScriptDlg();
+ 		return;
+ 	}
+ 
+ 	CMenu r; // recentMenu;
+ 	if( r.CreatePopupMenu())
+ 	{
+ 		if( !m_recent1.IsEmpty()) r.AppendMenu( MF_STRING, IDC_RECENT_SCRIPT1,  m_recent1);
+ 		if( !m_recent2.IsEmpty()) r.AppendMenu( MF_STRING, IDC_RECENT_SCRIPT2,  m_recent2);
+ 		if( !m_recent3.IsEmpty()) r.AppendMenu( MF_STRING, IDC_RECENT_SCRIPT3,  m_recent3);
+ 		if( !m_recent4.IsEmpty()) r.AppendMenu( MF_STRING, IDC_RECENT_SCRIPT4,  m_recent4);
+ 		if( !m_recent5.IsEmpty()) r.AppendMenu( MF_STRING, IDC_RECENT_SCRIPT5,  m_recent5);
+ 	}
+ 
+ 	CMenu p;
+ 	if( p.CreatePopupMenu())
+ 	{
+ 		p.AppendMenu( MF_STRING, IDC_LOADSCRIPT_COMMAND,   "Load Script");
+ 		if( !m_edit.GetLoadedScriptFileName().IsEmpty())
+ 			p.AppendMenu( MF_STRING,IDC_RELOAD_COMMAND, "Reload Current"); // or IDC_RELOADRUN_COMMAND
+ 		if( !m_recent1.IsEmpty()) // m_recent1 can tell us if there is anything in the recent list
+ 			p.AppendMenu( MF_POPUP, (UINT_PTR) r.GetSafeHmenu(), "Recent Scripts");
+ 		p.AppendMenu( MF_STRING, IDC_SELECTENGINE_COMMAND,   "Settings");
+ 		
+ 		CRect rc;
+ 		m_cmdButton.GetWindowRect( &rc);
+ 		p.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON, rc.left + rc.Width()/2, rc.top + rc.Height()/2, this);
+ 		Invalidate();
+ 	}
+ }
+ 
+ void CConsoleCtrl::RunScript()
+ {
+ 	if( !m_edit.GetLoadedScript().IsEmpty())
+ 	{
+ 		Message( CString( "Executing script: ") + m_edit.GetLoadedScriptFileName(), MSG_INFO);
+ 		m_edit.ExecuteScript( m_edit.GetLoadedScript());
+ 	}
+ 	else
+ 		Message( "Script not found!", MSG_INFO);
+ }
+ 
+ void CConsoleCtrl::LoadScript( const CString& p_fileName)
+ {
+ 	m_edit.SetLoadedScript(""); // erase old loaded script contents
+ 
+ 	CStdioFile _file;
+ 
+ 	// open file
+ 	if( _file.Open( p_fileName, CFile::modeRead | CFile::typeText) == 0) {
+ 		Message( "Unable to open file.", MSG_ERROR);
+ 		return;
+ 	}
+ 
+ 	CString script_buf;
+ 	unsigned int sizeof_file = (unsigned int) _file.GetLength();
+ 	sizeof_file = _file.Read( script_buf.GetBufferSetLength( sizeof_file), sizeof_file);
+ 	// sizeof_file was modified above because of newline handling
+ 	if( sizeof_file > 0) script_buf.ReleaseBufferSetLength( sizeof_file);
+ 	_file.Close();
+ 
+ 	m_edit.SetLoadedScript( script_buf);
+ 	m_edit.SetScriptFileName( p_fileName);
+ 
+ 	Message( CString( "Loaded script: ") + p_fileName, MSG_INFO);
+ }
+ 
+ void CConsoleCtrl::LoadScriptDlg()
+ {
+ 	CFileDialog dlg(TRUE, "py", 0,
+ 		OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ 		"Script Files (*.js;*.py;*.vbs)|*.js;*.vbs;*.py|"
+ 		"Python Script Files (*.py)|*.py|"
+ 		"JScript Files (*.js)|*.js|"
+ 		"VBScript Files (*.vbs)|*.vbs|"
+ 		"Text Files (*.txt)|*.txt|"
+ 		"All Files (*.*)|*.*||");
+ 
+ 	if( dlg.DoModal() == IDOK) 
+ 	{
+ 		CString fpath = dlg.GetPathName();
+ 		LoadScript( fpath);
+ 
+ 		if( m_recent1.IsEmpty())
+ 			m_recent1 = fpath;
+ 		else if( m_recent2.IsEmpty())
+ 		{
+ 			m_recent2 = m_recent1;
+ 			m_recent1 = fpath;
+ 		}
+ 		else if( m_recent3.IsEmpty())
+ 		{
+ 			m_recent3 = m_recent2;
+ 			m_recent2 = m_recent1;
+ 			m_recent1 = fpath;
+ 		}
+ 		else if( m_recent4.IsEmpty())
+ 		{
+ 			m_recent4 = m_recent3;
+ 			m_recent3 = m_recent2;
+ 			m_recent2 = m_recent1;
+ 			m_recent1 = fpath;
+ 		}
+ 		else if( m_recent5.IsEmpty())
+ 		{
+ 			m_recent5 = m_recent4;
+ 			m_recent4 = m_recent3;
+ 			m_recent3 = m_recent2;
+ 			m_recent2 = m_recent1;
+ 			m_recent1 = fpath;
+ 		}
+ 	}
+ }
+ 
+ void CConsoleCtrl::runScript()
+ {
+ 	RunScript();
+ }
+ 
+ void CConsoleCtrl::relScript() // reload
+ {
+ 	LoadScript( m_edit.GetLoadedScriptFileName());
+ }
+ 
+ void CConsoleCtrl::rlrScript() // reload & run
+ {
+ 	LoadScript( m_edit.GetLoadedScriptFileName());
+ 	RunScript();
+ }
+ 
+ void CConsoleCtrl::selectEngine()
+ {
+ 	try {
+ 		CComPtr<IMgaLauncher> launcher;
+ 		COMTHROW( launcher.CoCreateInstance(L"Mga.MgaLauncher") );
+ 		COMTHROW( launcher->GmeDlg());
+ 	}
+ 	catch(...) {
+ 		Message( "Error while trying to show GME settings dialog", MSG_ERROR);
+ 	}
+ }
+ 
+ void CConsoleCtrl::loadRecent( UINT which)
+ {
+ 	switch( which) {
+ 	case IDC_RECENT_SCRIPT1: LoadScript( m_recent1);break;
+ 	case IDC_RECENT_SCRIPT2: LoadScript( m_recent2);break;
+ 	case IDC_RECENT_SCRIPT3: LoadScript( m_recent3);break;
+ 	case IDC_RECENT_SCRIPT4: LoadScript( m_recent4);break;
+ 	case IDC_RECENT_SCRIPT5: LoadScript( m_recent5);break;
+ 	}
+ }
\ No newline at end of file

Index: ScriptEdit.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Console/ScriptEdit.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ScriptEdit.cpp	10 Apr 2008 22:32:38 -0000	1.7
--- ScriptEdit.cpp	15 Apr 2008 20:04:57 -0000	1.8
***************
*** 58,61 ****
--- 58,62 ----
  	if (nChar == VK_ESCAPE)
  	{
+ 		lastup = -1;
  		SetSel(0, -1);
  		ReplaceSel("");
***************
*** 97,101 ****
--- 98,108 ----
  		{
  			if (m_inputlist[k] == inp)
+ 			{
+ 				// shift m_inputlist[k..size - 1] by 1 to the left, to have preserve 'recentness'
+ 				for( int l  = k; l < (int) m_inputlist.size() - 1; ++l)
+ 					m_inputlist[l] = m_inputlist[l + 1];
+ 				m_inputlist[ l] = inp; // last element
  				break;
+ 			}
  		}
  		// add if inp is new
***************
*** 110,137 ****
  		}
  
! 		try
! 		{
! 			// load engine info from registry 
! 			CComPtr<IMgaRegistrar> registrar;
! 			COMTHROW(registrar.CoCreateInstance(CComBSTR("Mga.MgaRegistrar")));
! 			ASSERT( registrar != NULL );
! 			BSTR eng = NULL;
! 			COMTHROW( registrar->get_ScriptEngine(REGACCESS_USER, &eng) );
! 			_bstr_t engine("JScript");
! 			if (eng != NULL  &&  ((_bstr_t)eng).length() != 0)
! 				engine = eng;
  
! 			_bstr_t input = inp;
! 			COMTHROW(m_host->InitEngine((void*)m_console, engine));
! 			COMTHROW(m_host->ProcessString(input));
  			SetSel(0, -1);
  			Clear();
  		}
! 		catch(hresult_exception &e) 
! 		{ 
! 			char s[1000];
! 			sprintf(s, "Scripting Error: 0x%x", e.hr);
! 			m_console->Message((LPCTSTR)s, MSG_ERROR);
! 		}
  	}
  }
--- 117,141 ----
  		}
  
! 		
! 		static const char *cls_c = "!cls";
! 		static const char *run_c = "!run";
! 		static const char *lod_c = "!load ";
! 		static const char *rel_c = "!rel"; // reload
! 		static const char *rlr_c = "!rlr"; // reload & run
! 		bool             handled = false;
  
! 		if(      inp == run_c) handled = true, m_console->RunScript();
! 		else if( inp == lod_c) handled = true, m_console->LoadScript( inp.Mid( strlen( lod_c)));
! 		else if( inp == rel_c) handled = true, m_console->LoadScript( m_loadedFileName);
! 		else if( inp == rlr_c) handled = true, m_console->LoadScript( m_loadedFileName), m_console->RunScript();
! 		else if( inp == cls_c) handled = true, m_console->Clear();
! 		
! 		if( handled) {
  			SetSel(0, -1);
  			Clear();
+ 			return;
  		}
! 		else
! 			ExecuteScript( inp);
  	}
  }
***************
*** 184,185 ****
--- 188,220 ----
  	}
  }
+ 
+ void CScriptEdit::ExecuteScript( CString& p_str)
+ {
+ 	try {
+ 		// load engine info from registry 
+ 		CComPtr<IMgaRegistrar> registrar;
+ 		COMTHROW(registrar.CoCreateInstance(CComBSTR("Mga.MgaRegistrar")));
+ 		ASSERT( registrar != NULL );
+ 		BSTR eng = NULL;
+ 		COMTHROW( registrar->get_ScriptEngine(REGACCESS_USER, &eng) );
+ 		_bstr_t engine("JScript");
+ 		if (eng != NULL  &&  ((_bstr_t)eng).length() != 0)
+ 			engine = eng;
+ 
+ 		_bstr_t input = p_str;
+ 		COMTHROW(m_host->InitEngine((void*)m_console, engine));
+ 		COMTHROW(m_host->ProcessString(input));
+ 	}
+ 	catch(hresult_exception& e) {
+ 		char s[1000];
+ 		sprintf(s, "Scripting Error: 0x%x", e.hr);
+ 		m_console->Message((LPCTSTR)s, MSG_ERROR);
+ 	}
+ 	catch(...) {
+ 		m_console->Message( "Exception handled.", MSG_ERROR);
+ 	}
+ 
+ 	SetSel(0, -1);
+ 	Clear();
+ }
+ 



More information about the GME-commit mailing list