Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4587 from mono/master-issue4566
Browse files Browse the repository at this point in the history
Fixes issue #4566 Enabling code folding by default
  • Loading branch information
mhutch committed Apr 26, 2018
2 parents bd2f7a4 + 2fe14ec commit 0ddb16e
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ class Actor<T>
private double percent;
private bool can_expire = true;

public Actor (T target, uint duration)
public Actor (T target, uint duration, double percent)
{
this.target = target;
this.duration = duration;
this.percent = percent;
Reset ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public Actor<T> Add (T target)
}
}

public Actor<T> Add (T target, uint duration)
public Actor<T> Add (T target, uint duration, double percent = 1.0)
{
lock (this) {
if (Contains (target)) {
throw new InvalidOperationException ("Stage already contains this actor");
}

Actor<T> actor = new Actor<T> (target, duration);
Actor<T> actor = new Actor<T> (target, duration, percent);
actors.Add (target, actor);

CheckTimeout ();
Expand Down Expand Up @@ -231,7 +231,7 @@ public void Pause ()
}
}

public void Exeunt ()
public void Exeunt ()
{
lock (this) {
actors.Clear ();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// FoldMarkerMargin.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

using System.Linq;
using System.Collections.Generic;
using Cairo;
using MonoDevelop.Components;
using MonoDevelop.Ide.Editor.Highlighting;

namespace Mono.TextEditor
{
partial class FoldMarkerMargin
{
abstract class FoldMarkerMarginDrawer
{
readonly FoldMarkerMargin margin;

public FoldMarkerMargin Margin => margin;
public MonoTextEditor Editor => margin.editor;
public abstract bool AutoHide { get; }
public double FoldMarkerOcapitiy { get; set; }

protected FoldMarkerMarginDrawer (FoldMarkerMargin margin)
{
this.margin = margin;
}

public abstract void OptionsChanged ();

public abstract void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight);

protected MarginMarker GetMarginMarker (DocumentLine line)
{
if (line != null) {
foreach (var m in Editor.Document.GetMarkers (line)) {
var mm = m as MarginMarker;
if (mm != null && mm.CanDraw (Margin)) {
return mm;
}
}
}
return null;
}

protected bool IsMouseHover (IEnumerable<FoldSegment> foldings)
{
return foldings.Any (s => Margin.lineHover == s.GetStartLine (Editor.Document));
}
}

abstract class LineStateFoldMarkerMarginDrawer : FoldMarkerMarginDrawer
{
Color lineStateChangedGC, lineStateDirtyGC, backgroundColor;

protected LineStateFoldMarkerMarginDrawer (FoldMarkerMargin margin) : base (margin)
{
}

public override void OptionsChanged ()
{
lineStateChangedGC = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.QuickDiffChanged);
lineStateDirtyGC = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.QuickDiffDirty);
backgroundColor = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.Background);
}

public override void Draw (Context cr, Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight)
{
MarginMarker marker = GetMarginMarker (line);
bool hasDrawn = false;
if (marker != null) {
hasDrawn = marker.DrawBackground (Editor, cr, new MarginDrawMetrics (Margin, area, line, lineNumber, x, y, lineHeight));
}

if (!hasDrawn) {
if (Editor.GetTextEditorData ().HighlightCaretLine && Editor.Caret.Line == lineNumber) {
Editor.TextViewMargin.DrawCaretLineMarker (cr, x, y, Margin.Width, lineHeight);
} else {
cr.Rectangle (x, y, Margin.Width, lineHeight);
cr.SetSourceColor (backgroundColor);
cr.Fill ();
}
}

var state = Editor.Document.GetLineState (line);

if (Editor.Options.EnableQuickDiff && state != TextDocument.LineState.Unchanged) {
var prevState = line?.PreviousLine != null ? Editor.Document.GetLineState (line.PreviousLine) : TextDocument.LineState.Unchanged;
var nextState = line?.NextLine != null ? Editor.Document.GetLineState (line.NextLine) : TextDocument.LineState.Unchanged;

if (state == TextDocument.LineState.Changed) {
cr.SetSourceColor (lineStateChangedGC);
} else if (state == TextDocument.LineState.Dirty) {
cr.SetSourceColor (lineStateDirtyGC);
}

if ((prevState == TextDocument.LineState.Unchanged && prevState != state ||
nextState == TextDocument.LineState.Unchanged && nextState != state)) {
FoldingScreenbackgroundRenderer.DrawRoundRectangle (
cr,
prevState == TextDocument.LineState.Unchanged,
nextState == TextDocument.LineState.Unchanged,
x + 1,
y,
lineHeight / 4,
Margin.Width / 4,
lineHeight
);
} else {
cr.Rectangle (x + 1, y, Margin.Width / 4, lineHeight);
}
cr.Fill ();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// FoldMarkerMargin.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

using System.Linq;
using System.Collections.Generic;
using Cairo;
using MonoDevelop.Components;
using MonoDevelop.Ide.Editor.Highlighting;
using System.Runtime.InteropServices.ComTypes;
using Mono.TextEditor.Theatrics;

namespace Mono.TextEditor
{
partial class FoldMarkerMargin
{
sealed class VSCodeFoldMarkerMarginDrawer : LineStateFoldMarkerMarginDrawer
{
double foldSegmentSize = 8;
Color background, foreground, foldLine;

List<FoldSegment> startFoldings = new List<FoldSegment> ();

public override bool AutoHide { get => true; }

internal VSCodeFoldMarkerMarginDrawer (FoldMarkerMargin margin) : base (margin)
{
}

public override void OptionsChanged ()
{
base.OptionsChanged ();
background = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.Background);
foreground = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.Foreground);
foldLine = SyntaxHighlightingService.GetColor (Editor.EditorTheme, EditorThemeColors.FoldLine);
}

public override void Draw (Context cr, Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight)
{
base.Draw (cr, area, line, lineNumber, x, y, lineHeight);
if (!Editor.Options.ShowFoldMargin || lineNumber > Editor.Document.LineCount || line == null)
return;

foldSegmentSize = Margin.Width * 4 / 6;
foldSegmentSize -= (foldSegmentSize) % 2;

startFoldings.Clear ();

foreach (var segment in Editor.Document.GetFoldingContaining (line)) {
if (segment.GetStartLine (Editor.Document)?.Offset == line.Offset)
startFoldings.Add (segment);
}
if (startFoldings.Count == 0)
return;

bool isCollapsed = false;

foreach (var foldSegment in startFoldings) {
if (foldSegment.IsCollapsed) {
isCollapsed = true;
break;
}
}

if (!isCollapsed && FoldMarkerOcapitiy <= 0)
return;
DrawFoldSegment (cr, x, y, isCollapsed);
}

void DrawFoldSegment (Cairo.Context ctx, double x, double y, bool isCollapsed)
{
var drawArea = new Cairo.Rectangle (System.Math.Floor (x + (Margin.Width - foldSegmentSize) / 2) + 0.5,
System.Math.Floor (y + (Editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);
ctx.Rectangle (drawArea);
var useSolidColor = isCollapsed || FoldMarkerOcapitiy >= 1;
var drawColor = background;
if (!useSolidColor)
drawColor.A = FoldMarkerOcapitiy;

ctx.SetSourceColor (drawColor);
ctx.FillPreserve ();

drawColor = foldLine;
if (!useSolidColor)
drawColor.A = FoldMarkerOcapitiy;

ctx.SetSourceColor (drawColor);
ctx.Stroke ();

drawColor = foreground;
if (!useSolidColor)
drawColor.A = FoldMarkerOcapitiy;

ctx.DrawLine (drawColor,
drawArea.X + drawArea.Width * 2 / 10,
drawArea.Y + drawArea.Height / 2,
drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
drawArea.Y + drawArea.Height / 2);

if (isCollapsed)
ctx.DrawLine (drawColor,
drawArea.X + drawArea.Width / 2,
drawArea.Y + drawArea.Height * 2 / 10,
drawArea.X + drawArea.Width / 2,
drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10);
}
}

}
}
Loading

0 comments on commit 0ddb16e

Please sign in to comment.