|
11 | 11 | using Microsoft.UI.Xaml.Input; |
12 | 12 | using System.IO; |
13 | 13 | using System.Windows.Input; |
| 14 | +using Windows.AI.Actions; |
| 15 | +using Windows.AI.Actions.Hosting; |
14 | 16 | using Windows.ApplicationModel.DataTransfer; |
| 17 | +using Microsoft.Windows.ApplicationModel.Resources; |
15 | 18 | using Windows.UI.Text; |
| 19 | +using Microsoft.UI.Xaml.Media.Imaging; |
16 | 20 |
|
17 | 21 | namespace Files.App.ViewModels.UserControls |
18 | 22 | { |
@@ -65,6 +69,8 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr |
65 | 69 |
|
66 | 70 | // Properties |
67 | 71 |
|
| 72 | + internal static ActionRuntime? ActionRuntime { get; private set; } |
| 73 | + |
68 | 74 | public ObservableCollection<PathBoxItem> PathComponents { get; } = []; |
69 | 75 |
|
70 | 76 | public ObservableCollection<NavigationBarSuggestionItem> NavigationBarSuggestions { get; } = []; |
@@ -248,7 +254,6 @@ public bool IsOmnibarFocused |
248 | 254 | _ = PopulateOmnibarSuggestionsForPathMode(); |
249 | 255 | break; |
250 | 256 | case OmnibarPaletteModeName: |
251 | | - if (OmnibarCommandPaletteModeSuggestionItems.Count is 0) |
252 | 257 | PopulateOmnibarSuggestionsForCommandPaletteMode(); |
253 | 258 | break; |
254 | 259 | case OmnibarSearchModeName: |
@@ -1172,23 +1177,60 @@ public void PopulateOmnibarSuggestionsForCommandPaletteMode() |
1172 | 1177 | OmnibarCommandPaletteModeText ??= string.Empty; |
1173 | 1178 | OmnibarCommandPaletteModeSuggestionItems.Clear(); |
1174 | 1179 |
|
1175 | | - var suggestionItems = Commands.Where(command => |
1176 | | - command.IsExecutable && |
1177 | | - command.IsAccessibleGlobally && |
1178 | | - (command.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase) || |
1179 | | - command.Code.ToString().Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) |
1180 | | - .Select(command => new NavigationBarSuggestionItem() |
| 1180 | + if (ContentPageContext.SelectedItems.Count == 1 && ContentPageContext.SelectedItem is not null && !ContentPageContext.SelectedItem.IsFolder) |
1181 | 1181 | { |
1182 | | - ThemedIconStyle = command.Glyph.ToThemedIconStyle(), |
1183 | | - Glyph = command.Glyph.BaseGlyph, |
1184 | | - Text = command.Code.ToString(), |
1185 | | - PrimaryDisplay = command.Description, |
1186 | | - HotKeys = command.HotKeys, |
1187 | | - SearchText = OmnibarCommandPaletteModeText, |
1188 | | - }); |
| 1182 | + var dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); |
| 1183 | + |
| 1184 | + dispatcherQueue.TryEnqueue(() => |
| 1185 | + { |
| 1186 | + var selectedItemPath = ContentPageContext.SelectedItem.ItemPath; |
| 1187 | + var fileActionEntity = ActionManager.Instance.EntityFactory.CreateFileEntity(selectedItemPath); |
| 1188 | + var actions = ActionManager.Instance.ActionRuntime.ActionCatalog.GetActionsForInputs(new[] { fileActionEntity }); |
| 1189 | + |
| 1190 | + foreach (var action in actions.Where(a => a.Definition.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) |
| 1191 | + { |
| 1192 | + var newItem = new NavigationBarSuggestionItem |
| 1193 | + { |
| 1194 | + PrimaryDisplay = action.Definition.Description, |
| 1195 | + SearchText = OmnibarCommandPaletteModeText, |
| 1196 | + ActionInstance = action |
| 1197 | + }; |
| 1198 | + |
| 1199 | + if (Uri.TryCreate(action.Definition.IconFullPath, UriKind.RelativeOrAbsolute, out Uri? validUri)) |
| 1200 | + { |
| 1201 | + try |
| 1202 | + { |
| 1203 | + newItem.ActionIconSource = new BitmapImage(validUri); |
| 1204 | + } |
| 1205 | + catch (Exception) |
| 1206 | + { |
| 1207 | + } |
| 1208 | + } |
| 1209 | + |
| 1210 | + OmnibarCommandPaletteModeSuggestionItems.Add(newItem); |
| 1211 | + } |
| 1212 | + }); |
| 1213 | + } |
| 1214 | + |
| 1215 | + var suggestionItems = Commands |
| 1216 | + .Where(command => command.IsExecutable |
| 1217 | + && command.IsAccessibleGlobally |
| 1218 | + && (command.Description.Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase) |
| 1219 | + || command.Code.ToString().Contains(OmnibarCommandPaletteModeText, StringComparison.OrdinalIgnoreCase))) |
| 1220 | + .Select(command => new NavigationBarSuggestionItem |
| 1221 | + { |
| 1222 | + ThemedIconStyle = command.Glyph.ToThemedIconStyle(), |
| 1223 | + Glyph = command.Glyph.BaseGlyph, |
| 1224 | + Text = command.Code.ToString(), |
| 1225 | + PrimaryDisplay = command.Description, |
| 1226 | + HotKeys = command.HotKeys, |
| 1227 | + SearchText = OmnibarCommandPaletteModeText, |
| 1228 | + }); |
1189 | 1229 |
|
1190 | 1230 | foreach (var item in suggestionItems) |
| 1231 | + { |
1191 | 1232 | OmnibarCommandPaletteModeSuggestionItems.Add(item); |
| 1233 | + } |
1192 | 1234 | } |
1193 | 1235 |
|
1194 | 1236 | [Obsolete("Remove once Omnibar goes out of experimental.")] |
|
0 commit comments