Esempio n. 1
0
        public IWorkItem GetParameterFromSelectedSuggestion(IWorkItem selectedSuggestion)
        {
            ImageWorkItem selectedImageWorkItem = (selectedSuggestion as ImageWorkItem);

            selectedImageWorkItem.image = CraftSynth.BuildingBlocks.IO.Clipboard.GetImageFromClipboard();
            FormImagePreview.Execute(selectedImageWorkItem.image);
            return(selectedSuggestion);
        }
Esempio n. 2
0
        public Dictionary <string, IWorkItem> GetSuggestions()
        {
            Dictionary <string, IWorkItem> suggestions = new Dictionary <string, IWorkItem>();

            if (CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName() == DataFormats.Bitmap)
            {
                ImageWorkItem imageWorkItem = new ImageWorkItem();
                imageWorkItem.filePath = "[Image from clipboard]";
                imageWorkItem.provider = this;
                suggestions.Add("[Image from clipboard]", imageWorkItem);
            }

            return(suggestions);
        }
Esempio n. 3
0
        private void ProcessCommand(Object o)
        {
            KeyValuePair <IEnsoService, Command> parameters = (KeyValuePair <IEnsoService, Command>)o;
            IEnsoService service = parameters.Key;
            Command      command = parameters.Value;

            if (command.parametersOnExecute[0] is ImageWorkItem)
            {
                string targetFilePath = null;
                try
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.DefaultExt = ".png";
                    saveFileDialog.Filter     = ".bmp|.bmp|.emf|.emf|.exif|.exif|.gif|.gif|.ico|.ico|.jpg|.jpg|.png|.png|.tif|.tif|.wmf|.wmf";
                    SetSaveFileDialogCommonOptions(saveFileDialog);

                    Thread bringToFrontAssistant = new Thread(BringToFront);
                    bringToFrontAssistant.Start(saveFileDialog.Title);

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Settings.Current.FileManagerSaveToDefaultFolder = Path.GetDirectoryName(saveFileDialog.FileName);
                        targetFilePath = saveFileDialog.FileName;
                        string      targetExtension   = Path.GetExtension(targetFilePath);
                        ImageFormat targetImageFormat = ImageFormat.Png;
                        if (string.Compare(targetExtension, ".bmp", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Bmp;
                        }
                        else
                        if (string.Compare(targetExtension, ".emf", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Emf;
                        }
                        else
                        if (string.Compare(targetExtension, ".exif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Exif;
                        }
                        else
                        if (string.Compare(targetExtension, ".gif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Gif;
                        }
                        else
                        if (string.Compare(targetExtension, ".ico", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Icon;
                        }
                        else
                        if (string.Compare(targetExtension, ".jpg", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Jpeg;
                        }
                        else
                        if (string.Compare(targetExtension, ".png", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Png;
                        }
                        else
                        if (string.Compare(targetExtension, ".tif", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Tiff;
                        }
                        else
                        if (string.Compare(targetExtension, ".wmf", true) == 0)
                        {
                            targetImageFormat = ImageFormat.Wmf;
                        }

                        ImageWorkItem imageWorkItem = (ImageWorkItem)command.parametersOnExecute[0];
                        imageWorkItem.image.Save(targetFilePath, targetImageFormat);

                        Logging.AddActionLog(string.Format("FileManager: Image saved to '{0}'.", targetFilePath));
                        MessagesHandler.Display(string.Format("Saved.", command.Name));

                        if (command.Postfix == "[what] and copy its file path")
                        {
                            CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(targetFilePath);
                            Logging.AddActionLog(string.Format("ClipboardManager: file path '{0}' copied to clipboard.", targetFilePath));
                            MessagesHandler.Display("Image saved and its file path copied.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new ApplicationException(string.Format("FileManager: Failed to save image to '{0}'.", targetFilePath ?? "not set"), exception);
                }
            }
            else
            if ((command.parametersOnExecute[0] is Entities.StringWorkItem) ||
                (command.parametersOnExecute[0] is Entities.Shortcut) ||
                (command.parametersOnExecute[0] is Entities.Contact) ||
                (command.parametersOnExecute[0] is Entities.CallerHistoryItem) ||
                (command.parametersOnExecute[0] is Entities.MemorizedString))
            {
                string targetFilePath = null;
                try
                {
                    MessagesHandler.Display(command.parametersOnExecute[0].GetValueAsText());

                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.DefaultExt = ".txt";
                    saveFileDialog.Filter     = ".txt|.txt";
                    SetSaveFileDialogCommonOptions(saveFileDialog);

                    Thread bringToFrontAssistant = new Thread(BringToFront);
                    bringToFrontAssistant.Start(saveFileDialog.Title);

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Settings.Current.FileManagerSaveToDefaultFolder = Path.GetDirectoryName(saveFileDialog.FileName);
                        targetFilePath = saveFileDialog.FileName;

                        File.WriteAllText(targetFilePath, command.parametersOnExecute[0].GetValueAsText());

                        Logging.AddActionLog(string.Format("FileManager: Text saved from work item to '{0}'.", targetFilePath));
                        MessagesHandler.Display(string.Format("Saved.", command.Name));

                        if (command.Postfix == "[what] and copy its file path")
                        {
                            CraftSynth.BuildingBlocks.IO.Clipboard.SetTextToClipboard(targetFilePath);
                            Logging.AddActionLog(string.Format("ClipboardManager: file path '{0}' copied to clipboard.", targetFilePath));
                            MessagesHandler.Display("Text saved and its file path copied.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new ApplicationException(string.Format("FileManager: Failed to save text from work item to '{0}'.", targetFilePath ?? "not set"), exception);
                }
            }
            else
            {
                Logging.AddErrorLog(string.Format("FileManager: Tried to save unsupported work item type."));
                MessagesHandler.Display("Can not save work item of this type.");
            }
        }