﻿// =======================================================================================================
//
//    ,uEZGZX  LG                             Eu       iJ       vi                                              
//   BB7.  .:  uM                             8F       0BN      Bq             S:                               
//  @X         LO    rJLYi    :     i    iYLL XJ       Xu7@     Mu    7LjL;   rBOii   7LJ7    .vYUi             
// ,@          LG  7Br...SB  vB     B   B1...7BL       0S i@,   OU  :@7. ,u@   @u.. :@:  ;B  LB. ::             
// v@          LO  B      Z0 i@     @  BU     @Y       qq  .@L  Oj  @      5@  Oi   @.    MB U@                 
// .@          JZ :@      :@ rB     B  @      5U       Eq    @0 Xj ,B      .B  Br  ,B:rv777i  :0ZU              
//  @M         LO  @      Mk :@    .@  BL     @J       EZ     GZML  @      XM  B;   @            Y@             
//   ZBFi::vu  1B  ;B7..:qO   BS..iGB   BJ..:vB2       BM      rBj  :@7,.:5B   qM.. i@r..i5. ir. UB             
//     iuU1vi   ,    ;LLv,     iYvi ,    ;LLr  .       .,       .     rvY7:     rLi   7LLr,  ,uvv:  
//
//
// Copyright 2014-2015 daxnet
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =======================================================================================================

namespace CloudNotes.DesktopClient.Extensibility
{
    using CloudNotes.DesktopClient.Extensibility.Properties;
    using System;
    using System.Windows.Forms;

    /// <summary>
    /// Represents the dialog which can show the exception details.
    /// </summary>
    public partial class FrmExceptionDialog : Form
    {
        #region Private Fields
        private bool showDetail = false;
        #endregion

        #region Ctor
        private FrmExceptionDialog()
        {
            InitializeComponent();
            txtDetail.Visible = false;
            this.Height = 151;
        }
        #endregion

        #region Public Static Methods
        /// <summary>
        /// Shows the exception details in the dialog.
        /// </summary>
        /// <param name="ex">The exception to be shown in the dialog.</param>
        /// <returns></returns>
        public static DialogResult ShowException(Exception ex)
        {
            var excDialog = new FrmExceptionDialog
                                {
                                    txtMessage = { Text = ex.Message },
                                    txtDetail = { Text = ex.ToString() }
                                };
            
            return excDialog.ShowDialog();
        }
        #endregion

        #region Private Methods
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            showDetail = !showDetail;
            if (showDetail)
            {
                linkLabel1.Text = Resources.HideDetail;
                txtDetail.Visible = true;
                this.Height = 307;
            }
            else
            {
                linkLabel1.Text = Resources.ShowDetail;
                txtDetail.Visible = false;
                this.Height = 151;
            }
        }
        #endregion
    }
}
