2013-11-03 23:53:49 +13:00
#region License Information ( GPL v3 )
/ *
ShareX - A program that allows you to take screenshots and share any file type
2014-01-12 20:25:51 +13:00
Copyright ( C ) 2008 - 2014 ShareX Developers
2013-11-03 23:53:49 +13:00
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 2
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 , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
Optionally you can also view the license at < http : //www.gnu.org/licenses/>.
* /
#endregion License Information ( GPL v3 )
using HelpersLib ;
using HistoryLib ;
using ImageEffectsLib ;
2013-11-16 22:11:39 +13:00
using ScreenCaptureLib ;
2013-11-03 23:53:49 +13:00
using ShareX.Properties ;
using System ;
2014-04-01 00:23:47 +13:00
using System.Diagnostics ;
2013-11-21 02:36:02 +13:00
using System.Drawing ;
2014-04-01 00:23:47 +13:00
using System.IO ;
2013-11-03 23:53:49 +13:00
using System.Linq ;
using System.Threading ;
using System.Windows.Forms ;
using UploadersLib ;
namespace ShareX
{
public partial class MainForm : HotkeyForm
{
public bool IsReady { get ; private set ; }
private bool forceClose ;
private UploadInfoManager uim ;
2014-03-05 02:04:46 +13:00
private ToolStripDropDownItem tsmiImageFileUploaders , tsmiTrayImageFileUploaders , tsmiTextFileUploaders , tsmiTrayTextFileUploaders ;
2013-11-03 23:53:49 +13:00
public MainForm ( )
{
InitControls ( ) ;
UpdateControls ( ) ;
HandleCreated + = MainForm_HandleCreated ;
}
private void MainForm_HandleCreated ( object sender , EventArgs e )
{
LoadSettings ( ) ;
InitHotkeys ( ) ;
#if ! DEBUG
AutoCheckUpdate ( ) ;
#endif
IsReady = true ;
DebugHelper . WriteLine ( "Startup time: {0} ms" , Program . StartTimer . ElapsedMilliseconds ) ;
UseCommandLineArgs ( Environment . GetCommandLineArgs ( ) ) ;
}
private void AfterShownJobs ( )
{
this . ShowActivate ( ) ;
}
private void InitControls ( )
{
InitializeComponent ( ) ;
Text = Program . Title ;
2013-11-06 06:58:22 +13:00
Icon = ShareXResources . Icon ;
2013-11-03 23:53:49 +13:00
2014-05-11 23:47:37 +12:00
AddMultiEnumItems < AfterCaptureTasks > ( x = > Program . DefaultTaskSettings . AfterCaptureJob = Program . DefaultTaskSettings . AfterCaptureJob . Swap ( x ) ,
2013-11-03 23:53:49 +13:00
tsddbAfterCaptureTasks , tsmiTrayAfterCaptureTasks ) ;
2014-05-11 23:47:37 +12:00
AddMultiEnumItems < AfterUploadTasks > ( x = > Program . DefaultTaskSettings . AfterUploadJob = Program . DefaultTaskSettings . AfterUploadJob . Swap ( x ) ,
2013-11-03 23:53:49 +13:00
tsddbAfterUploadTasks , tsmiTrayAfterUploadTasks ) ;
2014-05-11 23:47:37 +12:00
AddEnumItems < ImageDestination > ( x = > Program . DefaultTaskSettings . ImageDestination = x , tsmiImageUploaders , tsmiTrayImageUploaders ) ;
2014-03-05 02:04:46 +13:00
tsmiImageFileUploaders = ( ToolStripDropDownItem ) tsmiImageUploaders . DropDownItems [ tsmiImageUploaders . DropDownItems . Count - 1 ] ;
tsmiTrayImageFileUploaders = ( ToolStripDropDownItem ) tsmiTrayImageUploaders . DropDownItems [ tsmiTrayImageUploaders . DropDownItems . Count - 1 ] ;
2014-05-11 23:47:37 +12:00
AddEnumItems < FileDestination > ( x = > Program . DefaultTaskSettings . ImageFileDestination = x , tsmiImageFileUploaders , tsmiTrayImageFileUploaders ) ;
AddEnumItems < TextDestination > ( x = > Program . DefaultTaskSettings . TextDestination = x , tsmiTextUploaders , tsmiTrayTextUploaders ) ;
2014-03-05 02:04:46 +13:00
tsmiTextFileUploaders = ( ToolStripDropDownItem ) tsmiTextUploaders . DropDownItems [ tsmiTextUploaders . DropDownItems . Count - 1 ] ;
tsmiTrayTextFileUploaders = ( ToolStripDropDownItem ) tsmiTrayTextUploaders . DropDownItems [ tsmiTrayTextUploaders . DropDownItems . Count - 1 ] ;
2014-05-11 23:47:37 +12:00
AddEnumItems < FileDestination > ( x = > Program . DefaultTaskSettings . TextFileDestination = x , tsmiTextFileUploaders , tsmiTrayTextFileUploaders ) ;
AddEnumItems < FileDestination > ( x = > Program . DefaultTaskSettings . FileDestination = x , tsmiFileUploaders , tsmiTrayFileUploaders ) ;
AddEnumItems < UrlShortenerType > ( x = > Program . DefaultTaskSettings . URLShortenerDestination = x , tsmiURLShorteners , tsmiTrayURLShorteners ) ;
AddEnumItems < SocialNetworkingService > ( x = > Program . DefaultTaskSettings . SocialNetworkingServiceDestination = x , tsmiSocialServices , tsmiTraySocialServices ) ;
2013-11-03 23:53:49 +13:00
ImageList il = new ImageList ( ) ;
il . ColorDepth = ColorDepth . Depth32Bit ;
il . Images . Add ( Resources . navigation_090_button ) ;
il . Images . Add ( Resources . cross_button ) ;
il . Images . Add ( Resources . tick_button ) ;
il . Images . Add ( Resources . navigation_000_button ) ;
lvUploads . SmallImageList = il ;
TaskManager . ListViewControl = lvUploads ;
uim = new UploadInfoManager ( lvUploads ) ;
}
private void UpdateDestinationStates ( )
{
if ( Program . UploadersConfig ! = null )
{
EnableDisableToolStripMenuItems < ImageDestination > ( tsmiImageUploaders , tsmiTrayImageUploaders ) ;
2014-03-05 02:04:46 +13:00
EnableDisableToolStripMenuItems < FileDestination > ( tsmiImageFileUploaders , tsmiTrayImageFileUploaders ) ;
2013-11-03 23:53:49 +13:00
EnableDisableToolStripMenuItems < TextDestination > ( tsmiTextUploaders , tsmiTrayTextUploaders ) ;
2014-03-05 02:04:46 +13:00
EnableDisableToolStripMenuItems < FileDestination > ( tsmiTextFileUploaders , tsmiTrayTextFileUploaders ) ;
2013-11-03 23:53:49 +13:00
EnableDisableToolStripMenuItems < FileDestination > ( tsmiFileUploaders , tsmiTrayFileUploaders ) ;
EnableDisableToolStripMenuItems < UrlShortenerType > ( tsmiURLShorteners , tsmiTrayURLShorteners ) ;
EnableDisableToolStripMenuItems < SocialNetworkingService > ( tsmiSocialServices , tsmiTraySocialServices ) ;
}
}
private void AddEnumItems < T > ( Action < T > selectedEnum , params ToolStripDropDownItem [ ] parents )
{
string [ ] enums = Helpers . GetEnumDescriptions < T > ( ) ;
foreach ( ToolStripDropDownItem parent in parents )
{
for ( int i = 0 ; i < enums . Length ; i + + )
{
ToolStripMenuItem tsmi = new ToolStripMenuItem ( enums [ i ] ) ;
int index = i ;
tsmi . Click + = ( sender , e ) = >
{
foreach ( ToolStripDropDownItem parent2 in parents )
{
for ( int i2 = 0 ; i2 < enums . Length ; i2 + + )
{
ToolStripMenuItem tsmi2 = ( ToolStripMenuItem ) parent2 . DropDownItems [ i2 ] ;
tsmi2 . Checked = index = = i2 ;
}
}
selectedEnum ( ( T ) Enum . ToObject ( typeof ( T ) , index ) ) ;
UpdateUploaderMenuNames ( ) ;
} ;
parent . DropDownItems . Add ( tsmi ) ;
}
}
}
private void SetEnumChecked ( Enum value , params ToolStripDropDownItem [ ] parents )
{
int index = value . GetIndex ( ) ;
foreach ( ToolStripDropDownItem parent in parents )
{
( ( ToolStripMenuItem ) parent . DropDownItems [ index ] ) . Checked = true ;
}
}
private void AddMultiEnumItems < T > ( Action < T > selectedEnum , params ToolStripDropDownItem [ ] parents )
{
string [ ] enums = Enum . GetValues ( typeof ( T ) ) . Cast < Enum > ( ) . Skip ( 1 ) . Select ( x = > x . GetDescription ( ) ) . ToArray ( ) ;
foreach ( ToolStripDropDownItem parent in parents )
{
for ( int i = 0 ; i < enums . Length ; i + + )
{
ToolStripMenuItem tsmi = new ToolStripMenuItem ( enums [ i ] ) ;
int index = i ;
tsmi . Click + = ( sender , e ) = >
{
foreach ( ToolStripDropDownItem parent2 in parents )
{
ToolStripMenuItem tsmi2 = ( ToolStripMenuItem ) parent2 . DropDownItems [ index ] ;
tsmi2 . Checked = ! tsmi2 . Checked ;
}
selectedEnum ( ( T ) Enum . ToObject ( typeof ( T ) , 1 < < index ) ) ;
UpdateUploaderMenuNames ( ) ;
} ;
parent . DropDownItems . Add ( tsmi ) ;
}
}
}
private void SetMultiEnumChecked ( Enum value , params ToolStripDropDownItem [ ] parents )
{
for ( int i = 0 ; i < parents [ 0 ] . DropDownItems . Count ; i + + )
{
foreach ( ToolStripDropDownItem parent in parents )
{
ToolStripMenuItem tsmi = ( ToolStripMenuItem ) parent . DropDownItems [ i ] ;
tsmi . Checked = value . HasFlag ( 1 < < i ) ;
}
}
}
private void EnableDisableToolStripMenuItems < T > ( params ToolStripDropDownItem [ ] parents )
{
foreach ( ToolStripDropDownItem parent in parents )
{
for ( int i = 0 ; i < parent . DropDownItems . Count ; i + + )
{
parent . DropDownItems [ i ] . Enabled = Program . UploadersConfig . IsActive < T > ( i ) ;
}
}
}
private void UpdateControls ( )
{
cmsUploadInfo . SuspendLayout ( ) ;
tsmiStopUpload . Visible = tsmiOpen . Visible = tsmiCopy . Visible = tsmiShowErrors . Visible = tsmiShowResponse . Visible =
tsmiUploadSelectedFile . Visible = tsmiClearList . Visible = tssUploadInfo1 . Visible = false ;
pbPreview . Reset ( ) ;
uim . RefreshSelectedItems ( ) ;
if ( uim . IsItemSelected )
{
if ( GetCurrentTasks ( ) . Any ( x = > x . IsWorking ) )
{
tsmiStopUpload . Visible = true ;
}
else
{
if ( uim . SelectedItem . Info . Result . IsError )
{
tsmiShowErrors . Visible = true ;
}
2014-04-05 10:56:30 +13:00
// Open
tsmiOpen . Visible = true ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiOpenURL . Enabled = uim . SelectedItem . IsURLExist ;
tsmiOpenShortenedURL . Enabled = uim . SelectedItem . IsShortenedURLExist ;
tsmiOpenThumbnailURL . Enabled = uim . SelectedItem . IsThumbnailURLExist ;
tsmiOpenDeletionURL . Enabled = uim . SelectedItem . IsDeletionURLExist ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiOpenFile . Enabled = uim . SelectedItem . IsFileExist ;
tsmiOpenFolder . Enabled = uim . SelectedItem . IsFileExist ;
2014-04-23 09:00:41 +12:00
tsmiOpenThumbnailFile . Enabled = uim . SelectedItem . IsThumbnailFileExist ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
// Copy
tsmiCopy . Visible = true ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiCopyURL . Enabled = uim . SelectedItems . Any ( x = > x . IsURLExist ) ;
tsmiCopyShortenedURL . Enabled = uim . SelectedItems . Any ( x = > x . IsShortenedURLExist ) ;
tsmiCopyThumbnailURL . Enabled = uim . SelectedItems . Any ( x = > x . IsThumbnailURLExist ) ;
tsmiCopyDeletionURL . Enabled = uim . SelectedItems . Any ( x = > x . IsDeletionURLExist ) ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiCopyFile . Enabled = uim . SelectedItem . IsFileExist ;
tsmiCopyImage . Enabled = uim . SelectedItem . IsImageFile ;
tsmiCopyText . Enabled = uim . SelectedItem . IsTextFile ;
2014-04-23 09:00:41 +12:00
tsmiCopyThumbnailFile . Enabled = uim . SelectedItem . IsThumbnailFileExist ;
tsmiCopyThumbnailImage . Enabled = uim . SelectedItem . IsThumbnailFileExist ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiCopyHTMLLink . Enabled = uim . SelectedItems . Any ( x = > x . IsURLExist ) ;
tsmiCopyHTMLImage . Enabled = uim . SelectedItems . Any ( x = > x . IsImageURL ) ;
tsmiCopyHTMLLinkedImage . Enabled = uim . SelectedItems . Any ( x = > x . IsImageURL & & x . IsThumbnailURLExist ) ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiCopyForumLink . Enabled = uim . SelectedItems . Any ( x = > x . IsURLExist ) ;
tsmiCopyForumImage . Enabled = uim . SelectedItems . Any ( x = > x . IsImageURL & & x . IsURLExist ) ;
tsmiCopyForumLinkedImage . Enabled = uim . SelectedItems . Any ( x = > x . IsImageURL & & x . IsThumbnailURLExist ) ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
tsmiCopyFilePath . Enabled = uim . SelectedItems . Any ( x = > x . IsFilePathValid ) ;
tsmiCopyFileName . Enabled = uim . SelectedItems . Any ( x = > x . IsFilePathValid ) ;
tsmiCopyFileNameWithExtension . Enabled = uim . SelectedItems . Any ( x = > x . IsFilePathValid ) ;
tsmiCopyFolder . Enabled = uim . SelectedItems . Any ( x = > x . IsFilePathValid ) ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
CleanCustomClipboardFormats ( ) ;
2013-11-03 23:53:49 +13:00
2014-04-05 10:56:30 +13:00
if ( Program . Settings . ClipboardContentFormats ! = null & & Program . Settings . ClipboardContentFormats . Count > 0 )
{
tssCopy5 . Visible = true ;
foreach ( ClipboardFormat cf in Program . Settings . ClipboardContentFormats )
{
ToolStripMenuItem tsmiClipboardFormat = new ToolStripMenuItem ( cf . Description ) ;
tsmiClipboardFormat . Tag = cf ;
tsmiClipboardFormat . Click + = tsmiClipboardFormat_Click ;
tsmiCopy . DropDownItems . Add ( tsmiClipboardFormat ) ;
2013-11-03 23:53:49 +13:00
}
}
if ( uim . SelectedItem . Info . Result . IsError & & ! string . IsNullOrEmpty ( uim . SelectedItem . Info . Result . Response ) )
{
tsmiShowResponse . Visible = true ;
}
tsmiUploadSelectedFile . Visible = uim . SelectedItem . IsFileExist ;
}
if ( ! scMain . Panel2Collapsed )
{
if ( uim . SelectedItem . IsImageFile )
{
pbPreview . LoadImageFromFileAsync ( uim . SelectedItem . Info . FilePath ) ;
}
else if ( uim . SelectedItem . IsImageURL )
{
pbPreview . LoadImageFromURLAsync ( uim . SelectedItem . Info . Result . URL ) ;
}
}
}
tsmiClearList . Visible = tssUploadInfo1 . Visible = lvUploads . Items . Count > 0 ;
cmsUploadInfo . ResumeLayout ( ) ;
}
private void CleanCustomClipboardFormats ( )
{
tssCopy5 . Visible = false ;
int tssCopy5Index = tsmiCopy . DropDownItems . IndexOf ( tssCopy5 ) ;
while ( tssCopy5Index < tsmiCopy . DropDownItems . Count - 1 )
{
using ( ToolStripItem tsi = tsmiCopy . DropDownItems [ tsmiCopy . DropDownItems . Count - 1 ] )
{
tsmiCopy . DropDownItems . Remove ( tsi ) ;
}
}
}
private void tsmiClipboardFormat_Click ( object sender , EventArgs e )
{
ToolStripMenuItem tsmiClipboardFormat = sender as ToolStripMenuItem ;
ClipboardFormat cf = tsmiClipboardFormat . Tag as ClipboardFormat ;
uim . CopyCustomFormat ( cf . Format ) ;
}
private void LoadSettings ( )
{
2013-11-06 06:58:22 +13:00
niTray . Icon = ShareXResources . Icon ;
2013-11-03 23:53:49 +13:00
niTray . Visible = Program . Settings . ShowTray ;
2013-11-21 02:36:02 +13:00
if ( Program . Settings . RememberMainFormSize & & ! Program . Settings . MainFormSize . IsEmpty )
{
StartPosition = FormStartPosition . Manual ;
Size = Program . Settings . MainFormSize ;
Screen currentScreen = Screen . FromPoint ( Cursor . Position ) ;
Location = new Point ( currentScreen . Bounds . Width / 2 - Size . Width / 2 , currentScreen . Bounds . Height / 2 - Size . Height / 2 ) ;
}
2013-11-03 23:53:49 +13:00
2013-11-21 02:36:02 +13:00
UpdateMainFormSettings ( ) ;
2013-11-03 23:53:49 +13:00
UpdateMenu ( ) ;
UpdateUploaderMenuNames ( ) ;
RegisterMenuClosing ( ) ;
AfterSettingsJobs ( ) ;
if ( Program . Settings . PreviewSplitterDistance > 0 )
{
scMain . SplitterDistance = Program . Settings . PreviewSplitterDistance ;
}
UpdatePreviewSplitter ( ) ;
TaskbarManager . Enabled = Program . Settings . TaskbarProgressEnabled ;
}
private void RegisterMenuClosing ( )
{
foreach ( ToolStripDropDownItem dropDownItem in new ToolStripDropDownItem [ ]
{
2014-03-05 02:04:46 +13:00
tsddbAfterCaptureTasks , tsddbAfterUploadTasks , tsmiImageUploaders , tsmiImageFileUploaders , tsmiTextUploaders , tsmiTextFileUploaders , tsmiFileUploaders ,
tsmiURLShorteners , tsmiSocialServices , tsmiTrayAfterCaptureTasks , tsmiTrayAfterUploadTasks , tsmiTrayImageUploaders , tsmiTrayImageFileUploaders ,
tsmiTrayTextUploaders , tsmiTrayTextFileUploaders , tsmiTrayFileUploaders , tsmiTrayURLShorteners , tsmiTraySocialServices
2013-11-03 23:53:49 +13:00
} )
{
dropDownItem . DropDown . Closing + = ( sender , e ) = > e . Cancel = ( e . CloseReason = = ToolStripDropDownCloseReason . ItemClicked ) ;
}
}
private void AfterSettingsJobs ( )
{
2013-12-04 21:54:32 +13:00
ProxyInfo . Current = Program . Settings . ProxySettings ;
2013-11-03 23:53:49 +13:00
ClipboardHelpers . UseAlternativeCopyImage = Program . Settings . UseAlternativeClipboardCopyImage ;
}
public void UpdateMainFormSettings ( )
{
2014-05-11 23:47:37 +12:00
SetMultiEnumChecked ( Program . DefaultTaskSettings . AfterCaptureJob , tsddbAfterCaptureTasks , tsmiTrayAfterCaptureTasks ) ;
SetMultiEnumChecked ( Program . DefaultTaskSettings . AfterUploadJob , tsddbAfterUploadTasks , tsmiTrayAfterUploadTasks ) ;
SetEnumChecked ( Program . DefaultTaskSettings . ImageDestination , tsmiImageUploaders , tsmiTrayImageUploaders ) ;
SetEnumChecked ( Program . DefaultTaskSettings . ImageFileDestination , tsmiImageFileUploaders , tsmiTrayImageFileUploaders ) ;
SetEnumChecked ( Program . DefaultTaskSettings . TextDestination , tsmiTextUploaders , tsmiTrayTextUploaders ) ;
SetEnumChecked ( Program . DefaultTaskSettings . TextFileDestination , tsmiTextFileUploaders , tsmiTrayTextFileUploaders ) ;
SetEnumChecked ( Program . DefaultTaskSettings . FileDestination , tsmiFileUploaders , tsmiTrayFileUploaders ) ;
SetEnumChecked ( Program . DefaultTaskSettings . URLShortenerDestination , tsmiURLShorteners , tsmiTrayURLShorteners ) ;
SetEnumChecked ( Program . DefaultTaskSettings . SocialNetworkingServiceDestination , tsmiSocialServices , tsmiTraySocialServices ) ;
2013-11-03 23:53:49 +13:00
}
private void UpdateUploaderMenuNames ( )
{
2014-05-11 23:47:37 +12:00
string imageUploader = Program . DefaultTaskSettings . ImageDestination = = ImageDestination . FileUploader ?
Program . DefaultTaskSettings . ImageFileDestination . GetDescription ( ) : Program . DefaultTaskSettings . ImageDestination . GetDescription ( ) ;
2013-11-03 23:53:49 +13:00
tsmiImageUploaders . Text = tsmiTrayImageUploaders . Text = "Image uploader: " + imageUploader ;
2014-05-11 23:47:37 +12:00
string textUploader = Program . DefaultTaskSettings . TextDestination = = TextDestination . FileUploader ?
Program . DefaultTaskSettings . TextFileDestination . GetDescription ( ) : Program . DefaultTaskSettings . TextDestination . GetDescription ( ) ;
2013-11-03 23:53:49 +13:00
tsmiTextUploaders . Text = tsmiTrayTextUploaders . Text = "Text uploader: " + textUploader ;
2014-05-11 23:47:37 +12:00
tsmiFileUploaders . Text = tsmiTrayFileUploaders . Text = "File uploader: " + Program . DefaultTaskSettings . FileDestination . GetDescription ( ) ;
2013-11-03 23:53:49 +13:00
2014-05-11 23:47:37 +12:00
tsmiURLShorteners . Text = tsmiTrayURLShorteners . Text = "URL shortener: " + Program . DefaultTaskSettings . URLShortenerDestination . GetDescription ( ) ;
2013-11-03 23:53:49 +13:00
2014-05-11 23:47:37 +12:00
tsmiSocialServices . Text = tsmiTraySocialServices . Text = "Social networking service: " + Program . DefaultTaskSettings . SocialNetworkingServiceDestination . GetDescription ( ) ;
2013-11-03 23:53:49 +13:00
}
2013-12-04 21:54:32 +13:00
private void AutoCheckUpdate ( )
{
if ( Program . Settings . AutoCheckUpdate )
{
Thread updateThread = new Thread ( CheckUpdate ) ;
updateThread . IsBackground = true ;
updateThread . Start ( ) ;
}
}
2013-11-03 23:53:49 +13:00
private void CheckUpdate ( )
{
2013-11-28 12:18:00 +13:00
UpdateChecker updateChecker = TaskHelpers . CheckUpdate ( ) ;
2013-11-03 23:53:49 +13:00
2013-11-15 18:30:54 +13:00
if ( updateChecker . UpdateInfo ! = null & & updateChecker . UpdateInfo . Status = = UpdateStatus . UpdateAvailable & &
2014-05-11 17:13:51 +12:00
MessageBox . Show ( "A newer version of ShareX is available.\r\nWould you like to download and install it?" , string . Format ( "{0} v{1} is available" , Application . ProductName , updateChecker . UpdateInfo . LatestVersion . ToString ( ) ) ,
2013-11-15 18:30:54 +13:00
MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button1 ) = = DialogResult . Yes )
2013-11-03 23:53:49 +13:00
{
2014-05-10 12:23:47 +12:00
using ( DownloaderForm updaterForm = new DownloaderForm ( updateChecker ) )
2013-11-14 22:31:38 +13:00
{
2014-05-08 04:26:14 +12:00
updaterForm . ShowDialog ( ) ;
if ( updaterForm . Status = = DownloaderFormStatus . InstallStarted )
{
Application . Exit ( ) ;
}
2013-11-03 23:53:49 +13:00
}
}
}
private void ForceClose ( )
{
forceClose = true ;
Close ( ) ;
}
public void UseCommandLineArgs ( string [ ] args )
{
if ( args ! = null & & args . Length > 1 )
{
for ( int i = 1 ; i < args . Length ; i + + )
{
if ( args [ i ] . Equals ( "-clipboardupload" , StringComparison . InvariantCultureIgnoreCase ) )
{
UploadManager . ClipboardUpload ( ) ;
}
2014-03-11 22:38:50 +13:00
else if ( args [ i ] . Equals ( "-autocapture" , StringComparison . InvariantCultureIgnoreCase ) )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . StartAutoCapture ( ) ;
2014-03-11 22:38:50 +13:00
}
2013-11-03 23:53:49 +13:00
else if ( args [ i ] [ 0 ] ! = '-' )
{
UploadManager . UploadFile ( args [ i ] ) ;
}
}
}
}
private UploadTask [ ] GetCurrentTasks ( )
{
if ( lvUploads . SelectedItems . Count > 0 )
{
return lvUploads . SelectedItems . Cast < ListViewItem > ( ) . Select ( x = > x . Tag as UploadTask ) . Where ( x = > x ! = null ) . ToArray ( ) ;
}
return null ;
}
private TaskInfo GetCurrentUploadInfo ( )
{
TaskInfo info = null ;
UploadTask [ ] tasks = GetCurrentTasks ( ) ;
if ( tasks ! = null & & tasks . Length > 0 )
{
info = tasks [ 0 ] . Info ;
}
return info ;
}
private void RemoveSelectedItems ( )
{
lvUploads . SelectedItems . Cast < ListViewItem > ( ) . Select ( x = > x . Tag as UploadTask ) . Where ( x = > x ! = null & & ! x . IsWorking ) . ForEach ( TaskManager . Remove ) ;
}
private void RemoveAllItems ( )
{
lvUploads . Items . Cast < ListViewItem > ( ) . Select ( x = > x . Tag as UploadTask ) . Where ( x = > x ! = null & & ! x . IsWorking ) . ForEach ( TaskManager . Remove ) ;
}
private void UpdateMenu ( )
{
if ( Program . Settings . ShowMenu )
{
tsmiHideMenu . Text = "Hide menu" ;
}
else
{
tsmiHideMenu . Text = "Show menu" ;
}
tsMain . Visible = lblSplitter . Visible = Program . Settings . ShowMenu ;
Refresh ( ) ;
}
private void UpdatePreviewSplitter ( )
{
if ( Program . Settings . ShowPreview )
{
tsmiHidePreview . Text = "Hide image preview" ;
}
else
{
tsmiHidePreview . Text = "Show image preview" ;
}
scMain . Panel2Collapsed = ! Program . Settings . ShowPreview ;
Refresh ( ) ;
}
#region Form events
protected override void SetVisibleCore ( bool value )
{
2014-02-17 09:27:15 +13:00
if ( value & & ! IsHandleCreated & & ( Program . IsSilentRun | | Program . Settings . SilentRun ) & & Program . Settings . ShowTray )
2013-11-03 23:53:49 +13:00
{
CreateHandle ( ) ;
value = false ;
}
base . SetVisibleCore ( value ) ;
}
private void MainForm_Shown ( object sender , EventArgs e )
{
AfterShownJobs ( ) ;
}
private void MainForm_Resize ( object sender , EventArgs e )
{
Refresh ( ) ;
}
private void MainForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2013-11-21 02:36:02 +13:00
Program . Settings . MainFormSize = Size ;
2013-11-03 23:53:49 +13:00
if ( e . CloseReason = = CloseReason . UserClosing & & Program . Settings . ShowTray & & ! forceClose )
{
e . Cancel = true ;
Hide ( ) ;
2013-12-12 07:36:23 +13:00
Program . Settings . SaveAsync ( Program . ApplicationConfigFilePath ) ;
2013-11-03 23:53:49 +13:00
}
}
private void MainForm_FormClosed ( object sender , FormClosedEventArgs e )
{
TaskManager . StopAllTasks ( ) ;
}
private void MainForm_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop , false ) | |
e . Data . GetDataPresent ( DataFormats . Bitmap , false ) | |
e . Data . GetDataPresent ( DataFormats . Text , false ) )
{
e . Effect = DragDropEffects . Copy ;
}
else
{
e . Effect = DragDropEffects . None ;
}
}
private void MainForm_DragDrop ( object sender , DragEventArgs e )
{
UploadManager . DragDropUpload ( e . Data ) ;
}
private void tsbClipboardUpload_Click ( object sender , EventArgs e )
{
2014-05-12 16:16:19 +12:00
UploadManager . ClipboardUploadMainWindow ( HotkeyManager . GetTasksettings ( HotkeyType . ClipboardUpload ) ) ;
2013-11-03 23:53:49 +13:00
}
private void tsbFileUpload_Click ( object sender , EventArgs e )
{
2014-05-12 16:16:19 +12:00
UploadManager . UploadFile ( HotkeyManager . GetTasksettings ( HotkeyType . FileUpload ) ) ;
2013-11-03 23:53:49 +13:00
}
2014-04-06 14:10:34 +12:00
private void tsbDragDropUpload_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenDropWindow ( ) ;
2014-04-06 14:10:34 +12:00
}
2013-11-03 23:53:49 +13:00
private void tsddbDestinations_DropDownOpened ( object sender , EventArgs e )
{
UpdateDestinationStates ( ) ;
}
private void tsmiShowDebugLog_Click ( object sender , EventArgs e )
{
new DebugForm ( DebugHelper . Logger ) . Show ( ) ;
}
private void tsmiTestImageUpload_Click ( object sender , EventArgs e )
{
2014-04-20 13:16:51 +12:00
UploadManager . RunImageTask ( Resources . Test ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiTestTextUpload_Click ( object sender , EventArgs e )
{
2014-04-20 13:16:51 +12:00
UploadManager . UploadText ( "Text upload test" ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiTestFileUpload_Click ( object sender , EventArgs e )
{
2014-04-20 13:16:51 +12:00
UploadManager . UploadImage ( Resources . Test , ImageDestination . FileUploader ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiTestURLShortener_Click ( object sender , EventArgs e )
{
UploadManager . ShortenURL ( Links . URL_WEBSITE ) ;
}
private void tsmiTestUploaders_Click ( object sender , EventArgs e )
{
using ( UploadTestForm form = new UploadTestForm ( ) )
{
form . ShowDialog ( ) ;
}
}
private void tsmiTestShapeCapture_Click ( object sender , EventArgs e )
{
2014-05-11 23:47:37 +12:00
new RegionCapturePreview ( Program . DefaultTaskSettings . CaptureSettings . SurfaceOptions ) . Show ( ) ;
2013-11-03 23:53:49 +13:00
}
2014-05-10 12:25:54 +12:00
private void tsmiScreenRecorder_Click ( object sender , EventArgs e )
2013-11-03 23:53:49 +13:00
{
2014-05-11 23:47:37 +12:00
TaskHelpers . DoScreenRecorder ( ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiAutoCapture_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenAutoCapture ( ) ;
2013-11-03 23:53:49 +13:00
}
private void tsbApplicationSettings_Click ( object sender , EventArgs e )
{
2014-01-09 14:16:48 +13:00
using ( ApplicationSettingsForm settingsForm = new ApplicationSettingsForm ( ) )
2013-11-03 23:53:49 +13:00
{
settingsForm . ShowDialog ( ) ;
}
AfterSettingsJobs ( ) ;
2013-12-12 07:36:23 +13:00
Program . Settings . SaveAsync ( Program . ApplicationConfigFilePath ) ;
2014-04-16 02:04:34 +12:00
Program . ConfigureUploadersConfigWatcher ( ) ;
2013-11-03 23:53:49 +13:00
}
private void tsbTaskSettings_Click ( object sender , EventArgs e )
{
using ( TaskSettingsForm taskSettingsForm = new TaskSettingsForm ( Program . DefaultTaskSettings , true ) )
{
taskSettingsForm . ShowDialog ( ) ;
}
2013-12-12 07:36:23 +13:00
Program . Settings . SaveAsync ( Program . ApplicationConfigFilePath ) ;
2013-11-03 23:53:49 +13:00
}
private void tsbHotkeySettings_Click ( object sender , EventArgs e )
{
if ( Program . HotkeysConfig = = null )
{
Program . HotkeySettingsResetEvent . WaitOne ( ) ;
}
using ( HotkeySettingsForm hotkeySettingsForm = new HotkeySettingsForm ( ) )
{
hotkeySettingsForm . ShowDialog ( ) ;
}
2013-12-12 07:36:23 +13:00
Program . HotkeysConfig . SaveAsync ( Program . HotkeysConfigFilePath ) ;
2013-11-03 23:53:49 +13:00
}
private void tsbDestinationSettings_Click ( object sender , EventArgs e )
{
if ( Program . UploadersConfig = = null )
{
Program . UploaderSettingsResetEvent . WaitOne ( ) ;
}
2014-02-15 05:54:10 +13:00
using ( UploadersConfigForm uploadersConfigForm = new UploadersConfigForm ( Program . UploadersConfig ) )
2013-11-03 23:53:49 +13:00
{
uploadersConfigForm . ShowDialog ( ) ;
}
2014-04-16 02:04:34 +12:00
Program . UploadersConfigSaveAsync ( ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiCursorHelper_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenScreenColorPicker ( ) ;
}
private void tsmiRuler_Click ( object sender , EventArgs e )
{
TaskHelpers . OpenRuler ( ) ;
2013-11-03 23:53:49 +13:00
}
2014-05-03 06:06:03 +12:00
private void tsmiFTPClient_Click ( object sender , EventArgs e )
{
TaskHelpers . OpenFTPClient ( ) ;
}
2013-11-03 23:53:49 +13:00
private void tsmiHashCheck_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenHashCheck ( ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiIndexFolder_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenIndexFolder ( ) ;
2013-11-03 23:53:49 +13:00
}
2014-05-04 10:22:47 +12:00
private void tsmiImageEditor_Click ( object sender , EventArgs e )
{
TaskHelpers . OpenImageEditor ( ) ;
}
2013-11-08 14:14:04 +13:00
private void tsmiImageEffects_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenImageEffects ( ) ;
2013-11-08 14:14:04 +13:00
}
2014-01-07 09:22:15 +13:00
private void tsmiMonitorTest_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenMonitorTest ( ) ;
2014-01-07 09:22:15 +13:00
}
2014-03-22 14:39:28 +13:00
private void tsmiDNSChanger_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
TaskHelpers . OpenDNSChanger ( ) ;
2014-03-22 14:39:28 +13:00
}
2013-11-03 23:53:49 +13:00
private void tsbScreenshotsFolder_Click ( object sender , EventArgs e )
{
2014-05-02 18:12:51 +12:00
if ( Directory . Exists ( Program . ScreenshotsFolder ) )
{
Helpers . OpenFolder ( Program . ScreenshotsFolder ) ;
}
else
{
Helpers . OpenFolder ( Program . ScreenshotsParentFolder ) ;
}
2013-11-03 23:53:49 +13:00
}
private void tsbHistory_Click ( object sender , EventArgs e )
{
HistoryForm historyForm = new HistoryForm ( Program . HistoryFilePath ) ;
Program . Settings . HistoryWindowState . AutoHandleFormState ( historyForm ) ;
historyForm . Text = "ShareX - History: " + Program . HistoryFilePath ;
historyForm . Show ( ) ;
}
private void tsbImageHistory_Click ( object sender , EventArgs e )
{
ImageHistoryForm imageHistoryForm = new ImageHistoryForm ( Program . HistoryFilePath , Program . Settings . ImageHistoryViewMode ,
Program . Settings . ImageHistoryThumbnailSize , Program . Settings . ImageHistoryMaxItemCount ) ;
Program . Settings . ImageHistoryWindowState . AutoHandleFormState ( imageHistoryForm ) ;
imageHistoryForm . Text = "ShareX - Image history: " + Program . HistoryFilePath ;
imageHistoryForm . FormClosed + = imageHistoryForm_FormClosed ;
imageHistoryForm . Show ( ) ;
}
private void imageHistoryForm_FormClosed ( object sender , FormClosedEventArgs e )
{
ImageHistoryForm imageHistoryForm = sender as ImageHistoryForm ;
Program . Settings . ImageHistoryViewMode = imageHistoryForm . ViewMode ;
Program . Settings . ImageHistoryThumbnailSize = imageHistoryForm . ThumbnailSize ;
Program . Settings . ImageHistoryMaxItemCount = imageHistoryForm . MaxItemCount ;
}
private void tsbAbout_Click ( object sender , EventArgs e )
{
using ( AboutForm aboutForm = new AboutForm ( ) )
{
aboutForm . ShowDialog ( ) ;
}
}
private void tsbDonate_Click ( object sender , EventArgs e )
{
2014-05-03 05:56:51 +12:00
Helpers . OpenURL ( Links . URL_DONATE ) ;
2013-11-03 23:53:49 +13:00
}
private void lblDragAndDropTip_MouseUp ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Right )
{
UpdateControls ( ) ;
cmsUploadInfo . Show ( lblDragAndDropTip , e . X + 1 , e . Y + 1 ) ;
}
}
private void lvUploads_SelectedIndexChanged ( object sender , EventArgs e )
{
UpdateControls ( ) ;
}
private void lvUploads_MouseUp ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Right )
{
UpdateControls ( ) ;
cmsUploadInfo . Show ( lvUploads , e . X + 1 , e . Y + 1 ) ;
}
}
private void lvUploads_MouseDoubleClick ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Left )
{
uim . TryOpen ( ) ;
}
}
private void scMain_SplitterMoved ( object sender , SplitterEventArgs e )
{
Program . Settings . PreviewSplitterDistance = scMain . SplitterDistance ;
}
private void lvUploads_KeyDown ( object sender , KeyEventArgs e )
{
switch ( e . KeyData )
{
default :
return ;
case Keys . Enter :
uim . TryOpen ( ) ;
break ;
case Keys . Control | Keys . Enter :
uim . OpenFile ( ) ;
break ;
case Keys . Control | Keys . X :
uim . CopyURL ( ) ;
RemoveSelectedItems ( ) ;
break ;
case Keys . Control | Keys . C :
uim . CopyURL ( ) ;
break ;
case Keys . Control | Keys . V :
2014-05-12 16:16:19 +12:00
UploadManager . ClipboardUploadMainWindow ( HotkeyManager . GetTasksettings ( HotkeyType . ClipboardUpload ) ) ;
2013-11-03 23:53:49 +13:00
break ;
case Keys . Delete :
RemoveSelectedItems ( ) ;
break ;
}
e . Handled = true ;
}
#region Tray events
private void niTray_MouseUp ( object sender , MouseEventArgs e )
{
switch ( e . Button )
{
case MouseButtons . Middle :
CaptureScreenshot ( CaptureType . Rectangle , null , false ) ;
break ;
}
}
private void niTray_MouseDoubleClick ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Left )
{
this . ShowActivate ( ) ;
}
}
private void niTray_BalloonTipClicked ( object sender , EventArgs e )
{
string url = niTray . Tag as string ;
if ( ! string . IsNullOrEmpty ( url ) )
{
2014-05-03 05:56:51 +12:00
Helpers . OpenURL ( url ) ;
2013-11-03 23:53:49 +13:00
}
}
2014-02-18 11:53:53 +13:00
private void tsmiTrayShow_Click ( object sender , EventArgs e )
{
this . ShowActivate ( ) ;
}
2013-11-03 23:53:49 +13:00
private void tsmiTrayExit_Click ( object sender , EventArgs e )
{
ForceClose ( ) ;
}
#endregion Tray events
#region UploadInfoMenu events
private void tsmiStopUpload_Click ( object sender , EventArgs e )
{
if ( lvUploads . SelectedItems . Count > 0 )
{
foreach ( UploadTask task in GetCurrentTasks ( ) )
{
task . Stop ( ) ;
}
}
}
private void tsmiOpenURL_Click ( object sender , EventArgs e )
{
uim . OpenURL ( ) ;
}
private void tsmiOpenShortenedURL_Click ( object sender , EventArgs e )
{
uim . OpenShortenedURL ( ) ;
}
private void tsmiOpenThumbnailURL_Click ( object sender , EventArgs e )
{
uim . OpenThumbnailURL ( ) ;
}
private void tsmiOpenDeletionURL_Click ( object sender , EventArgs e )
{
uim . OpenDeletionURL ( ) ;
}
private void tsmiOpenFile_Click ( object sender , EventArgs e )
{
uim . OpenFile ( ) ;
}
2014-04-23 09:00:41 +12:00
private void tsmiOpenThumbnailFile_Click ( object sender , EventArgs e )
{
uim . OpenThumbnailFile ( ) ;
}
2013-11-03 23:53:49 +13:00
private void tsmiOpenFolder_Click ( object sender , EventArgs e )
{
uim . OpenFolder ( ) ;
}
private void tsmiCopyURL_Click ( object sender , EventArgs e )
{
uim . CopyURL ( ) ;
}
private void tsmiCopyShortenedURL_Click ( object sender , EventArgs e )
{
uim . CopyShortenedURL ( ) ;
}
private void tsmiCopyThumbnailURL_Click ( object sender , EventArgs e )
{
uim . CopyThumbnailURL ( ) ;
}
private void tsmiCopyDeletionURL_Click ( object sender , EventArgs e )
{
uim . CopyDeletionURL ( ) ;
}
private void tsmiCopyFile_Click ( object sender , EventArgs e )
{
uim . CopyFile ( ) ;
}
private void tsmiCopyImage_Click ( object sender , EventArgs e )
{
uim . CopyImage ( ) ;
}
private void tsmiCopyText_Click ( object sender , EventArgs e )
{
uim . CopyText ( ) ;
}
2014-04-23 09:00:41 +12:00
private void tsmiCopyThumbnailFile_Click ( object sender , EventArgs e )
{
uim . CopyThumbnailFile ( ) ;
}
private void tsmiCopyThumbnailImage_Click ( object sender , EventArgs e )
{
uim . CopyThumbnailImage ( ) ;
}
2013-11-03 23:53:49 +13:00
private void tsmiCopyHTMLLink_Click ( object sender , EventArgs e )
{
uim . CopyHTMLLink ( ) ;
}
private void tsmiCopyHTMLImage_Click ( object sender , EventArgs e )
{
uim . CopyHTMLImage ( ) ;
}
private void tsmiCopyHTMLLinkedImage_Click ( object sender , EventArgs e )
{
uim . CopyHTMLLinkedImage ( ) ;
}
private void tsmiCopyForumLink_Click ( object sender , EventArgs e )
{
uim . CopyForumLink ( ) ;
}
private void tsmiCopyForumImage_Click ( object sender , EventArgs e )
{
uim . CopyForumImage ( ) ;
}
private void tsmiCopyForumLinkedImage_Click ( object sender , EventArgs e )
{
uim . CopyForumLinkedImage ( ) ;
}
private void tsmiCopyFilePath_Click ( object sender , EventArgs e )
{
uim . CopyFilePath ( ) ;
}
private void tsmiCopyFileName_Click ( object sender , EventArgs e )
{
uim . CopyFileName ( ) ;
}
private void tsmiCopyFileNameWithExtension_Click ( object sender , EventArgs e )
{
uim . CopyFileNameWithExtension ( ) ;
}
private void tsmiCopyFolder_Click ( object sender , EventArgs e )
{
uim . CopyFolder ( ) ;
}
private void tsmiShowErrors_Click ( object sender , EventArgs e )
{
uim . ShowErrors ( ) ;
}
private void tsmiShowResponse_Click ( object sender , EventArgs e )
{
uim . ShowResponse ( ) ;
}
private void tsmiUploadSelectedFile_Click ( object sender , EventArgs e )
{
uim . Upload ( ) ;
}
private void tsmiClearList_Click ( object sender , EventArgs e )
{
RemoveAllItems ( ) ;
}
private void tsmiClipboardUpload_Click ( object sender , EventArgs e )
{
2014-05-12 16:16:19 +12:00
UploadManager . ClipboardUploadMainWindow ( HotkeyManager . GetTasksettings ( HotkeyType . ClipboardUpload ) ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiUploadFile_Click ( object sender , EventArgs e )
{
2014-05-12 16:16:19 +12:00
UploadManager . UploadFile ( HotkeyManager . GetTasksettings ( HotkeyType . FileUpload ) ) ;
2013-11-03 23:53:49 +13:00
}
private void tsmiHideMenu_Click ( object sender , EventArgs e )
{
Program . Settings . ShowMenu = ! Program . Settings . ShowMenu ;
UpdateMenu ( ) ;
}
private void tsmiHidePreview_Click ( object sender , EventArgs e )
{
Program . Settings . ShowPreview = ! Program . Settings . ShowPreview ;
UpdatePreviewSplitter ( ) ;
UpdateControls ( ) ;
}
#endregion UploadInfoMenu events
#endregion Form events
}
}