Changed some more properties, now I have a way so supply "defaults" which aren't constants

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@856 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2010-08-24 10:49:48 +00:00
parent 8eafe91ce0
commit 2a1ef29b84
8 changed files with 53 additions and 19 deletions

View file

@ -335,7 +335,7 @@ namespace Greenshot.Forms {
bool fileWritten = false;
if (captureDestinations.Contains(CaptureDestination.File)) {
string filename = FilenameHelper.GetFilenameFromPattern(conf.OutputFileFilenamePattern, conf.OutputFileFormat, captureDetails);
fullPath = Path.Combine(conf.Output_File_Path,filename);
fullPath = Path.Combine(conf.OutputFilePath,filename);
// Catching any exception to prevent that the user can't write in the directory.
// This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642

View file

@ -601,8 +601,8 @@ namespace Greenshot {
string path;
if (lastImagePath != null && Directory.Exists(lastImagePath)) {
path = lastImagePath;
} else if (Directory.Exists(conf.Output_File_Path)) {
path = conf.Output_File_Path;
} else if (Directory.Exists(conf.OutputFilePath)) {
path = conf.OutputFilePath;
} else {
// What do I open when nothing can be found? Right, nothing...
return;

View file

@ -64,7 +64,7 @@ namespace Greenshot.Test
public void SuggestBasicFileNameTest() {
CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
//conf.Output_FileAs_Fullpath = @"c:\path\to\greenshot_testdir\gstest_28.jpg";
conf.Output_File_Path = @"c:\path\to\greenshot_testdir\";
conf.OutputFilePath = @"c:\path\to\greenshot_testdir\";
conf.OutputFileFilenamePattern = "gstest_%NUM%";
conf.OutputFileFormat = OutputFormat.Jpeg;
conf.OutputFileIncrementingNumber = 28;

View file

@ -61,13 +61,16 @@ namespace Greenshot.Core {
[IniProperty("PlayCameraSound", Description="Play a camera sound after taking a capture.", DefaultValue="false")]
public bool PlayCameraSound = false;
public string Output_File_Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
[IniProperty("OutputFilePath", Description="Output file path.")]
public string OutputFilePath;
[IniProperty("OutputFileFilenamePattern", Description="Filename pattern for screenshot.", DefaultValue="%title%_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%")]
public string OutputFileFilenamePattern;
[IniProperty("OutputFileFormat", Description="Default file type for writing screenshots. (Bmp, Gif, Jepg, Png, Tiff)", DefaultValue="Png")]
public OutputFormat OutputFileFormat = OutputFormat.Png;
[IniProperty("OutputFileCopyPathToClipboard", Description="When saving a screenshot, copy the path to the clipboard?", DefaultValue="true")]
public bool OutputFileCopyPathToClipboard;
[IniProperty("OutputFileAsFullpath", Description="SaveAs Full path?")]
public string OutputFileAsFullpath;
[IniProperty("OutputFileJpegQuality", Description="JPEG file save quality in %.", DefaultValue="80")]
public int OutputFileJpegQuality;
@ -76,8 +79,6 @@ namespace Greenshot.Core {
[IniProperty("OutputFileIncrementingNumber", Description="The number for the %NUM% in the filename pattern, is increased automatically after each save.", DefaultValue="1")]
public uint OutputFileIncrementingNumber;
public string Output_FileAs_Fullpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
[IniProperty("OutputPrintPromptOptions", Description="Ask for print options when printing?", DefaultValue="true")]
public bool OutputPrintPromptOptions;
[IniProperty("OutputPrintAllowRotate", Description="Allow rotating the picture for fitting on paper?", DefaultValue="true")]
@ -90,5 +91,23 @@ namespace Greenshot.Core {
public bool OutputPrintCenter;
[IniProperty("OutputPrintTimestamp", Description="Print timestamp on print?", DefaultValue="true")]
public bool OutputPrintTimestamp;
//[IniProperty("Test", Description="Print timestamp on print?", DefaultValue="")]
//public Dictionary<string, bool> testProp;
/// <summary>
/// Supply values we can't put as defaults
/// </summary>
/// <param name="property">The property to return a default for</param>
/// <returns>string with the default value for the supplied property</returns>
public override string GetDefault(string property) {
switch(property) {
case "OutputFileAsFullpath":
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
case "OutputFilePath":
return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
}
return null;
}
}
}

View file

@ -61,10 +61,21 @@ namespace Greenshot.Core {
}
}
// Interface for
public class IniSection {
// Flag to specify if values have been changed
/// <summary>
/// Base class for all IniSections
/// </summary>
public abstract class IniSection {
/// Flag to specify if values have been changed
public bool IsDirty = false;
/// <summary>
/// Supply values we can't put as defaults
/// </summary>
/// <param name="property">The property to return a default for</param>
/// <returns>string with the default value for the supplied property</returns>
public virtual string GetDefault(string property) {
return null;
}
}
public class IniConfig {
@ -179,8 +190,12 @@ namespace Greenshot.Core {
} else {
// Mark as dirty, we didn't use properties from the file (even defaults from the default file are allowed)
section.IsDirty = true;
propertyValue = iniPropertyAttribute.DefaultValue;
LOG.Debug("Using default property for " + propertyName + " : " + propertyValue);
if (iniPropertyAttribute.DefaultValue != null) {
propertyValue = iniPropertyAttribute.DefaultValue;
} else {
propertyValue = section.GetDefault(propertyName);
}
LOG.Debug("Using default: " + propertyName + "=" + propertyValue);
}
// Get the type, or the underlying type for nullables

View file

@ -57,7 +57,7 @@ namespace Greenshot.Forms {
private void init() {
saveFileDialog = new SaveFileDialog();
applyFilterOptions();
saveFileDialog.InitialDirectory = Path.GetDirectoryName(conf.Output_FileAs_Fullpath);
saveFileDialog.InitialDirectory = Path.GetDirectoryName(conf.OutputFileAsFullpath);
// The following property fixes a problem that the directory where we save is locked (bug #2899790)
saveFileDialog.RestoreDirectory = true;
@ -73,7 +73,7 @@ namespace Greenshot.Forms {
for(int i=0; i<filterOptions.Length; i++){
FilterOption fo = filterOptions[i];
fdf += fo.Label + "|*." + fo.Extension + "|";
if(conf.Output_FileAs_Fullpath.EndsWith(fo.Extension, StringComparison.CurrentCultureIgnoreCase)) preselect = i;
if(conf.OutputFileAsFullpath.EndsWith(fo.Extension, StringComparison.CurrentCultureIgnoreCase)) preselect = i;
}
fdf = fdf.Substring(0, fdf.Length-1);
saveFileDialog.Filter = fdf;
@ -203,7 +203,7 @@ namespace Greenshot.Forms {
}
private string GetRootDirFromConfig() {
string rootDir =conf.Output_File_Path;
string rootDir =conf.OutputFilePath;
// the idea was to let the user choose whether to suggest the dir
// configured in the settings dialog or just remember the latest path.
// however, we'd need an extra option for this, making the settings dialog

View file

@ -170,7 +170,7 @@ namespace Greenshot {
private void DisplaySettings() {
combobox_language.SelectedValue = lang.CurrentLanguage;
checkbox_registerhotkeys.Checked = conf.RegisterHotkeys;
textbox_storagelocation.Text = conf.Output_File_Path;
textbox_storagelocation.Text = conf.OutputFilePath;
textbox_screenshotname.Text = conf.OutputFileFilenamePattern;
combobox_primaryimageformat.Text = conf.OutputFileFormat.ToString();
checkbox_copypathtoclipboard.Checked = conf.OutputFileCopyPathToClipboard;
@ -217,7 +217,7 @@ namespace Greenshot {
//MainForm.instance.UpdateUI(); // TODO
conf.RegisterHotkeys = checkbox_registerhotkeys.Checked;
conf.Output_File_Path = textbox_storagelocation.Text;
conf.OutputFilePath = textbox_storagelocation.Text;
conf.OutputFileFilenamePattern = textbox_screenshotname.Text;
conf.OutputFileFormat = (OutputFormat)Enum.Parse(typeof(OutputFormat), combobox_primaryimageformat.Text);
conf.OutputFileCopyPathToClipboard = checkbox_copypathtoclipboard.Checked;

View file

@ -157,7 +157,7 @@ namespace Greenshot.Helpers
string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
ImageOutput.Save(image, fileNameWithExtension, captureDetails);
returnValue = fileNameWithExtension;
conf.Output_FileAs_Fullpath = fileNameWithExtension;
conf.OutputFileAsFullpath = fileNameWithExtension;
IniConfig.Save();
} catch(System.Runtime.InteropServices.ExternalException) {
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetInstance().GetString(LangKey.error));