patch for go to line command line option

Main development forum.

patch for go to line command line option

Postby drkow » Thu Sep 17, 2009 3:51 am

I wrote some VS macros for quick code merging with winmerge, and was annoyed by constantly scrolling down to the line I was editing.

Here is a quick and dirty patch to add support for go to line as a command line switch.

usage: winmergeu.exe /l 123 1.txt 2.txt

Code: Select all
Index: Src/MainFrm.cpp
===================================================================
--- Src/MainFrm.cpp   (revision 6990)
+++ Src/MainFrm.cpp   (working copy)
@@ -1082,7 +1082,7 @@
  */
 BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*/,
    DWORD dwLeftFlags /*=0*/, DWORD dwRightFlags /*=0*/, BOOL bRecurse /*=FALSE*/, CDirDoc *pDirDoc/*=NULL*/,
-   CString prediffer /*=_T("")*/)
+   CString prediffer /*=_T("")*/, int goToLine)
 {
    // If the dirdoc we are supposed to use is busy doing a diff, bail out
    if (IsComparing())
@@ -1310,6 +1310,15 @@
 
       ShowMergeDoc(pDirDoc, filelocLeft, filelocRight, dwLeftFlags, dwRightFlags,
          &infoUnpacker);
+
+      if (goToLine != 0)
+      {
+         const MergeDocList &docs = GetAllMergeDocs();
+         POSITION pos = docs.GetHeadPosition();
+         CMergeDoc * pMergeDoc = docs.GetNext(pos);
+         CMergeEditView * pLeft = pMergeDoc->GetLeftView();
+         pLeft->GotoLine(goToLine - 1, true, 0);
+      }
    }
    return TRUE;
 }
Index: Src/MainFrm.h
===================================================================
--- Src/MainFrm.h   (revision 6990)
+++ Src/MainFrm.h   (working copy)
@@ -108,7 +108,7 @@
 
    BOOL SyncFileToVCS(LPCTSTR pszDest,   BOOL &bApplyToAll, CString *psError);
    BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
-      DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE, CDirDoc *pDirDoc = NULL, CString prediffer = _T(""));
+      DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE, CDirDoc *pDirDoc = NULL, CString prediffer = _T(""), int goToLine = 0);
    int ShowMergeDoc(CDirDoc * pDirDoc, const FileLocation & filelocLeft,
       const FileLocation & filelocRight, DWORD dwLeftFlags = 0,
       DWORD dwRightFlags = 0, PackingInfo * infoUnpacker = NULL);
Index: Src/Merge.cpp
===================================================================
--- Src/Merge.cpp   (revision 6990)
+++ Src/Merge.cpp   (working copy)
@@ -611,7 +611,7 @@
          bCompared = pMainFrame->DoFileOpen(cmdInfo.m_Files[0].c_str(),
             cmdInfo.m_Files[1].c_str(),   cmdInfo.m_dwLeftFlags,
             cmdInfo.m_dwRightFlags, cmdInfo.m_bRecurse, NULL,
-            cmdInfo.m_sPreDiffer.c_str());
+            cmdInfo.m_sPreDiffer.c_str(), _wtoi(cmdInfo.m_sGoToLine.c_str()));
       }
       else if (cmdInfo.m_Files.size() == 1)
       {
Index: Src/MergeCmdLineInfo.cpp
===================================================================
--- Src/MergeCmdLineInfo.cpp   (revision 6990)
+++ Src/MergeCmdLineInfo.cpp   (working copy)
@@ -260,6 +260,12 @@
          // -? to show common command line arguments.
          m_bShowUsage = true;
       }
+      
+      else if (param == _T("l"))
+      {
+         // -l line_number - go to specific line.
+         q = EatParam(q, m_sGoToLine);
+      }
       else if (param == _T("dl"))
       {
          // -dl "desc" - description for left file
Index: Src/MergeCmdLineInfo.h
===================================================================
--- Src/MergeCmdLineInfo.h   (revision 6990)
+++ Src/MergeCmdLineInfo.h   (working copy)
@@ -65,6 +65,8 @@
 
    DWORD m_dwLeftFlags; /**< Left side file's behavior options. */
    DWORD m_dwRightFlags; /**< Right side file's behavior options. */
+   
+   String m_sGoToLine; /**< Go to specified line. */
 
    String m_sLeftDesc; /**< Left side file's description. */
    String m_sRightDesc; /**< Right side file's description. */



and here is the VS macro:
Code: Select all
    Sub diff()
        Dim selection As EnvDTE.TextSelection
        Dim line As Integer
        selection = DTE.ActiveDocument.Selection()
        line = selection.ActivePoint.Line
        Dim lineS As String = Convert.ToString(line)
        Dim fileName As String
        fileName = DTE.ActiveDocument.FullName
        Microsoft.VisualBasic.ChDir("C:\Program Files\WinMerge\")
        Microsoft.VisualBasic.Shell("cmd.exe /c start WinMergeU.exe /wr /s /l " + lineS + " " + fileName + " " + Replace(fileName, "meerkat", "snowglobe"), AppWinStyle.MaximizedFocus)
    End Sub
drkow
 
Posts: 1
Joined: Thu Sep 17, 2009 3:04 am

Re: patch for go to line command line option

Postby matthias1955 » Sun Sep 27, 2009 9:33 pm

matthias1955
 
Posts: 162
Joined: Wed Dec 17, 2008 1:55 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 3 guests