~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta.Core/Actions/FileActions.cs

  • Committer: Iain Lane
  • Date: 2010-03-13 18:20:18 UTC
  • mfrom: (1.1.2)
  • Revision ID: git-v1:1781694a68ecf232d0110c0b2f3d4a1b96c74ec2
Merge commit 'upstream/0.2'

Conflicts:
        debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                
44
44
                public FileActions ()
45
45
                {
46
 
                        New = new Gtk.Action ("New", Mono.Unix.Catalog.GetString ("New"), null, "gtk-new");
47
 
                        Open = new Gtk.Action ("Open", Mono.Unix.Catalog.GetString ("Open"), null, "gtk-open");
 
46
                        New = new Gtk.Action ("New", Mono.Unix.Catalog.GetString ("New..."), null, "gtk-new");
 
47
                        Open = new Gtk.Action ("Open", Mono.Unix.Catalog.GetString ("Open..."), null, "gtk-open");
48
48
                        OpenRecent = new Gtk.Action ("OpenRecent", Mono.Unix.Catalog.GetString ("Open Recent"), null, "gtk-open");
49
49
                        Close = new Gtk.Action ("Close", Mono.Unix.Catalog.GetString ("Close"), null, "gtk-close");
50
50
                        Save = new Gtk.Action ("Save", Mono.Unix.Catalog.GetString ("Save"), null, "gtk-save");
51
 
                        SaveAs = new Gtk.Action ("SaveAs", Mono.Unix.Catalog.GetString ("Save As"), null, "gtk-save-as");
 
51
                        SaveAs = new Gtk.Action ("SaveAs", Mono.Unix.Catalog.GetString ("Save As..."), null, "gtk-save-as");
52
52
                        Print = new Gtk.Action ("Print", Mono.Unix.Catalog.GetString ("Print"), null, "gtk-print");
53
 
                        Exit = new Gtk.Action ("Exit", Mono.Unix.Catalog.GetString ("Exit"), null, "gtk-quit");
 
53
                        Exit = new Gtk.Action ("Exit", Mono.Unix.Catalog.GetString ("Quit"), null, "gtk-quit");
54
54
                        
55
55
                        OpenRecent.Sensitive = false;
56
56
                        Close.Sensitive = false;
84
84
                }
85
85
                #endregion
86
86
 
87
 
                #region Action Handlers
88
 
                private void HandlePintaCoreActionsFileOpenActivated (object sender, EventArgs e)
 
87
                #region Public Methods
 
88
                public void OpenFile (string file)
89
89
                {
90
 
                        Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Open Image File", PintaCore.Chrome.MainWindow, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);
91
 
                        
92
 
                        int response = fcd.Run ();
93
 
                        
94
 
                        if (response == (int)Gtk.ResponseType.Ok) {
95
 
                                
96
 
                                string file = fcd.Filename;
97
 
                                
 
90
                        try {
 
91
                                // Open the image and add it to the layers
 
92
                                Pixbuf bg = new Pixbuf (file);
 
93
 
98
94
                                PintaCore.Layers.Clear ();
99
95
                                PintaCore.History.Clear ();
100
96
                                PintaCore.Layers.DestroySelectionLayer ();
101
 
                                
102
 
                                // Open the image and add it to the layers
103
 
                                Pixbuf bg = new Pixbuf (file);
104
 
                                
105
 
                                PintaCore.Workspace.ImageSize = new Cairo.PointD (bg.Width, bg.Height);
106
 
                                PintaCore.Workspace.CanvasSize = new Cairo.PointD (bg.Width, bg.Height);
107
 
                                
 
97
 
 
98
                                PintaCore.Workspace.ImageSize = new Cairo.Point (bg.Width, bg.Height);
 
99
                                PintaCore.Workspace.CanvasSize = new Cairo.Point (bg.Width, bg.Height);
 
100
 
108
101
                                PintaCore.Layers.ResetSelectionPath ();
109
 
                                
 
102
 
110
103
                                Layer layer = PintaCore.Layers.AddNewLayer (System.IO.Path.GetFileName (file));
111
 
                                
 
104
 
112
105
                                using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
113
106
                                        CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
114
107
                                        g.Paint ();
115
108
                                }
116
 
                                
 
109
 
117
110
                                bg.Dispose ();
118
111
 
119
112
                                PintaCore.Workspace.Filename = System.IO.Path.GetFileName (file);
 
113
                                PintaCore.History.PushNewItem (new BaseHistoryItem ("gtk-open", "Open Image"));
120
114
                                PintaCore.Workspace.IsDirty = false;
121
 
 
 
115
                                PintaCore.Actions.View.ZoomToWindow.Activate ();
122
116
                                PintaCore.Workspace.Invalidate ();
123
 
                                PintaCore.Actions.View.ZoomToWindow.Activate ();
 
117
                        } catch {
 
118
                                MessageDialog md = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not open file: {0}", file);
 
119
                                md.Title = "Error";
 
120
                                
 
121
                                md.Run ();
 
122
                                md.Destroy ();
124
123
                        }
 
124
                }
 
125
                #endregion
 
126
                
 
127
                #region Action Handlers
 
128
                private void HandlePintaCoreActionsFileOpenActivated (object sender, EventArgs e)
 
129
                {
 
130
                        Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Open Image File", PintaCore.Chrome.MainWindow, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);
 
131
                        
 
132
                        int response = fcd.Run ();
 
133
                        
 
134
                        if (response == (int)Gtk.ResponseType.Ok)
 
135
                                OpenFile (fcd.Filename);
125
136
                        
126
137
                        fcd.Destroy ();
127
138
                }