View | Details | Raw Unified | Return to bug 551688
Collapse All | Expand All

(-)MonoDevelop.AspNet/MonoDevelop.AspNet.csproj (+1 lines)
Lines 318-323 Link Here
318
    <Compile Include="MonoDevelop.AspNet\AspNetSyntaxMode.cs" />
318
    <Compile Include="MonoDevelop.AspNet\AspNetSyntaxMode.cs" />
319
    <Compile Include="MonoDevelop.AspNet\AspNetMSBuildImportProvider.cs" />
319
    <Compile Include="MonoDevelop.AspNet\AspNetMSBuildImportProvider.cs" />
320
    <Compile Include="MonoDevelop.Html\PathCompletion.cs" />
320
    <Compile Include="MonoDevelop.Html\PathCompletion.cs" />
321
    <Compile Include="MonoDevelop.AspNet\SwapCodeBehindCommand.cs" />
321
  </ItemGroup>
322
  </ItemGroup>
322
  <ItemGroup>
323
  <ItemGroup>
323
    <None Include="Makefile.am" />
324
    <None Include="Makefile.am" />
(-)MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetCommands.cs (+1 lines)
Lines 34-38 Link Here
34
	public enum AspNetCommands
34
	public enum AspNetCommands
35
	{
35
	{
36
		AddAspNetDirectory,
36
		AddAspNetDirectory,
37
		SwapCodeBehind
37
	}
38
	}
38
}
39
}
(-)MonoDevelop.AspNet/MonoDevelop.AspNet/SwapCodeBehindCommand.cs (+107 lines)
Line 0 Link Here
1
// 
2
// SwapCodeBehindCommand.cs
3
//  
4
// Author:
5
//       cwensley <>
6
// 
7
// Copyright (c) 2009 cwensley
8
// 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
15
// 
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
18
// 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
// THE SOFTWARE.
26
27
using System;
28
using MonoDevelop.Components.Commands;
29
using System.IO;
30
using MonoDevelop.Projects;
31
using MonoDevelop.Ide.Gui;
32
using System.Linq;
33
34
namespace MonoDevelop.AspNet
35
{
36
	/// <summary>
37
	/// Swaps between the .aspx/.ascx/etc and the code behind file
38
	/// </summary>
39
	public class SwapCodeBehindCommand : CommandHandler
40
	{
41
		// TODO: Move to AspNetAppProject?
42
		public static string[] HeaderExtensions = {
43
			".ASPX",
44
			".ASCX",
45
			".ASHX",
46
			".MASTER"
47
		};
48
49
		// TODO: Move to AspNetAppProject?
50
		public static bool IsHeaderFile (string filename)
51
		{
52
			string extension = Path.GetExtension (filename).ToUpper ();
53
			return HeaderExtensions.Any(a => a.EndsWith(extension));
54
		}
55
56
		// TODO: Move to AspNetAppProject?
57
		public string MatchingFile (AspNetAppProject ap, string sourceFile) {
58
			string filenameStub;
59
			if (IsHeaderFile(sourceFile))
60
				filenameStub = ap.LanguageBinding.GetFileName(sourceFile);
61
			else if (ap.LanguageBinding.IsSourceCodeFile(sourceFile))
62
				filenameStub = Path.Combine(Path.GetDirectoryName(sourceFile), Path.GetFileNameWithoutExtension (sourceFile));
63
			else
64
				return null;
65
			
66
			ProjectFile file = ap.GetProjectFile(filenameStub);
67
			if (file != null)
68
				return file.Name;
69
			
70
			return null;
71
		}
72
73
		protected override void Run ()
74
		{
75
			var doc = IdeApp.Workbench.ActiveDocument;
76
			if (doc == null)
77
				return;
78
			
79
			var ap = doc.Project as AspNetAppProject;
80
			if (ap != null) {
81
				string match = MatchingFile (ap, doc.FileName);
82
				
83
				if (match != null)
84
					IdeApp.Workbench.OpenDocument (match);
85
			}
86
		}
87
88
		protected override void Update (CommandInfo info)
89
		{
90
			info.Visible = false;
91
			
92
			var doc = IdeApp.Workbench.ActiveDocument;
93
			if (doc == null)
94
				return;
95
			
96
			var ap = doc.Project as AspNetAppProject;
97
			if (ap == null)
98
				return;
99
			
100
			info.Visible = true;
101
			
102
			string filename = doc.FileName;
103
			info.Enabled = (IsHeaderFile (filename) || ap.LanguageBinding.IsSourceCodeFile(filename))
104
				&& MatchingFile (ap, doc.FileName) != null;
105
		}
106
	}
107
}
(-)MonoDevelop.AspNet/MonoDevelop.AspNet.addin.xml (+6 lines)
Lines 167-172 Link Here
167
		<Command id = "MonoDevelop.AspNet.Deployment.WebDeployCommands.DeployProject"
167
		<Command id = "MonoDevelop.AspNet.Deployment.WebDeployCommands.DeployProject"
168
		         defaultHandler = "MonoDevelop.AspNet.Deployment.ProjectDeployHandler"
168
		         defaultHandler = "MonoDevelop.AspNet.Deployment.ProjectDeployHandler"
169
		         _label = "Deploy to Web..." />
169
		         _label = "Deploy to Web..." />
170
		<Command id = "MonoDevelop.AspNet.AspNetCommands.SwapCodeBehind" 
171
			_label = "Swap Code Behind/Designer"
172
			shortcut = "F7"
173
			_description = "Swap code behind/designer display"
174
			defaultHandler="MonoDevelop.AspNet.SwapCodeBehindCommand"
175
		/>
170
		</Category>
176
		</Category>
171
	</Extension>
177
	</Extension>
172
	
178
	
(-)MonoDevelop.AspNet/Makefile.am (+1 lines)
Lines 121-126 Link Here
121
	MonoDevelop.AspNet/MasterContentFileDescriptionTemplate.cs \
121
	MonoDevelop.AspNet/MasterContentFileDescriptionTemplate.cs \
122
	MonoDevelop.AspNet/ProjectFolderNodeBuilderExtension.cs \
122
	MonoDevelop.AspNet/ProjectFolderNodeBuilderExtension.cs \
123
	MonoDevelop.AspNet/ProjectRegisteredControls.cs \
123
	MonoDevelop.AspNet/ProjectRegisteredControls.cs \
124
	MonoDevelop.AspNet/SwapCodeBehindCommand.cs \
124
	MonoDevelop.AspNet/VerifyCodeBehindBuildStep.cs \
125
	MonoDevelop.AspNet/VerifyCodeBehindBuildStep.cs \
125
	MonoDevelop.AspNet/WebTypeManager.cs \
126
	MonoDevelop.AspNet/WebTypeManager.cs \
126
	MonoDevelop.AspNet/XspParameters.cs \
127
	MonoDevelop.AspNet/XspParameters.cs \

Return to bug 551688