/// <summary>
        /// Load all ProjectViewItems in GridView children.
        /// </summary>
        public async Task LoadAllProjectViewItems()
        {
            IEnumerable <StorageFolder> zipFolders = await FileUtil.FIndZipFolders();

            //Refresh, when the count is not equal.
            if (zipFolders.Count() != this.MainLayout.Count)
            {
                this.MainLayout.Items.Clear(); //Notify

                foreach (StorageFolder folder in zipFolders)
                {
                    // [StorageFolder] --> [projectViewItem]
                    IProjectViewItem item = FileUtil.ConstructProjectViewItem(folder);
                    if (item != null)
                    {
                        this.MainLayout.Items.Add(item);               //Notify
                    }
                }
            }

            if (this.MainLayout.Count == 0)
            {
                this.MainLayout.State = MainPageState.Initial;
            }
            else
            {
                this.MainLayout.State = MainPageState.Main;
            }
        }
        /// <summary>
        /// Rename the ProjectViewItem.
        /// </summary>
        /// <param name="oldName"> The old name. </param>
        /// <param name="newName"> The new name. </param>
        public async Task RenameProjectViewItem(string oldName, string newName)
        {
            //Same name.
            if (oldName == newName)
            {
                this.RenameTipTextBlock.Visibility = Visibility.Visible;
                return;
            }

            //Name is already occupied.
            bool hasRenamed = this.MainLayout.Items.Any(p => p.Name == newName);

            if (hasRenamed)
            {
                this.RenameTipTextBlock.Visibility = Visibility.Visible;
                return;
            }

            //Rename
            IProjectViewItem item = this.MainLayout.Items.First(p => p.Name == oldName);
            await FileUtil.RenameZipFolder(oldName, newName, item);

            this.HideRenameDialog();
            this.MainLayout.State = MainPageState.Main;
        }
        private void ShowRenameDialog(IProjectViewItem item)
        {
            this.RenameDialog.Show();

            this._rename            = item.Name;
            this.RenameTextBox.Text = item.Name;
            this.RenameTextBox.SelectAll();
            this.RenameTextBox.Focus(FocusState.Programmatic);
        }
        /// <summary>
        /// Rename zip folder and thumbnail.
        /// </summary>
        /// <param name="oldName"> The old name. </param>
        /// <param name="newName"> The new name. </param>
        /// <param name="item"> The IProjectViewItem. </param>
        public static async Task RenameZipFolder(string oldName, string newName, IProjectViewItem item)
        {
            StorageFolder zipFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync($"{oldName}.photo2pk");

            await zipFolder.RenameAsync($"{newName}.photo2pk");

            //Rename thumbnail.
            string thumbnail = $"{zipFolder.Path}\\Thumbnail.png";

            item.Rename(newName, thumbnail);
        }
Ejemplo n.º 5
0
        private void ShowRenameDialog(IProjectViewItem item)
        {
            this.MainLayout.State = MainPageState.Dialog;

            this.RenameDialog.Show();

            this._rename            = item.Name;
            this.RenameTextBox.Text = item.Name;
            this.RenameTextBox.Focus(FocusState.Keyboard);
            this.RenameTextBox.SelectAll();
        }
        /// <summary>
        /// Duplicate all selected ProjectViewItem(s).
        /// </summary>
        /// <param name="items"> The items. </param>
        public async Task DuplicateProjectViewItems(IEnumerable <IProjectViewItem> items)
        {
            foreach (IProjectViewItem item in items.ToList())
            {
                string        oldName       = item.Name;
                string        newName       = this.MainLayout.UntitledRenameByRecursive(oldName);
                StorageFolder storageFolder = await FileUtil.DuplicateZipFolder(oldName, newName);

                IProjectViewItem newItem = FileUtil.ConstructProjectViewItem(newName, storageFolder);
                this.MainLayout.Items.Add(newItem);//Notify
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Save the current project.
        /// </summary>
        private async Task Save()
        {
            string        name      = this.ApplicationView.Title;
            int           width     = this.ViewModel.CanvasTransformer.Width;
            int           height    = this.ViewModel.CanvasTransformer.Height;
            StorageFolder zipFolder = await FileUtil.DeleteAllInZipFolder(name);


            // Save project file.
            Project project = new Project
            {
                Width     = width,
                Height    = height,
                Layerages = LayerManager.RootLayerage.Children
            };
            await Retouch_Photo2.XML.SaveProjectFile(zipFolder, project);

            // Save thumbnail file.
            IProjectViewItem item = this.Items.FirstOrDefault(p => p.Name == name);

            if ((item is null) == false)
            {
                CanvasRenderTarget thumbnail = this.ViewModel.Render(width, height);
                item.ImageSource = await FileUtil.SaveThumbnailFile(zipFolder, thumbnail);
            }

            // Save layers file.
            IEnumerable <Layerage> savedLayerages = LayerManager.GetFlatNestingLayerages(LayerManager.RootLayerage);
            IEnumerable <ILayer>   savedLayers    = from layer in LayerBase.Instances.Values where savedLayerages.Any(p => layer.Equals(p)) select layer;
            await XML.SaveLayersFile(zipFolder, savedLayers);

            // Save photos file.
            IEnumerable <Photocopier> savedPhotocopiers = LayerManager.GetPhotocopiers(savedLayerages);
            IEnumerable <Photo>       savedPhotos       = from photo in Photo.Instances.Values where savedPhotocopiers.Any(p => photo.Equals(p)) select photo;
            await XML.SavePhotosFile(zipFolder, savedPhotos);

            // Move photo file.
            foreach (Photo photo in savedPhotos)
            {
                //@Release: case Debug
                {
                    //await photo.MoveFile(zipFolder);
                }
                //@Release: case Release
                {
                    // Move photo file.
                    StorageFile file = await StorageFile.GetFileFromPathAsync(photo.ImageFilePath);

                    await file.CopyAsync(zipFolder);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary> The current page becomes the active page. </summary>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //Extension
            this.AVTBBE.Invalidate();

            await this._lockOnNavigatedTo();

            // Occurs occuse after <see  cref="DrawPage.Frame.GoBack()"/>;
            if (this.ViewModel.IsUpdateThumbnailByName)
            {
                this.ViewModel.IsUpdateThumbnailByName = false;

                IProjectViewItem item = this.MainLayout.Items.FirstOrDefault(i => i.Name == this.ViewModel.Name);
                if (item != null)
                {
                    item.RefreshImageSource();
                }
            }
        }
        // InitialControl
        private void ConstructInitialControl()
        {
            this.InitialSampleButton.Click += async(s, e) =>
            {
                this.MainLayout.Count = 3;
                this.MainLayout.State = MainPageState.Main;
                await FileUtil.SaveSampleFile();

                // Projects
                foreach (StorageFolder zipFolder in await FileUtil.FIndAllZipFolders())
                {
                    // [StorageFolder] --> [projectViewItem]
                    IProjectViewItem item = await FileUtil.ConstructProjectViewItem(zipFolder);

                    this.Items.Add(item);
                }
            };
            this.InitialAddButton.Click   += (s, e) => this.ShowAddDialog();
            this.InitialPhotoButton.Click += async(s, e) => await this.NewFromPicture(PickerLocationId.PicturesLibrary);

            this.InitialDestopButton.Click += async(s, e) => await this.NewFromPicture(PickerLocationId.Desktop);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame is null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content is null)
                {
                    // FileUtil
                    await FileUtil.DeleteAllInTemporaryFolder();

                    // Projects
                    foreach (StorageFolder zipFolder in await FileUtil.FIndAllZipFolders())
                    {
                        // [StorageFolder] --> [projectViewItem]
                        IProjectViewItem item = await FileUtil.ConstructProjectViewItem(zipFolder);

                        App.Projects.Add(item);
                    }

                    // Setting
                    Setting setting = await XML.ConstructSettingFile();

                    App.SettingViewModel.ConstructSetting(setting);

                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
                    {
                        throw new Exception("Failed to create initial page");
                    }
                    // Ensure the current window is active
                    Window.Current.Activate();
                }
            }
        }
        /// <summary>
        /// Open from ProjectViewItem.
        /// </summary>
        /// <param name="item"> The ProjectViewItem. </param>
        public async void OpenFromProjectViewItem(IProjectViewItem item)
        {
            this.LoadingControl.State = LoadingState.Loading;

            // FileUtil
            string name = item.Name;

            if (name is null || name == string.Empty)
            {
                this.LoadingControl.State = LoadingState.FileNull;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }

            // FileUtil
            await FileUtil.DeleteAllInTemporaryFolder();

            bool isExists = await FileUtil.MoveAllInZipFolderToTemporaryFolder(name);

            if (isExists == false)
            {
                this.LoadingControl.State = LoadingState.FileCorrupt;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }


            // Load all photos file.
            Photo.Instances.Clear();
            Photo.InstancesCollection.Clear();
            IEnumerable <Photo> photos = XML.LoadPhotosFile();

            if ((photos is null) == false)
            {
                foreach (Photo photo in photos)
                {
                    string id = photo.FolderRelativeId;
                    await photo.ConstructPhotoSource(LayerManager.CanvasDevice);

                    Photo.Instances.Add(id, photo);
                    Photo.UpdateInstancesCollection();
                }
            }

            // Load all layers file.
            LayerBase.Instances.Clear();
            IEnumerable <ILayer> layers = XML.LoadLayersFile();

            if ((layers is null) == false)
            {
                foreach (ILayer layer in layers)
                {
                    string id = layer.Id;
                    LayerBase.Instances.Add(id, layer);
                }
            }

            // Load project file.
            Project project = XML.LoadProjectFile();

            if (project is null)
            {
                this.LoadingControl.State = LoadingState.LoadFailed;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }

            // Item
            item.Project = project;
            item.RenderImageVisualRect(Window.Current.Content);

            this.LoadingControl.State = LoadingState.None;
            this.Frame.Navigate(typeof(DrawPage), item); // Navigate
        }
        /// <summary>
        /// Open from ProjectViewItem.
        /// </summary>
        /// <param name="projectViewItem"> The ProjectViewItem. </param>
        public async void OpenFromProjectViewItem(IProjectViewItem projectViewItem)
        {
            this.LoadingControl.State    = LoadingState.Loading;
            this.LoadingControl.IsActive = true;

            //FileUtil
            string name = projectViewItem.Name;

            if (name == null || name == string.Empty)
            {
                this.LoadingControl.IsActive = false;
                this.LoadingControl.State    = LoadingState.FileNull;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }


            await FileUtil.DeleteInTemporaryFolder();

            bool isExists = await FileUtil.MoveAllAndReturn(name);

            if (isExists == false)
            {
                this.LoadingControl.IsActive = false;
                this.LoadingControl.State    = LoadingState.FileCorrupt;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }


            //Load all photos file.
            Photo.Instances.Clear();
            IEnumerable <Photo> photos = XML.LoadPhotosFile();

            if (photos != null)
            {
                foreach (Photo photo in photos)
                {
                    await photo.ConstructPhotoSource(this.ViewModel.CanvasDevice);

                    Photo.Instances.Add(photo);
                }
            }

            //Load all layers file.
            LayerBase.Instances.Clear();
            IEnumerable <ILayer> layers = XML.LoadLayersFile(this.ViewModel.CanvasDevice);

            if (layers != null)
            {
                foreach (ILayer layer in layers)
                {
                    LayerBase.Instances.Add(layer);
                }
            }

            //Load project file.
            Project project = XML.LoadProjectFile(name);

            if (project == null)
            {
                this.LoadingControl.IsActive = false;
                this.LoadingControl.State    = LoadingState.LoadFailed;
                await Task.Delay(800);

                this.LoadingControl.State = LoadingState.None;
                return;
            }

            this.ViewModel.LoadFromProject(project);
            this.SelectionViewModel.SetMode(this.ViewModel.LayerageCollection);//Selection


            //Transition
            TransitionData data = new TransitionData
            {
                Type       = TransitionType.Transition,
                SourceRect = projectViewItem.GetVisualRect(Window.Current.Content),
                PageSize   = new Size(this.ActualWidth, this.ActualHeight - 50)
            };

            this.LoadingControl.State    = LoadingState.None;
            this.LoadingControl.IsActive = false;
            this.Frame.Navigate(typeof(DrawPage), data);//Navigate
        }