crashanalysercmd/UI/Graphical/UI/CAGraphicalUI.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 using System;
       
    19 using System.Collections.Generic;
       
    20 using System.ComponentModel;
       
    21 using System.Data;
       
    22 using System.Drawing;
       
    23 using System.Text;
       
    24 using System.Windows.Forms;
       
    25 using CrashAnalyserEngine.Interfaces;
       
    26 using CrashAnalyserEngine.Plugins;
       
    27 using CrashAnalyserEngine.Tabs;
       
    28 using CrashAnalyser.Menu;
       
    29 using CrashAnalyserEngine.Engine;
       
    30 using SymbianTabStripLib.Manager;
       
    31 
       
    32 namespace CrashAnalyser.UI
       
    33 {
       
    34     internal partial class CAGraphicalUI : Form, IEngineUIManager
       
    35     {
       
    36         #region Constructors
       
    37         public CAGraphicalUI( CAEngine aEngine )
       
    38         {
       
    39             iEngine = aEngine;
       
    40 
       
    41             // Must call this to ensure that UI components are created before
       
    42             // we load the crash analyser plugins.
       
    43             InitializeComponent();
       
    44             
       
    45             // Create tab manager to oversee all tab items
       
    46             iTabManager = new TabStripManager( iTabStrip, this );
       
    47             iTabManager.AutoHide = true;
       
    48             
       
    49             // Listen for tab change events
       
    50             iMenuManager = new CAMenuManager( iEngine.Settings, iMenu, iTabManager );
       
    51 
       
    52             // Now it's safe to do this - the menu items that each plugin hangs off of
       
    53             // will have been created
       
    54             iEngine.UIManager = this;
       
    55 
       
    56             // Restore settings needed to position & size form
       
    57             iEngine.Settings.Load( "GraphicalUI", this );
       
    58         }
       
    59         #endregion
       
    60 
       
    61         #region API
       
    62         #endregion
       
    63 
       
    64         #region Event handlers
       
    65         private void iMenu_File_DropDownOpening( object sender, EventArgs e )
       
    66         {
       
    67             ShowOrHideMenu( iMenu_File, iMenu_File_SaveAs );
       
    68             ShowOrHideMenu( iMenu_File, iMenu_File_New );
       
    69             
       
    70             // Hide the separator if no save as or new menu item
       
    71             iMenu_File_ExitSep.Visible = ( iMenu_File_SaveAs.DropDownItems.Count > 0 || iMenu_File_New.DropDownItems.Count > 0 );
       
    72         }
       
    73         
       
    74         private void iMenu_File_Exit_Click( object sender, EventArgs e )
       
    75         {
       
    76             this.Close();
       
    77         }
       
    78 
       
    79         private void CAGraphicalUI_Load( object sender, EventArgs e )
       
    80         {
       
    81         }
       
    82 
       
    83         private void CAGraphicalUI_FormClosing( object sender, FormClosingEventArgs e )
       
    84         {
       
    85             iEngine.Settings.Save( "GraphicalUI", this );
       
    86         }
       
    87 
       
    88         private void TabStrip_TabCloseRequestReceiver( SymbianTabStripLib.Tabs.TabStripTab aTab )
       
    89         {
       
    90             if ( aTab.Page != null && aTab.Page.Body != null )
       
    91             {
       
    92                 CATab body = aTab.Page.Body as CATab;
       
    93                 if ( body != null )
       
    94                 {
       
    95                     UIManagerContentClose( body );
       
    96                 }
       
    97             }
       
    98         }
       
    99 
       
   100         private void CAGraphicalUI_LocationChanged( object sender, EventArgs e )
       
   101         {
       
   102 
       
   103         }
       
   104 
       
   105         private void CAGraphicalUI_Resize( object sender, EventArgs e )
       
   106         {
       
   107 
       
   108         }
       
   109         #endregion
       
   110 
       
   111         #region Internal methods
       
   112         private void SetLabelVisibility( bool aVisible )
       
   113         {
       
   114             iLbl_Title.Visible = aVisible;
       
   115             iLbl_Copyright.Visible = aVisible;
       
   116         }
       
   117 
       
   118         private void ShowOrHideMenu( ToolStripMenuItem aParent, ToolStripMenuItem aMenu )
       
   119         {
       
   120             int count = aMenu.DropDownItems.Count;
       
   121             bool added = aParent.DropDownItems.Contains( aMenu );
       
   122             aMenu.Visible = ( count > 0 );
       
   123         } 
       
   124         #endregion
       
   125 
       
   126         #region IEngineUIManager Members
       
   127         public void UIManagerContentAdd( CATab aTab )
       
   128         {
       
   129             iTabManager.Add( aTab );
       
   130             SetLabelVisibility( iTabManager.TabCount > 0 );
       
   131         }
       
   132 
       
   133         public void UIManagerContentClose( CATab aTab )
       
   134         {
       
   135             iTabManager.Remove( aTab );
       
   136             SetLabelVisibility( iTabManager.TabCount == 0 );
       
   137         }
       
   138 
       
   139         public void UIManagerMenuItemAdd( TEngineUIMenuPane aPane, string aCaption, UIMenuItemClickHandler aClickHandler, object aTag )
       
   140         {
       
   141             UIManagerMenuItemAdd( aPane, aCaption, aClickHandler, aTag, null );
       
   142         }
       
   143 
       
   144         public void UIManagerMenuItemAdd( TEngineUIMenuPane aPane, string aCaption, UIMenuItemClickHandler aClickHandler, object aTag, CATab aHost )
       
   145         {
       
   146             ToolStripMenuItem parent = null;
       
   147             //
       
   148             switch ( aPane )
       
   149             {
       
   150             case TEngineUIMenuPane.EFileNew:
       
   151                 parent = iMenu_File_New;
       
   152                 break;
       
   153             case TEngineUIMenuPane.EFileSaveAs:
       
   154                 parent = iMenu_File_SaveAs;
       
   155                 break;
       
   156             }
       
   157             //
       
   158             if ( parent != null )
       
   159             {
       
   160                 iMenuManager.Add( parent, aCaption, aClickHandler, aTag, aHost );
       
   161             } 
       
   162         }
       
   163 
       
   164         public Version UIVersion
       
   165         {
       
   166             get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; }
       
   167         }
       
   168 
       
   169         public string UICommandLineArguments
       
   170         {
       
   171             get { return Environment.CommandLine; }
       
   172         }
       
   173 
       
   174         public bool UIIsSilent
       
   175         {
       
   176             get { return false; }
       
   177         }
       
   178 
       
   179         public void UITrace( string aMessage )
       
   180         {
       
   181             if ( iDebug )
       
   182             {
       
   183                 StringBuilder text = new StringBuilder( aMessage );
       
   184                 text.Insert( 0, string.Format( "[{0:x6}] ", System.Threading.Thread.CurrentThread.ManagedThreadId ) );
       
   185                 //
       
   186                 System.Diagnostics.Debug.WriteLine( text.ToString() );
       
   187             }
       
   188         }
       
   189 
       
   190         public void UITrace( string aFormat, params object[] aParams )
       
   191         {
       
   192             string msg = string.Format( aFormat, aParams );
       
   193             UITrace( msg );
       
   194         }
       
   195         #endregion
       
   196 
       
   197         #region Data members
       
   198         private bool iDebug = true;
       
   199         private readonly CAEngine iEngine;
       
   200         private readonly CAMenuManager iMenuManager;
       
   201         private readonly TabStripManager iTabManager;
       
   202         #endregion
       
   203     }
       
   204 }