Exemplo n.º 1
0
        /// <summary>
        /// Dumps an object to the specified sink.
        /// </summary>
        /// <param name="o">The object to dump.</param>
        /// <param name="description">A description of the object. Can be null.</param>
        /// <param name="sink">The sink URI. If no sink URI is specified the default sink is used.</param>
        public static void Dump(this object o, string description, Uri sink = null)
        {
            if (sink == null)
            {
                sink = DefaultSinkUri;
            }
            var s = GetSink(sink);

            if (s == null)
            {
                throw new NotSupportedException("The requested sink doesnt exist: " + sink + ", make sure the URI is spelled correctly and the module containing the specified sink is loaded.");
            }

            Execute.OnUIThreadEx(() =>
            {
                try
                {
                    s.Dump(o, description);
                }
                catch (Exception ex)
                {
                    var log = LogManager.GetLog(typeof(Shell));
                    log.Error(ex);
                    throw;
                }
            });
        }
Exemplo n.º 2
0
        public override void CanClose(System.Action <bool> callback)
        {
            //callback(!IsDirty);
            if (!IsDirty)
            {
                callback(true);
                return;
            }

            Execute.OnUIThreadEx(() =>
            {
                MessageBoxResult result = MessageBox.Show("Do you want to save this document before closing?" + Environment.NewLine + Uri.AbsolutePath, "Confirmation", MessageBoxButton.YesNoCancel);
                if (result == MessageBoxResult.Yes)
                {
                    Save();
                    callback(true);
                }
                else if (result == MessageBoxResult.No)
                {
                    callback(true);
                }
                else
                {
                    // Cancel
                    callback(false);
                }
            });
        }
Exemplo n.º 3
0
 public void UpdateMessage(string message)
 {
     lock (syncRoot)
     {
         this.message = message;
     }
     Execute.OnUIThread(() => NotifyOfPropertyChange(() => Message));
 }
Exemplo n.º 4
0
 public override void Save()
 {
     Execute.OnUIThreadEx(() =>
     {
         textEditor.Save(path);
         originalText = textEditor.Text;
         IsDirty      = false;
     });
 }
Exemplo n.º 5
0
 public void SaveLayout(XmlWriter xmlWriter)
 {
     if (shellView != null && shellView.DockingManager != null)
     {
         Execute.OnUIThreadEx(() =>
         {
             var layoutSerializer = new XmlLayoutSerializer(shellView.DockingManager);
             layoutSerializer.Serialize(xmlWriter);
         });
     }
 }
Exemplo n.º 6
0
        public override void SaveAs(string newFile)
        {
            Execute.OnUIThreadEx(() =>
            {
                textEditor.Save(newFile);
                this.path = newFile;
                fileName  = Path.GetFileName(newFile);
                Uri       = new Uri(System.IO.Path.GetFullPath(newFile));

                originalText = textEditor.Text;
                IsDirty      = false;
                DisplayName  = fileName;
                NotifyOfPropertyChange(() => DisplayName);
            });
        }
Exemplo n.º 7
0
 public void Select(int start, int length)
 {
     start = Math.Abs(start);
     start = Math.Abs(length);
     Execute.OnUIThreadEx(() =>
     {
         if (start > textEditor.Document.TextLength)
         {
             start = textEditor.Document.TextLength - 1;
         }
         if (start + length > textEditor.Document.TextLength)
         {
             length = textEditor.Document.TextLength - start;
         }
         textEditor.Select(start, length);
     });
 }
Exemplo n.º 8
0
 public void Uncomment()
 {
     Execute.OnUIThreadEx(() => editorView.Uncomment());
 }
Exemplo n.º 9
0
 public void SelectAll()
 {
     Execute.OnUIThreadEx(() => textEditor.SelectAll());
 }
Exemplo n.º 10
0
 public void Paste()
 {
     Execute.OnUIThreadEx(() => textEditor.Paste());
 }
Exemplo n.º 11
0
 public void Copy()
 {
     Execute.OnUIThreadEx(() => textEditor.Copy());
 }
Exemplo n.º 12
0
 public void Redo()
 {
     Execute.OnUIThreadEx(() => textEditor.Redo());
 }
Exemplo n.º 13
0
        public void LoadLayout(XmlReader xmlReader)
        {
            if (shellView != null && shellView.DockingManager != null)
            {
                Execute.OnUIThreadEx(() =>
                {
                    var layoutSerializer = new XmlLayoutSerializer(shellView.DockingManager);
                    //Here I've implemented the LayoutSerializationCallback just to show
                    // a way to feed layout desarialization with content loaded at runtime
                    //Actually I could in this case let AvalonDock to attach the contents
                    //from current layout using the content ids
                    //LayoutSerializationCallback should anyway be handled to attach contents
                    //not currently loaded
                    layoutSerializer.LayoutSerializationCallback += (s, e) =>
                    {
                        var contentId = e.Model.ContentId;
                        //if no content id is available or the content has already been found we dont bother loading it
                        if (string.IsNullOrEmpty(contentId) || e.Content != null)
                        {
                            return;
                        }

                        //restore the documents and sinks
                        var uri = new Uri(contentId);
                        if (uri.Scheme == "file")
                        {
                            e.Content = CShell.Shell.GetDocument(uri, true);
                        }
                        if (uri.Scheme == "sink")
                        {
                            e.Content = CShell.Shell.GetSink(uri, true);  //do not open sink
                        }
                        //make sure that the document is part of the shells items
                        var doc = e.Content as IDocument;
                        if (doc != null)
                        {
                            EnsureItem(doc);
                        }

                        //restore the tools
                        if (uri.Scheme == "tool")
                        {
                            e.Content = CShell.Shell.GetTool(uri, true);
                        }
                        var tool = e.Content as ITool;
                        if (tool != null && !_tools.Contains(tool))
                        {
                            _tools.Add(tool);
                        }
                    };
                    try
                    {
                        layoutSerializer.Deserialize(xmlReader);
                    }
                    catch (Exception ex)
                    {
                        //no big deal if the layout cannot be restored, there can be a few reasons, we just log the error and move on
                        // one reason is if there is no layout element in the xml
                        log.Error(ex);
                    }
                });
            }
        }//end method
Exemplo n.º 14
0
 public void Clear()
 {
     Execute.OnUIThread(() => internalRepl.Clear());
 }