Пример #1
0
 /// <summary>
 /// Deletes this lego robot file
 /// Use with care!!
 /// </summary>
 public async Task <bool> Delete()
 {
     return(await BrickExplorer.DeleteFile(Path));
 }
        private async void Execute(object sender, File file, ActionType type)
        {
            switch (type)
            {
            case ActionType.OPEN:
            {
                if (CURRENT_FILE?.Path != file.Path)
                {
                    CURRENT_FILE  = file;
                    SELECTED_FILE = file;
                    await previewPane.Set(file);
                }
                Entry entry = new Entry(file.Path, EntryType.FILE);
                if (entry.IsOpenEnabled)
                {
                    switch (file.Type)
                    {
                    case FileType.SoundFile:
                    {
                        Manager.Brick.Sound.Play((SoundFile)file, 50);
                        break;
                    }

                    case FileType.TextFile:
                    {
                        using (TextFileEditor textFileEditor = new TextFileEditor())
                        {
                            await textFileEditor.Initialize((TextFile)file);

                            textFileEditor.Directory = CURRENT_DIRECTORY;
                            textFileEditor.ShowDialog();
                            if (textFileEditor.RefreshDirectory)
                            {
                                Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                            }
                        }
                        break;
                    }
                    }
                }
                break;
            }

            case ActionType.SELECT:
            {
                SELECTED_FILE = file;
                await previewPane.Set(file);

                break;
            }

            case ActionType.DOWNLOAD:
            {
                ((Manager)Parent).UseWaitCursor = true;
                await Download(SELECTED_FILE);

                ((Manager)Parent).UseWaitCursor = false;
                break;
            }

            case ActionType.UPLOAD_FILE:
            {
                await UpLoadFile();

                Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                break;
            }

            case ActionType.DELETE:
            {
                if (MessageBox.Show("Are you sure you want to permanently delete this file?", "Delete file", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    await BrickExplorer.DeleteFile(file.Path);

                    Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                }
                break;
            }

            case ActionType.NEW_RTF_FILE:
            {
                using (TextFileEditor textFileEditor = new TextFileEditor())
                {
                    await textFileEditor.Initialize();

                    textFileEditor.Directory = CURRENT_DIRECTORY;
                    textFileEditor.ShowDialog();
                    if (textFileEditor.RefreshDirectory)
                    {
                        Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                    }
                }
                break;
            }

            case ActionType.NEW_IMAGE_FILE:
            {
                await UploadImage();

                Execute(this, CURRENT_DIRECTORY, ActionType.REFRESH_DIRECTORY);
                break;
            }
            }
        }