</HorizontalStack>
</Border>
</ItemTemplate>
- <ItemTemplate DataType="System.IO.DirectoryInfo" Data="GetFileSystemInfos">
+ <ItemTemplate DataType="System.IO.DirectoryInfo" Data="GetFileSystemInfosOrdered">
<Expandable Caption="{Name}" MouseDoubleClick="/onClickForExpand">
<Template>
<VerticalStack>
gr.Save();
r.Inflate((int)-width / 2, (int)-width / 2);
gr.LineWidth = width;
- gr.SetSourceColor(Colors.White);
+ gr.SetSource(Colors.White);
gr.MoveTo(r.BottomLeft);
gr.LineTo(r.TopLeft);
gr.LineTo(r.TopRight);
gr.Stroke();
- gr.SetSourceColor(Colors.DarkGrey);
+ gr.SetSource(Colors.DarkGrey);
gr.MoveTo(r.TopRight);
gr.LineTo(r.BottomRight);
gr.LineTo(r.BottomLeft);
gr.Save();
r.Inflate((int)-width / 2, (int)-width / 2);
gr.LineWidth = width;
- gr.SetSourceColor(Colors.DarkGrey);
+ gr.SetSource(Colors.DarkGrey);
gr.MoveTo(r.BottomLeft);
gr.LineTo(r.TopLeft);
gr.LineTo(r.TopRight);
gr.Stroke();
- gr.SetSourceColor(Colors.White);
+ gr.SetSource(Colors.White);
gr.MoveTo(r.TopRight);
gr.LineTo(r.BottomRight);
gr.LineTo(r.BottomLeft);
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
+using System.IO;
+using System.Linq;
using System.Linq.Expressions;
namespace Crow
ctx.Stroke ();
}
- public static void SetSourceColor(this Cairo.Context ctx, Color c)
- {
- ctx.SetSourceRGBA(c.R,c.G,c.B,c.A);
- }
public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c)
{
grad.AddColorStop (offset, c);
return null;
}
+
+ public static FileSystemInfo [] GetFileSystemInfosOrdered (this DirectoryInfo di)
+ => di.GetFileSystemInfos ().OrderBy (f => f.Attributes).ThenBy (f => f.Name).ToArray ();
}
}
//System.Diagnostics.Debug.WriteLine ($"*** search extension method: {t};{methodName} => key={key}");
MethodInfo mi = null;
- mi = GetExtensionMethods (Assembly.GetEntryAssembly (), t, methodName);
- if (mi == null)
- mi = GetExtensionMethods (t.Module.Assembly, t, methodName);
+ if (!TryGetExtensionMethods (Assembly.GetEntryAssembly (), t, methodName, out mi)) {
+ if (!TryGetExtensionMethods (t.Module.Assembly, t, methodName, out mi)) {
+ foreach (Assembly a in Interface.crowAssemblies) {
+ if (TryGetExtensionMethods (a, t, methodName, out mi))
+ break;
+ }
+ if (mi == null)
+ TryGetExtensionMethods (Assembly.GetExecutingAssembly (), t, methodName, out mi);//crow Assembly
+ }
+ }
//add key even if mi is null to prevent searching again and again for propertyless bindings
knownExtMethods.Add (key, mi);
return mi;
}
- public static MethodInfo GetExtensionMethods (Assembly assembly, Type extendedType, string methodName)
+ public static bool TryGetExtensionMethods (Assembly assembly, Type extendedType, string methodName, out MethodInfo foundMI)
{
+ foundMI = null;
if (assembly == null)
- return null;
+ return false;
foreach (Type t in assembly.GetTypes ().Where
(ty => ty.IsDefined (typeof (ExtensionAttribute), false))) {
foreach (MethodInfo mi in t.GetMethods
m.GetParameters ().Length == 1)) {
Type curType = extendedType;
while (curType != null) {
- if (mi.GetParameters () [0].ParameterType == curType)
- return mi;
+ if (mi.GetParameters () [0].ParameterType == curType) {
+ foundMI = mi;
+ return true;
+ }
curType = curType.BaseType;
}
}
}
- return null;
+ return false;
}
/// <summary>
/// retrieve event handler in class or ancestors
Type t = Address.LastOrDefault ().CrowType;
member = t.GetMember (memberName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault ();
-#region search for extensions methods if member not found in type
- if (member == null && !string.IsNullOrEmpty (memberName)) {
- Assembly a = Assembly.GetExecutingAssembly ();
- string mn = memberName;
- member = CompilerServices.GetExtensionMethods (a, t, mn);
- }
-#endregion
+ if (member == null && !string.IsNullOrEmpty (memberName))
+ member = CompilerServices.SearchExtMethod (t, memberName);
return member != null;
}
get { return NativeMethods.cairo_get_reference_count (handle); }
}
- public void SetSourceColor (Color color)
+ public void SetSource (Color color)
{
NativeMethods.cairo_set_source_rgba (handle, color.R / 255.0, color.G / 255.0, color.B / 255.0, color.A / 255.0);
}
double radius = CornerRadius;
if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0))
radius = Math.Min (rBack.Height / 2.0, rBack.Width / 2.0);
- gr.SetSourceColor (sunkenColor);
+ gr.SetSource (sunkenColor);
gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius);
gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75);
gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius);
gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI / 2.0, Math.PI * 0.75);
gr.Stroke ();
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius);
gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75);
gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius);
gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75);
} else {
gr.Stroke ();
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
}
gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius);
gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25);
gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75);
gr.Stroke ();
} else {
- gr.SetSourceColor (sunkenColor);
+ gr.SetSource (sunkenColor);
gr.MoveTo (0.5 + rBack.Left, rBack.Bottom);
gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Y);
gr.LineTo (rBack.Right, 0.5 + rBack.Y);
gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom);
gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom);
gr.Stroke ();
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom);
gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y);
gr.LineTo (rBack.Right, 1.5 + rBack.Y);
} else {
gr.Stroke ();
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
}
gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y);
gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom);
Foreground.SetAsSource (gr, rBack);
else {
if (BorderStyle == BorderStyle.Sunken)
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
else
- gr.SetSourceColor (sunkenColor);
+ gr.SetSource (sunkenColor);
CairoHelpers.CairoRectangle (gr, rBack, crad, bw);
if (BorderStyle == BorderStyle.Sunken)
- gr.SetSourceColor (sunkenColor);
+ gr.SetSource (sunkenColor);
else
- gr.SetSourceColor (raisedColor);
+ gr.SetSource (raisedColor);
bw /= 2.0;
rBack.Width -= (int)Math.Round(bw);
break;
}
- gr.SetSourceColor (Colors.Black);
+ gr.SetSource (Colors.Black);
gr.LineWidth = 2.0;
gr.StrokePreserve ();
- gr.SetSourceColor (Colors.White);
+ gr.SetSource (Colors.White);
gr.LineWidth = 1.0;
gr.Stroke ();
}
if (showFiles && !string.IsNullOrEmpty(fileMask))
fi.AddRange(di.GetFiles(fileMask));
return showHidden ?
- fi.ToArray() :
- fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).ToArray();
+ fi.OrderBy(f=>f.Attributes).ThenBy(f=>f.Name).ToArray() :
+ fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).OrderBy (f => f.Attributes).ThenBy (f => f.Name).ToArray();
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine (ex.ToString ());
return null;
-//
-// FileDialog.cs
+// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// 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.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
-using System.Xml.Serialization;
using System.ComponentModel;
using System.IO;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text.RegularExpressions;
namespace Crow
{
break;
}
- gr.SetSourceColor (Colors.Black);
+ gr.SetSource (Colors.Black);
gr.LineWidth = 2.0;
gr.StrokePreserve ();
- gr.SetSourceColor (Colors.White);
+ gr.SetSource (Colors.White);
gr.LineWidth = 1.0;
gr.Stroke ();
}
else
_currentCol = value;
NotifyValueChanged ("CurrentColumn", _currentCol);
+
+ Rectangle cb = ClientRectangle;
+
+ if (Width == Measure.Fit || cb.Width >= cachedTextSize.Width) {
+ xTranslation = 0;
+ return;
+ }
+ int xpos = xposition;
+ if (xTranslation + xpos > cb.Width)
+ xTranslation = cb.Width - xpos;
+ else if (xpos < -xTranslation)
+ xTranslation = -xpos;
+ RegisterForRedraw ();
}
}
+ int xTranslation = 0;
+ int xposition {
+ get {
+ using (Context gr = new Context (IFace.surf)) {
+ //Cairo.FontFace cf = gr.GetContextFontFace ();
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
+ gr.FontOptions = Interface.FontRenderingOptions;
+ gr.Antialias = Interface.Antialias;
+ try {
+ string l = lines [_currentLine];
+ if (_currentCol < l.Length)
+ l = l.Remove (Math.Min (_currentCol, l.Length));
+ l = l.Replace ("\t", new String (' ', Interface.TAB_SIZE));
+ return (int)Math.Ceiling (gr.TextExtents (l).XAdvance);
+ } catch {
+ System.Diagnostics.Debug.WriteLine ("xpos measuring fault in label");
+ return 0;
+ }
+ }
+ }
+ }
+
[DefaultValue(0)]
public int CurrentLine{
get { return _currentLine; }
[XmlIgnore]public string SelectedText
{
get {
-
if (SelRelease < 0 || SelBegin < 0)
return "";
if (selectionStart.Y == selectionEnd.Y)
gr.FontOptions = Interface.FontRenderingOptions;
gr.Antialias = Interface.Antialias;
+ gr.Save ();
+ gr.Translate (xTranslation, 0);
+
rText = new Rectangle(new Size(
measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height)));
rText.Width -= 2 * Margin;
if (Selectable) {
if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
- gr.SetSourceColor (selBackground);
+ gr.SetSource (selBackground);
Rectangle selRect = lineRect;
gr.FillPreserve ();
gr.Save ();
gr.Clip ();
- gr.SetSourceColor (SelectionForeground);
+ gr.SetSource (SelectionForeground);
gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i);
gr.ShowText (l);
gr.Fill ();
}
}
}
+
+ gr.Restore ();
}
#endregion
#region Mouse handling
void updatemouseLocalPos(Point mpos){
mouseLocalPos = mpos - ScreenCoordinates(Slot).TopLeft - ClientRectangle.TopLeft;
+ mouseLocalPos.X -= xTranslation;
if (mouseLocalPos.X < 0)
mouseLocalPos.X = 0;
if (mouseLocalPos.Y < 0)
gr.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0);
- gr.SetSourceColor (Colors.Black);
+ gr.SetSource (Colors.Black);
gr.LineWidth = 2.0;
gr.StrokePreserve ();
- gr.SetSourceColor (Colors.White);
+ gr.SetSource (Colors.White);
gr.LineWidth = 1.0;
gr.Stroke ();
}
#region CTOR
protected TextBox() {}
public TextBox(Interface iface, string style = null) : base (iface, style) { }
-// public TextBox(string _initialValue)
-// : base(_initialValue)
-// {
-//
-// }
#endregion
#region GraphicObject overrides
protected override void onDraw (Context gr)
{
base.onDraw (gr);
- FontExtents fe = gr.FontExtents;
}
#endregion
#region Keyboard handling
public override void onKeyDown (object sender, KeyEventArgs e)
{
- base.onKeyDown (sender, e);
-
Key key = e.Key;
switch (key)
default:
break;
}
-
- RegisterForGraphicUpdate();
+ e.Handled = true;
+ base.onKeyDown (sender, e);
+ RegisterForGraphicUpdate ();
}
public override void onKeyPress (object sender, KeyPressEventArgs e)
{
NotifyValueChanged ("CurrentDir",CurrentDir);
}
}
+ public void goUpDirClick (object sender, MouseButtonEventArgs e)
+ {
+ string root = Directory.GetDirectoryRoot (CurrentDir);
+ if (CurrentDir == root)
+ return;
+ CurrentDir = Directory.GetParent (CurrentDir).FullName;
+ }
protected override void OnInitialized ()
{
<?xml version="1.0"?>
<HorizontalStack Background="DarkGrey" Margin="2">
- <DirectoryView Name="dv" CurrentDirectory="Interfaces" Width="25%" SelectedItemChanged="Dv_SelectedItemChanged"/>
+ <VerticalStack Width="25%">
+ <HorizontalStack Height="Fit">
+ <Image Margin="2" Width="14" Height="14" Path="#Crow.Icons.level-up.svg" MouseClick="./goUpDirClick"/>
+ <TextBox Text="{²CurrentDir}" Margin="2"/>
+ </HorizontalStack>
+ <DirectoryView Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/>
+ </VerticalStack>
<Splitter Width="6"/>
<VerticalStack>
<Container Name="CrowContainer" Height="60%" Background="Black"/>