Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CommitMessageStylePanelWidget.cs « MonoDevelop.VersionControl.Dialogs « MonoDevelop.VersionControl « VersionControl « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 79a73b6d11b8dce30aa1f953ffaaa65527e89df1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// CommitMessageStylePanelWidget.cs
//
// Author:
//   Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

using System;
using MonoDevelop.Ide;
using MonoDevelop.Projects;
using MonoDevelop.Ide.Fonts;

namespace MonoDevelop.VersionControl
{
	[System.ComponentModel.ToolboxItem(true)]
	public partial class CommitMessageStylePanelWidget : Gtk.Bin
	{
		CommitMessageFormat format;
		AuthorInformation uinfo;
		bool updating;
		
		public event EventHandler Changed;
		
		public CommitMessageStylePanelWidget()
		{
			this.Build();

			textview.AcceptsTab = true;
		}
		
		public void Load (CommitMessageFormat format, AuthorInformation uinfo)
		{
			updating = true;
			this.format = format;
			this.uinfo = uinfo;
			checkIndent.Active = format.Style.LineAlign != 0;
			checkLineSep.Active = format.Style.InterMessageLines != 0;
			checkMsgInNewLine.Active = format.Style.LastFilePostfix == ":\n";
			checkOneLinePerFile.Active = format.Style.FileSeparator == ":\n* ";
			checkUseBullets.Active = format.Style.FirstFilePrefix.Trim ().Length > 0;
			checkIndentEntries.Active = format.Style.Indent.Length > 0;
			checkIncludeDirs.Active = format.Style.IncludeDirectoryPaths;
			entryHeader.Text = ToCString (format.Style.Header.TrimEnd ('\n'));
			checkWrap.Active = format.Style.Wrap;
			UpdatePreview ();
			updating = false;
		}
		
		void UpdatePreview ()
		{
			if (format == null)
				return;
			ChangeLogWriter writer = new ChangeLogWriter ("./", uinfo);
			string msg = "My changes made additional changes. This is sample documentation.";
			writer.AddFile (msg, "./somedir/myfile.ext");
			writer.AddFile (msg, "./yourfile.ext");
			writer.AddFile ("Some additional changes on another file of the project.", "./otherfile.ext");
			format.MaxColumns = 60;
			writer.MessageFormat = format;
			
			textview.Buffer.Text = writer.ToString ();
		}

		protected virtual void OnCheckIndentToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			UpdateBullets ();
			OnChanged ();
		}

		protected virtual void OnCheckLineSepToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			format.Style.InterMessageLines = checkLineSep.Active ? 1 : 0;
			OnChanged ();
		}

		protected virtual void OnCheckOneLinePerFileToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			UpdateBullets ();
			OnChanged ();
		}

		protected virtual void OnCheckMsgInNewLineToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			UpdateBullets ();
			OnChanged ();
		}

		protected virtual void OnEntryHeaderChanged (object sender, System.EventArgs e)
		{
			if (updating) return;
			format.Style.Header = !string.IsNullOrEmpty (entryHeader.Text) ? FromCString (entryHeader.Text) + "\n\n" : "";
			OnChanged ();
		}
		
		static string FromCString (string txt)
		{
			return txt.Replace ("\\t", "\t").Replace ("\\n", "\n");
		}
		
		static string ToCString (string txt)
		{
			return txt.Replace ("\t", "\\t").Replace ("\n", "\\n");
		}
		
		void UpdateBullets ()
		{
			format.Style.FileSeparator = checkOneLinePerFile.Active ? ":\n" + format.Style.FirstFilePrefix : ", ";
			format.Style.LineAlign = checkIndent.Active ? format.Style.FirstFilePrefix.Length : 0;
			format.Style.LastFilePostfix = checkMsgInNewLine.Active ? ":\n" + new string (' ',format.Style.LineAlign): ": ";
		}
		
		void OnChanged ()
		{
			UpdatePreview ();
			if (Changed != null)
				Changed (this, EventArgs.Empty);
		}
		
		protected virtual void OnCheckUseBulletsToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			if (checkUseBullets.Active)
				format.Style.FirstFilePrefix = "* ";
			else
				format.Style.FirstFilePrefix = "";
			UpdateBullets ();
			OnChanged ();
		}

		protected virtual void OnCheckIndentEntriesToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			format.Style.Indent = checkIndentEntries.Active ? "\t" : "";
			OnChanged ();
		}
		
		protected virtual void OnCheckIncludeDirsToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			format.Style.IncludeDirectoryPaths = checkIncludeDirs.Active;
			OnChanged ();
		}
		
		protected virtual void OnCheckWrapToggled (object sender, System.EventArgs e)
		{
			if (updating) return;
			format.Style.Wrap = checkWrap.Active;
			OnChanged ();
		}
	}
}