private void _notificationSink_BlogProviderButtonNotificationReceived(string blogId, string buttonId) { lock (_commandsLock) { // see if we are currently managing this button (can get "stale" notifications if they // come in from a background thread after we have switched blogs) if (_editingManager != null && _editingManager.BlogId == blogId) { bool refreshRequired = false; // Find the gallery item corresponding to this buttonId foreach (GalleryItem item in items) { Command command = item.Cookie; if (command != null) { BlogProviderButton providerButton = command.Tag as BlogProviderButton; if (providerButton != null && providerButton.Id == buttonId) { command.LargeImage = providerButton.CurrentImage; command.LabelTitle = providerButton.CurrentText; command.CommandBarButtonBitmapEnabled = providerButton.CurrentImage; command.Text = providerButton.CurrentText; command.AccessibleName = providerButton.CurrentText; // GalleryItem calls dispose on the bitmap, so give it a new copy item.Image = new Bitmap(providerButton.CurrentImage); item.Label = TextHelper.GetTitleFromText(providerButton.CurrentText, RibbonHelper.GalleryItemTextMaxChars, TextHelper.Units.Characters); // We are done updating the gallery item, flag for refresh refreshRequired = true; break; } } } // Reload the shortcuts gallery to actually see any changes made above. // Invalidating 'ItemsSource' property will cause ribbon to reload items if (refreshRequired) { Invalidate(new PropertyKey[] { PropertyKeys.ItemsSource }); } } } }
private void BlogProviderButton_Execute(object sender, EventArgs e) { lock (_commandsLock) { // get the command and frame button Command command = sender as Command; BlogProviderButton blogProviderButton = command.Tag as BlogProviderButton; // notify the button that it is being clicked blogProviderButton.RecordButtonClicked(); // launch the browser if (!String.IsNullOrEmpty(blogProviderButton.ClickUrl)) { ShellHelper.LaunchUrl(blogProviderButton.ClickUrl); } else if (!String.IsNullOrEmpty(blogProviderButton.ContentUrl)) { ShellHelper.LaunchUrl(blogProviderButton.ContentUrl); } } }
public BlogProviderContentViewer(BlogProviderButton button) { _button = button; }
/// <summary> /// Must be called under the proection of _commandsLock. /// </summary> /// <param name="blog"></param> private void ConnectToBlog(Blog blog) { items.Clear(); UpdateInvalidationState(PropertyKeys.ItemsSource, InvalidationState.Pending); InvalidateSelectedItemProperties(); // always clear existing providers to start ClearBlogProvider(); blogAdminUrl = _editingManager.BlogAdminUrl; // Add the homepage link commandsOffset = 1; string homepageLinkText = _editingManager.Blog.ClientOptions.HomepageLinkText; items.Add(new GalleryItem(!String.IsNullOrEmpty(homepageLinkText) ? homepageLinkText : Res.Get(StringId.ViewWeblog), Images.BlogWebPreview_SmallImage, commandViewWeblog)); // Add the admin link, if we've got one. if (blogAdminUrl != String.Empty) { commandsOffset++; // @RIBBON TODO: Add an icon for the admin link item string adminLinkText = _editingManager.Blog.ClientOptions.AdminLinkText; items.Add(new GalleryItem(!String.IsNullOrEmpty(adminLinkText) ? adminLinkText : Res.Get(StringId.ManageWeblog), Images.BlogAccount_SmallImage, commandViewWeblogAdmin)); } if (PostEditorSettings.AllowProviderButtons) { // Now add the custom blog provider buttons IBlogProviderButtonDescription[] providerButtonDescriptions = blog.ButtonDescriptions; if (providerButtonDescriptions.Length > 0) { // create buttons and attach to commands for (int i = 0; (i < providerButtonDescriptions.Length) && (i < _commands.Length); i++) { // create button BlogProviderButton providerButton = new BlogProviderButton(blog.Id, blog.HostBlogId, blog.HomepageUrl, blog.PostApiUrl, providerButtonDescriptions[i].Id); // notify button we are connecting (allows it to reset notification image and // force an immediate notification check) providerButton.ConnectToFrame(); // connect button to frame _commands[i].On = true; _commands[i].Tag = providerButton; _commands[i].Enabled = PostEditorSettings.AllowProviderButtons; _commands[i].AccessibleName = providerButton.CurrentText; _commands[i].LabelTitle = providerButton.CurrentText; _commands[i].LargeImage = providerButton.CurrentImage; // @RIBBON TODO: Cleanly remove obsolete code string clippedName = TextHelper.GetTitleFromText(providerButton.CurrentText, RibbonHelper.GalleryItemTextMaxChars, TextHelper.Units.Characters); Bitmap bitmap = (providerButton.CurrentImage != null) ? new Bitmap(providerButton.CurrentImage) : null; items.Add(new GalleryItem(clippedName, bitmap, _commands[i])); if (providerButton.SupportsContent) { // install drop down content source _commands[i].CommandBarButtonContextMenuHandler = new CommandBarButtonContextMenuHandler( new BlogProviderContentViewer(providerButton).ViewContent); // make separate drop down for split buttons if (providerButton.SupportsClick) { _commands[i].CommandBarButtonContextMenuDropDown = true; } else { _commands[i].CommandBarButtonContextMenuDropDown = false; } } else { RemoveDropDownMenu(_commands[i]); } } // attach notification sink _notificationSink.Attach(blog); } OnStateChanged(EventArgs.Empty); } }