1:   //  FileCommands.cs
2:   //  Copyright (C) 2002 Mike Krueger
3:   //
4:   //  This program is free software; you can redistribute it and/or modify
5:   //  it under the terms of the GNU General Public License as published by
6:   //  the Free Software Foundation; either version 2 of the License, or
7:   //  (at your option) any later version.
8:   //
9:   //  This program is distributed in the hope that it will be useful,
10:   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11:   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12:   //  GNU General Public License for more details.
13:   //
14:   //  You should have received a copy of the GNU General Public License
15:   //  along with this program; if not, write to the Free Software
16:   //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17:  
18:   using System;
19:   using System.IO;
20:   using System.Threading;
21:   using System.Drawing;
22:   using System.Drawing.Printing;
23:   using System.Collections;
24:   using System.ComponentModel;
25:   using System.Windows.Forms;
26:   using System.Diagnostics;
27:  
28:   using Core.AddIns;
29:   using Core.Util;
30:   using Core.Properties;
31:   using Core.Gui;
32:   using Core.Gui.Creators;
33:  
34:   using SharpDevelop.Gui;
35:   using SharpDevelop.Gui.Dialogs;
36:  
37:   namespace SharpDevelop.Base.Commands {
38:       
39:       public class CreateNewProject : AbstractMenuCommand
40:       {
41:           public override void Run()
42:           {
43:               NewProjectDialog npdlg new NewProjectDialog();
44:               npdlg.Owner = (Form)WorkbenchSingleton.Workbench;
45:               if (npdlg.ShowDialog() == DialogResult.OK) {
46:                   WorkbenchSingleton.Workbench.OpenCombine(npdlg.NewCombineLocation);
47:               }
48:               npdlg.Dispose();
49:           }
50:       }
51:       
52:       public class CreateNewFile : AbstractMenuCommand
53:       {
54:           public override void Run()
55:           {
56:               NewFileDialog nfd new NewFileDialog();
57:               nfd.Owner = (Form)WorkbenchSingleton.Workbench;
58:               nfd.ShowDialog();
59:               nfd.Dispose();
60:           }
61:       }
62:       
63:       public class CloseFile : AbstractMenuCommand
64:       {
65:           public override void Run()
66:           {
67:               WorkbenchSingleton.Workbench.CloseActiveFile();
68:           }
69:       }
70:  
71:       public class SaveFile : AbstractMenuCommand
72:       {
73:           public override void Run()
74:           {
75:               IWorkbenchWindow window WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
76:               
77:               if (window != null) {
78:                   if (window.WindowContent.ContentName == null) {
79:                       SaveFileAs sfa new SaveFileAs();
80:                       sfa.Run();
81:                   else {
82:                       WorkbenchSingleton.Workbench.ProjectManager.MarkFileDirty(window.WindowContent.ContentName);
83:                       window.WindowContent.SaveFile();
84:                   }
85:               }
86:           }
87:       }
88:  
89:       public class ReloadFile : AbstractMenuCommand
90:       {
91:           public override void Run()
92:           {
93:               IWorkbenchWindow window WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
94:               
95:               if (window != null && window.WindowContent.ContentName != null) {
96:                   IXmlConvertable memento null;
97:                   if (window.WindowContent is IMementoable) {
98:                       memento = ((IMementoable)window.WindowContent).CreateMemento();
99:                   }
100:                   window.WindowContent.LoadFile(window.WindowContent.ContentName);
101:                   
102:                   if (memento != null) {
103:                       ((IMementoable)window.WindowContent).SetMemento(memento);
104:                   }
105:               }
106:           }
107:       }
108:       
109:       public class SaveFileAs : AbstractMenuCommand
110:       {
111:           public override void Run()
112:           {
113:               IWorkbenchWindow window WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
114:               
115:               if (window != null) {
116:                   SaveFileDialog fdiag new SaveFileDialog();
117:                   fdiag.OverwritePrompt true;
118:                   fdiag.AddExtension    true;
119:                   
120:                   fdiag.Filter          String.Join("|", (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string)));
121:                   
122:                   if (fdiag.ShowDialog() == DialogResult.OK) {
123:                       string fileName fdiag.FileName;
124:                       // currently useless, because the fdiag.FileName can't
125:                       // handle wildcard extensions :(
126:                       if (Path.GetExtension(fileName).StartsWith("?") || Path.GetExtension(fileName) == "*") {
127:                           fileName Path.ChangeExtension(fileName"");
128:                       }
129:                           
130:                       window.WindowContent.SaveFile(fileName);
131:                       MessageBox.Show(fileName"File saved"MessageBoxButtons.OK);
132:                   }
133:                   fdiag.Dispose();
134:               }
135:           }
136:       }
137:       
138:       public class SaveAllFiles : AbstractMenuCommand
139:       {
140:           public override void Run()
141:           {
142:               foreach (IWindowContent content in WorkbenchSingleton.Workbench.WindowContentCollection) {
143:                   if (content.ContentName == null) {
144:                       SaveFileDialog fdiag new SaveFileDialog();
145:                       fdiag.OverwritePrompt true;
146:                       fdiag.AddExtension    true;
147:                       
148:                       fdiag.Filter          String.Join("|", (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string)));
149:                       
150:                       if (fdiag.ShowDialog() == DialogResult.OK) {
151:                           string fileName fdiag.FileName;
152:                           // currently useless, because the fdiag.FileName can't
153:                           // handle wildcard extensions :(
154:                           if (Path.GetExtension(fileName).StartsWith("?") || Path.GetExtension(fileName) == "*") {
155:                               fileName Path.ChangeExtension(fileName"");
156:                           }
157:                               
158:                           content.SaveFile(fileName);
159:                           MessageBox.Show(fileName"File saved"MessageBoxButtons.OK);
160:                       }
161:                       fdiag.Dispose();
162:                   else {
163:                       content.SaveFile();
164:                   }
165:               }
166:           }
167:       }
168:       
169:       public class OpenCombine : AbstractMenuCommand
170:       {
171:           public override void Run()
172:           {
173:               OpenFileDialog fdiag  new OpenFileDialog();
174:               fdiag.AddExtension    true;
175:               fdiag.Filter          String.Join("|", (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/Combine/FileFilter").BuildChildItems(this)).ToArray(typeof(string)));
176:               fdiag.Multiselect     false;
177:               fdiag.CheckFileExists true;
178:               if (fdiag.ShowDialog() == DialogResult.OK) {
179:                   switch (Path.GetExtension(fdiag.FileName).ToUpper()) {
180:                       case ".CMBX":
181:                       case ".PRJX":
182:                           WorkbenchSingleton.Workbench.OpenCombine(fdiag.FileName);
183:                           break;
184:                       default:
185:                           MessageBox.Show("Can't open file " fdiag.FileName "as project""Error"MessageBoxButtons.OKMessageBoxIcon.Error);
186:                           break;
187:                   }
188:               }
189:               fdiag.Dispose();
190:           }
191:       }
192:       
193:       public class OpenFile : AbstractMenuCommand
194:       {
195:           public override void Run()
196:           {
197:               OpenFileDialog fdiag  new OpenFileDialog();
198:               fdiag.AddExtension    true;
199:               
200:               string filter String.Join("|", (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string)));
201:               fdiag.Filter          filter;
202:               
203:               fdiag.Multiselect     true;
204:               fdiag.CheckFileExists true;
205:               
206:               if (fdiag.ShowDialog() == DialogResult.OK) {
207:                   foreach (string name in fdiag.FileNames) {
208:                       WorkbenchSingleton.Workbench.OpenFile(name);
209:                   }
210:               }
211:               fdiag.Dispose();
212:           }
213:       }
214:       
215:       public class ClearCombine : AbstractMenuCommand
216:       {
217:           public override void Run()
218:           {
219:               WorkbenchSingleton.Workbench.ProjectManager.ClearCombine();
220:               WorkbenchSingleton.Workbench.CloseAllFiles();
221:           }
222:       }
223:           
224:       public class ExitWorkbenchCommand : AbstractMenuCommand
225:       {
226:           public override void Run()
227:           {
228:               ((Form)WorkbenchSingleton.Workbench).Close();
229:           }
230:       }
231:       
232:       public class Print : AbstractMenuCommand
233:       {
234:           public override void Run()
235:           {
236:               IWorkbenchWindow window WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
237:               
238:               if (window != null) {
239:                   if (window.WindowContent is IPrintable) {
240:                       PrintDocument pdoc = ((IPrintable)window.WindowContent).PrintDocument;
241:                       if (pdoc != null) {
242:                           PrintDialog ppd new PrintDialog();
243:                           ppd.Document  pdoc;
244:                           ppd.AllowSomePages true;
245:                           if (ppd.ShowDialog() == DialogResult.OK) { // fixed by Roger Rubin
246:                               pdoc.Print();
247:                           }
248:                       else {
249:                           MessageBox.Show("Couldn't create PrintDocument""Error"MessageBoxButtons.OKMessageBoxIcon.Error);
250:                       }
251:                   else {
252:                       MessageBox.Show("Can't print this window content""Error"MessageBoxButtons.OKMessageBoxIcon.Error);
253:                   }
254:               }
255:           }
256:       }
257:       
258:       public class PrintPreview : AbstractMenuCommand
259:       {
260:           public override void Run()
261:           {
262:               try {
263:                   IWorkbenchWindow window WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
264:                   
265:                   if (window != null) {
266:                       if (window.WindowContent is IPrintable) {
267:                           PrintDocument pdoc = ((IPrintable)window.WindowContent).PrintDocument;
268:                           if (pdoc != null) {
269:                               PrintPreviewDialog ppd new PrintPreviewDialog();
270:                               ppd.Owner     = (Form)WorkbenchSingleton.Workbench;
271:                               ppd.TopMost   true;
272:                               ppd.Document  pdoc;
273:                               ppd.Show();
274:                           else {
275:                               MessageBox.Show("Couldn't create PrintDocument""Error"MessageBoxButtons.OKMessageBoxIcon.Error);
276:                           }
277:                       }
278:                   }
279:               catch (System.Drawing.Printing.InvalidPrinterException) {
280:               }
281:           }
282:       }    
283:       
284:   }

This page was automatically generated by SharpDevelop.