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

PublishCommand.cs « MonoDevelop.VersionControl « MonoDevelop.VersionControl « VersionControl « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5dee5c58c9a925e1779ae1e7bb7f75c320699625 (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
using System.Collections.Generic;
using System.Linq;

using MonoDevelop.Projects;
using MonoDevelop.Core;
using MonoDevelop.VersionControl.Dialogs;
using MonoDevelop.Ide;

namespace MonoDevelop.VersionControl 
{
	internal class PublishCommand 
	{
		public static bool Publish (WorkspaceObject entry, FilePath localPath, bool test)
		{
			if (test)
				return VersionControlService.CheckVersionControlInstalled () && VersionControlService.GetRepository (entry) == null;

			List<FilePath> files = new List<FilePath> ();

			// Build the list of files to be checked in			
			string moduleName = entry.Name;
			if (localPath == entry.BaseDirectory) {
				GetFiles (files, entry);
			} else if (entry is Project) {
				foreach (ProjectFile file in ((Project)entry).Files.GetFilesInPath (localPath))
					if (file.Subtype != Subtype.Directory)
						files.Add (file.FilePath);
			} else
				return false;

			if (files.Count == 0)
				return false;
	
			SelectRepositoryDialog dlg = new SelectRepositoryDialog (SelectRepositoryMode.Publish);
			try {
				dlg.ModuleName = moduleName;
				dlg.Message = GettextCatalog.GetString ("Initial check-in of module {0}", moduleName);
				do {
					if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok && dlg.Repository != null) {
						AlertButton publishButton = new AlertButton ("_Publish");					
						if (MessageService.AskQuestion (GettextCatalog.GetString ("Are you sure you want to publish the project?"), GettextCatalog.GetString ("The project will be published to the repository '{0}', module '{1}'.", dlg.Repository.Name, dlg.ModuleName), AlertButton.Cancel, publishButton) == publishButton) {
							PublishWorker w = new PublishWorker (dlg.Repository, dlg.ModuleName, localPath, files.ToArray (), dlg.Message);
							w.Start ();
							break;
						}
					} else
						break;
				} while (true);
			} finally {
				dlg.Destroy ();
			}
			return true;
		}

		static void GetFiles (List<FilePath> files, WorkspaceObject entry)
		{
			// Ensure that we strip out all linked files from outside of the solution/projects path.
			if (entry is IWorkspaceFileObject)
				files.AddRange (((IWorkspaceFileObject)entry).GetItemFiles (true).Where (file => file.IsChildPathOf (entry.BaseDirectory)));
		}
		
		public static bool CanPublish (Repository vc, string path, bool isDir) {
			if (!VersionControlService.CheckVersionControlInstalled ())
				return false;

			if (!vc.GetVersionInfo (path).IsVersioned && isDir) 
				return true;
			return false;
		}
	}
	
	internal class PublishWorker : VersionControlTask {
		Repository vc;
		FilePath path;
		string moduleName;
		FilePath[] files;
		string message;

		public PublishWorker (Repository vc, string moduleName, FilePath localPath, FilePath[] files, string message) 
		{
			this.vc = vc;
			this.path = localPath;
			this.moduleName = moduleName;
			this.files = files;
			this.message = message;
			OperationType = VersionControlOperationType.Push;
		}

		protected override string GetDescription ()
		{
			return GettextCatalog.GetString ("Publishing \"{0}\" Project...", moduleName);
		}
		
		protected override void Run ()
		{
			try {
				vc.Publish (moduleName, path, files, message, Monitor);
			} catch (VersionControlException e) {
				Monitor.ReportError (e.Message, null);
				return;
			}

			Monitor.ReportSuccess (GettextCatalog.GetString ("Publish operation completed."));
			
			Gtk.Application.Invoke (delegate {
				VersionControlService.NotifyFileStatusChanged (new FileUpdateEventArgs (vc, path, true));
			});
		}
	}
}