|
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.Text; |
|
20 using System.IO; |
|
21 using System.Collections.Generic; |
|
22 using System.Windows.Forms; |
|
23 using SymbianUtils.Settings; |
|
24 using SymbianTabStripLib.Tabs; |
|
25 using SymbianTabStripLib.Pages; |
|
26 using SymbianTabStripLib.Manager; |
|
27 using CrashAnalyserEngine.Interfaces; |
|
28 using CrashAnalyserEngine.Tabs; |
|
29 |
|
30 namespace CrashAnalyser.Menu |
|
31 { |
|
32 internal class CAMenuManager |
|
33 { |
|
34 #region Constructors |
|
35 public CAMenuManager( XmlSettings aSettings, MenuStrip aMenu, TabStripManager aTabStripManager ) |
|
36 { |
|
37 iSettings = aSettings; |
|
38 iMenuBar = aMenu; |
|
39 iTabStripManager = aTabStripManager; |
|
40 |
|
41 // Listen to tab changes |
|
42 iTabStripManager.TabStrip.SelectedTabChanged += new TabStrip.TabHandler( TabStrip_SelectedTabChanged ); |
|
43 } |
|
44 #endregion |
|
45 |
|
46 #region API |
|
47 public void Add( ToolStripMenuItem aParent, string aCaption, UIMenuItemClickHandler aClickHandler, object aTag, CATab aHost ) |
|
48 { |
|
49 CAMenuItem item = new CAMenuItem( this, aCaption, aClickHandler, aTag ); |
|
50 |
|
51 if ( aHost != null ) |
|
52 { |
|
53 // Find a menu list for the corresponding tab |
|
54 CAMenuItemList list = this[ aHost ]; |
|
55 if ( list == null ) |
|
56 { |
|
57 list = new CAMenuItemList( this ); |
|
58 iDictionary.Add( aHost, list ); |
|
59 } |
|
60 |
|
61 // Add the item to the list |
|
62 list.Add( item ); |
|
63 } |
|
64 else |
|
65 { |
|
66 // Not associated with a specific tab, so most likely a top-level |
|
67 // plugin menu item that is always visible |
|
68 } |
|
69 |
|
70 aParent.DropDownItems.Add( item ); |
|
71 } |
|
72 #endregion |
|
73 |
|
74 #region Properties |
|
75 public XmlSettings Settings |
|
76 { |
|
77 get { return iSettings; } |
|
78 } |
|
79 |
|
80 public MenuStrip MenuBar |
|
81 { |
|
82 get { return iMenuBar; } |
|
83 } |
|
84 #endregion |
|
85 |
|
86 #region Event handlers |
|
87 private void TabStrip_SelectedTabChanged( TabStripTab aTab ) |
|
88 { |
|
89 TabStripPage page = aTab.Page; |
|
90 if ( page != null ) |
|
91 { |
|
92 // Get the corresponding tab host |
|
93 Control mainControl = aTab.Page.Body; |
|
94 CATab host = mainControl as CATab; |
|
95 if ( host != null ) |
|
96 { |
|
97 // Map tab host back to our tab type |
|
98 CAMenuItemList menuItems = this[ host ]; |
|
99 if ( menuItems != null ) |
|
100 { |
|
101 Activate( menuItems ); |
|
102 } |
|
103 } |
|
104 } |
|
105 } |
|
106 #endregion |
|
107 |
|
108 #region Internal methods |
|
109 private CAMenuItemList this[ CATab aHost ] |
|
110 { |
|
111 get |
|
112 { |
|
113 CAMenuItemList ret = null; |
|
114 // |
|
115 if ( iDictionary.ContainsKey( aHost ) ) |
|
116 { |
|
117 ret = iDictionary[ aHost ]; |
|
118 } |
|
119 // |
|
120 return ret; |
|
121 } |
|
122 } |
|
123 |
|
124 private void Activate( CAMenuItemList aList ) |
|
125 { |
|
126 if ( iActiveList != null ) |
|
127 { |
|
128 iActiveList.Deactivate(); |
|
129 iActiveList = null; |
|
130 } |
|
131 // |
|
132 iActiveList = aList; |
|
133 // |
|
134 if ( iActiveList != null ) |
|
135 { |
|
136 iActiveList.Activate(); |
|
137 } |
|
138 } |
|
139 #endregion |
|
140 |
|
141 #region Data members |
|
142 private readonly XmlSettings iSettings; |
|
143 private readonly MenuStrip iMenuBar; |
|
144 private readonly TabStripManager iTabStripManager; |
|
145 private CAMenuItemList iActiveList = null; |
|
146 private Dictionary<CATab, CAMenuItemList> iDictionary = new Dictionary<CATab, CAMenuItemList>(); |
|
147 #endregion |
|
148 } |
|
149 } |