[GME-commit] GMESRC/GME/ObjectInspector Attribute.cpp,1.16,1.17 InPlaceManager.cpp,1.24,1.25 InPlaceManager.h,1.8,1.9 InspectorDefs.h,1.13,1.14 ItemData.cpp,1.23,1.24 ItemData.h,1.18,1.19 ObjectInspector.vcproj,1.1,1.2

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Fri Feb 10 21:00:03 CST 2006


Update of /project/gme-repository/GMESRC/GME/ObjectInspector
In directory escher:/tmp/cvs-serv11251

Modified Files:
	Attribute.cpp InPlaceManager.cpp InPlaceManager.h 
	InspectorDefs.h ItemData.cpp ItemData.h ObjectInspector.vcproj 
Log Message:
Content-type (or extension) based editor launched as associated in the Windows Shell,
first the one associated with the edit verb, if such not exists open verb is used.
If unsuccessful, launched the one specified in the GME registry.
The content-type or extension is to be provided in the metamodel, in FieldAttribute's Content-Type field.
Strings starting with '.' are interpreted as extensions,
all others as content-types (mime types).
Mime types are stored in the MIME database: HKCR/MIME/DATABASE/Content-Type.



CVS User: Zoltan Molnar, ISIS (zolmol)

Index: InPlaceManager.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/InPlaceManager.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** InPlaceManager.h	2 Mar 2004 21:51:28 -0000	1.8
--- InPlaceManager.h	10 Feb 2006 21:00:00 -0000	1.9
***************
*** 57,61 ****
  	void HideEdit();
  
! 
  
  
--- 57,63 ----
  	void HideEdit();
  
! 	static bool findExt( const CString& pContentType, CString& pExtension);
! 	//implemented, but not used
! 	//static bool findCommand( const CString& pExtension, CString& pEditCommand);
  
  

Index: InspectorDefs.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/InspectorDefs.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** InspectorDefs.h	2 Mar 2004 21:51:28 -0000	1.13
--- InspectorDefs.h	10 Feb 2006 21:00:00 -0000	1.14
***************
*** 72,75 ****
--- 72,76 ----
  #define ATTRIBUTE_MULTILINE_PREFERENCE_REGISTRY_PATH "multiLine"
  #define ATTRIBUTE_HELP_REGISTRY_PATH "help"
+ #define ATTRIBUTE_CONTENTTYPE_REGISTRY_PATH "content-type"
  
  

Index: ItemData.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/ItemData.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** ItemData.cpp	15 Nov 2005 20:01:58 -0000	1.23
--- ItemData.cpp	10 Feb 2006 21:00:00 -0000	1.24
***************
*** 63,66 ****
--- 63,67 ----
  	strName=srcListItem.strName;			
  	strToolTip=srcListItem.strToolTip;	
+ 	strContentType=srcListItem.strContentType;
  	bIsDefault=srcListItem.bIsDefault;
  	bIsReadOnly=srcListItem.bIsReadOnly;
***************
*** 505,508 ****
--- 506,510 ----
  	strName=srcListItem.strName;			
  	strToolTip=srcListItem.strToolTip;	
+ 	strContentType=srcListItem.strContentType;
  	bIsDefault=srcListItem.bIsDefault;
  	bIsReadOnly=srcListItem.bIsReadOnly;

Index: Attribute.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/Attribute.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Attribute.cpp	3 Sep 2004 19:43:47 -0000	1.16
--- Attribute.cpp	10 Feb 2006 21:00:00 -0000	1.17
***************
*** 301,304 ****
--- 301,311 ----
  	ListItem.strToolTip=strHelpText;
  
+ 	// Getting content-type (stored in the registry like 'helpText')
+ 	CComBSTR bstrContTypePref;
+ 	CComBSTR bstrContTypePrefPath = ATTRIBUTE_CONTENTTYPE_REGISTRY_PATH;
+ 	COMTHROW(ccpMetaAttribute->get_RegistryValue(bstrContTypePrefPath,&bstrContTypePref));
+ 	CString strContentType=bstrContTypePref;
+ 	ListItem.strContentType=strContentType;
+ 
  	// Getting attribute type
  	attval_enum aeAttributeType;

Index: InPlaceManager.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/InPlaceManager.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** InPlaceManager.cpp	6 Jul 2005 20:10:10 -0000	1.24
--- InPlaceManager.cpp	10 Feb 2006 21:00:00 -0000	1.25
***************
*** 354,357 ****
--- 354,388 ----
  	}
  	
+ 	CString szAppPath;
+ 	bool content_specific_editor = false;
+ 
+ 	if( !ListItem.strContentType.IsEmpty())
+ 	{
+ 		CString extension;
+ 		bool content_type_valid = true;
+ 		if( ListItem.strContentType.GetAt(0) == '.') // starts with '.' -> interpret it as extension
+ 			extension = ListItem.strContentType;
+ 		else // interpret it as MIME type (Content-Type), and lookup the extension corresponding to it
+ 			content_type_valid = CInPlaceManager::findExt( ListItem.strContentType, extension);
+ 	
+ 		content_specific_editor = true;
+ 		// if enough space, append the extension to the filename
+ 		if( content_type_valid && _tcslen( szTempFileName) + extension.GetLength() <= MAX_PATH - 1) // there is enough room for appending the extension
+ 			_tcscat( szTempFileName, extension);
+ 		else if( content_type_valid && extension.GetLength() == 4) // replace tailing .tmp with extension
+ 			_tcsncpy( szTempFileName + _tcslen( szTempFileName) - 4, extension, 4);
+ 		else // can't use the content_specific_editor because the extension is not appended
+ 			content_specific_editor = false;
+ 
+ 		// we could use findCommand (implemented at bottom of file) to locate the command
+ 		// assigned for open/edit verbs, but we choose to rely on the ShellExecute call
+ 		//if( content_type_valid)
+ 		//{
+ 		//	content_specific_editor = findCommand( extension, szAppPath);
+ 		//	if( szAppPath.Find( "%1") != -1) // if "%1" found in command string replace it with tempfilename
+ 		//		szAppPath.Replace( "%1", szTempFileName); 
+ 		//}
+ 	}
+ 
  	CStdioFile tempFile;
  	if (tempFile.Open(szTempFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText) == 0) {
***************
*** 370,402 ****
  	tempFile.Close();
  
! 	// Get External Editor prefs and build command line for the editor application
! 	CString szAppPath;
! 	CComPtr<IMgaRegistrar> registrar;
! 	try {
! 		COMTHROW( registrar.CoCreateInstance(OLESTR("MGA.MgaRegistrar")) );
! 		ASSERT( registrar != NULL );
! 		COMTHROW( registrar->get_ExternalEditor(REGACCESS_USER, PutOut(szAppPath)) );
! 	} 
! 	catch (hresult_exception &) {
  	}
  
! 	CString szCommandLine = " ";
! 	szCommandLine += szTempFileName;
! 	int nCommandLineLength = szCommandLine.GetLength();
  
! 	// startup info for the redactor's process is taken similar to that
! 	// of invoking application
! 	STARTUPINFO startUpInfo;
! 	PROCESS_INFORMATION processInfo;
! 	::GetStartupInfo(&startUpInfo);
  
! 	// start notepad.exe with the XML file name as the command line parameter
  
! 	::CreateProcess(szAppPath,szCommandLine.GetBuffer(nCommandLineLength),
! 		NULL,NULL,FALSE,0,NULL,NULL,&startUpInfo,&processInfo);
! 	szCommandLine.ReleaseBuffer();
  
  	// DWORD h = ::WaitForSingleObject(processInfo.hProcess, INFINITE);
! 	m_EditorButton.MessageBox("Click OK to finish.", "Using External Text Editor", MB_ICONINFORMATION);
  
  	// open temporary file
--- 401,447 ----
  	tempFile.Close();
  
! 	BOOL launched = FALSE;
! 	if( content_specific_editor)
! 	{
! 		// success codes are strictly greater than 32
! 		int retcode = (int) ShellExecute( (HWND) m_EditorButton, "edit", szTempFileName, 0, 0, SW_SHOWNORMAL);
! 		if( retcode == SE_ERR_NOASSOC) // failed because no such verb (edit) exists for this extension
! 			retcode = (int) ShellExecute( (HWND) m_EditorButton, "open", szTempFileName, 0, 0, SW_SHOWNORMAL);
! 
! 		launched = retcode > 32;
! 		// if it was not launched successfully, use the specified editor
  	}
  
! 	if( !launched) // if not found a content specific one, or if it failed to launch
! 	{
! 		// Get External Editor prefs and build command line for the editor application
! 		CComPtr<IMgaRegistrar> registrar;
! 		try {
! 			COMTHROW( registrar.CoCreateInstance(OLESTR("MGA.MgaRegistrar")) );
! 			ASSERT( registrar != NULL );
! 			COMTHROW( registrar->get_ExternalEditor(REGACCESS_USER, PutOut(szAppPath)) );
! 		} 
! 		catch (hresult_exception &) {
! 		}
  
! 		CString szCommandLine = " ";
! 		szCommandLine += szTempFileName;
! 		int nCommandLineLength = szCommandLine.GetLength();
  
! 		// startup info for the redactor's process is taken similar to that
! 		// of invoking application
! 		STARTUPINFO startUpInfo;
! 		PROCESS_INFORMATION processInfo;
! 		::GetStartupInfo(&startUpInfo);
  
! 		// start notepad.exe with the XML file name as the command line parameter
! 
! 		launched = ::CreateProcess(szAppPath,szCommandLine.GetBuffer(nCommandLineLength),
! 			NULL,NULL,FALSE,0,NULL,NULL,&startUpInfo,&processInfo);
! 		szCommandLine.ReleaseBuffer();
! 	}
  
  	// DWORD h = ::WaitForSingleObject(processInfo.hProcess, INFINITE);
! 	if( launched) m_EditorButton.MessageBox("Click OK to finish.", "Using External Text Editor", MB_ICONINFORMATION);
  
  	// open temporary file
***************
*** 680,681 ****
--- 725,811 ----
  	}
  }
+ 
+ /*static*/ bool CInPlaceManager::findExt( const CString& pContentType, CString& pExtension)
+ {
+ 	// mime types (content types) are enumerated under:
+ 	const TCHAR MIME_DB[] = _T("MIME\\Database\\Content Type\\");
+ 	const TCHAR EXTENSION_VALUE[] = _T("Extension");
+ 
+ 	CRegKey rk;
+ 	LONG res = rk.Open( HKEY_CLASSES_ROOT, MIME_DB + pContentType, KEY_READ);
+ 
+ 	if( res != ERROR_SUCCESS) // such a mime type not found
+ 		return false;
+ 
+ 	// an Extension value exists hopefully
+ 	ULONG buff_len = 32; // we don't expect wider extensions than 32
+ 	CString ext(' ', buff_len);
+ 	TCHAR* buff = ext.GetBufferSetLength( buff_len);
+ 	res = rk.QueryStringValue( EXTENSION_VALUE, buff, &buff_len);
+ 	ext.ReleaseBufferSetLength( buff_len);
+ 	rk.Close();
+ 
+ 	if( res != ERROR_SUCCESS) // it doesn't
+ 		return false;
+ 
+ 	pExtension = ext;
+ 	return !pExtension.IsEmpty();
+ }
+ 
+ // finds the Open/Edit verb defined for the file class (extension)
+ // format of returned string pCommand
+ // "C:\Program Files\Windows Media Player\wmplayer.exe" "%L"
+ // "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" "%1"
+ // "C:\Program Files\Opera8\Opera.exe" "%1"
+ // "C:\Program Files\apps\Microsoft Office\Office10\msohtmed.exe" %1
+ //
+ ///*static*/ bool CInPlaceManager::findCommand( const CString& pExtension, CString& pCommand)
+ //{
+ //	if( pExtension.IsEmpty() || pExtension.GetAt(0) != '.') return false;
+ //
+ //	CRegKey rk;
+ //	LONG res;
+ //	res = rk.Open( HKEY_CLASSES_ROOT, pExtension , KEY_READ);
+ //	if( res != ERROR_SUCCESS) // such an extension not found
+ //		return false;
+ //
+ //	// for each extension a file class is created typically: .xls -> Excel.Sheet.8
+ //	ULONG buff_len = 256; // it is enough long for a file class name
+ //	CString file_class( ' ', buff_len); 
+ //	TCHAR * buff = file_class.GetBufferSetLength( buff_len);
+ //	res = rk.QueryStringValue( 0, buff, &buff_len);
+ //	file_class.ReleaseBufferSetLength( buff_len);
+ //
+ //	rk.Close();
+ //	if( res != ERROR_SUCCESS)
+ //		return false;
+ //
+ //	file_class = buff;
+ //
+ //	res = rk.Open(HKEY_CLASSES_ROOT, file_class , KEY_READ);
+ //	if( res != ERROR_SUCCESS) return false;
+ //
+ //	CRegKey sk;
+ //	const TCHAR SHELL_EDIT_COMMAND[] = _T("SHELL\\EDIT\\COMMAND");
+ //	const TCHAR SHELL_OPEN_COMMAND[] = _T("SHELL\\OPEN\\COMMAND");
+ //
+ //	res = sk.Open( rk, SHELL_EDIT_COMMAND, KEY_READ);
+ //	if( res != ERROR_SUCCESS)
+ //	{
+ //		res = sk.Open( rk, SHELL_OPEN_COMMAND, KEY_READ); // this is the most common
+ //		if( res != ERROR_SUCCESS)
+ //			return false;
+ //	}
+ //
+ //	
+ //	ULONG cmd_len = MAX_PATH;
+ //	TCHAR * cmd = pCommand.GetBufferSetLength( cmd_len);
+ //	res = sk.QueryStringValue( 0, cmd, &cmd_len);
+ //	pCommand.ReleaseBufferSetLength( cmd_len);
+ //	sk.Close();
+ //
+ //	if( res != ERROR_SUCCESS)
+ //		return false;
+ //
+ //	return !pCommand.IsEmpty(); // return true only if something valuable found
+ //}

Index: ItemData.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/ItemData.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** ItemData.h	15 Nov 2005 20:01:58 -0000	1.18
--- ItemData.h	10 Feb 2006 21:00:00 -0000	1.19
***************
*** 107,110 ****
--- 107,111 ----
  	CString strName;
  	CString strToolTip;
+ 	CString strContentType;
  	bool bIsDefault;
  	bool bIsReadOnly;

Index: ObjectInspector.vcproj
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/ObjectInspector/ObjectInspector.vcproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ObjectInspector.vcproj	26 Jan 2005 17:30:55 -0000	1.1
--- ObjectInspector.vcproj	10 Feb 2006 21:00:00 -0000	1.2
***************
*** 49,52 ****
--- 49,53 ----
  			<Tool
  				Name="VCLinkerTool"
+ 				AdditionalDependencies="shell32.lib"
  				OutputFile=".\Release/ObjectInspector.ocx"
  				LinkIncremental="1"
***************
*** 126,129 ****
--- 127,131 ----
  			<Tool
  				Name="VCLinkerTool"
+ 				AdditionalDependencies="shell32.lib"
  				OutputFile=".\Debug/ObjectInspector.ocx"
  				LinkIncremental="2"



More information about the GME-commit mailing list