Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
7f0e2484
Unverified
Commit
7f0e2484
authored
Feb 25, 2020
by
Evan W. Patton
Committed by
GitHub
Feb 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Perform menu item operations using identifiers as references (#2053)
Change-Id: Ib52c9c26f468c25b8c52fa3a99720898dc1b5c9a
parent
2c98e799
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
1 deletion
+45
-1
appinventor/appengine/src/com/google/appinventor/client/widgets/DropDownButton.java
...com/google/appinventor/client/widgets/DropDownButton.java
+45
-1
No files found.
appinventor/appengine/src/com/google/appinventor/client/widgets/DropDownButton.java
View file @
7f0e2484
...
@@ -16,7 +16,9 @@ import com.google.gwt.user.client.ui.MenuItem;
...
@@ -16,7 +16,9 @@ import com.google.gwt.user.client.ui.MenuItem;
import
com.google.gwt.user.client.ui.Image
;
import
com.google.gwt.user.client.ui.Image
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* Class representing a drop-down button with its associated menu. Note
* Class representing a drop-down button with its associated menu. Note
...
@@ -26,6 +28,7 @@ import java.util.List;
...
@@ -26,6 +28,7 @@ import java.util.List;
public
class
DropDownButton
extends
TextButton
{
public
class
DropDownButton
extends
TextButton
{
private
final
ContextMenu
menu
;
private
final
ContextMenu
menu
;
private
final
Map
<
String
,
MenuItem
>
itemsById
=
new
HashMap
<>();
private
final
List
<
MenuItem
>
items
;
private
final
List
<
MenuItem
>
items
;
private
final
boolean
rightAlign
;
private
final
boolean
rightAlign
;
...
@@ -187,7 +190,22 @@ public class DropDownButton extends TextButton {
...
@@ -187,7 +190,22 @@ public class DropDownButton extends TextButton {
if
(
item
==
null
)
{
if
(
item
==
null
)
{
menu
.
addSeparator
();
menu
.
addSeparator
();
}
else
{
}
else
{
items
.
add
(
menu
.
addItem
(
item
.
caption
,
true
,
item
.
command
));
MenuItem
menuItem
=
menu
.
addItem
(
item
.
caption
,
true
,
item
.
command
);
itemsById
.
put
(
item
.
widgetName
,
menuItem
);
items
.
add
(
menuItem
);
}
}
/**
* Removes a menu item identified by {@code id} if it exists.
*
* @param id the identifier of the menu item
*/
public
void
removeItemById
(
String
id
)
{
if
(
itemsById
.
containsKey
(
id
))
{
MenuItem
item
=
itemsById
.
remove
(
id
);
items
.
remove
(
item
);
menu
.
removeItem
(
item
);
}
}
}
}
...
@@ -201,6 +219,19 @@ public class DropDownButton extends TextButton {
...
@@ -201,6 +219,19 @@ public class DropDownButton extends TextButton {
}
}
}
}
/**
* Enables or disables a menu item identified by {@code id}.
*
* @param id the identifier of the menu item
* @param enabled true if the menu item should be enabled, false for disabled
*/
public
void
setItemEnabledById
(
String
id
,
boolean
enabled
)
{
MenuItem
item
=
itemsById
.
get
(
id
);
if
(
item
!=
null
)
{
item
.
setEnabled
(
enabled
);
}
}
public
void
setItemEnabled
(
String
itemName
,
boolean
enabled
)
{
public
void
setItemEnabled
(
String
itemName
,
boolean
enabled
)
{
for
(
MenuItem
item
:
items
)
{
for
(
MenuItem
item
:
items
)
{
if
(
item
.
getText
().
equals
(
itemName
))
{
if
(
item
.
getText
().
equals
(
itemName
))
{
...
@@ -216,6 +247,19 @@ public class DropDownButton extends TextButton {
...
@@ -216,6 +247,19 @@ public class DropDownButton extends TextButton {
items
.
add
(
menu
.
addItem
(
item
.
caption
,
true
,
item
.
command
));
items
.
add
(
menu
.
addItem
(
item
.
caption
,
true
,
item
.
command
));
}
}
/**
* Sets the HTML content of a menu item, identified by {@code id}, to the given {@code html}.
*
* @param id the identifier of the menu item
* @param html the HTML content to use for the menu item
*/
public
void
setItemHtmlById
(
String
id
,
String
html
)
{
MenuItem
item
=
itemsById
.
get
(
id
);
if
(
item
!=
null
)
{
item
.
setHTML
(
html
);
}
}
public
void
setCaption
(
String
caption
)
{
public
void
setCaption
(
String
caption
)
{
this
.
setText
(
caption
+
" \u25BE "
);
this
.
setText
(
caption
+
" \u25BE "
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment