4
// John Luke <john.luke@gmail.com>
6
// Copyright (c) 2004 John Luke
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:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
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
31
using MonoDevelop.Core;
32
using MonoDevelop.Ide.Gui;
33
using MonoDevelop.Ide.Gui.Components;
34
using MonoDevelop.Projects;
35
using MonoDevelop.Components.Docking;
37
namespace MonoDevelop.Ide.Gui.Pads
39
internal class FileScout : Gtk.VPaned, IPadContent
41
PadFontChanger fontChanger;
44
get { return "MonoDevelop.Ide.Gui.Pads.FileScout"; }
47
public string DefaultPlacement {
48
get { return "Left"; }
51
public Gtk.Widget Control {
57
public void RedrawContent()
61
FileList filelister = new FileList ();
62
FileBrowser fb = new FileBrowser ();
66
string path = IdeApp.ProjectOperations.ProjectsDefaultPath;
68
if (Directory.Exists(path))
73
fb.DirectoryChangedEvent += new DirectoryChangedEventHandler (OnDirChanged);
74
filelister.RowActivated += new Gtk.RowActivatedHandler (FileSelected);
75
IdeApp.Workspace.FirstWorkspaceItemOpened += OnCombineOpened;
76
IdeApp.Workspace.LastWorkspaceItemClosed += OnCombineClosed;
78
Gtk.ScrolledWindow listsw = new Gtk.ScrolledWindow ();
79
listsw.Add (filelister);
81
fontChanger = new PadFontChanger (listsw, delegate (Pango.FontDescription desc) {
82
filelister.SetCustomFont (desc);
83
fb.SetCustomFont (desc);
85
filelister.ColumnsAutosize ();
86
fb.ColumnsAutosize ();
89
this.Pack1 (fb, true, true);
90
this.Pack2 (listsw, true, true);
94
OnDirChanged (fb.CurrentDir);
98
public void Initialize (IPadWindow window)
100
DockItemToolbar toolbar = window.GetToolbar (Gtk.PositionType.Top);
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 {
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 {
114
toolbar.Add (goHome);
116
Gtk.Entry entry = new Gtk.Entry ();
117
entry.TooltipText = GettextCatalog.GetString ("Location");
118
entry.Activated += delegate {
119
fb.GoPath (entry.Text);
122
fb.DirectoryChangedEvent += delegate {
123
entry.Text = fb.CurrentDir;
124
goUp.Sensitive = System.IO.Path.GetPathRoot (fb.CurrentDir) != fb.CurrentDir;
126
toolbar.Add (entry, true);
131
void OnDirChanged (string path)
135
bool ignoreHidden = !PropertyService.Get ("MonoDevelop.Core.Gui.FileScout.ShowHidden", false);
136
fb.IgnoreHidden = ignoreHidden;
138
foreach (string f in fb.Files)
142
if (System.IO.File.Exists(f))
144
if (!(System.IO.Path.GetFileName (f)).StartsWith ("."))
146
FileListItem it = new FileListItem (f);
147
filelister.ItemAdded (it);
153
FileListItem it = new FileListItem (f);
154
filelister.ItemAdded (it);
160
catch (IOException) {} // Avoid crash on file existence check error
164
void FileSelected (object sender, Gtk.RowActivatedArgs e)
169
// we are not using SelectMultiple
170
// nor can more than one be activated here
171
if (filelister.Selection.GetSelected (out model, out iter))
173
FileListItem item = (FileListItem) filelister.Model.GetValue (iter, 3);
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);
180
IdeApp.Workbench.OpenDocument (item.FullName);
184
void OnCombineOpened(object sender, WorkspaceItemEventArgs args)
187
Solution sol = args.Item as Solution;
188
if (sol != null && sol.StartupItem != null)
189
fb.CurrentDir = sol.StartupItem.BaseDirectory;
191
fb.CurrentDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
195
void OnCombineClosed(object sender, EventArgs args)
197
fb.CurrentDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
200
public override void Dispose ()
202
fontChanger.Dispose ();