Skip to content

Commit

Permalink
Added the possibility to create notes on color bookmarks (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Mar 16, 2024
1 parent 0c0f13f commit 4d2d3d1
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ColorPicker/Pages/AiGenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
return;
}
Global.Bookmarks.ColorBookmarks.Add(hex); // Add to color bookmarks
Global.Bookmarks.ColorBookmarksNotes.Add(""); // Add note

BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}
Expand Down
1 change: 1 addition & 0 deletions ColorPicker/Pages/ContrastPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
return;
}
Global.Bookmarks.ColorBookmarks.Add($"#{ColorInfo.HEX.Value}"); // Add to color bookmarks
Global.Bookmarks.ColorBookmarksNotes.Add(""); // Add note
BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}
Expand Down
1 change: 1 addition & 0 deletions ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
return;
}
Global.Bookmarks.ColorBookmarks.Add(HexTxt.Text); // Add to color bookmarks
Global.Bookmarks.ColorBookmarksNotes.Add(""); // Add note
BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}
Expand Down
1 change: 1 addition & 0 deletions ColorPicker/Pages/HarmoniesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
return;
}
Global.Bookmarks.ColorBookmarks.Add($"#{ColorInfo.HEX.Value}"); // Add to color bookmarks
Global.Bookmarks.ColorBookmarksNotes.Add(""); // Add note
BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}
Expand Down
1 change: 1 addition & 0 deletions ColorPicker/Pages/SelectorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
return;
}
Global.Bookmarks.ColorBookmarks.Add(HexTxt.Text); // Add to color bookmarks
Global.Bookmarks.ColorBookmarksNotes.Add(""); // Add note
BookmarkBtn.Content = "\uF1F8";
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}
Expand Down
68 changes: 68 additions & 0 deletions ColorPicker/UserControls/ColorItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@
</StackPanel>

<StackPanel Grid.Column="2" Orientation="Horizontal">
<TextBlock
x:Name="NoteIcon"
Margin="0 6 5 0"
Padding="5"
VerticalAlignment="Top"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Text="&#xF56C;">
<TextBlock.ToolTip>
<ToolTip
x:Name="NoteToolTip"
Background="{DynamicResource Background1}"
Foreground="{DynamicResource Foreground1}" />
</TextBlock.ToolTip>
</TextBlock>
<Button
x:Name="DeleteBtn"
Grid.Column="3"
Expand Down Expand Up @@ -190,6 +204,15 @@
Color="#000" />
</Border.Effect>
<StackPanel>
<Button
x:Name="AddNoteBtn"
HorizontalContentAlignment="Left"
Background="Transparent"
Click="AddNoteBtn_Click"
Content="{x:Static lang:Resources.AddNote}"
FontWeight="Bold"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource DefaultButton}" />
<Button
x:Name="EditSelectorBtn"
HorizontalContentAlignment="Left"
Expand Down Expand Up @@ -220,6 +243,51 @@
</StackPanel>
</Border>
</Popup>
<Popup
x:Name="NotePopup"
AllowsTransparency="True"
Placement="MousePoint"
PlacementTarget="{Binding MoreBtn}"
StaysOpen="False">
<Border
Margin="10"
Padding="10"
Background="{DynamicResource Background1}"
CornerRadius="10">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Direction="135"
Opacity="0.2"
ShadowDepth="0"
Color="#000" />
</Border.Effect>
<StackPanel>
<Border
Padding="2"
BorderBrush="{DynamicResource AccentColor}"
BorderThickness="1"
CornerRadius="5">
<TextBox
x:Name="NoteTxt"
MinWidth="100"
MinHeight="50"
BorderThickness="0" />
</Border>
<Button
x:Name="SaveBtn"
Margin="5"
Padding="5 2"
HorizontalAlignment="Center"
Background="{DynamicResource AccentColor}"
Click="SaveBtn_Click"
Content="{x:Static lang:Resources.Save}"
FontWeight="Bold"
Foreground="{DynamicResource WindowButtonsHoverForeground1}"
Style="{DynamicResource PrimaryButton}" />
</StackPanel>
</Border>
</Popup>
</StackPanel>
</Grid>
</Border>
Expand Down
40 changes: 39 additions & 1 deletion ColorPicker/UserControls/ColorItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public ColorItem(string hexColor)
InitUI();
}

private int GetIndex()
{
int i = Global.Bookmarks.ColorBookmarks.IndexOf(HexColor);
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf(HexColor.ToLower());
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf(HexColor.ToUpper());
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf("#" + HexColor.ToLower());
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf("#" + HexColor.ToUpper());
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf(HexColor.ToLower().Replace("#", ""));
if (i == -1) i = Global.Bookmarks.ColorBookmarks.IndexOf(HexColor.ToUpper().Replace("#", ""));
return i;
}

private void InitUI()
{
Color color = Color.FromRgb(ColorInfo.RGB.R, ColorInfo.RGB.G, ColorInfo.RGB.B);
Expand All @@ -62,6 +74,13 @@ private void InitUI()

RgbTxt.Text = $"{ColorInfo.RGB.R}{Global.Settings.RgbSeparator}{ColorInfo.RGB.G}{Global.Settings.RgbSeparator}{ColorInfo.RGB.B}"; // Set text
HEXTxt.Text = HexColor; // Set text
try
{
NoteTxt.Text = Global.Bookmarks.ColorBookmarksNotes[GetIndex()];
NoteToolTip.Content = NoteTxt.Text;
NoteIcon.Visibility = string.IsNullOrEmpty(NoteTxt.Text) ? Visibility.Collapsed : Visibility.Visible;
}
catch { }
}

private void ColorBorder_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
Expand All @@ -82,7 +101,9 @@ private void ColorBorder_MouseLeftButtonUp(object sender, System.Windows.Input.M

private void DeleteBtn_Click(object sender, RoutedEventArgs e)
{
Global.Bookmarks.ColorBookmarks.Remove(HexColor);
int index = GetIndex();
Global.Bookmarks.ColorBookmarks.RemoveAt(index);
Global.Bookmarks.ColorBookmarksNotes.RemoveAt(index);
Global.BookmarksPage.ColorsBookmarks.Children.Remove(this);
Global.SelectorPage.LoadDetails();
Global.ConverterPage.LoadDetails();
Expand Down Expand Up @@ -162,5 +183,22 @@ private void EditPaletteBtn_Click(object sender, RoutedEventArgs e)
Global.PalettePage.InitPaletteUI(true);
GoClick?.Invoke(sender, new PageEventArgs(AppPages.ColorPalette));
}

private void AddNoteBtn_Click(object sender, RoutedEventArgs e)
{
MorePopup.IsOpen = false;
NotePopup.IsOpen = true;
}

private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
try
{
Global.Bookmarks.ColorBookmarksNotes[GetIndex()] = NoteTxt.Text;
NoteToolTip.Content = NoteTxt.Text;
NoteIcon.Visibility = string.IsNullOrEmpty(NoteTxt.Text) ? Visibility.Collapsed : Visibility.Visible;
}
catch { }
}
}
}

0 comments on commit 4d2d3d1

Please sign in to comment.