~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/SystemFileNodeBuilder.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
using MonoDevelop.Ide.Gui;
38
38
using MonoDevelop.Components.Commands;
39
39
using MonoDevelop.Ide.Gui.Components;
 
40
using System.Collections.Generic;
 
41
using System.Linq;
40
42
 
41
43
namespace MonoDevelop.Ide.Gui.Pads.ProjectPad
42
44
{
118
120
                        IdeApp.Workbench.OpenDocument (file.Path);
119
121
                }
120
122
                
121
 
                public override void DeleteItem ()
 
123
                public override void DeleteMultipleItems ()
122
124
                {
123
 
                        SystemFile file = CurrentNode.DataItem as SystemFile;
124
 
                        
125
 
                        bool yes = MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to permanently delete the file {0}?", file.Path), AlertButton.Delete);
126
 
                        if (!yes) return;
127
 
 
128
 
                        try {
129
 
                                FileService.DeleteFile (file.Path);
130
 
                        } catch {
131
 
                                MessageService.ShowError (GettextCatalog.GetString ("The file {0} could not be deleted", file.Path));
 
125
                        if (CurrentNodes.Length == 1) {
 
126
                                SystemFile file = (SystemFile)CurrentNodes[0].DataItem;
 
127
                                if (!MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to permanently delete the file {0}?", file.Path), AlertButton.Delete))
 
128
                                        return;
 
129
                        } else {
 
130
                                if (!MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to permanently delete all selected files?"), AlertButton.Delete))
 
131
                                        return;
 
132
                        }
 
133
                        foreach (SystemFile file in CurrentNodes.Select (n => (SystemFile)n.DataItem)) {
 
134
                                try {
 
135
                                        FileService.DeleteFile (file.Path);
 
136
                                } catch {
 
137
                                        MessageService.ShowError (GettextCatalog.GetString ("The file {0} could not be deleted", file.Path));
 
138
                                }
132
139
                        }
133
140
                }
134
141
                
143
150
                {
144
151
                        Set<SolutionEntityItem> projects = new Set<SolutionEntityItem> ();
145
152
                        Set<Solution> solutions = new Set<Solution> ();
146
 
                        foreach (ITreeNavigator node in CurrentNodes) {
147
 
                                SystemFile file = (SystemFile) node.DataItem;
148
 
                                Project project = node.GetParentDataItem (typeof(Project), true) as Project;
149
 
                                if (project != null) {
150
 
                                        project.AddFile (file.Path);
151
 
                                        projects.Add (project);
152
 
                                }
153
 
                                else {
154
 
                                        SolutionFolder folder = node.GetParentDataItem (typeof(SolutionFolder), true) as SolutionFolder;
155
 
                                        if (folder != null) {
156
 
                                                folder.Files.Add (file.Path);
157
 
                                                solutions.Add (folder.ParentSolution);
 
153
                        var nodesByProject = CurrentNodes.GroupBy (n => n.GetParentDataItem (typeof(Project), true) as Project);
 
154
                        
 
155
                        foreach (var projectGroup in nodesByProject) {
 
156
                                Project project = projectGroup.Key;
 
157
                                List<FilePath> newFiles = new List<FilePath> ();
 
158
                                foreach (ITreeNavigator node in projectGroup) {
 
159
                                        SystemFile file = (SystemFile) node.DataItem;
 
160
                                        if (project != null) {
 
161
                                                newFiles.Add (file.Path);
 
162
                                                projects.Add (project);
158
163
                                        }
159
164
                                        else {
160
 
                                                Solution sol = node.GetParentDataItem (typeof(Solution), true) as Solution;
161
 
                                                sol.RootFolder.Files.Add (file.Path);
162
 
                                                solutions.Add (sol);
 
165
                                                SolutionFolder folder = node.GetParentDataItem (typeof(SolutionFolder), true) as SolutionFolder;
 
166
                                                if (folder != null) {
 
167
                                                        folder.Files.Add (file.Path);
 
168
                                                        solutions.Add (folder.ParentSolution);
 
169
                                                }
 
170
                                                else {
 
171
                                                        Solution sol = node.GetParentDataItem (typeof(Solution), true) as Solution;
 
172
                                                        sol.RootFolder.Files.Add (file.Path);
 
173
                                                        solutions.Add (sol);
 
174
                                                }
163
175
                                        }
164
176
                                }
 
177
                                if (newFiles.Count > 0)
 
178
                                        project.AddFiles (newFiles);
165
179
                        }
166
180
                        IdeApp.ProjectOperations.Save (projects);
167
181
                        foreach (Solution sol in solutions)
191
205
                [CommandUpdateHandler (ViewCommands.OpenWithList)]
192
206
                public void OnOpenWithUpdate (CommandArrayInfo info)
193
207
                {
194
 
                        SystemFile file = CurrentNode.DataItem as SystemFile;
195
 
                        FileViewer prev = null; 
196
 
                        foreach (FileViewer fv in IdeApp.Workbench.GetFileViewers (file.Path)) {
197
 
                                if (prev != null && fv.IsExternal != prev.IsExternal)
198
 
                                        info.AddSeparator ();
199
 
                                info.Add (fv.Title, fv);
200
 
                                prev = fv;
201
 
                        }
 
208
                        ProjectFileNodeCommandHandler.PopulateOpenWithViewers (info, null, ((SystemFile) CurrentNode.DataItem).Path);
202
209
                }
203
210
        }
204
211
}