using System;
using System.IO;
using System.Collections;
using System.Threading;
using Gtk;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
a.RetVal = true;
Application.Quit();
}
protected virtual void menu_exit (object sender, System.EventArgs e)
{
Application.Quit();
}
protected virtual void open_file (object sender, System.EventArgs e)
{
FileChooserDialog fc
= new Gtk
.FileChooserDialog( "Elija el archivo a abrir",
this,
FileChooserAction.Open,
"Cancelar",ResponseType.Cancel,
"Abrir",ResponseType.Accept
);
if (fc.Run() == (int)ResponseType.Accept){ // Si se ha seleccionado el archivo...
System.IO.StreamReader file
= new System.IO.StreamReader(fc
.Filename);
this.textview1.Buffer.Text = file.ReadToEnd();
file.Close();
// Creamos el hilo para comprobar si el archivo fue modificado
Thread checkFileDate1
= new Thread
(() => checkFileDate
(fc
.Filename)); //Thread checkFileDate1 = new Thread(new ThreadStart(checkFileDate));
checkFileDate1.Start();
}
fc.Destroy();
}
// Esto se encarga de comprobar si los ficheros abiertos han sido cambiados
public void checkFileDate(string file)
{
DateTime lastDate = System.IO.File.GetLastWriteTime(file);
while(true){
int result = DateTime.Compare(lastDate, System.IO.File.GetLastWriteTime(file));
if (result >= 0){
MessageDialog alert
= new MessageDialog
( this,
DialogFlags.DestroyWithParent,
MessageType.Info,
ButtonsType.Ok,
"¡El archivo ha sido modificado!"
);
alert.Run();
alert.Destroy();
//MessageBox.Show("¡El archivo ha sido modificado!");
}
Thread.Sleep(5000);
}
}
}