Skip to content

Add support for creating google docs files from the "new" menu #8784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Files.Launcher/Helpers/ShellNewMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ private static async Task<ShellNewEntry> GetShellNewRegistryEntries(RegistryKey
private static async Task<ShellNewEntry> ParseShellNewRegistryEntry(RegistryKey key, RegistryKey root)
{
var valueNames = key.GetValueNames();
if (!valueNames.Contains("NullFile") &&
!valueNames.Contains("ItemName") &&
!valueNames.Contains("FileName"))
if (!valueNames.Contains("NullFile", StringComparer.OrdinalIgnoreCase) &&
!valueNames.Contains("ItemName", StringComparer.OrdinalIgnoreCase) &&
!valueNames.Contains("FileName", StringComparer.OrdinalIgnoreCase) &&
!valueNames.Contains("Command", StringComparer.OrdinalIgnoreCase))
{
return null;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Files.Uwp/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class CommandLineParser
{
public static ParsedCommands ParseUntrustedCommands(string cmdLineString)
{
var parsedArgs = Parse(SplitArguments(cmdLineString));
var parsedArgs = Parse(SplitArguments(cmdLineString, true));
return ParseSplitArguments(parsedArgs);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private static ParsedCommands ParseSplitArguments(List<KeyValuePair<string, stri
return commands;
}

private static string[] SplitArguments(string commandLine)
public static string[] SplitArguments(string commandLine, bool trimQuotes = false)
{
char[] commandLineCharArray = commandLine.ToCharArray();
bool isInQuote = false;
Expand All @@ -94,7 +94,14 @@ private static string[] SplitArguments(string commandLine)
}
}

return new string(commandLineCharArray).Replace("\"", "", StringComparison.Ordinal).Split('\n');
if (trimQuotes)
{
return new string(commandLineCharArray).Replace("\"", "", StringComparison.Ordinal).Split('\n');
}
else
{
return new string(commandLineCharArray).Split('\n');
}
}

public static List<KeyValuePair<string, string>> Parse(string[] args = null)
Expand Down
27 changes: 24 additions & 3 deletions src/Files.Uwp/Extensions/ShellNewEntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;
using Windows.Storage;
using System.Linq;

namespace Files.Extensions
{
Expand Down Expand Up @@ -60,19 +61,39 @@ public static async Task<FilesystemResult<BaseStorageFile>> Create(this ShellNew
var parentFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(filePath));
if (parentFolder)
{
return await Create(shellEntry, parentFolder, Path.GetFileName(filePath));
return await Create(shellEntry, parentFolder, filePath);
}
return new FilesystemResult<BaseStorageFile>(null, parentFolder.ErrorCode);
}

public static async Task<FilesystemResult<BaseStorageFile>> Create(this ShellNewEntry shellEntry, BaseStorageFolder parentFolder, string fileName)
public static async Task<FilesystemResult<BaseStorageFile>> Create(this ShellNewEntry shellEntry, BaseStorageFolder parentFolder, string filePath)
{
FilesystemResult<BaseStorageFile> createdFile = null;
var fileName = Path.GetFileName(filePath);
if (!fileName.EndsWith(shellEntry.Extension, StringComparison.Ordinal))
{
fileName += shellEntry.Extension;
}
if (shellEntry.Template == null)
if (shellEntry.Command != null)
{
var args = CommandLine.CommandLineParser.SplitArguments(shellEntry.Command);
if (args.Any())
{
var connection = await AppServiceConnectionHelper.Instance;
if (connection != null)
{
_ = await connection.SendMessageForResponseAsync(new ValueSet()
{
{ "Arguments", "LaunchApp" },
{ "WorkingDirectory", PathNormalization.GetParentDir(filePath) },
{ "Application", args[0].Replace("\"", "", StringComparison.Ordinal) },
{ "Parameters", string.Join(" ", args.Skip(1)).Replace("%1", filePath) }
});
}
}
createdFile = new FilesystemResult<BaseStorageFile>(null, Shared.Enums.FileSystemStatusCode.Success);
}
else if (shellEntry.Template == null)
{
createdFile = await FilesystemTasks.Wrap(() => parentFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName).AsTask());
}
Expand Down
19 changes: 12 additions & 7 deletions src/Files.Uwp/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,22 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
}
}

// Show rename dialog
DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog();
await dialog.ShowAsync();

if (dialog.DynamicResult != DynamicDialogResult.Primary)
// Skip rename dialog when ShellNewEntry has a Command (e.g. ".accdb", ".gdoc")
string userInput = null;
if (itemType != AddItemDialogItemType.File || itemInfo?.Command == null)
{
return null;
DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog();
await dialog.ShowAsync(); // Show rename dialog

if (dialog.DynamicResult != DynamicDialogResult.Primary)
{
return null;
}

userInput = dialog.ViewModel.AdditionalData as string;
}

// Create file based on dialog result
string userInput = dialog.ViewModel.AdditionalData as string;
var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath);
var created = new FilesystemResult<(ReturnResult, IStorageItem)>((ReturnResult.Failed, null), FileSystemStatusCode.Generic);
if (folderRes)
Expand Down