Skip to content

Commit

Permalink
feat: Toggle undo/redo button state alongside editor state
Browse files Browse the repository at this point in the history
Allow button interactivity when undo/redo actions are available.
  • Loading branch information
dcalhoun committed Jan 8, 2025
1 parent dd12e2f commit fa5c90b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,11 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag
val helpMenuItem = menu.findItem(R.id.menu_editor_help)
if (undoItem != null) {
undoItem.setEnabled(menuHasUndo)
undoItem.setVisible(!htmlModeMenuStateOn && !isGutenbergKitEditor)
undoItem.setVisible(!htmlModeMenuStateOn)
}
if (redoItem != null) {
redoItem.setEnabled(menuHasRedo)
redoItem.setVisible(!htmlModeMenuStateOn && !isGutenbergKitEditor)
redoItem.setVisible(!htmlModeMenuStateOn)
}
if (secondaryAction != null && editPostRepository.hasPost()) {
secondaryAction.setVisible(showMenuItems && this.secondaryAction.isVisible)
Expand Down Expand Up @@ -2516,6 +2516,12 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag
storePostViewModel.savePostWithDelay()
}
})
editorFragment?.onEditorHistoryChanged(object : GutenbergView.HistoryChangeListener {
override fun onHistoryChanged(hasUndo: Boolean, hasRedo: Boolean) {
onToggleUndo(!hasUndo)
onToggleRedo(!hasRedo)
}
})
editorFragment?.onOpenMediaLibrary(object: GutenbergView.OpenMediaLibraryListener {
override fun onOpenMediaLibrary(config: GutenbergView.OpenMediaLibraryConfig) {
editorPhotoPicker?.allowMultipleSelection = config.multiple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import org.wordpress.aztec.util.AztecLog;
import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.xml.sax.Attributes;

Expand Down Expand Up @@ -711,6 +712,9 @@ public Pair<CharSequence, CharSequence> getTitleAndContent(CharSequence original
@Override public void onEditorContentChanged(@Nullable ContentChangeListener listener) {
}

@Override public void onEditorHistoryChanged(@Nullable HistoryChangeListener listener) {
}

@Override public void onOpenMediaLibrary(@Nullable OpenMediaLibraryListener listener) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;

import java.util.ArrayList;
Expand All @@ -41,6 +42,7 @@ public class EditorFragmentNotAddedException extends Exception {
public abstract Pair<CharSequence, CharSequence> getTitleAndContent(CharSequence originalContent) throws
EditorFragmentNotAddedException;
public abstract void onEditorContentChanged(ContentChangeListener listener);
public abstract void onEditorHistoryChanged(HistoryChangeListener listener);
public abstract void onOpenMediaLibrary(OpenMediaLibraryListener listener);
public abstract LiveData<Editable> getTitleOrContentChanged();
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.aztec.IHistoryListener;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.LogExceptionCallback;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergEmbedWebViewActivity;
Expand Down Expand Up @@ -1259,6 +1260,9 @@ public void onContentInfoReceived(HashMap<String, Object> contentInfo) {
public void onEditorContentChanged(@NonNull ContentChangeListener listener) {
}

public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) {
}

public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.wordpress.aztec.IHistoryListener;
import org.wordpress.gutenberg.GutenbergView;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.wordpress.gutenberg.GutenbergView.TitleAndContentCallback;
import org.wordpress.gutenberg.GutenbergWebViewPool;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class GutenbergKitEditorFragment extends EditorFragmentAbstract implement

private final LiveTextWatcher mTextWatcher = new LiveTextWatcher();
@Nullable private ContentChangeListener mContentChangeListener = null;
@Nullable private HistoryChangeListener mHistoryChangeListener = null;
@Nullable private OpenMediaLibraryListener mOpenMediaLibraryListener = null;

private boolean mEditorDidMount;
Expand Down Expand Up @@ -135,6 +137,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return null;
});
mGutenbergView.setContentChangeListener(mContentChangeListener);
mGutenbergView.setHistoryChangeListener(mHistoryChangeListener);
mGutenbergView.setOpenMediaLibraryListener(mOpenMediaLibraryListener);
mGutenbergView.setEditorDidBecomeAvailable(view -> {
mEditorFragmentListener.onEditorFragmentContentReady(new ArrayList<>(), false);
Expand Down Expand Up @@ -364,6 +367,10 @@ public void onEditorContentChanged(@NonNull ContentChangeListener listener) {
mContentChangeListener = listener;
}

public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) {
mHistoryChangeListener = listener;
}

public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) {
mOpenMediaLibraryListener = listener;
}
Expand Down Expand Up @@ -462,6 +469,7 @@ public void onDestroy() {
if (mGutenbergView != null) {
GutenbergWebViewPool.recycleWebView(mGutenbergView);
mContentChangeListener = null;
mHistoryChangeListener = null;
}
super.onDestroy();
}
Expand Down

0 comments on commit fa5c90b

Please sign in to comment.