Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Gtk;
- public partial class MainWindow: Gtk.Window
- {
- // Set up some consts
- string appVersion = "0.0.2";
- public MainWindow (): base (Gtk.WindowType.Toplevel)
- {
- Build ();
- }
- protected void OnDeleteEvent (object sender, DeleteEventArgs a)
- {
- Application.Quit ();
- a.RetVal = true;
- }
- void ShowLicenseFromChooser()
- {
- string filename = GetLicenseFileFromChooser();
- if (!string.IsNullOrEmpty (filename))
- {
- ShowLicenseFromFile(filename);
- }
- }
- string GetLicenseFileFromChooser()
- {
- FileChooserDialog chooser = new FileChooserDialog(
- "Please select a logfile to view...",
- this,
- FileChooserAction.Open,
- "Cancel", ResponseType.Cancel,
- "Open", ResponseType.Accept );
- var chooserResult = chooser.Run ();
- string result;
- if (chooserResult == (int)ResponseType.Accept)
- result = chooser.Filename;
- else
- result = null;
- chooser.Destroy ();
- return result;
- }
- void ShowLicenseFromFile(string filename)
- {
- System.IO.StreamReader file =
- System.IO.File.OpenText(filename);
- licenseTextView.Buffer.Text = file.ReadToEnd ();
- UpdateTitle (filename);
- file.Close ();
- }
- void ResetWindow()
- {
- int width, height;
- this.GetDefaultSize (out width, out height);
- this.Resize (width, height);
- }
- void ClearTextBox()
- {
- licenseTextView.Buffer.Text = "";
- }
- void UpdateTitle(string title)
- {
- if (!string.IsNullOrEmpty(title))
- this.Title = "License Viewer -- " + title;
- else
- this.Title = "License Viewer";
- }
- protected void OnOpen (object sender, System.EventArgs e)
- {
- ShowLicenseFromChooser();
- }
- protected void OnClose (object sender, System.EventArgs e)
- {
- ResetWindow ();
- ClearTextBox ();
- UpdateTitle (null);
- }
- protected void OnExit (object sender, System.EventArgs e)
- {
- Application.Quit ();
- }
- protected void OnAbout (object sender, System.EventArgs e)
- {
- // Create a nuew About dialog
- AboutDialog about = new AboutDialog();
- // Change the dialog's properties to the appropriate values
- about.Name = "Philip Korsika's License Viewer";
- about.Version = appVersion;
- // Show the dialog and pass it control
- about.Run ();
- // Destroy the dialog
- about.Destroy();
- }
- }
Add Comment
Please, Sign In to add comment