Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.documentsui; |
| 18 | |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 19 | import android.app.Fragment; |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 20 | import android.view.KeyboardShortcutGroup; |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 21 | import android.view.Menu; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 22 | import android.view.MenuInflater; |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 23 | import android.view.MenuItem; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 24 | import android.view.View; |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 25 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 26 | import com.android.documentsui.base.DocumentInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 27 | import com.android.documentsui.base.Menus; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 28 | import com.android.documentsui.base.RootInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 29 | import com.android.documentsui.base.State; |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 30 | import com.android.documentsui.dirlist.DirectoryFragment; |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 31 | import com.android.documentsui.files.FilesActivity; |
Steve McKay | 3a26823 | 2016-10-19 11:15:47 -0700 | [diff] [blame] | 32 | import com.android.documentsui.queries.SearchViewManager; |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 33 | import com.android.documentsui.sidebar.RootsFragment; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 34 | import com.android.internal.annotations.VisibleForTesting; |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 35 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 36 | import java.util.List; |
| 37 | import java.util.function.IntFunction; |
| 38 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 39 | public abstract class MenuManager { |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 40 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 41 | final protected SearchViewManager mSearchManager; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 42 | final protected State mState; |
| 43 | final protected DirectoryDetails mDirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 44 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 45 | public MenuManager( |
| 46 | SearchViewManager searchManager, |
| 47 | State displayState, |
| 48 | DirectoryDetails dirDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 49 | mSearchManager = searchManager; |
| 50 | mState = displayState; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 51 | mDirDetails = dirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 54 | /** @see ActionModeController */ |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 55 | public void updateActionMenu(Menu menu, SelectionDetails selection) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 56 | updateOpenInActionMode(menu.findItem(R.id.menu_open), selection); |
Tomasz Mikolajewski | ac3e63e | 2017-02-13 10:08:58 +0900 | [diff] [blame] | 57 | updateOpenWith(menu.findItem(R.id.menu_open_with), selection); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 58 | updateDelete(menu.findItem(R.id.menu_delete), selection); |
| 59 | updateShare(menu.findItem(R.id.menu_share), selection); |
| 60 | updateRename(menu.findItem(R.id.menu_rename), selection); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 61 | updateSelectAll(menu.findItem(R.id.menu_select_all)); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 62 | updateMoveTo(menu.findItem(R.id.menu_move_to), selection); |
| 63 | updateCopyTo(menu.findItem(R.id.menu_copy_to), selection); |
Tomasz Mikolajewski | 26640ab | 2017-02-06 10:37:59 +0900 | [diff] [blame] | 64 | updateCompress(menu.findItem(R.id.menu_compress), selection); |
Tomasz Mikolajewski | 5a8e378 | 2017-01-24 12:40:55 +0900 | [diff] [blame] | 65 | updateExtractTo(menu.findItem(R.id.menu_extract_to), selection); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 66 | updateViewInOwner(menu.findItem(R.id.menu_view_in_owner), selection); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 67 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 68 | Menus.disableHiddenItems(menu); |
| 69 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 70 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 71 | /** @see BaseActivity#onPrepareOptionsMenu */ |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 72 | public void updateOptionMenu(Menu menu) { |
| 73 | updateCreateDir(menu.findItem(R.id.menu_create_dir)); |
| 74 | updateSettings(menu.findItem(R.id.menu_settings)); |
Jon Mann | 49be24c | 2017-02-13 17:29:20 -0800 | [diff] [blame] | 75 | updateSelectAll(menu.findItem(R.id.menu_select_all)); |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 76 | updateNewWindow(menu.findItem(R.id.menu_new_window)); |
| 77 | updateModePicker(menu.findItem(R.id.menu_grid), menu.findItem(R.id.menu_list)); |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 78 | updateAdvanced(menu.findItem(R.id.menu_advanced)); |
Jon Mann | eb1d11b | 2017-04-01 15:36:59 -0700 | [diff] [blame] | 79 | updateDebug(menu.findItem(R.id.menu_debug)); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 80 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 81 | Menus.disableHiddenItems(menu); |
| 82 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 83 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 84 | /** |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 85 | * Called when we needs {@link MenuManager} to ask Android to show context menu for us. |
| 86 | * {@link MenuManager} can choose to defeat this request. |
| 87 | * |
| 88 | * {@link #inflateContextMenuForDocs} and {@link #inflateContextMenuForContainer} are called |
| 89 | * afterwards when Android asks us to provide the content of context menus, so they're not |
| 90 | * correct locations to suppress context menus. |
| 91 | */ |
| 92 | public void showContextMenu(Fragment f, View v, float x, float y) { |
| 93 | // Pickers don't have any context menu at this moment. |
| 94 | } |
| 95 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 96 | public void inflateContextMenuForContainer(Menu menu, MenuInflater inflater) { |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 97 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 98 | } |
| 99 | |
| 100 | public void inflateContextMenuForDocs( |
| 101 | Menu menu, MenuInflater inflater, SelectionDetails selectionDetails) { |
| 102 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 103 | } |
| 104 | |
| 105 | /** |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 106 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 107 | * |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 108 | * Called when user tries to generate a context menu anchored to a file when the selection |
| 109 | * doesn't contain any folder. |
| 110 | * |
| 111 | * @param selectionDetails |
| 112 | * containsFiles may return false because this may be called when user right clicks on an |
| 113 | * unselectable item in pickers |
| 114 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 115 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 116 | public void updateContextMenuForFiles(Menu menu, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 117 | assert(selectionDetails != null); |
| 118 | |
| 119 | MenuItem share = menu.findItem(R.id.menu_share); |
| 120 | MenuItem open = menu.findItem(R.id.menu_open); |
| 121 | MenuItem openWith = menu.findItem(R.id.menu_open_with); |
| 122 | MenuItem rename = menu.findItem(R.id.menu_rename); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 123 | MenuItem viewInOwner = menu.findItem(R.id.menu_view_in_owner); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 124 | |
| 125 | updateShare(share, selectionDetails); |
| 126 | updateOpenInContextMenu(open, selectionDetails); |
| 127 | updateOpenWith(openWith, selectionDetails); |
| 128 | updateRename(rename, selectionDetails); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 129 | updateViewInOwner(viewInOwner, selectionDetails); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 130 | |
| 131 | updateContextMenu(menu, selectionDetails); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @see DirectoryFragment#onCreateContextMenu |
| 136 | * |
| 137 | * Called when user tries to generate a context menu anchored to a folder when the selection |
| 138 | * doesn't contain any file. |
| 139 | * |
| 140 | * @param selectionDetails |
| 141 | * containDirectories may return false because this may be called when user right clicks on |
| 142 | * an unselectable item in pickers |
| 143 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 144 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 145 | public void updateContextMenuForDirs(Menu menu, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 146 | assert(selectionDetails != null); |
| 147 | |
| 148 | MenuItem openInNewWindow = menu.findItem(R.id.menu_open_in_new_window); |
| 149 | MenuItem rename = menu.findItem(R.id.menu_rename); |
| 150 | MenuItem pasteInto = menu.findItem(R.id.menu_paste_into_folder); |
| 151 | |
| 152 | updateOpenInNewWindow(openInNewWindow, selectionDetails); |
| 153 | updateRename(rename, selectionDetails); |
| 154 | updatePasteInto(pasteInto, selectionDetails); |
| 155 | |
| 156 | updateContextMenu(menu, selectionDetails); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @see DirectoryFragment#onCreateContextMenu |
| 161 | * |
| 162 | * Update shared context menu items of both files and folders context menus. |
| 163 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 164 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 165 | public void updateContextMenu(Menu menu, SelectionDetails selectionDetails) { |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 166 | assert(selectionDetails != null); |
| 167 | |
| 168 | MenuItem cut = menu.findItem(R.id.menu_cut_to_clipboard); |
| 169 | MenuItem copy = menu.findItem(R.id.menu_copy_to_clipboard); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 170 | MenuItem delete = menu.findItem(R.id.menu_delete); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 171 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 172 | final boolean canCopy = |
| 173 | selectionDetails.size() > 0 && !selectionDetails.containsPartialFiles(); |
| 174 | final boolean canDelete = selectionDetails.canDelete(); |
| 175 | cut.setEnabled(canCopy && canDelete); |
| 176 | copy.setEnabled(canCopy); |
| 177 | delete.setEnabled(canDelete); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 180 | /** |
| 181 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 182 | * |
| 183 | * Called when user tries to generate a context menu anchored to an empty pane. |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 184 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 185 | @VisibleForTesting |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 186 | public void updateContextMenuForContainer(Menu menu) { |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 187 | MenuItem paste = menu.findItem(R.id.menu_paste_from_clipboard); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 188 | MenuItem selectAll = menu.findItem(R.id.menu_select_all); |
Garfield Tan | d330727 | 2016-10-10 13:33:25 -0700 | [diff] [blame] | 189 | MenuItem createDir = menu.findItem(R.id.menu_create_dir); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 190 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 191 | paste.setEnabled(mDirDetails.hasItemsToPaste() && mDirDetails.canCreateDoc()); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 192 | updateSelectAll(selectAll); |
Garfield Tan | d330727 | 2016-10-10 13:33:25 -0700 | [diff] [blame] | 193 | updateCreateDir(createDir); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 194 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 195 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 196 | /** |
| 197 | * @see RootsFragment#onCreateContextMenu |
| 198 | */ |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 199 | public void updateRootContextMenu(Menu menu, RootInfo root, DocumentInfo docInfo) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 200 | MenuItem eject = menu.findItem(R.id.menu_eject_root); |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 201 | MenuItem pasteInto = menu.findItem(R.id.menu_paste_into_folder); |
| 202 | MenuItem openInNewWindow = menu.findItem(R.id.menu_open_in_new_window); |
| 203 | MenuItem settings = menu.findItem(R.id.menu_settings); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 204 | |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 205 | updateEject(eject, root); |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 206 | updatePasteInto(pasteInto, root, docInfo); |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 207 | updateOpenInNewWindow(openInNewWindow, root); |
| 208 | updateSettings(settings, root); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 211 | public abstract void updateKeyboardShortcutsMenu( |
| 212 | List<KeyboardShortcutGroup> data, IntFunction<String> stringSupplier); |
| 213 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 214 | protected void updateModePicker(MenuItem grid, MenuItem list) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 215 | grid.setVisible(mState.derivedMode != State.MODE_GRID); |
| 216 | list.setVisible(mState.derivedMode != State.MODE_LIST); |
| 217 | } |
| 218 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 219 | protected void updateAdvanced(MenuItem advanced) { |
Steve McKay | 01996bc | 2016-10-21 13:38:49 -0700 | [diff] [blame] | 220 | advanced.setVisible(mState.showDeviceStorageOption); |
| 221 | advanced.setTitle(mState.showDeviceStorageOption && mState.showAdvanced |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 222 | ? R.string.menu_advanced_hide : R.string.menu_advanced_show); |
| 223 | } |
| 224 | |
Jon Mann | eb1d11b | 2017-04-01 15:36:59 -0700 | [diff] [blame] | 225 | protected void updateDebug(MenuItem debug) { |
| 226 | debug.setVisible(mState.debugMode); |
| 227 | } |
| 228 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 229 | protected void updateSettings(MenuItem settings) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 230 | settings.setVisible(false); |
| 231 | } |
| 232 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 233 | protected void updateSettings(MenuItem settings, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 234 | settings.setVisible(false); |
| 235 | } |
| 236 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 237 | protected void updateEject(MenuItem eject, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 238 | eject.setVisible(false); |
| 239 | } |
| 240 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 241 | protected void updateNewWindow(MenuItem newWindow) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 242 | newWindow.setVisible(false); |
| 243 | } |
| 244 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 245 | protected void updateOpenInActionMode(MenuItem open, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 246 | open.setVisible(false); |
| 247 | } |
| 248 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 249 | protected void updateOpenWith(MenuItem openWith, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 250 | openWith.setVisible(false); |
| 251 | } |
| 252 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 253 | protected void updateOpenInNewWindow( |
| 254 | MenuItem openInNewWindow, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 255 | openInNewWindow.setVisible(false); |
| 256 | } |
| 257 | |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 258 | protected void updateOpenInNewWindow( |
| 259 | MenuItem openInNewWindow, RootInfo root) { |
| 260 | openInNewWindow.setVisible(false); |
| 261 | } |
| 262 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 263 | protected void updateShare(MenuItem share, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 264 | share.setVisible(false); |
| 265 | } |
| 266 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 267 | protected void updateDelete(MenuItem delete, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 268 | delete.setVisible(false); |
| 269 | } |
| 270 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 271 | protected void updateRename(MenuItem rename, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 272 | rename.setVisible(false); |
| 273 | } |
| 274 | |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 275 | protected void updateViewInOwner(MenuItem view, SelectionDetails selectionDetails) { |
| 276 | view.setVisible(false); |
| 277 | } |
| 278 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 279 | protected void updateMoveTo(MenuItem moveTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 280 | moveTo.setVisible(false); |
| 281 | } |
| 282 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 283 | protected void updateCopyTo(MenuItem copyTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 284 | copyTo.setVisible(false); |
| 285 | } |
| 286 | |
Tomasz Mikolajewski | 26640ab | 2017-02-06 10:37:59 +0900 | [diff] [blame] | 287 | protected void updateCompress(MenuItem compress, SelectionDetails selectionDetails) { |
| 288 | compress.setVisible(false); |
| 289 | } |
| 290 | |
Tomasz Mikolajewski | 5a8e378 | 2017-01-24 12:40:55 +0900 | [diff] [blame] | 291 | protected void updateExtractTo(MenuItem extractTo, SelectionDetails selectionDetails) { |
| 292 | extractTo.setVisible(false); |
| 293 | } |
| 294 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 295 | protected void updatePasteInto(MenuItem pasteInto, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 296 | pasteInto.setVisible(false); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 299 | protected void updatePasteInto(MenuItem pasteInto, RootInfo root, DocumentInfo docInfo) { |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 300 | pasteInto.setVisible(false); |
| 301 | } |
| 302 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 303 | protected abstract void updateOpenInContextMenu( |
| 304 | MenuItem open, SelectionDetails selectionDetails); |
| 305 | protected abstract void updateSelectAll(MenuItem selectAll); |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 306 | protected abstract void updateCreateDir(MenuItem createDir); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 307 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 308 | /** |
| 309 | * Access to meta data about the selection. |
| 310 | */ |
| 311 | public interface SelectionDetails { |
| 312 | boolean containsDirectories(); |
| 313 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 314 | boolean containsFiles(); |
| 315 | |
| 316 | int size(); |
| 317 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 318 | boolean containsPartialFiles(); |
| 319 | |
| 320 | // TODO: Update these to express characteristics instead of answering concrete questions, |
| 321 | // since the answer to those questions is (or can be) activity specific. |
| 322 | boolean canDelete(); |
| 323 | |
| 324 | boolean canRename(); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 325 | |
| 326 | boolean canPasteInto(); |
Tomasz Mikolajewski | 5a8e378 | 2017-01-24 12:40:55 +0900 | [diff] [blame] | 327 | |
| 328 | boolean canExtract(); |
Tomasz Mikolajewski | ac3e63e | 2017-02-13 10:08:58 +0900 | [diff] [blame] | 329 | |
| 330 | boolean canOpenWith(); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 331 | |
| 332 | boolean canViewInOwner(); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | public static class DirectoryDetails { |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 336 | private final BaseActivity mActivity; |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 337 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 338 | public DirectoryDetails(BaseActivity activity) { |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 339 | mActivity = activity; |
| 340 | } |
| 341 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 342 | public boolean hasRootSettings() { |
| 343 | return mActivity.getCurrentRoot().hasSettings(); |
| 344 | } |
| 345 | |
| 346 | public boolean hasItemsToPaste() { |
| 347 | return false; |
| 348 | } |
| 349 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 350 | public boolean canCreateDoc() { |
| 351 | return isInRecents() ? false : mActivity.getCurrentDirectory().isCreateSupported(); |
| 352 | } |
| 353 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 354 | public boolean isInRecents() { |
| 355 | return mActivity.getCurrentDirectory() == null; |
| 356 | } |
| 357 | |
| 358 | public boolean canCreateDirectory() { |
| 359 | return mActivity.canCreateDirectory(); |
| 360 | } |
| 361 | } |
| 362 | } |