OSDN Git Service

Add /fileext command line option
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 22 Jul 2021 12:11:28 +0000 (21:11 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 22 Jul 2021 12:11:28 +0000 (21:11 +0900)
15 files changed:
Docs/Manual/EN/Command_line.xml
Docs/Manual/JP/Command_line.xml
Docs/Users/ChangeLog.html
Docs/Users/ChangeLog.md
Docs/Users/ReleaseNotes.html
Docs/Users/ReleaseNotes.md
Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.cpp
Src/MergeCmdLineInfo.cpp
Src/MergeCmdLineInfo.h
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/MergeEditView.cpp
Src/MergeEditView.h

index 36ce1ac..cb312cd 100644 (file)
       <arg choice="opt" rep="norepeat"><option>/cp</option>
       <replaceable>codepage</replaceable></arg>
 
+      <arg choice="opt" rep="norepeat"><option>/fileext</option>
+      <replaceable>file-extension</replaceable></arg>
+
       <arg choice="opt" rep="norepeat"><option>/cfg</option>
       <replaceable>name=value</replaceable></arg>
 
     </varlistentry>
 
     <varlistentry>
+      <term><option>/fileext <replaceable>file-extension</replaceable></option></term>
+      <listitem>
+        <para>Specifies a file extension for determining syntax hightliting.</para>
+      </listitem>
+    </varlistentry>
+
+    <varlistentry>
       <term><option>/cfg</option></term>
       <listitem>
         <para>TBD</para>
index 3101c20..2547ed9 100644 (file)
       <arg choice="opt" rep="norepeat"><option>/cp</option>
       <replaceable>codepage</replaceable></arg>
 
+      <arg choice="opt" rep="norepeat"><option>/fileext</option>
+      <replaceable>file-extension</replaceable></arg>
+
       <arg choice="opt" rep="norepeat"><option>/cfg</option>
       <replaceable>name=value</replaceable></arg>
 
     </varlistentry>
 
     <varlistentry>
+      <term><option>/fileext <replaceable>file-extension</replaceable></option></term>
+      <listitem>
+        <para>シンタックスハイライトの種類を決定するため、ファイル拡張子を指定します。</para>
+      </listitem>
+    </varlistentry>
+
+    <varlistentry>
       <term><option>/cfg</option></term>
       <listitem>
         <para>TBD</para>
index 008f1a0..217009b 100644 (file)
@@ -56,7 +56,7 @@
 </ul>
 <h3 id="select-files-or-folders-dialog">Select Files or Folders dialog</h3>
 <ul>
-<li>BugFix: Fix the Select Files or Folders dialog. (PR #882)</li>
+<li>BugFix: Fix the Select Files or Folders dialog. (PR #882,#892)</li>
 </ul>
 <h3 id="plugins">Plugins</h3>
 <ul>
@@ -91,7 +91,7 @@
 <h3 id="command-line">Command line</h3>
 <ul>
 <li>Added /l command line option (osdn.net #41528)</li>
-<li>Added /t, /table-delimiter, /new and /inifile command line option</li>
+<li>Added /t, /table-delimiter, /new, /fileext and /inifile command line option</li>
 </ul>
 <h3 id="installer">Installer</h3>
 <ul>
 <li>Translation updates:
 <ul>
 <li>Bulgarian (PR #850)</li>
-<li>Dutch (PR #842)</li>
+<li>Dutch (PR #842,#893)</li>
 <li>Galician (PR #869)</li>
 <li>German (PR #860,#870,#883,#890)</li>
 <li>Hungarian (PR #845,#856)</li>
index 3f54021..9269acf 100644 (file)
@@ -39,7 +39,7 @@
 
 ### Select Files or Folders dialog
 
-- BugFix: Fix the Select Files or Folders dialog. (PR #882)
+- BugFix: Fix the Select Files or Folders dialog. (PR #882,#892)
 
 ### Plugins
 
@@ -72,7 +72,7 @@
 ### Command line
 
 - Added /l command line option (osdn.net #41528)
-- Added /t, /table-delimiter, /new and /inifile command line option
+- Added /t, /table-delimiter, /new, /fileext and /inifile command line option
 
 ### Installer
 
@@ -83,7 +83,7 @@
 
 - Translation updates:
   - Bulgarian (PR #850)
-  - Dutch (PR #842)
+  - Dutch (PR #842,#893)
   - Galician (PR #869)
   - German (PR #860,#870,#883,#890)
   - Hungarian (PR #845,#856)
index add7fb2..5acc786 100644 (file)
@@ -66,7 +66,7 @@
 </ul>
 <h3 id="select-files-or-folders-dialog">Select Files or Folders dialog</h3>
 <ul>
-<li>BugFix: Fix the Select Files or Folders dialog. (PR #882)</li>
+<li>BugFix: Fix the Select Files or Folders dialog. (PR #882,#892)</li>
 </ul>
 <h3 id="plugins">Plugins</h3>
 <ul>
 <h3 id="command-line">Command line</h3>
 <ul>
 <li>Added /l command line option (osdn.net #41528)</li>
-<li>Added /t, /table-delimiter, /new and /inifile command line option</li>
+<li>Added /t, /table-delimiter, /new, /fileext and /inifile command line option</li>
 </ul>
 <h3 id="installer">Installer</h3>
 <ul>
 <li>Translation updates:
 <ul>
 <li>Bulgarian (PR #850)</li>
-<li>Dutch (PR #842)</li>
+<li>Dutch (PR #842,#893)</li>
 <li>Galician (PR #869)</li>
 <li>German (PR #860,#870,#883,#890)</li>
 <li>Hungarian (PR #845,#856)</li>
index a1a8155..0d7039f 100644 (file)
@@ -53,7 +53,7 @@ Please submit bug reports to our <a href="http://github.com/winmerge/winmerge/is
 
 ### Select Files or Folders dialog
 
-- BugFix: Fix the Select Files or Folders dialog. (PR #882)
+- BugFix: Fix the Select Files or Folders dialog. (PR #882,#892)
 
 ### Plugins
 
@@ -86,7 +86,7 @@ Please submit bug reports to our <a href="http://github.com/winmerge/winmerge/is
 ### Command line
 
 - Added /l command line option (osdn.net #41528)
-- Added /t, /table-delimiter, /new and /inifile command line option
+- Added /t, /table-delimiter, /new, /fileext and /inifile command line option
 
 ### Installer
 
@@ -97,7 +97,7 @@ Please submit bug reports to our <a href="http://github.com/winmerge/winmerge/is
 
 - Translation updates:
   - Bulgarian (PR #850)
-  - Dutch (PR #842)
+  - Dutch (PR #842,#893)
   - Galician (PR #869)
   - German (PR #860,#870,#883,#890)
   - Hungarian (PR #845,#856)
index e917b2f..564edab 100644 (file)
@@ -824,7 +824,8 @@ bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pD
        pMergeDoc->SetEnableTableEditing(table);
        if (pOpenParams && table.value_or(false))
        {
-               CMergeDoc::TableProps props = CMergeDoc::GetTablePropertiesByFileName(fileloc[0].filepath, true, false);
+               CMergeDoc::TableProps props = CMergeDoc::GetTablePropertiesByFileName(
+                       pOpenParams->m_fileExt.empty() ? fileloc[0].filepath : pOpenParams->m_fileExt, true, false);
                props.delimiter = pOpenParams->m_tableDelimiter.value_or(props.delimiter);
                props.quote = pOpenParams->m_tableQuote.value_or(props.quote);
                props.allowNewlinesInQuotes = pOpenParams->m_tableAllowNewlinesInQuotes.value_or(props.allowNewlinesInQuotes);
@@ -844,6 +845,9 @@ bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pD
                return false;
        }
 
+       if (pOpenParams && !pOpenParams->m_fileExt.empty())
+               pMergeDoc->SetTextType(pOpenParams->m_fileExt);
+
        for (int pane = 0; pane < nFiles; pane++)
        {
                if (dwFlags)
index 228a1d4..d4f5f4e 100644 (file)
@@ -75,6 +75,7 @@ public:
                std::optional<TCHAR> m_tableDelimiter;
                std::optional<TCHAR> m_tableQuote;
                std::optional<bool> m_tableAllowNewlinesInQuotes;
+               String m_fileExt;
        };
 
        CMainFrame();
index 05cad9f..910cdce 100644 (file)
@@ -714,6 +714,7 @@ bool CMergeApp::ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainF
 
                CMainFrame::OpenTextFileParams openParams;
                openParams.m_line = cmdInfo.m_nLineIndex;
+               openParams.m_fileExt = cmdInfo.m_sFileExt;
                if (cmdInfo.m_nWindowType == MergeCmdLineInfo::TABLE)
                {
                        openParams.m_tableDelimiter = cmdInfo.m_cTableDelimiter;
index 55bb1f6..fe5b0f8 100644 (file)
@@ -328,16 +328,16 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                        // -maximize means maximize the main window.
                        m_nCmdShow = MAXIMIZE;
                }
-               else if (param == _T("prediffer"))
-               {
-                       // Get prediffer if specified (otherwise prediffer will be blank, which is default)
-                       q = EatParam(q, m_sPreDiffer);
-               }
                else if (param == _T("unpacker"))
                {
                        // Get unpacker if specified (otherwise unpacker will be blank, which is default)
                        q = EatParam(q, m_sUnpacker);
                }
+               else if (param == _T("prediffer"))
+               {
+                       // Get prediffer if specified (otherwise prediffer will be blank, which is default)
+                       q = EatParam(q, m_sPreDiffer);
+               }
                else if (param == _T("wl"))
                {
                        // -wl to open left path as read-only
@@ -463,6 +463,12 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                        q = EatParam(q, codepage);
                        m_nCodepage = atoi(ucr::toUTF8(codepage).c_str());
                }
+               else if (param == _T("fileext"))
+               {
+                       q = EatParam(q, m_sFileExt);
+                       if (!m_sFileExt.empty() && m_sFileExt[0] != '.')
+                               m_sFileExt = _T(".") + m_sFileExt;
+               }
                else if (param == _T("ignorews"))
                {
                        q = SetOption(q, OPT_CMP_IGNORE_WHITESPACE);
index 3be64b5..77ed86c 100644 (file)
@@ -91,6 +91,7 @@ public:
        String m_sFileFilter; /**< File filter mask. */
        String m_sPreDiffer; /**< Pre-differ name. */
        String m_sUnpacker; /**< Unpacker name. */
+       String m_sFileExt; /**< File extension for determining syntax highliting */
 
        String m_sOutputpath;
        String m_sReportFile;
index 542dcbc..fe3bc4b 100644 (file)
@@ -129,6 +129,7 @@ CMergeDoc::CMergeDoc()
 , m_pView{nullptr}
 , m_bAutomaticRescan(false)
 , m_CurrentPredifferID(0)
+, m_bChangedSchemeManually(false)
 {
        DIFFOPTIONS options = {0};
 
@@ -2867,6 +2868,26 @@ void CMergeDoc::SetTableProperties()
        }
 }
 
+void CMergeDoc::SetTextType(int textType)
+{
+       ForEachView([textType, this](auto& pView) {
+               pView->SetTextType(CrystalLineParser::TextType(textType));
+               pView->SetDisableBSAtSOL(false);
+               m_bChangedSchemeManually = true;
+       });
+}
+
+void CMergeDoc::SetTextType(const String& ext)
+{
+       String ext2 = ext;
+       strutils::replace(ext2, _T("."), _T(""));
+       ForEachView([&ext2, this](auto& pView) {
+               pView->SetTextType(ext2.c_str());
+               pView->SetDisableBSAtSOL(false);
+               m_bChangedSchemeManually = true;
+       });
+}
+
 /**
  * @brief Loads files and does initial rescan.
  * @param fileloc [in] File to open to left/middle/right side (path & encoding info)
index 8974b15..bbec150 100644 (file)
@@ -319,6 +319,9 @@ public:
        std::optional<bool> GetEnableTableEditing() const { return m_bEnableTableEditing; }
        void SetEnableTableEditing(std::optional<bool> bEnableTableEditing) { m_bEnableTableEditing = bEnableTableEditing; }
        void SetTableProperties(const TableProps& props) { m_pTablePropsCommandLine.reset(new TableProps(props)); }
+       void SetTextType(int textType);
+       void SetTextType(const String& ext);
+       bool GetChangedSchemeManually() const { return m_bChangedSchemeManually; }
        bool GetAutomaticRescan() const { return m_bAutomaticRescan; }
        // to customize the mergeview menu
        HMENU createPrediffersSubmenu(HMENU hMenu);
@@ -365,6 +368,7 @@ protected:
        bool m_bAutomaticRescan;
        /// active prediffer ID : helper to check the radio button
        int m_CurrentPredifferID;
+       bool m_bChangedSchemeManually;  /**< `true` if the syntax highlighting scheme is changed manually */
 
 // friend access
        friend class RescanSuppress;
index 8c2bca4..25caf6a 100644 (file)
@@ -66,7 +66,6 @@ CMergeEditView::CMergeEditView()
 , fTimerWaitingForIdle(0)
 , m_lineBegin(0)
 , m_lineEnd(-1)
-, m_bChangedSchemeManually(false)
 {
        SetParser(&m_xParser);
        
@@ -260,15 +259,6 @@ 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
  */
@@ -3330,7 +3320,7 @@ void CMergeEditView::RefreshOptions()
 
        if (!GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT))
                SetTextType(CrystalLineParser::SRC_PLAIN);
-       else if (!m_bChangedSchemeManually)
+       else if (!GetDocument()->GetChangedSchemeManually())
        {
                // The syntax highlighting scheme should only be applied if it has not been manually changed.
                String fileName = GetDocument()->m_filePaths[m_nThisPane];
@@ -4083,21 +4073,7 @@ void CMergeEditView::OnChangeScheme(UINT nID)
 {
        CMergeDoc *pDoc = GetDocument();
        ASSERT(pDoc != nullptr);
-
-       for (int nGroup = 0; nGroup < pDoc->m_nGroups; nGroup++)
-               for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++) 
-               {
-                       CMergeEditView *pView = pDoc->GetView(nGroup, nPane);
-                       ASSERT(pView != nullptr);
-
-                       if (pView != nullptr)
-                       {
-                               pView->SetTextType(CrystalLineParser::TextType(nID - ID_COLORSCHEME_FIRST));
-                               pView->SetDisableBSAtSOL(false);
-                               pView->m_bChangedSchemeManually = true;
-                       }
-               }
-
+       pDoc->SetTextType(nID - ID_COLORSCHEME_FIRST);
        OnRefresh();
 }
 
index a73a330..44e1763 100644 (file)
@@ -87,11 +87,8 @@ private:
 
        bool m_bCurrentLineIsDiff; /**< `true` if cursor is in diff line */
 
-       bool m_bChangedSchemeManually;  /**< `true` if the syntax highlighting scheme is changed manually */
-
 // Attributes
 public:
-       void CopyProperties (CCrystalTextView* pSource) override;
 
 // Operations
 public: