OSDN Git Service

Fix the problem that the BS key does not work at the beginning of the line after...
[winmerge-jp/winmerge-jp.git] / Src / MergeEditView.cpp
index 92de286..b6fc755 100644 (file)
@@ -32,6 +32,7 @@
 #include "DirDoc.h"
 #include "ShellContextMenu.h"
 #include "editcmd.h"
+#include "Shell.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -63,7 +64,6 @@ CMergeEditView::CMergeEditView()
 , m_nThisGroup(0)
 , m_bDetailView(false)
 , m_piMergeEditStatus(nullptr)
-, m_bAutomaticRescan(false)
 , fTimerWaitingForIdle(0)
 , m_lineBegin(0)
 , m_lineEnd(-1)
@@ -221,6 +221,7 @@ BEGIN_MESSAGE_MAP(CMergeEditView, CCrystalEditViewEx)
        ON_COMMAND(ID_FILE_OPEN_REGISTERED, OnOpenFile)
        ON_COMMAND(ID_FILE_OPEN_WITHEDITOR, OnOpenFileWithEditor)
        ON_COMMAND(ID_FILE_OPEN_WITH, OnOpenFileWith)
+       ON_COMMAND(ID_FILE_OPEN_PARENT_FOLDER, OnOpenParentFolder)
        ON_COMMAND(ID_SWAPPANES_SWAP12, OnViewSwapPanes12)
        ON_COMMAND(ID_SWAPPANES_SWAP23, OnViewSwapPanes23)
        ON_COMMAND(ID_SWAPPANES_SWAP13, OnViewSwapPanes13)
@@ -268,6 +269,15 @@ CCrystalTextBuffer *CMergeEditView::LocateTextBuffer()
        return GetDocument()->m_ptBuf[m_nThisPane].get();
 }
 
+void CMergeEditView::CopyProperties(CCrystalTextView* pSource)
+{
+       __super::CopyProperties(pSource);
+       auto pSourceEditView = dynamic_cast<decltype(this)>(pSource);
+       if (!pSourceEditView)
+               return;
+       m_bChangedSchemeManually = pSourceEditView->m_bChangedSchemeManually;
+}
+
 /**
  * @brief Update any resources necessary after a GUI language change
  */
@@ -300,9 +310,8 @@ CString CMergeEditView::GetLineText(int idx)
  */
 CString CMergeEditView::GetSelectedText()
 {
-       CPoint ptStart, ptEnd;
        CString strText;
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
        if (ptStart != ptEnd)
                GetTextWithoutEmptys(ptStart.y, ptStart.x, ptEnd.y, ptEnd.x, strText);
        return strText;
@@ -415,8 +424,7 @@ void CMergeEditView::GetFullySelectedDiffs(int & firstDiff, int & lastDiff, int
                return;
 
        int firstLine, lastLine;
-       CPoint ptStart, ptEnd;
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
        if (pptStart != nullptr)
                ptStart = *pptStart;
        if (pptEnd != nullptr)
@@ -538,8 +546,7 @@ void CMergeEditView::GetSelectedDiffs(int & firstDiff, int & lastDiff)
                return;
 
        int firstLine, lastLine;
-       CPoint ptStart, ptEnd;
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
        firstLine = ptStart.y;
        lastLine = ptEnd.y;
 
@@ -568,8 +575,7 @@ std::map<int, std::vector<int>> CMergeEditView::GetColumnSelectedWordDiffIndice(
        CMergeDoc *pDoc = GetDocument();
        std::map<int, std::vector<int>> ret;
        std::map<int, std::vector<int> *> list;
-       CPoint ptStart, ptEnd;
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
        for (int nLine = ptStart.y; nLine <= ptEnd.y; ++nLine)
        {
                if (pDoc->m_diffList.LineToDiff(nLine) != -1)
@@ -1163,8 +1169,7 @@ void CMergeEditView::OnUpdateCurdiff(CCmdUI* pCmdUI)
 void CMergeEditView::OnEditCopy()
 {
        CMergeDoc * pDoc = GetDocument();
-       CPoint ptSelStart, ptSelEnd;
-       GetSelection(ptSelStart, ptSelEnd);
+       auto [ptSelStart, ptSelEnd] = GetSelection();
 
        // Nothing selected
        if (ptSelStart == ptSelEnd)
@@ -1201,9 +1206,8 @@ void CMergeEditView::OnEditCut()
        if (!QueryEditable())
                return;
 
-       CPoint ptSelStart, ptSelEnd;
        CMergeDoc * pDoc = GetDocument();
-       GetSelection(ptSelStart, ptSelEnd);
+       auto [ptSelStart, ptSelEnd] = GetSelection();
 
        // Nothing selected
        if (ptSelStart == ptSelEnd)
@@ -1950,8 +1954,7 @@ void CMergeEditView::OnX2Y(int srcPane, int dstPane, bool selectedLineOnly)
                }
        }
 
-       CPoint ptStart, ptEnd;
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
        if (IsSelection() || pDoc->EqualCurrentWordDiff(srcPane, ptStart, ptEnd))
        {
                if (!m_bRectangularSelection)
@@ -2023,8 +2026,7 @@ void CMergeEditView::OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI)
                // If one or more diffs inside selection OR
                // there is an active diff OR
                // cursor is inside diff
-               CPoint ptStart, ptEnd;
-               GetSelection(ptStart, ptEnd);
+               auto [ptStart, ptEnd] = GetSelection();
                if (IsSelection() || GetDocument()->EqualCurrentWordDiff(m_nThisPane, ptStart, ptEnd))
                {
                        if (m_bCurrentLineIsDiff || (m_pTextBuffer->GetLineFlags(m_ptSelStart.y) & LF_NONTRIVIAL_DIFF) != 0)
@@ -2345,7 +2347,7 @@ void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText, size_t cchTex
        pDoc->UpdateHeaderPath(m_nThisPane);
 
        // If automatic rescan enabled, rescan after edit events
-       if (m_bAutomaticRescan)
+       if (pDoc->GetAutomaticRescan())
        {
                // keep document up to date     
                // (Re)start timer to rescan only when user edits text
@@ -3470,8 +3472,6 @@ void CMergeEditView::RefreshOptions()
        RENDERING_MODE nRenderingMode = static_cast<RENDERING_MODE>(GetOptionsMgr()->GetInt(OPT_RENDERING_MODE));
        SetRenderingMode(nRenderingMode);
 
-       m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
-
        if (GetOptionsMgr()->GetInt(OPT_TAB_TYPE) == 0)
                SetInsertTabs(true);
        else
@@ -3492,6 +3492,7 @@ void CMergeEditView::RefreshOptions()
                        SetTextType(def->type);
                else
                        SetTextType(CrystalLineParser::SRC_PLAIN);
+               SetDisableBSAtSOL(false);
        }
 
        SetWordWrapping(GetOptionsMgr()->GetBool(OPT_WORDWRAP));
@@ -3808,14 +3809,12 @@ void CMergeEditView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
  */
 void CMergeEditView::OnEditCopyLineNumbers()
 {
-       CPoint ptStart;
-       CPoint ptEnd;
        CString strText;
        CString strLine;
        CString strNumLine;
 
        CMergeDoc *pDoc = GetDocument();
-       GetSelection(ptStart, ptEnd);
+       auto [ptStart, ptEnd] = GetSelection();
 
        // Get last selected line (having widest linenumber)
        int line = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(ptEnd.y);
@@ -3860,13 +3859,7 @@ void CMergeEditView::OnOpenFile()
        String sFileName = pDoc->m_filePaths[m_nThisPane];
        if (sFileName.empty())
                return;
-       HINSTANCE rtn = ShellExecute(::GetDesktopWindow(), _T("edit"), sFileName.c_str(),
-                       0, 0, SW_SHOWNORMAL);
-       if (reinterpret_cast<uintptr_t>(rtn) == SE_ERR_NOASSOC)
-               rtn = ShellExecute(::GetDesktopWindow(), _T("open"), sFileName.c_str(),
-                        0, 0, SW_SHOWNORMAL);
-       if (reinterpret_cast<uintptr_t>(rtn) == SE_ERR_NOASSOC)
-               OnOpenFileWith();
+       shell::Edit(sFileName.c_str());
 }
 
 /**
@@ -3880,14 +3873,7 @@ void CMergeEditView::OnOpenFileWith()
        String sFileName = pDoc->m_filePaths[m_nThisPane];
        if (sFileName.empty())
                return;
-
-       CString sysdir;
-       if (!GetSystemDirectory(sysdir.GetBuffer(MAX_PATH), MAX_PATH))
-               return;
-       sysdir.ReleaseBuffer();
-       CString arg = (CString)_T("shell32.dll,OpenAs_RunDLL ") + sFileName.c_str();
-       ShellExecute(::GetDesktopWindow(), 0, _T("RUNDLL32.EXE"), arg,
-                       sysdir, SW_SHOWNORMAL);
+       shell::OpenWith(sFileName.c_str());
 }
 
 /**
@@ -3907,6 +3893,21 @@ void CMergeEditView::OnOpenFileWithEditor()
 }
 
 /**
+ * @brief Open parent folder of active file
+ */
+void CMergeEditView::OnOpenParentFolder()
+{
+       CMergeDoc * pDoc = GetDocument();
+       ASSERT(pDoc != nullptr);
+
+       String sFileName = pDoc->m_filePaths[m_nThisPane];
+       if (sFileName.empty())
+               return;
+
+       shell::OpenParentFolder(sFileName.c_str());
+}
+
+/**
  * @brief Force repaint of the location pane.
  */
 void CMergeEditView::RepaintLocationPane()
@@ -4288,9 +4289,6 @@ void CMergeEditView::DocumentsLoaded()
                SetTopMargin(false);
        }
 
-       // Enable/disable automatic rescan (rescanning after edit)
-       EnableRescan(GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN));
-
        // SetTextType will revert to language dependent defaults for tab
        SetTabSize(GetOptionsMgr()->GetInt(OPT_TAB_SIZE));
        SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
@@ -4504,7 +4502,9 @@ void CMergeEditView::ZoomText(short amount)
 
        if ( amount == 0)
        {
-               nPointSize = -MulDiv(GetOptionsMgr()->GetInt(OPT_FONT_FILECMP + OPT_FONT_HEIGHT), 72, nLogPixelsY);
+               nPointSize = GetOptionsMgr()->GetInt(OPT_FONT_FILECMP + OPT_FONT_POINTSIZE);
+               if (nPointSize ==  0)
+                       nPointSize = -MulDiv(GetOptionsMgr()->GetInt(OPT_FONT_FILECMP + OPT_FONT_HEIGHT), 72, nLogPixelsY);
        }
 
        nPointSize += amount;
@@ -4637,8 +4637,7 @@ void CMergeEditView::ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll /*= F
                if (EnsureInDiff(pt))
                        SetCursorPos(pt);
 
-               CPoint ptSelStart, ptSelEnd;
-               GetSelection(ptSelStart, ptSelEnd);
+               auto [ptSelStart, ptSelEnd] = GetSelection();
                if (EnsureInDiff(ptSelStart) || EnsureInDiff(ptSelEnd))
                        SetSelection(ptSelStart, ptSelEnd);
        }