~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// FileScout.cs
 
2
//
 
3
// Author:
 
4
//   John Luke  <john.luke@gmail.com>
 
5
//
 
6
// Copyright (c) 2004 John Luke
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
//
 
26
//
 
27
 
 
28
using System;
 
29
using System.IO;
 
30
 
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Ide.Gui;
 
33
using MonoDevelop.Ide.Gui.Components;
 
34
using MonoDevelop.Projects;
 
35
using MonoDevelop.Components.Docking;
 
36
 
 
37
namespace MonoDevelop.Ide.Gui.Pads
 
38
{
 
39
        internal class FileScout : Gtk.VPaned, IPadContent
 
40
        {
 
41
                PadFontChanger fontChanger;
 
42
                
 
43
                public string Id {
 
44
                        get { return "MonoDevelop.Ide.Gui.Pads.FileScout"; }
 
45
                }
 
46
                
 
47
                public string DefaultPlacement {
 
48
                        get { return "Left"; }
 
49
                }
 
50
 
 
51
                public Gtk.Widget Control {
 
52
                        get {
 
53
                                return this;
 
54
                        }
 
55
                }
 
56
                
 
57
                public void RedrawContent()
 
58
                {
 
59
                }
 
60
                
 
61
                FileList filelister = new FileList ();
 
62
                FileBrowser fb = new FileBrowser ();
 
63
 
 
64
                public FileScout()
 
65
                {
 
66
                        string path = IdeApp.ProjectOperations.ProjectsDefaultPath;
 
67
 
 
68
                        if (Directory.Exists(path))
 
69
                        {
 
70
                                fb.CurrentDir = path;
 
71
                        }
 
72
 
 
73
                        fb.DirectoryChangedEvent += new DirectoryChangedEventHandler (OnDirChanged);
 
74
                        filelister.RowActivated += new Gtk.RowActivatedHandler (FileSelected);
 
75
                        IdeApp.Workspace.FirstWorkspaceItemOpened += OnCombineOpened;
 
76
                        IdeApp.Workspace.LastWorkspaceItemClosed += OnCombineClosed;
 
77
 
 
78
                        Gtk.ScrolledWindow listsw = new Gtk.ScrolledWindow ();
 
79
                        listsw.Add (filelister);
 
80
                        
 
81
                        fontChanger = new PadFontChanger (listsw, delegate (Pango.FontDescription desc) {
 
82
                                filelister.SetCustomFont (desc);
 
83
                                fb.SetCustomFont (desc);
 
84
                        }, delegate () {
 
85
                                filelister.ColumnsAutosize ();
 
86
                                fb.ColumnsAutosize ();
 
87
                        });
 
88
                        
 
89
                        this.Pack1 (fb, true, true);
 
90
                        this.Pack2 (listsw, true, true);
 
91
 
 
92
                        fb.SelectFirst ();
 
93
                        
 
94
                        OnDirChanged (fb.CurrentDir);
 
95
                        this.ShowAll ();
 
96
                }
 
97
                
 
98
                public void Initialize (IPadWindow window)
 
99
                {
 
100
                        DockItemToolbar toolbar = window.GetToolbar (Gtk.PositionType.Top);
 
101
                        
 
102
                        Gtk.Button goUp = new Gtk.Button (new Gtk.Image (Gtk.Stock.GoUp, Gtk.IconSize.Menu));
 
103
                        goUp.TooltipText = GettextCatalog.GetString ("Go up one level");
 
104
                        goUp.Clicked += delegate {
 
105
                                fb.GoUp ();
 
106
                        };
 
107
                        toolbar.Add (goUp);
 
108
                        
 
109
                        Gtk.Button goHome = new Gtk.Button (new Gtk.Image (Gtk.Stock.Home, Gtk.IconSize.Menu));
 
110
                        goHome.TooltipText = GettextCatalog.GetString ("Home");
 
111
                        goHome.Clicked += delegate {
 
112
                                fb.GoHome ();
 
113
                        };
 
114
                        toolbar.Add (goHome);
 
115
                        
 
116
                        Gtk.Entry entry = new Gtk.Entry ();
 
117
                        entry.TooltipText = GettextCatalog.GetString ("Location");
 
118
                        entry.Activated += delegate {
 
119
                                fb.GoPath (entry.Text);
 
120
                        };
 
121
                        
 
122
                        fb.DirectoryChangedEvent += delegate {
 
123
                                entry.Text = fb.CurrentDir;
 
124
                                goUp.Sensitive = System.IO.Path.GetPathRoot (fb.CurrentDir) != fb.CurrentDir;
 
125
                        };
 
126
                        toolbar.Add (entry, true);
 
127
                        toolbar.ShowAll ();
 
128
                }
 
129
 
 
130
 
 
131
                void OnDirChanged (string path) 
 
132
                {
 
133
                        filelister.Clear ();
 
134
 
 
135
                        bool ignoreHidden = !PropertyService.Get ("MonoDevelop.Core.Gui.FileScout.ShowHidden", false);
 
136
                        fb.IgnoreHidden = ignoreHidden;
 
137
 
 
138
                        foreach (string f in fb.Files)
 
139
                        {
 
140
                                try
 
141
                                {
 
142
                                        if (System.IO.File.Exists(f))
 
143
                                        {
 
144
                                                if (!(System.IO.Path.GetFileName (f)).StartsWith ("."))
 
145
                                                {
 
146
                                                        FileListItem it = new FileListItem (f);
 
147
                                                        filelister.ItemAdded (it);
 
148
                                                }
 
149
                                                else
 
150
                                                {
 
151
                                                        if (!ignoreHidden)
 
152
                                                        {
 
153
                                                                FileListItem it = new FileListItem (f);
 
154
                                                                filelister.ItemAdded (it);
 
155
                                                        
 
156
                                                        }
 
157
                                                }
 
158
                                        }
 
159
                                }
 
160
                                catch (IOException) {} // Avoid crash on file existence check error
 
161
                        }
 
162
                }
 
163
 
 
164
                void FileSelected (object sender, Gtk.RowActivatedArgs e)
 
165
                {
 
166
                        Gtk.TreeIter iter;
 
167
                        Gtk.TreeModel model;
 
168
 
 
169
                        // we are not using SelectMultiple
 
170
                        // nor can more than one be activated here
 
171
                        if (filelister.Selection.GetSelected (out model, out iter))
 
172
                        {
 
173
                                FileListItem item = (FileListItem) filelister.Model.GetValue (iter, 3);
 
174
 
 
175
                                //FIXME: use mimetypes not extensions
 
176
                                // also change to Project tab when its a project
 
177
                                if (Services.ProjectService.IsWorkspaceItemFile (item.FullName))
 
178
                                        IdeApp.Workspace.OpenWorkspaceItem (item.FullName);
 
179
                                else
 
180
                                        IdeApp.Workbench.OpenDocument (item.FullName);
 
181
                        }
 
182
                }
 
183
 
 
184
                void OnCombineOpened(object sender, WorkspaceItemEventArgs args)
 
185
                {
 
186
                        try {
 
187
                                Solution sol = args.Item as Solution;
 
188
                                if (sol != null && sol.StartupItem != null)
 
189
                                        fb.CurrentDir = sol.StartupItem.BaseDirectory;
 
190
                        } catch {
 
191
                                fb.CurrentDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
 
192
                        }
 
193
                }
 
194
 
 
195
                void OnCombineClosed(object sender, EventArgs args)
 
196
                {
 
197
                        fb.CurrentDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
 
198
                }
 
199
                
 
200
                public override void Dispose ()
 
201
                {
 
202
                        fontChanger.Dispose ();
 
203
                        base.Dispose ();
 
204
                }
 
205
 
 
206
        }
 
207
}