コード例 #1
0
        internal void RenameResourceId(string oldId, string newId, IServerConnection conn, ISiteExplorer siteExp)
        {
            Check.ArgumentNotEmpty(oldId, nameof(oldId));
            Check.ArgumentNotEmpty(newId, nameof(newId));
            Check.ArgumentNotNull(siteExp, nameof(siteExp));
            Check.ArgumentNotNull(conn, nameof(conn));

            string oldKey = ComputeResourceKey(oldId, conn);
            string newKey = ComputeResourceKey(newId, conn);

            if (oldKey.Equals(newKey))
            {
                return;
            }

            //Original must exist and new id must not
            if (_openItems.ContainsKey(oldKey) && !_openItems.ContainsKey(newKey))
            {
                var ed = _openItems[oldKey];
                _openItems.Remove(oldKey);
                _openItems[newKey] = ed;

                siteExp.FlagNode(conn.DisplayName, oldId, NodeFlagAction.None);
                siteExp.FlagNode(conn.DisplayName, newId, NodeFlagAction.HighlightOpen);
            }
        }
コード例 #2
0
        internal static string ComputeResourceKey(IResource res, IServerConnection conn) => $"{conn.DisplayName}|{res.ResourceID}"; //NOXLATE

        /// <summary>
        /// Opens the specified resource using its assigned editor. If the resource is already
        /// open, the the existing editor view is activated instead. If the resource has no assigned
        /// editor or useXmlEditor is true, the resource will be opened in the default
        /// XML editor.
        /// </summary>
        /// <param name="res"></param>
        /// <param name="conn"></param>
        /// <param name="useXmlEditor"></param>
        /// <param name="siteExp"></param>
        public IEditorViewContent Open(IResource res, IServerConnection conn, bool useXmlEditor, ISiteExplorer siteExp)
        {
            string key = ComputeResourceKey(res, conn);

            if (!_openItems.ContainsKey(key))
            {
                var svc = ServiceRegistry.GetService <ViewContentManager>();
                IEditorViewContent ed = null;
                if (useXmlEditor || !res.IsStronglyTyped)
                {
                    ed = svc.OpenContent <XmlEditor>(ViewRegion.Document);
                }
                else
                {
                    ed = FindEditor(svc, res.GetResourceTypeDescriptor());
                }
                var launcher  = ServiceRegistry.GetService <UrlLauncherService>();
                var editorSvc = new ResourceEditorService(res.ResourceID, conn, launcher, siteExp, this, this);
                ed.EditorService = editorSvc;
                _openItems[key]  = ed;
                CancelEventHandler vcClosing = (sender, e) =>
                {
                    if (ed.IsDirty && !ed.DiscardChangesOnClose)
                    {
                        if (ed.IsNew)
                        {
                            if (!MessageService.AskQuestion(string.Format(Strings.CloseUnsavedResource, string.Empty)))
                            {
                                e.Cancel = true;
                            }
                        }
                        else
                        {
                            using (var diag = new DirtyStateConfirmationDialog(ed.EditorService))
                            {
                                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.No)
                                {
                                    e.Cancel = true;
                                }
                            }
                        }
                    }
                };
                ed.ViewContentClosing += WeakEventHandler.Wrap(vcClosing, (eh) => ed.ViewContentClosing -= eh);
                EventHandler vcClosed = (sender, e) =>
                {
                    //Recompute the resource key as that may have changed by a save as operation
                    _openItems.Remove(ComputeResourceKey(((EditorContentBase)sender).EditorService.ResourceID, conn));
                    siteExp.FlagNode(conn.DisplayName, ed.EditorService.ResourceID, NodeFlagAction.None);
                };
                ed.ViewContentClosed += WeakEventHandler.Wrap(vcClosed, (eh) => ed.ViewContentClosed -= eh);
                EventHandler edSaved = (sender, e) =>
                {
                    //If saved from new resource, the resource id would be session based
                    //So we need to update this to the new resource id as defined by the
                    //editor service
                    if (_openItems.ContainsKey(key))
                    {
                        var ed2 = _openItems[key];
                        _openItems.Remove(key);
                        _openItems[ComputeResourceKey(ed.EditorService.ResourceID, conn)] = ed2;
                    }
                };
                ed.EditorService.Saved += WeakEventHandler.Wrap(edSaved, (eh) => ed.EditorService.Saved -= eh);
                EventHandler dirty = (sender, e) =>
                {
                    siteExp.FlagNode(conn.DisplayName, res.ResourceID, ed.IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
                };
                ed.DirtyStateChanged += WeakEventHandler.Wrap(dirty, (eh) => ed.DirtyStateChanged -= eh);
            }
            _openItems[key].Activate();
            siteExp.FlagNode(conn.DisplayName, res.ResourceID, _openItems[key].IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
            return(_openItems[key]);
        }
コード例 #3
0
ファイル: OpenResourceManager.cs プロジェクト: kanbang/Colt
        internal void RenameResourceId(string oldId, string newId, IServerConnection conn, ISiteExplorer siteExp)
        {
            Check.NotEmpty(oldId, "oldId"); //NOXLATE
            Check.NotEmpty(newId, "newId"); //NOXLATE
            Check.NotNull(siteExp, "siteExp"); //NOXLATE
            Check.NotNull(conn, "conn"); //NOXLATE

            string oldKey = ComputeResourceKey(oldId, conn);
            string newKey = ComputeResourceKey(newId, conn);

            if (oldKey.Equals(newKey))
                return;

            //Original must exist and new id must not
            if (_openItems.ContainsKey(oldKey) && !_openItems.ContainsKey(newKey))
            {
                var ed = _openItems[oldKey];
                _openItems.Remove(oldKey);
                _openItems[newKey] = ed;

                siteExp.FlagNode(conn.DisplayName, oldId, NodeFlagAction.None);
                siteExp.FlagNode(conn.DisplayName, newId, NodeFlagAction.HighlightOpen);
            }
        }
コード例 #4
0
ファイル: OpenResourceManager.cs プロジェクト: kanbang/Colt
 /// <summary>
 /// Opens the specified resource using its assigned editor. If the resource is already
 /// open, the the existing editor view is activated instead. If the resource has no assigned
 /// editor or useXmlEditor is true, the resource will be opened in the default
 /// XML editor.
 /// </summary>
 /// <param name="res"></param>
 /// <param name="conn"></param>
 /// <param name="useXmlEditor"></param>
 /// <param name="siteExp"></param>
 public IEditorViewContent Open(IResource res, IServerConnection conn, bool useXmlEditor, ISiteExplorer siteExp)
 {
     string key = ComputeResourceKey(res, conn);
     if (!_openItems.ContainsKey(key))
     {
         var svc = ServiceRegistry.GetService<ViewContentManager>();
         IEditorViewContent ed = null;
         if (useXmlEditor || !res.IsStronglyTyped)
         {
             ed = svc.OpenContent<XmlEditor>(ViewRegion.Document);
         }
         else
         {
             ed = FindEditor(svc, res.GetResourceTypeDescriptor());
         }
         var launcher = ServiceRegistry.GetService<UrlLauncherService>();
         var editorSvc = new ResourceEditorService(res.ResourceID, conn, launcher, siteExp, this);
         ed.EditorService = editorSvc;
         _openItems[key] = ed;
         ed.ViewContentClosing += (sender, e) =>
         {
             if (ed.IsDirty && !ed.DiscardChangesOnClose)
             {
                 if (ed.IsNew)
                 {
                     if (!MessageService.AskQuestion(string.Format(Strings.CloseUnsavedResource, string.Empty)))
                     {
                         e.Cancel = true;
                     }
                 }
                 else
                 {
                     using (var diag = new DirtyStateConfirmationDialog(ed.EditorService))
                     {
                         if (diag.ShowDialog() == System.Windows.Forms.DialogResult.No)
                         {
                             e.Cancel = true;
                         }
                     }
                 }
             }
         };
         ed.ViewContentClosed += (sender, e) =>
         {
             //Recompute the resource key as that may have changed by a save as operation
             _openItems.Remove(ComputeResourceKey(((EditorContentBase)sender).EditorService.ResourceID, conn));
             siteExp.FlagNode(conn.DisplayName, ed.EditorService.ResourceID, NodeFlagAction.None);
         };
         ed.EditorService.Saved += (sender, e) =>
         {
             //If saved from new resource, the resource id would be session based
             //So we need to update this to the new resource id as defined by the
             //editor service
             if (_openItems.ContainsKey(key))
             {
                 var ed2 = _openItems[key];
                 _openItems.Remove(key);
                 _openItems[ComputeResourceKey(ed.EditorService.ResourceID, conn)] = ed2;
             }
         };
         ed.DirtyStateChanged += (sender, e) =>
         {
             siteExp.FlagNode(conn.DisplayName, res.ResourceID, ed.IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
         };
     }
     _openItems[key].Activate();
     siteExp.FlagNode(conn.DisplayName, res.ResourceID, _openItems[key].IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
     return _openItems[key];
 }