Skip to content
This repository was archived by the owner on Dec 13, 2017. It is now read-only.

Commit 90d690f

Browse files
BaudouinBaudouin
authored andcommitted
Expose a way to make visible or hidden a toolbar item
refs #4427 - In order to be able to hide the “Insert image” button when a WordPress user doesn’t have the upload_files capabilities, I need to be able to set the hidden property of the toolbar button item. Because of the specifics of the implementation of WPEditorFormatbarView, rather than exposing a UIBarButtonItem* property to be consumed directly by the app, it’s better to provide a helper method that will, similarly to -enableToolbarItem:showSourceButton:, do the work under the hood of the editor itself.
1 parent 16e4b80 commit 90d690f

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Classes/WPEditorFormatbarView.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ typedef enum
139139

140140
#pragma mark - Toolbar items
141141

142+
/**
143+
* @brief Makes a toolbar item visible or hidden
144+
*
145+
* @param tag WPEditorViewControllerElementTag of the item to alter.
146+
* @param visible YES to make the item visible, NO to hide it.
147+
*/
148+
- (void)toolBarItemWithTag:(WPEditorViewControllerElementTag)tag setVisible:(BOOL)visible;
149+
142150
/**
143151
* @brief Enables and disables the toolbar items.
144152
*

Classes/WPEditorFormatbarView.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ - (void)setSelectedItemTintColor:(UIColor *)selectedItemTintColor
189189

190190
#pragma mark - Toolbar items
191191

192+
- (void)toolBarItemWithTag:(WPEditorViewControllerElementTag)tag setVisible:(BOOL)visible
193+
{
194+
for (ZSSBarButtonItem *item in self.leftToolbar.items) {
195+
if (item.tag == tag) {
196+
item.customView.hidden = !visible;
197+
}
198+
}
199+
200+
for (ZSSBarButtonItem *item in self.regularToolbar.items) {
201+
if (item.tag == tag) {
202+
item.customView.hidden = !visible;
203+
}
204+
}
205+
}
206+
192207
- (void)enableToolbarItems:(BOOL)enable
193208
shouldShowSourceButton:(BOOL)showSource
194209
{

0 commit comments

Comments
 (0)