Skip to content

Commit

Permalink
feat: add clipboard notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Jun 16, 2023
1 parent 9b5e2ca commit 4dd9c84
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
1 change: 0 additions & 1 deletion MHFZ_Overlay/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,6 @@ Thunder Clad, Vigorous" Text="{Binding GetActiveSkillsForImage,Mode=OneTime}" Fo
</TabItem.Header>
<Grid>
<DockPanel Margin="5,5,5,5">

<Grid x:Name="HuntedLogGrid">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
Expand Down
27 changes: 15 additions & 12 deletions MHFZ_Overlay/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ private void BtnSaveFile_Click(object sender, RoutedEventArgs e)
}

/// <summary>
/// Copy to clipboard
/// Copy to clipboard. TODO: change function name, its too generic
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Expand All @@ -981,20 +981,22 @@ private void BtnCopyFile_Click(object sender, RoutedEventArgs e)
textToSave = MainWindow.DataLoader.model.MarkdownSavedGearStats;
else if (GetTextFormatMode() == "Image")
{
var previousBackground = GearTextGrid.Background;
GearTextGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(GearTextGrid);
GearTextGrid.Background = new SolidColorBrush(Color.FromArgb(0x00, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(GearTextGrid, ConfigWindowSnackBar);
GearTextGrid.Background = previousBackground;
return;
}

//https://stackoverflow.com/questions/3546016/how-to-copy-data-to-clipboard-in-c-sharp
Clipboard.SetText(textToSave);
ConfigWindowSnackBar.Show(Messages.INFO_TITLE, "Copied text to clipboard", new SymbolIcon(SymbolRegular.Clipboard32), ControlAppearance.Success);
}

private void BtnImageFile_Click(object sender, RoutedEventArgs e)
{
var fileName = "HunterSet";
FileManager.SaveElementAsImageFile(GearImageGrid, fileName);
FileManager.SaveElementAsImageFile(GearImageGrid, fileName, ConfigWindowSnackBar);
}


Expand Down Expand Up @@ -1023,7 +1025,7 @@ private void Config_Closed(object sender, EventArgs e)
private void BtnGuildCardFile_Click(object sender, RoutedEventArgs e)
{
var fileName = "GuildCard";
FileManager.SaveElementAsImageFile(GuildCardGrid, fileName);
FileManager.SaveElementAsImageFile(GuildCardGrid, fileName, ConfigWindowSnackBar);
}

private void ChangeMonsterInfo()
Expand Down Expand Up @@ -1607,7 +1609,7 @@ private void QuestLogGearBtnCopyFile_Click(object sender, RoutedEventArgs e)
if (questLogGearStatsTextBlock == null) return;
var previousBackground = questLogGearStatsTextBlock.Background;
questLogGearStatsTextBlock.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(questLogGearStatsTextBlock);
FileManager.CopyUIElementToClipboard(questLogGearStatsTextBlock, ConfigWindowSnackBar);
questLogGearStatsTextBlock.Background = previousBackground;
}

Expand All @@ -1631,28 +1633,29 @@ private void CompendiumBtnSaveFile_Click(object sender, RoutedEventArgs e)
private void CompendiumBtnCopyFile_Click(object sender, RoutedEventArgs e)
{
if (compendiumInformationStackPanel == null) return;
var previousBackground = compendiumInformationStackPanel.Background;
compendiumInformationStackPanel.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(compendiumInformationStackPanel);
compendiumInformationStackPanel.Background = new SolidColorBrush(Color.FromArgb(0x00, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(compendiumInformationStackPanel, ConfigWindowSnackBar);
compendiumInformationStackPanel.Background = previousBackground;
}

// TODO: dictories paths should be in a static class
// TODO: put in file manager class?
private void CalendarButtonSaveFile_Click(object sender, RoutedEventArgs e)
{
try
{
var data = MainWindow.DataLoader.model.CalendarRuns;
if (data == null) return;
Settings s = (Settings)Application.Current.TryFindResource("Settings");
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "CSV files (*.csv)|*.csv";
saveFileDialog.Title = "Save Calendar Runs as CSV";
Settings s = (Settings)Application.Current.TryFindResource("Settings");
saveFileDialog.InitialDirectory = Path.GetDirectoryName(s.DatabaseFilePath);
string dateTime = DateTime.Now.ToString();
dateTime = dateTime.Replace("/", "-");
dateTime = dateTime.Replace(" ", "_");
dateTime = dateTime.Replace(":", "-");
saveFileDialog.FileName = string.Format("CalendarRuns_{0}", datePickerDate.ToString("yy/MM/dd").Replace("/","-"));
saveFileDialog.FileName = string.Format("CalendarRuns-{0}", datePickerDate.ToString("yy/MM/dd").Replace("/","-"));
if (saveFileDialog.ShowDialog() == true)
{
string filePath = saveFileDialog.FileName;
Expand Down Expand Up @@ -1692,7 +1695,7 @@ private void CalendarButtonCopyFile_Click(object sender, RoutedEventArgs e)
if (calendarDataGrid == null) return;
var previousBackground = calendarDataGrid.Background;
calendarDataGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
FileManager.CopyUIElementToClipboard(calendarDataGrid);
FileManager.CopyUIElementToClipboard(calendarDataGrid, ConfigWindowSnackBar);
calendarDataGrid.Background = previousBackground;
}

Expand Down
26 changes: 18 additions & 8 deletions MHFZ_Overlay/Core/Class/IO/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
using Wpf.Ui.Controls.Window;
using Clipboard = System.Windows.Clipboard;
using MessageBox = System.Windows.MessageBox;
using SaveFileDialog = Microsoft.Win32.SaveFileDialog;

namespace MHFZ_Overlay.Core.Class.IO;

Expand All @@ -32,7 +40,6 @@ internal class FileManager
/// </summary>
/// <param name="textToSave">The text to save.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="initialDirectory">The initial directory.</param>
/// <param name="beginningFileName">Name of the beginning file.</param>
/// <param name="beginningText">The beginning text.</param>
public static void SaveTextFile(string textToSave, string fileName, string beginningFileName = "", string beginningText = "")
Expand Down Expand Up @@ -67,8 +74,7 @@ public static void SaveTextFile(string textToSave, string fileName, string begin
/// </summary>
/// <param name="gridToSave">The grid to save.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="initialDirectory">The initial directory.</param>
public static void SaveElementAsImageFile(Grid gridToSave, string fileName, string initialDirectory = @"USERDATA\HunterInfo\")
public static void SaveElementAsImageFile(Grid gridToSave, string fileName, Snackbar snackbar)
{
try
{
Expand All @@ -79,13 +85,14 @@ public static void SaveElementAsImageFile(Grid gridToSave, string fileName, stri
dateTime = dateTime.Replace(":", "-");
savefile.FileName = string.Format("{0}-{1}.png", fileName, dateTime);
savefile.Filter = "PNG files (*.png)|*.png";
savefile.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory + initialDirectory;

savefile.Title = "Save Image";
Settings s = (Settings)System.Windows.Application.Current.TryFindResource("Settings");
savefile.InitialDirectory = Path.GetDirectoryName(s.DatabaseFilePath);
if (savefile.ShowDialog() == true)
{
gridToSave.Background = new SolidColorBrush(Color.FromArgb(0x00, 0x1E, 0x1E, 0x2E));
CreateBitmapFromVisual(gridToSave, savefile.FileName);
CopyUIElementToClipboard(gridToSave);
CopyUIElementToClipboard(gridToSave, snackbar);
gridToSave.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x1E, 0x1E, 0x2E));
logger.Info("Saved image {0}", savefile.FileName);
}
Expand All @@ -100,7 +107,7 @@ public static void SaveElementAsImageFile(Grid gridToSave, string fileName, stri
/// Copies a UI element to the clipboard as an image.
/// </summary>
/// <param name="element">The element to copy.</param>
public static void CopyUIElementToClipboard(FrameworkElement element)
public static void CopyUIElementToClipboard(FrameworkElement element, Snackbar snackbar)
{
try
{
Expand All @@ -122,6 +129,7 @@ public static void CopyUIElementToClipboard(FrameworkElement element)
}
bmpCopied.Render(dv);
Clipboard.SetImage(bmpCopied);
snackbar.Show(Messages.INFO_TITLE, "Copied image to clipboard", new SymbolIcon(SymbolRegular.Clipboard32), ControlAppearance.Success);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -193,7 +201,9 @@ public static void SaveMonsterLogRecordsAsCSVFile(MonsterLog[] Monsters)
dateTime = dateTime.Replace(":", "-");
savefile.FileName = "HuntedLog-" + dateTime + ".csv";
savefile.Filter = "CSV files (*.csv)|*.csv";
savefile.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory + @"USERDATA\HuntedLogs\";
savefile.Title = "Save Monster Log Records as CSV";
Settings s = (Settings)System.Windows.Application.Current.TryFindResource("Settings");
savefile.InitialDirectory = Path.GetDirectoryName(s.DatabaseFilePath);

//https://stackoverflow.com/questions/11776781/savefiledialog-make-problems-with-streamwriter-in-c-sharp
if (savefile.ShowDialog() == true)
Expand Down

0 comments on commit 4dd9c84

Please sign in to comment.