Пример #1
0
        public App()
        {
            InitializeComponent();
            Suspending        += OnSuspending;
            LeavingBackground += OnLeavingBackground;
            // Initialize NLog
            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            NLog.LogManager.Configuration.Variables["LogPath"] = storageFolder.Path;

            RegisterUncaughtExceptionLogger();

            ConsentDialogDisplay    = new Dialogs.ConsentDialog();
            PropertiesDialogDisplay = new Dialogs.PropertiesDialog();
            LayoutDialogDisplay     = new Dialogs.LayoutDialog();
            AddItemDialogDisplay    = new Dialogs.AddItemDialog();
            ExceptionDialogDisplay  = new Dialogs.ExceptionDialog();
            // this.UnhandledException += App_UnhandledException;
            Clipboard.ContentChanged += Clipboard_ContentChanged;
            Clipboard_ContentChanged(null, null);
            AppCenter.Start("682666d1-51d3-4e4a-93d0-d028d43baaa0", typeof(Analytics), typeof(Crashes));

            SidebarPinned                    = new SidebarPinnedModel();
            AppSettings                      = new SettingsViewModel();
            InteractionViewModel             = new InteractionViewModel();
            SelectedItemsPropertiesViewModel = new SelectedItemsPropertiesViewModel();
            DirectoryPropertiesViewModel     = new DirectoryPropertiesViewModel();
        }
Пример #2
0
        private void NavigationViewLocationItem_Drop(object sender, DragEventArgs e)
        {
            if (!((sender as Microsoft.UI.Xaml.Controls.NavigationViewItem).DataContext is LocationItem locationItem))
            {
                return;
            }

            // If the dropped item is a folder or file from a file system
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                VisualStateManager.GoToState(sender as Microsoft.UI.Xaml.Controls.NavigationViewItem, "Drop", false);

                var deferral = e.GetDeferral();
                SidebarItemDropped?.Invoke(this, new SidebarItemDroppedEventArgs()
                {
                    Package           = e.DataView,
                    ItemPath          = locationItem.Path,
                    AcceptedOperation = e.AcceptedOperation
                });
                deferral.Complete();
            }
            else if ((e.DataView.Properties["sourceLocationItem"] as Microsoft.UI.Xaml.Controls.NavigationViewItem).DataContext is LocationItem sourceLocationItem)
            {
                // Else if the dropped item is a location item

                // Swap the two items
                SidebarPinnedModel.SwapItems(sourceLocationItem, locationItem);
            }
        }
Пример #3
0
        private async Task LoadAsync()
        {
            Folder = ApplicationData.Current.LocalCacheFolder;

            try
            {
                JsonFile = await Folder.GetFileAsync(JsonFileName);
            }
            catch (FileNotFoundException)
            {
                try
                {
                    var oldPinnedItemsFile = await Folder.GetFileAsync("PinnedItems.txt");

                    var oldPinnedItems = await FileIO.ReadLinesAsync(oldPinnedItemsFile);

                    await oldPinnedItemsFile.DeleteAsync();

                    foreach (var line in oldPinnedItems)
                    {
                        if (!Model.FavoriteItems.Contains(line))
                        {
                            Model.FavoriteItems.Add(line);
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    Model.AddDefaultItems();
                }

                JsonFile = await Folder.CreateFileAsync(JsonFileName, CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(JsonFile, JsonConvert.SerializeObject(Model, Formatting.Indented));
            }

            try
            {
                Model = JsonConvert.DeserializeObject <SidebarPinnedModel>(await FileIO.ReadTextAsync(JsonFile));
                if (Model == null)
                {
                    throw new Exception($"{JsonFileName} is empty, regenerating...");
                }
                Model.SetController(this);
            }
            catch (Exception)
            {
                await JsonFile.DeleteAsync();

                Model = new SidebarPinnedModel();
                Model.SetController(this);
                Model.AddDefaultItems();
                Model.Save();
            }

            await Model.AddAllItemsToSidebar();
        }
Пример #4
0
        private async Task LoadAsync()
        {
            StorageFolder Folder = await FilesystemTasks.Wrap(() => ApplicationData.Current.LocalFolder.CreateFolderAsync("settings", CreationCollisionOption.OpenIfExists).AsTask());

            if (Folder == null)
            {
                Model.AddDefaultItems();
                await Model.AddAllItemsToSidebar();

                return;
            }

            var JsonFile = await FilesystemTasks.Wrap(() => Folder.GetFileAsync(JsonFileName).AsTask());

            if (!JsonFile)
            {
                if (JsonFile == FileSystemStatusCode.NotFound)
                {
                    var oldItems = await ReadV2PinnedItemsFile() ?? await ReadV1PinnedItemsFile();

                    if (oldItems != null)
                    {
                        foreach (var item in oldItems)
                        {
                            if (!Model.FavoriteItems.Contains(item))
                            {
                                Model.FavoriteItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        Model.AddDefaultItems();
                    }

                    Model.Save();
                    await Model.AddAllItemsToSidebar();

                    return;
                }
                else
                {
                    Model.AddDefaultItems();
                    await Model.AddAllItemsToSidebar();

                    return;
                }
            }

            try
            {
                configContent = await FileIO.ReadTextAsync(JsonFile.Result);

                Model = JsonConvert.DeserializeObject <SidebarPinnedModel>(configContent);
                if (Model == null)
                {
                    throw new ArgumentException($"{JsonFileName} is empty, regenerating...");
                }
                Model.SetController(this);
            }
            catch (Exception)
            {
                Model = new SidebarPinnedModel();
                Model.SetController(this);
                Model.AddDefaultItems();
                Model.Save();
            }

            await Model.AddAllItemsToSidebar();
        }
Пример #5
0
 public SidebarPinnedController()
 {
     Model = new SidebarPinnedModel();
     Model.SetController(this);
 }