Example #1
0
        private void RemoveAConfiguredAccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dlg = new ChooseAccount())
            {
                dlg.ShowDialog(this);
                var account = dlg.SelectedAccount;
                if (account != null)
                {
                    if (this.ShowConfirm("Are you sure you want to remove account '" + account.UserEmailAddress + "'?") != DialogResult.Yes)
                    {
                        return;
                    }

                    account.Synchronizer.Stop();
                    account.Synchronizer.StateProvider.Reset();
                    account.Remove();
                    account.UnregisterOnDemandSynchronizer();
                    IOUtilities.DirectoryDelete(account.DataDirectoryPath, true, false);
                    Settings.Current.ResetAccounts();
                    this.ShowMessage("Account '" + account.UserEmailAddress + "' was removed successfully.");
                }
            }
        }
Example #2
0
        protected override void OnMenuInvoke(ShellMenuInvokeEventArgs e)
        {
            if (e.Verb != null)
            {
                // user is using "New ..." menu in the Explorer command bar
                // note if the user is using the "New..." menu in the folder's Context menu, it will not get there but be handled by WebShellFolderServer's notifier creation handling
                if (e.Verb.EqualsIgnoreCase("NewFolder") || e.Verb.EqualsIgnoreCase("NewLink") || e.Verb.StartsWith("."))
                {
                    // come up with a new file name
                    // since we're virtual we use a temp path

                    // here, we use the Shell itself to come up with a new file name (roundtrip api)
                    // note this can be costy in terms of performance (server call, etc.)
                    // so, we could choose arbitrary name instead, or ask the server for a new name
                    var files   = new List <string>();
                    var folders = new List <string>();
                    foreach (var item in ApiItem.EnumerateChildren())
                    {
                        if (item.IsFolder)
                        {
                            folders.Add(IOUtilities.PathToValidFileName(item.Name));
                        }
                        else
                        {
                            files.Add(IOUtilities.PathToValidFileName(item.Name));
                        }
                    }

                    // use ShellBoost's utility classes
                    var options = new CreateNewItemOptions();
                    options.ExistingFileNames   = files;
                    options.ExistingFolderNames = folders;
                    var path = Menu.CreateNewItem(e.Verb, options, false);
                    if (path != null)
                    {
                        var name = ApiItem.GetNewName(Path.GetFileName(path));
                        if (IOUtilities.DirectoryExists(path))
                        {
                            WebApi.CreateAsync(ApiItem.Id, null, name, FileAttributes.Directory);
                        }
                        else
                        {
                            WebApi.CreateAsync(ApiItem.Id, path, name);
                        }

                        // cleanup temp files
                        IOUtilities.DirectoryDelete(options.TargetPath, true, false);
                    }
                    return;
                }
            }

            // copy & cut support
            if (e.Command == DFM_CMD.DFM_CMD_COPY || e.Command == DFM_CMD.DFM_CMD_MOVE)
            {
                // make sure items are present locally
                // note if the past action is too fast, items may not be here yet (user will have to press "Retry")
                foreach (var si in e.Items)
                {
                    if (si is not IObjectWithApiItem apiItem)
                    {
                        continue;
                    }

                    Task.Run(() => apiItem.ApiItem.EnsureLocalAsync(si.FileSystemPath));
                }
                return;
            }

            // note DFM_CMD_DELETE is unhandled here so will fallback in OnOperate RecycleItem / RemoveItem
            base.OnMenuInvoke(e);
        }