Beispiel #1
0
        public override object GetTagValue(SolutionItem item, string tag)
        {
            switch (tag)
            {
            case "ITEMNAME":
            case "PROJECTNAME":
                return(item.Name);

            case "AUTHORCOPYRIGHT":
                AuthorInformation authorInfo = item.AuthorInformation ?? AuthorInformation.Default;
                return(authorInfo.Copyright);

            case "AUTHORCOMPANY":
                authorInfo = item.AuthorInformation ?? AuthorInformation.Default;
                return(authorInfo.Company);

            case "AUTHORTRADEMARK":
                authorInfo = item.AuthorInformation ?? AuthorInformation.Default;
                return(authorInfo.Trademark);

            case "AUTHOREMAIL":
                authorInfo = item.AuthorInformation ?? AuthorInformation.Default;
                return(authorInfo.Email);

            case "AUTHORNAME":
                authorInfo = item.AuthorInformation ?? AuthorInformation.Default;
                return(authorInfo.Name);

            case "ITEMDIR":
            case "PROJECTDIR":
                return(item.BaseDirectory);
            }
            throw new NotSupportedException();
        }
		public AuthorInformationPanelWidget (AuthorInformation info)
		{
			this.Build();
			
			this.info = info;
			checkCustom.Active = (info != null);
			UseDefaultToggled (this, EventArgs.Empty);
		}
		public static string GetHeader (AuthorInformation authorInfo, StandardHeaderPolicy policy, TextStylePolicy textPolicy,
		                                string fileName, bool newFile)
		{
			string[] comment = Document.GetCommentTags (fileName);
			if (comment == null)
				return "";
			
			if (string.IsNullOrEmpty (policy.Text) || (newFile && !policy.IncludeInNewFiles))
				return "";
			
			string result;
			string eolMarker = TextStylePolicy.GetEolMarker (textPolicy.EolMarker);
			
			if (comment.Length == 1) {
				string cmt = comment[0];
				//make sure there's a space between the comment char and the license text
				if (!char.IsWhiteSpace (cmt[cmt.Length - 1]))
					cmt = cmt + " ";
				
				StringBuilder sb = new StringBuilder (policy.Text.Length);
				string[] lines = policy.Text.Split ('\n');
				foreach (string line in lines) {
					if (string.IsNullOrWhiteSpace (line)) {
						sb.Append (cmt.TrimEnd ());
						sb.Append (eolMarker);
						continue;
					}
					sb.Append (cmt);
					sb.Append (line);
					sb.Append (eolMarker);
				}
				result = sb.ToString ();
			} else {
				//multiline comment
				result = String.Concat (comment[0], "\n", policy.Text, "\n", comment[1], "\n");
			}
			
			return StringParserService.Parse (result, new string[,] { 
				{ "FileName", Path.GetFileName (fileName) }, 
				{ "FileNameWithoutExtension", Path.GetFileNameWithoutExtension (fileName) }, 
				{ "Directory", Path.GetDirectoryName (fileName) }, 
				{ "FullFileName", fileName },
				{ "AuthorName", authorInfo.Name },
				{ "AuthorEmail", authorInfo.Email },
				{ "CopyrightHolder", authorInfo.Copyright },
			});
		}
		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;
		}
		public static CommitMessageFormat GetCommitMessageFormat (ChangeSet cset, out AuthorInformation authorInfo)
		{
			// If all files belong to a project, use that project's policy. If not, use the solution policy
			Project project = null;
			bool sameProject = true;
			foreach (ChangeSetItem item in cset.Items) {
				if (project != null) {
					if (project.Files.GetFile (item.LocalPath) == null) {
						// Not all files belong to the same project
						sameProject = false;
						break;
					}
				} else {
					project = IdeApp.Workspace.GetProjectContainingFile (item.LocalPath);
				}
			}
			CommitMessageStyle style;
			
			if (project != null) {
				VersionControlPolicy policy;
				if (sameProject)
					policy = project.Policies.Get<VersionControlPolicy> ();
				else
					policy = project.ParentSolution.Policies.Get<VersionControlPolicy> ();
				style = policy.CommitMessageStyle;
			}
			else {
				style = PolicyService.GetDefaultPolicy<CommitMessageStyle> ();
			}
			
			authorInfo = project != null ? project.AuthorInformation : AuthorInformation.Default;
			
			CommitMessageFormat format = new CommitMessageFormat ();
			format.Style = style;
			format.ShowFilesForSingleComment = false;
			
			return format;
		}
		void UseDefaultToggled (object sender, System.EventArgs e)
		{
			if (checkCustom.Active) {
				infoTable.Sensitive = true;
				if (info != null) {
					nameEntry.Text = info.Name ?? "";
					emailEntry.Text = info.Email ?? "";
					copyrightEntry.Text = info.Copyright ?? "";
				}
			} else {
				infoTable.Sensitive = false;
				info = new AuthorInformation (nameEntry.Text, emailEntry.Text, copyrightEntry.Text);
				if (String.IsNullOrEmpty (info.Name) && String.IsNullOrEmpty (info.Email))
					info = null;
				nameEntry.Text = AuthorInformation.Default.Name ?? "";
				emailEntry.Text = AuthorInformation.Default.Email ?? "";
				copyrightEntry.Text = AuthorInformation.Default.Copyright ?? "";
			}
		}
		public ChangeLogWriter (string path, AuthorInformation uinfo)
		{
			changelog_path = Path.GetDirectoryName (path);
			this.uinfo = uinfo;
		}