コード例 #1
0
        /// <summary>
        /// Клик по файлу в инспекторе
        /// </summary>
        private void projectInspector_MouseClick(object sender, MouseEventArgs e)
        {
            NSDirectoryInspector.Entry en = projectInspector.SelectedEntry;
            bool free = false;

            if (en != null)
            {
                free = Project.OperableFile(en.Tag);
            }
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                NSContextMenu cm = new NSContextMenu();
                if (en != null)
                {
                    // Открытие файла
                    cm.Items.Add(ControlStrings.InspectorContextOpen, ShadowImage.CompiledFromImage(InspectorIcons.MenuOpen, 16, 1), (sndr, args) => {
                        if (en != null)
                        {
                            if (en.IsDirectory)
                            {
                                Project.Dir dr = en.Tag as Project.Dir;
                                if (dr != null)
                                {
                                    PopulateManager(dr);
                                }
                            }
                            else
                            {
                                OpenEditor(en.Tag as Project.Entry);
                            }
                        }
                    });
                }

                // Создание файла
                ToolStripMenuItem crItem = new ToolStripMenuItem(ControlStrings.InspectorContextCreate, ShadowImage.CompiledFromImage(InspectorIcons.MenuAdd, 16, 1));
                crItem.DropDown = new NSContextMenu();
                AddCreationMenuItems(crItem.DropDown.Items);
                cm.Items.Add(crItem);

                // Разделитель
                cm.Items.Add(new ToolStripSeparator());

                if (en != null)
                {
                    // Смена имени
                    cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextRename, ShadowImage.CompiledFromImage(InspectorIcons.MenuRename, 16, 1), (sndr, args) => {
                        string[] used;
                        string ext = "";
                        if (en.IsDirectory)
                        {
                            used = (en.Tag as Project.Dir).UsedNames;
                        }
                        else
                        {
                            used = (en.Tag as Project.Entry).Parent.UsedNames;
                            ext  = System.IO.Path.GetExtension((en.Tag as Project.Entry).Name);
                        }

                        RenameItemDialog rd = new RenameItemDialog(en.Name);
                        rd.SpecifiedName    = en.Name;
                        rd.Extension        = ext;
                        rd.ExistingNames    = used;
                        needProjectRescan   = false;
                        if (rd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            if (en.IsDirectory)
                            {
                                Project.RenameItem(en.Tag as Project.Dir, rd.SpecifiedName);
                            }
                            else
                            {
                                Project.RenameItem(en.Tag as Project.Entry, rd.SpecifiedName);
                            }
                        }
                    })
                    {
                        Enabled = free
                    });

                    // Копирование
                    cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextCopy, ShadowImage.CompiledFromImage(InspectorIcons.MenuCopy, 16, 1), (sndr, args) => {
                        if (en != null)
                        {
                            copyingDir   = null;
                            copyingEntry = null;
                            if (en.IsDirectory)
                            {
                                copyingDir = en.Tag as Project.Dir;
                            }
                            else
                            {
                                copyingEntry = en.Tag as Project.Entry;
                            }
                        }
                    })
                    {
                        Enabled = free
                    });
                }

                // Вставка
                ToolStripMenuItem ps = new ToolStripMenuItem(ControlStrings.InspectorContextPaste, ShadowImage.CompiledFromImage(InspectorIcons.MenuPaste, 16, 1), (sndr, args) => {
                    Project.Dir bd    = (Project.Dir)projectInspector.Tag;
                    localFileEvent    = true;
                    needProjectRescan = false;
                    if (copyingDir != null)
                    {
                        Project.Dir cd = Project.CopyDir(copyingDir, bd);
                        NSDirectoryInspector.Entry fen = new NSDirectoryInspector.Entry();
                        fen.IsDirectory = true;
                        fen.Name        = cd.ShortName;
                        fen.Tag         = (object)cd;
                        projectInspector.Entries.Add(fen);
                        projectInspector.SelectedEntry = fen;
                    }
                    else if (copyingEntry != null)
                    {
                        Project.Entry ce = Project.CopyEntry(copyingEntry, bd);
                        NSDirectoryInspector.Entry fen = new NSDirectoryInspector.Entry();
                        fen.IsDirectory = false;
                        fen.Name        = System.IO.Path.GetFileNameWithoutExtension(ce.Name);
                        fen.Icon        = ce.Icon;
                        fen.Tag         = (object)ce;
                        projectInspector.Entries.Add(fen);
                        projectInspector.SelectedEntry = fen;
                    }
                    localFileEvent = false;
                });
                ps.Enabled = copyingDir != null || copyingEntry != null;
                cm.Items.Add(ps);

                if (en != null)
                {
                    // Удаление
                    cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextDelete, ShadowImage.CompiledFromImage(InspectorIcons.MenuDelete, 16, 1), (sndr, args) => {
                        if (en != null)
                        {
                            RemoveEntry(en);
                        }
                    })
                    {
                        Enabled = free
                    });
                }

                cm.Show(inspectorPopupLocation);
            }
        }
コード例 #2
0
        public override void Run()
        {
            var wb      = Workbench.Instance;
            var exp     = wb.ActiveSiteExplorer;
            var omgr    = ServiceRegistry.GetService <OpenResourceManager>();
            var connMgr = ServiceRegistry.GetService <ServerConnectionManager>();
            var conn    = connMgr.GetConnection(exp.ConnectionName);

            if (exp.SelectedItems.Length == 1)
            {
                var           current = exp.SelectedItems[0];
                var           parent  = current.Parent;
                List <string> names   = new List <string>();
                foreach (var item in parent.Children)
                {
                    if (item != exp.SelectedItems[0])
                    {
                        names.Add(item.Name);
                    }
                }

                if (!current.IsFolder && omgr.IsOpen(current.ResourceId, conn))
                {
                    MessageService.ShowMessage(Strings.CannotRenameAlreadyOpenedResource);
                    return;
                }

                var dlg = new RenameItemDialog(current.Name, names);
                if (dlg.ShowDialog(wb) == System.Windows.Forms.DialogResult.OK)
                {
                    string oldid = string.Empty;
                    string newid = string.Empty;
                    if (current.IsFolder)
                    {
                        oldid = $"{parent.ResourceId + current.Name}/"; //NOXLATE
                        newid = $"{parent.ResourceId + dlg.NewName}/";  //NOXLATE
                    }
                    else
                    {
                        oldid = $"{parent.ResourceId + current.Name}.{current.ResourceType}"; //NOXLATE
                        newid = $"{parent.ResourceId + dlg.NewName}.{current.ResourceType}";  //NOXLATE
                    }

                    if (omgr.IsOpen(newid, conn))
                    {
                        MessageService.ShowMessage(string.Format(Strings.CannotRenameToResourceAlreadyOpened, newid));
                        return;
                    }

                    var prog = new ProgressDialog();
                    prog.RunOperationAsync(wb, (worker, e, args) =>
                    {
                        LengthyOperationProgressCallBack cb = (s, cbArgs) =>
                        {
                            worker.ReportProgress(cbArgs.Progress, cbArgs.StatusMessage);
                        };

                        //Perform the operation
                        if (dlg.UpdateReferences)
                        {
                            conn.ResourceService.MoveResourceWithReferences(oldid, newid, null, cb);
                        }
                        else
                        {
                            conn.ResourceService.MoveResource(oldid, newid, true); // dlg.Overwrite);
                        }

                        /*
                         * if (current.IsFolder)
                         * {
                         *  if (dlg.UpdateReferences)
                         *      conn.ResourceService.MoveFolderWithReferences(oldid, newid, null, cb);
                         *  else
                         *      conn.ResourceService.MoveFolder(oldid, newid, dlg.Overwrite);
                         * }
                         * else
                         * {
                         *  if (dlg.UpdateReferences)
                         *  {
                         *      conn.ResourceService.MoveResourceWithReferences(oldid, newid, null, cb);
                         *  }
                         *  else
                         *      conn.ResourceService.MoveResource(oldid, newid, dlg.Overwrite);
                         * }*/

                        current.Name = dlg.NewName;

                        return(true);
                    });

                    //Need to refresh the model because it still is called by the old name
                    var folder = ResourceIdentifier.GetParentFolder(oldid);
                    exp.RefreshModel(conn.DisplayName, folder);
                }
            }
        }