81c2858
To: vim-dev@vim.org
81c2858
Subject: Patch 7.2.150 (extra)
81c2858
Fcc: outbox
81c2858
From: Bram Moolenaar <Bram@moolenaar.net>
81c2858
Mime-Version: 1.0
81c2858
Content-Type: text/plain; charset=ISO-8859-1
81c2858
Content-Transfer-Encoding: 8bit
81c2858
------------
81c2858
81c2858
Note: I haven't tested this myself, since I don't have a compiler that
81c2858
works for this code.
81c2858
81c2858
Patch 7.2.150 (extra)
81c2858
Problem:    Can't use tab pages from VisVim.
81c2858
Solution:   Add tab page support to VisVim. (Adam Slater)
81c2858
Files:	    src/VisVim/Commands.cpp, src/VisVim/Resource.h,
81c2858
	    src/VisVim/VisVim.rc
81c2858
81c2858
81c2858
*** ../vim-7.2.149/src/VisVim/Commands.cpp	Thu May 10 20:45:34 2007
81c2858
--- src/VisVim/Commands.cpp	Mon Mar  2 00:52:15 2009
81c2858
***************
81c2858
*** 20,39 ****
81c2858
  
81c2858
  static BOOL g_bEnableVim = TRUE;	// Vim enabled
81c2858
  static BOOL g_bDevStudioEditor = FALSE;	// Open file in Dev Studio editor simultaneously
81c2858
  static int g_ChangeDir = CD_NONE;	// CD after file open?
81c2858
  
81c2858
! static void VimSetEnableState (BOOL bEnableState);
81c2858
! static BOOL VimOpenFile (BSTR& FileName, long LineNr);
81c2858
! static DISPID VimGetDispatchId (COleAutomationControl& VimOle, char* Method);
81c2858
! static void VimErrDiag (COleAutomationControl& VimOle);
81c2858
! static void VimChangeDir (COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName);
81c2858
! static void DebugMsg (char* Msg, char* Arg = NULL);
81c2858
  
81c2858
  
81c2858
  /////////////////////////////////////////////////////////////////////////////
81c2858
  // CCommands
81c2858
  
81c2858
! CCommands::CCommands ()
81c2858
  {
81c2858
  	// m_pApplication == NULL; M$ Code generation bug!!!
81c2858
  	m_pApplication = NULL;
81c2858
--- 20,40 ----
81c2858
  
81c2858
  static BOOL g_bEnableVim = TRUE;	// Vim enabled
81c2858
  static BOOL g_bDevStudioEditor = FALSE;	// Open file in Dev Studio editor simultaneously
81c2858
+ static BOOL g_bNewTabs = FALSE;
81c2858
  static int g_ChangeDir = CD_NONE;	// CD after file open?
81c2858
  
81c2858
! static void VimSetEnableState(BOOL bEnableState);
81c2858
! static BOOL VimOpenFile(BSTR& FileName, long LineNr);
81c2858
! static DISPID VimGetDispatchId(COleAutomationControl& VimOle, char* Method);
81c2858
! static void VimErrDiag(COleAutomationControl& VimOle);
81c2858
! static void VimChangeDir(COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName);
81c2858
! static void DebugMsg(char* Msg, char* Arg = NULL);
81c2858
  
81c2858
  
81c2858
  /////////////////////////////////////////////////////////////////////////////
81c2858
  // CCommands
81c2858
  
81c2858
! CCommands::CCommands()
81c2858
  {
81c2858
  	// m_pApplication == NULL; M$ Code generation bug!!!
81c2858
  	m_pApplication = NULL;
81c2858
***************
81c2858
*** 41,57 ****
81c2858
  	m_pDebuggerEventsObj = NULL;
81c2858
  }
81c2858
  
81c2858
! CCommands::~CCommands ()
81c2858
  {
81c2858
! 	ASSERT (m_pApplication != NULL);
81c2858
  	if (m_pApplication)
81c2858
  	{
81c2858
! 		m_pApplication->Release ();
81c2858
  		m_pApplication = NULL;
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
! void CCommands::SetApplicationObject (IApplication * pApplication)
81c2858
  {
81c2858
  	// This function assumes pApplication has already been AddRef'd
81c2858
  	// for us, which CDSAddIn did in it's QueryInterface call
81c2858
--- 42,58 ----
81c2858
  	m_pDebuggerEventsObj = NULL;
81c2858
  }
81c2858
  
81c2858
! CCommands::~CCommands()
81c2858
  {
81c2858
! 	ASSERT(m_pApplication != NULL);
81c2858
  	if (m_pApplication)
81c2858
  	{
81c2858
! 		m_pApplication->Release();
81c2858
  		m_pApplication = NULL;
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
! void CCommands::SetApplicationObject(IApplication * pApplication)
81c2858
  {
81c2858
  	// This function assumes pApplication has already been AddRef'd
81c2858
  	// for us, which CDSAddIn did in it's QueryInterface call
81c2858
***************
81c2858
*** 61,115 ****
81c2858
  		return;
81c2858
  
81c2858
  	// Create Application event handlers
81c2858
! 	XApplicationEventsObj::CreateInstance (&m_pApplicationEventsObj);
81c2858
  	if (! m_pApplicationEventsObj)
81c2858
  	{
81c2858
! 		ReportInternalError ("XApplicationEventsObj::CreateInstance");
81c2858
  		return;
81c2858
  	}
81c2858
! 	m_pApplicationEventsObj->AddRef ();
81c2858
! 	m_pApplicationEventsObj->Connect (m_pApplication);
81c2858
  	m_pApplicationEventsObj->m_pCommands = this;
81c2858
  
81c2858
  #ifdef NEVER
81c2858
  	// Create Debugger event handler
81c2858
  	CComPtr < IDispatch > pDebugger;
81c2858
! 	if (SUCCEEDED (m_pApplication->get_Debugger (&pDebugger))
81c2858
  	    && pDebugger != NULL)
81c2858
  	{
81c2858
! 		XDebuggerEventsObj::CreateInstance (&m_pDebuggerEventsObj);
81c2858
! 		m_pDebuggerEventsObj->AddRef ();
81c2858
! 		m_pDebuggerEventsObj->Connect (pDebugger);
81c2858
  		m_pDebuggerEventsObj->m_pCommands = this;
81c2858
  	}
81c2858
  #endif
81c2858
  
81c2858
  	// Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim
81c2858
! 	HKEY hAppKey = GetAppKey ("Vim");
81c2858
  	if (hAppKey)
81c2858
  	{
81c2858
! 		HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim");
81c2858
  		if (hSectionKey)
81c2858
  		{
81c2858
! 			g_bEnableVim = GetRegistryInt (hSectionKey, "EnableVim",
81c2858
  						       g_bEnableVim);
81c2858
! 			g_bDevStudioEditor = GetRegistryInt(hSectionKey,"DevStudioEditor",
81c2858
! 							    g_bDevStudioEditor);
81c2858
! 			g_ChangeDir = GetRegistryInt (hSectionKey, "ChangeDir",
81c2858
  						      g_ChangeDir);
81c2858
! 			RegCloseKey (hSectionKey);
81c2858
  		}
81c2858
! 		RegCloseKey (hAppKey);
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
! void CCommands::UnadviseFromEvents ()
81c2858
  {
81c2858
! 	ASSERT (m_pApplicationEventsObj != NULL);
81c2858
  	if (m_pApplicationEventsObj)
81c2858
  	{
81c2858
! 		m_pApplicationEventsObj->Disconnect (m_pApplication);
81c2858
! 		m_pApplicationEventsObj->Release ();
81c2858
  		m_pApplicationEventsObj = NULL;
81c2858
  	}
81c2858
  
81c2858
--- 62,118 ----
81c2858
  		return;
81c2858
  
81c2858
  	// Create Application event handlers
81c2858
! 	XApplicationEventsObj::CreateInstance(&m_pApplicationEventsObj);
81c2858
  	if (! m_pApplicationEventsObj)
81c2858
  	{
81c2858
! 		ReportInternalError("XApplicationEventsObj::CreateInstance");
81c2858
  		return;
81c2858
  	}
81c2858
! 	m_pApplicationEventsObj->AddRef();
81c2858
! 	m_pApplicationEventsObj->Connect(m_pApplication);
81c2858
  	m_pApplicationEventsObj->m_pCommands = this;
81c2858
  
81c2858
  #ifdef NEVER
81c2858
  	// Create Debugger event handler
81c2858
  	CComPtr < IDispatch > pDebugger;
81c2858
! 	if (SUCCEEDED(m_pApplication->get_Debugger(&pDebugger))
81c2858
  	    && pDebugger != NULL)
81c2858
  	{
81c2858
! 		XDebuggerEventsObj::CreateInstance(&m_pDebuggerEventsObj);
81c2858
! 		m_pDebuggerEventsObj->AddRef();
81c2858
! 		m_pDebuggerEventsObj->Connect(pDebugger);
81c2858
  		m_pDebuggerEventsObj->m_pCommands = this;
81c2858
  	}
81c2858
  #endif
81c2858
  
81c2858
  	// Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim
81c2858
! 	HKEY hAppKey = GetAppKey("Vim");
81c2858
  	if (hAppKey)
81c2858
  	{
81c2858
! 		HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
81c2858
  		if (hSectionKey)
81c2858
  		{
81c2858
! 			g_bEnableVim = GetRegistryInt(hSectionKey, "EnableVim",
81c2858
  						       g_bEnableVim);
81c2858
! 			g_bDevStudioEditor = GetRegistryInt(hSectionKey,
81c2858
! 					"DevStudioEditor", g_bDevStudioEditor);
81c2858
! 			g_bNewTabs = GetRegistryInt(hSectionKey, "NewTabs",
81c2858
! 						    g_bNewTabs);
81c2858
! 			g_ChangeDir = GetRegistryInt(hSectionKey, "ChangeDir",
81c2858
  						      g_ChangeDir);
81c2858
! 			RegCloseKey(hSectionKey);
81c2858
  		}
81c2858
! 		RegCloseKey(hAppKey);
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
! void CCommands::UnadviseFromEvents()
81c2858
  {
81c2858
! 	ASSERT(m_pApplicationEventsObj != NULL);
81c2858
  	if (m_pApplicationEventsObj)
81c2858
  	{
81c2858
! 		m_pApplicationEventsObj->Disconnect(m_pApplication);
81c2858
! 		m_pApplicationEventsObj->Release();
81c2858
  		m_pApplicationEventsObj = NULL;
81c2858
  	}
81c2858
  
81c2858
***************
81c2858
*** 121,130 ****
81c2858
  		// unadvise from its events (thus the VERIFY_OK below--see
81c2858
  		// stdafx.h).
81c2858
  		CComPtr < IDispatch > pDebugger;
81c2858
! 		VERIFY_OK (m_pApplication->get_Debugger (&pDebugger));
81c2858
! 		ASSERT (pDebugger != NULL);
81c2858
! 		m_pDebuggerEventsObj->Disconnect (pDebugger);
81c2858
! 		m_pDebuggerEventsObj->Release ();
81c2858
  		m_pDebuggerEventsObj = NULL;
81c2858
  	}
81c2858
  #endif
81c2858
--- 124,133 ----
81c2858
  		// unadvise from its events (thus the VERIFY_OK below--see
81c2858
  		// stdafx.h).
81c2858
  		CComPtr < IDispatch > pDebugger;
81c2858
! 		VERIFY_OK(m_pApplication->get_Debugger(&pDebugger));
81c2858
! 		ASSERT(pDebugger != NULL);
81c2858
! 		m_pDebuggerEventsObj->Disconnect(pDebugger);
81c2858
! 		m_pDebuggerEventsObj->Release();
81c2858
  		m_pDebuggerEventsObj = NULL;
81c2858
  	}
81c2858
  #endif
81c2858
***************
81c2858
*** 136,156 ****
81c2858
  
81c2858
  // Application events
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeBuildStart ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BuildFinish (long nNumErrors, long nNumWarnings)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
--- 139,159 ----
81c2858
  
81c2858
  // Application events
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeBuildStart()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BuildFinish(long nNumErrors, long nNumWarnings)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
***************
81c2858
*** 158,166 ****
81c2858
  // is done.
81c2858
  // Vim gets called from here.
81c2858
  //
81c2858
! HRESULT CCommands::XApplicationEvents::DocumentOpen (IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  
81c2858
  	if (! g_bEnableVim)
81c2858
  		// Vim not enabled or empty command line entered
81c2858
--- 161,169 ----
81c2858
  // is done.
81c2858
  // Vim gets called from here.
81c2858
  //
81c2858
! HRESULT CCommands::XApplicationEvents::DocumentOpen(IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  
81c2858
  	if (! g_bEnableVim)
81c2858
  		// Vim not enabled or empty command line entered
81c2858
***************
81c2858
*** 169,175 ****
81c2858
  	// First get the current file name and line number
81c2858
  
81c2858
  	// Get the document object
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc (theDocument);
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
--- 172,178 ----
81c2858
  	// First get the current file name and line number
81c2858
  
81c2858
  	// Get the document object
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(theDocument);
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
***************
81c2858
*** 177,202 ****
81c2858
  	long LineNr = -1;
81c2858
  
81c2858
  	// Get the document name
81c2858
! 	if (FAILED (pDoc->get_FullName (&FileName)))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	LPDISPATCH pDispSel;
81c2858
  
81c2858
  	// Get a selection object dispatch pointer
81c2858
! 	if (SUCCEEDED (pDoc->get_Selection (&pDispSel)))
81c2858
  	{
81c2858
  		// Get the selection object
81c2858
! 		CComQIPtr < ITextSelection, &IID_ITextSelection > pSel (pDispSel);
81c2858
  
81c2858
  		if (pSel)
81c2858
  			// Get the selection line number
81c2858
! 			pSel->get_CurrentLine (&LineNr);
81c2858
  
81c2858
! 		pDispSel->Release ();
81c2858
  	}
81c2858
  
81c2858
  	// Open the file in Vim and position to the current line
81c2858
! 	if (VimOpenFile (FileName, LineNr))
81c2858
  	{
81c2858
  		if (! g_bDevStudioEditor)
81c2858
  		{
81c2858
--- 180,205 ----
81c2858
  	long LineNr = -1;
81c2858
  
81c2858
  	// Get the document name
81c2858
! 	if (FAILED(pDoc->get_FullName(&FileName)))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	LPDISPATCH pDispSel;
81c2858
  
81c2858
  	// Get a selection object dispatch pointer
81c2858
! 	if (SUCCEEDED(pDoc->get_Selection(&pDispSel)))
81c2858
  	{
81c2858
  		// Get the selection object
81c2858
! 		CComQIPtr < ITextSelection, &IID_ITextSelection > pSel(pDispSel);
81c2858
  
81c2858
  		if (pSel)
81c2858
  			// Get the selection line number
81c2858
! 			pSel->get_CurrentLine(&LineNr);
81c2858
  
81c2858
! 		pDispSel->Release();
81c2858
  	}
81c2858
  
81c2858
  	// Open the file in Vim and position to the current line
81c2858
! 	if (VimOpenFile(FileName, LineNr))
81c2858
  	{
81c2858
  		if (! g_bDevStudioEditor)
81c2858
  		{
81c2858
***************
81c2858
*** 204,233 ****
81c2858
  			CComVariant vSaveChanges = dsSaveChangesPrompt;
81c2858
  			DsSaveStatus Saved;
81c2858
  
81c2858
! 			pDoc->Close (vSaveChanges, &Saved);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
  	// We're done here
81c2858
! 	SysFreeString (FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeDocumentClose (IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::DocumentSave (IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::NewDocument (IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  
81c2858
  	if (! g_bEnableVim)
81c2858
  		// Vim not enabled or empty command line entered
81c2858
--- 207,236 ----
81c2858
  			CComVariant vSaveChanges = dsSaveChangesPrompt;
81c2858
  			DsSaveStatus Saved;
81c2858
  
81c2858
! 			pDoc->Close(vSaveChanges, &Saved);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
  	// We're done here
81c2858
! 	SysFreeString(FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::BeforeDocumentClose(IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::NewDocument(IDispatch * theDocument)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  
81c2858
  	if (! g_bEnableVim)
81c2858
  		// Vim not enabled or empty command line entered
81c2858
***************
81c2858
*** 235,253 ****
81c2858
  
81c2858
  	// First get the current file name and line number
81c2858
  
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc (theDocument);
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
  	BSTR FileName;
81c2858
  	HRESULT hr;
81c2858
  
81c2858
! 	hr = pDoc->get_FullName (&FileName);
81c2858
! 	if (FAILED (hr))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Open the file in Vim and position to the current line
81c2858
! 	if (VimOpenFile (FileName, 0))
81c2858
  	{
81c2858
  		if (! g_bDevStudioEditor)
81c2858
  		{
81c2858
--- 238,256 ----
81c2858
  
81c2858
  	// First get the current file name and line number
81c2858
  
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(theDocument);
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
  	BSTR FileName;
81c2858
  	HRESULT hr;
81c2858
  
81c2858
! 	hr = pDoc->get_FullName(&FileName);
81c2858
! 	if (FAILED(hr))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Open the file in Vim and position to the current line
81c2858
! 	if (VimOpenFile(FileName, 0))
81c2858
  	{
81c2858
  		if (! g_bDevStudioEditor)
81c2858
  		{
81c2858
***************
81c2858
*** 255,303 ****
81c2858
  			CComVariant vSaveChanges = dsSaveChangesPrompt;
81c2858
  			DsSaveStatus Saved;
81c2858
  
81c2858
! 			pDoc->Close (vSaveChanges, &Saved);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
! 	SysFreeString (FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WindowActivate (IDispatch * theWindow)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WindowDeactivate (IDispatch * theWindow)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WorkspaceOpen ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WorkspaceClose ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::NewWorkspace ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
  // Debugger event
81c2858
  
81c2858
! HRESULT CCommands::XDebuggerEvents::BreakpointHit (IDispatch * pBreakpoint)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
--- 258,306 ----
81c2858
  			CComVariant vSaveChanges = dsSaveChangesPrompt;
81c2858
  			DsSaveStatus Saved;
81c2858
  
81c2858
! 			pDoc->Close(vSaveChanges, &Saved);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
! 	SysFreeString(FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WindowActivate(IDispatch * theWindow)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WindowDeactivate(IDispatch * theWindow)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WorkspaceOpen()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::WorkspaceClose()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! HRESULT CCommands::XApplicationEvents::NewWorkspace()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
  // Debugger event
81c2858
  
81c2858
! HRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch * pBreakpoint)
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
***************
81c2858
*** 308,324 ****
81c2858
  class CMainDialog : public CDialog
81c2858
  {
81c2858
      public:
81c2858
! 	CMainDialog (CWnd * pParent = NULL);	// Standard constructor
81c2858
  
81c2858
  	//{{AFX_DATA(CMainDialog)
81c2858
  	enum { IDD = IDD_ADDINMAIN };
81c2858
  	int	m_ChangeDir;
81c2858
  	BOOL	m_bDevStudioEditor;
81c2858
  	//}}AFX_DATA
81c2858
  
81c2858
  	//{{AFX_VIRTUAL(CMainDialog)
81c2858
      protected:
81c2858
! 	virtual void DoDataExchange (CDataExchange * pDX);	// DDX/DDV support
81c2858
  	//}}AFX_VIRTUAL
81c2858
  
81c2858
      protected:
81c2858
--- 311,328 ----
81c2858
  class CMainDialog : public CDialog
81c2858
  {
81c2858
      public:
81c2858
! 	CMainDialog(CWnd * pParent = NULL);	// Standard constructor
81c2858
  
81c2858
  	//{{AFX_DATA(CMainDialog)
81c2858
  	enum { IDD = IDD_ADDINMAIN };
81c2858
  	int	m_ChangeDir;
81c2858
  	BOOL	m_bDevStudioEditor;
81c2858
+ 	BOOL	m_bNewTabs;
81c2858
  	//}}AFX_DATA
81c2858
  
81c2858
  	//{{AFX_VIRTUAL(CMainDialog)
81c2858
      protected:
81c2858
! 	virtual void DoDataExchange(CDataExchange * pDX);	// DDX/DDV support
81c2858
  	//}}AFX_VIRTUAL
81c2858
  
81c2858
      protected:
81c2858
***************
81c2858
*** 326,425 ****
81c2858
  	afx_msg void OnEnable();
81c2858
  	afx_msg void OnDisable();
81c2858
  	//}}AFX_MSG
81c2858
! 	DECLARE_MESSAGE_MAP ()
81c2858
  };
81c2858
  
81c2858
! CMainDialog::CMainDialog (CWnd * pParent /* =NULL */ )
81c2858
! 	: CDialog (CMainDialog::IDD, pParent)
81c2858
  {
81c2858
  	//{{AFX_DATA_INIT(CMainDialog)
81c2858
  	m_ChangeDir = -1;
81c2858
  	m_bDevStudioEditor = FALSE;
81c2858
  	//}}AFX_DATA_INIT
81c2858
  }
81c2858
  
81c2858
! void CMainDialog::DoDataExchange (CDataExchange * pDX)
81c2858
  {
81c2858
! 	CDialog::DoDataExchange (pDX);
81c2858
  	//{{AFX_DATA_MAP(CMainDialog)
81c2858
  	DDX_Radio(pDX, IDC_CD_SOURCE_PATH, m_ChangeDir);
81c2858
! 	DDX_Check (pDX, IDC_DEVSTUDIO_EDITOR, m_bDevStudioEditor);
81c2858
  	//}}AFX_DATA_MAP
81c2858
  }
81c2858
  
81c2858
! BEGIN_MESSAGE_MAP (CMainDialog, CDialog)
81c2858
  	//{{AFX_MSG_MAP(CMainDialog)
81c2858
  	//}}AFX_MSG_MAP
81c2858
! END_MESSAGE_MAP ()
81c2858
  
81c2858
  
81c2858
  /////////////////////////////////////////////////////////////////////////////
81c2858
  // CCommands methods
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimDialog ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  
81c2858
  	// Use m_pApplication to access the Developer Studio Application
81c2858
  	// object,
81c2858
  	// and VERIFY_OK to see error strings in DEBUG builds of your add-in
81c2858
  	// (see stdafx.h)
81c2858
  
81c2858
! 	VERIFY_OK (m_pApplication->EnableModeless (VARIANT_FALSE));
81c2858
  
81c2858
  	CMainDialog Dlg;
81c2858
  
81c2858
  	Dlg.m_bDevStudioEditor = g_bDevStudioEditor;
81c2858
  	Dlg.m_ChangeDir = g_ChangeDir;
81c2858
! 	if (Dlg.DoModal () == IDOK)
81c2858
  	{
81c2858
  		g_bDevStudioEditor = Dlg.m_bDevStudioEditor;
81c2858
  		g_ChangeDir = Dlg.m_ChangeDir;
81c2858
  
81c2858
  		// Save settings to registry HKEY_CURRENT_USER\Software\Vim\VisVim
81c2858
! 		HKEY hAppKey = GetAppKey ("Vim");
81c2858
  		if (hAppKey)
81c2858
  		{
81c2858
! 			HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim");
81c2858
  			if (hSectionKey)
81c2858
  			{
81c2858
! 				WriteRegistryInt (hSectionKey, "DevStudioEditor",
81c2858
  						  g_bDevStudioEditor);
81c2858
! 				WriteRegistryInt (hSectionKey, "ChangeDir", g_ChangeDir);
81c2858
! 				RegCloseKey (hSectionKey);
81c2858
  			}
81c2858
! 			RegCloseKey (hAppKey);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
! 	VERIFY_OK (m_pApplication->EnableModeless (VARIANT_TRUE));
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimEnable ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
! 	VimSetEnableState (true);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimDisable ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
! 	VimSetEnableState (false);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimToggle ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
! 	VimSetEnableState (! g_bEnableVim);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimLoad ()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE (AfxGetStaticModuleState ());
81c2858
  
81c2858
  	// Use m_pApplication to access the Developer Studio Application object,
81c2858
  	// and VERIFY_OK to see error strings in DEBUG builds of your add-in
81c2858
--- 330,435 ----
81c2858
  	afx_msg void OnEnable();
81c2858
  	afx_msg void OnDisable();
81c2858
  	//}}AFX_MSG
81c2858
! 	DECLARE_MESSAGE_MAP()
81c2858
  };
81c2858
  
81c2858
! CMainDialog::CMainDialog(CWnd * pParent /* =NULL */ )
81c2858
! 	: CDialog(CMainDialog::IDD, pParent)
81c2858
  {
81c2858
  	//{{AFX_DATA_INIT(CMainDialog)
81c2858
  	m_ChangeDir = -1;
81c2858
  	m_bDevStudioEditor = FALSE;
81c2858
+ 	m_bNewTabs = FALSE;
81c2858
  	//}}AFX_DATA_INIT
81c2858
  }
81c2858
  
81c2858
! void CMainDialog::DoDataExchange(CDataExchange * pDX)
81c2858
  {
81c2858
! 	CDialog::DoDataExchange(pDX);
81c2858
  	//{{AFX_DATA_MAP(CMainDialog)
81c2858
  	DDX_Radio(pDX, IDC_CD_SOURCE_PATH, m_ChangeDir);
81c2858
! 	DDX_Check(pDX, IDC_DEVSTUDIO_EDITOR, m_bDevStudioEditor);
81c2858
! 	DDX_Check(pDX, IDC_NEW_TABS, m_bNewTabs);
81c2858
  	//}}AFX_DATA_MAP
81c2858
  }
81c2858
  
81c2858
! BEGIN_MESSAGE_MAP(CMainDialog, CDialog)
81c2858
  	//{{AFX_MSG_MAP(CMainDialog)
81c2858
  	//}}AFX_MSG_MAP
81c2858
! END_MESSAGE_MAP()
81c2858
  
81c2858
  
81c2858
  /////////////////////////////////////////////////////////////////////////////
81c2858
  // CCommands methods
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimDialog()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  
81c2858
  	// Use m_pApplication to access the Developer Studio Application
81c2858
  	// object,
81c2858
  	// and VERIFY_OK to see error strings in DEBUG builds of your add-in
81c2858
  	// (see stdafx.h)
81c2858
  
81c2858
! 	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));
81c2858
  
81c2858
  	CMainDialog Dlg;
81c2858
  
81c2858
  	Dlg.m_bDevStudioEditor = g_bDevStudioEditor;
81c2858
+ 	Dlg.m_bNewTabs = g_bNewTabs;
81c2858
  	Dlg.m_ChangeDir = g_ChangeDir;
81c2858
! 	if (Dlg.DoModal() == IDOK)
81c2858
  	{
81c2858
  		g_bDevStudioEditor = Dlg.m_bDevStudioEditor;
81c2858
+ 		g_bNewTabs = Dlg.m_bNewTabs;
81c2858
  		g_ChangeDir = Dlg.m_ChangeDir;
81c2858
  
81c2858
  		// Save settings to registry HKEY_CURRENT_USER\Software\Vim\VisVim
81c2858
! 		HKEY hAppKey = GetAppKey("Vim");
81c2858
  		if (hAppKey)
81c2858
  		{
81c2858
! 			HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
81c2858
  			if (hSectionKey)
81c2858
  			{
81c2858
! 				WriteRegistryInt(hSectionKey, "DevStudioEditor",
81c2858
  						  g_bDevStudioEditor);
81c2858
! 				WriteRegistryInt(hSectionKey, "NewTabs",
81c2858
! 						  g_bNewTabs);
81c2858
! 				WriteRegistryInt(hSectionKey, "ChangeDir", g_ChangeDir);
81c2858
! 				RegCloseKey(hSectionKey);
81c2858
  			}
81c2858
! 			RegCloseKey(hAppKey);
81c2858
  		}
81c2858
  	}
81c2858
  
81c2858
! 	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimEnable()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
! 	VimSetEnableState(true);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimDisable()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
! 	VimSetEnableState(false);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimToggle()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
! 	VimSetEnableState(! g_bEnableVim);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
! STDMETHODIMP CCommands::VisVimLoad()
81c2858
  {
81c2858
! 	AFX_MANAGE_STATE(AfxGetStaticModuleState());
81c2858
  
81c2858
  	// Use m_pApplication to access the Developer Studio Application object,
81c2858
  	// and VERIFY_OK to see error strings in DEBUG builds of your add-in
81c2858
***************
81c2858
*** 430,436 ****
81c2858
  	CComPtr < IDispatch > pDispDoc, pDispSel;
81c2858
  
81c2858
  	// Get a document object dispatch pointer
81c2858
! 	VERIFY_OK (m_pApplication->get_ActiveDocument (&pDispDoc));
81c2858
  	if (! pDispDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
--- 440,446 ----
81c2858
  	CComPtr < IDispatch > pDispDoc, pDispSel;
81c2858
  
81c2858
  	// Get a document object dispatch pointer
81c2858
! 	VERIFY_OK(m_pApplication->get_ActiveDocument(&pDispDoc));
81c2858
  	if (! pDispDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
***************
81c2858
*** 438,467 ****
81c2858
  	long LineNr = -1;
81c2858
  
81c2858
  	// Get the document object
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc (pDispDoc);
81c2858
  
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Get the document name
81c2858
! 	if (FAILED (pDoc->get_FullName (&FileName)))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Get a selection object dispatch pointer
81c2858
! 	if (SUCCEEDED (pDoc->get_Selection (&pDispSel)))
81c2858
  	{
81c2858
  		// Get the selection object
81c2858
! 		CComQIPtr < ITextSelection, &IID_ITextSelection > pSel (pDispSel);
81c2858
  
81c2858
  		if (pSel)
81c2858
  			// Get the selection line number
81c2858
! 			pSel->get_CurrentLine (&LineNr);
81c2858
  	}
81c2858
  
81c2858
  	// Open the file in Vim
81c2858
! 	VimOpenFile (FileName, LineNr);
81c2858
  
81c2858
! 	SysFreeString (FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
--- 448,477 ----
81c2858
  	long LineNr = -1;
81c2858
  
81c2858
  	// Get the document object
81c2858
! 	CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(pDispDoc);
81c2858
  
81c2858
  	if (! pDoc)
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Get the document name
81c2858
! 	if (FAILED(pDoc->get_FullName(&FileName)))
81c2858
  		return S_OK;
81c2858
  
81c2858
  	// Get a selection object dispatch pointer
81c2858
! 	if (SUCCEEDED(pDoc->get_Selection(&pDispSel)))
81c2858
  	{
81c2858
  		// Get the selection object
81c2858
! 		CComQIPtr < ITextSelection, &IID_ITextSelection > pSel(pDispSel);
81c2858
  
81c2858
  		if (pSel)
81c2858
  			// Get the selection line number
81c2858
! 			pSel->get_CurrentLine(&LineNr);
81c2858
  	}
81c2858
  
81c2858
  	// Open the file in Vim
81c2858
! 	VimOpenFile(FileName, LineNr);
81c2858
  
81c2858
! 	SysFreeString(FileName);
81c2858
  	return S_OK;
81c2858
  }
81c2858
  
81c2858
***************
81c2858
*** 472,487 ****
81c2858
  
81c2858
  // Set the enable state and save to registry
81c2858
  //
81c2858
! static void VimSetEnableState (BOOL bEnableState)
81c2858
  {
81c2858
  	g_bEnableVim = bEnableState;
81c2858
! 	HKEY hAppKey = GetAppKey ("Vim");
81c2858
  	if (hAppKey)
81c2858
  	{
81c2858
! 		HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim");
81c2858
  		if (hSectionKey)
81c2858
! 			WriteRegistryInt (hSectionKey, "EnableVim", g_bEnableVim);
81c2858
! 		RegCloseKey (hAppKey);
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
--- 482,497 ----
81c2858
  
81c2858
  // Set the enable state and save to registry
81c2858
  //
81c2858
! static void VimSetEnableState(BOOL bEnableState)
81c2858
  {
81c2858
  	g_bEnableVim = bEnableState;
81c2858
! 	HKEY hAppKey = GetAppKey("Vim");
81c2858
  	if (hAppKey)
81c2858
  	{
81c2858
! 		HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
81c2858
  		if (hSectionKey)
81c2858
! 			WriteRegistryInt(hSectionKey, "EnableVim", g_bEnableVim);
81c2858
! 		RegCloseKey(hAppKey);
81c2858
  	}
81c2858
  }
81c2858
  
81c2858
***************
81c2858
*** 490,496 ****
81c2858
  // letter.
81c2858
  // 'LineNr' must contain a valid line number or 0, e. g. for a new file
81c2858
  //
81c2858
! static BOOL VimOpenFile (BSTR& FileName, long LineNr)
81c2858
  {
81c2858
  
81c2858
  	// OLE automation object for com. with Vim
81c2858
--- 500,506 ----
81c2858
  // letter.
81c2858
  // 'LineNr' must contain a valid line number or 0, e. g. for a new file
81c2858
  //
81c2858
! static BOOL VimOpenFile(BSTR& FileName, long LineNr)
81c2858
  {
81c2858
  
81c2858
  	// OLE automation object for com. with Vim
81c2858
***************
81c2858
*** 507,513 ****
81c2858
  	// Get a dispatch id for the SendKeys method of Vim;
81c2858
  	// enables connection to Vim if necessary
81c2858
  	DISPID DispatchId;
81c2858
! 	DispatchId = VimGetDispatchId (VimOle, "SendKeys");
81c2858
  	if (! DispatchId)
81c2858
  		// OLE error, can't obtain dispatch id
81c2858
  		goto OleError;
81c2858
--- 517,523 ----
81c2858
  	// Get a dispatch id for the SendKeys method of Vim;
81c2858
  	// enables connection to Vim if necessary
81c2858
  	DISPID DispatchId;
81c2858
! 	DispatchId = VimGetDispatchId(VimOle, "SendKeys");
81c2858
  	if (! DispatchId)
81c2858
  		// OLE error, can't obtain dispatch id
81c2858
  		goto OleError;
81c2858
***************
81c2858
*** 525,544 ****
81c2858
  #ifdef SINGLE_WINDOW
81c2858
  	// Update the current file in Vim if it has been modified.
81c2858
  	// Disabled, because it could write the file when you don't want to.
81c2858
! 	sprintf (VimCmd + 2, ":up\n");
81c2858
  #endif
81c2858
! 	if (! VimOle.Method (DispatchId, "s", TO_OLE_STR_BUF (VimCmd, Buf)))
81c2858
  		goto OleError;
81c2858
  
81c2858
  	// Change Vim working directory to where the file is if desired
81c2858
  	if (g_ChangeDir != CD_NONE)
81c2858
! 		VimChangeDir (VimOle, DispatchId, FileName);
81c2858
  
81c2858
  	// Make Vim open the file.
81c2858
  	// In the filename convert all \ to /, put a \ before a space.
81c2858
! 	sprintf(VimCmd, ":drop ");
81c2858
  	sprintf(FileNameTmp, "%S", (char *)FileName);
81c2858
- 	s = VimCmd + 6;
81c2858
  	for (p = FileNameTmp; *p != '\0' && s < FileNameTmp + MAX_OLE_STR - 4;
81c2858
  									  ++p)
81c2858
  		if (*p == '\\')
81c2858
--- 535,562 ----
81c2858
  #ifdef SINGLE_WINDOW
81c2858
  	// Update the current file in Vim if it has been modified.
81c2858
  	// Disabled, because it could write the file when you don't want to.
81c2858
! 	sprintf(VimCmd + 2, ":up\n");
81c2858
  #endif
81c2858
! 	if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
81c2858
  		goto OleError;
81c2858
  
81c2858
  	// Change Vim working directory to where the file is if desired
81c2858
  	if (g_ChangeDir != CD_NONE)
81c2858
! 		VimChangeDir(VimOle, DispatchId, FileName);
81c2858
  
81c2858
  	// Make Vim open the file.
81c2858
  	// In the filename convert all \ to /, put a \ before a space.
81c2858
! 	if (g_bNewTabs)
81c2858
! 	{
81c2858
! 		sprintf(VimCmd, ":tab drop ");
81c2858
! 		s = VimCmd + 11;
81c2858
! 	}
81c2858
! 	else
81c2858
! 	{
81c2858
! 		sprintf(VimCmd, ":drop ");
81c2858
! 		s = VimCmd + 6;
81c2858
! 	}
81c2858
  	sprintf(FileNameTmp, "%S", (char *)FileName);
81c2858
  	for (p = FileNameTmp; *p != '\0' && s < FileNameTmp + MAX_OLE_STR - 4;
81c2858
  									  ++p)
81c2858
  		if (*p == '\\')
81c2858
***************
81c2858
*** 552,571 ****
81c2858
  	*s++ = '\n';
81c2858
  	*s = '\0';
81c2858
  
81c2858
! 	if (! VimOle.Method (DispatchId, "s", TO_OLE_STR_BUF (VimCmd, Buf)))
81c2858
  		goto OleError;
81c2858
  
81c2858
  	if (LineNr > 0)
81c2858
  	{
81c2858
  		// Goto line
81c2858
! 		sprintf (VimCmd, ":%d\n", LineNr);
81c2858
! 		if (! VimOle.Method (DispatchId, "s", TO_OLE_STR_BUF (VimCmd, Buf)))
81c2858
  			goto OleError;
81c2858
  	}
81c2858
  
81c2858
  	// Make Vim come to the foreground
81c2858
! 	if (! VimOle.Method ("SetForeground"))
81c2858
! 		VimOle.ErrDiag ();
81c2858
  
81c2858
  	// We're done
81c2858
  	return true;
81c2858
--- 570,589 ----
81c2858
  	*s++ = '\n';
81c2858
  	*s = '\0';
81c2858
  
81c2858
! 	if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
81c2858
  		goto OleError;
81c2858
  
81c2858
  	if (LineNr > 0)
81c2858
  	{
81c2858
  		// Goto line
81c2858
! 		sprintf(VimCmd, ":%d\n", LineNr);
81c2858
! 		if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
81c2858
  			goto OleError;
81c2858
  	}
81c2858
  
81c2858
  	// Make Vim come to the foreground
81c2858
! 	if (! VimOle.Method("SetForeground"))
81c2858
! 		VimOle.ErrDiag();
81c2858
  
81c2858
  	// We're done
81c2858
  	return true;
81c2858
***************
81c2858
*** 573,579 ****
81c2858
      OleError:
81c2858
  	// There was an OLE error
81c2858
  	// Check if it's the "unknown class string" error
81c2858
! 	VimErrDiag (VimOle);
81c2858
  	return false;
81c2858
  }
81c2858
  
81c2858
--- 591,597 ----
81c2858
      OleError:
81c2858
  	// There was an OLE error
81c2858
  	// Check if it's the "unknown class string" error
81c2858
! 	VimErrDiag(VimOle);
81c2858
  	return false;
81c2858
  }
81c2858
  
81c2858
***************
81c2858
*** 581,598 ****
81c2858
  // Create the Vim OLE object if necessary
81c2858
  // Returns a valid dispatch id or null on error
81c2858
  //
81c2858
! static DISPID VimGetDispatchId (COleAutomationControl& VimOle, char* Method)
81c2858
  {
81c2858
  	// Initialize Vim OLE connection if not already done
81c2858
! 	if (! VimOle.IsCreated ())
81c2858
  	{
81c2858
! 		if (! VimOle.CreateObject ("Vim.Application"))
81c2858
  			return NULL;
81c2858
  	}
81c2858
  
81c2858
  	// Get the dispatch id for the SendKeys method.
81c2858
  	// By doing this, we are checking if Vim is still there...
81c2858
! 	DISPID DispatchId = VimOle.GetDispatchId ("SendKeys");
81c2858
  	if (! DispatchId)
81c2858
  	{
81c2858
  		// We can't get a dispatch id.
81c2858
--- 599,616 ----
81c2858
  // Create the Vim OLE object if necessary
81c2858
  // Returns a valid dispatch id or null on error
81c2858
  //
81c2858
! static DISPID VimGetDispatchId(COleAutomationControl& VimOle, char* Method)
81c2858
  {
81c2858
  	// Initialize Vim OLE connection if not already done
81c2858
! 	if (! VimOle.IsCreated())
81c2858
  	{
81c2858
! 		if (! VimOle.CreateObject("Vim.Application"))
81c2858
  			return NULL;
81c2858
  	}
81c2858
  
81c2858
  	// Get the dispatch id for the SendKeys method.
81c2858
  	// By doing this, we are checking if Vim is still there...
81c2858
! 	DISPID DispatchId = VimOle.GetDispatchId("SendKeys");
81c2858
  	if (! DispatchId)
81c2858
  	{
81c2858
  		// We can't get a dispatch id.
81c2858
***************
81c2858
*** 604,615 ****
81c2858
  		// should not be kept long enough to allow the user to terminate Vim
81c2858
  		// to avoid memory corruption (why the heck is there no system garbage
81c2858
  		// collection for those damned OLE memory chunks???).
81c2858
! 		VimOle.DeleteObject ();
81c2858
! 		if (! VimOle.CreateObject ("Vim.Application"))
81c2858
  			// If this create fails, it's time for an error msg
81c2858
  			return NULL;
81c2858
  
81c2858
! 		if (! (DispatchId = VimOle.GetDispatchId ("SendKeys")))
81c2858
  			// There is something wrong...
81c2858
  			return NULL;
81c2858
  	}
81c2858
--- 622,633 ----
81c2858
  		// should not be kept long enough to allow the user to terminate Vim
81c2858
  		// to avoid memory corruption (why the heck is there no system garbage
81c2858
  		// collection for those damned OLE memory chunks???).
81c2858
! 		VimOle.DeleteObject();
81c2858
! 		if (! VimOle.CreateObject("Vim.Application"))
81c2858
  			// If this create fails, it's time for an error msg
81c2858
  			return NULL;
81c2858
  
81c2858
! 		if (! (DispatchId = VimOle.GetDispatchId("SendKeys")))
81c2858
  			// There is something wrong...
81c2858
  			return NULL;
81c2858
  	}
81c2858
***************
81c2858
*** 620,639 ****
81c2858
  // Output an error message for an OLE error
81c2858
  // Check on the classstring error, which probably means Vim wasn't registered.
81c2858
  //
81c2858
! static void VimErrDiag (COleAutomationControl& VimOle)
81c2858
  {
81c2858
! 	SCODE sc = GetScode (VimOle.GetResult ());
81c2858
  	if (sc == CO_E_CLASSSTRING)
81c2858
  	{
81c2858
  		char Buf[256];
81c2858
! 		sprintf (Buf, "There is no registered OLE automation server named "
81c2858
  			 "\"Vim.Application\".\n"
81c2858
  			 "Use the OLE-enabled version of Vim with VisVim and "
81c2858
  			 "make sure to register Vim by running \"vim -register\".");
81c2858
! 		MessageBox (NULL, Buf, "OLE Error", MB_OK);
81c2858
  	}
81c2858
  	else
81c2858
! 		VimOle.ErrDiag ();
81c2858
  }
81c2858
  
81c2858
  // Change directory to the directory the file 'FileName' is in or it's parent
81c2858
--- 638,657 ----
81c2858
  // Output an error message for an OLE error
81c2858
  // Check on the classstring error, which probably means Vim wasn't registered.
81c2858
  //
81c2858
! static void VimErrDiag(COleAutomationControl& VimOle)
81c2858
  {
81c2858
! 	SCODE sc = GetScode(VimOle.GetResult());
81c2858
  	if (sc == CO_E_CLASSSTRING)
81c2858
  	{
81c2858
  		char Buf[256];
81c2858
! 		sprintf(Buf, "There is no registered OLE automation server named "
81c2858
  			 "\"Vim.Application\".\n"
81c2858
  			 "Use the OLE-enabled version of Vim with VisVim and "
81c2858
  			 "make sure to register Vim by running \"vim -register\".");
81c2858
! 		MessageBox(NULL, Buf, "OLE Error", MB_OK);
81c2858
  	}
81c2858
  	else
81c2858
! 		VimOle.ErrDiag();
81c2858
  }
81c2858
  
81c2858
  // Change directory to the directory the file 'FileName' is in or it's parent
81c2858
***************
81c2858
*** 644,650 ****
81c2858
  //	CD_SOURCE_PATH
81c2858
  //	CD_SOURCE_PARENT
81c2858
  //
81c2858
! static void VimChangeDir (COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName)
81c2858
  {
81c2858
  	// Do a :cd first
81c2858
  
81c2858
--- 662,668 ----
81c2858
  //	CD_SOURCE_PATH
81c2858
  //	CD_SOURCE_PARENT
81c2858
  //
81c2858
! static void VimChangeDir(COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName)
81c2858
  {
81c2858
  	// Do a :cd first
81c2858
  
81c2858
***************
81c2858
*** 655,661 ****
81c2858
  	char DirUnix[_MAX_DIR * 2];
81c2858
  	char *s, *t;
81c2858
  
81c2858
! 	_splitpath (StrFileName, Drive, Dir, NULL, NULL);
81c2858
  
81c2858
  	// Convert to Unix path name format, escape spaces.
81c2858
  	t = DirUnix;
81c2858
--- 673,679 ----
81c2858
  	char DirUnix[_MAX_DIR * 2];
81c2858
  	char *s, *t;
81c2858
  
81c2858
! 	_splitpath(StrFileName, Drive, Dir, NULL, NULL);
81c2858
  
81c2858
  	// Convert to Unix path name format, escape spaces.
81c2858
  	t = DirUnix;
81c2858
***************
81c2858
*** 676,694 ****
81c2858
  	OLECHAR Buf[MAX_OLE_STR];
81c2858
  	char VimCmd[MAX_OLE_STR];
81c2858
  
81c2858
! 	sprintf (VimCmd, ":cd %s%s%s\n", Drive, DirUnix,
81c2858
  		 g_ChangeDir == CD_SOURCE_PARENT && DirUnix[1] ? ".." : "");
81c2858
! 	VimOle.Method (DispatchId, "s", TO_OLE_STR_BUF (VimCmd, Buf));
81c2858
  }
81c2858
  
81c2858
  #ifdef _DEBUG
81c2858
  // Print out a debug message
81c2858
  //
81c2858
! static void DebugMsg (char* Msg, char* Arg)
81c2858
  {
81c2858
  	char Buf[400];
81c2858
! 	sprintf (Buf, Msg, Arg);
81c2858
! 	AfxMessageBox (Buf);
81c2858
  }
81c2858
  #endif
81c2858
- 
81c2858
--- 694,711 ----
81c2858
  	OLECHAR Buf[MAX_OLE_STR];
81c2858
  	char VimCmd[MAX_OLE_STR];
81c2858
  
81c2858
! 	sprintf(VimCmd, ":cd %s%s%s\n", Drive, DirUnix,
81c2858
  		 g_ChangeDir == CD_SOURCE_PARENT && DirUnix[1] ? ".." : "");
81c2858
! 	VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf));
81c2858
  }
81c2858
  
81c2858
  #ifdef _DEBUG
81c2858
  // Print out a debug message
81c2858
  //
81c2858
! static void DebugMsg(char* Msg, char* Arg)
81c2858
  {
81c2858
  	char Buf[400];
81c2858
! 	sprintf(Buf, Msg, Arg);
81c2858
! 	AfxMessageBox(Buf);
81c2858
  }
81c2858
  #endif
81c2858
*** ../vim-7.2.149/src/VisVim/Resource.h	Sun Jun 13 19:17:32 2004
81c2858
--- src/VisVim/Resource.h	Mon Mar  2 00:39:21 2009
81c2858
***************
81c2858
*** 16,21 ****
81c2858
--- 16,22 ----
81c2858
  #define IDC_CD_SOURCE_PATH		1001
81c2858
  #define IDC_CD_SOURCE_PARENT		1002
81c2858
  #define IDC_CD_NONE			1003
81c2858
+ #define IDC_NEW_TABS			1004
81c2858
  
81c2858
  // Next default values for new objects
81c2858
  //
81c2858
*** ../vim-7.2.149/src/VisVim/VisVim.rc	Sun Jun 13 19:38:03 2004
81c2858
--- src/VisVim/VisVim.rc	Mon Mar  2 00:40:19 2009
81c2858
***************
81c2858
*** 122,127 ****
81c2858
--- 122,130 ----
81c2858
      CONTROL         "&Open file in DevStudio editor simultaneously",
81c2858
                      IDC_DEVSTUDIO_EDITOR,"Button",BS_AUTOCHECKBOX | WS_GROUP | 
81c2858
                      WS_TABSTOP,7,7,153,10
81c2858
+     CONTROL         "Open files in new tabs",
81c2858
+                     IDC_NEW_TABS,"Button",BS_AUTOCHECKBOX | WS_GROUP | 
81c2858
+                     WS_TABSTOP,7,21,153,10
81c2858
      GROUPBOX        "Current directory",IDC_STATIC,7,35,164,58,WS_GROUP
81c2858
      CONTROL         "Set to &source file path",IDC_CD_SOURCE_PATH,"Button",
81c2858
                      BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,17,49,85,10
81c2858
*** ../vim-7.2.149/src/version.c	Wed Apr 22 12:53:31 2009
81c2858
--- src/version.c	Wed Apr 22 13:04:32 2009
81c2858
***************
81c2858
*** 678,679 ****
81c2858
--- 678,681 ----
81c2858
  {   /* Add new patch number below this line */
81c2858
+ /**/
81c2858
+     150,
81c2858
  /**/
81c2858
81c2858
-- 
81c2858
A poem:                read aloud:
81c2858
81c2858
<> !*''#               Waka waka bang splat tick tick hash,
81c2858
^"`$$-                 Caret quote back-tick dollar dollar dash,
81c2858
!*=@$_                 Bang splat equal at dollar under-score,
81c2858
%*<> ~#4               Percent splat waka waka tilde number four,
81c2858
&[]../                 Ampersand bracket bracket dot dot slash,
81c2858
|{,,SYSTEM HALTED      Vertical-bar curly-bracket comma comma CRASH.
81c2858
81c2858
Fred Bremmer and Steve Kroese (Calvin College & Seminary of Grand Rapids, MI.)
81c2858
81c2858
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
81c2858
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
81c2858
\\\        download, build and distribute -- http://www.A-A-P.org        ///
81c2858
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///