66
66
// bool canShowClassBrowser;
67
67
ISourceEditorOptions options {
69
return this.textEditor.Options;
69
return textEditor.Options;
73
bool isDisposed = false;
75
75
ParsedDocument parsedDocument;
77
readonly MonoDevelop.SourceEditor.ExtensibleTextEditor textEditor;
78
MonoDevelop.SourceEditor.ExtensibleTextEditor splittedTextEditor;
79
MonoDevelop.SourceEditor.ExtensibleTextEditor lastActiveEditor;
77
readonly ExtensibleTextEditor textEditor;
78
ExtensibleTextEditor splittedTextEditor;
79
ExtensibleTextEditor lastActiveEditor;
81
81
public MonoDevelop.SourceEditor.ExtensibleTextEditor TextEditor {
162
156
public Gtk.VBox Vbox {
163
157
get { return this.vbox; }
160
public bool SearchWidgetHasFocus {
162
if (HasAnyFocusedChild (searchAndReplaceWidget) || HasAnyFocusedChild (gotoLineNumberWidget))
168
static bool HasAnyFocusedChild (Widget widget)
170
// Seems that this is the only reliable way doing it on os x and linux :/
173
var stack = new Stack<Widget> ();
175
while (stack.Count > 0) {
176
var cur = stack.Pop ();
180
var c = cur as Gtk.Container;
182
foreach (var child in c.Children) {
166
190
public class Border : Gtk.DrawingArea
191
215
return scrolledWindow.Vadjustment;
195
219
public DecoratedScrolledWindow (SourceEditorWidget parent)
197
221
this.parent = parent;
198
222
this.strip = new QuickTaskStrip ();
200
Border border = new Border ();
201
border.HeightRequest = 1;
202
PackStart (border, false, true, 0);
204
HBox box = new HBox ();
206
border = new Border ();
207
border.WidthRequest = 1;
208
box.PackStart (border, false, true, 0);
210
scrolledWindow = new ScrolledWindow ();
211
scrolledWindow.BorderWidth = 0;
212
scrolledWindow.ShadowType = ShadowType.None;
213
scrolledWindow.ButtonPressEvent += PrepareEvent;
214
box.PackStart (scrolledWindow, true, true, 0);
217
border = new Border ();
218
border.WidthRequest = 1;
219
box.PackStart (border, false, true, 0);
221
PackStart (box, true, true, 0);
223
border = new Border ();
224
border.HeightRequest = 1;
225
PackStart (border, false, true, 0);*/
227
scrolledWindow = new SmartScrolledWindow ();
228
// scrolledWindow.BorderWidth = 0;
229
// scrolledWindow.ShadowType = ShadowType.In;
224
scrolledWindow = new CompactScrolledWindow ();
230
225
scrolledWindow.ButtonPressEvent += PrepareEvent;
231
226
PackStart (scrolledWindow, true, true, 0);
232
if (parent.quickTaskProvider.Count > 0) {
233
strip.VAdjustment = scrolledWindow.Vadjustment;
234
scrolledWindow.ReplaceVScrollBar (strip);
227
strip.VAdjustment = scrolledWindow.Vadjustment;
228
PackEnd (strip, false, true, 0);
230
parent.quickTaskProvider.ForEach (AddQuickTaskProvider);
232
QuickTaskStrip.EnableFancyFeatures.Changed += FancyFeaturesChanged;
233
FancyFeaturesChanged (null, null);
236
void FancyFeaturesChanged (object sender, EventArgs e)
238
if (QuickTaskStrip.EnableFancyFeatures) {
239
scrolledWindow.VScrollbar.SizeRequested += SuppressSize;
240
scrolledWindow.VScrollbar.ExposeEvent += SuppressExpose;
236
strip.Visible = false;
242
scrolledWindow.VScrollbar.SizeRequested -= SuppressSize;
243
scrolledWindow.VScrollbar.ExposeEvent -= SuppressExpose;
238
parent.quickTaskProvider.ForEach (p => AddQuickTaskProvider (p));
249
static void SuppressExpose (object o, ExposeEventArgs args)
255
static void SuppressSize (object o, SizeRequestedArgs args)
257
args.Requisition = Requisition.Zero;
241
261
public void AddQuickTaskProvider (IQuickTaskProvider p)
243
if (!strip.Visible) {
244
strip.VAdjustment = scrolledWindow.Vadjustment;
245
scrolledWindow.ReplaceVScrollBar (strip);
247
263
p.TasksUpdated += HandleTasksUpdated;
282
295
args.RetVal = true;
285
public void SetTextEditor (TextEditorContainer container)
298
public void SetTextEditor (TextEditor container)
287
300
scrolledWindow.Child = container;
288
this.strip.TextEditor = container.TextEditorWidget;
301
this.strip.TextEditor = container;
289
302
// container.TextEditorWidget.EditorOptionsChanged += OptionsChanged;
290
container.TextEditorWidget.Caret.ModeChanged += parent.UpdateLineColOnEventHandler;
291
container.TextEditorWidget.Caret.PositionChanged += parent.CaretPositionChanged;
292
container.TextEditorWidget.SelectionChanged += parent.UpdateLineColOnEventHandler;
303
container.Caret.ModeChanged += parent.UpdateLineColOnEventHandler;
304
container.Caret.PositionChanged += parent.CaretPositionChanged;
305
container.SelectionChanged += parent.UpdateLineColOnEventHandler;
295
308
void OptionsChanged (object sender, EventArgs e)
297
310
TextEditor editor = (TextEditor)sender;
298
scrolledWindow.ModifyBg (StateType.Normal, editor.ColorStyle.Default.BackgroundColor);
311
scrolledWindow.ModifyBg (StateType.Normal, (Mono.TextEditor.HslColor)editor.ColorStyle.PlainText.Background);
301
314
void RemoveEvents ()
303
TextEditorContainer container = scrolledWindow.Child as TextEditorContainer;
316
var container = scrolledWindow.Child as TextEditor;
304
317
if (container == null) {
305
318
LoggingService.LogError ("can't remove events from text editor container.");
308
321
// container.TextEditorWidget.EditorOptionsChanged -= OptionsChanged;
309
container.TextEditorWidget.Caret.ModeChanged -= parent.UpdateLineColOnEventHandler;
310
container.TextEditorWidget.Caret.PositionChanged -= parent.CaretPositionChanged;
311
container.TextEditorWidget.SelectionChanged -= parent.UpdateLineColOnEventHandler;
322
container.Caret.ModeChanged -= parent.UpdateLineColOnEventHandler;
323
container.Caret.PositionChanged -= parent.CaretPositionChanged;
324
container.SelectionChanged -= parent.UpdateLineColOnEventHandler;
314
public TextEditorContainer RemoveTextEditor ()
327
public TextEditor RemoveTextEditor ()
316
TextEditorContainer child = scrolledWindow.Child as TextEditorContainer;
329
var child = scrolledWindow.Child as TextEditor;
317
330
if (child == null)
326
TextEditorContainer textEditorContainer;
327
339
public SourceEditorWidget (SourceEditorView view)
329
341
this.view = view;
330
342
vbox.SetSizeRequest (32, 32);
331
343
this.lastActiveEditor = this.textEditor = new MonoDevelop.SourceEditor.ExtensibleTextEditor (view);
332
this.textEditor.FocusInEvent += (o, s) => lastActiveEditor = (ExtensibleTextEditor)o;
333
this.textEditor.FocusOutEvent += delegate {
334
if (this.splittedTextEditor == null || !splittedTextEditor.HasFocus)
344
this.textEditor.TextArea.FocusInEvent += (o, s) => {
345
lastActiveEditor = (ExtensibleTextEditor)((TextArea)o).GetTextEditorData ().Parent;
346
view.FireCompletionContextChanged ();
348
this.textEditor.TextArea.FocusOutEvent += delegate {
349
if (this.splittedTextEditor == null || !splittedTextEditor.TextArea.HasFocus)
337
352
mainsw = new DecoratedScrolledWindow (this);
338
this.textEditorContainer = new TextEditorContainer (textEditor);
339
mainsw.SetTextEditor (textEditorContainer);
353
mainsw.SetTextEditor (textEditor);
341
355
vbox.PackStart (mainsw, true, true, 0);
355
369
RemoveErrorUndelinesResetTimerId ();
356
370
StopParseInfoThread ();
373
foreach (var provider in quickTaskProvider.ToArray ()) {
374
RemoveQuickTaskProvider (provider);
359
377
this.lastActiveEditor = null;
360
378
this.splittedTextEditor = null;
363
IdeApp.Workbench.StatusBar.ClearCaretState ();
381
// IdeApp.Workbench.StatusBar.ClearCaretState ();
364
382
if (parseInformationUpdaterWorkerThread != null) {
365
383
parseInformationUpdaterWorkerThread.Dispose ();
366
384
parseInformationUpdaterWorkerThread = null;
722
729
secondsw = new DecoratedScrolledWindow (this);
723
this.splittedTextEditor = new MonoDevelop.SourceEditor.ExtensibleTextEditor (view, this.textEditor.Options, textEditor.Document);
724
this.splittedTextEditor.FocusInEvent += (o, s) => lastActiveEditor = (ExtensibleTextEditor)o;
725
this.splittedTextEditor.FocusOutEvent += delegate {
726
if (!textEditor.HasFocus)
730
splittedTextEditor = new MonoDevelop.SourceEditor.ExtensibleTextEditor (view, textEditor.Options, textEditor.Document);
731
splittedTextEditor.TextArea.FocusInEvent += (o, s) => {
732
lastActiveEditor = (ExtensibleTextEditor)((TextArea)o).GetTextEditorData ().Parent;
733
view.FireCompletionContextChanged ();
735
splittedTextEditor.TextArea.FocusOutEvent += delegate {
736
if (!textEditor.TextArea.HasFocus)
729
this.splittedTextEditor.Extension = textEditor.Extension;
731
this.splittedTextEditorContainer = new TextEditorContainer (this.splittedTextEditor);
732
secondsw.SetTextEditor (this.splittedTextEditorContainer);
739
splittedTextEditor.Extension = textEditor.Extension;
740
if (textEditor.GetTextEditorData ().HasIndentationTracker)
741
splittedTextEditor.GetTextEditorData ().IndentationTracker = textEditor.GetTextEditorData ().IndentationTracker;
742
splittedTextEditor.Document.BracketMatcher = textEditor.Document.BracketMatcher;
744
secondsw.SetTextEditor (splittedTextEditor);
733
745
splitContainer.Add2 (secondsw);
735
747
vbox.PackStart (splitContainer, true, true, 0);
736
this.splitContainer.Position = (vSplit ? vbox.Allocation.Height : vbox.Allocation.Width) / 2 - 1;
748
splitContainer.Position = (vSplit ? vbox.Allocation.Height : vbox.Allocation.Width) / 2 - 1;
739
751
secondsw.Vadjustment.Value = mainsw.Vadjustment.Value = vadjustment;
745
757
// destroy old scrolled window to work around Bug 526721 - When splitting window vertically,
746
758
// the slider under left split is not shown unitl window is resized
747
double vadjustment = this.mainsw.Vadjustment.Value;
748
double hadjustment = this.mainsw.Hadjustment.Value;
750
var removedTextEditor = this.mainsw.RemoveTextEditor ();
751
this.mainsw.Destroy ();
753
this.mainsw = new DecoratedScrolledWindow (this);
754
this.mainsw.SetTextEditor (removedTextEditor);
755
this.mainsw.Vadjustment.Value = vadjustment;
756
this.mainsw.Hadjustment.Value = hadjustment;
759
double vadjustment = mainsw.Vadjustment.Value;
760
double hadjustment = mainsw.Hadjustment.Value;
762
var removedTextEditor = mainsw.RemoveTextEditor ();
765
mainsw = new DecoratedScrolledWindow (this);
766
mainsw.SetTextEditor (removedTextEditor);
767
mainsw.Vadjustment.Value = vadjustment;
768
mainsw.Hadjustment.Value = hadjustment;
757
769
lastActiveEditor = textEditor;
787
799
if (messageBar == null) {
788
800
messageBar = new MonoDevelop.Components.InfoBar (MessageType.Warning);
789
801
messageBar.SetMessageLabel (GettextCatalog.GetString (
790
"<b>The file \"{0}\" has been changed outside of MonoDevelop.</b>\n" +
802
"<b>The file \"{0}\" has been changed outside of {1}.</b>\n" +
791
803
"Do you want to keep your changes, or reload the file from disk?",
792
EllipsizeMiddle (Document.FileName, 50)));
804
EllipsizeMiddle (Document.FileName, 50), BrandingService.ApplicationName));
794
806
var b1 = new Button (GettextCatalog.GetString ("_Reload from disk"));
795
807
b1.Image = ImageService.GetImage (Gtk.Stock.Refresh, IconSize.Button);
840
852
internal bool UseIncorrectMarkers { get; set; }
841
853
internal bool HasIncorrectEolMarker {
855
string eol = DetectedEolMarker;
858
return eol != textEditor.Options.DefaultEolMarker;
861
string DetectedEolMarker {
843
863
if (textEditor.IsDisposed) {
844
864
LoggingService.LogWarning ("SourceEditorWidget.cs: HasIncorrectEolMarker was called on disposed source editor widget." + Environment.NewLine + Environment.StackTrace);
847
867
var firstLine = Document.GetLine (1);
848
868
if (firstLine != null && firstLine.DelimiterLength > 0) {
849
869
string firstDelimiter = Document.GetTextAt (firstLine.Length, firstLine.DelimiterLength);
850
return firstDelimiter != textEditor.Options.DefaultEolMarker;
870
return firstDelimiter;
892
912
if (messageBar == null) {
893
913
messageBar = new MonoDevelop.Components.InfoBar (MessageType.Warning);
914
string detectedEol = DetectedEolMarker.Replace ("\n", "NL").Replace ("\r", "CR");
915
string defaultEol = textEditor.Options.DefaultEolMarker.Replace ("\n", "NL").Replace ("\r", "CR");
894
916
messageBar.SetMessageLabel (GettextCatalog.GetString (
895
"<b>The file \"{0}\" has line endings which differ from the policy settings.</b>\n" +
917
"<b>The file \"{0}\" has line endings (" + detectedEol + ") which differ from the policy settings(" + defaultEol + ").</b>\n" +
896
918
"Do you want to convert the line endings?",
897
919
EllipsizeMiddle (Document.FileName, 50)));
953
975
TextEditor.Visible = false;
954
976
if (messageBar == null) {
955
977
messageBar = new MonoDevelop.Components.InfoBar (MessageType.Warning);
956
messageBar.SetMessageLabel (GettextCatalog.GetString (
978
messageBar.SetMessageLabel (BrandingService.BrandApplicationName (GettextCatalog.GetString (
957
979
"<b>An autosave file has been found for this file.</b>\n" +
958
980
"This could mean that another instance of MonoDevelop is editing this " +
959
981
"file, or that MonoDevelop crashed with unsaved changes.\n\n" +
960
"Do you want to use the original file, or load from the autosave file?"));
982
"Do you want to use the original file, or load from the autosave file?")));
962
984
Button b1 = new Button (GettextCatalog.GetString("_Use original file"));
963
985
b1.Image = ImageService.GetImage (Gtk.Stock.Refresh, IconSize.Button);
1061
1083
internal void UpdateLineCol ()
1063
int offset = TextEditor.Caret.Offset;
1064
if (offset < 0 || offset > TextEditor.Document.TextLength)
1066
DocumentLocation location = TextEditor.LogicalToVisualLocation (TextEditor.Caret.Location);
1067
IdeApp.Workbench.StatusBar.ShowCaretState (TextEditor.Caret.Line,
1069
TextEditor.IsSomethingSelected ? TextEditor.SelectionRange.Length : 0,
1070
TextEditor.Caret.IsInInsertMode);
1085
// int offset = TextEditor.Caret.Offset;
1086
// if (offset < 0 || offset > TextEditor.Document.TextLength)
1088
// DocumentLocation location = TextEditor.LogicalToVisualLocation (TextEditor.Caret.Location);
1089
// IdeApp.Workbench.StatusBar.ShowCaretState (TextEditor.Caret.Line,
1091
// TextEditor.IsSomethingSelected ? TextEditor.SelectionRange.Length : 0,
1092
// TextEditor.Caret.IsInInsertMode);
1174
1196
searchAndReplaceWidgetFrame.Child = searchAndReplaceWidget = new SearchAndReplaceWidget (TextEditor, searchAndReplaceWidgetFrame);
1175
1197
searchAndReplaceWidget.Destroyed += (sender, e) => RemoveSearchWidget ();
1176
1198
searchAndReplaceWidgetFrame.ShowAll ();
1177
this.TextEditorContainer.AddAnimatedWidget (searchAndReplaceWidgetFrame, 300, Easing.ExponentialInOut, Blocking.Downstage, TextEditor.Allocation.Width - 400, -searchAndReplaceWidget.Allocation.Height);
1199
this.TextEditor.AddAnimatedWidget (searchAndReplaceWidgetFrame, 300, Mono.TextEditor.Theatrics.Easing.ExponentialInOut, Blocking.Downstage, TextEditor.Allocation.Width - 400, -searchAndReplaceWidget.Allocation.Height);
1178
1200
// this.PackEnd (searchAndReplaceWidget);
1179
1201
// this.SetChildPacking (searchAndReplaceWidget, false, false, CHILD_PADDING, PackType.End);
1180
1202
// searchAndReplaceWidget.ShowAll ();
1214
1236
gotoLineNumberWidgetFrame.Child = gotoLineNumberWidget = new GotoLineNumberWidget (textEditor, gotoLineNumberWidgetFrame);
1215
1237
gotoLineNumberWidget.Destroyed += (sender, e) => RemoveSearchWidget ();
1216
1238
gotoLineNumberWidgetFrame.ShowAll ();
1217
TextEditorContainer.AddAnimatedWidget (gotoLineNumberWidgetFrame, 300, Easing.ExponentialInOut, Mono.TextEditor.Theatrics.Blocking.Downstage, this.TextEditor.Allocation.Width - 400, -gotoLineNumberWidget.Allocation.Height);
1239
TextEditor.AddAnimatedWidget (gotoLineNumberWidgetFrame, 300, Mono.TextEditor.Theatrics.Easing.ExponentialInOut, Mono.TextEditor.Theatrics.Blocking.Downstage, this.TextEditor.Allocation.Width - 400, -gotoLineNumberWidget.Allocation.Height);
1219
1241
ResetFocusChain ();
1251
1273
void SetSearchPatternToSelection ()
1275
if (!TextEditor.IsSomethingSelected) {
1276
int start = textEditor.Caret.Offset;
1278
while (start - 1 >= 0 && DynamicAbbrevHandler.IsIdentifierPart (textEditor.GetCharAt (start - 1)))
1281
while (end < textEditor.Length && DynamicAbbrevHandler.IsIdentifierPart (textEditor.GetCharAt (end)))
1283
textEditor.Caret.Offset = end;
1284
TextEditor.SetSelection (start, end);
1253
1287
if (TextEditor.IsSomethingSelected) {
1254
1288
var pattern = FormatPatternToSelectionOption (TextEditor.SelectedText);
1256
TextEditor.SearchPattern = pattern;
1289
SearchAndReplaceOptions.SearchPattern = pattern;
1257
1290
SearchAndReplaceWidget.UpdateSearchHistory (TextEditor.SearchPattern);
1259
1292
if (searchAndReplaceWidget != null)
1297
1330
DomRegion region;
1298
1331
var res = TextEditor.GetLanguageItem (TextEditor.Caret.Offset, out region);
1332
if (res is UnknownIdentifierResolveResult) {
1333
var uir = (UnknownIdentifierResolveResult)res;
1334
IdeApp.HelpOperations.SearchHelpFor (uir.Identifier);
1338
if (res is UnknownMemberResolveResult) {
1339
var uir = (UnknownMemberResolveResult)res;
1340
IdeApp.HelpOperations.SearchHelpFor (uir.MemberName);
1299
1344
string url = HelpService.GetMonoDocHelpUrl (res);
1300
1345
if (url != null)
1301
1346
IdeApp.HelpOperations.ShowHelp (url);
1361
1406
string startLineText = Document.GetTextAt (startLine.Offset, startLine.Length);
1362
1407
string endLineText = Document.GetTextAt (endLine.Offset, endLine.Length);
1363
if (startLineText.StartsWith (blockStart) && endLineText.EndsWith (blockEnd)) {
1408
if (startLineText.StartsWith (blockStart) && endLineText.EndsWith (blockEnd, StringComparison.Ordinal)) {
1364
1409
textEditor.Remove (endLine.Offset + endLine.Length - blockEnd.Length, blockEnd.Length);
1365
1410
textEditor.Remove (startLine.Offset, blockStart.Length);
1366
1411
if (TextEditor.IsSomethingSelected) {
1589
1633
EndCol = Info.Region.BeginColumn + o - start + 1;
1637
public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
1639
Color = Info.ErrorType == ErrorType.Warning ? editor.ColorStyle.UnderlineWarning.Color : editor.ColorStyle.UnderlineError.Color;
1641
base.Draw (editor, cr, layout, selected, startOffset, endOffset, y, startXPos, endXPos);
b'\\ No newline at end of file'