public async Task Initialize() { Directory root = await BrickExplorer.GetDirectory(BrickExplorer.ROOT_PATH); CURRENT_DIRECTORY = root; SELECTED_DIRECTORY = root; await folderTree.Initialize(root); await previewPane.Initialize(root); navigationBar.Initialize(); DirectoryContent content = await DirectoryContent.Get(root); directoryContentPane.Set(content); statusBar.Set(content.Info); if (UserSettings.Mode == Mode.BASIC) { Directory drive = await BrickExplorer.GetDirectory(BrickExplorer.PROJECTS_PATH); Execute(this, drive, ActionType.OPEN); } }
private async void Execute(object sender, Directory directory, ActionType type) { switch (type) { case ActionType.OPEN: { if (CURRENT_DIRECTORY.Path == directory.Path) { return; // do not open again is already open } CURRENT_DIRECTORY = directory; SELECTED_DIRECTORY = directory; statusBar.SetLoading(); ((Manager)Parent).UseWaitCursor = true; DirectoryContent content = await DirectoryContent.Get(directory); previewPane.Set(directory, content.Info); directoryContentPane.Set(content); statusBar.Set(content.Info); navigationBar.Set(directory); ((Manager)Parent).UseWaitCursor = false; break; } case ActionType.SELECT: { SELECTED_DIRECTORY = directory; previewPane.Set(directory, null); break; } case ActionType.DOWNLOAD: { ((Manager)Parent).UseWaitCursor = true; await Download(SELECTED_DIRECTORY); ((Manager)Parent).UseWaitCursor = false; break; } case ActionType.CREATE_DIRECTORY: { using (CreateEntryDialog dialog = new CreateEntryDialog(CURRENT_DIRECTORY, EntryType.DIRECTORY, null)) { if (dialog.ShowDialog() == DialogResult.OK) { string path = System.IO.Path.Combine(CURRENT_DIRECTORY.Path, dialog.EntryName); await BrickExplorer.CreateDirectory(path); await folderTree.Refresh(CURRENT_DIRECTORY); Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY); } } break; } case ActionType.DELETE: { if (MessageBox.Show("Are you sure you want to permanently delete this directory and all it's content?", "Delete directory", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { ((Manager)Parent).UseWaitCursor = true; await BrickExplorer.DeleteDirectory(directory.Path, true); await folderTree.Refresh(CURRENT_DIRECTORY); Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY); ((Manager)Parent).UseWaitCursor = false; } break; } case ActionType.REFRESH_DIRECTORY: { statusBar.SetLoading(); ((Manager)Parent).UseWaitCursor = true; DirectoryContent content = await DirectoryContent.Get(CURRENT_DIRECTORY); directoryContentPane.Set(content); previewPane.Set(directory, content.Info); statusBar.Set(content.Info); ((Manager)Parent).UseWaitCursor = false; break; } case ActionType.UPLOAD_DIRECTORY: { await UploadDirectory(); await folderTree.Refresh(CURRENT_DIRECTORY); Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY); break; } } }