mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
Refactoring some more classes, making easier code in plug-ins possible. Needed this for better testing some problems with the CreateShadow function.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2094 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
017b874de3
commit
9488200886
20 changed files with 128 additions and 190 deletions
148
GreenshotPlugin/Controls/QualityDialog.Designer.cs
generated
Normal file
148
GreenshotPlugin/Controls/QualityDialog.Designer.cs
generated
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace GreenshotPlugin.Controls {
|
||||
partial class QualityDialog {
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
if (components != null) {
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label_choosejpegquality = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.textBoxJpegQuality = new System.Windows.Forms.TextBox();
|
||||
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
|
||||
this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.button_ok = new GreenshotPlugin.Controls.GreenshotButton();
|
||||
this.checkBox_reduceColors = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label_choosejpegquality
|
||||
//
|
||||
this.label_choosejpegquality.Location = new System.Drawing.Point(12, 47);
|
||||
this.label_choosejpegquality.Name = "label_choosejpegquality";
|
||||
this.label_choosejpegquality.Size = new System.Drawing.Size(268, 19);
|
||||
this.label_choosejpegquality.TabIndex = 15;
|
||||
this.label_choosejpegquality.LanguageKey = "jpegqualitydialog_choosejpegquality";
|
||||
//
|
||||
// textBoxJpegQuality
|
||||
//
|
||||
this.textBoxJpegQuality.Location = new System.Drawing.Point(245, 69);
|
||||
this.textBoxJpegQuality.Name = "textBoxJpegQuality";
|
||||
this.textBoxJpegQuality.ReadOnly = true;
|
||||
this.textBoxJpegQuality.Size = new System.Drawing.Size(35, 20);
|
||||
this.textBoxJpegQuality.TabIndex = 16;
|
||||
this.textBoxJpegQuality.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// trackBarJpegQuality
|
||||
//
|
||||
this.trackBarJpegQuality.LargeChange = 10;
|
||||
this.trackBarJpegQuality.Location = new System.Drawing.Point(12, 69);
|
||||
this.trackBarJpegQuality.Maximum = 100;
|
||||
this.trackBarJpegQuality.Name = "trackBarJpegQuality";
|
||||
this.trackBarJpegQuality.Size = new System.Drawing.Size(233, 45);
|
||||
this.trackBarJpegQuality.TabIndex = 14;
|
||||
this.trackBarJpegQuality.TickFrequency = 10;
|
||||
this.trackBarJpegQuality.Scroll += new System.EventHandler(this.TrackBarJpegQualityScroll);
|
||||
//
|
||||
// checkbox_dontaskagain
|
||||
//
|
||||
this.checkbox_dontaskagain.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
|
||||
this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
|
||||
this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 106);
|
||||
this.checkbox_dontaskagain.Name = "checkbox_dontaskagain";
|
||||
this.checkbox_dontaskagain.LanguageKey = "qualitydialog_dontaskagain";
|
||||
this.checkbox_dontaskagain.Size = new System.Drawing.Size(268, 37);
|
||||
this.checkbox_dontaskagain.TabIndex = 17;
|
||||
this.checkbox_dontaskagain.TextAlign = System.Drawing.ContentAlignment.TopLeft;
|
||||
this.checkbox_dontaskagain.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button_ok
|
||||
//
|
||||
this.button_ok.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.button_ok.Location = new System.Drawing.Point(205, 149);
|
||||
this.button_ok.Name = "button_ok";
|
||||
this.button_ok.Size = new System.Drawing.Size(75, 23);
|
||||
this.button_ok.TabIndex = 18;
|
||||
this.button_ok.LanguageKey = "OK";
|
||||
this.button_ok.UseVisualStyleBackColor = true;
|
||||
this.button_ok.Click += new System.EventHandler(this.Button_okClick);
|
||||
//
|
||||
// checkBox_reduceColors
|
||||
//
|
||||
this.checkBox_reduceColors.AutoSize = true;
|
||||
this.checkBox_reduceColors.Location = new System.Drawing.Point(12, 11);
|
||||
this.checkBox_reduceColors.Name = "checkBox_reduceColors";
|
||||
this.checkBox_reduceColors.Size = new System.Drawing.Size(95, 17);
|
||||
this.checkBox_reduceColors.TabIndex = 19;
|
||||
this.checkBox_reduceColors.Text = "settings_reducecolors";
|
||||
this.checkBox_reduceColors.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// QualityDialog
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(299, 184);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.checkBox_reduceColors);
|
||||
this.Controls.Add(this.button_ok);
|
||||
this.Controls.Add(this.checkbox_dontaskagain);
|
||||
this.Controls.Add(this.label_choosejpegquality);
|
||||
this.Controls.Add(this.textBoxJpegQuality);
|
||||
this.Controls.Add(this.trackBarJpegQuality);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "QualityDialog";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.LanguageKey = "qualitydialog_title";
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
private GreenshotPlugin.Controls.GreenshotButton button_ok;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain;
|
||||
private System.Windows.Forms.TrackBar trackBarJpegQuality;
|
||||
private System.Windows.Forms.TextBox textBoxJpegQuality;
|
||||
private GreenshotPlugin.Controls.GreenshotLabel label_choosejpegquality;
|
||||
private System.Windows.Forms.CheckBox checkBox_reduceColors;
|
||||
}
|
||||
}
|
69
GreenshotPlugin/Controls/QualityDialog.cs
Normal file
69
GreenshotPlugin/Controls/QualityDialog.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// Description of JpegQualityDialog.
|
||||
/// </summary>
|
||||
public partial class QualityDialog : GreenshotForm {
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
public OutputSettings Settings {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public QualityDialog(OutputSettings outputSettings) {
|
||||
Settings = outputSettings;
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent();
|
||||
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
||||
|
||||
this.checkBox_reduceColors.Checked = Settings.ReduceColors;
|
||||
this.trackBarJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||
this.trackBarJpegQuality.Value = Settings.JPGQuality;
|
||||
this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||
this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
|
||||
WindowDetails.ToForeground(Handle);
|
||||
}
|
||||
|
||||
void Button_okClick(object sender, System.EventArgs e) {
|
||||
Settings.JPGQuality = this.trackBarJpegQuality.Value;
|
||||
Settings.ReduceColors = checkBox_reduceColors.Checked;
|
||||
if (this.checkbox_dontaskagain.Checked) {
|
||||
conf.OutputFileJpegQuality = Settings.JPGQuality;
|
||||
conf.OutputFilePromptQuality = false;
|
||||
conf.OutputFileReduceColors = Settings.ReduceColors;
|
||||
IniConfig.Save();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
|
||||
textBoxJpegQuality.Text = trackBarJpegQuality.Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
209
GreenshotPlugin/Controls/SaveImageFileDialog.cs
Normal file
209
GreenshotPlugin/Controls/SaveImageFileDialog.cs
Normal file
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// Custom dialog for saving images, wraps SaveFileDialog.
|
||||
/// For some reason SFD is sealed :(
|
||||
/// </summary>
|
||||
public class SaveImageFileDialog {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SaveImageFileDialog));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
protected SaveFileDialog saveFileDialog;
|
||||
private FilterOption[] filterOptions;
|
||||
private DirectoryInfo eagerlyCreatedDirectory;
|
||||
private ICaptureDetails captureDetails = null;
|
||||
|
||||
public SaveImageFileDialog() {
|
||||
init();
|
||||
}
|
||||
|
||||
public SaveImageFileDialog(ICaptureDetails captureDetails) {
|
||||
this.captureDetails = captureDetails;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
applyFilterOptions();
|
||||
string initialDirectory = null;
|
||||
try {
|
||||
initialDirectory = Path.GetDirectoryName(conf.OutputFileAsFullpath);
|
||||
} catch {
|
||||
LOG.WarnFormat("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", conf.OutputFileAsFullpath);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory)) {
|
||||
saveFileDialog.InitialDirectory = initialDirectory;
|
||||
} else if (Directory.Exists(conf.OutputFilePath)) {
|
||||
saveFileDialog.InitialDirectory = conf.OutputFilePath;
|
||||
}
|
||||
// The following property fixes a problem that the directory where we save is locked (bug #2899790)
|
||||
saveFileDialog.RestoreDirectory = true;
|
||||
saveFileDialog.OverwritePrompt = true;
|
||||
saveFileDialog.CheckPathExists = false;
|
||||
saveFileDialog.AddExtension = true;
|
||||
ApplySuggestedValues();
|
||||
}
|
||||
|
||||
private void applyFilterOptions() {
|
||||
prepareFilterOptions();
|
||||
string fdf = "";
|
||||
int preselect = 0;
|
||||
for(int i=0; i<filterOptions.Length; i++){
|
||||
FilterOption fo = filterOptions[i];
|
||||
fdf += fo.Label + "|*." + fo.Extension + "|";
|
||||
if(conf.OutputFileAsFullpath.EndsWith(fo.Extension, StringComparison.CurrentCultureIgnoreCase)) preselect = i;
|
||||
}
|
||||
fdf = fdf.Substring(0, fdf.Length-1);
|
||||
saveFileDialog.Filter = fdf;
|
||||
saveFileDialog.FilterIndex = preselect + 1;
|
||||
}
|
||||
|
||||
private void prepareFilterOptions() {
|
||||
OutputFormat[] supportedImageFormats = (OutputFormat[])Enum.GetValues(typeof(OutputFormat));
|
||||
filterOptions = new FilterOption[supportedImageFormats.Length];
|
||||
for(int i=0; i<filterOptions.Length; i++){
|
||||
string ifo = supportedImageFormats[i].ToString();
|
||||
if (ifo.ToLower().Equals("jpeg")) ifo = "Jpg"; // we dont want no jpeg files, so let the dialog check for jpg
|
||||
FilterOption fo = new FilterOption();
|
||||
fo.Label = ifo.ToUpper();
|
||||
fo.Extension = ifo.ToLower();
|
||||
filterOptions.SetValue(fo, i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// filename exactly as typed in the filename field
|
||||
/// </summary>
|
||||
public string FileName {
|
||||
get {return saveFileDialog.FileName;}
|
||||
set {saveFileDialog.FileName = value;}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// initial directory of the dialog
|
||||
/// </summary>
|
||||
public string InitialDirectory {
|
||||
get {return saveFileDialog.InitialDirectory;}
|
||||
set {saveFileDialog.InitialDirectory = value;}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns filename as typed in the filename field with extension.
|
||||
/// if filename field value ends with selected extension, the value is just returned.
|
||||
/// otherwise, the selected extension is appended to the filename.
|
||||
/// </summary>
|
||||
public string FileNameWithExtension {
|
||||
get {
|
||||
string fn = saveFileDialog.FileName;
|
||||
// if the filename contains a valid extension, which is the same like the selected filter item's extension, the filename is okay
|
||||
if(fn.EndsWith(Extension,System.StringComparison.CurrentCultureIgnoreCase)) return fn;
|
||||
// otherwise we just add the selected filter item's extension
|
||||
else return fn + "." + Extension;
|
||||
}
|
||||
set {
|
||||
FileName = Path.GetFileNameWithoutExtension(value);
|
||||
Extension = Path.GetExtension(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets or sets selected extension
|
||||
/// </summary>
|
||||
public string Extension {
|
||||
get {
|
||||
return filterOptions[saveFileDialog.FilterIndex-1].Extension;
|
||||
}
|
||||
set {
|
||||
for(int i=0; i<filterOptions.Length; i++) {
|
||||
if(value.Equals(filterOptions[i].Extension, System.StringComparison.CurrentCultureIgnoreCase)) {
|
||||
saveFileDialog.FilterIndex = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DialogResult ShowDialog() {
|
||||
DialogResult ret = saveFileDialog.ShowDialog();
|
||||
CleanUp();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets InitialDirectory and FileName property of a SaveFileDialog smartly, considering default pattern and last used path
|
||||
/// </summary>
|
||||
/// <param name="sfd">a SaveFileDialog instance</param>
|
||||
private void ApplySuggestedValues() {
|
||||
// build the full path and set dialog properties
|
||||
string filenameFromPattern = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
|
||||
|
||||
FileName = Path.GetFileNameWithoutExtension(filenameFromPattern);
|
||||
Extension = Path.GetExtension(filenameFromPattern);
|
||||
}
|
||||
|
||||
private string GetRootDirFromConfig() {
|
||||
string rootDir = conf.OutputFilePath;
|
||||
rootDir = FilenameHelper.FillVariables(rootDir, false);
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
private class FilterOption {
|
||||
public string Label;
|
||||
public string Extension;
|
||||
}
|
||||
|
||||
private void CleanUp() {
|
||||
// fix for bug #3379053
|
||||
try {
|
||||
if(eagerlyCreatedDirectory != null && eagerlyCreatedDirectory.GetFiles().Length == 0 && eagerlyCreatedDirectory.GetDirectories().Length == 0) {
|
||||
eagerlyCreatedDirectory.Delete();
|
||||
eagerlyCreatedDirectory = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.WarnFormat("Couldn't cleanup directory due to: {0}", e.Message);
|
||||
eagerlyCreatedDirectory = null;
|
||||
}
|
||||
}
|
||||
|
||||
private string CreateDirectoryIfNotExists(string fullPath) {
|
||||
string dirName = null;
|
||||
try {
|
||||
dirName = Path.GetDirectoryName(fullPath);
|
||||
DirectoryInfo di = new DirectoryInfo(dirName);
|
||||
if(!di.Exists) {
|
||||
di = Directory.CreateDirectory(dirName);
|
||||
eagerlyCreatedDirectory = di;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error in CreateDirectoryIfNotExists",e);
|
||||
}
|
||||
return dirName;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue