Code quality changes [skip ci]

This commit is contained in:
Robin 2016-08-16 10:37:55 +02:00
parent 61cfe004c5
commit 798ca503a5
108 changed files with 1981 additions and 2258 deletions

View file

@ -34,12 +34,12 @@ namespace GreenshotDropboxPlugin {
/// This is the Dropbox base code
/// </summary>
public class DropboxPlugin : IGreenshotPlugin {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DropboxPlugin));
private static DropboxPluginConfiguration config;
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(DropboxPlugin));
private static DropboxPluginConfiguration _config;
public static PluginAttribute Attributes;
private IGreenshotHost host;
private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInConfig;
private IGreenshotHost _host;
private ComponentResourceManager _resources;
private ToolStripMenuItem _itemPlugInConfig;
public void Dispose() {
Dispose(true);
@ -48,9 +48,9 @@ namespace GreenshotDropboxPlugin {
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
if (_itemPlugInConfig != null) {
_itemPlugInConfig.Dispose();
_itemPlugInConfig = null;
}
}
}
@ -70,56 +70,48 @@ namespace GreenshotDropboxPlugin {
/// <summary>
/// Implementation of the IGreenshotPlugin.Initialize
/// </summary>
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
/// <param name="pluginAttribute">My own attributes</param>
/// <param name="pluginHost">Use the IGreenshotPluginHost interface to register events</param>
/// <param name="myAttributes">My own attributes</param>
public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) {
host = (IGreenshotHost)pluginHost;
_host = pluginHost;
Attributes = myAttributes;
// Register configuration (don't need the configuration itself)
config = IniConfig.GetIniSection<DropboxPluginConfiguration>();
resources = new ComponentResourceManager(typeof(DropboxPlugin));
_config = IniConfig.GetIniSection<DropboxPluginConfiguration>();
_resources = new ComponentResourceManager(typeof(DropboxPlugin));
itemPlugInConfig = new ToolStripMenuItem();
itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure);
itemPlugInConfig.Tag = host;
itemPlugInConfig.Click += new EventHandler(ConfigMenuClick);
itemPlugInConfig.Image = (Image)resources.GetObject("Dropbox");
_itemPlugInConfig = new ToolStripMenuItem
{
Text = Language.GetString("dropbox", LangKey.Configure),
Tag = _host,
Image = (Image)_resources.GetObject("Dropbox")
};
_itemPlugInConfig.Click += ConfigMenuClick;
PluginUtils.AddToContextMenu(host, itemPlugInConfig);
Language.LanguageChanged += new LanguageChangedHandler(OnLanguageChanged);
PluginUtils.AddToContextMenu(_host, _itemPlugInConfig);
Language.LanguageChanged += OnLanguageChanged;
return true;
}
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure);
if (_itemPlugInConfig != null) {
_itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure);
}
}
public virtual void Shutdown() {
LOG.Debug("Dropbox Plugin shutdown.");
Log.Debug("Dropbox Plugin shutdown.");
}
/// <summary>
/// Implementation of the IPlugin.Configure
/// </summary>
public virtual void Configure() {
config.ShowConfigDialog();
}
/// <summary>
/// This will be called when Greenshot is shutting down
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Closing(object sender, FormClosingEventArgs e) {
LOG.Debug("Application closing, de-registering Dropbox Plugin!");
Shutdown();
_config.ShowConfigDialog();
}
public void ConfigMenuClick(object sender, EventArgs eventArgs) {
config.ShowConfigDialog();
_config.ShowConfigDialog();
}
/// <summary>
@ -127,12 +119,12 @@ namespace GreenshotDropboxPlugin {
/// </summary>
public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) {
uploadUrl = null;
SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false);
SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, false);
try {
string dropboxUrl = null;
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait),
delegate() {
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));
dropboxUrl = DropboxUtils.UploadToDropbox(surfaceToUpload, outputSettings, filename);
}
);
@ -142,7 +134,7 @@ namespace GreenshotDropboxPlugin {
uploadUrl = dropboxUrl;
return true;
} catch (Exception e) {
LOG.Error(e);
Log.Error(e);
MessageBox.Show(Language.GetString("dropbox", LangKey.upload_failure) + " " + e.Message);
return false;
}