mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
Moving back to trunk!
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
ad265b2c54
commit
8d458998a1
332 changed files with 17647 additions and 9466 deletions
|
@ -19,12 +19,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.AccessControl;
|
||||
|
@ -34,41 +31,27 @@ using System.Threading;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Experimental;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Help;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.UnmanagedHelpers;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using GreenshotPlugin.Controls;
|
||||
using GreenshotPlugin.Core;
|
||||
using IniFile;
|
||||
|
||||
namespace Greenshot {
|
||||
/// <summary>
|
||||
/// Description of MainForm.
|
||||
/// </summary>
|
||||
public partial class MainForm : Form {
|
||||
private const string LOG4NET_FILE = "log4net.xml";
|
||||
private static log4net.ILog LOG = null;
|
||||
private static Mutex applicationMutex = null;
|
||||
private static CoreConfiguration conf;
|
||||
|
||||
private static void InitializeLog4NET() {
|
||||
// Setup log4j, currently the file is called log4net.xml
|
||||
string log4netFilename = Path.Combine(Application.StartupPath, LOG4NET_FILE);
|
||||
if (File.Exists(log4netFilename)) {
|
||||
log4net.Config.XmlConfigurator.Configure(new FileInfo(log4netFilename));
|
||||
} else {
|
||||
MessageBox.Show("Can't find file " + LOG4NET_FILE);
|
||||
}
|
||||
|
||||
// Setup the LOG
|
||||
LOG = log4net.LogManager.GetLogger(typeof(MainForm));
|
||||
}
|
||||
public static string LogFileLocation = null;
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args) {
|
||||
public static void Start(string[] args) {
|
||||
bool isAlreadyRunning = false;
|
||||
List<string> filesToOpen = new List<string>();
|
||||
|
||||
|
@ -76,7 +59,9 @@ namespace Greenshot {
|
|||
Thread.CurrentThread.Name = Application.ProductName;
|
||||
|
||||
// Init Log4NET
|
||||
InitializeLog4NET();
|
||||
LogFileLocation = LogHelper.InitializeLog4NET();
|
||||
// Get logger
|
||||
LOG = log4net.LogManager.GetLogger(typeof(MainForm));
|
||||
|
||||
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
||||
|
@ -84,6 +69,7 @@ namespace Greenshot {
|
|||
// Log the startup
|
||||
LOG.Info("Starting: " + EnvironmentInfo.EnvironmentToString(false));
|
||||
|
||||
IniConfig.Init();
|
||||
AppConfig.UpgradeToIni();
|
||||
// Read configuration
|
||||
conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
@ -100,7 +86,7 @@ namespace Greenshot {
|
|||
mutexsecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.ChangePermissions, AccessControlType.Deny));
|
||||
mutexsecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.Delete, AccessControlType.Deny));
|
||||
|
||||
bool created = false;
|
||||
bool created = false;
|
||||
// 1) Create Mutex
|
||||
applicationMutex = new Mutex(false, @"Local\F48E86D3-E34C-4DB7-8F8F-9A0EA55F0D08", out created, mutexsecurity);
|
||||
// 2) Get the right to it, this returns false if it's already locked
|
||||
|
@ -223,8 +209,9 @@ namespace Greenshot {
|
|||
}
|
||||
}
|
||||
|
||||
ILanguage lang = Language.GetInstance();
|
||||
if (isAlreadyRunning) {
|
||||
// We didn't initialize the language yet, do it here just for the message box
|
||||
ILanguage lang = Language.GetInstance();
|
||||
if (filesToOpen.Count > 0) {
|
||||
SendData(transport);
|
||||
} else {
|
||||
|
@ -240,21 +227,22 @@ namespace Greenshot {
|
|||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
// if language is not set, show language dialog
|
||||
if(conf.Language == null || conf.Language.Trim().Length == 0) {
|
||||
LanguageDialog ld = LanguageDialog.GetInstance();
|
||||
ld.ShowDialog();
|
||||
conf.Language = ld.SelectedLanguage;
|
||||
if(string.IsNullOrEmpty(conf.Language)) {
|
||||
LanguageDialog languageDialog = LanguageDialog.GetInstance();
|
||||
languageDialog.ShowDialog();
|
||||
conf.Language = languageDialog.SelectedLanguage;
|
||||
IniConfig.Save();
|
||||
}
|
||||
|
||||
// Check if it's the first time launch?
|
||||
if(conf.IsFirstLaunch) {
|
||||
if(conf.IsFirstLaunch) {
|
||||
conf.IsFirstLaunch = false;
|
||||
IniConfig.Save();
|
||||
transport.AddCommand(CommandEnum.FirstLaunch);
|
||||
}
|
||||
|
||||
MainForm mainForm = new MainForm(transport);
|
||||
Application.Run(mainForm);
|
||||
Application.Run();
|
||||
} catch(Exception ex) {
|
||||
LOG.Error("Exception in startup.", ex);
|
||||
Application_ThreadException(MainForm.ActiveForm, new ThreadExceptionEventArgs(ex));
|
||||
|
@ -288,11 +276,24 @@ namespace Greenshot {
|
|||
|
||||
private ILanguage lang;
|
||||
private ToolTip tooltip;
|
||||
private CaptureForm captureForm = null;
|
||||
private CopyData copyData = null;
|
||||
|
||||
// Thumbnail preview
|
||||
private FormWithoutActivation thumbnailForm = null;
|
||||
private IntPtr thumbnailHandle = IntPtr.Zero;
|
||||
private Rectangle parentMenuBounds = Rectangle.Empty;
|
||||
// Make sure we have only one settings form
|
||||
private SettingsForm settingsForm = null;
|
||||
// Make sure we have only one about form
|
||||
private AboutForm aboutForm = null;
|
||||
// Make sure we have only one help browser
|
||||
private HelpBrowserForm helpBrowserForm = null;
|
||||
|
||||
public MainForm(CopyDataTransport dataTransport) {
|
||||
instance = this;
|
||||
|
||||
// Make sure we never capture the mainform
|
||||
WindowDetails.RegisterIgnoreHandle(this.Handle);
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
|
@ -307,14 +308,35 @@ namespace Greenshot {
|
|||
tooltip = new ToolTip();
|
||||
|
||||
UpdateUI();
|
||||
InitializeQuickSettingsMenu();
|
||||
|
||||
// Do loading on a different Thread to shorten the startup
|
||||
Thread pluginInitThread = new Thread (delegate() {
|
||||
// Load all the plugins
|
||||
PluginHelper.instance.LoadPlugins(this);
|
||||
|
||||
// Check destinations, remove all that don't exist
|
||||
foreach(string destination in conf.OutputDestinations.ToArray()) {
|
||||
if (DestinationHelper.GetDestination(destination) == null) {
|
||||
conf.OutputDestinations.Remove(destination);
|
||||
}
|
||||
}
|
||||
|
||||
// we should have at least one!
|
||||
if (conf.OutputDestinations.Count == 0) {
|
||||
conf.OutputDestinations.Add(Destinations.EditorDestination.DESIGNATION);
|
||||
}
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
// Do after all plugins & finding the destination, otherwise they are missing!
|
||||
InitializeQuickSettingsMenu();
|
||||
});
|
||||
});
|
||||
pluginInitThread.Name = "Initialize plug-ins";
|
||||
pluginInitThread.IsBackground = true;
|
||||
pluginInitThread.Start();
|
||||
|
||||
captureForm = new CaptureForm();
|
||||
|
||||
// Load all the plugins
|
||||
PluginHelper.instance.LoadPlugins(this, captureForm);
|
||||
SoundHelper.Initialize();
|
||||
|
||||
|
||||
// Enable the Greenshot icon to be visible, this prevents Problems with the context menu
|
||||
notifyIcon.Visible = true;
|
||||
|
||||
|
@ -331,7 +353,6 @@ namespace Greenshot {
|
|||
if (dataTransport != null) {
|
||||
HandleDataTransport(dataTransport);
|
||||
}
|
||||
ClipboardHelper.RegisterClipboardViewer(this.Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -344,25 +365,47 @@ namespace Greenshot {
|
|||
CopyDataTransport dataTransport = (CopyDataTransport)copyDataReceivedEventArgs.Data;
|
||||
HandleDataTransport(dataTransport);
|
||||
}
|
||||
|
||||
|
||||
private void HandleDataTransport(CopyDataTransport dataTransport) {
|
||||
foreach(KeyValuePair<CommandEnum, string> command in dataTransport.Commands) {
|
||||
LOG.Debug("Data received, Command = " + command.Key + ", Data: " + command.Value);
|
||||
switch(command.Key) {
|
||||
case CommandEnum.Exit:
|
||||
exit();
|
||||
Exit();
|
||||
break;
|
||||
case CommandEnum.FirstLaunch:
|
||||
LOG.Info("FirstLaunch: Created new configuration.");
|
||||
LOG.Info("FirstLaunch: Created new configuration, showing balloon.");
|
||||
|
||||
try {
|
||||
EventHandler balloonTipClickedHandler = null;
|
||||
EventHandler balloonTipClosedHandler = null;
|
||||
balloonTipClosedHandler = delegate(object sender, EventArgs e) {
|
||||
notifyIcon.BalloonTipClicked -= balloonTipClickedHandler;
|
||||
notifyIcon.BalloonTipClosed -= balloonTipClosedHandler;
|
||||
};
|
||||
|
||||
balloonTipClickedHandler = delegate(object sender, EventArgs e) {
|
||||
ShowSetting();
|
||||
notifyIcon.BalloonTipClicked -= balloonTipClickedHandler;
|
||||
notifyIcon.BalloonTipClosed -= balloonTipClosedHandler;
|
||||
};
|
||||
notifyIcon.BalloonTipClicked += balloonTipClickedHandler;
|
||||
notifyIcon.BalloonTipClosed += balloonTipClosedHandler;
|
||||
notifyIcon.ShowBalloonTip(2000, "Greenshot", lang.GetFormattedString(LangKey.tooltip_firststart, HotkeyControl.GetLocalizedHotkeyStringFromString(conf.RegionHotkey)), ToolTipIcon.Info);
|
||||
} catch {}
|
||||
break;
|
||||
case CommandEnum.ReloadConfig:
|
||||
IniConfig.Reload();
|
||||
ReloadConfiguration(null, null);
|
||||
try {
|
||||
IniConfig.Reload();
|
||||
ReloadConfiguration(null, null);
|
||||
} catch {}
|
||||
break;
|
||||
case CommandEnum.OpenFile:
|
||||
string filename = command.Value;
|
||||
if (File.Exists(filename)) {
|
||||
captureForm.MakeCapture(filename);
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureHelper.CaptureFile(filename);
|
||||
});
|
||||
} else {
|
||||
LOG.Warn("No such file: " + filename);
|
||||
}
|
||||
|
@ -374,8 +417,15 @@ namespace Greenshot {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the ini-file changes
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ReloadConfiguration(object source, FileSystemEventArgs e) {
|
||||
lang.Load();
|
||||
lang.SetLanguage(conf.Language);
|
||||
lang.FreeResources();
|
||||
this.Invoke((MethodInvoker) delegate {
|
||||
// Even update language when needed
|
||||
UpdateUI();
|
||||
|
@ -392,9 +442,6 @@ namespace Greenshot {
|
|||
|
||||
#region hotkeys
|
||||
protected override void WndProc(ref Message m) {
|
||||
if (ClipboardHelper.HandleClipboardMessages(ref m)) {
|
||||
return;
|
||||
}
|
||||
if (HotkeyControl.HandleMessages(ref m)) {
|
||||
return;
|
||||
}
|
||||
|
@ -503,8 +550,9 @@ namespace Greenshot {
|
|||
|
||||
#region mainform events
|
||||
void MainFormFormClosing(object sender, FormClosingEventArgs e) {
|
||||
LOG.DebugFormat("Mainform closing, reason: {0}", e.CloseReason);
|
||||
instance = null;
|
||||
exit();
|
||||
Exit();
|
||||
}
|
||||
|
||||
void MainFormActivated(object sender, EventArgs e) {
|
||||
|
@ -515,98 +563,103 @@ namespace Greenshot {
|
|||
|
||||
#region key handlers
|
||||
void CaptureRegion() {
|
||||
captureForm.MakeCapture(CaptureMode.Region, true);
|
||||
CaptureHelper.CaptureRegion(true);
|
||||
}
|
||||
void CaptureClipboard() {
|
||||
captureForm.MakeCapture(CaptureMode.Clipboard, false);
|
||||
CaptureHelper.CaptureClipboard();
|
||||
}
|
||||
|
||||
void CaptureFile() {
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Filter = "Image files (*.png, *.jpg, *.gif, *.bmp, *.ico)|*.png; *.jpg; *.jpeg; *.gif; *.bmp; *.ico";
|
||||
openFileDialog.Filter = "Image files (*.png, *.jpg, *.gif, *.bmp, *.ico, *.tiff, *.wmf)|*.png; *.jpg; *.jpeg; *.gif; *.bmp; *.ico; *.tiff; *.tif; *.wmf";
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
||||
if (File.Exists(openFileDialog.FileName)) {
|
||||
captureForm.MakeCapture(openFileDialog.FileName);
|
||||
CaptureHelper.CaptureFile(openFileDialog.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CaptureFullScreen() {
|
||||
captureForm.MakeCapture(CaptureMode.FullScreen, true);
|
||||
CaptureHelper.CaptureFullscreen(true);
|
||||
}
|
||||
void CaptureLastRegion() {
|
||||
captureForm.MakeCapture(CaptureMode.LastRegion, true);
|
||||
CaptureHelper.CaptureLastRegion(true);
|
||||
}
|
||||
void CaptureIE() {
|
||||
captureForm.MakeCapture(CaptureMode.IE, true);
|
||||
CaptureHelper.CaptureIE(true);
|
||||
}
|
||||
void CaptureWindow() {
|
||||
CaptureMode captureMode = CaptureMode.None;
|
||||
if (conf.CaptureWindowsInteractive) {
|
||||
captureMode = CaptureMode.Window;
|
||||
CaptureHelper.CaptureWindowInteractive(true);
|
||||
} else {
|
||||
captureMode = CaptureMode.ActiveWindow;
|
||||
CaptureHelper.CaptureWindow(true);
|
||||
}
|
||||
captureForm.MakeCapture(captureMode, true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region contextmenu
|
||||
void ContextMenuOpening(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
if (Clipboard.ContainsImage()) {
|
||||
contextmenu_captureclipboard.Enabled = true;
|
||||
} else {
|
||||
contextmenu_captureclipboard.Enabled = false;
|
||||
}
|
||||
contextmenu_captureclipboard.Enabled = ClipboardHelper.ContainsImage();
|
||||
contextmenu_capturelastregion.Enabled = RuntimeConfig.LastCapturedRegion != Rectangle.Empty;
|
||||
|
||||
// IE context menu code
|
||||
if (conf.IECapture && IECaptureHelper.IsIERunning()) {
|
||||
this.contextmenu_captureie.Enabled = true;
|
||||
} else {
|
||||
this.contextmenu_captureie.Enabled = false;
|
||||
try {
|
||||
if (conf.IECapture && IECaptureHelper.IsIERunning()) {
|
||||
this.contextmenu_captureie.Enabled = true;
|
||||
} else {
|
||||
this.contextmenu_captureie.Enabled = false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.WarnFormat("Problem accessing IE information: {0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
void ContextMenuClosing(object sender, EventArgs e) {
|
||||
this.contextmenu_captureie.DropDownItems.Clear();
|
||||
this.contextmenu_capturewindow.DropDownItems.Clear();
|
||||
cleanupThumbnail();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a selectable list of IE tabs when we enter the menu item
|
||||
/// </summary>
|
||||
void EnterCaptureIEMenuItem(object sender, EventArgs e) {
|
||||
List<KeyValuePair<WindowDetails, string>> tabs = IECaptureHelper.GetTabList();
|
||||
this.contextmenu_captureie.DropDownItems.Clear();
|
||||
if (tabs.Count > 0) {
|
||||
this.contextmenu_captureie.Enabled = true;
|
||||
Dictionary<WindowDetails, int> counter = new Dictionary<WindowDetails, int>();
|
||||
|
||||
foreach(KeyValuePair<WindowDetails, string> tabData in tabs) {
|
||||
ToolStripMenuItem captureIETabItem = new ToolStripMenuItem(tabData.Value);
|
||||
int index;
|
||||
if (counter.ContainsKey(tabData.Key)) {
|
||||
index = counter[tabData.Key];
|
||||
} else {
|
||||
index = 0;
|
||||
void CaptureIEMenuDropDownOpening(object sender, EventArgs e) {
|
||||
try {
|
||||
List<KeyValuePair<WindowDetails, string>> tabs = IECaptureHelper.GetTabList();
|
||||
this.contextmenu_captureie.DropDownItems.Clear();
|
||||
if (tabs.Count > 0) {
|
||||
this.contextmenu_captureie.Enabled = true;
|
||||
Dictionary<WindowDetails, int> counter = new Dictionary<WindowDetails, int>();
|
||||
|
||||
foreach(KeyValuePair<WindowDetails, string> tabData in tabs) {
|
||||
ToolStripMenuItem captureIETabItem = new ToolStripMenuItem(tabData.Value);
|
||||
int index;
|
||||
if (counter.ContainsKey(tabData.Key)) {
|
||||
index = counter[tabData.Key];
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
captureIETabItem.Tag = new KeyValuePair<WindowDetails, int>(tabData.Key, index++);
|
||||
captureIETabItem.Click += new System.EventHandler(Contextmenu_captureIE_Click);
|
||||
this.contextmenu_captureie.DropDownItems.Add(captureIETabItem);
|
||||
if (counter.ContainsKey(tabData.Key)) {
|
||||
counter[tabData.Key] = index;
|
||||
} else {
|
||||
counter.Add(tabData.Key, index);
|
||||
}
|
||||
}
|
||||
captureIETabItem.Tag = new KeyValuePair<WindowDetails, int>(tabData.Key, index++);
|
||||
captureIETabItem.Click += new System.EventHandler(Contextmenu_captureIE_Click);
|
||||
this.contextmenu_captureie.DropDownItems.Add(captureIETabItem);
|
||||
if (counter.ContainsKey(tabData.Key)) {
|
||||
counter[tabData.Key] = index;
|
||||
} else {
|
||||
counter.Add(tabData.Key, index);
|
||||
}
|
||||
} else {
|
||||
this.contextmenu_captureie.Enabled = false;
|
||||
}
|
||||
} else {
|
||||
this.contextmenu_captureie.Enabled = false;
|
||||
} catch (Exception ex) {
|
||||
LOG.WarnFormat("Problem accessing IE information: {0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Build a selectable list of windows when we enter the menu item
|
||||
/// </summary>
|
||||
void EnterCaptureWindowMenuItem(object sender, EventArgs e) {
|
||||
private void CaptureWindowMenuDropDownOpening(object sender, EventArgs e) {
|
||||
// The Capture window context menu item used to go to the following code:
|
||||
// captureForm.MakeCapture(CaptureMode.Window, false);
|
||||
// Now we check which windows are there to capture
|
||||
|
@ -614,46 +667,146 @@ namespace Greenshot {
|
|||
AddCaptureWindowMenuItems(captureWindowMenuItem, Contextmenu_window_Click);
|
||||
}
|
||||
|
||||
public static void AddCaptureWindowMenuItems(ToolStripMenuItem menuItem, EventHandler eventHandler) {
|
||||
private void CaptureWindowMenuDropDownClosed(object sender, EventArgs e) {
|
||||
cleanupThumbnail();
|
||||
}
|
||||
|
||||
private void ShowThumbnailOnEnter(object sender, EventArgs e) {
|
||||
ToolStripMenuItem captureWindowItem = sender as ToolStripMenuItem;
|
||||
WindowDetails window = captureWindowItem.Tag as WindowDetails;
|
||||
parentMenuBounds = captureWindowItem.GetCurrentParent().TopLevelControl.Bounds;
|
||||
if (thumbnailForm == null) {
|
||||
thumbnailForm = new FormWithoutActivation();
|
||||
thumbnailForm.ShowInTaskbar = false;
|
||||
thumbnailForm.FormBorderStyle = FormBorderStyle.None;
|
||||
thumbnailForm.TopMost = false;
|
||||
thumbnailForm.Enabled = false;
|
||||
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
|
||||
thumbnailForm.BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
|
||||
} else {
|
||||
thumbnailForm.BackColor = Color.White;
|
||||
}
|
||||
}
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
DWM.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
thumbnailHandle = IntPtr.Zero;
|
||||
}
|
||||
DWM.DwmRegisterThumbnail(thumbnailForm.Handle, window.Handle, out thumbnailHandle);
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
Rectangle windowRectangle = window.WindowRectangle;
|
||||
int thumbnailHeight = 200;
|
||||
int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
|
||||
if (thumbnailWidth > parentMenuBounds.Width) {
|
||||
thumbnailWidth = parentMenuBounds.Width;
|
||||
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
|
||||
}
|
||||
thumbnailForm.Width = thumbnailWidth;
|
||||
thumbnailForm.Height = thumbnailHeight;
|
||||
// Prepare the displaying of the Thumbnail
|
||||
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
|
||||
props.Opacity = (byte)255;
|
||||
props.Visible = true;
|
||||
props.SourceClientAreaOnly = false;
|
||||
props.Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight);
|
||||
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
|
||||
if (!thumbnailForm.Visible) {
|
||||
thumbnailForm.Show();
|
||||
}
|
||||
// Make sure it's on "top"!
|
||||
User32.SetWindowPos(thumbnailForm.Handle,captureWindowItem.GetCurrentParent().TopLevelControl.Handle, 0,0,0,0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
|
||||
|
||||
// Align to menu
|
||||
Rectangle screenBounds = WindowCapture.GetScreenBounds();
|
||||
if (screenBounds.Contains(parentMenuBounds.Left, parentMenuBounds.Top - thumbnailHeight)) {
|
||||
thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width/2) - (thumbnailWidth/2), parentMenuBounds.Top - thumbnailHeight);
|
||||
} else {
|
||||
thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width/2) - (thumbnailWidth/2), parentMenuBounds.Bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HideThumbnailOnLeave(object sender, EventArgs e) {
|
||||
hideThumbnail();
|
||||
}
|
||||
|
||||
private void hideThumbnail() {
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
DWM.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
thumbnailHandle = IntPtr.Zero;
|
||||
thumbnailForm.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupThumbnail() {
|
||||
hideThumbnail();
|
||||
|
||||
if (thumbnailForm != null) {
|
||||
thumbnailForm.Close();
|
||||
thumbnailForm = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCaptureWindowMenuItems(ToolStripMenuItem menuItem, EventHandler eventHandler) {
|
||||
ILanguage lang = Language.GetInstance();
|
||||
menuItem.DropDownItems.Clear();
|
||||
// check if thumbnailPreview is enabled and DWM is enabled
|
||||
bool thumbnailPreview = conf.ThumnailPreview && DWM.isDWMEnabled();
|
||||
|
||||
List<WindowDetails> windows = WindowDetails.GetVisibleWindows();
|
||||
foreach(WindowDetails window in windows) {
|
||||
ToolStripMenuItem captureWindowItem = new ToolStripMenuItem(window.Text);
|
||||
captureWindowItem.Tag = window;
|
||||
captureWindowItem.Image = window.DisplayIcon;
|
||||
captureWindowItem.Click += new System.EventHandler(eventHandler);
|
||||
// Only show preview when enabled
|
||||
if (thumbnailPreview) {
|
||||
captureWindowItem.MouseEnter += new System.EventHandler(ShowThumbnailOnEnter);
|
||||
captureWindowItem.MouseLeave += new System.EventHandler(HideThumbnailOnLeave);
|
||||
}
|
||||
menuItem.DropDownItems.Add(captureWindowItem);
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureAreaToolStripMenuItemClick(object sender, EventArgs e) {
|
||||
captureForm.MakeCapture(CaptureMode.Region, false);
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureHelper.CaptureRegion(false);
|
||||
});
|
||||
}
|
||||
|
||||
void CaptureClipboardToolStripMenuItemClick(object sender, EventArgs e) {
|
||||
CaptureClipboard();
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureHelper.CaptureClipboard();
|
||||
});
|
||||
}
|
||||
|
||||
void OpenFileToolStripMenuItemClick(object sender, EventArgs e) {
|
||||
CaptureFile();
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureFile();
|
||||
});
|
||||
}
|
||||
|
||||
void CaptureFullScreenToolStripMenuItemClick(object sender, EventArgs e) {
|
||||
captureForm.MakeCapture(CaptureMode.FullScreen, false);
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureHelper.CaptureFullscreen(false);
|
||||
});
|
||||
}
|
||||
|
||||
void Contextmenu_capturelastregionClick(object sender, EventArgs e) {
|
||||
captureForm.MakeCapture(CaptureMode.LastRegion, false);
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
CaptureHelper.CaptureLastRegion(false);
|
||||
});
|
||||
}
|
||||
|
||||
void Contextmenu_window_Click(object sender,EventArgs e) {
|
||||
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
|
||||
try {
|
||||
WindowDetails windowToCapture = (WindowDetails)clickedItem.Tag;
|
||||
captureForm.MakeCapture(windowToCapture);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
try {
|
||||
WindowDetails windowToCapture = (WindowDetails)clickedItem.Tag;
|
||||
CaptureHelper.CaptureWindow(windowToCapture);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Contextmenu_captureIE_Click(object sender, EventArgs e) {
|
||||
|
@ -663,109 +816,187 @@ namespace Greenshot {
|
|||
}
|
||||
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
|
||||
KeyValuePair<WindowDetails, int> tabData = (KeyValuePair<WindowDetails, int>)clickedItem.Tag;
|
||||
try {
|
||||
IECaptureHelper.ActivateIETab(tabData.Key, tabData.Value);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
try {
|
||||
captureForm.MakeCapture(CaptureMode.IE, false);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
try {
|
||||
IECaptureHelper.ActivateIETab(tabData.Key, tabData.Value);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
try {
|
||||
CaptureHelper.CaptureIE(false);
|
||||
} catch (Exception exception) {
|
||||
LOG.Error(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Contextmenu_donateClick(object sender, EventArgs e) {
|
||||
Process.Start("http://getgreenshot.org/support/");
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
Process.Start("http://getgreenshot.org/support/");
|
||||
});
|
||||
}
|
||||
|
||||
void Contextmenu_settingsClick(object sender, EventArgs e) {
|
||||
SettingsForm settings = new SettingsForm();
|
||||
settings.ShowDialog();
|
||||
InitializeQuickSettingsMenu();
|
||||
this.Hide();
|
||||
BeginInvoke((MethodInvoker)delegate {
|
||||
ShowSetting();
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowSetting() {
|
||||
if (settingsForm != null) {
|
||||
WindowDetails.ToForeground(settingsForm.Handle);
|
||||
} else {
|
||||
try {
|
||||
using (settingsForm = new SettingsForm()) {
|
||||
if (settingsForm.ShowDialog() == DialogResult.OK) {
|
||||
InitializeQuickSettingsMenu();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
settingsForm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Contextmenu_aboutClick(object sender, EventArgs e) {
|
||||
new AboutForm().Show();
|
||||
if (aboutForm != null) {
|
||||
WindowDetails.ToForeground(aboutForm.Handle);
|
||||
} else {
|
||||
try {
|
||||
using (aboutForm = new AboutForm()) {
|
||||
aboutForm.ShowDialog();
|
||||
}
|
||||
} finally {
|
||||
aboutForm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Contextmenu_helpClick(object sender, EventArgs e) {
|
||||
HelpBrowserForm hpf = new HelpBrowserForm(conf.Language);
|
||||
hpf.Show();
|
||||
if (helpBrowserForm != null) {
|
||||
WindowDetails.ToForeground(helpBrowserForm.Handle);
|
||||
} else {
|
||||
try {
|
||||
using (helpBrowserForm = new HelpBrowserForm(conf.Language)) {
|
||||
helpBrowserForm.ShowDialog();
|
||||
}
|
||||
} finally {
|
||||
helpBrowserForm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Contextmenu_exitClick(object sender, EventArgs e) {
|
||||
exit();
|
||||
Exit();
|
||||
}
|
||||
|
||||
private void InitializeQuickSettingsMenu() {
|
||||
this.contextmenu_quicksettings.DropDownItems.Clear();
|
||||
// screenshot destination
|
||||
ToolStripMenuSelectList selectList = new ToolStripMenuSelectList("destination",true);
|
||||
ToolStripMenuSelectList selectList = new ToolStripMenuSelectList("destinations",true);
|
||||
selectList.Text = lang.GetString(LangKey.settings_destination);
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_destination_editor), Destination.Editor, conf.OutputDestinations.Contains(Destination.Editor));
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_destination_clipboard), Destination.Clipboard, conf.OutputDestinations.Contains(Destination.Clipboard));
|
||||
selectList.AddItem(lang.GetString(LangKey.quicksettings_destination_file), Destination.FileDefault, conf.OutputDestinations.Contains(Destination.FileDefault));
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_destination_fileas), Destination.FileWithDialog, conf.OutputDestinations.Contains(Destination.FileWithDialog));
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_destination_printer), Destination.Printer, conf.OutputDestinations.Contains(Destination.Printer));
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_destination_email), Destination.EMail, conf.OutputDestinations.Contains(Destination.EMail));
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||
// Working with IDestination:
|
||||
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
|
||||
selectList.AddItem(destination.Description, destination, conf.OutputDestinations.Contains(destination.Designation));
|
||||
}
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingDestinationChanged);
|
||||
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
|
||||
|
||||
// Capture Modes
|
||||
selectList = new ToolStripMenuSelectList("capturemodes", false);
|
||||
selectList.Text = lang.GetString(LangKey.settings_window_capture_mode);
|
||||
string enumTypeName = typeof(WindowCaptureMode).Name;
|
||||
foreach(WindowCaptureMode captureMode in Enum.GetValues(typeof(WindowCaptureMode))) {
|
||||
selectList.AddItem(lang.GetString(enumTypeName + "." + captureMode.ToString()), captureMode, conf.WindowCaptureMode == captureMode);
|
||||
}
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingCaptureModeChanged);
|
||||
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
|
||||
|
||||
// print options
|
||||
selectList = new ToolStripMenuSelectList("printoptions",true);
|
||||
selectList.Text = lang.GetString(LangKey.settings_printoptions);
|
||||
selectList.AddItem(lang.GetString(LangKey.printoptions_allowshrink), "AllowPrintShrink", conf.OutputPrintAllowShrink);
|
||||
selectList.AddItem(lang.GetString(LangKey.printoptions_allowenlarge), "AllowPrintEnlarge", conf.OutputPrintAllowEnlarge);
|
||||
selectList.AddItem(lang.GetString(LangKey.printoptions_allowrotate), "AllowPrintRotate", conf.OutputPrintAllowRotate);
|
||||
selectList.AddItem(lang.GetString(LangKey.printoptions_allowcenter), "AllowPrintCenter", conf.OutputPrintCenter);
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||
|
||||
IniValue iniValue;
|
||||
foreach(string propertyName in conf.Values.Keys) {
|
||||
if (propertyName.StartsWith("OutputPrint")) {
|
||||
iniValue = conf.Values[propertyName];
|
||||
selectList.AddItem(lang.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
|
||||
}
|
||||
}
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged);
|
||||
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
|
||||
|
||||
// effects
|
||||
selectList = new ToolStripMenuSelectList("effects",true);
|
||||
selectList.Text = lang.GetString(LangKey.settings_visualization);
|
||||
selectList.AddItem(lang.GetString(LangKey.settings_playsound), "PlaySound", conf.PlayCameraSound);
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||
|
||||
iniValue = conf.Values["PlayCameraSound"];
|
||||
selectList.AddItem(lang.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
|
||||
iniValue = conf.Values["ShowTrayNotification"];
|
||||
selectList.AddItem(lang.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value);
|
||||
selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged);
|
||||
this.contextmenu_quicksettings.DropDownItems.Add(selectList);
|
||||
}
|
||||
|
||||
void QuickSettingItemChanged(object sender, EventArgs e) {
|
||||
ToolStripMenuSelectList selectList = (ToolStripMenuSelectList)sender;
|
||||
void QuickSettingCaptureModeChanged(object sender, EventArgs e) {
|
||||
ToolStripMenuSelectListItem item = ((ItemCheckedChangedEventArgs)e).Item;
|
||||
if(selectList.Identifier.Equals("destination")) {
|
||||
Destination selectedDestination = (Destination)item.Data;
|
||||
if (item.Checked && !conf.OutputDestinations.Contains(selectedDestination)) {
|
||||
conf.OutputDestinations.Add(selectedDestination);
|
||||
}
|
||||
if (!item.Checked && conf.OutputDestinations.Contains(selectedDestination)) {
|
||||
conf.OutputDestinations.Remove(selectedDestination);
|
||||
}
|
||||
IniConfig.Save();
|
||||
} else if(selectList.Identifier.Equals("printoptions")) {
|
||||
if(item.Data.Equals("AllowPrintShrink")) conf.OutputPrintAllowShrink = item.Checked;
|
||||
else if(item.Data.Equals("AllowPrintEnlarge")) conf.OutputPrintAllowEnlarge = item.Checked;
|
||||
else if(item.Data.Equals("AllowPrintRotate")) conf.OutputPrintAllowRotate = item.Checked;
|
||||
else if(item.Data.Equals("AllowPrintCenter")) conf.OutputPrintCenter = item.Checked;
|
||||
IniConfig.Save();
|
||||
} else if(selectList.Identifier.Equals("effects")) {
|
||||
if(item.Data.Equals("PlaySound")) {
|
||||
conf.PlayCameraSound = item.Checked;
|
||||
}
|
||||
IniConfig.Save();
|
||||
|
||||
WindowCaptureMode windowsCaptureMode = (WindowCaptureMode)item.Data;
|
||||
if (item.Checked) {
|
||||
conf.WindowCaptureMode = windowsCaptureMode;
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingBoolItemChanged(object sender, EventArgs e) {
|
||||
ToolStripMenuSelectListItem item = ((ItemCheckedChangedEventArgs)e).Item;
|
||||
IniValue iniValue = item.Data as IniValue;
|
||||
if (iniValue != null) {
|
||||
iniValue.Value = item.Checked;
|
||||
IniConfig.Save();
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingDestinationChanged(object sender, EventArgs e) {
|
||||
ToolStripMenuSelectListItem item = ((ItemCheckedChangedEventArgs)e).Item;
|
||||
IDestination selectedDestination = (IDestination)item.Data;
|
||||
if (item.Checked && selectedDestination.Designation.Equals("Picker")) {
|
||||
foreach(ToolStripMenuSelectList ddi in contextmenu_quicksettings.DropDownItems) {
|
||||
if (ddi.Identifier.Equals("destinations")) {
|
||||
foreach(ToolStripMenuSelectListItem dropDownItem in ddi.DropDownItems) {
|
||||
IDestination destination = dropDownItem.Data as IDestination;
|
||||
if (!destination.Designation.Equals("Picker")) {
|
||||
if (dropDownItem.CheckState == CheckState.Checked) {
|
||||
dropDownItem.CheckState = CheckState.Unchecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
conf.OutputDestinations.Clear();
|
||||
conf.OutputDestinations.Add(selectedDestination.Designation);
|
||||
} else {
|
||||
if (item.Checked && !conf.OutputDestinations.Contains(selectedDestination.Designation)) {
|
||||
conf.OutputDestinations.Add(selectedDestination.Designation);
|
||||
}
|
||||
if (!item.Checked && conf.OutputDestinations.Contains(selectedDestination.Designation)) {
|
||||
conf.OutputDestinations.Remove(selectedDestination.Designation);
|
||||
}
|
||||
}
|
||||
IniConfig.Save();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
|
||||
string exceptionText = EnvironmentInfo.BuildReport(e.ExceptionObject as Exception);
|
||||
LOG.Error(exceptionText);
|
||||
Exception exceptionToLog = e.ExceptionObject as Exception;
|
||||
string exceptionText = EnvironmentInfo.BuildReport(exceptionToLog);
|
||||
LOG.Error(EnvironmentInfo.ExceptionToString(exceptionToLog));
|
||||
new BugReportForm(exceptionText).ShowDialog();
|
||||
}
|
||||
|
||||
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) {
|
||||
string exceptionText = EnvironmentInfo.BuildReport(e.Exception);
|
||||
LOG.Error(exceptionText);
|
||||
Exception exceptionToLog = e.Exception;
|
||||
string exceptionText = EnvironmentInfo.BuildReport(exceptionToLog);
|
||||
LOG.Error(EnvironmentInfo.ExceptionToString(exceptionToLog));
|
||||
new BugReportForm(exceptionText).ShowDialog();
|
||||
}
|
||||
|
||||
|
@ -779,7 +1010,7 @@ namespace Greenshot {
|
|||
/// </summary>
|
||||
private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) {
|
||||
string path;
|
||||
string configPath = FilenameHelper.FillVariables(conf.OutputFilePath);
|
||||
string configPath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
|
||||
string lastFilePath = Path.GetDirectoryName(conf.OutputFileAsFullpath);
|
||||
if (Directory.Exists(lastFilePath)) {
|
||||
path = lastFilePath;
|
||||
|
@ -802,9 +1033,7 @@ namespace Greenshot {
|
|||
/// <summary>
|
||||
/// Shutdown / cleanup
|
||||
/// </summary>
|
||||
public void exit() {
|
||||
ClipboardHelper.DeregisterClipboardViewer(this.Handle);
|
||||
|
||||
public void Exit() {
|
||||
LOG.Info("Exit: " + EnvironmentInfo.EnvironmentToString(false));
|
||||
|
||||
// Close all open forms (except this), use a separate List to make sure we don't get a "InvalidOperationException: Collection was modified"
|
||||
|
@ -852,6 +1081,8 @@ namespace Greenshot {
|
|||
LOG.Error("Error closing application!", e);
|
||||
}
|
||||
|
||||
ImageOutput.RemoveTmpFiles();
|
||||
|
||||
// Store any open configuration changes
|
||||
try {
|
||||
IniConfig.Save();
|
||||
|
@ -876,9 +1107,8 @@ namespace Greenshot {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BackgroundWorkerTimerTick(object sender, EventArgs e) {
|
||||
LOG.Debug("BackgroundWorkerTimerTick");
|
||||
|
||||
if (UpdateHelper.IsUpdateCheckNeeded()) {
|
||||
LOG.Debug("BackgroundWorkerTimerTick checking for update");
|
||||
// Start update check in the background
|
||||
Thread backgroundTask = new Thread (new ThreadStart(UpdateHelper.CheckAndAskForUpdate));
|
||||
backgroundTask.IsBackground = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue