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

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor/Gui/FoldMarkerMargin.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:
69
69
                        layout = PangoUtil.CreateLayout (editor);
70
70
                        editor.Caret.PositionChanged += HandleEditorCaretPositionChanged;
71
71
                        editor.Document.FoldTreeUpdated += HandleEditorDocumentFoldTreeUpdated;
 
72
                        this.editor.Caret.PositionChanged += EditorCarethandlePositionChanged;
 
73
                }
 
74
 
 
75
                void EditorCarethandlePositionChanged (object sender, DocumentLocationEventArgs e)
 
76
                {
 
77
                        if (!editor.Options.HighlightCaretLine || e.Location.Line == editor.Caret.Line)
 
78
                                return;
 
79
                        editor.RedrawMarginLine (this, e.Location.Line);
 
80
                        editor.RedrawMarginLine (this, editor.Caret.Line);
72
81
                }
73
82
 
74
83
                void HandleEditorDocumentFoldTreeUpdated (object sender, EventArgs e)
75
84
                {
76
85
                        editor.RedrawMargin (this);
77
86
                }
78
 
 
 
87
                
79
88
                void HandleEditorCaretPositionChanged (object sender, DocumentLocationEventArgs e)
80
89
                {
81
90
                        if (!IsInCodeFocusMode) 
159
168
                                RemoveBackgroundRenderer ();
160
169
                        }
161
170
                }
162
 
                
 
171
                List<FoldSegment> oldFolds;
163
172
                bool SetBackgroundRenderer ()
164
173
                {
 
174
                        List<FoldSegment> curFolds = new List<FoldSegment> (foldings);
 
175
                        if (oldFolds != null && oldFolds.Count == curFolds.Count) {
 
176
                                bool same = true;
 
177
                                for (int i = 0; i < curFolds.Count; i++) {
 
178
                                        if (oldFolds[i] != curFolds [i]) {
 
179
                                                same = false;
 
180
                                                break;
 
181
                                        }
 
182
                                }
 
183
 
 
184
                                if (same)
 
185
                                        return false;
 
186
                        }
 
187
 
 
188
                        oldFolds = curFolds;
165
189
                        editor.TextViewMargin.DisposeLayoutDict ();
166
190
                        editor.TextViewMargin.BackgroundRenderer = new FoldingScreenbackgroundRenderer (editor, foldings);
167
191
                        editor.QueueDraw ();
181
205
                IEnumerable<FoldSegment> foldings;
182
206
                void RemoveBackgroundRenderer ()
183
207
                {
 
208
                        oldFolds = null;
184
209
                        if (editor.TextViewMargin.BackgroundRenderer != null) {
185
210
                                editor.TextViewMargin.BackgroundRenderer = null;
186
211
                                editor.QueueDraw ();
201
226
                
202
227
                internal protected override void OptionsChanged ()
203
228
                {
204
 
                        foldBgGC = editor.ColorStyle.FoldLine.CairoBackgroundColor;
205
 
                        foldLineGC = editor.ColorStyle.FoldLine.CairoColor;
206
 
                        foldLineHighlightedGC = editor.ColorStyle.FoldLineHighlighted;
 
229
                        foldBgGC = editor.ColorStyle.PlainText.Background;
 
230
                        foldLineGC = editor.ColorStyle.FoldLineColor.Color;
 
231
                        foldLineHighlightedGC = editor.ColorStyle.PlainText.Foreground;
207
232
                        
208
 
                        HslColor hslColor = new HslColor (editor.ColorStyle.Default.CairoBackgroundColor);
 
233
                        HslColor hslColor = new HslColor (editor.ColorStyle.PlainText.Background);
209
234
                        double brightness = HslColor.Brightness (hslColor);
210
235
                        if (brightness < 0.5) {
211
236
                                hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25;
214
239
                        }
215
240
                        
216
241
                        foldLineHighlightedGCBg = hslColor;
217
 
                        foldToggleMarkerGC = editor.ColorStyle.FoldToggleMarker;
218
 
                        lineStateChangedGC = editor.ColorStyle.LineChangedBg;
219
 
                        lineStateDirtyGC = editor.ColorStyle.LineDirtyBg;
 
242
                        foldToggleMarkerGC = editor.ColorStyle.FoldCross.Color;
 
243
                        foldToggleMarkerBackground = editor.ColorStyle.FoldCross.SecondColor;
 
244
                        lineStateChangedGC = editor.ColorStyle.QuickDiffChanged.Color;
 
245
                        lineStateDirtyGC = editor.ColorStyle.QuickDiffDirty.Color;
220
246
                        
221
247
                        marginWidth = editor.LineHeight;
222
248
                }
223
249
                
224
 
                Cairo.Color foldBgGC, foldLineGC, foldLineHighlightedGC, foldLineHighlightedGCBg, foldToggleMarkerGC;
 
250
                Cairo.Color foldBgGC, foldLineGC, foldLineHighlightedGC, foldLineHighlightedGCBg, foldToggleMarkerGC, foldToggleMarkerBackground;
225
251
                Cairo.Color lineStateChangedGC, lineStateDirtyGC;
226
252
                
227
253
                public override void Dispose ()
231
257
                        editor.Document.FoldTreeUpdated -= HandleEditorDocumentFoldTreeUpdated;
232
258
                        layout = layout.Kill ();
233
259
                }
234
 
 
 
260
                
235
261
                void DrawFoldSegment (Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected)
236
262
                {
237
263
                        var drawArea = new Cairo.Rectangle (System.Math.Floor (x + (Width - foldSegmentSize) / 2) + 0.5, 
238
 
                                                                System.Math.Floor (y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);
 
264
                                                            System.Math.Floor (y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);
239
265
                        ctx.Rectangle (drawArea);
240
 
                        ctx.Color = foldBgGC;
 
266
                        ctx.Color = isOpen ? foldBgGC : foldToggleMarkerBackground;
241
267
                        ctx.FillPreserve ();
242
268
                        ctx.Color = isSelected ? foldLineHighlightedGC  : foldLineGC;
243
269
                        ctx.Stroke ();
244
 
 
245
 
                        ctx.DrawLine (foldToggleMarkerGC,
 
270
                        
 
271
                        ctx.DrawLine (isSelected ? foldLineHighlightedGC  : foldToggleMarkerGC,
246
272
                                      drawArea.X  + drawArea.Width * 2 / 10,
247
273
                                      drawArea.Y + drawArea.Height / 2,
248
274
                                      drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
249
275
                                      drawArea.Y + drawArea.Height / 2);
250
 
 
 
276
                        
251
277
                        if (!isOpen)
252
 
                                ctx.DrawLine (foldToggleMarkerGC,
 
278
                                ctx.DrawLine (isSelected ? foldLineHighlightedGC  : foldToggleMarkerGC,
253
279
                                              drawArea.X + drawArea.Width / 2,
254
280
                                              drawArea.Y + drawArea.Height * 2 / 10,
255
281
                                              drawArea.X  + drawArea.Width / 2,
281
307
                        bool isContainingSelected = false;
282
308
                        bool isEndSelected = false;
283
309
                        
284
 
                        if (line <= editor.Document.LineCount) {
 
310
                        if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount) {
285
311
                                startFoldings.Clear ();
286
312
                                containingFoldings.Clear ();
287
313
                                endFoldings.Clear ();
295
321
                                        }
296
322
                                }
297
323
                                
298
 
                                isFoldStart  = startFoldings.Count > 0;
 
324
                                isFoldStart = startFoldings.Count > 0;
299
325
                                isContaining = containingFoldings.Count > 0;
300
 
                                isFoldEnd    = endFoldings.Count > 0;
 
326
                                isFoldEnd = endFoldings.Count > 0;
301
327
                                
302
 
                                isStartSelected      = this.lineHover != null && IsMouseHover (startFoldings);
 
328
                                isStartSelected = this.lineHover != null && IsMouseHover (startFoldings);
303
329
                                isContainingSelected = this.lineHover != null && IsMouseHover (containingFoldings);
304
 
                                isEndSelected        = this.lineHover != null && IsMouseHover (endFoldings);
305
 
                        }
306
 
                        
307
 
                        var bgGC = foldBgGC;
308
 
                        if (editor.TextViewMargin.BackgroundRenderer != null) {
309
 
                                if (isContainingSelected || isStartSelected || isEndSelected) {
310
 
                                        bgGC = foldBgGC;
311
 
                                } else {
312
 
                                        bgGC = foldLineHighlightedGCBg;
313
 
                                }
314
 
                        }
315
 
                        
316
 
                        cr.Rectangle (drawArea);
317
 
                        cr.Color = bgGC;
318
 
                        cr.Fill ();
319
 
                        
320
 
                        if (state == TextDocument.LineState.Changed) {
321
 
                                cr.Color = lineStateChangedGC;
322
 
                                cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
323
 
                                cr.Fill ();
324
 
                        } else if (state == TextDocument.LineState.Dirty) {
325
 
                                cr.Color = lineStateDirtyGC;
326
 
                                cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
327
 
                                cr.Fill ();
328
 
                        }
329
 
                        
330
 
                        if (line < editor.Document.LineCount) {
 
330
                                isEndSelected = this.lineHover != null && IsMouseHover (endFoldings);
 
331
                        }
 
332
 
 
333
                        if (editor.Options.HighlightCaretLine && editor.Caret.Line == line) {
 
334
                                editor.TextViewMargin.DrawCaretLineMarker (cr, x, y, Width, lineHeight);
 
335
                        } else {
 
336
                                var bgGC = foldBgGC;
 
337
                                if (editor.TextViewMargin.BackgroundRenderer != null) {
 
338
                                        if (isContainingSelected || isStartSelected || isEndSelected) {
 
339
                                                bgGC = foldBgGC;
 
340
                                        } else {
 
341
                                                bgGC = foldLineHighlightedGCBg;
 
342
                                        }
 
343
                                }
 
344
                                
 
345
                                cr.Rectangle (drawArea);
 
346
                                cr.Color = bgGC;
 
347
                                cr.Fill ();
 
348
                        }
 
349
 
 
350
                        if (editor.Options.EnableQuickDiff) {
 
351
                                if (state == TextDocument.LineState.Changed) {
 
352
                                        cr.Color = lineStateChangedGC;
 
353
                                        cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
 
354
                                        cr.Fill ();
 
355
                                } else if (state == TextDocument.LineState.Dirty) {
 
356
                                        cr.Color = lineStateDirtyGC;
 
357
                                        cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
 
358
                                        cr.Fill ();
 
359
                                }
 
360
                        }
 
361
 
 
362
                        if (editor.Options.ShowFoldMargin && line < editor.Document.LineCount) {
331
363
                                double foldSegmentYPos = y + System.Math.Floor (editor.LineHeight - foldSegmentSize) / 2;
332
364
                                double xPos = x + System.Math.Floor (marginWidth / 2) + 0.5;
333
365
                                
347
379
                                                        isFoldEndFromUpperFold = true;
348
380
                                        }
349
381
                                        DrawFoldSegment (cr, x, y, isVisible, isStartSelected);
350
 
 
 
382
                                        
351
383
                                        if (isContaining || isFoldEndFromUpperFold)
352
384
                                                cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, foldSegmentYPos - 2);
353
385
                                        if (isContaining || moreLinedOpenFold) 
354
386
                                                cr.DrawLine (isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Y + drawArea.Height);
355
387
                                } else {
356
 
 
 
388
                                        
357
389
                                        if (isFoldEnd) {
358
 
 
359
 
                                                double yMid = drawArea.Y + drawArea.Height / 2;
 
390
                                                
 
391
                                                double yMid = System.Math.Floor (drawArea.Y + drawArea.Height / 2) + 0.5;
360
392
                                                cr.DrawLine (isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + marginWidth - 2, yMid);
361
393
                                                cr.DrawLine (isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, yMid);
362
 
 
 
394
                                                
363
395
                                                if (isContaining) 
364
 
                                                        cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid + 1, xPos, drawArea.Y + drawArea.Height);
 
396
                                                        cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos, drawArea.Y + drawArea.Height);
365
397
                                        } else if (isContaining) {
366
398
                                                cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);
367
399
                                        }
368
 
 
 
400
                                        
369
401
                                }
370
402
                        }
371
403
                }