Merge pull request #283 from barsv/fix_1_menuChecks

Change check behavior for Destinations->Image uploader->File uploader
This commit is contained in:
Jaex 2014-09-14 09:28:38 +03:00
commit 3e0fa792ec
4 changed files with 86 additions and 7 deletions

View file

@ -89,7 +89,26 @@ private void InitControls()
tsddbAfterCaptureTasks, tsmiTrayAfterCaptureTasks); tsddbAfterCaptureTasks, tsmiTrayAfterCaptureTasks);
AddMultiEnumItems<AfterUploadTasks>(x => Program.DefaultTaskSettings.AfterUploadJob = Program.DefaultTaskSettings.AfterUploadJob.Swap(x), AddMultiEnumItems<AfterUploadTasks>(x => Program.DefaultTaskSettings.AfterUploadJob = Program.DefaultTaskSettings.AfterUploadJob.Swap(x),
tsddbAfterUploadTasks, tsmiTrayAfterUploadTasks); tsddbAfterUploadTasks, tsmiTrayAfterUploadTasks);
AddEnumItems<ImageDestination>(x => Program.DefaultTaskSettings.ImageDestination = x, tsmiImageUploaders, tsmiTrayImageUploaders); // Destinations -> Image uploader
AddEnumItems<ImageDestination>(x =>
{
Program.DefaultTaskSettings.ImageDestination = x;
// if click on "folder" with file destinations then set ImageFileDestination and check it
if (x == ImageDestination.FileUploader)
{
Program.DefaultTaskSettings.ImageFileDestination =
Program.DefaultTaskSettings.ImageFileDestination ?? FileDestination.Dropbox;
SetEnumChecked(Program.DefaultTaskSettings.ImageFileDestination, tsmiImageFileUploaders,
tsmiTrayImageFileUploaders);
}
else // if click not on "folder" with destinations then uncheck file destinations
{
if (Program.DefaultTaskSettings.ImageFileDestination != null)
{
Uncheck(tsmiImageFileUploaders, tsmiTrayImageFileUploaders);
}
}
}, tsmiImageUploaders, tsmiTrayImageUploaders);
tsmiImageFileUploaders = (ToolStripDropDownItem)tsmiImageUploaders.DropDownItems[tsmiImageUploaders.DropDownItems.Count - 1]; tsmiImageFileUploaders = (ToolStripDropDownItem)tsmiImageUploaders.DropDownItems[tsmiImageUploaders.DropDownItems.Count - 1];
tsmiTrayImageFileUploaders = (ToolStripDropDownItem)tsmiTrayImageUploaders.DropDownItems[tsmiTrayImageUploaders.DropDownItems.Count - 1]; tsmiTrayImageFileUploaders = (ToolStripDropDownItem)tsmiTrayImageUploaders.DropDownItems[tsmiTrayImageUploaders.DropDownItems.Count - 1];
AddEnumItems<FileDestination>(x => AddEnumItems<FileDestination>(x =>
@ -98,7 +117,26 @@ private void InitControls()
tsmiImageFileUploaders.PerformClick(); tsmiImageFileUploaders.PerformClick();
tsmiTrayImageFileUploaders.PerformClick(); tsmiTrayImageFileUploaders.PerformClick();
}, tsmiImageFileUploaders, tsmiTrayImageFileUploaders); }, tsmiImageFileUploaders, tsmiTrayImageFileUploaders);
AddEnumItems<TextDestination>(x => Program.DefaultTaskSettings.TextDestination = x, tsmiTextUploaders, tsmiTrayTextUploaders); // Destinations -> Text uploader
AddEnumItems<TextDestination>(x =>
{
Program.DefaultTaskSettings.TextDestination = x;
// if click on "folder" with file destinations then set TextFileDestination and check it
if (x == TextDestination.FileUploader)
{
Program.DefaultTaskSettings.TextFileDestination = Program.DefaultTaskSettings.TextFileDestination
?? FileDestination.Dropbox;
SetEnumChecked(Program.DefaultTaskSettings.TextFileDestination, tsmiTextFileUploaders,
tsmiTrayTextFileUploaders);
}
else // if click not on "folder" with destinations then uncheck file destinations
{
if (Program.DefaultTaskSettings.TextFileDestination != null)
{
Uncheck(tsmiTextFileUploaders, tsmiTrayTextFileUploaders);
}
}
}, tsmiTextUploaders, tsmiTrayTextUploaders);
tsmiTextFileUploaders = (ToolStripDropDownItem)tsmiTextUploaders.DropDownItems[tsmiTextUploaders.DropDownItems.Count - 1]; tsmiTextFileUploaders = (ToolStripDropDownItem)tsmiTextUploaders.DropDownItems[tsmiTextUploaders.DropDownItems.Count - 1];
tsmiTrayTextFileUploaders = (ToolStripDropDownItem)tsmiTrayTextUploaders.DropDownItems[tsmiTrayTextUploaders.DropDownItems.Count - 1]; tsmiTrayTextFileUploaders = (ToolStripDropDownItem)tsmiTrayTextUploaders.DropDownItems[tsmiTrayTextUploaders.DropDownItems.Count - 1];
AddEnumItems<FileDestination>(x => AddEnumItems<FileDestination>(x =>
@ -107,6 +145,7 @@ private void InitControls()
tsmiTextFileUploaders.PerformClick(); tsmiTextFileUploaders.PerformClick();
tsmiTrayTextFileUploaders.PerformClick(); tsmiTrayTextFileUploaders.PerformClick();
}, tsmiTextFileUploaders, tsmiTrayTextFileUploaders); }, tsmiTextFileUploaders, tsmiTrayTextFileUploaders);
// Destinations -> File uploader
AddEnumItems<FileDestination>(x => Program.DefaultTaskSettings.FileDestination = x, tsmiFileUploaders, tsmiTrayFileUploaders); AddEnumItems<FileDestination>(x => Program.DefaultTaskSettings.FileDestination = x, tsmiFileUploaders, tsmiTrayFileUploaders);
AddEnumItems<UrlShortenerType>(x => Program.DefaultTaskSettings.URLShortenerDestination = x, tsmiURLShorteners, tsmiTrayURLShorteners); AddEnumItems<UrlShortenerType>(x => Program.DefaultTaskSettings.URLShortenerDestination = x, tsmiURLShorteners, tsmiTrayURLShorteners);
AddEnumItems<URLSharingServices>(x => Program.DefaultTaskSettings.URLSharingServiceDestination = x, tsmiURLSharingServices, tsmiTrayURLSharingServices); AddEnumItems<URLSharingServices>(x => Program.DefaultTaskSettings.URLSharingServiceDestination = x, tsmiURLSharingServices, tsmiTrayURLSharingServices);
@ -141,6 +180,21 @@ private void InitControls()
ExportImportControl.UploadRequested += json => UploadManager.UploadText(json); ExportImportControl.UploadRequested += json => UploadManager.UploadText(json);
} }
/// <summary>
/// Unchecks all items in drop downs
/// </summary>
/// <param name="lists">List of drop downs</param>
public static void Uncheck(params ToolStripDropDownItem[] lists)
{
foreach (ToolStripDropDownItem parent in lists)
{
foreach (var dropDownItem in parent.DropDownItems)
{
((ToolStripMenuItem)dropDownItem).Checked = false;
}
}
}
private void UpdateWorkflowsMenu() private void UpdateWorkflowsMenu()
{ {
tsddbWorkflows.DropDownItems.Clear(); tsddbWorkflows.DropDownItems.Clear();
@ -230,8 +284,15 @@ private void AddEnumItems<T>(Action<T> selectedEnum, params ToolStripDropDownIte
} }
} }
/// <summary>
/// Finds dropDowonItem corresponding to the enum value and checks it.
/// </summary>
/// <param name="value">Enum item</param>
/// <param name="parents">DropDowns where enum-th item must be checked.</param>
private void SetEnumChecked(Enum value, params ToolStripDropDownItem[] parents) private void SetEnumChecked(Enum value, params ToolStripDropDownItem[] parents)
{ {
if (value == null)
return;
int index = value.GetIndex(); int index = value.GetIndex();
foreach (ToolStripDropDownItem parent in parents) foreach (ToolStripDropDownItem parent in parents)

View file

@ -83,7 +83,25 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false)
}, cmsTask); }, cmsTask);
AddMultiEnumItemsContextMenu<AfterCaptureTasks>(x => TaskSettings.AfterCaptureJob = TaskSettings.AfterCaptureJob.Swap(x), cmsAfterCapture); AddMultiEnumItemsContextMenu<AfterCaptureTasks>(x => TaskSettings.AfterCaptureJob = TaskSettings.AfterCaptureJob.Swap(x), cmsAfterCapture);
AddMultiEnumItemsContextMenu<AfterUploadTasks>(x => TaskSettings.AfterUploadJob = TaskSettings.AfterUploadJob.Swap(x), cmsAfterUpload); AddMultiEnumItemsContextMenu<AfterUploadTasks>(x => TaskSettings.AfterUploadJob = TaskSettings.AfterUploadJob.Swap(x), cmsAfterUpload);
AddEnumItems<ImageDestination>(x => TaskSettings.ImageDestination = x, tsmiImageUploaders); AddEnumItems<ImageDestination>(x =>
{
TaskSettings.ImageDestination = x;
// if click on "folder" with file destinations then set ImageFileDestination and check it
if (x == ImageDestination.FileUploader)
{
TaskSettings.ImageFileDestination = TaskSettings.ImageFileDestination
?? FileDestination.Dropbox;
SetEnumChecked(TaskSettings.ImageFileDestination, tsmiImageFileUploaders);
}
else // if click not on "folder" with destinations then uncheck file destinations
{
if (TaskSettings.ImageFileDestination != null)
{
MainForm.Uncheck(tsmiImageFileUploaders);
}
}
TaskSettings.ImageFileDestination = null;
}, tsmiImageUploaders);
tsmiImageFileUploaders = (ToolStripDropDownItem)tsmiImageUploaders.DropDownItems[tsmiImageUploaders.DropDownItems.Count - 1]; tsmiImageFileUploaders = (ToolStripDropDownItem)tsmiImageUploaders.DropDownItems[tsmiImageUploaders.DropDownItems.Count - 1];
AddEnumItems<FileDestination>(x => TaskSettings.ImageFileDestination = x, tsmiImageFileUploaders); AddEnumItems<FileDestination>(x => TaskSettings.ImageFileDestination = x, tsmiImageFileUploaders);
AddEnumItems<TextDestination>(x => TaskSettings.TextDestination = x, tsmiTextUploaders); AddEnumItems<TextDestination>(x => TaskSettings.TextDestination = x, tsmiTextUploaders);

View file

@ -63,9 +63,9 @@ public string Description
public bool UseDefaultDestinations = true; public bool UseDefaultDestinations = true;
public ImageDestination ImageDestination = ImageDestination.Imgur; public ImageDestination ImageDestination = ImageDestination.Imgur;
public FileDestination ImageFileDestination = FileDestination.Dropbox; public FileDestination? ImageFileDestination = null;
public TextDestination TextDestination = TextDestination.Pastebin; public TextDestination TextDestination = TextDestination.Pastebin;
public FileDestination TextFileDestination = FileDestination.Dropbox; public FileDestination? TextFileDestination = null;
public FileDestination FileDestination = FileDestination.Dropbox; public FileDestination FileDestination = FileDestination.Dropbox;
public UrlShortenerType URLShortenerDestination = UrlShortenerType.BITLY; public UrlShortenerType URLShortenerDestination = UrlShortenerType.BITLY;
public URLSharingServices URLSharingServiceDestination = URLSharingServices.Twitter; public URLSharingServices URLSharingServiceDestination = URLSharingServices.Twitter;

View file

@ -796,10 +796,10 @@ public UploadResult UploadFile(Stream stream, string fileName)
switch (Info.DataType) switch (Info.DataType)
{ {
case EDataType.Image: case EDataType.Image:
fileDestination = Info.TaskSettings.ImageFileDestination; fileDestination = Info.TaskSettings.ImageFileDestination ?? FileDestination.Dropbox;
break; break;
case EDataType.Text: case EDataType.Text:
fileDestination = Info.TaskSettings.TextFileDestination; fileDestination = Info.TaskSettings.TextFileDestination ?? FileDestination.Dropbox;
break; break;
default: default:
case EDataType.File: case EDataType.File: