Beispiel #1
0
        public NodeActionResult Rename()
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return(NodeActionResult.NotOnline);
            }

            // Only 1 CustomInputDialog should be open at the same time.
            if (this.AppInformation.PickerOrAsyncDialogIsOpen)
            {
                return(NodeActionResult.Cancelled);
            }

            var settings = new CustomInputDialogSettings()
            {
                DefaultText                = this.Name,
                SelectDefaultText          = true,
                IgnoreExtensionInSelection = true,
            };

            var inputDialog = new CustomInputDialog(UiResources.Rename, UiResources.RenameItem, this.AppInformation, settings);

            inputDialog.OkButtonTapped += (sender, args) =>
            {
                if (SdkService.ExistsNodeByName(this.MegaSdk.getParentNode(this.OriginalMNode), args.InputText, this.OriginalMNode.isFolder()))
                {
                    inputDialog.HideDialog();
                    OnUiThread(() =>
                    {
                        new CustomMessageDialog(
                            AppMessages.RenameNodeFailed_Title,
                            this.OriginalMNode.isFolder() ? AppMessages.AM_FolderAlreadyExists : AppMessages.AM_FileAlreadyExists,
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });

                    return;
                }

                this.MegaSdk.renameNode(this.OriginalMNode, args.InputText, new RenameNodeRequestListener(this));
            };
            inputDialog.ShowDialog();

            return(NodeActionResult.IsBusy);
        }