Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Experiments / Attic / Generator / Castle.ActiveRecord.Generator / Actions / ProjectOpenAction.cs
blob662c6d49008527f7d5fc6644ff87de8c0b178603
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Generator.Actions
17 using System;
18 using System.IO;
19 using System.Windows.Forms;
20 using System.Runtime.Serialization.Formatters.Binary;
22 using Castle.ActiveRecord.Generator.Components;
25 public class ProjectOpenAction : AbstractAction
27 private ToolBarButton _button;
29 public ProjectOpenAction()
33 #region IAction Members
35 public override void Install(IWorkspace workspace, object parentMenu, object parentGroup)
37 base.Install(workspace, parentMenu, parentGroup);
39 MenuItem item = new MenuItem("&Open...");
41 item.Click += new EventHandler(OnOpen);
43 (parentMenu as MenuItem).MenuItems.Add(item);
45 _button = new ToolBarButton();
46 _button.ToolTipText = "Open";
47 _button.ImageIndex = 1;
49 (parentGroup as ToolBar).Buttons.Add( _button );
50 (parentGroup as ToolBar).ButtonClick += new ToolBarButtonClickEventHandler(OnButtonClick);
53 #endregion
55 private void OnOpen(object sender, EventArgs e)
57 String filename = null;
59 using (OpenFileDialog dlg = new OpenFileDialog())
61 dlg.CheckFileExists = true;
62 dlg.CheckPathExists = true;
63 dlg.Multiselect = false;
64 dlg.ShowReadOnly = false;
65 dlg.DefaultExt = ".arproj";
67 if (dlg.ShowDialog(Workspace.ActiveWindow) == DialogResult.OK)
69 filename = dlg.FileName;
73 try
75 using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
77 BinaryFormatter formatter = new BinaryFormatter();
79 Model.CurrentProject = formatter.Deserialize( fs ) as Project;
82 Model.Filename = filename;
84 catch(Exception ex)
86 Model.CurrentProject = new Project();
88 MessageBox.Show(Workspace.ActiveWindow, ex.Message, "Error opening project");
92 private void OnButtonClick(object sender, ToolBarButtonClickEventArgs e)
94 if (e.Button == _button)
96 OnOpen(sender, e);