Skip to content

Commit

Permalink
v 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SioGabx committed Apr 25, 2023
1 parent dc33431 commit 82dbf66
Show file tree
Hide file tree
Showing 40 changed files with 2,455 additions and 1,257 deletions.
75 changes: 42 additions & 33 deletions MapsInMyFolder.Common/Collectif.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Jint;
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -17,9 +15,11 @@
using System.Windows.Media;
using System.Text.RegularExpressions;
using System.Windows.Media.Animation;
using System.Windows.Input;
using MapsInMyFolder.Commun;
using Newtonsoft.Json;
using NetVips;
using System.Windows.Input;
using Jint;

namespace MapsInMyFolder.Commun
{
Expand Down Expand Up @@ -211,6 +211,7 @@ public static List<Url_class> GetListOfUrlFromLocation(Dictionary<string, double
}
}


public static DoubleAnimation GetOpacityAnimation(int toValue, double durationMultiplicator = 1)
{
return new DoubleAnimation(toValue, TimeSpan.FromMilliseconds((long)(Settings.animations_duration_millisecond * durationMultiplicator)))
Expand Down Expand Up @@ -297,7 +298,7 @@ public static SolidColorBrush HexValueToSolidColorBrush(string hexvalue, string
{
return HexValueToSolidColorBrush(defaulthexvalue);
}

}

public static SolidColorBrush RgbValueToSolidColorBrush(int R, int G, int B)
Expand Down Expand Up @@ -463,7 +464,7 @@ public static byte[] GetEmptyImageBufferFromText(string BitmapErrorsMessage)
int offsetY = (int)Math.Floor((double)(border_tile_size - text.Height) / 2);
using (NetVips.Image image = NetVips.Image.Black(border_tile_size, border_tile_size).Linear(color, color).Composite2(text, NetVips.Enums.BlendMode.Atop, offsetX, offsetY))
{
return image.Gravity(Enums.CompassDirection.Centre, tile_size, tile_size, Enums.Extend.Black).WriteToBuffer("." + format, saveVOption); ;
return image.Gravity(Enums.CompassDirection.Centre, tile_size, tile_size, Enums.Extend.Black).WriteToBuffer("." + format, saveVOption); ;
}
}
}
Expand All @@ -487,7 +488,7 @@ public static string FormatBytes(long bytes)
return String.Format("{0:0} {1}", dblSByte, Suffix[i]);
}

public static VOption getSaveVOption(string final_saveformat, int quality, int tile_size)
public static VOption getSaveVOption(string final_saveformat, int quality, int? tile_size)
{
if (quality <= 0)
{
Expand Down Expand Up @@ -793,7 +794,7 @@ public static void InsertTextAtCaretPosition(ICSharpCode.AvalonEdit.TextEditor T
{
int CaretIndex = TextBox.CaretOffset;
TextBox.TextArea.Document.Insert(CaretIndex, text);

TextBox.CaretOffset = CaretIndex + text.Length;
}
else
Expand All @@ -802,32 +803,25 @@ public static void InsertTextAtCaretPosition(ICSharpCode.AvalonEdit.TextEditor T
TextBox.CaretOffset += TextBox.SelectedText.Length;
TextBox.SelectionLength = 0;
}

//int lineIndex = TextBox.GetLineIndexFromCharacterIndex(TextBox.CaretIndex);
//TextBox.ScrollToLine(lineIndex);
}

public static void TextEditorCursorPositionChanged(ICSharpCode.AvalonEdit.TextEditor textEditor, Grid grid, ScrollViewer scrollViewer, int MarginTop = 25)
{
if (Mouse.LeftButton == MouseButtonState.Pressed) { return; }


double Margin = 40;
double Margin = 40;

double TextboxLayerScriptTopPosition = textEditor.TranslatePoint(new Point(0, 0), grid).Y;
double TextboxLayerScriptCaretTopPosition = textEditor.TextArea.Caret.CalculateCaretRectangle().Top + TextboxLayerScriptTopPosition;
if (TextboxLayerScriptCaretTopPosition > (grid.ActualHeight - Margin))
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + (TextboxLayerScriptCaretTopPosition - (grid.ActualHeight - Margin)));
Debug.WriteLine("Scroll down");
return;
}else if (TextboxLayerScriptCaretTopPosition < MarginTop)
}
else if (TextboxLayerScriptCaretTopPosition < MarginTop)
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - Math.Abs((MarginTop) - TextboxLayerScriptCaretTopPosition));
Debug.WriteLine("Scroll up");
return;
}
// e.
Debug.WriteLine($"-----\nEditeurScrollBar.VerticalOffset : {scrollViewer.VerticalOffset}\nTextboxLayerScript.TextArea.Caret :{textEditor.TextArea.Caret.CalculateCaretRectangle().Top}\nTextboxLayerScript.ActualHeight :{textEditor.ActualHeight}\nTextboxLayerScriptCaretTopPosition : {TextboxLayerScriptCaretTopPosition}\nEditeurGrid.ActualHeight : {grid.ActualHeight}\nTextboxLayerScriptTopPosition : {TextboxLayerScriptTopPosition}");
}

public static void IndenterCode(object sender, EventArgs e, ICSharpCode.AvalonEdit.TextEditor textBox)
Expand Down Expand Up @@ -872,9 +866,11 @@ public static List<UIElement> FindVisualChildren(UIElement obj, List<System.Type
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
UIElement objChild;
try {
objChild = (UIElement)VisualTreeHelper.GetChild(obj, i);
}catch(InvalidCastException)
try
{
objChild = (UIElement)VisualTreeHelper.GetChild(obj, i);
}
catch (InvalidCastException)
{
//Unable to cast object to type 'System.Windows.UIElement'
continue;
Expand Down Expand Up @@ -949,17 +945,17 @@ public static T FindChild<T>(DependencyObject parent, string childName)

public static int CheckIfInputValueHaveChange(UIElement SourcePanel)
{

List<System.Type> TypeOfSearchElement = new List<System.Type>
{
typeof(TextBox),
typeof(ComboBox),
typeof(CheckBox),
typeof(RadioButton),
typeof(ICSharpCode.AvalonEdit.TextEditor)
typeof(ICSharpCode.AvalonEdit.TextEditor),
typeof(BlackPearl.Controls.CoreLibrary.MultiSelectCombobox)
};

var ListOfisualChildren = FindVisualChildren(SourcePanel, TypeOfSearchElement);
List<UIElement> ListOfisualChildren = FindVisualChildren(SourcePanel, TypeOfSearchElement);

string strHachCode = String.Empty;
ListOfisualChildren.ForEach(element =>
Expand Down Expand Up @@ -988,7 +984,8 @@ public static int CheckIfInputValueHaveChange(UIElement SourcePanel)
{
hachCode = value.GetHashCode();
}
}else if (type == typeof(ComboBox))
}
else if (type == typeof(ComboBox))
{
ComboBox ComboBox = (ComboBox)element;
string value = ComboBox.Text;
Expand All @@ -1008,6 +1005,19 @@ public static int CheckIfInputValueHaveChange(UIElement SourcePanel)
RadioButton RadioButton = (RadioButton)element;
hachCode = RadioButton.IsChecked.GetHashCode();
}
else if (type == typeof(BlackPearl.Controls.CoreLibrary.MultiSelectCombobox))
{
BlackPearl.Controls.CoreLibrary.MultiSelectCombobox MultiSelectCombobox = (BlackPearl.Controls.CoreLibrary.MultiSelectCombobox)element;
if (MultiSelectCombobox.SelectedItems != null && MultiSelectCombobox.SelectedItems.Count > 0)
{

hachCode = string.Join(";", MultiSelectCombobox.SelectedValues("EnglishName")).GetHashCode();
}
else
{
hachCode = 0;
}
}
else
{
throw new System.NotSupportedException("The type " + type.Name + " is not supported by the function");
Expand All @@ -1016,6 +1026,7 @@ public static int CheckIfInputValueHaveChange(UIElement SourcePanel)
}
}
});
ListOfisualChildren.Clear();
return strHachCode.GetHashCode();
}

Expand Down Expand Up @@ -1107,7 +1118,7 @@ public static bool FilterDigitOnlyWhileWritingInTextBox(TextBox textbElement, Li
string textboxtext = textbElement.Text;
var cursor_position = textbElement.SelectionStart;
string filtered_string = FilterDigitOnly(textboxtext, char_supplementaire);
textbElement.Text = filtered_string;
textbElement.SetText(filtered_string);
if (textboxtext != filtered_string)
{
if (cursor_position > 0) textbElement.SelectionStart = cursor_position - 1;
Expand All @@ -1120,29 +1131,27 @@ public static bool FilterDigitOnlyWhileWritingInTextBox(TextBox textbElement, Li
}
}

public static bool FilterDigitOnlyWhileWritingInTextBox(TextBox textbElement, System.Windows.Controls.TextChangedEventHandler action, int MaxInt = -1, List<char> char_supplementaire = null)
public static bool FilterDigitOnlyWhileWritingInTextBoxWithMaxValue(TextBox textbElement, int MaxInt = -1, List<char> char_supplementaire = null)
{
if (textbElement is null)
{
return false;
}
bool TextHasBeenFilteredAndChanged = false;
textbElement.TextChanged -= action;
if (FilterDigitOnlyWhileWritingInTextBox(textbElement, char_supplementaire))
{
if (MaxInt != -1 && Convert.ToUInt32(textbElement?.Text) > MaxInt)
if (!double.TryParse(textbElement?.Text, out double textbElementTextValue)) { return false; }
if (MaxInt != -1 && textbElementTextValue > MaxInt)
{
string MaxIntString = MaxInt.ToString();
textbElement.Text = MaxIntString;
textbElement.SetText(MaxIntString);
textbElement.SelectionStart = MaxIntString.Length;
}
else
{
TextHasBeenFilteredAndChanged = true;
}
}
textbElement.TextChanged += action;

return TextHasBeenFilteredAndChanged;
}

Expand Down
85 changes: 85 additions & 0 deletions MapsInMyFolder.Common/Country.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace MapsInMyFolder.Commun
{
public class Country
{
public string DisplayName { get; set; }
public string EnglishName { get; set; }


public static IEnumerable<Country> getList()
{
List<Country> CountryList = new List<Country>();
foreach (var ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
string CurentCultureCountry = getCountryFromCultureName(ci.DisplayName);
string EnglishCultureCountry = getCountryFromCultureName(ci.EnglishName);
if (!string.IsNullOrWhiteSpace(CurentCultureCountry) && !string.IsNullOrWhiteSpace(EnglishCultureCountry))
{
CountryList.Add(new Country() { EnglishName = EnglishCultureCountry, DisplayName = CurentCultureCountry });
}
}

CountryList.Add(new Country() { EnglishName = "World", DisplayName = "Monde" });
CountryList.Add(new Country() { EnglishName = "*", DisplayName = "*" });

//remove duplicates and order by DisplayName
return CountryList.GroupBy(x => x.EnglishName).Select(y => y.First()).OrderBy(z => z.DisplayName);
}

public static List<Country> getListFromEnglishName(IEnumerable<string> ListOfEnglishName)
{
List<Country> CountryList = new List<Country>();
foreach (var ci in getList())
{
if (ListOfEnglishName.Contains(ci.EnglishName))
{
CountryList.Add(ci);
}
}
return CountryList;
}

public static List<Country> getListFromEnglishName(string EnglishName)
{
return getListFromEnglishName(new string[] { EnglishName });
}


private static string getCountryFromCultureName(string Name)
{
string resultString = Regex.Match(Name, @"(?<=\().+?(?=\))", RegexOptions.RightToLeft).Value;
if (resultString.Contains(','))
{
string[] regionsplit = resultString.Split(',');
resultString = regionsplit[regionsplit.Length - 1];
}
if (resultString.Contains('[') && resultString.Contains(']'))
{
Regex regex = new Regex("\\[.*?\\]");
resultString = regex.Replace(resultString, "");
}
resultString = resultString.Trim();
if (!string.IsNullOrWhiteSpace(resultString) && char.IsLower(resultString[0]))
{
resultString = string.Empty;
}

return resultString;
}


}




}
Loading

0 comments on commit 82dbf66

Please sign in to comment.