From: <net...@us...> - 2002-12-30 10:43:29
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin In directory sc8-pr-cvs1:/tmp/cvs-serv30180 Modified Files: VCLineBasedTextDocument.cpp rftavc6addin.odl rftavc6addin.dsp Resource.h DSAddIn.cpp Commands.h Commands.cpp Added Files: SplitLocaleVariableDialog.cpp RftaInlineLocalVarDialog.cpp How-To-Add-Commands.txt Log Message: -- added fcts 'InlineTemp' and 'SplitTemp' --- NEW FILE: SplitLocaleVariableDialog.cpp --- // SplitLocaleVariableDialog.cpp : implementation file // #include "stdafx.h" #include "rftavc6addin.h" #include "SplitLocaleVariableDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // SplitLocaleVariableDialog dialog SplitLocaleVariableDialog::SplitLocaleVariableDialog(CWnd* pParent /*=NULL*/) : CDialog(SplitLocaleVariableDialog::IDD, pParent) { //{{AFX_DATA_INIT(SplitLocaleVariableDialog) m_NewVariableName = _T(""); //}}AFX_DATA_INIT } void SplitLocaleVariableDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(SplitLocaleVariableDialog) DDX_Text(pDX, IDC_NEW_NAME, m_NewVariableName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(SplitLocaleVariableDialog, CDialog) //{{AFX_MSG_MAP(SplitLocaleVariableDialog) // NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // SplitLocaleVariableDialog message handlers --- NEW FILE: RftaInlineLocalVarDialog.cpp --- // RftaInlineLocalVarDialog.cpp : implementation file // #include "stdafx.h" #include "rftavc6addin.h" #include "RftaInlineLocalVarDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // RftaInlineLocalVarDialog dialog RftaInlineLocalVarDialog::RftaInlineLocalVarDialog(CWnd* pParent /*=NULL*/) : CDialog(RftaInlineLocalVarDialog::IDD, pParent) { //{{AFX_DATA_INIT(RftaInlineLocalVarDialog) m_VariableName = _T(""); m_AddBraces = FALSE; //}}AFX_DATA_INIT } void RftaInlineLocalVarDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(RftaInlineLocalVarDialog) DDX_Text(pDX, IDC_OLD_NAME, m_VariableName); DDX_Check(pDX, IDC_CHECK1, m_AddBraces); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(RftaInlineLocalVarDialog, CDialog) //{{AFX_MSG_MAP(RftaInlineLocalVarDialog) // NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // RftaInlineLocalVarDialog message handlers --- NEW FILE: How-To-Add-Commands.txt --- This article describes howto add new refactoring commands to the vc6 addin: step 1) go to VS6-IDE class-browser of the project vc6addin. right click the 'ICommands' element and select "Add Method" Enter a method name representing your add in function step 2) go to VS6-IDE resource-browser of the project vc6addin * right click 'Dialog' and select "insert dialog" Choose a dialog identifier representing your addin function * double click 'IDR_TOOLBAR_REFACTORING' and draw a new icon for your function at the last position in the toolbar * double click 'StringTable' and add a String describing the tool tip for the new button in the tool bar (choose a good StringIdentifier (IDS_...) for your function step 3) go to VS6-IDE class-browser of the project vc6addin. * right click project name and select 'New Form...' (maybe you need to create a class wizard file before this option appears). Select the Dialog-ID of your designed dialog of step 1). * create class members for all dialog data elements using the class wizard (this is needed to access the data entered by the user) step 4) open the file DSAddIn.cpp and go to method'CDSAddIn::OnConnection'. there your will find the code for registration of all refactoring methods that appear in the tool bar. Insert the following code for your addin function: { // ENTER HERE the ICommand function name you have choosen in Step 1) LPCTSTR szCommand = _T(" xxxxxxxxxxxxxxxx "); VARIANT_BOOL bRet; CString strCmdString; // ENTER HERE the StringTable Indentifier you have created in Step 2c) strCmdString.LoadString( xxxxxxxxxxxxxxxxx ); strCmdString = szCommand + strCmdString; CComBSTR bszCmdString(strCmdString); // ENTER HERE the ICommand function name you have choosen in Step 1) CComBSTR bszMethod(_T("RftaRenameLocaleVariable")); CComBSTR bszCmdName(szCommand); // ENTER HERE the correct index position of the icon in the toolbar VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, xxxxxx , m_dwCookie, &bRet)); if (bRet == VARIANT_FALSE) { // AddCommand failed because a command with this name already // exists. You may try adding your command under a different name. // Or, you can fail to load as we will do here. *OnConnection = VARIANT_FALSE; return S_OK; } // Add toolbar buttons only if this is the first time the add-in // is being loaded. Toolbar buttons are automatically remembered // by Developer Studio from session to session, so we should only // add the toolbar buttons once. if (bFirstTime == VARIANT_TRUE) { VERIFY_OK(pApplication-> AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); } } Step 5) Open file "Commands.h" and go to the section "ICommands methods" There will be a new element with the name you entered in Step 1). Please add the parameter "THIS" Open file "Commands.cpp" go to the end. There will be an empty implementation of the function you specified in step 1). Add calls to your refactoring functionality in here (also the dialog handling etc.) ... watch the other functions... Index: VCLineBasedTextDocument.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/VCLineBasedTextDocument.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VCLineBasedTextDocument.cpp 18 Dec 2002 22:53:27 -0000 1.1 --- VCLineBasedTextDocument.cpp 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 11,15 **** VCLineBasedTextDocument::VCLineBasedTextDocument( const TextDocumentHelper &helper ) ! : helper_( helper ) { initialize( getAllText() ); --- 11,15 ---- VCLineBasedTextDocument::VCLineBasedTextDocument( const TextDocumentHelper &helper ) ! : helper_( helper ), LineBasedTextDocument(3) { initialize( getAllText() ); Index: rftavc6addin.odl =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/rftavc6addin.odl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rftavc6addin.odl 18 Dec 2002 22:53:27 -0000 1.1 --- rftavc6addin.odl 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 31,34 **** --- 31,38 ---- [id(1)] HRESULT RftaRenameLocaleVariable(); + [id(2), helpstring("Inline local variable value at all occurences of the variable.")] + HRESULT RftaInlineLocaleVariable(); + [id(3), helpstring("Split the uses of local variables at assignment point (create additional declaration with new name)")] + HRESULT RftaSplitLocaleVariable(); }; Index: rftavc6addin.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/rftavc6addin.dsp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rftavc6addin.dsp 18 Dec 2002 22:53:27 -0000 1.1 --- rftavc6addin.dsp 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 56,60 **** # ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /libpath:"../../lib" # Begin Special Build Tool ! TargetPath=\prg\vc\Rfta\build\rftavc6addin\Release\rftavc6addin.dll SOURCE="$(InputPath)" PostBuild_Desc=exporting... --- 56,60 ---- # ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /libpath:"../../lib" # Begin Special Build Tool ! TargetPath=\Projects\Cpptool\rfta\build\rftavc6addin\Release\rftavc6addin.dll SOURCE="$(InputPath)" PostBuild_Desc=exporting... *************** *** 88,92 **** # ADD LINK32 cppunitd_dll.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept /libpath:"../../lib" /libpath:"../../deplib/cppunit/lib" # Begin Special Build Tool ! TargetPath=\prg\vc\Rfta\build\rftavc6addin\Debug\rftavc6addin.dll SOURCE="$(InputPath)" PostBuild_Desc=Exporting... --- 88,92 ---- # ADD LINK32 cppunitd_dll.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept /libpath:"../../lib" /libpath:"../../deplib/cppunit/lib" # Begin Special Build Tool ! TargetPath=\Projects\Cpptool\rfta\build\rftavc6addin\Debug\rftavc6addin.dll SOURCE="$(InputPath)" PostBuild_Desc=Exporting... *************** *** 105,108 **** --- 105,112 ---- # Begin Source File + SOURCE=.\res\bmp00001.bmp + # End Source File + # Begin Source File + SOURCE=.\res\rftavc6addin.rc2 # PROP Exclude_From_Scan -1 *************** *** 118,121 **** --- 122,133 ---- SOURCE=.\res\TBarMedm.bmp # End Source File + # Begin Source File + + SOURCE=.\res\toolbar1.bmp + # End Source File + # Begin Source File + + SOURCE=.\res\toolbar_.bmp + # End Source File # End Group # Begin Group "Stuffs" *************** *** 218,221 **** --- 230,249 ---- # Begin Source File + SOURCE=.\RftaInlineLocalVarDialog.cpp + # End Source File + # Begin Source File + + SOURCE=.\RftaInlineLocalVarDialog.h + # End Source File + # Begin Source File + + SOURCE=.\SplitLocaleVariableDialog.cpp + # End Source File + # Begin Source File + + SOURCE=.\SplitLocaleVariableDialog.h + # End Source File + # Begin Source File + SOURCE=.\VCLineBasedTextDocument.cpp # End Source File *************** *** 225,228 **** --- 253,260 ---- # End Source File # End Group + # Begin Source File + + SOURCE=".\How-To-Add-Commands.txt" + # End Source File # Begin Source File Index: Resource.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/Resource.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Resource.h 18 Dec 2002 22:53:27 -0000 1.1 --- Resource.h 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 5,14 **** #define IDS_RFTAVC6ADDIN_LONGNAME 1 #define IDS_RFTAVC6ADDIN_DESCRIPTION 2 ! #define IDS_CMD_STRING 3 ! #define IDR_TOOLBAR_MEDIUM 128 ! #define IDR_TOOLBAR_LARGE 129 #define IDD_RENAME_LOCALE_VARIABLE 130 #define IDC_NEW_NAME 1000 #define IDC_OLD_NAME 1001 // Next default values for new objects --- 5,23 ---- #define IDS_RFTAVC6ADDIN_LONGNAME 1 #define IDS_RFTAVC6ADDIN_DESCRIPTION 2 ! #define IDS_RENAMELOCAL_INFO 3 ! #define IDS_INLINELOCAL_INFO 4 ! #define IDS_SPLITLOCAL_INFO 5 ! #define IDR_REPLACE_MEDIUM 128 #define IDD_RENAME_LOCALE_VARIABLE 130 + #define IDB_INLINE_MEDIUM 131 + #define IDD_INLINE_LOCAL_VARIABLE 132 + #define IDR_TOOLBAR_REFACTORING 135 + #define IDD_SPLIT_LOCAL_VAR 137 #define IDC_NEW_NAME 1000 #define IDC_OLD_NAME 1001 + #define IDC_CHECK1 1002 + #define ID_BUTTON32771 32771 + #define ID_BUTTON32772 32772 + #define ID_BUTTON32773 32773 // Next default values for new objects *************** *** 16,22 **** #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS ! #define _APS_NEXT_RESOURCE_VALUE 131 ! #define _APS_NEXT_COMMAND_VALUE 32771 ! #define _APS_NEXT_CONTROL_VALUE 1002 #define _APS_NEXT_SYMED_VALUE 101 #endif --- 25,31 ---- #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS ! #define _APS_NEXT_RESOURCE_VALUE 138 ! #define _APS_NEXT_COMMAND_VALUE 32774 ! #define _APS_NEXT_CONTROL_VALUE 1003 #define _APS_NEXT_SYMED_VALUE 101 #endif Index: DSAddIn.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/DSAddIn.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DSAddIn.cpp 18 Dec 2002 22:53:27 -0000 1.1 --- DSAddIn.cpp 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 42,46 **** VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(), ! (LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie)); // Inform DevStudio of the commands we implement --- 42,46 ---- VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(), ! (LPDISPATCH) m_pCommands, IDR_TOOLBAR_REFACTORING, IDR_TOOLBAR_REFACTORING, m_dwCookie)); // Inform DevStudio of the commands we implement *************** *** 53,83 **** // command are stored in the string table (IDS_CMD_STRING) and should // be localized. ! LPCTSTR szCommand = _T("RftaRenameLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_CMD_STRING); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaRenameLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } *OnConnection = VARIANT_TRUE; --- 53,153 ---- // command are stored in the string table (IDS_CMD_STRING) and should // be localized. ! { ! LPCTSTR szCommand = _T("RftaRenameLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_RENAMELOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaRenameLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } ! } ! ! // The command name should not be localized to other languages. The ! // tooltip, command description, and other strings related to this ! // command are stored in the string table (IDS_CMD_STRING) and should ! // be localized. ! { ! LPCTSTR szCommand = _T("RftaInlineLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_INLINELOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaInlineLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 1, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } ! } ! ! // The command name should not be localized to other languages. The ! // tooltip, command description, and other strings related to this ! // command are stored in the string table (IDS_CMD_STRING) and should ! // be localized. ! { ! LPCTSTR szCommand = _T("RftaSplitLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_SPLITLOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaSplitLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 2, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } ! } *OnConnection = VARIANT_TRUE; Index: Commands.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/Commands.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Commands.h 18 Dec 2002 22:53:27 -0000 1.1 --- Commands.h 30 Dec 2002 10:43:26 -0000 1.2 *************** *** 94,97 **** --- 94,99 ---- // ICommands methods STDMETHOD(RftaRenameLocaleVariable)(THIS); + STDMETHOD(RftaInlineLocaleVariable)(THIS); + STDMETHOD(RftaSplitLocaleVariable)(); }; Index: Commands.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/Commands.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Commands.cpp 22 Dec 2002 16:03:53 -0000 1.4 --- Commands.cpp 30 Dec 2002 10:43:26 -0000 1.5 *************** *** 7,13 **** --- 7,17 ---- #include "Commands.h" #include "RenameLocaleVariableDialog.h" + #include "RftaInlineLocalVarDialog.h" + #include "SplitLocaleVariableDialog.h" #include "VCLineBasedTextDocument.h" #include <rfta/refactoring/RefactoringError.h> #include <rfta/refactoring/RenameTempRefactoring.h> + #include <rfta/refactoring/InlineTempRefactoring.h> + #include <rfta/refactoring/SplitTempRefactoring.h> #ifdef _DEBUG *************** *** 198,201 **** --- 202,274 ---- if ( dialog.DoModal() == IDOK ) refactoring.apply( (LPCTSTR)dialog.newName_ ); + } + catch ( Refactoring::RefactoringError &e ) + { + CString message( "An error occurred during refactoring:\n" ); + message += e.what(); + + AfxMessageBox( message ); + } + + return S_OK; + } + + STDMETHODIMP CCommands::RftaInlineLocaleVariable() + { + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + + TextDocumentHelper documentHelper = ApplicationHelper::activeTextDocument(); + if ( !documentHelper.isValid() ) + return S_OK; // current document is not a text document + + VCLineBasedTextDocument document( documentHelper ); + Refactoring::SourceRange selection = document.getSelectionRange(); + + try + { + Refactoring::InlineTempRefactoring refactoring( document, + selection.getStartIndex() ); + + bool addBraces = refactoring.areBracesSuggested(); + RftaInlineLocalVarDialog dialog; + dialog.m_VariableName = refactoring.getVariableName().c_str(); + dialog.m_AddBraces = addBraces; + + if ( dialog.DoModal() == IDOK ) + refactoring.apply( dialog.m_AddBraces==TRUE ); + } + catch ( Refactoring::RefactoringError &e ) + { + CString message( "An error occurred during refactoring:\n" ); + message += e.what(); + + AfxMessageBox( message ); + } + + return S_OK; + } + + STDMETHODIMP CCommands::RftaSplitLocaleVariable() + { + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + + TextDocumentHelper documentHelper = ApplicationHelper::activeTextDocument(); + if ( !documentHelper.isValid() ) + return S_OK; // current document is not a text document + + VCLineBasedTextDocument document( documentHelper ); + Refactoring::SourceRange selection = document.getSelectionRange(); + + try + { + Refactoring::SplitTempRefactoring refactoring( document, + selection.getStartIndex() ); + + SplitLocaleVariableDialog dialog; + + if ( dialog.DoModal() == IDOK ) + { + refactoring.apply( LPCTSTR(dialog.m_NewVariableName) ); + } } catch ( Refactoring::RefactoringError &e ) |