private async void TabStrip_TabStripDrop(object sender, DragEventArgs e)
        {
            HorizontalTabView.CanReorderTabs = true;
            if (!(sender is TabView tabStrip))
            {
                return;
            }

            if (!e.DataView.Properties.TryGetValue(TabPathIdentifier, out object tabViewItemPathObj) || !(tabViewItemPathObj is string tabViewItemString))
            {
                return;
            }

            var index = -1;

            for (int i = 0; i < tabStrip.TabItems.Count; i++)
            {
                var item = tabStrip.ContainerFromIndex(i) as TabViewItem;

                if (e.GetPosition(item).Y - item.ActualHeight < 0)
                {
                    index = i;
                    break;
                }
            }

            var tabViewItemArgs = TabItemArguments.Deserialize(tabViewItemString);

            ApplicationData.Current.LocalSettings.Values[TabDropHandledIdentifier] = true;
            await MainPageViewModel.AddNewTabByParam(tabViewItemArgs.InitialPageType, tabViewItemArgs.NavigationArg, index);
        }
Esempio n. 2
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Logger.Info("App activated");

            await EnsureSettingsAndConfigurationAreBootstrapped();

            // Window management
            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame              = new Frame();
                rootFrame.CacheSize    = 1;
                Window.Current.Content = rootFrame;
            }

            var currentView = SystemNavigationManager.GetForCurrentView();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var parsedArgs     = eventArgs.Uri.Query.TrimStart('?').Split('=');
                    var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]);
                    switch (parsedArgs[0])
                    {
                    case "tab":
                        rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo());
                        break;

                    case "folder":
                        rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo());
                        break;
                    }
                }

                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                            rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo());

                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                            return;

                        case ParsedCommandType.OpenPath:

                            try
                            {
                                var det = await StorageFolder.GetFolderFromPathAsync(command.Payload);

                                rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo());

                                // Ensure the current window is active.
                                Window.Current.Activate();
                                Window.Current.CoreWindow.Activated += CoreWindow_Activated;

                                return;
                            }
                            catch (System.IO.FileNotFoundException ex)
                            {
                                //Not a folder
                                Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }

                            break;

                        case ParsedCommandType.Unknown:
                            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.Activated += CoreWindow_Activated;

                            return;
                        }
                    }
                }
                break;

            case ActivationKind.ToastNotification:
                var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
                if (eventArgsForNotification.Argument == "report")
                {
                    // Launch the URI and open log files location
                    //SettingsViewModel.OpenLogLocation();
                    SettingsViewModel.ReportIssueOnGitHub();
                }
                break;
            }

            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
        }
Esempio n. 3
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            await logWriter.InitializeAsync("debug.log");

            Logger.Info($"App activated by {args.Kind.ToString()}");

            await EnsureSettingsAndConfigurationAreBootstrapped();

            _ = InitializeAppComponentsAsync().ContinueWith(t => Logger.Warn(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted);

            var rootFrame = EnsureWindowIsInitialized();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var parsedArgs     = eventArgs.Uri.Query.TrimStart('?').Split('=');
                    var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]);
                    var folder         = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(unescapedValue).AsTask());

                    if (folder != null && !string.IsNullOrEmpty(folder.Path))
                    {
                        unescapedValue = folder.Path;     // Convert short name to long name (#6190)
                    }
                    switch (parsedArgs[0])
                    {
                    case "tab":
                        rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo());
                        break;

                    case "folder":
                        rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo());
                        break;
                    }
                }

                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    async Task PerformNavigation(string payload, string selectItem = null)
                    {
                        if (!string.IsNullOrEmpty(payload))
                        {
                            payload = CommonPaths.ShellPlaces.Get(payload.ToUpperInvariant(), payload);
                            var folder = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(payload).AsTask());

                            if (folder != null && !string.IsNullOrEmpty(folder.Path))
                            {
                                payload = folder.Path;     // Convert short name to long name (#6190)
                            }
                        }
                        var paneNavigationArgs = new PaneNavigationArguments
                        {
                            LeftPaneNavPathParam    = payload,
                            LeftPaneSelectItemParam = selectItem,
                        };

                        if (rootFrame.Content != null)
                        {
                            await MainPageViewModel.AddNewTabByParam(typeof(PaneHolderPage), paneNavigationArgs);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), paneNavigationArgs, new SuppressNavigationTransitionInfo());
                        }
                    }

                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                        case ParsedCommandType.OpenPath:
                        case ParsedCommandType.ExplorerShellCommand:
                            var selectItemCommand = parsedCommands.FirstOrDefault(x => x.Type == ParsedCommandType.SelectItem);
                            await PerformNavigation(command.Payload, selectItemCommand?.Payload);

                            break;

                        case ParsedCommandType.SelectItem:
                            if (Path.IsPathRooted(command.Payload))
                            {
                                await PerformNavigation(Path.GetDirectoryName(command.Payload), Path.GetFileName(command.Payload));
                            }
                            break;

                        case ParsedCommandType.Unknown:
                            if (command.Payload.Equals("."))
                            {
                                await PerformNavigation(activationPath);
                            }
                            else
                            {
                                var target = Path.GetFullPath(Path.Combine(activationPath, command.Payload));
                                if (!string.IsNullOrEmpty(command.Payload))
                                {
                                    await PerformNavigation(target);
                                }
                                else
                                {
                                    await PerformNavigation(null);
                                }
                            }
                            break;

                        case ParsedCommandType.OutputPath:
                            OutputPath = command.Payload;
                            break;
                        }
                    }

                    if (rootFrame.Content != null)
                    {
                        // Ensure the current window is active.
                        Window.Current.Activate();
                        Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                        return;
                    }
                }
                break;

            case ActivationKind.ToastNotification:
                var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
                if (eventArgsForNotification.Argument == "report")
                {
                    await Launcher.LaunchUriAsync(new Uri(Constants.GitHub.FeedbackUrl));
                }
                break;

            case ActivationKind.StartupTask:
                break;
            }

            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;

            WindowDecorationsHelper.RequestWindowDecorationsAccess();
        }
Esempio n. 4
0
        protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
        {
            if (eventArgs.NavigationMode != NavigationMode.Back)
            {
                App.AppSettings             = new SettingsViewModel();
                App.InteractionViewModel    = new InteractionViewModel();
                App.SidebarPinnedController = new SidebarPinnedController();

                Helpers.ThemeHelper.Initialize();

                if (eventArgs.Parameter == null || (eventArgs.Parameter is string eventStr && string.IsNullOrEmpty(eventStr)))
                {
                    try
                    {
                        if (App.AppSettings.ResumeAfterRestart)
                        {
                            App.AppSettings.ResumeAfterRestart = false;

                            foreach (string tabArgsString in App.AppSettings.LastSessionPages)
                            {
                                var tabArgs = TabItemArguments.Deserialize(tabArgsString);
                                await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg);
                            }

                            if (!App.AppSettings.ContinueLastSessionOnStartUp)
                            {
                                App.AppSettings.LastSessionPages = null;
                            }
                        }
                        else if (App.AppSettings.OpenASpecificPageOnStartup)
                        {
                            if (App.AppSettings.PagesOnStartupList != null)
                            {
                                foreach (string path in App.AppSettings.PagesOnStartupList)
                                {
                                    await AddNewTabByPathAsync(typeof(PaneHolderPage), path);
                                }
                            }
                            else
                            {
                                await AddNewTabAsync();
                            }
                        }
                        else if (App.AppSettings.ContinueLastSessionOnStartUp)
                        {
                            if (App.AppSettings.LastSessionPages != null)
                            {
                                foreach (string tabArgsString in App.AppSettings.LastSessionPages)
                                {
                                    var tabArgs = TabItemArguments.Deserialize(tabArgsString);
                                    await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg);
                                }
                                var defaultArg = new TabItemArguments()
                                {
                                    InitialPageType = typeof(PaneHolderPage), NavigationArg = "NewTab".GetLocalized()
                                };
                                App.AppSettings.LastSessionPages = new string[] { defaultArg.Serialize() };
                            }
                            else
                            {
                                await AddNewTabAsync();
                            }
                        }
                        else
                        {
                            await AddNewTabAsync();
                        }
                    }
                    catch (Exception)
                    {
                        await AddNewTabAsync();
                    }
                }
                else
                {
                    if (eventArgs.Parameter is string navArgs)
                    {
                        await AddNewTabByPathAsync(typeof(PaneHolderPage), navArgs);
                    }
                    else if (eventArgs.Parameter is TabItemArguments tabArgs)
                    {
                        await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg);
                    }
                }

                // Check for required updates
                AppUpdater updater = new AppUpdater();
                updater.CheckForUpdatesAsync();

                // Initial setting of SelectedTabItem
                Frame rootFrame = Window.Current.Content as Frame;
                var   mainView  = rootFrame.Content as MainPage;
                mainView.SelectedTabItem = AppInstances[App.InteractionViewModel.TabStripSelectedIndex];
            }
Esempio n. 5
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            await logWriter.InitializeAsync("debug.log");

            Logger.Info($"App activated by {args.Kind.ToString()}");

            await EnsureSettingsAndConfigurationAreBootstrapped();

            var rootFrame = EnsureWindowIsInitialized();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var parsedArgs     = eventArgs.Uri.Query.TrimStart('?').Split('=');
                    var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]);
                    switch (parsedArgs[0])
                    {
                    case "tab":
                        rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo());
                        break;

                    case "folder":
                        rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo());
                        break;
                    }
                }

                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    async Task PerformNavigation(string payload)
                    {
                        if (!string.IsNullOrEmpty(payload))
                        {
                            payload = CommonPaths.ShellPlaces.Get(payload.ToUpperInvariant(), payload);
                            var folder = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(payload).AsTask());

                            if (folder != null && !string.IsNullOrEmpty(folder.Path))
                            {
                                payload = folder.Path;     // Convert short name to long name (#6190)
                            }
                        }
                        if (rootFrame.Content != null)
                        {
                            await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), payload);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), payload, new SuppressNavigationTransitionInfo());
                        }
                    }

                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                        case ParsedCommandType.OpenPath:
                        case ParsedCommandType.ExplorerShellCommand:
                            await PerformNavigation(command.Payload);

                            break;

                        case ParsedCommandType.Unknown:
                            if (command.Payload.Equals("."))
                            {
                                await PerformNavigation(activationPath);
                            }
                            else
                            {
                                var target = Path.GetFullPath(Path.Combine(activationPath, command.Payload));
                                if (!string.IsNullOrEmpty(command.Payload))
                                {
                                    await PerformNavigation(target);
                                }
                                else
                                {
                                    await PerformNavigation(null);
                                }
                            }
                            break;

                        case ParsedCommandType.OutputPath:
                            OutputPath = command.Payload;
                            break;
                        }
                    }

                    if (rootFrame.Content != null)
                    {
                        // Ensure the current window is active.
                        Window.Current.Activate();
                        Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                        return;
                    }
                }
                break;

            case ActivationKind.ToastNotification:
                var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
                if (eventArgsForNotification.Argument == "report")
                {
                    // Launch the URI and open log files location
                    //SettingsViewModel.OpenLogLocation();
                    SettingsViewModel.ReportIssueOnGitHub();
                }
                break;
            }

            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
        }