From 9de85b8772f28bc4f7abab63927dd8b448207dcb Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 12 Nov 2013 12:44:19 +0000 Subject: [PATCH] CP-6267: Restored status strip on the main window. Signed-off-by: Konstantina Chremmou --- .../MainWindowControls/NavigationPane.cs | 11 ++ .../MainWindowControls/NavigationView.cs | 14 ++- XenAdmin/MainWindow.Designer.cs | 32 ++++++ XenAdmin/MainWindow.cs | 59 +++++++++- XenAdmin/MainWindow.resx | 107 ++++++++++++++---- XenAdmin/Plugins/Features/TabPageFeature.cs | 41 +++++++ 6 files changed, 237 insertions(+), 27 deletions(-) diff --git a/XenAdmin/Controls/MainWindowControls/NavigationPane.cs b/XenAdmin/Controls/MainWindowControls/NavigationPane.cs index cb5bc9dcc..25cb7b5fe 100644 --- a/XenAdmin/Controls/MainWindowControls/NavigationPane.cs +++ b/XenAdmin/Controls/MainWindowControls/NavigationPane.cs @@ -83,12 +83,16 @@ namespace XenAdmin.Controls.MainWindowControls [Browsable(true)] public event Action TreeViewRefreshResumed; + internal event Action DragDropCommandActivated; + #endregion public NavigationPane() { InitializeComponent(); + navigationView.DragDropCommandActivated += navigationView_DragDropCommandActivated; + AddNavigationItemPair(buttonInfraBig, buttonInfraSmall); AddNavigationItemPair(buttonObjectsBig, buttonObjectsSmall); AddNavigationItemPair(buttonOrganizationBig, buttonOrganizationSmall); @@ -282,6 +286,13 @@ namespace XenAdmin.Controls.MainWindowControls #region Control Event Handlers + private void navigationView_DragDropCommandActivated(string cmdText) + { + if (DragDropCommandActivated != null) + DragDropCommandActivated(cmdText); + } + + private void navigationView_TreeViewSelectionChanged() { if (TreeViewSelectionChanged != null) diff --git a/XenAdmin/Controls/MainWindowControls/NavigationView.cs b/XenAdmin/Controls/MainWindowControls/NavigationView.cs index 5694d54cb..1b2fdcf36 100644 --- a/XenAdmin/Controls/MainWindowControls/NavigationView.cs +++ b/XenAdmin/Controls/MainWindowControls/NavigationView.cs @@ -89,6 +89,8 @@ namespace XenAdmin.Controls.MainWindowControls [Browsable(true)] public event Action TreeViewRefreshResumed; + internal event Action DragDropCommandActivated; + #endregion public NavigationView() @@ -451,6 +453,9 @@ namespace XenAdmin.Controls.MainWindowControls _highlightedDragTarget.ForeColor = treeView.ForeColor; _highlightedDragTarget = null; treeBuilder.HighlightedDragTarget = null; + + if (DragDropCommandActivated != null) + DragDropCommandActivated(null); } } @@ -697,13 +702,20 @@ namespace XenAdmin.Controls.MainWindowControls } VirtualTreeNode targetToHighlight = null; - + + string statusBarText = null; foreach (DragDropCommand cmd in GetDragDropCommands(targetNode, e.Data)) { if (cmd.CanExecute()) targetToHighlight = cmd.HighlightNode; + + if (cmd.StatusBarText != null) + statusBarText = cmd.StatusBarText; } + if (DragDropCommandActivated != null) + DragDropCommandActivated(statusBarText); + if (targetToHighlight != null) { if (_highlightedDragTarget != targetToHighlight) diff --git a/XenAdmin/MainWindow.Designer.cs b/XenAdmin/MainWindow.Designer.cs index ee2a3a17d..047a09b0f 100644 --- a/XenAdmin/MainWindow.Designer.cs +++ b/XenAdmin/MainWindow.Designer.cs @@ -269,6 +269,9 @@ namespace XenAdmin this.MainMenuBar = new XenAdmin.Controls.MenuStripEx(); this.securityGroupsToolStripMenuItem = new XenAdmin.Commands.CommandToolStripMenuItem(); this.MenuPanel = new System.Windows.Forms.Panel(); + this.StatusStrip = new System.Windows.Forms.StatusStrip(); + this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusProgressBar = new System.Windows.Forms.ToolStripProgressBar(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); @@ -282,6 +285,7 @@ namespace XenAdmin this.ToolBarContextMenu.SuspendLayout(); this.MainMenuBar.SuspendLayout(); this.MenuPanel.SuspendLayout(); + this.StatusStrip.SuspendLayout(); this.SuspendLayout(); // // splitContainer1 @@ -1742,6 +1746,28 @@ namespace XenAdmin resources.ApplyResources(this.MenuPanel, "MenuPanel"); this.MenuPanel.Name = "MenuPanel"; // + // StatusStrip + // + resources.ApplyResources(this.StatusStrip, "StatusStrip"); + this.StatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.statusLabel, + this.statusProgressBar}); + this.StatusStrip.Name = "StatusStrip"; + // + // statusLabel + // + resources.ApplyResources(this.statusLabel, "statusLabel"); + this.statusLabel.Name = "statusLabel"; + this.statusLabel.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never; + this.statusLabel.Spring = true; + // + // statusProgressBar + // + resources.ApplyResources(this.statusProgressBar, "statusProgressBar"); + this.statusProgressBar.Margin = new System.Windows.Forms.Padding(5); + this.statusProgressBar.Name = "statusProgressBar"; + this.statusProgressBar.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never; + // // MainWindow // resources.ApplyResources(this, "$this"); @@ -1749,6 +1775,7 @@ namespace XenAdmin this.Controls.Add(this.splitContainer1); this.Controls.Add(this.ToolStrip); this.Controls.Add(this.MenuPanel); + this.Controls.Add(this.StatusStrip); this.DoubleBuffered = true; this.KeyPreview = true; this.MainMenuStrip = this.MainMenuBar; @@ -1775,6 +1802,8 @@ namespace XenAdmin this.MainMenuBar.ResumeLayout(false); this.MainMenuBar.PerformLayout(); this.MenuPanel.ResumeLayout(false); + this.StatusStrip.ResumeLayout(false); + this.StatusStrip.PerformLayout(); this.ResumeLayout(false); } @@ -1989,6 +2018,9 @@ namespace XenAdmin private ToolStripMenuItem customTemplatesToolStripMenuItem; private ToolStripMenuItem templatesToolStripMenuItem1; private ToolStripMenuItem localStorageToolStripMenuItem; + private StatusStrip StatusStrip; + private ToolStripStatusLabel statusLabel; + private ToolStripProgressBar statusProgressBar; } } diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index 1aa1006e7..b4311d55c 100644 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -99,6 +99,9 @@ namespace XenAdmin internal readonly VMStoragePage VMStoragePage = new VMStoragePage(); internal readonly AdPage AdPage = new AdPage(); + private ActionBase statusBarAction = null; + public ActionBase StatusBarAction { get { return statusBarAction; } } + private bool IgnoreTabChanges = false; private bool ToolbarsEnabled; @@ -165,6 +168,7 @@ namespace XenAdmin AddTabContents(SearchPage, TabPageSearch); TheTabControl.SelectedIndexChanged += TheTabControl_SelectedIndexChanged; + navigationPane.DragDropCommandActivated += navigationPane_DragDropCommandActivated; PoolCollectionChangedWithInvoke = Program.ProgramInvokeHandler(CollectionChanged); MessageCollectionChangedWithInvoke = Program.ProgramInvokeHandler(MessageCollectionChanged); @@ -184,7 +188,6 @@ namespace XenAdmin contextMenuBuilder = new ContextMenuBuilder(pluginManager, commandInterface); SearchPage.SearchChanged += SearchPanel_SearchChanged; - Alert.XenCenterAlerts.CollectionChanged += XenCenterAlerts_CollectionChanged; FormFontFixer.Fix(this); @@ -197,6 +200,8 @@ namespace XenAdmin TitleLabel.ForeColor = Program.TitleBarForeColor; loggedInLabel1.SetTextColor(Program.TitleBarForeColor); + statusProgressBar.Visible = false; + SelectionManager.BindTo(MainMenuBar.Items, commandInterface); SelectionManager.BindTo(ToolStrip.Items, commandInterface); Properties.Settings.Default.SettingChanging += Default_SettingChanging; @@ -362,6 +367,17 @@ namespace XenAdmin if (action == null) return; + var meddlingAction = action as MeddlingAction; + if (meddlingAction == null) + { + SetStatusBar(null, null); + if (statusBarAction != null) + { + statusBarAction.Changed -= actionChanged; + statusBarAction.Completed -= actionChanged; + } + statusBarAction = action; + } action.Changed += actionChanged; action.Completed += actionChanged; actionChanged(action); @@ -378,15 +394,26 @@ namespace XenAdmin void actionChanged_(ActionBase action) { + var meddlingAction = action as MeddlingAction; + if (meddlingAction == null) + statusProgressBar.Visible = action.ShowProgress && !action.IsCompleted; + // Be defensive against CA-8517. if (action.PercentComplete < 0 || action.PercentComplete > 100) { log.ErrorFormat("PercentComplete is erroneously {0}", action.PercentComplete); } + else if (meddlingAction == null) + { + statusProgressBar.Value = action.PercentComplete; + } // Don't show cancelled exception if (action.Exception != null && !(action.Exception is CancelledException)) { + if (meddlingAction == null) + SetStatusBar(XenAdmin.Properties.Resources._000_error_h32bit_16, action.Exception.Message); + IXenObject model = (IXenObject)action.VM ?? (IXenObject)action.Host ?? @@ -397,6 +424,31 @@ namespace XenAdmin RequestRefreshTreeView(); } + else if (meddlingAction == null) + { + SetStatusBar(null, + action.IsCompleted ? null : + !string.IsNullOrEmpty(action.Description) ? action.Description : + !string.IsNullOrEmpty(action.Title) ? action.Title : + null); + } + } + + public void SetStatusBar(Image image, string message) + { + if ((statusLabel.Text != null && statusLabel.Text.Equals(message)) + || (statusLabel.Image != null && statusLabel.Equals(image))) + return; + + statusLabel.Image = image; + statusLabel.Text = Helpers.FirstLine(message); + statusToolTip.SetToolTip(StatusStrip, message); + } + + public void SetProgressBar(bool visible, int progress) + { + statusProgressBar.Visible = visible; + statusProgressBar.Value = progress; } private void MainWindow_Shown(object sender, EventArgs e) @@ -2512,6 +2564,11 @@ namespace XenAdmin return name; } + void navigationPane_DragDropCommandActivated(string cmdText) + { + SetStatusBar(null, cmdText); + } + private void navigationPane_TreeViewSelectionChanged() { UpdateToolbars(); diff --git a/XenAdmin/MainWindow.resx b/XenAdmin/MainWindow.resx index 984b5e54b..da75bc2c0 100644 --- a/XenAdmin/MainWindow.resx +++ b/XenAdmin/MainWindow.resx @@ -135,7 +135,7 @@ 0, 0 - 243, 675 + 243, 648 @@ -187,7 +187,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 8 @@ -217,7 +217,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 4 @@ -244,7 +244,7 @@ 4, 22 - 753, 619 + 753, 592 14 @@ -268,7 +268,7 @@ 4, 22 - 753, 619 + 753, 592 19 @@ -298,7 +298,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 1 @@ -328,7 +328,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 6 @@ -358,7 +358,7 @@ 3, 3, 3, 3 - 753, 619 + 753, 592 12 @@ -388,7 +388,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 7 @@ -418,7 +418,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 7 @@ -448,7 +448,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 8 @@ -481,7 +481,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 2 @@ -508,7 +508,7 @@ 3, 3, 3, 3 - 753, 619 + 753, 592 10 @@ -535,7 +535,7 @@ 3, 3, 3, 3 - 753, 619 + 753, 592 15 @@ -568,7 +568,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 0 @@ -592,7 +592,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 17 @@ -616,7 +616,7 @@ 4, 22 - 753, 619 + 753, 592 14 @@ -640,7 +640,7 @@ 4, 22 - 753, 619 + 753, 592 16 @@ -664,7 +664,7 @@ 4, 22 - 753, 619 + 753, 592 18 @@ -694,7 +694,7 @@ 0, 0, 0, 0 - 753, 619 + 753, 592 0 @@ -724,7 +724,7 @@ 0, 0 - 761, 645 + 761, 618 0 @@ -754,7 +754,7 @@ 12, 12, 12, 12 - 761, 645 + 761, 618 0 @@ -784,7 +784,7 @@ 12, 12, 12, 12 - 761, 645 + 761, 618 0 @@ -814,7 +814,7 @@ 12, 12, 12, 12 - 761, 645 + 761, 618 5 @@ -1027,7 +1027,7 @@ 100 - 1008, 675 + 1008, 648 243 @@ -2453,6 +2453,51 @@ 3 + + 0, 703 + + + False + + + MiddleLeft + + + 852, 22 + + + MiddleLeft + + + False + + + 100, 17 + + + 0, 703 + + + 1008, 27 + + + 3 + + + statusStrip1 + + + StatusStrip + + + System.Windows.Forms.StatusStrip, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + True @@ -3500,6 +3545,18 @@ XenAdmin.Commands.CommandToolStripMenuItem, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + statusLabel + + + System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + statusProgressBar + + + System.Windows.Forms.ToolStripProgressBar, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainWindow diff --git a/XenAdmin/Plugins/Features/TabPageFeature.cs b/XenAdmin/Plugins/Features/TabPageFeature.cs index e61783d4f..d90d91d4e 100644 --- a/XenAdmin/Plugins/Features/TabPageFeature.cs +++ b/XenAdmin/Plugins/Features/TabPageFeature.cs @@ -42,7 +42,9 @@ using System.Windows.Forms; using System.Xml; using XenAdmin.Core; using XenAdmin.Network; +using XenAdmin.XenSearch; using XenAPI; +using XenAdmin.Actions; namespace XenAdmin.Plugins @@ -112,6 +114,8 @@ namespace XenAdmin.Plugins private WebBrowser2 Browser; private bool UrlIsLoaded; + private ActionBase MainWindowActionAtNavigateTime = null; + /// /// If true, this indicates that the most recent Navigation was an error. /// @@ -195,6 +199,7 @@ namespace XenAdmin.Plugins Browser = new WebBrowser2(); Browser.Dock = DockStyle.Fill; Browser.IsWebBrowserContextMenuEnabled = ContextEnabled; + Browser.ProgressChanged += Browser_ProgressChanged; Browser.DocumentCompleted += Browser_DocumentCompleted; Browser.Navigating += Browser_Navigating; Browser.Navigated += Browser_Navigated; @@ -301,6 +306,17 @@ namespace XenAdmin.Plugins { Program.AssertOnEventThread(); + if (tabControl != null && tabControl.SelectedTab != null && tabControl.SelectedTab.Tag == this) + { + if (Program.MainWindow.StatusBarAction == null + || Program.MainWindow.StatusBarAction.IsCompleted && MainWindowActionAtNavigateTime.Equals(Program.MainWindow.StatusBarAction)) + { + // we still have 'control' of the status bar + Program.MainWindow.SetProgressBar(false, 0); + Program.MainWindow.SetStatusBar(null, null); + } + } + if (!XenCenterOnly && lastBrowserState != null) { log.DebugFormat("url for '{0}' set to '{1}'", Helpers.GetName(lastBrowserState.Obj), e.Url); @@ -308,6 +324,31 @@ namespace XenAdmin.Plugins } } + private void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) + { + Program.AssertOnEventThread(); + + if (tabControl != null && tabControl.SelectedTab != null && tabControl.SelectedTab.Tag == this) + { + if (e.MaximumProgress != 0) + { + if (Program.MainWindow.StatusBarAction == null || Program.MainWindow.StatusBarAction.IsCompleted) + { + MainWindowActionAtNavigateTime = Program.MainWindow.StatusBarAction; + int progr = Convert.ToInt32((e.CurrentProgress * 100L) / (e.MaximumProgress)); + Program.MainWindow.SetProgressBar(true, progr); + } + if (Browser.Url != null) + { + string text = e.CurrentProgress >= e.MaximumProgress + ? "" + : string.Format(Messages.LOADING, Browser.Url.ToString().Ellipsise(50)); + Program.MainWindow.SetStatusBar(null, text); + } + } + } + } + [DllImport("wininet.dll", SetLastError = true)] private static extern long DeleteUrlCacheEntry(string url);