Пример #1
0
 private void OnClearLocal(object sender, ShellMenuInvokeEventArgs e)
 {
     foreach (var item in e.Items)
     {
         IOUtilities.PathDelete(item.FileSystemPath, true, false);
     }
     NotifyUpdate();
 }
Пример #2
0
        private void DownloadLocally(object sender, ShellMenuInvokeEventArgs e)
        {
            foreach (var si in e.Items)
            {
                if (si.FileSystemPath == null || si is not IObjectWithApiItem apiItem)
                {
                    continue;
                }

                Task.Run(() => apiItem.ApiItem.EnsureLocalAsync(si.FileSystemPath));
            }
            NotifyUpdate();
        }
Пример #3
0
        private void PushToServer(object sender, ShellMenuInvokeEventArgs e)
        {
            foreach (var si in e.Items)
            {
                if (si.FileSystemPath == null || si is not IObjectWithApiItem apiItem)
                {
                    continue;
                }

                // already only on server,
                if (!IOUtilities.PathExists(si.FileSystemPath))
                {
                    continue;
                }

                Task.Run(() => FolderServer.LocalEvents.SynchronizeFile(si.FileSystemPath));
            }
            NotifyUpdate();
        }
Пример #4
0
        private void OnRootProperties(object sender, ShellMenuInvokeEventArgs e)
        {
            var ctx = ShellContext.Current.Clone();

            TaskUtilities.EnsureSTAThreadTask(() =>
            {
                // find the top view window handle
                var viewHandle = Core.WindowsShell.View.GetOwnerViewHandle(e.HwndOwner);
                using (var form = new RootProperties())
                {
                    form.MemoryCacheCleared += (s, e2) =>
                    {
                        WebApi.ClearCache();
                    };
                    // use native proxy's 32x32 icon
                    form.Icon           = FolderServer.NativeProxy.Icons.FirstOrDefault(i => i.Height == 32).ToIcon();
                    form.SelectedObject = WebApi.ServerInfo;
                    WindowsUtilities.RunForm(form, viewHandle);
                }
            });
        }
        private async void OnShellMenuItemInvoke(object sender, ShellMenuInvokeEventArgs e)
        {
            // e.MenuItem can be null for standard commands
            var menu = (ShellMenu)sender;

            // log something (if a logger is configured)
            menu.Server.Configuration?.Logger?.Log(TraceLevel.Info, "Shell Item '" + e.MenuItem + "' (cmd:" + e.Command + ") called.");

            var mc = Conversions.ChangeType(e.MenuItem?.Tag, MenuCommand.Unknown);

            switch (mc)
            {
            case MenuCommand.Modify:
                if (e.Items.Count == 1)                // we only support modification of one value at a time
                {
                    using (var form = new EditValue()) // note because of async + await, Dispose will happen in continuing task
                    {
                        var valueItem = (RegistryValueItem)e.Items[0];
                        form.LoadEditor(BaseParent.Hive, Path, valueItem.KeyName);
                        await WindowsUtilities.ShowModelessAsync(form, e.HwndOwner).ContinueWith((task) =>
                        {
                            if (task.Result == DialogResult.OK)
                            {
                                using (var key = OpenKey(true))
                                {
                                    key.SetValue(valueItem.KeyName, form.NewValue);
                                    valueItem.Parent?.NotifyUpdate();
                                }
                            }
                        });
                    }
                    return;
                }
                break;

            case MenuCommand.NewKey:
                using (var key = OpenKey(true))
                {
                    if (key != null)
                    {
                        var newName = GetNewName("New Key #", key.GetSubKeyNames());
                        try
                        {
                            key.CreateSubKey(newName);
                            e.Folder.RefreshShellViews();
                            await SelectAndEdit(newName);
                        }
                        catch (Exception ex)
                        {
                            // probably an access denied error
                            await WindowsUtilities.DoModelessAsync(() =>
                            {
                                MessageBox.Show(new Win32Window(e.HwndOwner), "The Registry Folder cannot set a value here: " + ex.Message, "Registry Folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            });
                        }
                    }
                }
                break;

            case MenuCommand.NewValueString:
            case MenuCommand.NewValueBinary:
            case MenuCommand.NewValueDWord:
            case MenuCommand.NewValueQWord:
            case MenuCommand.NewValueMultiString:
            case MenuCommand.NewValueExpandString:
                var kind = (RegistryValueKind)mc;
                using (var key = OpenKey(true))
                {
                    if (key != null)
                    {
                        var newName = GetNewName("New Value #", key.GetValueNames());
                        try
                        {
                            key.SetValue(newName, GetDefaultValue(kind), kind);
                            e.Folder.RefreshShellViews();
                            await SelectAndEdit(newName);
                        }
                        catch (Exception ex)
                        {
                            // probably an access denied error
                            await WindowsUtilities.DoModelessAsync(() =>
                            {
                                MessageBox.Show(new Win32Window(e.HwndOwner), "The Registry Folder cannot set a value here: " + ex.Message, "Registry Folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            });
                        }
                    }
                }
                break;
            }
        }
Пример #6
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);
        }
 private void OnShellMenuItemInvoke(object sender, ShellMenuInvokeEventArgs e)
 {
     // TODO: get the clicked Id from the e argument and handle the item creation
 }