GUI.cs :  » Office » BibWord » BibWordExtender » UI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Office » BibWord 
BibWord » BibWordExtender » UI » GUI.cs
using System;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

using BibWordExtender.Data;

namespace BibWordExtender.UI{
  public partial class GUI : Form
  {
    #region Variables

    /// <summary>
    /// Mapping of style names (keys) and style paths (values).
    /// </summary>
    private Dictionary<string, string> map;

    /// <summary>
    /// Background worker thread for creating the mapping between style names and style paths.
    /// </summary>
    private BackgroundWorker worker;

    /// <summary>
    /// Splash form.
    /// </summary>
    private Splash splash;
    
    #endregion Variables

    #region Constructors

    public GUI()
    {
      InitializeComponent();

      LoadStyleInformation();

      toolTip.SetToolTip(this.cmdClean, "Remove all BibWord extensions from the bibliographic sources.");
      toolTip.SetToolTip(this.cmdExit, "Exit the application.");
      toolTip.SetToolTip(this.cmdInfo, "Display information about the application.");
      toolTip.SetToolTip(this.cmdWordDocSelection, "Select a Word document.");
      toolTip.SetToolTip(this.cmdReload, "Reload all style information.");
      toolTip.SetToolTip(this.cmdExtend, "Extend the bibliographic sources.");
    }

    #endregion Constructors

    #region Methods

    /// <summary>
    /// Ensures the loading of all style information through a background worker thread.
    /// </summary>
    private void LoadStyleInformation()
    {
      // Initialize the background worker.
      this.worker = new BackgroundWorker();
      this.worker.DoWork += new DoWorkEventHandler(Worker_DoWork);
      this.worker.ProgressChanged += new ProgressChangedEventHandler(Worker_ProgressChanged);
      this.worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
      this.worker.WorkerReportsProgress = true;

      // Start running the background worker.
      this.worker.RunWorkerAsync();

      // Display the splash form.
      this.splash = new Splash();
      this.splash.ShowDialog();
    }
    
    #endregion Methods
    
    #region Event Handling

    /// <summary>
    /// Background worker thread.
    /// </summary>
    private void Worker_DoWork(object sender, DoWorkEventArgs e)
    {
      // Load information about all the bibliography styles.
      e.Result = BibWord.LoadBibliographyStylesInformation(this.worker);
    }

    /// <summary>
    /// Handle the ProgressChanged event raised by the background worker.
    /// </summary>
    private void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
      // Update status label on the splash screen.
      this.splash.StatusText = "Processed " + e.UserState.ToString() + " ... (" + e.ProgressPercentage + "%)";
    }

    /// <summary>
    /// Handle the RunWorkerCompleted event raised by the background worker.
    /// </summary>
    private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
      // Assign the result to the map.
      this.map = (Dictionary<string, string>)e.Result;

      // Bind the result to the combobox.
      this.cmbStyles.DataSource = new BindingSource(this.map, null);
      this.cmbStyles.DisplayMember = "Key";

      // Close the splash screen.
      this.splash.AllowClosing = true;
      this.splash.Close();
    }

    /// <summary>
    /// Handle the clicking of the reload button.
    /// </summary>
    private void cmdReload_Click(object sender, EventArgs e)
    {
      // Reload the style information.
      this.LoadStyleInformation();
    }

    /// <summary>
    /// Handle the clicking of the info button.
    /// </summary>
    private void cmdInfo_Click(object sender, EventArgs e)
    {
      this.splash = new Splash(true);
      this.splash.ShowDialog();
    }

    /// <summary>
    /// Handle the clicking of the exit button.
    /// </summary>
    private void cmdExit_Click(object sender, EventArgs e)
    {
      this.Close();
    }

    /// <summary>
    /// Handle the clicking of the extend button.
    /// </summary>
    private void cmdExtend_Click(object sender, EventArgs e)
    {
      try
      {
        bool success = BibWord.ExtendBibliography(this.txtWordDoc.Text, this.map[this.cmbStyles.Text]);

        // Give the user a hint to the result of the extension attempt.
        if (success == true)
        {
          MessageBox.Show("Bibliography extension successful.", "Extension result", 
            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
          MessageBox.Show("Bibliography extension failed. Either there was no" +
            "bibliography or it was not a BibWord bibliography.", "Extension result",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
      }
      catch (FileFormatException)
      {
        MessageBox.Show("Not a valid Word 2007 file.");
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

    /// <summary>
    /// Handle the clicking of the button to select a file.
    /// </summary>
    private void cmdWordDocSelection_Click(object sender, EventArgs e)
    {
      // Let the user pick a Word docx file.
      openFileDialog.ShowDialog();

      // Display the selected file.
      if (openFileDialog.FileName != "")
      {
        txtWordDoc.Text = openFileDialog.FileName;

        // Sets the bibliography style currently used by the document.
        try
        {
          this.cmbStyles.Text = BibWord.GetBibliographyStyle(openFileDialog.FileName, this.map);
        }
        catch (Exception ex)
        {
          MessageBox.Show(ex.Message);
        }
      }
    }

    /// <summary>
    /// Handle the clicking of the clean button.
    /// </summary>
    private void cmdClean_Click(object sender, EventArgs e)
    {
      try
      {
        BibWord.CleanBibliography(this.txtWordDoc.Text);

        // Give the user.
        MessageBox.Show("Bibliography was successfully cleaned.", 
          "Bibliography cleaned", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      catch (FileFormatException)
      {
        MessageBox.Show("Not a valid Word 2007 file.");
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

    #endregion Event Handling
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.