Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using Gtk;
  3.  
  4. public partial class MainWindow: Gtk.Window
  5. {  
  6.     // Set up some consts
  7.     string appVersion = "0.0.2";
  8.    
  9.    
  10.    
  11.     public MainWindow (): base (Gtk.WindowType.Toplevel)
  12.     {
  13.         Build ();
  14.     }
  15.    
  16.     protected void OnDeleteEvent (object sender, DeleteEventArgs a)
  17.     {
  18.         Application.Quit ();
  19.         a.RetVal = true;
  20.     }
  21.    
  22.     void ShowLicenseFromChooser()
  23.     {
  24.         string filename = GetLicenseFileFromChooser();
  25.         if (!string.IsNullOrEmpty (filename))
  26.         {
  27.             ShowLicenseFromFile(filename);
  28.         }
  29.     }
  30.    
  31.     string GetLicenseFileFromChooser()
  32.     {
  33.         FileChooserDialog chooser = new FileChooserDialog(
  34.             "Please select a logfile to view...",
  35.             this,
  36.             FileChooserAction.Open,
  37.             "Cancel", ResponseType.Cancel,
  38.             "Open", ResponseType.Accept );
  39.        
  40.         var chooserResult = chooser.Run ();
  41.         string result;
  42.        
  43.         if (chooserResult == (int)ResponseType.Accept)
  44.             result = chooser.Filename;
  45.         else
  46.             result = null;
  47.        
  48.         chooser.Destroy ();
  49.         return result;
  50.     }
  51.    
  52.     void ShowLicenseFromFile(string filename)
  53.     {
  54.         System.IO.StreamReader file =
  55.             System.IO.File.OpenText(filename);
  56.        
  57.         licenseTextView.Buffer.Text = file.ReadToEnd ();
  58.        
  59.         UpdateTitle (filename);
  60.        
  61.         file.Close ();
  62.     }
  63.    
  64.     void ResetWindow()
  65.     {
  66.         int width, height;
  67.         this.GetDefaultSize (out width, out height);
  68.         this.Resize (width, height);
  69.     }
  70.    
  71.     void ClearTextBox()
  72.     {
  73.         licenseTextView.Buffer.Text = "";
  74.     }
  75.    
  76.     void UpdateTitle(string title)
  77.     {
  78.         if (!string.IsNullOrEmpty(title))
  79.             this.Title = "License Viewer -- " + title; 
  80.         else
  81.             this.Title = "License Viewer";
  82.        
  83.     }
  84.    
  85.     protected void OnOpen (object sender, System.EventArgs e)
  86.     {
  87.         ShowLicenseFromChooser();
  88.     }
  89.    
  90.     protected void OnClose (object sender, System.EventArgs e)
  91.     {
  92.         ResetWindow ();
  93.         ClearTextBox ();
  94.         UpdateTitle (null);
  95.     }
  96.    
  97.     protected void OnExit (object sender, System.EventArgs e)
  98.     {
  99.         Application.Quit ();
  100.     }
  101.  
  102.     protected void OnAbout (object sender, System.EventArgs e)
  103.     {
  104.         // Create a nuew About dialog
  105.         AboutDialog about = new AboutDialog();
  106.        
  107.         // Change the dialog's properties to the appropriate values
  108.         about.Name = "Philip Korsika's License Viewer";
  109.         about.Version = appVersion;
  110.        
  111.         // Show the dialog and pass it control
  112.         about.Run ();
  113.        
  114.         // Destroy the dialog
  115.         about.Destroy();
  116.     }
  117. }
Add Comment
Please, Sign In to add comment