~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/LogView.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
using MonoDevelop.Core.ProgressMonitoring;
34
34
using MonoDevelop.Core.Execution;
35
35
using System.IO;
 
36
using System.Text.RegularExpressions;
 
37
using MonoDevelop.Ide.Fonts;
 
38
using MonoDevelop.Components.Commands;
36
39
 
37
40
namespace MonoDevelop.Ide.Gui.Components
38
41
{
41
44
                Gtk.TextBuffer buffer;
42
45
                Gtk.TextView textEditorControl;
43
46
                TextMark endMark;
44
 
                FontDescription customFont;
45
 
                
 
47
 
46
48
                TextTag tag;
47
49
                TextTag bold;
48
50
                TextTag errorTag;
58
60
                
59
61
                const int MAX_BUFFER_LENGTH = 4000 * 1024; 
60
62
 
 
63
                /// <summary>
 
64
                /// The log text view allows the user to jump to the source of an error/warning
 
65
                /// by double clicking on the line in the text view.
 
66
                /// </summary>
 
67
                public class LogTextView : TextView
 
68
                {
 
69
                        public LogTextView (Gtk.TextBuffer buf) : base (buf)
 
70
                        {
 
71
                        }
 
72
 
 
73
                        public LogTextView () 
 
74
                        {
 
75
                        }
 
76
 
 
77
                        static Regex lineRegex = new Regex ("\\b.*\\s(?<file>[/\\\\].*):(line\\s)?(?<line>\\d+)\\s*$", RegexOptions.Compiled);
 
78
                        protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
 
79
                        {
 
80
                                if (evnt.Type == Gdk.EventType.TwoButtonPress) {
 
81
                                        var cursorPos = base.Buffer.GetIterAtOffset (this.Buffer.CursorPosition);
 
82
 
 
83
                                        TextIter iterStart;
 
84
                                        TextIter iterEnd;
 
85
                                        string lineText;
 
86
                                        try {
 
87
                                                iterStart = Buffer.GetIterAtLine (cursorPos.Line);
 
88
                                                iterEnd = Buffer.GetIterAtOffset (iterStart.Offset + iterStart.CharsInLine);
 
89
 
 
90
                                                lineText = Buffer.GetText (iterStart, iterEnd, true);
 
91
                                        } catch (Exception e) {
 
92
                                                LoggingService.LogError ("Error in getting text of the current line.", e);
 
93
                                                return base.OnButtonPressEvent (evnt);
 
94
                                        }
 
95
 
 
96
                                        var match = lineRegex.Match (lineText);
 
97
                                        if (match.Success) {
 
98
                                                string file = match.Groups["file"].Value;
 
99
                                                string line = match.Groups["line"].Value;
 
100
                                                if (!string.IsNullOrEmpty (file) && !string.IsNullOrEmpty (line)) {
 
101
                                                        bool fileExists;
 
102
                                                        try {
 
103
                                                                fileExists = File.Exists (file);
 
104
                                                        } catch {
 
105
                                                                fileExists = false;
 
106
                                                        }
 
107
                                                        if (fileExists) {
 
108
                                                                int lineNumber;
 
109
                                                                try {
 
110
                                                                        lineNumber = int.Parse (line);
 
111
                                                                } catch (Exception) {
 
112
                                                                        lineNumber = 1;
 
113
                                                                }
 
114
                                                                IdeApp.Workbench.OpenDocument (file, lineNumber, 1);
 
115
                                                        }
 
116
                                                }
 
117
                                        }
 
118
                                }
 
119
                                return base.OnButtonPressEvent (evnt);
 
120
                        }
 
121
                }
 
122
 
61
123
                public LogView ()
62
124
                {
63
125
                        buffer = new Gtk.TextBuffer (new Gtk.TextTagTable ());
64
 
                        textEditorControl = new Gtk.TextView (buffer);
 
126
                        textEditorControl = new LogTextView (buffer);
65
127
                        textEditorControl.Editable = false;
66
128
                        
67
129
                        ShadowType = ShadowType.None;
87
149
                        
88
150
                        endMark = buffer.CreateMark ("end-mark", buffer.EndIter, false);
89
151
 
90
 
                        UpdateCustomFont (IdeApp.Preferences.CustomOutputPadFont);
 
152
                        UpdateCustomFont ();
91
153
                        IdeApp.Preferences.CustomOutputPadFontChanged += HandleCustomFontChanged;
92
154
                        
93
155
                        outputDispatcher = new GLib.TimeoutHandler (outputDispatchHandler);
94
156
                }
 
157
 
 
158
                [CommandHandler (Ide.Commands.EditCommands.Copy)]
 
159
                void CopyText ()
 
160
                {
 
161
                        TextIter start;
 
162
                        TextIter end;
 
163
                        if (buffer.HasSelection && buffer.GetSelectionBounds (out start, out end)) {
 
164
                                var text = buffer.GetText (start, end, false);
 
165
                                var clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
 
166
                                clipboard.Text = text;
 
167
 
 
168
                                clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
 
169
                                clipboard.Text = text;
 
170
                        }
 
171
                }
95
172
                
96
173
                public LogViewProgressMonitor GetProgressMonitor ()
97
174
                {
109
186
                        buffer.Clear();
110
187
                }
111
188
                
112
 
                void HandleCustomFontChanged (object sender, PropertyChangedEventArgs e)
 
189
                void HandleCustomFontChanged (object sender, EventArgs e)
113
190
                {
114
 
                        UpdateCustomFont ((string)e.NewValue);
 
191
                        UpdateCustomFont ();
115
192
                }
116
193
                
117
 
                void UpdateCustomFont (string name)
 
194
                void UpdateCustomFont ()
118
195
                {
119
 
                        if (customFont != null) {
120
 
                                customFont.Dispose ();
121
 
                                customFont = null;
122
 
                        }
123
 
                        if (!string.IsNullOrEmpty (name)) {
124
 
                                customFont = Pango.FontDescription.FromString (name);
125
 
                        }
126
 
                        textEditorControl.ModifyFont (customFont);
 
196
                        textEditorControl.ModifyFont (IdeApp.Preferences.CustomOutputPadFont ?? FontService.DefaultMonospaceFontDescription);
127
197
                }
128
198
                
129
199
                //mechanism to to batch copy text when large amounts are being dumped
281
351
                                lastTextWrite = null;
282
352
                        }
283
353
                        IdeApp.Preferences.CustomOutputPadFontChanged -= HandleCustomFontChanged;
284
 
                        if (customFont != null) {
285
 
                                customFont.Dispose ();
286
 
                                customFont = null;
287
 
                        }
288
354
                }
289
355
                
290
356
                private abstract class QueuedUpdate
447
513
                                return;
448
514
                        userWarned = true;
449
515
                        string title = GettextCatalog.GetString ("Console input not supported");
450
 
                        string desc = GettextCatalog.GetString ("Console input is not supported when using the MonoDevelop output console. If your applications needs to read data from the standard input, please set the 'Run in External Console' option in the project options.");
 
516
                        string desc = GettextCatalog.GetString (
 
517
                                "Console input is not supported when using the {0} output console. If your application needs to read " +
 
518
                                "data from the standard input, please set the 'Run in External Console' option in the project options.",
 
519
                                BrandingService.ApplicationName
 
520
                        );
451
521
                        MessageService.ShowWarning (title, desc);
452
522
                }
453
523