Skip to content

Commit

Permalink
save window size/position, add remove from history
Browse files Browse the repository at this point in the history
  • Loading branch information
Luch00 committed Jun 14, 2016
1 parent 6df8d81 commit ec7b26e
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 85 deletions.
12 changes: 12 additions & 0 deletions ScreenShotterWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@
<setting name="imgurTokenExpire" serializeAs="String">
<value>0</value>
</setting>
<setting name="windowHeight" serializeAs="String">
<value>500</value>
</setting>
<setting name="windowWidth" serializeAs="String">
<value>380</value>
</setting>
<setting name="windowLeft" serializeAs="String">
<value>100</value>
</setting>
<setting name="windowTop" serializeAs="String">
<value>100</value>
</setting>
</ScreenShotterWPF.Properties.Settings>
</userSettings>
<runtime>
Expand Down
43 changes: 32 additions & 11 deletions ScreenShotterWPF/MainLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public void SetAsComplete()
queue.CompleteAdding();
}

public void RemoveXImage(XImage selected)
{
lock(ximages)
{
ximages.Remove(selected);
WriteXML();
}
}

private void AddToQueue(XImage x)
{
try
Expand Down Expand Up @@ -502,12 +511,12 @@ public void D3DCapPrimaryScreen()
// Capture whole screen area
public void CapFullscreen()
{
if (Properties.Settings.Default.d3dAutoDetect && NotificationState() == NativeMethods.USERNOTIFICATIONSTATE.QUNS_RUNNING_D3D_FULL_SCREEN)
/*if (Properties.Settings.Default.d3dAutoDetect && NotificationState() == NativeMethods.USERNOTIFICATIONSTATE.QUNS_RUNNING_D3D_FULL_SCREEN)
{
Console.WriteLine("D3DFullscreen Detected!");
D3DCapPrimaryScreen();
return;
}
}*/

var top = SystemParameters.VirtualScreenTop;
var left = SystemParameters.VirtualScreenLeft;
Expand Down Expand Up @@ -566,12 +575,12 @@ public void CapWindowFromPoint(int x, int y)
// Create an overlay, draw a rectangle on the overlay to cap that area
public void CapArea()
{
if (Properties.Settings.Default.d3dAutoDetect && NotificationState() == NativeMethods.USERNOTIFICATIONSTATE.QUNS_RUNNING_D3D_FULL_SCREEN)
/*if (Properties.Settings.Default.d3dAutoDetect && NotificationState() == NativeMethods.USERNOTIFICATIONSTATE.QUNS_RUNNING_D3D_FULL_SCREEN)
{
Console.WriteLine("D3DFullscreen Detected!");
D3DCapPrimaryScreen();
return;
}
}*/

if (!overlay_created)
{
Expand Down Expand Up @@ -697,7 +706,7 @@ private static string GetActiveWindowTitle()
const int nChars = 256;
StringBuilder buff = new StringBuilder(nChars);
var handle = NativeMethods.GetForegroundWindow();

return NativeMethods.GetWindowText(handle, buff, nChars) > 0 ? buff.ToString() : "null";
}

Expand Down Expand Up @@ -779,8 +788,11 @@ private void ImageManager(byte[] image, string filename)
{
x.filepath = SaveImageToDisk(x.image, filename);
x.filename = Path.GetFileName(x.filepath);
ximages.Add(x);
WriteXML();
lock (ximages)
{
ximages.Add(x);
WriteXML();
}
}

if (Properties.Settings.Default.autoUpload)
Expand All @@ -805,8 +817,11 @@ private void AddXimageToList(XImage x, string url)
if (!Properties.Settings.Default.saveLocal && x.filepath.Length == 0)
{
x.url = url;
ximages.Add(x);
WriteXML();
lock (ximages)
{
ximages.Add(x);
WriteXML();
}
}
else
{
Expand All @@ -821,8 +836,11 @@ private void AddXimageToList(XImage x, string url)
else
{
x.url = url;
ximages.Add(x);
WriteXML();
lock (ximages)
{
ximages.Add(x);
WriteXML();
}
}
}
if (url.Length > 0)
Expand Down Expand Up @@ -876,6 +894,9 @@ private void RetryClipboard(string obj)
// Set picturebox image only for local and imgur hosted images
public static BitmapImage GetPicture(XImage x)
{
if (x == null)
return null;

string url;
if (x.filepath != string.Empty && File.Exists(x.filepath))
{
Expand Down
10 changes: 9 additions & 1 deletion ScreenShotterWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:views="clr-namespace:ScreenShotterWPF.Views"
Title="LXtory 0.93" Height="500" Width="380" MinWidth="380" MinHeight="500" Closing="Window_Closing" Icon="Resources/Hoshimemo5.ico" StateChanged="UI_StateChanged" Loaded="UI_Loaded" Margin="0" Padding="0">
xmlns:p="clr-namespace:ScreenShotterWPF.Properties"
Title="LXtory 0.93"
Height="{Binding Source={x:Static p:Settings.Default}, Path=windowHeight, Mode=TwoWay}"
Width="{Binding Source={x:Static p:Settings.Default}, Path=windowWidth, Mode=TwoWay}"
Top="{Binding Source={x:Static p:Settings.Default}, Path=windowTop, Mode=TwoWay}"
Left="{Binding Source={x:Static p:Settings.Default}, Path=windowLeft, Mode=TwoWay}"
MinWidth="380"
MinHeight="500"
Closing="Window_Closing" Icon="Resources/Hoshimemo5.ico" StateChanged="UI_StateChanged" Loaded="UI_Loaded" Margin="0" Padding="0" Closed="UI_Closed">
<views:MainView x:Name="MainView" Loaded="MainView_Loaded"/>
</Window>
9 changes: 9 additions & 0 deletions ScreenShotterWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ private void Window_Closing(object sender, CancelEventArgs e)
this.ShowInTaskbar = false;
this.Visibility = Visibility.Hidden;
}
else
{
Properties.Settings.Default.Save();
}
}

private void UI_StateChanged(object sender, EventArgs e)
Expand All @@ -78,6 +82,11 @@ private void MainView_Loaded(object sender, RoutedEventArgs e)
mainview.WindowHandle = helper.Handle;
}

private void UI_Closed(object sender, EventArgs e)
{
//Properties.Settings.Default.Save();
}

#endregion
}
}
52 changes: 52 additions & 0 deletions ScreenShotterWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ScreenShotterWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,17 @@
<Setting Name="hkGifcapture" Provider="PortableSettingsProvider" Type="ScreenShotterWPF.HotKey" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="windowHeight" Provider="PortableSettingsProvider" Type="System.Double" Scope="User">
<Value Profile="(Default)">500</Value>
</Setting>
<Setting Name="windowWidth" Provider="PortableSettingsProvider" Type="System.Double" Scope="User">
<Value Profile="(Default)">380</Value>
</Setting>
<Setting Name="windowLeft" Provider="PortableSettingsProvider" Type="System.Double" Scope="User">
<Value Profile="(Default)">100</Value>
</Setting>
<Setting Name="windowTop" Provider="PortableSettingsProvider" Type="System.Double" Scope="User">
<Value Profile="(Default)">100</Value>
</Setting>
</Settings>
</SettingsFile>
23 changes: 17 additions & 6 deletions ScreenShotterWPF/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
Expand Down Expand Up @@ -29,6 +28,7 @@ class MainViewModel : BindableBase
public ICommand ExitCommand { get; private set; }
public ICommand OpenCommand { get; private set; }
//public ICommand OpenSettingsCommand { get; private set; }
public ICommand DeleteCommand { get; private set; }

public ICommand CaptureFullscreenCommand { get; private set; }
public ICommand CaptureWindowCommand { get; private set; }
Expand Down Expand Up @@ -62,6 +62,7 @@ public MainViewModel()
this.ExitCommand = new DelegateCommand(ExitApplication);
this.OpenCommand = new DelegateCommand(OpenImageFolder);
//this.OpenSettingsCommand = new DelegateCommand(OpenSettings);
this.DeleteCommand = new DelegateCommand(DeleteItem);

this.CaptureFullscreenCommand = new DelegateCommand(CaptureFullscreen);
this.CaptureWindowCommand = new DelegateCommand(CaptureWindow);
Expand Down Expand Up @@ -92,6 +93,12 @@ private void RaiseSettings()
});
}

private void DeleteItem()
{
//Console.WriteLine(selectedItem.filename);
Main.RemoveXImage(selectedItem);
}

private void CaptureGif()
{
GifButtonEnabled = false;
Expand Down Expand Up @@ -138,6 +145,7 @@ private void CaptureArea()

private static void ExitApplication()
{
Properties.Settings.Default.Save();
Application.Current.Shutdown();
}

Expand Down Expand Up @@ -176,15 +184,15 @@ public BitmapImage DisplayImage
set { displayImage = value; OnPropertyChanged("DisplayImage"); }
}

public XImage SelectedIndex
public XImage SelectedItem
{
get { return selectedItem; }
set
{
selectedItem = value;
CheckContextMenuItems();
//CheckContextMenuItems();
DisplayImage = MainLogic.GetPicture(selectedItem);
OnPropertyChanged("SelectedIndex");
OnPropertyChanged("SelectedItem");
}
}

Expand All @@ -193,12 +201,15 @@ private void GetContent()
Main.ReadXML();
}

private void CheckContextMenuItems()
/*private void CheckContextMenuItems()
{
if (selectedItem == null)
return;
SelectedIndex.OpenLocalEnabled = SelectedIndex.filepath != string.Empty && File.Exists(SelectedIndex.filepath);
SelectedIndex.OpenBrowserEnabled = SelectedIndex.CopyClipboardEnabled = (SelectedIndex.url != string.Empty);
}
}*/

public bool PassCommandLineArgs(IList<string> args)
{
Expand Down
Loading

0 comments on commit ec7b26e

Please sign in to comment.