/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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 .
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Plugin;
namespace GreenshotImgurPlugin {
///
/// This is the ImgurPlugin code
///
[Plugin("Imgur", true)]
public class ImgurPlugin : IGreenshotPlugin {
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ImgurPlugin));
private static ImgurConfiguration _config;
private ComponentResourceManager _resources;
private ToolStripMenuItem _historyMenuItem;
private ToolStripMenuItem _itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (_historyMenuItem != null) {
_historyMenuItem.Dispose();
_historyMenuItem = null;
}
if (_itemPlugInConfig != null) {
_itemPlugInConfig.Dispose();
_itemPlugInConfig = null;
}
}
}
private IEnumerable Destinations() {
yield return new ImgurDestination(this);
}
///
/// Implementation of the IGreenshotPlugin.Initialize
///
/// true if plugin is initialized, false if not (doesn't show)
public bool Initialize() {
// Get configuration
_config = IniConfig.GetIniSection();
_resources = new ComponentResourceManager(typeof(ImgurPlugin));
ToolStripMenuItem itemPlugInRoot = new ToolStripMenuItem("Imgur")
{
Image = (Image) _resources.GetObject("Imgur")
};
// Provide the IDestination
SimpleServiceProvider.Current.AddService(Destinations());
_historyMenuItem = new ToolStripMenuItem(Language.GetString("imgur", LangKey.history));
_historyMenuItem.Click += delegate {
ImgurHistory.ShowHistory();
};
itemPlugInRoot.DropDownItems.Add(_historyMenuItem);
_itemPlugInConfig = new ToolStripMenuItem(Language.GetString("imgur", LangKey.configure));
_itemPlugInConfig.Click += delegate {
_config.ShowConfigDialog();
};
itemPlugInRoot.DropDownItems.Add(_itemPlugInConfig);
PluginUtils.AddToContextMenu(itemPlugInRoot);
Language.LanguageChanged += OnLanguageChanged;
// Enable history if there are items available
UpdateHistoryMenuItem();
return true;
}
public void OnLanguageChanged(object sender, EventArgs e) {
if (_itemPlugInConfig != null) {
_itemPlugInConfig.Text = Language.GetString("imgur", LangKey.configure);
}
if (_historyMenuItem != null) {
_historyMenuItem.Text = Language.GetString("imgur", LangKey.history);
}
}
private void UpdateHistoryMenuItem() {
if (_historyMenuItem == null)
{
return;
}
try
{
var form = SimpleServiceProvider.Current.GetInstance