Added HistorySettings class

This commit is contained in:
Jaex 2018-08-01 16:52:10 +03:00
parent 3383e25570
commit b166e94131
5 changed files with 54 additions and 25 deletions

View file

@ -36,20 +36,18 @@ namespace ShareX.HistoryLib
{
public partial class HistoryForm : Form
{
public event Action<int> SplitterDistanceChanged;
public string HistoryPath { get; private set; }
public int MaxItemCount { get; set; }
public HistorySettings Settings { get; private set; }
private HistoryManager history;
private HistoryItemManager him;
private HistoryItem[] allHistoryItems;
private string defaultTitle;
public HistoryForm(string historyPath, int maxItemCount, int splitterDistance = 0, Action<string> uploadFile = null, Action<string> editImage = null)
public HistoryForm(string historyPath, HistorySettings settings, Action<string> uploadFile = null, Action<string> editImage = null)
{
HistoryPath = historyPath;
MaxItemCount = maxItemCount;
Settings = settings;
InitializeComponent();
Icon = ShareXResources.Icon;
@ -74,10 +72,12 @@ public HistoryForm(string historyPath, int maxItemCount, int splitterDistance =
cbFilenameFilterMethod.SelectedIndex = 0; // Contains
lvHistory.FillLastColumn();
if (splitterDistance > 0)
if (Settings.SplitterDistance > 0)
{
scMain.SplitterDistance = splitterDistance;
scMain.SplitterDistance = Settings.SplitterDistance;
}
Settings.WindowState.AutoHandleFormState(this);
}
private void RefreshHistoryItems()
@ -101,9 +101,9 @@ private HistoryItem[] GetHistoryItems()
IEnumerable<HistoryItem> tempHistoryItems = history.GetHistoryItems();
tempHistoryItems = tempHistoryItems.Reverse();
if (MaxItemCount > 0)
if (Settings.MaxItemCount > 0)
{
tempHistoryItems = tempHistoryItems.Take(MaxItemCount);
tempHistoryItems = tempHistoryItems.Take(Settings.MaxItemCount);
}
return tempHistoryItems.ToArray();
@ -289,14 +289,6 @@ private void UpdatePictureBox()
}
}
protected void OnSplitterDistanceChanged(int splitterDistance)
{
if (SplitterDistanceChanged != null)
{
SplitterDistanceChanged(splitterDistance);
}
}
#region Form events
private void HistoryForm_Shown(object sender, EventArgs e)
@ -342,7 +334,7 @@ private void HistoryForm_KeyDown(object sender, KeyEventArgs e)
private void scMain_SplitterMoved(object sender, SplitterEventArgs e)
{
OnSplitterDistanceChanged(scMain.SplitterDistance);
Settings.SplitterDistance = scMain.SplitterDistance;
}
private void btnApplyFilters_Click(object sender, EventArgs e)

View file

@ -0,0 +1,41 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2018 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShareX.HistoryLib
{
public class HistorySettings
{
public WindowState WindowState { get; set; } = new WindowState();
public int MaxItemCount { get; set; } = 0;
public int SplitterDistance { get; set; } = 550;
}
}

View file

@ -99,6 +99,7 @@
<Compile Include="Forms\ImageHistorySettingsForm.Designer.cs">
<DependentUpon>ImageHistorySettingsForm.cs</DependentUpon>
</Compile>
<Compile Include="HistorySettings.cs" />
<Compile Include="ImageHistorySettings.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View file

@ -123,10 +123,7 @@ public ApplicationConfig()
public bool RecentTasksShowInTrayMenu = true;
public bool RecentTasksTrayMenuMostRecentFirst = false;
public WindowState HistoryWindowState = new WindowState();
public int HistoryMaxItemCount = 0;
public int HistorySplitterDistance = 550;
public HistorySettings HistorySettings = new HistorySettings();
public ImageHistorySettings ImageHistorySettings = new ImageHistorySettings();
#endregion History

View file

@ -714,10 +714,8 @@ public static void OpenScreenshotsFolder()
public static void OpenHistory()
{
HistoryForm historyForm = new HistoryForm(Program.HistoryFilePath, Program.Settings.HistoryMaxItemCount, Program.Settings.HistorySplitterDistance,
HistoryForm historyForm = new HistoryForm(Program.HistoryFilePath, Program.Settings.HistorySettings,
filePath => UploadManager.UploadFile(filePath), filePath => AnnotateImageFromFile(filePath));
historyForm.SplitterDistanceChanged += splitterDistance => Program.Settings.HistorySplitterDistance = splitterDistance;
Program.Settings.HistoryWindowState.AutoHandleFormState(historyForm);
historyForm.Show();
}