Skip to content

Commit b06d697

Browse files
authored
Feature: Added option to open tab in new/existing instance (#13743)
1 parent 7d920f1 commit b06d697

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

src/Files.App/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static void Main()
4242
WinRT.ComWrappersSupport.InitializeComWrappers();
4343

4444
var proc = Process.GetCurrentProcess();
45-
var alwaysOpenNewInstance = ApplicationData.Current.LocalSettings.Values.Get("AlwaysOpenANewInstance", false);
45+
var OpenTabInExistingInstance = ApplicationData.Current.LocalSettings.Values.Get("OpenTabInExistingInstance", true);
4646
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
4747

4848
if (activatedArgs.Data is ICommandLineActivatedEventArgs cmdLineArgs)
@@ -76,7 +76,7 @@ private static void Main()
7676

7777
// Always open a new instance for OpenDialog, never open new instance for "-Tag" command
7878
if (parsedCommands is null || !parsedCommands.Any(x => x.Type == ParsedCommandType.OutputPath) &&
79-
(!alwaysOpenNewInstance || parsedCommands.Any(x => x.Type == ParsedCommandType.TagFiles)))
79+
(OpenTabInExistingInstance || parsedCommands.Any(x => x.Type == ParsedCommandType.TagFiles)))
8080
{
8181
var activePid = ApplicationData.Current.LocalSettings.Values.Get("INSTANCE_ACTIVE", -1);
8282
var instance = AppInstance.FindOrRegisterForKey(activePid.ToString());
@@ -102,7 +102,7 @@ private static void Main()
102102
}
103103
}
104104

105-
if (!alwaysOpenNewInstance)
105+
if (OpenTabInExistingInstance)
106106
{
107107
if (activatedArgs.Data is ILaunchActivatedEventArgs launchArgs)
108108
{
@@ -117,7 +117,8 @@ private static void Main()
117117
else if (activatedArgs.Data is IProtocolActivatedEventArgs protocolArgs)
118118
{
119119
var parsedArgs = protocolArgs.Uri.Query.TrimStart('?').Split('=');
120-
if (parsedArgs.Length == 2 && parsedArgs[0] == "cmd") // Treat as command line launch
120+
if ((parsedArgs.Length == 2 && parsedArgs[0] == "cmd") ||
121+
parsedArgs.Length == 1) // Treat Win+E & Open file location as command line launch
121122
{
122123
var activePid = ApplicationData.Current.LocalSettings.Values.Get("INSTANCE_ACTIVE", -1);
123124
var instance = AppInstance.FindOrRegisterForKey(activePid.ToString());

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public bool OpenNewTabOnStartup
4343
set => Set(value);
4444
}
4545

46-
public bool AlwaysOpenNewInstance
46+
public bool OpenTabInExistingInstance
4747
{
48-
get => Get(false);
48+
get => Get(true);
4949
set => Set(value);
5050
}
5151

@@ -241,7 +241,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
241241
case nameof(OpenSpecificPageOnStartup):
242242
case nameof(ContinueLastSessionOnStartUp):
243243
case nameof(OpenNewTabOnStartup):
244-
case nameof(AlwaysOpenNewInstance):
244+
case nameof(OpenTabInExistingInstance):
245245
case nameof(AlwaysOpenDualPaneInNewTab):
246246
case nameof(ShowQuickAccessWidget):
247247
case nameof(ShowRecentFilesWidget):

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,8 @@
18151815
<data name="RestoreDefault" xml:space="preserve">
18161816
<value>Restore default</value>
18171817
</data>
1818-
<data name="OpenNewInstance" xml:space="preserve">
1819-
<value>Open new instance when opening directories from the taskbar jumplist</value>
1818+
<data name="OpenTabInExistingInstance" xml:space="preserve">
1819+
<value>Open tab in existing instance when opening Files from another app</value>
18201820
</data>
18211821
<data name="StartupSettings" xml:space="preserve">
18221822
<value>Startup settings</value>

src/Files.App/ViewModels/Settings/GeneralViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ public ReadOnlyCollection<IMenuFlyoutItemViewModel> AddFlyoutItemsSource
222222
set => SetProperty(ref addFlyoutItemsSource, value);
223223
}
224224

225-
public bool AlwaysOpenANewInstance
225+
public bool OpenTabInExistingInstance
226226
{
227-
get => UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance;
227+
get => UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance;
228228
set
229229
{
230-
if (value != UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance)
230+
if (value != UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance)
231231
{
232-
UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance = value;
232+
UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance = value;
233233

234234
// Needed in Program.cs
235-
ApplicationData.Current.LocalSettings.Values["AlwaysOpenANewInstance"] = value;
235+
ApplicationData.Current.LocalSettings.Values["OpenTabInExistingInstance"] = value;
236236

237237
OnPropertyChanged();
238238
}

src/Files.App/Views/Settings/GeneralPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@
190190
</ListView>
191191
</Grid>
192192

193-
<local:SettingsBlockControl Title="{helpers:ResourceString Name=OpenNewInstance}" HorizontalAlignment="Stretch">
193+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=OpenTabInExistingInstance}" HorizontalAlignment="Stretch">
194194
<ToggleSwitch
195-
AutomationProperties.Name="{helpers:ResourceString Name=OpenNewInstance}"
196-
IsOn="{x:Bind ViewModel.AlwaysOpenANewInstance, Mode=TwoWay}"
195+
AutomationProperties.Name="{helpers:ResourceString Name=OpenTabInExistingInstance}"
196+
IsOn="{x:Bind ViewModel.OpenTabInExistingInstance, Mode=TwoWay}"
197197
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
198198
</local:SettingsBlockControl>
199199
</StackPanel>

src/Files.Core/Services/Settings/IGeneralSettingsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
3535
bool OpenNewTabOnStartup { get; set; }
3636

3737
/// <summary>
38-
/// Gets or sets a value indicating whether or not opening the app from the jumplist should open the directory in a new instance.
38+
/// Gets or sets a value indicating whether or not opening Files from another app should open a tab in the existing instance.
3939
/// </summary>
40-
bool AlwaysOpenNewInstance { get; set; }
40+
bool OpenTabInExistingInstance { get; set; }
4141

4242
/// <summary>
4343
/// A list containing all paths to open at startup.

0 commit comments

Comments
 (0)