Skip to content

Commit 00776c2

Browse files
authored
Merge pull request #245 from duke7553/custom-start
Support opening of folders in new tabs and windows
2 parents a0fbab3 + 77d8ef9 commit 00776c2

File tree

10 files changed

+182
-15
lines changed

10 files changed

+182
-15
lines changed

Files UWP/App.xaml.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,24 @@ protected override void OnActivated(IActivatedEventArgs args)
280280
Window.Current.Content = rootFrame;
281281
}
282282

283-
// Open the page that we created to handle activation for results.
283+
if (args.Kind == ActivationKind.Protocol)
284+
{
285+
var eventArgs = args as ProtocolActivatedEventArgs;
286+
287+
if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
288+
{
289+
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
290+
}
291+
else
292+
{
293+
var trimmedPath = eventArgs.Uri.OriginalString.Split('=')[1];
294+
rootFrame.Navigate(typeof(InstanceTabsView), @trimmedPath, new SuppressNavigationTransitionInfo());
295+
}
296+
// Ensure the current window is active.
297+
Window.Current.Activate();
298+
return;
299+
}
300+
284301
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
285302

286303
// Ensure the current window is active.

Files UWP/GenericFileBrowser.xaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,21 @@
208208
<Setter Property="ContextFlyout">
209209
<Setter.Value>
210210
<MenuFlyout Opened="RightClickContextMenu_Opened" x:Name="RightClickContextMenu" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutFluentThemeResources}">
211-
<MenuFlyoutItem Text="Open With..." x:Name="OpenItem">
211+
<MenuFlyoutItem Text="Open with..." x:Name="OpenItem">
212212
<MenuFlyoutItem.Icon>
213213
<FontIcon Glyph="&#xE7AC;"/>
214214
</MenuFlyoutItem.Icon>
215215
</MenuFlyoutItem>
216-
216+
<MenuFlyoutItem Text="Open in new tab" x:Name="OpenInNewTab">
217+
<MenuFlyoutItem.Icon>
218+
<FontIcon Glyph="&#xE737;"/>
219+
</MenuFlyoutItem.Icon>
220+
</MenuFlyoutItem>
221+
<MenuFlyoutItem Text="Open in new window" x:Name="OpenInNewWindowItem">
222+
<MenuFlyoutItem.Icon>
223+
<FontIcon Glyph="&#xE8A7;"/>
224+
</MenuFlyoutItem.Icon>
225+
</MenuFlyoutItem>
217226
<MenuFlyoutItem Text="Share" x:Name="ShareItem">
218227
<MenuFlyoutItem.Icon>
219228
<FontIcon Glyph="&#xE72D;"/>

Files UWP/GenericFileBrowser.xaml.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ public GenericFileBrowser()
5050
grid = RootGrid;
5151
Clipboard.ContentChanged += Clipboard_ContentChanged;
5252
RefreshEmptySpace.Click += NavigationActions.Refresh_Click;
53+
Frame rootFrame = Window.Current.Content as Frame;
54+
InstanceTabsView instanceTabsView = rootFrame.Content as InstanceTabsView;
55+
instanceTabsView.TabStrip_SelectionChanged(null, null);
5356
tabInstance = App.selectedTabInstance;
57+
if (tabInstance.instanceViewModel == null && tabInstance.instanceInteraction == null)
58+
{
59+
tabInstance.instanceViewModel = new ItemViewModel();
60+
tabInstance.instanceInteraction = new Interaction();
61+
}
5462
viewModelInstance = tabInstance.instanceViewModel;
5563
PasteEmptySpace.Click += tabInstance.instanceInteraction.PasteItem_ClickAsync;
5664
OpenItem.Click += tabInstance.instanceInteraction.OpenItem_Click;
@@ -60,10 +68,12 @@ public GenericFileBrowser()
6068
CutItem.Click += tabInstance.instanceInteraction.CutItem_Click;
6169
CopyItem.Click += tabInstance.instanceInteraction.CopyItem_ClickAsync;
6270
SidebarPinItem.Click += tabInstance.instanceInteraction.PinItem_Click;
71+
OpenInNewTab.Click += tabInstance.instanceInteraction.OpenDirectoryInNewTab_Click;
6372
AllView.RightTapped += tabInstance.instanceInteraction.AllView_RightTapped;
6473
AllView.DoubleTapped += tabInstance.instanceInteraction.List_ItemClick;
6574
OpenTerminal.Click += tabInstance.instanceInteraction.OpenDirectoryInTerminal;
6675
PropertiesItem.Click += tabInstance.ShowPropertiesButton_Click;
76+
OpenInNewWindowItem.Click += tabInstance.instanceInteraction.OpenInNewWindowItem_Click;
6777
}
6878

6979
private void AddItem_Click(object sender, RoutedEventArgs e)
@@ -304,11 +314,15 @@ private void RightClickContextMenu_Opened(object sender, object e)
304314
var selectedDataItem = tabInstance.instanceViewModel.FilesAndFolders[AllView.SelectedIndex];
305315
if (selectedDataItem.FileType != "Folder" || AllView.SelectedItems.Count > 1)
306316
{
307-
SidebarPinItem.IsEnabled = false;
317+
SidebarPinItem.Visibility = Visibility.Collapsed;
318+
OpenInNewTab.Visibility = Visibility.Collapsed;
319+
OpenInNewWindowItem.Visibility = Visibility.Collapsed;
308320
}
309321
else if (selectedDataItem.FileType == "Folder")
310322
{
311-
SidebarPinItem.IsEnabled = true;
323+
SidebarPinItem.Visibility = Visibility.Visible;
324+
OpenInNewTab.Visibility = Visibility.Visible;
325+
OpenInNewWindowItem.Visibility = Visibility.Visible;
312326
}
313327
}
314328

Files UWP/InstanceTabsView.xaml.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Windows.UI.ViewManagement;
1212
using Windows.UI.Xaml;
1313
using Windows.UI.Xaml.Controls;
14+
using Windows.UI.Xaml.Navigation;
1415

1516
namespace Files
1617
{
@@ -20,6 +21,7 @@ namespace Files
2021
public sealed partial class InstanceTabsView : Page
2122
{
2223
public static TabView tabView;
24+
public string navArgs;
2325
public InstanceTabsView()
2426
{
2527
this.InitializeComponent();
@@ -56,19 +58,34 @@ public InstanceTabsView()
5658
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 155, 155, 155);
5759
//titleBar.BackgroundColor = Colors.Transparent;
5860
}
59-
AddNewTab(typeof(ProHome), "Start");
61+
62+
}
63+
64+
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
65+
{
66+
navArgs = eventArgs.Parameter?.ToString();
67+
68+
if (string.IsNullOrEmpty(navArgs))
69+
{
70+
AddNewTab(typeof(ProHome), "Start");
71+
}
72+
else
73+
{
74+
AddNewTab(typeof(ProHome), navArgs);
75+
}
76+
6077
Microsoft.UI.Xaml.Controls.FontIconSource icon = new Microsoft.UI.Xaml.Controls.FontIconSource();
6178
icon.Glyph = "\xE713";
6279
if ((tabView.SelectedItem as TabViewItem).Header.ToString() != "Settings" && (tabView.SelectedItem as TabViewItem).IconSource != icon)
6380
{
6481
App.selectedTabInstance = ItemViewModel.GetCurrentSelectedTabInstance<ProHome>();
6582
}
6683
}
67-
84+
6885
public void AddNewTab(Type t, string path)
6986
{
7087
Frame frame = new Frame();
71-
frame.Navigate(t, path);
88+
//frame.Navigate(t, path);
7289
string tabLocationHeader = null;
7390
Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
7491
Microsoft.UI.Xaml.Controls.IconSource tabIcon;
@@ -154,6 +171,10 @@ public void AddNewTab(Type t, string path)
154171
};
155172
tabView.TabItems.Add(tvi);
156173
TabStrip.SelectedItem = TabStrip.TabItems[TabStrip.TabItems.Count - 1];
174+
if(tabView.SelectedItem == tvi)
175+
{
176+
(((tabView.SelectedItem as TabViewItem).Content as Grid).Children[0] as Frame).Navigate(t, path);
177+
}
157178
}
158179

159180
public async void SetSelectedTabInfo(string text, string currentPathForTabIcon = null)
@@ -249,7 +270,7 @@ private void DragArea_Loaded(object sender, RoutedEventArgs e)
249270
Window.Current.SetTitleBar(sender as Grid);
250271
}
251272

252-
private void TabStrip_SelectionChanged(object sender, SelectionChangedEventArgs e)
273+
public void TabStrip_SelectionChanged(object sender, SelectionChangedEventArgs e)
253274
{
254275
if(TabStrip.SelectedItem == null)
255276
{

Files UWP/Interacts/Interaction.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ namespace Files.Interacts
2929
public class Interaction
3030
{
3131
private ProHome tabInstance;
32+
InstanceTabsView instanceTabsView;
3233
public Interaction()
3334
{
3435
tabInstance = App.selectedTabInstance;
36+
Frame rootFrame = Window.Current.Content as Frame;
37+
instanceTabsView = rootFrame.Content as InstanceTabsView;
3538
}
3639

3740
public async void List_ItemClick(object sender, DoubleTappedRoutedEventArgs e)
@@ -236,6 +239,41 @@ public async void List_ItemClick(object sender, DoubleTappedRoutedEventArgs e)
236239

237240
}
238241

242+
public async void OpenInNewWindowItem_Click(object sender, RoutedEventArgs e)
243+
{
244+
var CurrentSourceType = App.selectedTabInstance.accessibleContentFrame.CurrentSourcePageType;
245+
int index = -1;
246+
if (CurrentSourceType == typeof(GenericFileBrowser))
247+
{
248+
index = (tabInstance.accessibleContentFrame.Content as GenericFileBrowser).data.SelectedIndex;
249+
}
250+
else if (CurrentSourceType == typeof(PhotoAlbum))
251+
{
252+
index = (tabInstance.accessibleContentFrame.Content as PhotoAlbum).gv.SelectedIndex;
253+
}
254+
var selectedItemPath = tabInstance.instanceViewModel.FilesAndFolders[index].FilePath;
255+
var folderUri = new Uri("files-uwp:" + "?folder=" + @selectedItemPath);
256+
257+
await Launcher.LaunchUriAsync(folderUri);
258+
}
259+
260+
public void OpenDirectoryInNewTab_Click(object sender, RoutedEventArgs e)
261+
{
262+
var CurrentSourceType = App.selectedTabInstance.accessibleContentFrame.CurrentSourcePageType;
263+
int index = -1;
264+
if(CurrentSourceType == typeof(GenericFileBrowser))
265+
{
266+
index = (tabInstance.accessibleContentFrame.Content as GenericFileBrowser).data.SelectedIndex;
267+
}
268+
else if(CurrentSourceType == typeof(PhotoAlbum))
269+
{
270+
index = (tabInstance.accessibleContentFrame.Content as PhotoAlbum).gv.SelectedIndex;
271+
}
272+
var selectedItemPath = tabInstance.instanceViewModel.FilesAndFolders[index].FilePath;
273+
274+
instanceTabsView.AddNewTab(typeof(ProHome), selectedItemPath);
275+
}
276+
239277
public async void OpenDirectoryInTerminal(object sender, RoutedEventArgs e)
240278
{
241279

Files UWP/PhotoAlbum.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@
419419
<FontIcon Glyph="&#xE7AC;"/>
420420
</MenuFlyoutItem.Icon>
421421
</MenuFlyoutItem>
422+
<MenuFlyoutItem Text="Open in new tab" x:Name="OpenInNewTab">
423+
<MenuFlyoutItem.Icon>
424+
<FontIcon Glyph="&#xE737;"/>
425+
</MenuFlyoutItem.Icon>
426+
</MenuFlyoutItem>
427+
<MenuFlyoutItem Text="Open in new window" x:Name="OpenInNewWindowItem">
428+
<MenuFlyoutItem.Icon>
429+
<FontIcon Glyph="&#xE8A7;"/>
430+
</MenuFlyoutItem.Icon>
431+
</MenuFlyoutItem>
422432
<MenuFlyoutItem Click="ShareItem_Click" Text="Share" Name="ShareItem">
423433
<MenuFlyoutItem.Icon>
424434
<FontIcon Glyph="&#xE72D;"/>

Files UWP/PhotoAlbum.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public PhotoAlbum()
6060
FileList.DoubleTapped += tabInstance.instanceInteraction.List_ItemClick;
6161
SidebarPinItem.Click += tabInstance.instanceInteraction.PinItem_Click;
6262
OpenTerminal.Click += tabInstance.instanceInteraction.OpenDirectoryInTerminal;
63-
63+
OpenInNewWindowItem.Click += tabInstance.instanceInteraction.OpenInNewWindowItem_Click;
64+
OpenInNewTab.Click += tabInstance.instanceInteraction.OpenDirectoryInNewTab_Click;
6465
}
6566

6667
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
@@ -294,11 +295,15 @@ private void RightClickContextMenu_Opened(object sender, object e)
294295
var selectedDataItem = tabInstance.instanceViewModel.FilesAndFolders[gv.SelectedIndex];
295296
if (selectedDataItem.FileType != "Folder" || gv.SelectedItems.Count > 1)
296297
{
297-
SidebarPinItem.IsEnabled = false;
298+
SidebarPinItem.Visibility = Visibility.Collapsed;
299+
OpenInNewTab.Visibility = Visibility.Collapsed;
300+
OpenInNewWindowItem.Visibility = Visibility.Collapsed;
298301
}
299302
else if (selectedDataItem.FileType == "Folder")
300303
{
301-
SidebarPinItem.IsEnabled = true;
304+
SidebarPinItem.Visibility = Visibility.Visible;
305+
OpenInNewTab.Visibility = Visibility.Visible;
306+
OpenInNewWindowItem.Visibility = Visibility.Visible;
302307
}
303308
}
304309
}

Files UWP/ProHome.xaml.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,56 @@ private void RibbonTip_Loaded(object sender, RoutedEventArgs e)
929929

930930
private void Page_Loaded(object sender, RoutedEventArgs e)
931931
{
932-
accessibleContentFrame.Navigate(typeof(YourHome), NavParams, new SuppressNavigationTransitionInfo());
932+
933+
934+
if (NavParams == "Start" || NavParams == "New tab")
935+
{
936+
ItemDisplayFrame.Navigate(typeof(YourHome), NavParams, new SuppressNavigationTransitionInfo());
937+
locationsList.SelectedIndex = 0;
938+
}
939+
else if (NavParams == "Desktop")
940+
{
941+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), DesktopPath, new SuppressNavigationTransitionInfo());
942+
locationsList.SelectedIndex = 1;
943+
}
944+
else if (NavParams == "Downloads")
945+
{
946+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), DownloadsPath, new SuppressNavigationTransitionInfo());
947+
locationsList.SelectedIndex = 2;
948+
}
949+
else if (NavParams == "Documents")
950+
{
951+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), DocumentsPath, new SuppressNavigationTransitionInfo());
952+
locationsList.SelectedIndex = 3;
953+
}
954+
else if (NavParams == "Pictures" || NavParams == PicturesPath)
955+
{
956+
ItemDisplayFrame.Navigate(typeof(PhotoAlbum), PicturesPath, new SuppressNavigationTransitionInfo());
957+
locationsList.SelectedIndex = 4;
958+
}
959+
else if (NavParams == "Music")
960+
{
961+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), MusicPath, new SuppressNavigationTransitionInfo());
962+
locationsList.SelectedIndex = 5;
963+
}
964+
else if (NavParams == "Videos")
965+
{
966+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), VideosPath, new SuppressNavigationTransitionInfo());
967+
locationsList.SelectedIndex = 6;
968+
}
969+
else
970+
{
971+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), NavParams, new SuppressNavigationTransitionInfo());
972+
if (NavParams.Contains("C:", StringComparison.OrdinalIgnoreCase))
973+
{
974+
drivesList.SelectedIndex = 0;
975+
}
976+
else
977+
{
978+
drivesList.SelectedItem = null;
979+
}
980+
}
981+
//accessibleContentFrame.Navigate(typeof(YourHome), NavParams, new SuppressNavigationTransitionInfo());
933982
this.Loaded -= Page_Loaded;
934983
}
935984

@@ -968,6 +1017,9 @@ private void ItemDisplayFrame_Navigated(object sender, Windows.UI.Xaml.Navigatio
9681017

9691018
if(instanceViewModel == null && instanceInteraction == null)
9701019
{
1020+
Frame rootFrame = Window.Current.Content as Frame;
1021+
var instanceTabsView = rootFrame.Content as InstanceTabsView;
1022+
instanceTabsView.TabStrip_SelectionChanged(null, null);
9711023
instanceViewModel = new ItemViewModel();
9721024
instanceInteraction = new Interaction();
9731025
}

Files UWP/YourHome.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
8282
Frame rootFrame = Window.Current.Content as Frame;
8383
var instanceTabsView = rootFrame.Content as InstanceTabsView;
8484
instanceTabsView.SetSelectedTabInfo(parameters, null);
85+
instanceTabsView.TabStrip_SelectionChanged(null, null);
8586
App.selectedTabInstance.BackButton.IsEnabled = App.selectedTabInstance.accessibleContentFrame.CanGoBack;
8687
App.selectedTabInstance.ForwardButton.IsEnabled = App.selectedTabInstance.accessibleContentFrame.CanGoForward;
8788
App.selectedTabInstance.RefreshButton.IsEnabled = false;
@@ -354,7 +355,7 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
354355
try
355356
{
356357
var file = (await StorageFile.GetFileFromPathAsync(path));
357-
if (file.FileType == "Application")
358+
if (file.DisplayType == "Application")
358359
{
359360
await Interaction.LaunchExe(path);
360361

FilesUwp.Package/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" IgnorableNamespaces="uap mp rescap desktop4 desktop">
3-
<Identity Name="49306atecsolution.FilesUWP" Publisher="CN=53EC4384-7F5B-4CF6-8C23-513FFE9D1AB7" Version="0.6.2.0" />
3+
<Identity Name="49306atecsolution.FilesUWP" Publisher="CN=53EC4384-7F5B-4CF6-8C23-513FFE9D1AB7" Version="0.6.4.0" />
44
<Properties>
55
<DisplayName>Files UWP</DisplayName>
66
<PublisherDisplayName>Yair A</PublisherDisplayName>

0 commit comments

Comments
 (0)