From 52648444355acfe7e65caaf3fb3c16b8e83f6a93 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Fri, 24 Jan 2014 23:24:19 +0100 Subject: [PATCH] Add bugtraq regex test dialog Based on code of TortoiseSVN. Signed-off-by: Sven Strickroth --- Languages/Tortoise.pot | 24 +++++ src/Resources/TortoiseProcENG.rc | 27 ++++++ src/TortoiseProc/BugtraqRegexTestDlg.cpp | 106 +++++++++++++++++++++ src/TortoiseProc/BugtraqRegexTestDlg.h | 55 +++++++++++ .../Settings/SettingsBugtraqConfig.cpp | 26 ++++- src/TortoiseProc/Settings/SettingsBugtraqConfig.h | 4 +- src/TortoiseProc/TortoiseProc.vcxproj | 2 + src/TortoiseProc/TortoiseProc.vcxproj.filters | 6 ++ src/TortoiseProc/resource.h | 10 +- src/Utils/MiscUI/SciEdit.cpp | 10 ++ src/Utils/MiscUI/SciEdit.h | 1 + 11 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 src/TortoiseProc/BugtraqRegexTestDlg.cpp create mode 100644 src/TortoiseProc/BugtraqRegexTestDlg.h diff --git a/Languages/Tortoise.pot b/Languages/Tortoise.pot index 1ec4b92d9..5df42e526 100644 --- a/Languages/Tortoise.pot +++ b/Languages/Tortoise.pot @@ -2208,6 +2208,10 @@ msgstr "" msgid "Bug-ID" msgstr "" +#. Resource IDs: (1578) +msgid "Bug-ID e&xpression:" +msgstr "" + #. Resource IDs: (1119) msgid "Bug-ID/Issue-Nr:" msgstr "" @@ -2220,6 +2224,10 @@ msgstr "" msgid "BugTraq" msgstr "" +#. Resource IDs: (327) +msgid "Bugtraq Regex Tester - TortoiseGit" +msgstr "" + #. Resource IDs: (16132) msgid "Button Appearance" msgstr "" @@ -5797,6 +5805,10 @@ msgstr "" msgid "Message onl&y" msgstr "" +#. Resource IDs: (1579) +msgid "Message part &expression:" +msgstr "" + #. Resource IDs: (116) msgid "Messages" msgstr "" @@ -7592,6 +7604,14 @@ msgstr "" msgid "Same commit time" msgstr "" +#. Resource IDs: (93) +msgid "Sample log message to test the bugtraq: regex strings.\n\nTesting mentions of issues inside a text: Mention single issue #55. Mention issues #77, #78, and #78. Mention more issues #123, #124 and #125 and some more separate ones: Issue #45, issue #46 and issue #47.\n\n\nUpdate issue #101\nFixes issue #202\nFixed issue #123\nResolves issue #88.\nCloses issue #99.\n" +msgstr "" + +#. Resource IDs: (1612) +msgid "Sample text:" +msgstr "" + #. Resource IDs: (156) msgid "Save" msgstr "" @@ -8648,6 +8668,10 @@ msgstr "" msgid "Temp files (including Gravatar images)" msgstr "" +#. Resource IDs: (1787) +msgid "Test" +msgstr "" + #. Resource IDs: (219) msgid "Test Only" msgstr "" diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index b195ff364..b43ea5e80 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -964,6 +964,7 @@ BEGIN COMBOBOX IDC_BUGTRAQ_NUMBER,113,128,63,15,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP EDITTEXT IDC_BUGTRAQ_LOGREGEX,113,144,170,25,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN CONTROL "inherit",IDC_CHECK_INHERIT_BTREGEXP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,113,172,60,10 + PUSHBUTTON "Test",IDC_TESTBUGTRAQREGEXBUTTON,231,171,52,12 LTEXT "bugtraq.url",IDC_STATIC,14,44,89,8 LTEXT "bugtraq.warningifnoissue",IDC_STATIC,14,60,91,10 LTEXT "bugtraq.message",IDC_STATIC,14,77,86,10 @@ -1948,6 +1949,21 @@ BEGIN COMBOBOX IDC_COMBO_SETTINGS_SAFETO,65,211,103,15,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP END +IDD_BUGTRAQREGEXTESTER DIALOGEX 0, 0, 317, 188 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +CAPTION "Bugtraq Regex Tester - TortoiseGit" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + LTEXT "Sample text:",IDC_SAMPLELABEL,7,7,303,8 + CONTROL "Scintilla",IDC_LOGMESSAGE,"Scintilla",WS_TABSTOP,7,18,303,100,WS_EX_STATICEDGE + LTEXT "Message part &expression:",IDC_REGEXMSGLABEL,7,124,74,18 + EDITTEXT IDC_BUGTRAQLOGREGEX2,88,123,222,14,ES_AUTOHSCROLL + LTEXT "Bug-ID e&xpression:",IDC_REGEXIDLABEL,7,144,74,17 + EDITTEXT IDC_BUGTRAQLOGREGEX1,88,144,222,14,ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,205,167,50,14 + PUSHBUTTON "Cancel",IDCANCEL,260,167,50,14 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -2815,6 +2831,15 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 224 END + + IDD_BUGTRAQREGEXTESTER, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 310 + VERTGUIDE, 88 + TOPMARGIN, 7 + BOTTOMMARGIN, 181 + END END #endif // APSTUDIO_INVOKED @@ -4337,6 +4362,8 @@ BEGIN IDS_LOG_FILTER_TOGGLE "Toggle checked filters" IDS_WARN_GITINIT_SPECIALFOLDER "The target folder \n%s\nis a special folder and is not supposed to be a repository root!\nAre you sure you want to initialize a git repository inside that folder?" + IDS_SAMPLEBUGTRAQTESTMSG + "Sample log message to test the bugtraq: regex strings.\n\nTesting mentions of issues inside a text: Mention single issue #55. Mention issues #77, #78, and #78. Mention more issues #123, #124 and #125 and some more separate ones: Issue #45, issue #46 and issue #47.\n\n\nUpdate issue #101\nFixes issue #202\nFixed issue #123\nResolves issue #88.\nCloses issue #99.\n" END STRINGTABLE diff --git a/src/TortoiseProc/BugtraqRegexTestDlg.cpp b/src/TortoiseProc/BugtraqRegexTestDlg.cpp new file mode 100644 index 000000000..5606bb5ae --- /dev/null +++ b/src/TortoiseProc/BugtraqRegexTestDlg.cpp @@ -0,0 +1,106 @@ +// TortoiseGit - a Windows shell extension for easy version control + +// Copyright (C) 2014 - TortoiseGit +// Copyright (C) 2011 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#include "stdafx.h" +#include "TortoiseProc.h" +#include "BugtraqRegexTestDlg.h" +#include "afxdialogex.h" +#include "AppUtils.h" +#include "ProjectProperties.h" + +// CBugtraqRegexTestDlg dialog + +IMPLEMENT_DYNAMIC(CBugtraqRegexTestDlg, CResizableStandAloneDialog) + +CBugtraqRegexTestDlg::CBugtraqRegexTestDlg(CWnd* pParent /*=nullptr*/) + : CResizableStandAloneDialog(CBugtraqRegexTestDlg::IDD, pParent) +{ +} + +CBugtraqRegexTestDlg::~CBugtraqRegexTestDlg() +{ +} + +void CBugtraqRegexTestDlg::DoDataExchange(CDataExchange* pDX) +{ + CResizableStandAloneDialog::DoDataExchange(pDX); + DDX_Text(pDX, IDC_BUGTRAQLOGREGEX1, m_sBugtraqRegex1); + DDX_Text(pDX, IDC_BUGTRAQLOGREGEX2, m_sBugtraqRegex2); + DDX_Control(pDX, IDC_BUGTRAQLOGREGEX1, m_BugtraqRegex1); + DDX_Control(pDX, IDC_BUGTRAQLOGREGEX2, m_BugtraqRegex2); + DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage); +} + +BEGIN_MESSAGE_MAP(CBugtraqRegexTestDlg, CResizableStandAloneDialog) + ON_EN_CHANGE(IDC_BUGTRAQLOGREGEX1, &CBugtraqRegexTestDlg::OnEnChangeBugtraqlogregex1) + ON_EN_CHANGE(IDC_BUGTRAQLOGREGEX2, &CBugtraqRegexTestDlg::OnEnChangeBugtraqlogregex2) +END_MESSAGE_MAP() + +void CBugtraqRegexTestDlg::OnEnChangeBugtraqlogregex1() +{ + UpdateLogControl(); +} + +void CBugtraqRegexTestDlg::OnEnChangeBugtraqlogregex2() +{ + UpdateLogControl(); +} + +BOOL CBugtraqRegexTestDlg::OnInitDialog() +{ + CResizableStandAloneDialog::OnInitDialog(); + CAppUtils::MarkWindowAsUnpinnable(m_hWnd); + + ProjectProperties projectprops; + projectprops.lProjectLanguage = -1; + projectprops.SetBugIDRe(m_sBugtraqRegex1); + projectprops.SetCheckRe(m_sBugtraqRegex2); + + m_cLogMessage.Init(projectprops); + m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8)); + + m_cLogMessage.SetText(CString(MAKEINTRESOURCE(IDS_SAMPLEBUGTRAQTESTMSG))); + m_cLogMessage.Call(SCI_SETCURRENTPOS, 0); + m_cLogMessage.Call(SCI_SETSEL, 0, 0); + + AddAnchor(IDC_SAMPLELABEL, TOP_LEFT, TOP_RIGHT); + AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, BOTTOM_RIGHT); + AddAnchor(IDC_REGEXIDLABEL, BOTTOM_LEFT); + AddAnchor(IDC_BUGTRAQLOGREGEX1, BOTTOM_LEFT, BOTTOM_RIGHT); + AddAnchor(IDC_REGEXMSGLABEL, BOTTOM_LEFT); + AddAnchor(IDC_BUGTRAQLOGREGEX2, BOTTOM_LEFT, BOTTOM_RIGHT); + AddAnchor(IDOK, BOTTOM_RIGHT); + AddAnchor(IDCANCEL, BOTTOM_RIGHT); + + return TRUE; +} + +void CBugtraqRegexTestDlg::UpdateLogControl() +{ + if (m_BugtraqRegex1.IsValidRegex() && m_BugtraqRegex2.IsValidRegex()) + { + UpdateData(); + ProjectProperties projectprops; + projectprops.lProjectLanguage = -1; + projectprops.SetBugIDRe(m_sBugtraqRegex1.Trim()); + projectprops.SetCheckRe(m_sBugtraqRegex2.Trim()); + m_cLogMessage.Init(projectprops); + m_cLogMessage.RestyleBugIDs(); + } +} diff --git a/src/TortoiseProc/BugtraqRegexTestDlg.h b/src/TortoiseProc/BugtraqRegexTestDlg.h new file mode 100644 index 000000000..0ac205704 --- /dev/null +++ b/src/TortoiseProc/BugtraqRegexTestDlg.h @@ -0,0 +1,55 @@ +// TortoiseGit - a Windows shell extension for easy version control + +// Copyright (C) 2014 - TortoiseGit +// Copyright (C) 2011 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#pragma once +#include "StandAloneDlg.h" +#include "RegexEdit.h" +#include "SciEdit.h" + +// CBugtraqRegexTestDlg dialog + +class CBugtraqRegexTestDlg : public CResizableStandAloneDialog +{ + DECLARE_DYNAMIC(CBugtraqRegexTestDlg) + +public: + CBugtraqRegexTestDlg(CWnd* pParent = nullptr); // standard constructor + virtual ~CBugtraqRegexTestDlg(); + + // Dialog Data + enum { IDD = IDD_BUGTRAQREGEXTESTER }; + + CString m_sBugtraqRegex1; + CString m_sBugtraqRegex2; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() + + afx_msg void OnEnChangeBugtraqlogregex1(); + afx_msg void OnEnChangeBugtraqlogregex2(); + +private: + void UpdateLogControl(); + CRegexEdit m_BugtraqRegex1; + CRegexEdit m_BugtraqRegex2; + CSciEdit m_cLogMessage; +}; diff --git a/src/TortoiseProc/Settings/SettingsBugtraqConfig.cpp b/src/TortoiseProc/Settings/SettingsBugtraqConfig.cpp index 97b7b4833..dbb9acba8 100644 --- a/src/TortoiseProc/Settings/SettingsBugtraqConfig.cpp +++ b/src/TortoiseProc/Settings/SettingsBugtraqConfig.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2013 - TortoiseGit +// Copyright (C) 2009-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -24,6 +24,8 @@ #include "SettingsBugtraqConfig.h" #include "ProjectProperties.h" #include "Git.h" +#include "BugtraqRegexTestDlg.h" + // CSettingsBugtraqConfig dialog IMPLEMENT_DYNAMIC(CSettingsBugtraqConfig, ISettingsPropPage) @@ -77,6 +79,7 @@ BEGIN_MESSAGE_MAP(CSettingsBugtraqConfig, ISettingsPropPage) ON_BN_CLICKED(IDC_CHECK_INHERIT_BTMSG, &OnChange) ON_BN_CLICKED(IDC_CHECK_INHERIT_BTLABEL, &OnChange) ON_BN_CLICKED(IDC_CHECK_INHERIT_BTREGEXP, &OnChange) + ON_BN_CLICKED(IDC_TESTBUGTRAQREGEXBUTTON, &CSettingsBugtraqConfig::OnBnClickedTestbugtraqregexbutton) END_MESSAGE_MAP() BOOL CSettingsBugtraqConfig::OnInitDialog() @@ -232,3 +235,24 @@ BOOL CSettingsBugtraqConfig::PreTranslateMessage(MSG* pMsg) m_tooltips.RelayEvent(pMsg); return ISettingsPropPage::PreTranslateMessage(pMsg); } + +void CSettingsBugtraqConfig::OnBnClickedTestbugtraqregexbutton() +{ + m_tooltips.Pop(); // hide the tooltips + CBugtraqRegexTestDlg dlg(this); + dlg.m_sBugtraqRegex2 = m_Logregex; + dlg.m_sBugtraqRegex2.Trim(); + dlg.m_sBugtraqRegex2.Replace(_T("\r\n"), _T("\n")); + if (dlg.m_sBugtraqRegex2.Find('\n') >= 0) + { + dlg.m_sBugtraqRegex1 = dlg.m_sBugtraqRegex2.Mid(dlg.m_sBugtraqRegex2.Find('\n')).Trim(); + dlg.m_sBugtraqRegex2 = dlg.m_sBugtraqRegex2.Left(dlg.m_sBugtraqRegex2.Find('\n')).Trim(); + } + if (dlg.DoModal() == IDOK) + { + m_Logregex = dlg.m_sBugtraqRegex1 + _T("\n") + dlg.m_sBugtraqRegex2; + m_Logregex.Trim(); + m_Logregex.Replace(_T("\n"), _T("\r\n")); + UpdateData(FALSE); + } +} diff --git a/src/TortoiseProc/Settings/SettingsBugtraqConfig.h b/src/TortoiseProc/Settings/SettingsBugtraqConfig.h index 17cdf482d..ad1814cac 100644 --- a/src/TortoiseProc/Settings/SettingsBugtraqConfig.h +++ b/src/TortoiseProc/Settings/SettingsBugtraqConfig.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2013 - TortoiseGit +// Copyright (C) 2009-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -42,6 +42,8 @@ protected: virtual BOOL OnApply(); virtual BOOL PreTranslateMessage(MSG* pMsg); + afx_msg void OnBnClickedTestbugtraqregexbutton(); + virtual void LoadDataImpl(git_config * config); virtual BOOL SafeDataImpl(git_config * config); virtual void EnDisableControls(); diff --git a/src/TortoiseProc/TortoiseProc.vcxproj b/src/TortoiseProc/TortoiseProc.vcxproj index 4ec9cc74c..34da3e02b 100644 --- a/src/TortoiseProc/TortoiseProc.vcxproj +++ b/src/TortoiseProc/TortoiseProc.vcxproj @@ -57,6 +57,7 @@ + @@ -238,6 +239,7 @@ + diff --git a/src/TortoiseProc/TortoiseProc.vcxproj.filters b/src/TortoiseProc/TortoiseProc.vcxproj.filters index c9b916cf9..6f0f9934f 100644 --- a/src/TortoiseProc/TortoiseProc.vcxproj.filters +++ b/src/TortoiseProc/TortoiseProc.vcxproj.filters @@ -683,6 +683,9 @@ Commands\UpdateCheck + + Commands\setting + @@ -1204,6 +1207,9 @@ Commands\UpdateCheck + + Commands\setting + diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index 7c12349f6..e253b1e50 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -139,6 +139,7 @@ #define IDR_ACC_COMMITDLG 325 #define IDD_SYNC 326 #define IDI_SHOWBRANCHES 326 +#define IDD_BUGTRAQREGEXTESTER 327 #define IDD_PATCH_VIEW 328 #define IDD_SVNIGNORE 329 #define IDD_CREATEREPO 330 @@ -1023,6 +1024,7 @@ #define IDC_BUTTON_BROWSE_SOURCE_BRANCH2 1484 #define IDC_BUTTON_BROWSE_DEST_BRANCH 1484 #define IDC_CHECK_FFONLY 1484 +#define IDS_SAMPLEBUGTRAQTESTMSG 1484 #define IDC_TITLE_ANIMATE 1485 #define IDC_CHECK_FETCHTAGS 1485 #define IDC_PROC_PUSH_SET_PUSHBRANCH 1485 @@ -1166,7 +1168,9 @@ #define IDC_CHECK_GLOBAL 1567 #define IDC_EDIT_URL 1568 #define IDC_EDIT_PUTTY_KEY 1569 +#define IDC_BUGTRAQLOGREGEX1 1569 #define IDC_CHECK_ISAUTOLOADPUTTYKEY 1570 +#define IDC_BUGTRAQLOGREGEX2 1570 #define IDC_PUTTYKEYFILE 1571 #define IDC_GROUP_CLONE 1572 #define IDC_GROUPT_REMOTE 1573 @@ -1174,8 +1178,10 @@ #define IDC_SENDMAIL_TO 1577 #define IDC_COMBOBOXEX_REF 1578 #define IDC_SENDMAIL_CC 1578 +#define IDC_REGEXIDLABEL 1578 #define IDC_STATIC_REF 1579 #define IDC_SENDMAIL_ATTACHMENT 1579 +#define IDC_REGEXMSGLABEL 1579 #define IDC_REFLOG_LIST 1580 #define IDC_SENDMAIL_SETUP 1580 #define IDC_STATIC_REPOURL 1580 @@ -1221,6 +1227,7 @@ #define IDC_COMBOBOXEX_URL 1610 #define IDC_BUTTON_PULL 1611 #define IDC_BUTTON_PUSH 1612 +#define IDC_SAMPLELABEL 1612 #define IDC_BUTTON_APPLY 1613 #define IDC_BUTTON_EMAIL 1614 #define IDC_STATIC_LOCAL_BRANCH 1616 @@ -1414,6 +1421,7 @@ #define IDC_CHECK_INHERIT_BTMSG 1782 #define IDC_CHECK_INHERIT_BTLABEL 1783 #define IDC_CURRENTBRANCH 1784 +#define IDC_TESTBUGTRAQREGEXBUTTON 1787 #define IDS_LOG_FILTER_BY 1850 #define IDS_LOG_FILTER_PATHS 1851 #define IDS_LOG_FILTER_AUTHORS 1852 @@ -1859,7 +1867,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 350 #define _APS_NEXT_COMMAND_VALUE 32865 -#define _APS_NEXT_CONTROL_VALUE 1785 +#define _APS_NEXT_CONTROL_VALUE 1788 #define _APS_NEXT_SYMED_VALUE 201 #endif #endif diff --git a/src/Utils/MiscUI/SciEdit.cpp b/src/Utils/MiscUI/SciEdit.cpp index 18344b8d0..b0d7fb36c 100644 --- a/src/Utils/MiscUI/SciEdit.cpp +++ b/src/Utils/MiscUI/SciEdit.cpp @@ -1489,3 +1489,13 @@ int CSciEdit::LoadFromFile(CString &filename) else return -1; } + +void CSciEdit::RestyleBugIDs() +{ + int endstylepos = (int)Call(SCI_GETLENGTH); + // clear all styles + Call(SCI_STARTSTYLING, 0, STYLE_MASK); + Call(SCI_SETSTYLING, endstylepos, STYLE_DEFAULT); + // style the bug IDs + MarkEnteredBugID(0, endstylepos); +} diff --git a/src/Utils/MiscUI/SciEdit.h b/src/Utils/MiscUI/SciEdit.h index 493fbc585..bc570db32 100644 --- a/src/Utils/MiscUI/SciEdit.h +++ b/src/Utils/MiscUI/SciEdit.h @@ -116,6 +116,7 @@ public: CStringA StringForControl(const CString& text); CString StringFromControl(const CStringA& text); int LoadFromFile(CString &filename); + void RestyleBugIDs(); private: bool IsUTF8(LPVOID pBuffer, size_t cb); -- 2.11.4.GIT