OSDN Git Service

2005-06-08 Perry
authorPerry Rapp <elsapo@users.sourceforge.net>
Wed, 8 Jun 2005 17:38:13 +0000 (17:38 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Wed, 8 Jun 2005 17:38:13 +0000 (17:38 +0000)
 PATCH: [ 1213238 ] noninteractive switch
  Src: MainFrm.cpp MainFrm.h Merge.cpp Merge.dsp Merge.h

Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.cpp
Src/Merge.dsp
Src/Merge.h
Src/readme.txt

index 6d69702..68900bb 100644 (file)
@@ -2011,6 +2011,18 @@ void CMainFrame::GetAllDirDocs(DirDocList * pDirDocs)
        }
 }
 
+/// Get list of all dirviews
+void CMainFrame::GetDirViews(DirViewList * pDirViews)
+{
+       GetAllViews(NULL, NULL, pDirViews);
+}
+
+/// Get list of all merge edit views
+void CMainFrame::GetMergeEditViews(MergeEditViewList * pMergeViews)
+{
+       GetAllViews(pMergeViews, NULL, NULL);
+}
+
 /// Get pointers to all views into typed lists (both arguments are optional)
 void CMainFrame::GetAllViews(MergeEditViewList * pEditViews, MergeDetailViewList * pDetailViews, DirViewList * pDirViews)
 {
@@ -2851,3 +2863,13 @@ CMainFrame::UpdateCodepageModule()
        // and push them into the codepage module
        updateDefaultCodepage(m_options.GetInt(OPT_CP_DEFAULT_MODE), m_options.GetInt(OPT_CP_DEFAULT_CUSTOM));
 }
+
+void
+CMainFrame::OnTimer(UINT nIDEvent)
+{
+       if (nIDEvent == WM_NONINTERACTIVE)
+       {
+               KillTimer(nIDEvent);
+               PostMessage(WM_CLOSE);
+       }
+}
index 8ab6d91..207ae79 100644 (file)
@@ -58,6 +58,8 @@ enum
        VCS_CLEARCASE,
 };
 
+enum { WM_NONINTERACTIVE = 888 }; // timer value
+
 class CDiffView;
 class CDirView;
 class CDirDoc;
@@ -119,6 +121,8 @@ public:
        void ShowVSSError(CException *e, CString strItem);
        void ShowHelp();
        void UpdateCodepageModule();
+       void GetDirViews(DirViewList * pDirViews);
+       void GetMergeEditViews(MergeEditViewList * pMergeViews);
 
 // Overrides
        // ClassWizard generated virtual function overrides
@@ -226,6 +230,7 @@ protected:
        afx_msg void OnViewToolbar();
        afx_msg void OnFileOpenproject();
        afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
+       afx_msg void OnTimer(UINT nIDEvent);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 
index a2f676e..5de4154 100644 (file)
@@ -47,8 +47,9 @@
 #include "Plugins.h"
 #include "DirScan.h" // for DirScan_InitializeDefaultCodepage
 #include "ProjectFile.h"
-
+#include "CmdArgs.h"
 #include "MergeEditView.h"
+
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #undef THIS_FILE
@@ -86,6 +87,7 @@ CMergeApp::CMergeApp() :
 // FileFilterHelper m_globalFileFilter
 , m_mainThreadScripts(NULL)
 , m_nLastCompareResult(0)
+, m_bNoninteractive(false)
 {
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
@@ -271,6 +273,19 @@ BOOL CMergeApp::InitInstance()
                CloseHandle(hMutex);
        }
 
+       if (m_bNoninteractive)
+       {
+               DirViewList DirViews;
+               pMainFrame->GetDirViews(&DirViews);
+               if (DirViews.GetCount() == 1)
+               {
+                       CDirView * pDirView = DirViews.RemoveHead();
+                       CDirFrame *pf = pDirView->GetParentFrame();
+                       pf->ShowProcessingBar(FALSE);
+               }
+               pMainFrame->PostMessage(WM_CLOSE, 0, 0);
+       }
+
        return TRUE;
 }
 
@@ -325,52 +340,64 @@ void CMergeApp::ParseArgsAndDoOpen(int argc, TCHAR *argv[], CMainFrame* pMainFra
 void CMergeApp::ParseArgs(int argc, TCHAR *argv[], CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles, BOOL & recurse,
                DWORD & dwLeftFlags, DWORD & dwRightFlags)
 {
-       for (int i = 1; i < argc; i++)
+       CmdArgs cmdArgs(argc, argv);
+
+       // -? for help
+       if (cmdArgs.HasEmptySwitch(_T("?")))
        {
-               LPCTSTR pszParam = argv[i];
-               if (pszParam[0] == '-' || pszParam[0] == '/')
-               {
-                       // remove flag specifier
-                       ++pszParam;
+               CString s;
+               VERIFY(s.LoadString(IDS_QUICKHELP));
+               AfxMessageBox(s, MB_ICONINFORMATION);
+       }
 
-                       // -? for help
-                       if (!_tcsicmp(pszParam, _T("?")))
-                       {
-                               CString s;
-                               VERIFY(s.LoadString(IDS_QUICKHELP));
-                               AfxMessageBox(s, MB_ICONINFORMATION);
-                       }
+       // -r to compare recursively
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("r")))
+               recurse = TRUE;
+
+       // -e to allow closing with single esc press
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("e")))
+               pMainFrame->m_bEscShutdown = TRUE;
 
-                       // -r to compare recursively
-                       if (!_tcsicmp(pszParam, _T("r")))
-                               recurse = TRUE;
+       // -wl to open left path as read-only
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("wl")))
+               dwLeftFlags |= FFILEOPEN_READONLY;
 
-                       // -e to allow closing with single esc press
-                       if (!_tcsicmp(pszParam, _T("e")))
-                               pMainFrame->m_bEscShutdown = TRUE;
+       // -wr to open right path as read-only
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("wr")))
+               dwRightFlags |= FFILEOPEN_READONLY;
 
-                       // -wl to open left path as read-only
-                       if (!_tcsicmp(pszParam, _T("wl")))
-                               dwLeftFlags |= FFILEOPEN_READONLY;
+       // -ul to not add left path to MRU
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("ul")))
+               dwLeftFlags |= FFILEOPEN_NOMRU;
 
-                       // -wr to open right path as read-only
-                       if (!_tcsicmp(pszParam, _T("wr")))
-                               dwRightFlags |= FFILEOPEN_READONLY;
+       // -ur to not add right path to MRU
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("ur")))
+               dwRightFlags |= FFILEOPEN_NOMRU;
 
-                       // -ul to not add left path to MRU
-                       if (!_tcsicmp(pszParam, _T("ul")))
-                               dwLeftFlags |= FFILEOPEN_NOMRU;
+       // -ub to not add paths to MRU
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("ub")))
+       {
+               dwLeftFlags |= FFILEOPEN_NOMRU;
+               dwRightFlags |= FFILEOPEN_NOMRU;
+       }
 
-                       // -ur to not add right path to MRU
-                       if (!_tcsicmp(pszParam, _T("ur")))
-                               dwRightFlags |= FFILEOPEN_NOMRU;
+       // -noninteractive to suppress message boxes & close with result code
+       if (cmdArgs.HasEmptySwitchInsensitive(_T("noninteractive")))
+       {
+               m_bNoninteractive = true;
+       }
+
+       // Can't get switches with arguments from cmdArgs
+       // because cmdArgs recognizes arguments using colons not spaces
+
+       for (int i = 1; i < argc; i++)
+       {
+               LPCTSTR pszParam = argv[i];
+               if (pszParam[0] == '-' || pszParam[0] == '/')
+               {
+                       // remove flag specifier
+                       ++pszParam;
 
-                       // -ub to not add paths to MRU
-                       if (!_tcsicmp(pszParam, _T("ub")))
-                       {
-                               dwLeftFlags |= FFILEOPEN_NOMRU;
-                               dwRightFlags |= FFILEOPEN_NOMRU;
-                       }
 
                        // -dl "desc" - description for left file
                        // Shown instead of filename
@@ -694,7 +721,10 @@ int CMergeApp::DoMessageBox( LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt )
        // Use our own message box implementation, which adds the
        // do not show again checkbox, and implements it on subsequent calls
        // (if caller set the style)
-       
+
+       if (m_bNoninteractive)
+               return IDCANCEL;
+
        // Create the message box dialog.
        CMessageBoxDialog dlgMessage(pParentWnd, lpszPrompt, _T(""), nType,
                nIDPrompt);
index 6df93bc..c1da360 100644 (file)
@@ -201,6 +201,10 @@ SOURCE=.\ChildFrm.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\CmdArgs.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\Common\CMoveConstraint.cpp
 # End Source File
 # Begin Source File
@@ -865,6 +869,10 @@ SOURCE=.\ChildFrm.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\CmdArgs.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\Common\CMoveConstraint.h
 # End Source File
 # Begin Source File
index 2080445..439742f 100644 (file)
@@ -98,6 +98,7 @@ protected:
 private:
        CAssureScriptsForThread * m_mainThreadScripts;
        int m_nLastCompareResult;
+       bool m_bNoninteractive;
 };
 
 extern CMergeApp theApp;
index 5995aac..63c7ebc 100644 (file)
@@ -1,3 +1,7 @@
+2005-06-08 Perry
+ PATCH: [ 1213238 ] noninteractive switch
+  Src: MainFrm.cpp MainFrm.h Merge.cpp Merge.dsp Merge.h
+
 2005-06-08 WinMerge experimental release 2.3.3.5 (cvs)
 
 2005-06-08 Kimmo