[Monodevelop-patches-list] r1203 - in trunk/MonoDevelop: . src/Libraries/MonoDevelop.Gui.Utils src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive src/Libraries/MonoDevelop.Gui.Utils/ReportingStream src/Main/Base src/Main/Base/Gui/CompletionDatabaseWizard
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Sat Mar 20 03:48:43 EST 2004
Author: iainmc
Date: 2004-03-20 03:48:42 -0500 (Sat, 20 Mar 2004)
New Revision: 1203
Added:
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Bz2Support.cs
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Decompressor.cs
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/GzSupport.cs
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/TarDecompressor.cs
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/ZipDecompressor.cs
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/ReportingStream.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs
Modified:
trunk/MonoDevelop/ChangeLog
trunk/MonoDevelop/configure.in
trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/Makefile.am
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreateDBGenerator.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreatingGenerator.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/GenerateDatabase.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/IDatabaseGenerator.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/UseExistingGenerator.cs
trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/druid.cs
trunk/MonoDevelop/src/Main/Base/Makefile.am
Log:
2004-03-20 Iain McCoy <iainmccoy at optusnet.com.au>
* src/Main/Base/Gui/CompletionDatabaseWizard/*: Remove WriteLine
statements
* src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs: add
downloading from a url
* src/Libraries/MonoDevelop.Gui.Utils/Makefile.am:
* src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/*:
* src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/*: Added
ReportingStream and DirectoryArchive utilities
Modified: trunk/MonoDevelop/ChangeLog
===================================================================
--- trunk/MonoDevelop/ChangeLog 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/ChangeLog 2004-03-20 08:48:42 UTC (rev 1203)
@@ -1,3 +1,13 @@
+2004-03-20 Iain McCoy <iainmccoy at optusnet.com.au>
+ * src/Main/Base/Gui/CompletionDatabaseWizard/*: Remove WriteLine
+ statements
+ * src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs: add
+ downloading from a url
+ * src/Libraries/MonoDevelop.Gui.Utils/Makefile.am:
+ * src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/*:
+ * src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/*: Added
+ ReportingStream and DirectoryArchive utilities
+
2004-03-20 Gustavo Giráldez <gustavo.giraldez at gmx.net>
* gdldock/gdl/Makefile.am:
Modified: trunk/MonoDevelop/configure.in
===================================================================
--- trunk/MonoDevelop/configure.in 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/configure.in 2004-03-20 08:48:42 UTC (rev 1203)
@@ -113,6 +113,7 @@
src/Main/StartUp/Makefile
src/Libraries/Makefile
src/Libraries/MonoDevelop.Core/Makefile
+src/Libraries/MonoDevelop.Misc/Makefile
src/Libraries/MonoDevelop.Gui.Utils/Makefile
src/Libraries/MonoDevelop.Gui.Widgets/Makefile
src/Libraries/SharpAssembly/Makefile
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Bz2Support.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Bz2Support.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Bz2Support.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,15 @@
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.BZip2;
+
+namespace MonoDevelop.Gui.Utils.DirectoryArchive {
+
+ public class BZip2Decompressor : ISingleFileDecompressor {
+ public Stream Decompress (Stream input)
+ {
+ input.ReadByte();
+ input.ReadByte();
+ return new BZip2InputStream(input);
+ }
+ }
+}
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Decompressor.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Decompressor.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/Decompressor.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,96 @@
+/* Decompressor.cs
+ *
+ * Iain McCoy <iain at mccoy.id.au>, 2004
+ *
+ * Just a little abstraction so that any sort of compressed archive can be
+ * extracted in the same way
+ *
+ * Supports zips, straight tar files and tarballs of the bz2 and gz varieties
+ */
+
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.BZip2;
+using ICSharpCode.SharpZipLib.GZip;
+
+namespace MonoDevelop.Gui.Utils.DirectoryArchive {
+ public enum CompressionType { Zip, TarGz, TarBz2, Tar }
+
+ public interface ISingleFileDecompressor {
+ Stream Decompress(Stream input);
+ }
+
+ public abstract class Decompressor {
+ public static Decompressor Load(string fileEnding)
+ {
+ return Load(GetTypeFromString(fileEnding));
+ }
+
+ public static Decompressor Load(CompressionType compression)
+ {
+ switch (compression) {
+ case CompressionType.Zip:
+ return new ZipDecompressor();
+ case CompressionType.TarGz:
+ return new TarDecompressor(new GZipDecompressor());
+ case CompressionType.TarBz2:
+ return new TarDecompressor(new BZip2Decompressor());
+ case CompressionType.Tar:
+ return new TarDecompressor(null);
+ default:
+ throw new ArgumentOutOfRangeException("compression");
+ }
+ }
+
+ protected void CopyStream (Stream inp, Stream outp)
+ {
+ byte[] buf = new byte[32 * 1024];
+ long amount = 0;
+ while (true) {
+ int numRead = inp.Read(buf, 0, buf.Length);
+ if (numRead <= 0) {
+ break;
+ }
+ amount += numRead;
+ outp.Write(buf, 0, numRead);
+
+ }
+ }
+
+ protected void EnsureDirectoryExists(string path)
+ {
+ EnsureDirectoryExists(new DirectoryInfo(path));
+ }
+ protected void EnsureDirectoryExists(DirectoryInfo path)
+ {
+ if (path.Parent != null)
+ EnsureDirectoryExists(path.Parent);
+ if (!path.Exists)
+ path.Create();
+ }
+
+ public static CompressionType GetTypeFromString(string fileEnding)
+ {
+ return GetTypeFromString(fileEnding, true);
+ }
+
+ public static CompressionType GetTypeFromString(string fileEnding, bool ThrowException)
+ {
+ if (fileEnding.EndsWith(".zip"))
+ return CompressionType.Zip;
+ else if (fileEnding.EndsWith(".tgz") || fileEnding.EndsWith(".tar.gz"))
+ return CompressionType.TarGz;
+ else if (fileEnding.EndsWith(".tbz2") || fileEnding.EndsWith(".tar.bz2"))
+ return CompressionType.TarBz2;
+ else if (fileEnding.EndsWith(".tar"))
+ return CompressionType.Tar;
+ else
+ if (ThrowException)
+ throw new ArgumentOutOfRangeException("fileEnding");
+ else
+ return (CompressionType)(-1);
+ }
+
+ public abstract void Extract(Stream CompressedData, string OutputPath);
+ }
+}
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/GzSupport.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/GzSupport.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/GzSupport.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,13 @@
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.GZip;
+
+namespace MonoDevelop.Gui.Utils.DirectoryArchive {
+
+ public class GZipDecompressor : ISingleFileDecompressor {
+ public Stream Decompress (Stream input)
+ {
+ return new GZipInputStream(input);
+ }
+ }
+}
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/TarDecompressor.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/TarDecompressor.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/TarDecompressor.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,34 @@
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.Tar;
+
+namespace MonoDevelop.Gui.Utils.DirectoryArchive {
+ public sealed class TarDecompressor : Decompressor {
+ private ISingleFileDecompressor inputDecompressor;
+
+ public TarDecompressor(ISingleFileDecompressor InputDecompressor)
+ {
+ this.inputDecompressor = InputDecompressor;
+ }
+
+
+ public override void Extract(Stream CompressedData, string OutputPath)
+ {
+ TarInputStream tarFile = new TarInputStream(inputDecompressor.Decompress(CompressedData));
+ if (!OutputPath.EndsWith(""+Path.DirectorySeparatorChar))
+ OutputPath = OutputPath + Path.DirectorySeparatorChar;
+
+ while (true) {
+ TarEntry entry = tarFile.GetNextEntry();
+ if (entry == null)
+ break;
+ string outputFile = OutputPath + entry.Name;
+ if (entry.IsDirectory)
+ continue;
+ EnsureDirectoryExists(Path.GetDirectoryName(outputFile));
+ CopyStream(tarFile, File.OpenWrite(outputFile));
+ }
+
+ }
+ }
+}
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/ZipDecompressor.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/ZipDecompressor.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/DirectoryArchive/ZipDecompressor.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,22 @@
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.Zip;
+
+namespace MonoDevelop.Gui.Utils.DirectoryArchive {
+ public sealed class ZipDecompressor : Decompressor {
+ public override void Extract(Stream CompressedData, string OutputPath)
+ {
+ ZipFile zipFile = new ZipFile(CompressedData);
+ if (!OutputPath.EndsWith(""+Path.DirectorySeparatorChar))
+ OutputPath = OutputPath + Path.DirectorySeparatorChar;
+ foreach (ZipEntry entry in zipFile) {
+ string outputFile = OutputPath + entry.Name;
+ if (entry.IsDirectory)
+ continue;
+ EnsureDirectoryExists(Path.GetDirectoryName(outputFile));
+ CopyStream(zipFile.GetInputStream(entry), File.OpenWrite(outputFile));
+ }
+
+ }
+ }
+}
Modified: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/Makefile.am
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/Makefile.am 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/Makefile.am 2004-03-20 08:48:42 UTC (rev 1203)
@@ -1,9 +1,15 @@
DLL = MonoDevelop.Gui.Utils.dll
-REFERENCES=/r:System.Drawing /r:gtk-sharp /r:gdk-sharp /r:pango-sharp /r:gnome-sharp /r:glib-sharp /r:glade-sharp
+REFERENCES=/r:System.Drawing /r:gtk-sharp /r:gdk-sharp /r:pango-sharp /r:gnome-sharp /r:glib-sharp /r:glade-sharp /r:ICSharpCode.SharpZipLib
FILES = ./FileIcons/FileIconLoader.cs \
./AssemblyInfo.cs \
./VFS/Vfs.cs \
+./ReportingStream/ReportingStream.cs \
+./DirectoryArchive/Decompressor.cs \
+./DirectoryArchive/TarDecompressor.cs \
+./DirectoryArchive/ZipDecompressor.cs \
+./DirectoryArchive/Bz2Support.cs \
+./DirectoryArchive/GzSupport.cs \
./Glue.cs
build_sources = $(addprefix $(srcdir)/, $(FILES))
Added: trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/ReportingStream.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/ReportingStream.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Libraries/MonoDevelop.Gui.Utils/ReportingStream/ReportingStream.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,106 @@
+using System;
+using System.IO;
+
+namespace MonoDevelop.Gui.Utils.ReportingStream {
+
+ public delegate void ReadNotification (object arg, int amount);
+
+ public class ReportingStream : Stream, IDisposable {
+ Stream s;
+ ReadNotification haveRead;
+ object arg;
+ private int count = 0;
+ private readonly int reportHurdle;
+
+ public ReportingStream(Stream stream, ReadNotification DataRead, object DataReadArg) : this (stream, DataRead, DataReadArg, .01) { }
+
+ public ReportingStream(Stream stream, ReadNotification DataRead, object DataReadArg, double reportPercentage)
+ {
+ this.s = stream;
+ this.haveRead = DataRead;
+ this.arg = DataReadArg;
+ this.reportHurdle = (int)(reportPercentage * stream.Length);
+ }
+
+ private void haveReadSomeData(int bytes)
+ {
+ this.count += bytes;
+ if (this.count > reportHurdle){
+ haveRead(arg, this.count);
+ this.count = 0;
+ }
+ }
+
+ public override bool CanRead {
+ get { return s.CanRead; }
+ }
+
+ public override bool CanSeek {
+ get { return s.CanSeek; }
+ }
+
+ public override bool CanWrite {
+ get { return s.CanWrite; }
+ }
+
+ public override long Length {
+ get { return s.Length; }
+ }
+
+ public override long Position {
+ get { return s.Position; }
+ set { s.Position = value; }
+ }
+
+ public override void Close()
+ {
+ s.Close();
+ }
+
+ public override void Flush()
+ {
+ s.Flush();
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ int amountRead = s.Read(buffer, offset, count);
+ if (amountRead > 0)
+ haveReadSomeData(amountRead);
+ return amountRead;
+ }
+
+ public override int ReadByte()
+ {
+ int result = s.ReadByte();
+ if (result != -1)
+ haveReadSomeData(1);
+ return result;
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ return s.Seek(offset, origin);
+ }
+
+ public override void SetLength(long value)
+ {
+ s.SetLength(value);
+ }
+
+ void IDisposable.Dispose()
+ {
+ (s as IDisposable).Dispose();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ s.Write(buffer, offset, count);
+ }
+
+ public override void WriteByte(byte value)
+ {
+ s.WriteByte(value);
+ }
+ }
+}
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreateDBGenerator.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreateDBGenerator.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreateDBGenerator.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -13,17 +13,15 @@
{
public class CreateDBGenerator : CreatingGenerator, IDatabaseGenerator
{
+ public bool Cancelable { get { return true; } }
public bool Fast;
public void Generate(IProgressMonitor progress)
{
string path = this.CreateCodeCompletionDir();
DefaultParserService parserService = (DefaultParserService)MonoDevelop.Core.Services.ServiceManager.Services.GetService(typeof(DefaultParserService));
- Console.WriteLine("using path " + path);
if (Fast) {
- Console.WriteLine("Creating DB with fast process");
parserService.GenerateCodeCompletionDatabaseFast(path, progress);
} else {
- Console.WriteLine("Creating DB with slow process");
parserService.GenerateEfficientCodeCompletionDatabase(path, progress);
}
}
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreatingGenerator.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreatingGenerator.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/CreatingGenerator.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -17,7 +17,7 @@
{
FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
- string path = propertyService.ConfigDirectory + System.IO.Path.DirectorySeparatorChar + "CodeCompletionData";
+ string path = fileUtilityService.GetDirectoryNameWithSeparator(propertyService.ConfigDirectory) + "CodeCompletionData";
if (!Directory.Exists (path))
Directory.CreateDirectory (path);
propertyService.SetProperty ("SharpDevelop.CodeCompletion.DataDirectory", path);
Added: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/DownloadGenerator.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -0,0 +1,114 @@
+using System;
+using System.Net;
+using System.IO;
+using Gtk;
+
+using MonoDevelop.Internal.Project;
+using MonoDevelop.Core.Properties;
+using MonoDevelop.Core.Services;
+using MonoDevelop.Services;
+
+using MonoDevelop.Core.AddIns.Codons;
+
+using MonoDevelop.Gui.Utils.DirectoryArchive;
+using MonoDevelop.Gui.Utils.ReportingStream;
+
+namespace MonoDevelop.Gui.Dialogs.OptionPanels.CompletionDatabaseWizard {
+
+ public class DownloadGenerator : CreatingGenerator, IDatabaseGenerator {
+
+ public bool Cancelable { get { return false; } }
+ public Uri SourceUri;
+
+ private void updateProgress(object arg, int amount)
+ {
+ ProgressHolder holder = (ProgressHolder)arg;
+ holder.currentProgress = holder.startProgress + holder.s.Position;
+ holder.progressBar.Worked ((int)((double)holder.currentProgress/holder.maxAmount * int.MaxValue), "Extracted more of the archive");
+
+ while (Gtk.Application.EventsPending ())
+ Gtk.Application.RunIteration ();
+ }
+
+ class ProgressHolder
+ {
+ public IProgressMonitor progressBar;
+ public long currentProgress;
+ public long startProgress;
+ public long maxAmount;
+ public Stream s;
+ }
+
+ public void Generate(IProgressMonitor progress)
+ {
+ string completionDir = this.CreateCodeCompletionDir();
+ if (!completionDir.EndsWith ("/"))
+ completionDir = completionDir + "/";
+
+ string compressedFile = Path.GetTempFileName();
+
+
+ long maxAmount;
+
+ try {
+ WebRequest dataReq = WebRequest.Create(SourceUri);
+ WebResponse dataResp = dataReq.GetResponse();
+ maxAmount = dataResp.ContentLength * 2;
+
+
+ progress.BeginTask("Downloading database", int.MaxValue);
+ DownloadFile (dataResp.GetResponseStream (),
+ compressedFile,
+ maxAmount, progress);
+ } catch (Exception e) {
+ throw new Exception("Could not download database", e);
+ }
+ Stream s = null;
+
+ try {
+ s = File.OpenRead(compressedFile);
+
+ ProgressHolder ph = new ProgressHolder();
+ ph.currentProgress = maxAmount / 2;
+ ph.startProgress = maxAmount / 2;
+ ph.maxAmount = maxAmount;
+ ph.progressBar = progress;
+ ph.s = s;
+ Decompressor archive = Decompressor.Load(SourceUri.ToString());
+ archive.Extract(new ReportingStream(s, new ReadNotification(updateProgress), ph), completionDir);
+ File.Delete(compressedFile);
+ } catch (Exception e) {
+ throw new Exception("Could not extract archive " + compressedFile + " of type " + Decompressor.GetTypeFromString(SourceUri.ToString()), e);
+ } finally {
+ if (s != null)
+ s.Close();
+ }
+ }
+
+ private void DownloadFile(Stream s, string fileName, long maxAmount, IProgressMonitor progress)
+ {
+ byte[] buffer = new byte[512*24];
+ long amountDownloaded = 0;
+ int amountRead;
+ Stream outstream = new FileStream(fileName, FileMode.Create);
+ long lastyield = 0;
+ while (true) {
+ amountRead = s.Read(buffer, 0, buffer.Length);
+ amountDownloaded += amountRead;
+ outstream.Write(buffer, 0, amountRead);
+ progress.Worked ((int)((float)amountDownloaded/maxAmount * int.MaxValue), "Downloaded more of " + fileName);
+
+ // make sure we let the GTK events happen at least every second
+ long nowticks = DateTime.Now.Ticks;
+ if (nowticks - lastyield > 1000) {
+ while (Gtk.Application.EventsPending ())
+ Gtk.Application.RunIteration ();
+ lastyield = nowticks;
+ }
+
+ if (amountRead == 0)
+ break;
+ }
+ }
+ }
+}
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/GenerateDatabase.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/GenerateDatabase.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/GenerateDatabase.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -43,25 +43,34 @@
public GeneratorProgress (IDatabaseGenerator generator) : base("Code completion database generator")
{
- this.generator = generator;
+ try {
+ this.generator = generator;
- Gtk.VBox vb = new Gtk.VBox(false, 6);
- this.Add(vb);
+ Gtk.VBox vb = new Gtk.VBox(false, 6);
+ this.Add(vb);
- vb.Add(new Gtk.Label("Creating database..."));
+ vb.Add(new Gtk.Label("Creating database..."));
- progress = new ProgressMonitorBar();
- vb.Add(progress);
+ progress = new ProgressMonitorBar();
+ vb.Add(progress);
- cancel = new Gtk.Button("Cancel");
- cancel.Clicked += new EventHandler(DoCancel);
- vb.Add(cancel);
- this.ShowAll();
- while (Gtk.Application.EventsPending ())
- Gtk.Application.RunIteration ();
+ cancel = new Gtk.Button("Cancel");
+ cancel.Clicked += new EventHandler(DoCancel);
+ if (!generator.Cancelable) {
+ cancel.Sensitive = false;
+ Tooltips t = new Tooltips();
+ t.SetTip(cancel, "Cancelling not available",
+ "This type of code completion database generator can not be canceled");
+ }
+ vb.Add(cancel);
+ this.ShowAll();
+ while (Gtk.Application.EventsPending ())
+ Gtk.Application.RunIteration ();
- generator.Generate(progress);
- this.Destroy();
+ generator.Generate(progress);
+ } finally {
+ this.Destroy();
+ }
}
private void DoCancel(object sender, EventArgs args)
@@ -87,14 +96,21 @@
void GotDruidData(object sender, IDatabaseGenerator gen)
{
+ GeneratorProgress gp = null;
try {
druidHost.Destroy();
- GeneratorProgress gp = new GeneratorProgress(gen);
+ gp = new GeneratorProgress(gen);
} catch (Exception e) {
- Console.WriteLine("Failed with exception " + e.GetType().Name + ": " + e.Message);
- //FIXME: display error message
+ IMessageService messageService = (IMessageService) ServiceManager.Services.GetService (typeof (IMessageService));
+ string message = e.Message;
+ if (e.InnerException != null)
+ message += ": " + e.InnerException.Message;
+ messageService.ShowError(message);
+ if (gp != null)
+ gp.Destroy();
Start();
+ return;
}
// restart & exit
ServiceManager.Services.UnloadAllServices();
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/IDatabaseGenerator.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/IDatabaseGenerator.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/IDatabaseGenerator.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -20,5 +20,6 @@
public interface IDatabaseGenerator
{
void Generate(IProgressMonitor monitor);
+ bool Cancelable { get; }
}
}
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/UseExistingGenerator.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/UseExistingGenerator.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/UseExistingGenerator.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -13,6 +13,7 @@
{
public class UseExistingDBGenerator : IDatabaseGenerator
{
+ public bool Cancelable { get { return true; } }
public string Path;
// changed to work during GLib.Idle
public void Generate(IProgressMonitor progress)
Modified: trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/druid.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/druid.cs 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Gui/CompletionDatabaseWizard/druid.cs 2004-03-20 08:48:42 UTC (rev 1203)
@@ -19,7 +19,7 @@
this.NextClicked += new NextClickedHandler(druid.GoToMethodPage);
AppendItem("", generateDatabase, "");
AppendItem("", useExisting, "");
-// AppendItem("", download, "");
+ AppendItem("", download, "");
}
}
@@ -51,11 +51,29 @@
class DownloadPage : DetailsPageBase {
internal Gtk.Entry uri;
- internal DownloadPage(CodeCompletionDruid druid) : base(druid) {
+ internal DownloadPage(CodeCompletionDruid druid) : base(druid)
+ {
Title = "Download Database";
uri = new Gtk.Entry();
AppendItem("Where would you like to download the code completion database from?", uri, "");
}
+
+ protected override string GetError (object sender)
+ {
+ try {
+ Uri u = new Uri(this.uri.Text);
+ } catch (UriFormatException ex) {
+ return "That Uri is invalid: " + ex.Message;
+ }
+
+ int compressionType = (int)MonoDevelop.Gui.Utils.DirectoryArchive.Decompressor.GetTypeFromString(this.uri.Text, false);
+
+ if (compressionType == -1){
+ return "That Uri appears not to refer to a file with a known compression type";
+ }
+
+ return null;
+ }
}
abstract class DetailsPageBase : DruidPageStandard {
@@ -70,11 +88,25 @@
internal void MoveNext(object sender, NextClickedArgs args)
{
+ string error = GetError(sender);
+
+ if (error != null) {
+ IMessageService messageService = (IMessageService) ServiceManager.Services.GetService (typeof (IMessageService));
+ messageService.ShowError(error);
+ args.RetVal = true;
+ return;
+ }
+
druid.PreviousPage = this;
druid.ShowLast();
args.RetVal = true;
}
+ protected virtual string GetError(object sender)
+ {
+ return null;
+ }
+
internal void MoveBack(object sender, BackClickedArgs args)
{
druid.ShowMain();
@@ -146,7 +178,6 @@
internal void EndOfWizard(object sender, FinishClickedArgs args)
{
- Console.WriteLine("Finishing druid");
IDatabaseGenerator generator = null;
if (methodSelectionPage.generateDatabase.Active) {
generator = (IDatabaseGenerator)new CreateDBGenerator();
@@ -155,7 +186,9 @@
} else if (methodSelectionPage.useExisting.Active) {
generator = (IDatabaseGenerator)new UseExistingDBGenerator();
((UseExistingDBGenerator)generator).Path = useExistingPage.filename.Path;
- // } else if (methodSelectionPage.download.Active) {
+ } else if (methodSelectionPage.download.Active) {
+ generator = (IDatabaseGenerator)new DownloadGenerator();
+ ((DownloadGenerator)generator).SourceUri = new Uri(downloadPage.uri.Text);
}
if (Finished != null)
Finished(this, generator);
@@ -168,7 +201,6 @@
internal void ShowMain()
{
- Console.WriteLine("Showing main page...");
Page = methodSelectionPage;
}
Modified: trunk/MonoDevelop/src/Main/Base/Makefile.am
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Makefile.am 2004-03-20 06:48:50 UTC (rev 1202)
+++ trunk/MonoDevelop/src/Main/Base/Makefile.am 2004-03-20 08:48:42 UTC (rev 1203)
@@ -137,6 +137,7 @@
./Gui/PixbufList.cs \
./Gui/AbstractSecondaryViewContent.cs \
./Gui/CompletionDatabaseWizard/CreateDBGenerator.cs \
+./Gui/CompletionDatabaseWizard/DownloadGenerator.cs \
./Gui/CompletionDatabaseWizard/CreatingGenerator.cs \
./Gui/CompletionDatabaseWizard/GenerateDatabase.cs \
./Gui/CompletionDatabaseWizard/druid.cs \
More information about the Monodevelop-patches-list
mailing list