OSDN Git Service

Issue 20: Add To Ignore from Commit dialog not working
[tortoisegit/TortoiseGitJp.git] / src / Git / GitStatusListCtrl.cpp
index ff45d93..a32d859 100644 (file)
@@ -2792,6 +2792,354 @@ void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
                                }\r
                        }\r
                        break;\r
+\r
+                       case IDSVNLC_IGNORE:\r
+                       {\r
+                               CTGitPathList ignorelist;\r
+                               //std::vector<CString> toremove;\r
+                               FillListOfSelectedItemPaths(ignorelist, true);\r
+                               SetRedraw(FALSE);\r
+\r
+                               if(!CAppUtils::IgnoreFile(ignorelist,false))\r
+                                       break;\r
+\r
+                               for(int i=0;i<ignorelist.GetCount();i++)\r
+                               {\r
+                                       int nListboxEntries = GetItemCount();\r
+                                       for (int nItem=0; nItem<nListboxEntries; ++nItem)\r
+                                       {\r
+                                               CTGitPath *path=(CTGitPath*)GetItemData(nItem);\r
+                                               if (path->GetGitPathString()==ignorelist[i].GetGitPathString())\r
+                                               {\r
+                                                       RemoveListEntry(nItem);\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               SetRedraw(TRUE);\r
+                       }\r
+#if 0\r
+                                       CTSVNPathList ignorelist;\r
+                                       std::vector<CString> toremove;\r
+                                       FillListOfSelectedItemPaths(ignorelist, true);\r
+                                       SetRedraw(FALSE);\r
+                                       for (int j=0; j<ignorelist.GetCount(); ++j)\r
+                                       {\r
+                                               int nListboxEntries = GetItemCount();\r
+                                               for (int i=0; i<nListboxEntries; ++i)\r
+                                               {\r
+                                                       if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))\r
+                                                       {\r
+                                                               selIndex = i;\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                               CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());\r
+                                               CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();\r
+                                               SVNProperties props(parentfolder, SVNRev::REV_WC, false);\r
+                                               CStringA value;\r
+                                               for (int i=0; i<props.GetCount(); i++)\r
+                                               {\r
+                                                       CString propname(props.GetItemName(i).c_str());\r
+                                                       if (propname.CompareNoCase(_T("git:ignore"))==0)\r
+                                                       {\r
+                                                               stdstring stemp;\r
+                                                               // treat values as normal text even if they're not\r
+                                                               value = (char *)props.GetItemValue(i).c_str();\r
+                                                       }\r
+                                               }\r
+                                               if (value.IsEmpty())\r
+                                                       value = name;\r
+                                               else\r
+                                               {\r
+                                                       value = value.Trim("\n\r");\r
+                                                       value += "\n";\r
+                                                       value += name;\r
+                                                       value.Remove('\r');\r
+                                               }\r
+                                               if (!props.Add(_T("git:ignore"), (LPCSTR)value))\r
+                                               {\r
+                                                       CString temp;\r
+                                                       temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);\r
+                                                       CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);\r
+                                                       break;\r
+                                               }\r
+                                               if (GetCheck(selIndex))\r
+                                                       m_nSelected--;\r
+                                               m_nTotal--;\r
+\r
+                                               // now, if we ignored a folder, remove all its children\r
+                                               if (ignorelist[j].IsDirectory())\r
+                                               {\r
+                                                       for (int i=0; i<(int)m_arListArray.size(); ++i)\r
+                                                       {\r
+                                                               FileEntry * entry = GetListEntry(i);\r
+                                                               if (entry->status == git_wc_status_unversioned)\r
+                                                               {\r
+                                                                       if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))\r
+                                                                       {\r
+                                                                               entry->status = git_wc_status_ignored;\r
+                                                                               entry->textstatus = git_wc_status_ignored;\r
+                                                                               if (GetCheck(i))\r
+                                                                                       m_nSelected--;\r
+                                                                               toremove.push_back(entry->GetPath().GetSVNPathString());\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+\r
+                                               CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;\r
+\r
+                                               FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];\r
+                                               if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items\r
+                                                       toremove.push_back(entry->GetPath().GetSVNPathString());\r
+\r
+                                               if (!m_bIgnoreRemoveOnly)\r
+                                               {\r
+                                                       SVNStatus status;\r
+                                                       git_wc_status2_t * s;\r
+                                                       CTSVNPath gitPath;\r
+                                                       s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);\r
+                                                       // first check if the folder isn't already present in the list\r
+                                                       bool bFound = false;\r
+                                                       nListboxEntries = GetItemCount();\r
+                                                       for (int i=0; i<nListboxEntries; ++i)\r
+                                                       {\r
+                                                               FileEntry * entry = GetListEntry(i);\r
+                                                               if (entry->path.IsEquivalentTo(gitPath))\r
+                                                               {\r
+                                                                       bFound = true;\r
+                                                                       break;\r
+                                                               }\r
+                                                       }\r
+                                                       if (!bFound)\r
+                                                       {\r
+                                                               if (s!=0)\r
+                                                               {\r
+                                                                       FileEntry * entry = new FileEntry();\r
+                                                                       entry->path = gitPath;\r
+                                                                       entry->basepath = basepath;\r
+                                                                       entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);\r
+                                                                       entry->textstatus = s->text_status;\r
+                                                                       entry->propstatus = s->prop_status;\r
+                                                                       entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);\r
+                                                                       entry->remotetextstatus = s->repos_text_status;\r
+                                                                       entry->remotepropstatus = s->repos_prop_status;\r
+                                                                       entry->inunversionedfolder = FALSE;\r
+                                                                       entry->checked = true;\r
+                                                                       entry->inexternal = false;\r
+                                                                       entry->direct = false;\r
+                                                                       entry->isfolder = true;\r
+                                                                       entry->last_commit_date = 0;\r
+                                                                       entry->last_commit_rev = 0;\r
+                                                                       entry->remoterev = 0;\r
+                                                                       if (s->entry)\r
+                                                                       {\r
+                                                                               if (s->entry->url)\r
+                                                                               {\r
+                                                                                       entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));\r
+                                                                               }\r
+                                                                       }\r
+                                                                       if (s->entry && s->entry->present_props)\r
+                                                                       {\r
+                                                                               entry->present_props = s->entry->present_props;\r
+                                                                       }\r
+                                                                       m_arStatusArray.push_back(entry);\r
+                                                                       m_arListArray.push_back(m_arStatusArray.size()-1);\r
+                                                                       AddEntry(entry, langID, GetItemCount());\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)\r
+                                       {\r
+                                               int nListboxEntries = GetItemCount();\r
+                                               for (int i=0; i<nListboxEntries; ++i)\r
+                                               {\r
+                                                       if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)\r
+                                                       {\r
+                                                               RemoveListEntry(i);\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       SetRedraw(TRUE);\r
+                               }\r
+#endif\r
+                               break;\r
+                       case IDSVNLC_IGNOREMASK:\r
+                               {\r
+                                       CString common;\r
+                                       CString ext=filepath->GetFileExtension();\r
+                                       CTGitPathList ignorelist;\r
+                                       FillListOfSelectedItemPaths(ignorelist, true);\r
+                                       SetRedraw(FALSE);\r
+\r
+                                       CAppUtils::IgnoreFile(ignorelist,true);\r
+                                       common=ignorelist.GetCommonRoot().GetGitPathString();\r
+\r
+                                       for (int i=0; i< GetItemCount(); ++i)\r
+                                       {\r
+                                               CTGitPath *path=(CTGitPath*)GetItemData(i);\r
+                                               if(!( path->m_Action & CTGitPath::LOGACTIONS_UNVER))\r
+                                                       continue;\r
+                                               if( path->GetGitPathString().Left(common.GetLength()) == common )\r
+                                               {\r
+                                                       if (path->GetFileExtension()==ext)\r
+                                                       {\r
+                                                               RemoveListEntry(i);\r
+                                                               i--; // remove index i at item, new one will replace. \r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       \r
+                                       SetRedraw(TRUE);\r
+                               }\r
+#if 0\r
+                                       std::set<CTSVNPath> parentlist;\r
+                                       for (int i=0; i<ignorelist.GetCount(); ++i)\r
+                                       {\r
+                                               parentlist.insert(ignorelist[i].GetContainingDirectory());\r
+                                       }\r
+                                       std::set<CTSVNPath>::iterator it;\r
+                                       std::vector<CString> toremove;\r
+                                       \r
+                                       for (it = parentlist.begin(); it != parentlist.end(); ++it)\r
+                                       {\r
+                                               CTSVNPath parentFolder = (*it).GetDirectory();\r
+                                               SVNProperties props(parentFolder, SVNRev::REV_WC, false);\r
+                                               CStringA value;\r
+                                               for (int i=0; i<props.GetCount(); i++)\r
+                                               {\r
+                                                       CString propname(props.GetItemName(i).c_str());\r
+                                                       if (propname.CompareNoCase(_T("git:ignore"))==0)\r
+                                                       {\r
+                                                               stdstring stemp;\r
+                                                               // treat values as normal text even if they're not\r
+                                                               value = (char *)props.GetItemValue(i).c_str();\r
+                                                       }\r
+                                               }\r
+                                               if (value.IsEmpty())\r
+                                                       value = name;\r
+                                               else\r
+                                               {\r
+                                                       value = value.Trim("\n\r");\r
+                                                       value += "\n";\r
+                                                       value += name;\r
+                                                       value.Remove('\r');\r
+                                               }\r
+                                               if (!props.Add(_T("git:ignore"), (LPCSTR)value))\r
+                                               {\r
+                                                       CString temp;\r
+                                                       temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);\r
+                                                       CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       CTSVNPath basepath;\r
+                                                       int nListboxEntries = GetItemCount();\r
+                                                       for (int i=0; i<nListboxEntries; ++i)\r
+                                                       {\r
+                                                               FileEntry * entry = GetListEntry(i);\r
+                                                               ASSERT(entry != NULL);\r
+                                                               if (entry == NULL)\r
+                                                                       continue;\r
+                                                               if (basepath.IsEmpty())\r
+                                                                       basepath = entry->basepath;\r
+                                                               // since we ignored files with a mask (e.g. *.exe)\r
+                                                               // we have to find find all files in the same\r
+                                                               // folder (IsAncestorOf() returns TRUE for _all_ children,\r
+                                                               // not just the immediate ones) which match the\r
+                                                               // mask and remove them from the list too.\r
+                                                               if ((entry->status == git_wc_status_unversioned)&&(parentFolder.IsAncestorOf(entry->path)))\r
+                                                               {\r
+                                                                       CString f = entry->path.GetSVNPathString();\r
+                                                                       if (f.Mid(parentFolder.GetSVNPathString().GetLength()).Find('/')<=0)\r
+                                                                       {\r
+                                                                               if (CStringUtils::WildCardMatch(name, f))\r
+                                                                               {\r
+                                                                                       if (GetCheck(i))\r
+                                                                                               m_nSelected--;\r
+                                                                                       m_nTotal--;\r
+                                                                                       toremove.push_back(f);\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                                       if (!m_bIgnoreRemoveOnly)\r
+                                                       {\r
+                                                               SVNStatus status;\r
+                                                               git_wc_status2_t * s;\r
+                                                               CTSVNPath gitPath;\r
+                                                               s = status.GetFirstFileStatus(parentFolder, gitPath, false, git_depth_empty);\r
+                                                               if (s!=0)\r
+                                                               {\r
+                                                                       // first check if the folder isn't already present in the list\r
+                                                                       bool bFound = false;\r
+                                                                       for (int i=0; i<nListboxEntries; ++i)\r
+                                                                       {\r
+                                                                               FileEntry * entry = GetListEntry(i);\r
+                                                                               if (entry->path.IsEquivalentTo(gitPath))\r
+                                                                               {\r
+                                                                                       bFound = true;\r
+                                                                                       break;\r
+                                                                               }\r
+                                                                       }\r
+                                                                       if (!bFound)\r
+                                                                       {\r
+                                                                               FileEntry * entry = new FileEntry();\r
+                                                                               entry->path = gitPath;\r
+                                                                               entry->basepath = basepath;\r
+                                                                               entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);\r
+                                                                               entry->textstatus = s->text_status;\r
+                                                                               entry->propstatus = s->prop_status;\r
+                                                                               entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);\r
+                                                                               entry->remotetextstatus = s->repos_text_status;\r
+                                                                               entry->remotepropstatus = s->repos_prop_status;\r
+                                                                               entry->inunversionedfolder = false;\r
+                                                                               entry->checked = true;\r
+                                                                               entry->inexternal = false;\r
+                                                                               entry->direct = false;\r
+                                                                               entry->isfolder = true;\r
+                                                                               entry->last_commit_date = 0;\r
+                                                                               entry->last_commit_rev = 0;\r
+                                                                               entry->remoterev = 0;\r
+                                                                               if (s->entry)\r
+                                                                               {\r
+                                                                                       if (s->entry->url)\r
+                                                                                       {\r
+                                                                                               entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));\r
+                                                                                       }\r
+                                                                               }\r
+                                                                               if (s->entry && s->entry->present_props)\r
+                                                                               {\r
+                                                                                       entry->present_props = s->entry->present_props;\r
+                                                                               }\r
+                                                                               m_arStatusArray.push_back(entry);\r
+                                                                               m_arListArray.push_back(m_arStatusArray.size()-1);\r
+                                                                               AddEntry(entry, langID, GetItemCount());\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)\r
+                                       {\r
+                                               int nListboxEntries = GetItemCount();\r
+                                               for (int i=0; i<nListboxEntries; ++i)\r
+                                               {\r
+                                                       if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)\r
+                                                       {\r
+                                                               RemoveListEntry(i);\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       SetRedraw(TRUE);\r
+                               }\r
+#endif\r
+                               break;\r
+                       \r
 #if 0\r
                        case IDSVNLC_COPY:\r
                                CopySelectedEntriesToClipboard(0);\r
@@ -3334,155 +3682,6 @@ void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point)
                                        SetRedraw(TRUE);\r
                                }\r
                                break;\r
-                       case IDSVNLC_IGNORE:\r
-                               {\r
-                                       CTSVNPathList ignorelist;\r
-                                       std::vector<CString> toremove;\r
-                                       FillListOfSelectedItemPaths(ignorelist, true);\r
-                                       SetRedraw(FALSE);\r
-                                       for (int j=0; j<ignorelist.GetCount(); ++j)\r
-                                       {\r
-                                               int nListboxEntries = GetItemCount();\r
-                                               for (int i=0; i<nListboxEntries; ++i)\r
-                                               {\r
-                                                       if (GetListEntry(i)->GetPath().IsEquivalentTo(ignorelist[j]))\r
-                                                       {\r
-                                                               selIndex = i;\r
-                                                               break;\r
-                                                       }\r
-                                               }\r
-                                               CString name = CPathUtils::PathPatternEscape(ignorelist[j].GetFileOrDirectoryName());\r
-                                               CTSVNPath parentfolder = ignorelist[j].GetContainingDirectory();\r
-                                               SVNProperties props(parentfolder, SVNRev::REV_WC, false);\r
-                                               CStringA value;\r
-                                               for (int i=0; i<props.GetCount(); i++)\r
-                                               {\r
-                                                       CString propname(props.GetItemName(i).c_str());\r
-                                                       if (propname.CompareNoCase(_T("git:ignore"))==0)\r
-                                                       {\r
-                                                               stdstring stemp;\r
-                                                               // treat values as normal text even if they're not\r
-                                                               value = (char *)props.GetItemValue(i).c_str();\r
-                                                       }\r
-                                               }\r
-                                               if (value.IsEmpty())\r
-                                                       value = name;\r
-                                               else\r
-                                               {\r
-                                                       value = value.Trim("\n\r");\r
-                                                       value += "\n";\r
-                                                       value += name;\r
-                                                       value.Remove('\r');\r
-                                               }\r
-                                               if (!props.Add(_T("git:ignore"), (LPCSTR)value))\r
-                                               {\r
-                                                       CString temp;\r
-                                                       temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);\r
-                                                       CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseSVN"), MB_ICONERROR);\r
-                                                       break;\r
-                                               }\r
-                                               if (GetCheck(selIndex))\r
-                                                       m_nSelected--;\r
-                                               m_nTotal--;\r
-\r
-                                               // now, if we ignored a folder, remove all its children\r
-                                               if (ignorelist[j].IsDirectory())\r
-                                               {\r
-                                                       for (int i=0; i<(int)m_arListArray.size(); ++i)\r
-                                                       {\r
-                                                               FileEntry * entry = GetListEntry(i);\r
-                                                               if (entry->status == git_wc_status_unversioned)\r
-                                                               {\r
-                                                                       if (!ignorelist[j].IsEquivalentTo(entry->GetPath())&&(ignorelist[j].IsAncestorOf(entry->GetPath())))\r
-                                                                       {\r
-                                                                               entry->status = git_wc_status_ignored;\r
-                                                                               entry->textstatus = git_wc_status_ignored;\r
-                                                                               if (GetCheck(i))\r
-                                                                                       m_nSelected--;\r
-                                                                               toremove.push_back(entry->GetPath().GetSVNPathString());\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-\r
-                                               CTSVNPath basepath = m_arStatusArray[m_arListArray[selIndex]]->basepath;\r
-\r
-                                               FileEntry * entry = m_arStatusArray[m_arListArray[selIndex]];\r
-                                               if ( entry->status == git_wc_status_unversioned ) // keep "deleted" items\r
-                                                       toremove.push_back(entry->GetPath().GetSVNPathString());\r
-\r
-                                               if (!m_bIgnoreRemoveOnly)\r
-                                               {\r
-                                                       SVNStatus status;\r
-                                                       git_wc_status2_t * s;\r
-                                                       CTSVNPath gitPath;\r
-                                                       s = status.GetFirstFileStatus(parentfolder, gitPath, false, git_depth_empty);\r
-                                                       // first check if the folder isn't already present in the list\r
-                                                       bool bFound = false;\r
-                                                       nListboxEntries = GetItemCount();\r
-                                                       for (int i=0; i<nListboxEntries; ++i)\r
-                                                       {\r
-                                                               FileEntry * entry = GetListEntry(i);\r
-                                                               if (entry->path.IsEquivalentTo(gitPath))\r
-                                                               {\r
-                                                                       bFound = true;\r
-                                                                       break;\r
-                                                               }\r
-                                                       }\r
-                                                       if (!bFound)\r
-                                                       {\r
-                                                               if (s!=0)\r
-                                                               {\r
-                                                                       FileEntry * entry = new FileEntry();\r
-                                                                       entry->path = gitPath;\r
-                                                                       entry->basepath = basepath;\r
-                                                                       entry->status = SVNStatus::GetMoreImportant(s->text_status, s->prop_status);\r
-                                                                       entry->textstatus = s->text_status;\r
-                                                                       entry->propstatus = s->prop_status;\r
-                                                                       entry->remotestatus = SVNStatus::GetMoreImportant(s->repos_text_status, s->repos_prop_status);\r
-                                                                       entry->remotetextstatus = s->repos_text_status;\r
-                                                                       entry->remotepropstatus = s->repos_prop_status;\r
-                                                                       entry->inunversionedfolder = FALSE;\r
-                                                                       entry->checked = true;\r
-                                                                       entry->inexternal = false;\r
-                                                                       entry->direct = false;\r
-                                                                       entry->isfolder = true;\r
-                                                                       entry->last_commit_date = 0;\r
-                                                                       entry->last_commit_rev = 0;\r
-                                                                       entry->remoterev = 0;\r
-                                                                       if (s->entry)\r
-                                                                       {\r
-                                                                               if (s->entry->url)\r
-                                                                               {\r
-                                                                                       entry->url = CUnicodeUtils::GetUnicode(CPathUtils::PathUnescape(s->entry->url));\r
-                                                                               }\r
-                                                                       }\r
-                                                                       if (s->entry && s->entry->present_props)\r
-                                                                       {\r
-                                                                               entry->present_props = s->entry->present_props;\r
-                                                                       }\r
-                                                                       m_arStatusArray.push_back(entry);\r
-                                                                       m_arListArray.push_back(m_arStatusArray.size()-1);\r
-                                                                       AddEntry(entry, langID, GetItemCount());\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       for (std::vector<CString>::iterator it = toremove.begin(); it != toremove.end(); ++it)\r
-                                       {\r
-                                               int nListboxEntries = GetItemCount();\r
-                                               for (int i=0; i<nListboxEntries; ++i)\r
-                                               {\r
-                                                       if (GetListEntry(i)->path.GetSVNPathString().Compare(*it)==0)\r
-                                                       {\r
-                                                               RemoveListEntry(i);\r
-                                                               break;\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       SetRedraw(TRUE);\r
-                               }\r
-                               break;\r
                        case IDSVNLC_EDITCONFLICT:\r
                                SVNDiff::StartConflictEditor(filepath);\r
                                break;\r
@@ -4371,9 +4570,13 @@ BOOL CGitStatusListCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
 \r
 void CGitStatusListCtrl::RemoveListEntry(int index)\r
 {\r
-#if 0\r
+\r
        Locker lock(m_critSec);\r
        DeleteItem(index);\r
+\r
+       m_arStatusArray.erase(m_arStatusArray.begin()+index);\r
+\r
+#if 0\r
        delete m_arStatusArray[m_arListArray[index]];\r
        m_arStatusArray.erase(m_arStatusArray.begin()+m_arListArray[index]);\r
        m_arListArray.erase(m_arListArray.begin()+index);\r