Datei: NDOPackage/Commands/AddPersistentClass.cs
Last Commit (946ad0e)
1 | using Microsoft.VisualStudio; |
2 | using Microsoft.VisualStudio.Shell.Interop; |
3 | using Project = EnvDTE.Project; |
4 | |
5 | namespace NDOVsPackage.Commands |
6 | { |
7 | ····[Command(PackageGuids.guidNDOPackageCmdSetString, PackageIds.cmdidAddClass)] |
8 | ····internal sealed class AddPersistentClass : BaseCommand<AddPersistentClass> |
9 | ····{ |
10 | protected override async Task ExecuteAsync( OleMenuCmdEventArgs e) |
11 | ········{ |
12 | ············await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
13 | System. Array solObjects = ( Array) this. VisualStudioApplication. ActiveSolutionProjects; |
14 | ············if (solObjects.Length < 1) |
15 | ················return; |
16 | |
17 | ············Project project = (Project) solObjects.GetValue( 0 ); |
18 | |
19 | if ( !( CodeGenHelper. IsCsOrVbProject( project) ) ) |
20 | ················return; |
21 | |
22 | ············PersistentClassDialog pcd = new PersistentClassDialog(); |
23 | ············pcd.ShowDialog(); |
24 | ············if (pcd.Result == DialogResult.Cancel) |
25 | ················return; |
26 | |
27 | SelectedItems selItems = VisualStudioApplication. SelectedItems; |
28 | ············ProjectItem parentItem = null; |
29 | ············if (selItems.Count == 1) |
30 | ············{ |
31 | ················IEnumerator ienum = selItems.GetEnumerator(); |
32 | ················ienum.MoveNext(); |
33 | ················SelectedItem si = (SelectedItem) ienum.Current; |
34 | ················if (si.ProjectItem != null && si.ProjectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}") // Folder |
35 | ····················parentItem = si.ProjectItem; |
36 | ············} |
37 | |
38 | ············if (CodeGenHelper.IsVbProject( project )) |
39 | ················new AddPersistentClassVb( project, pcd.ClassName, pcd.Serializable, parentItem ).DoIt(); |
40 | ············else if (CodeGenHelper.IsCsProject( project )) |
41 | ················new AddPersistentClassCs( project, pcd.ClassName, pcd.Serializable, parentItem ).DoIt(); |
42 | ········} |
43 | ············catch (Exception ex) |
44 | ············{ |
45 | Debug. WriteLine( ex. ToString( ) ) ; |
46 | MessageBox. Show( ex. Message, "Configure" ) ; |
47 | ············} |
48 | } |
49 | |
50 | ········protected override void BeforeQueryStatus(EventArgs e) |
51 | ········{ |
52 | ············ThreadHelper.JoinableTaskFactory.Run(async () => |
53 | ············{ |
54 | ················var project = await VS.Solutions.GetActiveProjectAsync(); |
55 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
56 | ················var enabled = CodeGenHelper.IsCsOrVbProject(project); |
57 | ················Command.Enabled = enabled; |
58 | ············}); |
59 | ········} |
60 | ····} |
61 | } |
62 |
New Commit (33e9857)
1 | using Microsoft.VisualStudio; |
2 | using Microsoft.VisualStudio.Shell.Interop; |
3 | using System.Diagnostics; |
4 | using Project = EnvDTE.Project; |
5 | using MessageBox = System.Windows.Forms.MessageBox; |
6 | using System.Windows.Forms; |
7 | using EnvDTE; |
8 | using System.Collections; |
9 | |
10 | namespace NDOVsPackage.Commands |
11 | { |
12 | ····[Command(PackageGuids.guidNDOPackageCmdSetString, PackageIds.cmdidAddClass)] |
13 | ····internal sealed class AddPersistentClass : BaseCommand<AddPersistentClass> |
14 | ····{ |
15 | ········protected override async Task ExecuteAsync( OleMenuCmdEventArgs e ) |
16 | ········{ |
17 | try |
18 | ············{ |
19 | |
20 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
21 | System. Array solObjects = ( Array) ApplicationObject. VisualStudioApplication. ActiveSolutionProjects; |
22 | ················if (solObjects.Length < 1) |
23 | ····················return; |
24 | |
25 | ················Project project = (Project) solObjects.GetValue( 0 ); |
26 | |
27 | if ( !( CodeGenHelper. IsCsOrVbProject( project ) ) ) |
28 | ····················return; |
29 | |
30 | ················PersistentClassDialog pcd = new PersistentClassDialog(); |
31 | ················pcd.ShowDialog(); |
32 | ················if (pcd.Result == DialogResult.Cancel) |
33 | ····················return; |
34 | |
35 | SelectedItems selItems = ApplicationObject. VisualStudioApplication. SelectedItems; |
36 | ················ProjectItem parentItem = null; |
37 | ················if (selItems.Count == 1) |
38 | ················{ |
39 | ····················IEnumerator ienum = selItems.GetEnumerator(); |
40 | ····················ienum.MoveNext(); |
41 | ····················SelectedItem si = (SelectedItem) ienum.Current; |
42 | ····················if (si.ProjectItem != null && si.ProjectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}") // Folder |
43 | ························parentItem = si.ProjectItem; |
44 | ················} |
45 | |
46 | ················if (CodeGenHelper.IsVbProject( project )) |
47 | ····················new AddPersistentClassVb( project, pcd.ClassName, pcd.Serializable, parentItem ).DoIt(); |
48 | ················else if (CodeGenHelper.IsCsProject( project )) |
49 | ····················new AddPersistentClassCs( project, pcd.ClassName, pcd.Serializable, parentItem ).DoIt(); |
50 | ············} |
51 | ············catch (Exception ex) |
52 | ············{ |
53 | Debug. WriteLine( ex. ToString( ) ) ; |
54 | MessageBox. Show( ex. Message, "AddPersistentClass" ) ; |
55 | ············} |
56 | ········} |
57 | |
58 | ········protected override void BeforeQueryStatus(EventArgs e) |
59 | ········{ |
60 | ············ThreadHelper.JoinableTaskFactory.Run(async () => |
61 | ············{ |
62 | ················var project = await VS.Solutions.GetActiveProjectAsync(); |
63 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
64 | ················var enabled = CodeGenHelper.IsCsOrVbProject(project); |
65 | ················Command.Enabled = enabled; |
66 | ············}); |
67 | ········} |
68 | ····} |
69 | } |
70 |