Datei: NDOPackage/MergeConflictBase.cs
Last Commit (0625a4c)
| 1 | // |
| 2 | // Copyright ( c) 2002-2019 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Diagnostics; |
| 25 | using System.IO; |
| 26 | using System.Windows.Forms; |
| 27 | using EnvDTE; |
| 28 | using EnvDTE80; |
| 29 | using Microsoft.VisualStudio.CommandBars; |
| 30 | using System.Text.RegularExpressions; |
| 31 | using Microsoft.VisualStudio.Shell; |
| 32 | using System.ComponentModel.Design; |
| 33 | |
| 34 | namespace NETDataObjects.NDOVSPackage |
| 35 | { |
| 36 | ····/// <summary> |
| 37 | /// Zusammenfassung für MergeConflictBase. |
| 38 | ····/// </summary> |
| 39 | ····internal abstract class MergeConflictBase : AbstractCommand |
| 40 | ····{ |
| 41 | ········public MergeConflictBase( _DTE dte, CommandID commandId ) |
| 42 | ············: base( dte, commandId ) |
| 43 | ········{ |
| 44 | ········} |
| 45 | |
| 46 | ········protected bool GetConflictPositions( out EditPoint ep, out int myCodeOffset, out int cgCodeOffset, out int endConflictOffset ) |
| 47 | ········{ |
| 48 | ············Document document; |
| 49 | ············TextDocument textDoc; |
| 50 | |
| 51 | ············// Values will be ignored, if we return mit false |
| 52 | ············ep = null; |
| 53 | ············myCodeOffset = 0; |
| 54 | ············cgCodeOffset = 0; |
| 55 | ············endConflictOffset = 0; |
| 56 | |
| 57 | ············document = this.VisualStudioApplication.ActiveDocument; |
| 58 | ············if (document == null) |
| 59 | ················return false; |
| 60 | |
| 61 | ············textDoc = (TextDocument)document.Object( "TextDocument" ); |
| 62 | ············if (textDoc == null) |
| 63 | ················return false; |
| 64 | |
| 65 | ············ep = textDoc.Selection.ActivePoint.CreateEditPoint(); |
| 66 | ············textDoc.Selection.SelectLine(); |
| 67 | |
| 68 | ············if (textDoc.Selection.Text.IndexOf( "!!!! ClassGenerator merge conflict !!!! Your code follows:" ) < 0) |
| 69 | ················return false;··// Nothing to do |
| 70 | |
| 71 | ············ep.StartOfLine(); |
| 72 | ············myCodeOffset = ep.AbsoluteCharOffset; |
| 73 | |
| 74 | ············while (true) |
| 75 | ············{ |
| 76 | ················if (ep.AtEndOfDocument) |
| 77 | ····················return false; |
| 78 | ················ep.LineDown( 1 ); |
| 79 | ················if (ep.GetText( ep.LineLength ).IndexOf( "!!!! The ClassGenerator's code follows:" ) >= 0) |
| 80 | ····················break; |
| 81 | ············} |
| 82 | ············cgCodeOffset = ep.AbsoluteCharOffset; |
| 83 | ············while (true) |
| 84 | ············{ |
| 85 | ················if (ep.AtEndOfDocument) |
| 86 | ····················return false; |
| 87 | ················ep.LineDown( 1 ); |
| 88 | ················if (ep.GetText( ep.LineLength ).IndexOf( "!!!! End of merge conflict" ) >= 0) |
| 89 | ····················break; |
| 90 | ············} |
| 91 | ············endConflictOffset = ep.AbsoluteCharOffset; |
| 92 | ············return true; |
| 93 | ········} |
| 94 | |
| 95 | ········public abstract void DoIt(); |
| 96 | |
| 97 | ········protected override void DoIt( object sender, EventArgs e ) |
| 98 | ········{ |
| 99 | ············DoIt(); |
| 100 | ········} |
| 101 | |
| 102 | ········protected override void OnBeforeQueryStatus( object sender, EventArgs e ) |
| 103 | ········{ |
| 104 | ············OleMenuCommand item = sender as OleMenuCommand; |
| 105 | ············bool enabled = false; |
| 106 | ············Document document = this.VisualStudioApplication.ActiveDocument; |
| 107 | ············if (document != null) |
| 108 | ············{ |
| 109 | |
| 110 | ················TextDocument textDoc = (TextDocument)document.Object( "TextDocument" ); |
| 111 | ················if (textDoc != null) |
| 112 | ················{ |
| 113 | ····················string fileName = document.FullName.ToLower(); |
| 114 | ····················if (fileName.EndsWith( ".cs" )) |
| 115 | ························enabled = true; |
| 116 | ····················else if (fileName.EndsWith( ".vb" )) |
| 117 | ························enabled = true; |
| 118 | ····················if (enabled) |
| 119 | ····················{ |
| 120 | ························EditPoint ep = textDoc.Selection.ActivePoint.CreateEditPoint(); |
| 121 | ························ep.StartOfLine(); |
| 122 | ························string s = ep.GetText( ep.LineLength ); |
| 123 | ························if (s.IndexOf( "!!!! ClassGenerator merge conflict !!!! Your code follows:" ) < 0) |
| 124 | ····························enabled = false; |
| 125 | ····················} |
| 126 | ················} |
| 127 | ············} |
| 128 | |
| 129 | ············item.Enabled = enabled; |
| 130 | ········} |
| 131 | |
| 132 | ········public static implicit operator OleMenuCommand( MergeConflictBase abstractCommand ) |
| 133 | ········{ |
| 134 | ············return abstractCommand.command; |
| 135 | ········} |
| 136 | ····} |
| 137 | } |
| 138 | |
| 139 | |
| 140 | |
| 141 |
New Commit (fa0d6d6)
| 1 | // |
| 2 | // Copyright ( c) 2002-2022 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Diagnostics; |
| 25 | using System.IO; |
| 26 | using System.Windows.Forms; |
| 27 | using EnvDTE; |
| 28 | using EnvDTE80; |
| 29 | using Microsoft.VisualStudio.CommandBars; |
| 30 | using System.Text.RegularExpressions; |
| 31 | using Microsoft.VisualStudio.Shell; |
| 32 | using System.ComponentModel.Design; |
| 33 | |
| 34 | namespace NETDataObjects.NDOVSPackage |
| 35 | { |
| 36 | ····/// <summary> |
| 37 | /// MergeConflictBase is currently not used. It is intended for the ClassGenerator. In the event of conflicts, this produces marks in the |
| 38 | ····/// code that can be resolved by this class. |
| 39 | ····/// </summary> |
| 40 | ····internal abstract class MergeConflictBase : AbstractCommand |
| 41 | ····{ |
| 42 | ········public MergeConflictBase( _DTE dte, CommandID commandId ) |
| 43 | ············: base( dte, commandId ) |
| 44 | ········{ |
| 45 | ········} |
| 46 | |
| 47 | ········protected bool GetConflictPositions( out EditPoint ep, out int myCodeOffset, out int cgCodeOffset, out int endConflictOffset ) |
| 48 | ········{ |
| 49 | ············Document document; |
| 50 | ············TextDocument textDoc; |
| 51 | |
| 52 | ············// Values will be ignored, if we return mit false |
| 53 | ············ep = null; |
| 54 | ············myCodeOffset = 0; |
| 55 | ············cgCodeOffset = 0; |
| 56 | ············endConflictOffset = 0; |
| 57 | |
| 58 | ············document = this.VisualStudioApplication.ActiveDocument; |
| 59 | ············if (document == null) |
| 60 | ················return false; |
| 61 | |
| 62 | ············textDoc = (TextDocument)document.Object( "TextDocument" ); |
| 63 | ············if (textDoc == null) |
| 64 | ················return false; |
| 65 | |
| 66 | ············ep = textDoc.Selection.ActivePoint.CreateEditPoint(); |
| 67 | ············textDoc.Selection.SelectLine(); |
| 68 | |
| 69 | ············if (textDoc.Selection.Text.IndexOf( "!!!! ClassGenerator merge conflict !!!! Your code follows:" ) < 0) |
| 70 | ················return false;··// Nothing to do |
| 71 | |
| 72 | ············ep.StartOfLine(); |
| 73 | ············myCodeOffset = ep.AbsoluteCharOffset; |
| 74 | |
| 75 | ············while (true) |
| 76 | ············{ |
| 77 | ················if (ep.AtEndOfDocument) |
| 78 | ····················return false; |
| 79 | ················ep.LineDown( 1 ); |
| 80 | ················if (ep.GetText( ep.LineLength ).IndexOf( "!!!! The ClassGenerator's code follows:" ) >= 0) |
| 81 | ····················break; |
| 82 | ············} |
| 83 | ············cgCodeOffset = ep.AbsoluteCharOffset; |
| 84 | ············while (true) |
| 85 | ············{ |
| 86 | ················if (ep.AtEndOfDocument) |
| 87 | ····················return false; |
| 88 | ················ep.LineDown( 1 ); |
| 89 | ················if (ep.GetText( ep.LineLength ).IndexOf( "!!!! End of merge conflict" ) >= 0) |
| 90 | ····················break; |
| 91 | ············} |
| 92 | ············endConflictOffset = ep.AbsoluteCharOffset; |
| 93 | ············return true; |
| 94 | ········} |
| 95 | |
| 96 | ········public abstract void DoIt(); |
| 97 | |
| 98 | ········protected override void DoIt( object sender, EventArgs e ) |
| 99 | ········{ |
| 100 | ············DoIt(); |
| 101 | ········} |
| 102 | |
| 103 | ········protected override void OnBeforeQueryStatus( object sender, EventArgs e ) |
| 104 | ········{ |
| 105 | ············OleMenuCommand item = sender as OleMenuCommand; |
| 106 | ············bool enabled = false; |
| 107 | ············Document document = this.VisualStudioApplication.ActiveDocument; |
| 108 | ············if (document != null) |
| 109 | ············{ |
| 110 | |
| 111 | ················TextDocument textDoc = (TextDocument)document.Object( "TextDocument" ); |
| 112 | ················if (textDoc != null) |
| 113 | ················{ |
| 114 | ····················string fileName = document.FullName.ToLower(); |
| 115 | ····················if (fileName.EndsWith( ".cs" )) |
| 116 | ························enabled = true; |
| 117 | ····················else if (fileName.EndsWith( ".vb" )) |
| 118 | ························enabled = true; |
| 119 | ····················if (enabled) |
| 120 | ····················{ |
| 121 | ························EditPoint ep = textDoc.Selection.ActivePoint.CreateEditPoint(); |
| 122 | ························ep.StartOfLine(); |
| 123 | ························string s = ep.GetText( ep.LineLength ); |
| 124 | ························if (s.IndexOf( "!!!! ClassGenerator merge conflict !!!! Your code follows:" ) < 0) |
| 125 | ····························enabled = false; |
| 126 | ····················} |
| 127 | ················} |
| 128 | ············} |
| 129 | |
| 130 | ············item.Enabled = enabled; |
| 131 | ········} |
| 132 | |
| 133 | ········public static implicit operator OleMenuCommand( MergeConflictBase abstractCommand ) |
| 134 | ········{ |
| 135 | ············return abstractCommand.command; |
| 136 | ········} |
| 137 | ····} |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 |