[Monodevelop-patches-list] r1527 - in trunk/MonoDevelop/src/Main/Base/Gui/Pads: . FileScout
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Tue Apr 27 18:43:33 EDT 2004
Author: jluke
Date: 2004-04-27 18:43:33 -0400 (Tue, 27 Apr 2004)
New Revision: 1527
Added:
trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/
trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileList.cs
trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileListItem.cs
trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileScout.cs
Log:
Added: trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileList.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileList.cs 2004-04-27 22:15:18 UTC (rev 1526)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileList.cs 2004-04-27 22:43:33 UTC (rev 1527)
@@ -0,0 +1,227 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Collections;
+
+using MonoDevelop.Core.Properties;
+using MonoDevelop.Core.Services;
+using MonoDevelop.Services;
+using MonoDevelop.Gui.Widgets;
+using MonoDevelop.Gui.Utils;
+
+namespace MonoDevelop.Gui.Pads
+{
+ public class FileList : Gtk.TreeView
+ {
+ private static GLib.GType gtype;
+ private FileSystemWatcher watcher;
+ private ArrayList Items;
+ private Gtk.TreeStore store;
+ private Gtk.Menu popmenu = null;
+ FileListItem selectedItem = null;
+ Gtk.TreeIter selectedIter;
+
+ public static new GLib.GType GType
+ {
+ get
+ {
+ if (gtype == GLib.GType.Invalid)
+ gtype = RegisterGType (typeof (FileList));
+ return gtype;
+ }
+ }
+
+ public FileList() : base (GType)
+ {
+ Items = new ArrayList ();
+ FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+
+ store = new Gtk.TreeStore (typeof (string), typeof (string), typeof(string), typeof(FileListItem), typeof (Gdk.Pixbuf));
+ Model = store;
+
+ HeadersVisible = true;
+ HeadersClickable = true;
+ Reorderable = true;
+ RulesHint = true;
+
+ Gtk.TreeViewColumn name_column = new Gtk.TreeViewColumn ();
+ name_column.Title = GettextCatalog.GetString ("Files");
+
+ Gtk.TreeViewColumn size_column = new Gtk.TreeViewColumn ();
+ size_column.Title = GettextCatalog.GetString ("Size");
+
+ Gtk.TreeViewColumn modi_column = new Gtk.TreeViewColumn ();
+ modi_column.Title = GettextCatalog.GetString ("Last modified");
+
+ Gtk.CellRendererPixbuf pix_render = new Gtk.CellRendererPixbuf ();
+ name_column.PackStart (pix_render, false);
+ name_column.AddAttribute (pix_render, "pixbuf", 4);
+
+ Gtk.CellRendererText render1 = new Gtk.CellRendererText ();
+ name_column.PackStart (render1, false);
+ name_column.AddAttribute (render1, "text", 0);
+
+ Gtk.CellRendererText render2 = new Gtk.CellRendererText ();
+ size_column.PackStart (render2, false);
+ size_column.AddAttribute (render2, "text", 1);
+
+ Gtk.CellRendererText render3 = new Gtk.CellRendererText ();
+ modi_column.PackStart (render3, false);
+ modi_column.AddAttribute (render3, "text", 2);
+
+ AppendColumn(name_column);
+ AppendColumn(size_column);
+ AppendColumn(modi_column);
+
+ this.PopupMenu += new Gtk.PopupMenuHandler (OnPopupMenu);
+ this.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler (OnButtonReleased);
+ this.Selection.Changed += OnSelectionChanged;
+
+ watcher = new FileSystemWatcher ();
+
+ if(watcher != null) {
+ watcher.NotifyFilter = NotifyFilters.FileName;
+ watcher.EnableRaisingEvents = false;
+
+ watcher.Renamed += new RenamedEventHandler(fileRenamed);
+ watcher.Deleted += new FileSystemEventHandler(fileDeleted);
+ watcher.Created += new FileSystemEventHandler(fileCreated);
+ watcher.Changed += new FileSystemEventHandler(fileChanged);
+ }
+ }
+
+ internal void ItemAdded(FileListItem item) {
+ store.AppendValues(item.Text, item.Size, item.LastModified, item, item.Icon);
+ }
+
+ void ItemRemoved (FileListItem item) {
+ Console.WriteLine ("remove called");
+ store.Remove (ref selectedIter);
+ }
+
+ internal void Clear() {
+ store.Clear();
+ }
+
+ void fileDeleted(object sender, FileSystemEventArgs e)
+ {
+ foreach(FileListItem fileItem in Items)
+ {
+ if(fileItem.FullName.ToLower() == e.FullPath.ToLower()) {
+ Items.Remove(fileItem);
+ break;
+ }
+ }
+ }
+
+ void fileChanged(object sender, FileSystemEventArgs e)
+ {
+ foreach(FileListItem fileItem in Items)
+ {
+ if(fileItem.FullName.ToLower() == e.FullPath.ToLower()) {
+
+ FileInfo info = new FileInfo(e.FullPath);
+ fileItem.Size = Math.Round((double)info.Length / 1024).ToString() + " KB";
+ fileItem.LastModified = info.LastWriteTime.ToString();
+ break;
+ }
+ }
+ }
+
+ void fileCreated(object sender, FileSystemEventArgs e)
+ {
+ FileInfo info = new FileInfo (e.FullPath);
+
+ FileListItem fileItem = new FileListItem (e.FullPath, Math.Round ((double) info.Length / 1024).ToString () + " KB", info.LastWriteTime.ToString ());
+
+ Items.Add (fileItem);
+ }
+
+ void fileRenamed(object sender, RenamedEventArgs e)
+ {
+ foreach(FileListItem fileItem in Items)
+ {
+ if(fileItem.FullName.ToLower() == e.OldFullPath.ToLower()) {
+ fileItem.FullName = e.FullPath;
+ //fileItem.Text = e.Name;
+ break;
+ }
+ }
+ }
+
+ private void OnRenameFile (object sender, EventArgs e)
+ {
+ /*
+ if(SelectedItems.Count == 1) {
+ //SelectedItems[0].BeginEdit();
+ }
+ */
+ }
+
+ private void OnDeleteFiles (object sender, EventArgs e)
+ {
+ IMessageService messageService =(IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
+
+ if (messageService.AskQuestion(GettextCatalog.GetString ("Are you sure you want to delete this file?"), GettextCatalog.GetString ("Delete files")))
+ {
+ try
+ {
+ File.Delete (selectedItem.FullName);
+ ItemRemoved (selectedItem);
+ }
+ catch (Exception ex)
+ {
+ messageService.ShowError (ex, "Could not delete file '" + System.IO.Path.GetFileName (selectedItem.FullName) + "'");
+ }
+ }
+ }
+
+ private void OnPopupMenu (object o, Gtk.PopupMenuArgs args)
+ {
+ ShowPopup ();
+ }
+
+ private void OnButtonReleased (object o, Gtk.ButtonReleaseEventArgs args)
+ {
+ if (args.Event.Button == 3)
+ ShowPopup ();
+ }
+
+ private void ShowPopup ()
+ {
+ Gtk.Menu menu = new Gtk.Menu ();
+
+ Gtk.MenuItem deleteFile = new Gtk.MenuItem (GettextCatalog.GetString ("Delete file"));
+ deleteFile.Activated += new EventHandler (OnDeleteFiles);
+
+ Gtk.MenuItem renameFile = new Gtk.MenuItem (GettextCatalog.GetString ("Rename file"));
+ renameFile.Activated += new EventHandler (OnRenameFile);
+ renameFile.Sensitive = false;
+
+ menu.Append (deleteFile);
+ menu.Append (renameFile);
+
+ menu.Popup (null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
+ menu.ShowAll ();
+ }
+
+ void OnSelectionChanged (object o, EventArgs args)
+ {
+ Gtk.TreeIter iter;
+ Gtk.TreeModel model;
+
+ if (this.Selection.GetSelected (out model, out iter))
+ {
+ selectedItem = (FileListItem) model.GetValue (iter, 3);
+ selectedIter = iter;
+ }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileListItem.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileListItem.cs 2004-04-27 22:15:18 UTC (rev 1526)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileListItem.cs 2004-04-27 22:43:33 UTC (rev 1527)
@@ -0,0 +1,81 @@
+using System;
+using System.IO;
+
+using MonoDevelop.Gui.Utils;
+using MonoDevelop.Services;
+using MonoDevelop.Core.Services;
+using MonoDevelop.Core.Properties;
+
+namespace MonoDevelop.Gui.Pads
+{
+ public class FileListItem
+ {
+ string fullname;
+ string text;
+ string size;
+ string lastModified;
+ Gdk.Pixbuf icon;
+
+ public string FullName {
+ get {
+ return fullname;
+ }
+ set {
+ fullname = System.IO.Path.GetFullPath(value);
+ text = System.IO.Path.GetFileName(fullname);
+ }
+ }
+
+ public string Text {
+ get {
+ return text;
+ }
+ }
+
+ public string Size {
+ get {
+ return size;
+ }
+ set {
+ size = value;
+ }
+ }
+
+ public string LastModified {
+ get {
+ return lastModified;
+ }
+ set {
+ lastModified = value;
+ }
+ }
+
+ public Gdk.Pixbuf Icon {
+ get {
+ return icon;
+ }
+ set {
+ icon = value;
+ }
+ }
+
+ public FileListItem(string fullname, string size, string lastModified)
+ {
+ this.size = size;
+ this.lastModified = lastModified;
+ //FIXME: This is because //home/blah is not the same as /home/blah according to Icon.LookupSync, if we get weird behaviours, lets look at this again, see if we still need it.
+ FullName = fullname.Substring (1);
+ icon = FileIconLoader.GetPixbufForFile (FullName, 24, 24);
+ }
+
+ public FileListItem (string name)
+ {
+ FileInfo fi = new FileInfo (name);
+ this.size = Math.Round ((double) fi.Length / 1024).ToString () + " KB";
+ this.lastModified = fi.LastWriteTime.ToString ();
+ FullName = System.IO.Path.GetFullPath (name);
+ icon = FileIconLoader.GetPixbufForFile (FullName, 24, 24);
+ }
+ }
+}
+
Added: trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileScout.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileScout.cs 2004-04-27 22:15:18 UTC (rev 1526)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/FileScout/FileScout.cs 2004-04-27 22:43:33 UTC (rev 1527)
@@ -0,0 +1,121 @@
+using System;
+
+using MonoDevelop.Gui.Widgets;
+using MonoDevelop.Services;
+using MonoDevelop.Core.Services;
+
+namespace MonoDevelop.Gui.Pads
+{
+ public class FileScout : Gtk.VPaned, IPadContent
+ {
+ public Gtk.Widget Control {
+ get {
+ return this;
+ }
+ }
+
+ public void BringToFront() {
+ // TODO
+ }
+
+ public string Title {
+ get {
+ return GettextCatalog.GetString ("Files");
+ }
+ }
+
+ public string Icon {
+ get {
+ //return MonoDevelop.Gui.Stock.OpenFolderBitmap;
+ return Gtk.Stock.Open;
+ }
+ }
+
+ public void RedrawContent()
+ {
+ }
+
+ FileList filelister = new FileList ();
+ FileBrowser fb = new FileBrowser ();
+
+ public FileScout()
+ {
+ fb.DirectoryChangedEvent += new DirectoryChangedEventHandler (OnDirChanged);
+ filelister.RowActivated += new Gtk.RowActivatedHandler (FileSelected);
+
+ Gtk.Frame treef = new Gtk.Frame ();
+ treef.Add (fb);
+
+ Gtk.ScrolledWindow listsw = new Gtk.ScrolledWindow ();
+ listsw.Add (filelister);
+
+ this.Pack1 (treef, true, true);
+ this.Pack2 (listsw, true, true);
+
+ fb.SelectFirst ();
+
+ OnDirChanged (fb.CurrentDir);
+ this.ShowAll ();
+ }
+
+ void OnDirChanged (string path)
+ {
+ filelister.Clear ();
+
+ PropertyService p = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+ bool ignoreHidden = !p.GetProperty ("MonoDevelop.Gui.FileScout.ShowHidden", false);
+ fb.IgnoreHidden = ignoreHidden;
+
+ foreach (string f in fb.Files)
+ {
+ if (!(System.IO.Path.GetFileName (f)).StartsWith ("."))
+ {
+ FileListItem it = new FileListItem (f);
+ filelister.ItemAdded (it);
+ }
+ else
+ {
+ if (!ignoreHidden)
+ {
+ FileListItem it = new FileListItem (f);
+ filelister.ItemAdded (it);
+
+ }
+ }
+ }
+ }
+
+ void FileSelected (object sender, Gtk.RowActivatedArgs e)
+ {
+ IProjectService projectService = (IProjectService)MonoDevelop.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
+ IFileService fileService = (IFileService)MonoDevelop.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
+ FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+
+ Gtk.TreeIter iter;
+ Gtk.TreeModel model;
+
+ // we are not using SelectMultiple
+ // nor can more than one be activated here
+ if (filelister.Selection.GetSelected (out model, out iter))
+ {
+ FileListItem item = (FileListItem) filelister.Model.GetValue (iter, 3);
+
+ //FIXME: use mimetypes not extensions
+ // also change to Project tab when its a project
+ switch (System.IO.Path.GetExtension (item.FullName).ToUpper ()) {
+ case ".cmbx":
+ case ".prjx":
+ projectService.OpenCombine (item.FullName);
+ break;
+ default:
+ //Console.WriteLine (item.FullName);
+ fileService.OpenFile (item.FullName);
+ break;
+ }
+ }
+ }
+
+ public event EventHandler TitleChanged;
+ public event EventHandler IconChanged;
+ }
+}
More information about the Monodevelop-patches-list
mailing list