private void PopulateMenu() { DropDownItems.Clear(); if (EnableRepeatEffectMenuItem && LastEffect != null) { string repeatFormat = PdnResources.GetString("Effects.RepeatMenuItem.Format"); string menuName = string.Format(repeatFormat, LastEffect.Name); PdnMenuItem pmi = new PdnMenuItem(menuName, LastEffect.Image, RepeatEffectMenuItem_Click) { Name = "RepeatEffect(" + LastEffect.GetType().FullName + ")", ShortcutKeys = Keys.Control | Keys.F }; DropDownItems.Add(pmi); ToolStripSeparator tss = new ToolStripSeparator(); DropDownItems.Add(tss); } AddEffectsToMenu(); Triple <Assembly, Type, Exception>[] errors = Effects.GetLoaderExceptions(); for (int i = 0; i < errors.Length; ++i) { AppWorkspace.ReportEffectLoadError(errors[i]); } MenuPopulated = true; }
protected override void OnDropDownOpening(EventArgs e) { this.DropDownItems.Clear(); IList <Triple <Assembly, Type, Exception> > pluginLoadErrors = AppWorkspace.GetEffectLoadErrors(); this.DropDownItems.AddRange(GetMenuItemsToAdd(pluginLoadErrors.Count > 0)); this.menuFileNew.Enabled = true; this.menuFileOpen.Enabled = true; this.menuFileOpenRecent.Enabled = true; this.menuFileOpenRecentSentinel.Enabled = true; this.menuFileAcquire.Enabled = true; this.menuFileAcquireFromScannerOrCamera.Enabled = true; this.menuFileExit.Enabled = true; if (AppWorkspace.ActiveDocumentWorkspace != null) { this.menuFileSave.Enabled = true; this.menuFileSaveAs.Enabled = true; this.menuFileClose.Enabled = true; this.menuFilePrint.Enabled = true; } else { this.menuFileSave.Enabled = false; this.menuFileSaveAs.Enabled = false; this.menuFileClose.Enabled = false; this.menuFilePrint.Enabled = false; } base.OnDropDownOpening(e); }
private void MenuWindowResetWindowLocations_Click(object sender, System.EventArgs e) { AppWorkspace.ResetFloatingForms(); AppWorkspace.Widgets.ToolsForm.Visible = true; AppWorkspace.Widgets.LayerForm.Visible = true; AppWorkspace.Widgets.ColorsForm.Visible = true; }
public MainPanel() { var dialog = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, FilterIndex = 0 }; dialog.ShowDialog(); var fileName = dialog.FileName; FileType type; var document = DocumentWorkspace.LoadDocument(this, fileName, out type, null); _workspace = new DocumentWorkspace { Document = document, Dock = DockStyle.Fill }; _appworkspace = new AppWorkspace(_workspace) { Dock = DockStyle.Fill }; Controls.Add(_appworkspace); }
public override void PerformAction(AppWorkspace appWorkspace) { string filePath; if (appWorkspace.ActiveDocumentWorkspace == null) { filePath = null; } else { // Default to the directory the active document came from string fileName; FileType fileType; SaveConfigToken saveConfigToken; appWorkspace.ActiveDocumentWorkspace.GetDocumentSaveOptions(out fileName, out fileType, out saveConfigToken); filePath = Path.GetDirectoryName(fileName); } string[] newFileNames; DialogResult result = DocumentWorkspace.ChooseFiles(appWorkspace, out newFileNames, true, filePath); if (result == DialogResult.OK) { appWorkspace.OpenFilesInNewWorkspace(newFileNames); } }
public void Finish(AppWorkspace appWorkspace) { // Assumes we are running in the main UI thread if (this.finishing) { return; } try { if (this.haveFinished) { throw new ApplicationException("already called Finish()"); } this.finishing = true; this.haveFinished = true; // Verify the update's signature bool verified = Security.VerifySignedFile(StateMachine.UIContext, this.installerPath, true, false); CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction(); appWorkspace.PerformAction(cawa); if (verified && !cawa.Cancelled) { // we're in the clear, launch the update! Settings.CurrentUser.SetString(PdnSettings.UpdateMsiFileName, this.installerPath); if (0 == string.Compare(Path.GetExtension(this.installerPath), ".exe", true)) { const string arguments = "/skipConfig"; Shell.Execute(appWorkspace, this.installerPath, arguments, true, Shell.ExecuteWaitType.RelaunchPdnOnExit); Startup.CloseApplication(); } else { } } else { try { File.Delete(this.installerPath); } catch (Exception) { } } } finally { this.finishing = false; } }
public void Finish(AppWorkspace appWorkspace) { // Assumes we are running in the main UI thread if (this.finishing) { return; } try { if (this.haveFinished) { throw new ApplicationException("already called Finish()"); } this.finishing = true; this.haveFinished = true; // Verify the update's signature bool verified = Security.VerifySignedFile(StateMachine.UIContext, this.installerPath, true, false); CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction(); appWorkspace.PerformAction(cawa); if (verified && !cawa.Cancelled) { // we're in the clear, launch the update! Settings.CurrentUser.SetString(PdnSettings.UpdateMsiFileName, this.installerPath); if (0 == string.Compare(Path.GetExtension(this.installerPath), ".exe", true)) { const string arguments = "/skipConfig"; Shell.Execute(appWorkspace, this.installerPath, arguments, true, Shell.ExecuteWaitType.RelaunchPdnOnExit); Startup.CloseApplication(); } else { } } else { try { File.Delete(this.installerPath); } catch (Exception) { } } } finally { this.finishing = false; } }
protected override void Dispose(bool disposing) { if (disposing && (this.appWorkspace != null)) { this.appWorkspace.HandleCreated -= new EventHandler(this.OnAppWorkspaceHandleCreated); this.appWorkspace = null; } base.Dispose(disposing); }
public override void PerformAction(AppWorkspace appWorkspace) { string question = PdnResources.GetString("ClearOpenRecentList.Dialog.Text"); if (MessageBoxUtil.AskYesNo(appWorkspace, question) == DialogResult.Yes) { MostRecentFilesService.Instance.Clear(); MostRecentFilesService.Instance.SaveMruList(); } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.defaultButton = new System.Windows.Forms.Button(); this.appWorkspace = new PaintDotNet.AppWorkspace(); this.floaterOpacityTimer = new System.Windows.Forms.Timer(this.components); this.deferredInitializationTimer = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // appWorkspace // this.appWorkspace.Dock = System.Windows.Forms.DockStyle.Fill; this.appWorkspace.Location = new System.Drawing.Point(0, 0); this.appWorkspace.Name = "appWorkspace"; this.appWorkspace.Size = new System.Drawing.Size(752, 648); this.appWorkspace.TabIndex = 2; this.appWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanging); this.appWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanged); // // floaterOpacityTimer // this.floaterOpacityTimer.Enabled = false; this.floaterOpacityTimer.Interval = 25; this.floaterOpacityTimer.Tick += new System.EventHandler(this.FloaterOpacityTimer_Tick); // // deferredInitializationTimer // this.deferredInitializationTimer.Interval = 250; this.deferredInitializationTimer.Tick += new EventHandler(DeferredInitialization); // // defaultButton // this.defaultButton.Size = new System.Drawing.Size(1, 1); this.defaultButton.Text = ""; this.defaultButton.Location = new Point(-100, -100); this.defaultButton.TabStop = false; this.defaultButton.Click += new EventHandler(DefaultButton_Click); // // MainForm // this.AllowDrop = true; this.AutoScaleDimensions = new SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(950, 738); this.Controls.Add(this.appWorkspace); this.Controls.Add(this.defaultButton); this.AcceptButton = this.defaultButton; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation; this.ForceActiveTitleBar = true; this.KeyPreview = true; this.Controls.SetChildIndex(this.appWorkspace, 0); this.ResumeLayout(false); this.PerformLayout(); }
public override void PerformAction(AppWorkspace appWorkspace) { string question = PdnResources.GetString("ClearOpenRecentList.Dialog.Text"); DialogResult result = Utility.AskYesNo(appWorkspace, question); if (result == DialogResult.Yes) { appWorkspace.MostRecentFiles.Clear(); appWorkspace.MostRecentFiles.SaveMruList(); } }
public override void PerformAction(AppWorkspace appWorkspace) { string question = PdnResources.GetString("ClearOpenRecentList.Dialog.Text"); DialogResult result = Utility.AskYesNo(appWorkspace, question); if (result == DialogResult.Yes) { appWorkspace.MostRecentFiles.Clear(); appWorkspace.MostRecentFiles.SaveMruList(); } }
private void FinishedRenderingHandler(object sender, EventArgs e) { if (AppWorkspace.InvokeRequired) { AppWorkspace.BeginInvoke(new EventHandler(FinishedRenderingHandler), new object[] { sender, e }); } else { AppWorkspace.ActiveDocumentWorkspace.EnableOutlineAnimation = true; } }
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace.CanSetActiveWorkspace) { using (NewFileDialog dialog = new NewFileDialog()) { SizeInt32?clipboardImageSize; SizeInt32 newDocumentSize = appWorkspace.GetNewDocumentSize(); using (new WaitCursorChanger(appWorkspace)) { CleanupManager.RequestCleanup(); try { IPdnDataObject dataObject = PdnClipboard.GetDataObject(); clipboardImageSize = ClipboardUtil.GetClipboardImageSize(appWorkspace, dataObject); dataObject = null; } catch (Exception) { clipboardImageSize = null; } CleanupManager.RequestCleanup(); } if (clipboardImageSize.HasValue) { newDocumentSize = clipboardImageSize.Value; } dialog.OriginalSize = new Size(newDocumentSize.Width, newDocumentSize.Height); dialog.OriginalDpuUnit = AppSettings.Instance.Workspace.LastNonPixelUnits.Value; dialog.OriginalDpu = Document.GetDefaultDpu(dialog.OriginalDpuUnit); dialog.Units = dialog.OriginalDpuUnit; dialog.Resolution = dialog.OriginalDpu; dialog.ConstrainToAspect = AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value; if ((((dialog.ShowDialog(appWorkspace) == DialogResult.OK) && (dialog.ImageWidth > 0)) && ((dialog.ImageHeight > 0) && dialog.Resolution.IsFinite())) && (dialog.Resolution > 0.0)) { SizeInt32 size = new SizeInt32(dialog.ImageWidth, dialog.ImageHeight); if (appWorkspace.CreateBlankDocumentInNewWorkspace(size, dialog.Units, dialog.Resolution, false)) { appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value = dialog.ConstrainToAspect; if (dialog.Units != MeasurementUnit.Pixel) { AppSettings.Instance.Workspace.LastNonPixelUnits.Value = dialog.Units; } if (appWorkspace.Units != MeasurementUnit.Pixel) { appWorkspace.Units = dialog.Units; } } } } } }
public override void PerformAction(AppWorkspace appWorkspace) { using (NewFileDialog nfd = new NewFileDialog()) { Size newDocSize = appWorkspace.GetNewDocumentSize(); if (Utility.IsClipboardImageAvailable()) { try { Utility.GCFullCollect(); IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject(); using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap)) { int width2 = clipImage.Width; int height2 = clipImage.Height; newDocSize = new Size(width2, height2); } } catch (Exception ex) { if (ex is OutOfMemoryException || ex is ExternalException || ex is NullReferenceException) { // ignore } else { throw; } } } nfd.OriginalSize = new Size(newDocSize.Width, newDocSize.Height); nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false); DialogResult dr = nfd.ShowDialog(appWorkspace); if (dr == DialogResult.OK) { bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), false); if (success) { appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect); } } } }
private void InvalidateTimer_Tick(object sender, System.EventArgs e) { if (AppWorkspace.FindForm().WindowState == FormWindowState.Minimized) { return; } if (ProgressRegions == null) { return; } lock (ProgressRegions) { int min = ProgressRegionsStartIndex; int max; for (max = min; max < ProgressRegions.Length; ++max) { if (ProgressRegions[max] == null) { break; } } if (min != max) { using (PdnRegion updateRegion = PdnRegion.CreateEmpty()) { for (int i = min; i < max; ++i) { updateRegion.Union(ProgressRegions[i]); } using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(updateRegion)) { AppWorkspace.ActiveDocumentWorkspace.ActiveLayer.Invalidate(simplified); } ProgressRegionsStartIndex = max; } } double progress = 100.0 * (double)max / (double)ProgressRegions.Length; AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(progress); } }
public override void PerformAction(AppWorkspace appWorkspace) { string email = "*****@*****.**"; string subject = string.Format(PdnResources.GetString("SendFeedback.Email.Subject.Format"), PdnInfo.FullAppName); string body = PdnResources.GetString("SendFeedback.Email.Body"); string fileName = this.GetEmailLaunchString(email, subject, body); fileName = fileName.Substring(0, Math.Min(0x400, fileName.Length)); try { Process.Start(fileName); } catch (Exception exception) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("SendFeedbackAction.Error"), exception); } }
private void MenuFileOpenRecentFile_Click(object sender, System.EventArgs e) { try { ToolStripMenuItem mi = (ToolStripMenuItem)sender; int spaceIndex = mi.Text.IndexOf(" "); string indexString = mi.Text.Substring(1, spaceIndex - 1); int index = int.Parse(indexString) - 1; MostRecentFile[] recentFiles = AppWorkspace.MostRecentFiles.GetFileList(); string fileName = recentFiles[recentFiles.Length - index - 1].FileName; AppWorkspace.OpenFileInNewWorkspace(fileName); } catch (Exception) { } }
public override void PerformAction(AppWorkspace appWorkspace) { string email = InvariantStrings.FeedbackEmail; string subjectFormat = PdnResources.GetString("SendFeedback.Email.Subject.Format"); string subject = string.Format(subjectFormat, PdnInfo.GetFullAppName()); string body = PdnResources.GetString("SendFeedback.Email.Body"); string launchMe = GetEmailLaunchString(email, subject, body); launchMe = launchMe.Substring(0, Math.Min(1024, launchMe.Length)); try { Process.Start(launchMe); } catch (Exception) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("LaunchLink.Error")); } }
public PdnStatusBar(AppWorkspace appWorkspace) { this.appWorkspace = appWorkspace; this.PopulateLocalizedUnitsArray(); this.zoomToWindowImage = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomToWindowIcon.png").Reference); this.zoomActualSizeImage = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewActualSizeIcon.png").Reference); this.windowText = EnumLocalizer.GetLocalizedEnumValue(typeof(PaintDotNet.ZoomBasis), PaintDotNet.ZoomBasis.FitToWindow).LocalizedName; this.percentageFormat = PdnResources.GetString("ZoomConfigWidget.Percentage.Format"); this.InitializeComponent(); this.imageInfoStatusLabel.Image = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.ImageSizeIcon.png").Reference); this.cursorInfoStatusLabel.Image = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.CursorXYIcon.png").Reference); this.zoomToWindowToggleButton.Image = this.zoomToWindowImage; this.zoomOutButton.Image = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomOutIcon.png").Reference); this.zoomInButton.Image = UIUtil.GetScaledImage(PdnResources.GetImageResource("Icons.MenuViewZoomInIcon.png").Reference); this.zoomOutButton.ToolTipText = PdnResources.GetString("ZoomConfigWidget.ZoomOutButton.ToolTipText"); this.zoomInButton.ToolTipText = PdnResources.GetString("ZoomConfigWidget.ZoomInButton.ToolTipText"); this.zoomBasis = PaintDotNet.ZoomBasis.FitToWindow; this.scaleFactor = PaintDotNet.ScaleFactor.OneToOne; this.OnZoomBasisChanged(); }
public override void PerformAction(AppWorkspace appWorkspace) { string email = InvariantStrings.FeedbackEmail; string subjectFormat = PdnResources.GetString("SendFeedback.Email.Subject.Format"); string subject = string.Format(subjectFormat, PdnInfo.GetFullAppName()); string body = PdnResources.GetString("SendFeedback.Email.Body"); string launchMe = GetEmailLaunchString(email, subject, body); launchMe = launchMe.Substring(0, Math.Min(1024, launchMe.Length)); try { Process.Start(launchMe); } catch (Exception) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("LaunchLink.Error")); } }
public override void PerformAction(AppWorkspace appWorkspace) { string filePath; if (appWorkspace.ActiveDocumentWorkspace == null) { filePath = null; } else { // Default to the directory the active document came from appWorkspace.ActiveDocumentWorkspace.GetDocumentSaveOptions(out string fileName, out FileType fileType, out SaveConfigToken saveConfigToken); filePath = Path.GetDirectoryName(fileName); } DialogResult result = DocumentWorkspace.ChooseFiles(appWorkspace, out string[] newFileNames, true, filePath); if (result == DialogResult.OK) { appWorkspace.OpenFilesInNewWorkspace(newFileNames); } }
private void InitializeComponent() { this.components = new Container(); this.defaultButton = new Button(); this.appWorkspace = new AppWorkspace(); this.deferredInitializationTimer = new System.Windows.Forms.Timer(this.components); base.SuspendLayout(); this.appWorkspace.SuspendLayout(); this.appWorkspace.Name = "appWorkspace"; this.appWorkspace.Dock = DockStyle.Fill; this.appWorkspace.TabIndex = 2; this.appWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(this.OnAppWorkspaceActiveDocumentWorkspaceChanging); this.appWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(this.OnAppWorkspaceActiveDocumentWorkspaceChanged); this.deferredInitializationTimer.Interval = 250; this.deferredInitializationTimer.Tick += new EventHandler(this.DeferredInitialization); this.defaultButton.Size = new Size(1, 1); this.defaultButton.Text = ""; this.defaultButton.Location = new Point(-100, -100); this.defaultButton.TabStop = false; this.defaultButton.Click += new EventHandler(this.OnDefaultButtonClick); try { this.AllowDrop = true; } catch (InvalidOperationException) { } base.Controls.Add(this.appWorkspace); base.Controls.Add(this.defaultButton); base.AcceptButton = this.defaultButton; base.Name = "MainForm"; base.ForceActiveTitleBar = true; base.KeyPreview = true; base.Controls.SetChildIndex(this.appWorkspace, 0); this.appWorkspace.ResumeLayout(false); base.ResumeLayout(false); }
public override void PerformAction(AppWorkspace appWorkspace) { if (!appWorkspace.CanSetActiveWorkspace) { this.cancelled = true; return; } DocumentWorkspace activeDocumentWorkspace = appWorkspace.ActiveDocumentWorkspace; int?nullable = null; try { nullable = new int?(appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency); appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0; } catch (NullReferenceException) { } List <DocumentWorkspace> unsavedDocs = new List <DocumentWorkspace>(); foreach (DocumentWorkspace workspace2 in appWorkspace.DocumentWorkspaces) { if ((workspace2.Document != null) && workspace2.Document.Dirty) { unsavedDocs.Add(workspace2); } } if (unsavedDocs.Count == 1) { CloseWorkspaceAction action = new CloseWorkspaceAction(unsavedDocs[0]); action.PerformAction(appWorkspace); this.cancelled = action.Cancelled; } else if (unsavedDocs.Count > 1) { using (UnsavedChangesDialog dialog = new UnsavedChangesDialog()) {
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace.CanSetActiveWorkspace) { string directoryName; string[] strArray; if (appWorkspace.ActiveDocumentWorkspace == null) { directoryName = null; } else { string str2; FileType type; SaveConfigToken token; appWorkspace.ActiveDocumentWorkspace.GetDocumentSaveOptions(out str2, out type, out token); directoryName = Path.GetDirectoryName(str2); } if (DocumentWorkspace.ChooseFiles(appWorkspace, out strArray, true, directoryName) == DialogResult.OK) { appWorkspace.OpenFilesInNewWorkspace(strArray); } } }
private void HandleEffectException(AppWorkspace appWorkspace, Effect effect, Exception ex) { try { AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar(); AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar(); } catch (Exception) { } // Figure out if it's a built-in effect, or a plug-in bool builtIn = IsBuiltInEffect(effect); if (builtIn) { // For built-in effects, tear down Paint.NET which will result in a crash log throw new ApplicationException("Effect threw an exception", ex); } else { Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.BugWarning.png").Reference); string formTitle = PdnResources.GetString("Effect.PluginErrorDialog.Title"); Image taskImage = null; string introText = PdnResources.GetString("Effect.PluginErrorDialog.IntroText"); TaskButton restartTB = new TaskButton( PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference, PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ActionText"), PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ExplanationText")); TaskButton doNotRestartTB = new TaskButton( PdnResources.GetImageResource("Icons.WarningIcon.png").Reference, PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ActionText"), PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ExplanationText")); string auxButtonText = PdnResources.GetString("Effect.PluginErrorDialog.AuxButton1.Text"); EventHandler auxButtonClickHandler = delegate(object sender, EventArgs e) { using (PdnBaseForm textBoxForm = new PdnBaseForm()) { textBoxForm.Name = "EffectCrash"; TextBox exceptionBox = new TextBox(); textBoxForm.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference); textBoxForm.Text = PdnResources.GetString("Effect.PluginErrorDialog.Title"); exceptionBox.Dock = DockStyle.Fill; exceptionBox.ReadOnly = true; exceptionBox.Multiline = true; string exceptionText = AppWorkspace.GetLocalizedEffectErrorMessage(effect.GetType().Assembly, effect.GetType(), ex); exceptionBox.Font = new Font(FontFamily.GenericMonospace, exceptionBox.Font.Size); exceptionBox.Text = exceptionText; exceptionBox.ScrollBars = ScrollBars.Vertical; textBoxForm.StartPosition = FormStartPosition.CenterParent; textBoxForm.ShowInTaskbar = false; textBoxForm.MinimizeBox = false; textBoxForm.Controls.Add(exceptionBox); textBoxForm.Width = UI.ScaleWidth(700); textBoxForm.ShowDialog(); } }; TaskButton clickedTB = TaskDialog.Show( appWorkspace, formIcon, formTitle, taskImage, true, introText, new TaskButton[] { restartTB, doNotRestartTB }, restartTB, doNotRestartTB, TaskDialog.DefaultPixelWidth96Dpi * 2, auxButtonText, auxButtonClickHandler); if (clickedTB == restartTB) { // Next, apply restart logic CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction(); cawa.PerformAction(appWorkspace); if (!cawa.Cancelled) { SystemLayer.Shell.RestartApplication(); Startup.CloseApplication(); } } } }
private void MenuHelpSendFeedback_Click(object sender, EventArgs e) { AppWorkspace.PerformAction(new SendFeedbackAction()); }
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace.CanSetActiveWorkspace) { try { SizeInt32? nullable; IPdnDataObject dataObject; MaskedSurface clipboardImage; try { using (new WaitCursorChanger(appWorkspace)) { CleanupManager.RequestCleanup(); dataObject = PdnClipboard.GetDataObject(); if (ClipboardUtil.IsClipboardImageMaybeAvailable(appWorkspace, dataObject)) { clipboardImage = ClipboardUtil.GetClipboardImage(appWorkspace, dataObject); if (clipboardImage != null) { nullable = new SizeInt32?(clipboardImage.GetCachedGeometryMaskScansBounds().Size); } else { nullable = null; } } else { clipboardImage = null; nullable = null; } } } catch (OutOfMemoryException exception) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception); return; } catch (Exception exception2) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2); return; } if (!nullable.HasValue) { MessageBoxUtil.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage")); } else { Type defaultToolType; SizeInt32 size = nullable.Value; Document document = null; if ((appWorkspace.ActiveDocumentWorkspace != null) && (appWorkspace.ActiveDocumentWorkspace.Tool != null)) { defaultToolType = appWorkspace.ActiveDocumentWorkspace.Tool.GetType(); } else { defaultToolType = appWorkspace.DefaultToolType; } using (new WaitCursorChanger(appWorkspace)) { document = new Document(size); DocumentWorkspace documentWorkspace = appWorkspace.AddNewDocumentWorkspace(); documentWorkspace.Document = document; documentWorkspace.History.PushNewMemento(new NullHistoryMemento(string.Empty, null)); PasteInToNewLayerAction action = new PasteInToNewLayerAction(documentWorkspace, dataObject, clipboardImage); if (action.PerformAction()) { using (new PushNullToolMode(documentWorkspace)) { documentWorkspace.Selection.Reset(); documentWorkspace.SetDocumentSaveOptions(null, null, null); documentWorkspace.History.ClearAll(); documentWorkspace.History.PushNewMemento(new NullHistoryMemento(PdnResources.GetString("Menu.Edit.PasteInToNewImage.Text"), PdnResources.GetImageResource("Icons.MenuEditPasteInToNewImageIcon.png"))); appWorkspace.ActiveDocumentWorkspace = documentWorkspace; } documentWorkspace.SetToolFromType(defaultToolType); } else { appWorkspace.RemoveDocumentWorkspace(documentWorkspace); document.Dispose(); } } } } catch (ExternalException exception3) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError"), exception3); } catch (OutOfMemoryException exception4) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory"), exception4); } catch (ThreadStateException) { } } }
public override void PerformAction(AppWorkspace appWorkspace) { try { IDataObject pasted; Image image; using (new WaitCursorChanger(appWorkspace)) { Utility.GCFullCollect(); pasted = Clipboard.GetDataObject(); image = (Image)pasted.GetData(DataFormats.Bitmap); } if (image == null) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage")); } else { Size newSize = image.Size; image.Dispose(); image = null; pasted = null; Document document = null; using (new WaitCursorChanger(appWorkspace)) { document = new Document(newSize); DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace(); dw.Document = document; dw.History.PushNewMemento(new NullHistoryMemento(string.Empty, null)); PasteInToNewLayerAction pitnla = new PasteInToNewLayerAction(dw); bool result = pitnla.PerformAction(); if (result) { dw.Selection.Reset(); dw.SetDocumentSaveOptions(null, null, null); dw.History.ClearAll(); dw.History.PushNewMemento( new NullHistoryMemento( PdnResources.GetString("NewImageAction.Name"), PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"))); appWorkspace.ActiveDocumentWorkspace = dw; } else { appWorkspace.RemoveDocumentWorkspace(dw); document.Dispose(); } } } } catch (ExternalException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError")); return; } catch (OutOfMemoryException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory")); return; } catch (ThreadStateException) { // The ApartmentState property of the application is not set to ApartmentState.STA // I don't think this one will ever happen, seeing as how Main is tagged with the // STA attribute. return; } }
public override void PerformAction(AppWorkspace appWorkspace) { if (!ScanningAndPrinting.CanScan) { Utility.ShowWiaError(appWorkspace); return; } string tempName = Path.ChangeExtension(SystemLayer.FileSystem.GetTempFileName(), ".bmp"); ScanResult result; try { result = ScanningAndPrinting.Scan(appWorkspace, tempName); } // If there was an exception, let's assume the user has already received an error dialog, // either from Windows or from the WIA UI, and let's /not/ present another error dialog. catch (Exception) { result = ScanResult.UserCancelled; } if (result == ScanResult.Success) { string errorText = null; try { Image image; try { image = PdnResources.LoadImage(tempName); } catch (FileNotFoundException) { errorText = PdnResources.GetString("LoadImage.Error.FileNotFoundException"); throw; } catch (OutOfMemoryException) { errorText = PdnResources.GetString("LoadImage.Error.OutOfMemoryException"); throw; } Document document; try { document = Document.FromImage(image); } catch (OutOfMemoryException) { errorText = PdnResources.GetString("LoadImage.Error.OutOfMemoryException"); throw; } finally { image.Dispose(); image = null; } DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace(); try { dw.Document = document; } catch (OutOfMemoryException) { errorText = PdnResources.GetString("LoadImage.Error.OutOfMemoryException"); throw; } document = null; dw.SetDocumentSaveOptions(null, null, null); dw.History.ClearAll(); HistoryMemento newHA = new NullHistoryMemento( PdnResources.GetString("AcquireImageAction.Name"), ImageResource.Get("Icons.MenuLayersAddNewLayerIcon.png")); dw.History.PushNewMemento(newHA); appWorkspace.ActiveDocumentWorkspace = dw; // Try to delete the temp file but don't worry if we can't try { File.Delete(tempName); } catch { } } catch (Exception) { if (errorText != null) { Utility.ErrorBox(appWorkspace, errorText); } else { throw; } } } }
public override void PerformAction(AppWorkspace appWorkspace) { try { IDataObject pasted; Image image; using (new WaitCursorChanger(appWorkspace)) { Utility.GCFullCollect(); pasted = Clipboard.GetDataObject(); image = (Image)pasted.GetData(DataFormats.Bitmap); } if (image == null) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage")); } else { Size newSize = image.Size; image.Dispose(); image = null; pasted = null; Document document = null; using (new WaitCursorChanger(appWorkspace)) { document = new Document(newSize); DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace(); dw.Document = document; dw.History.PushNewMemento(new NullHistoryMemento(string.Empty, null)); PasteInToNewLayerAction pitnla = new PasteInToNewLayerAction(dw); bool result = pitnla.PerformAction(); if (result) { dw.Selection.Reset(); dw.SetDocumentSaveOptions(null, null, null); dw.History.ClearAll(); dw.History.PushNewMemento( new NullHistoryMemento( PdnResources.GetString("NewImageAction.Name"), PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"))); appWorkspace.ActiveDocumentWorkspace = dw; } else { appWorkspace.RemoveDocumentWorkspace(dw); document.Dispose(); } } } } catch (ExternalException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError")); return; } catch (OutOfMemoryException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory")); return; } catch (ThreadStateException) { // The ApartmentState property of the application is not set to ApartmentState.STA // I don't think this one will ever happen, seeing as how Main is tagged with the // STA attribute. return; } }
public WorkspaceWidgets(AppWorkspace workspace) { this.workspace = workspace; }
public override void PerformAction(AppWorkspace appWorkspace) { int oldLatency = appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency; appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0; List<DocumentWorkspace> unsavedDocs = new List<DocumentWorkspace>(); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { if (dw.Document != null && dw.Document.Dirty) { unsavedDocs.Add(dw); } } if (unsavedDocs.Count == 1) { CloseWorkspaceAction cwa = new CloseWorkspaceAction(unsavedDocs[0]); cwa.PerformAction(appWorkspace); this.cancelled = cwa.Cancelled; } else if (unsavedDocs.Count > 1) { using (UnsavedChangesDialog dialog = new UnsavedChangesDialog()) { dialog.DocumentClicked += delegate(object sender, EventArgs<DocumentWorkspace> e2) { appWorkspace.ActiveDocumentWorkspace = e2.Data; }; dialog.Documents = unsavedDocs.ToArray(); if (appWorkspace.ActiveDocumentWorkspace.Document.Dirty) { dialog.SelectedDocument = appWorkspace.ActiveDocumentWorkspace; } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { PdnBaseForm asPDF = mainForm as PdnBaseForm; if (asPDF != null) { asPDF.RestoreWindow(); } } DialogResult dr = Utility.ShowDialog(dialog, appWorkspace); switch (dr) { case DialogResult.Yes: { foreach (DocumentWorkspace dw in unsavedDocs) { appWorkspace.ActiveDocumentWorkspace = dw; bool result = dw.DoSave(); if (result) { appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; break; } } } break; case DialogResult.No: this.cancelled = false; break; case DialogResult.Cancel: this.cancelled = true; break; default: throw new InvalidEnumArgumentException(); } } appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = oldLatency; } if (!this.cancelled) { UI.SuspendControlPainting(appWorkspace); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { appWorkspace.RemoveDocumentWorkspace(dw); } UI.ResumeControlPainting(appWorkspace); appWorkspace.Invalidate(true); } }
public override void PerformAction(AppWorkspace appWorkspace) { using (NewFileDialog nfd = new NewFileDialog()) { Size newDocSize = appWorkspace.GetNewDocumentSize(); if (Utility.IsClipboardImageAvailable()) { try { Utility.GCFullCollect(); IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject(); using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap)) { int width2 = clipImage.Width; int height2 = clipImage.Height; newDocSize = new Size(width2, height2); } } catch (Exception ex) { if (ex is OutOfMemoryException || ex is ExternalException || ex is NullReferenceException) { // ignore } else { throw; } } } nfd.OriginalSize = new Size(newDocSize.Width, newDocSize.Height); nfd.OriginalDpuUnit = SettingNames.GetLastNonPixelUnits(); nfd.OriginalDpu = Document.GetDefaultDpu(nfd.OriginalDpuUnit); nfd.Units = nfd.OriginalDpuUnit; nfd.Resolution = nfd.OriginalDpu; nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false); DialogResult dr = nfd.ShowDialog(appWorkspace); if (dr == DialogResult.OK) { bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), nfd.Units, nfd.Resolution, false); if (success) { appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect); if (nfd.Units != MeasurementUnit.Pixel) { Settings.CurrentUser.SetString(SettingNames.LastNonPixelUnits, nfd.Units.ToString()); } if (appWorkspace.Units != MeasurementUnit.Pixel) { appWorkspace.Units = nfd.Units; } } } } }
private void ClearList_Click(object sender, EventArgs e) { AppWorkspace.PerformAction(new ClearMruListAction()); }
private void MenuFileAcquireFromScannerOrCamera_Click(object sender, System.EventArgs e) { AppWorkspace.PerformAction(new AcquireFromScannerOrCameraAction()); }
private void MenuFileNew_Click(object sender, System.EventArgs e) { AppWorkspace.PerformAction(new NewImageAction()); }
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace == null) { throw new ArgumentNullException("appWorkspace"); } DocumentWorkspace dw; if (this.closeMe == null) { dw = appWorkspace.ActiveDocumentWorkspace; } else { dw = this.closeMe; } if (dw != null) { if (dw.Document == null) { appWorkspace.RemoveDocumentWorkspace(dw); } else if (!dw.Document.Dirty) { appWorkspace.RemoveDocumentWorkspace(dw); } else { appWorkspace.ActiveDocumentWorkspace = dw; TaskButton saveTB = new TaskButton( PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")); TaskButton dontSaveTB = new TaskButton( PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")); TaskButton cancelTB = new TaskButton( PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText")); string title = PdnResources.GetString("CloseWorkspaceAction.Title"); string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format"); string introText = string.Format(introTextFormat, dw.GetFriendlyName()); Image thumb = appWorkspace.GetDocumentWorkspaceThumbnail(dw); if (thumb == null) { thumb = new Bitmap(32, 32); } Bitmap taskImage = new Bitmap(thumb.Width + 2, thumb.Height + 2, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(taskImage)) { g.Clear(Color.Transparent); g.DrawImage( thumb, new Rectangle(1, 1, thumb.Width, thumb.Height), new Rectangle(0, 0, thumb.Width, thumb.Height), GraphicsUnit.Pixel); Utility.DrawDropShadow1px(g, new Rectangle(0, 0, taskImage.Width, taskImage.Height)); } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { if (mainForm is PdnBaseForm asPDF) { asPDF.RestoreWindow(); } } Icon warningIcon; ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png"); if (warningIconImageRes != null) { Image warningIconImage = warningIconImageRes.Reference; warningIcon = Utility.ImageToIcon(warningIconImage, false); } else { warningIcon = null; } TaskButton clickedTB = TaskDialog.Show( appWorkspace, warningIcon, title, taskImage, false, introText, new TaskButton[] { saveTB, dontSaveTB, cancelTB }, saveTB, cancelTB, 340); if (clickedTB == saveTB) { if (dw.DoSave()) { this.Cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.Cancelled = true; } } else if (clickedTB == dontSaveTB) { this.Cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.Cancelled = true; } } } Utility.GCFullCollect(); }
public override void PerformAction(AppWorkspace appWorkspace) { DocumentWorkspace dw; if (this.closeMe == null) { dw = appWorkspace.ActiveDocumentWorkspace; } else { dw = this.closeMe; } if (dw != null) { if (dw.Document == null) { appWorkspace.RemoveDocumentWorkspace(dw); } else if (!dw.Document.Dirty) { appWorkspace.RemoveDocumentWorkspace(dw); } else { appWorkspace.ActiveDocumentWorkspace = dw; TaskButton saveTB = new TaskButton( ImageResource.Get("Icons.MenuFileSaveIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")); TaskButton dontSaveTB = new TaskButton( ImageResource.Get("Icons.MenuFileCloseIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")); TaskButton cancelTB = new TaskButton( ImageResource.Get("Icons.CancelIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText")); string title = PdnResources.GetString("CloseWorkspaceAction.Title"); string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format"); string introText = string.Format(introTextFormat, dw.GetFriendlyName()); Image thumb = appWorkspace.GetDocumentWorkspaceThumbnail(dw); Bitmap taskImage = new Bitmap(thumb.Width + 2, thumb.Height + 2, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(taskImage)) { g.Clear(Color.Transparent); g.DrawImage( thumb, new Rectangle(1, 1, thumb.Width, thumb.Height), new Rectangle(0, 0, thumb.Width, thumb.Height), GraphicsUnit.Pixel); Utility.DrawDropShadow1px(g, new Rectangle(0, 0, taskImage.Width, taskImage.Height)); } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { PdnBaseForm asPDF = mainForm as PdnBaseForm; if (asPDF != null) { asPDF.RestoreWindow(); } } TaskButton clickedTB = TaskDialog.Show( appWorkspace, Utility.ImageToIcon(ImageResource.Get("Icons.WarningIcon.png").Reference, false), title, taskImage, false, introText, new TaskButton[] { saveTB, dontSaveTB, cancelTB }, saveTB, cancelTB, 340); if (clickedTB == saveTB) { if (dw.DoSave()) { this.cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; } } else if (clickedTB == dontSaveTB) { this.cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; } } } Utility.GCFullCollect(); }
private void MenuFileOpen_Click(object sender, System.EventArgs e) { AppWorkspace.PerformAction(new OpenFileAction()); }