123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.File.BatchSaveComponet;
- using System;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- namespace PaintDotNet.File.UnsavedProcessing
- {
- /// <summary>
- /// 关闭保存
- /// </summary>
- internal class UnsavedProcessingDialog : PdnBaseForm
- {
- #region 属性
- private DataGridView DataInformationView;
- private Panel panel1;
- private Panel panel2;
- private Button btn_Close;
- private Button btn_SelectAll;
- private Button btn_NotAll;
- private Button btn_Determine;
- private AppWorkspace appWorkspace;
- private DocumentWorkspace closeMe;
- private DataGridViewCheckBoxColumn Column1;
- private DataGridViewTextBoxColumn Column2;
- private DataGridViewTextBoxColumn Column3;
- private DataGridViewTextBoxColumn Column4;
- private DataGridViewButtonColumn Column5;
- private bool cancelled;
- public bool Cancelled
- {
- get
- {
- return this.cancelled;
- }
- }
- #endregion
- #region 构造函数
- public UnsavedProcessingDialog(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- }
- #endregion
- #region 事件
- private void UnsavedProcessingDialog_SizeChanged(object sender, EventArgs e)
- {
- DataInformationView.Columns[0].Width = 40;//设置保存列宽度
- DataInformationView.Columns[1].Width = 200;//设置名称列宽度
- DataInformationView.Columns[2].Width = 70;//设置类型列宽度
- DataInformationView.Columns[3].Width = DataInformationView.Width - 353;//设置路径列宽度
- DataInformationView.Columns[4].Width = 40;//设置浏览列宽度
- }
- private void UnsavedProcessingDialog_Load(object sender, EventArgs e)
- {
- DisplayNotSaved();
- }
- /// <summary>
- /// 确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_Determine_Click(object sender, EventArgs e)
- {
- if (this.DataInformationView.Rows.Count > 0)
- {
- for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
- {
- DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataInformationView.Rows[i].Cells[0];
- bool isSave = Convert.ToBoolean(checkCell.Value);
- if (isSave)
- {
- string path = this.DataInformationView.Rows[i].Cells[3].Value.ToString();
- if (!Directory.Exists(path))//判断是否存在
- {
- MessageBox.Show(path + " 路径不存在!");
- return;
- }
- }
- }
- }
- int Length = this.appWorkspace.DocumentWorkspaces.Length;
- for (int i = 0; i < Length; i++) PerformAction();
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- /// <summary>
- /// 全不选
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_NotAll_Click(object sender, EventArgs e)
- {
- if (this.DataInformationView.Rows.Count > 0)
- {
- for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
- {
- this.DataInformationView.Rows[i].Cells[0].Value = false;
- }
- }
- }
- /// <summary>
- /// 选择所有
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_SelectAll_Click(object sender, EventArgs e)
- {
- if (this.DataInformationView.Rows.Count > 0)
- {
- for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
- {
- this.DataInformationView.Rows[i].Cells[0].Value = true;
- }
- }
- }
- /// <summary>
- /// 取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_Close_Click(object sender, EventArgs e)
- {
- this.cancelled = true;
- this.Close();
- }
- /// <summary>
- /// 点击浏览选择路径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DataInformationView_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
- DataGridViewCell cell = this.DataInformationView.Rows[e.RowIndex].Cells[e.ColumnIndex];
- if (e.ColumnIndex == 4 /*cell.Value.ToString() == "浏览"*/ )
- {
- FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- string path = folderBrowserDialog1.SelectedPath;
- this.DataInformationView.Rows[e.RowIndex].Cells[3].Value = path;
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- #endregion
- #region 方法
- /// <summary>
- /// 控件初始化
- /// </summary>
- private void InitializeComponent()
- {
- this.DataInformationView = new System.Windows.Forms.DataGridView();
- this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
- this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column5 = new System.Windows.Forms.DataGridViewButtonColumn();
- this.panel1 = new System.Windows.Forms.Panel();
- this.panel2 = new System.Windows.Forms.Panel();
- this.btn_Close = new System.Windows.Forms.Button();
- this.btn_SelectAll = new System.Windows.Forms.Button();
- this.btn_NotAll = new System.Windows.Forms.Button();
- this.btn_Determine = new System.Windows.Forms.Button();
- ((System.ComponentModel.ISupportInitialize)(this.DataInformationView)).BeginInit();
- this.panel1.SuspendLayout();
- this.panel2.SuspendLayout();
- this.SuspendLayout();
- //
- // DataInformationView
- //
- this.DataInformationView.AllowUserToAddRows = false;
- this.DataInformationView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.DataInformationView.BackgroundColor = System.Drawing.SystemColors.Control;
- this.DataInformationView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.DataInformationView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.Column1,
- this.Column2,
- this.Column3,
- this.Column4,
- this.Column5});
- this.DataInformationView.Location = new System.Drawing.Point(0, 0);
- this.DataInformationView.Name = "DataInformationView";
- this.DataInformationView.RowHeadersVisible = false;
- this.DataInformationView.RowTemplate.Height = 23;
- this.DataInformationView.Size = new System.Drawing.Size(694, 352);
- this.DataInformationView.TabIndex = 0;
- this.DataInformationView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataInformationView_CellClick);
- //
- // Column1
- //
- this.Column1.HeaderText = PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText");
- this.Column1.Name = "Column1";
- this.Column1.Width = 40;
- //
- // Column2
- //
- this.Column2.HeaderText = PdnResources.GetString("Menu.name.text");
- this.Column2.Name = "Column2";
- this.Column2.Width = 200;
- //
- // Column3
- //
- this.Column3.HeaderText = PdnResources.GetString("Menu.Type.text");
- this.Column3.Name = "Column3";
- this.Column3.Width = 70;
- //
- // Column4
- //
- this.Column4.HeaderText = PdnResources.GetString("Path.text");
- this.Column4.Name = "Column4";
- this.Column4.Width = 326;
- //
- // Column5
- //
- this.Column5.HeaderText = "";
- this.Column5.Name = "Column5";
- this.Column5.Width = 55;
- //
- // panel1
- //
- this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel1.Controls.Add(this.DataInformationView);
- this.panel1.Location = new System.Drawing.Point(6, 7);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(694, 352);
- this.panel1.TabIndex = 5;
- //
- // panel2
- //
- this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.panel2.Controls.Add(this.btn_Close);
- this.panel2.Controls.Add(this.btn_SelectAll);
- this.panel2.Controls.Add(this.btn_NotAll);
- this.panel2.Controls.Add(this.btn_Determine);
- this.panel2.Location = new System.Drawing.Point(6, 364);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(694, 40);
- this.panel2.TabIndex = 6;
- //
- // btn_Close
- //
- this.btn_Close.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_Close.Location = new System.Drawing.Point(603, 7);
- this.btn_Close.Name = "btn_Close";
- this.btn_Close.Size = new System.Drawing.Size(75, 23);
- this.btn_Close.TabIndex = 3;
- this.btn_Close.Text = "取消";
- this.btn_Close.UseVisualStyleBackColor = true;
- this.btn_Close.Click += new System.EventHandler(this.btn_Close_Click);
- //
- // btn_SelectAll
- //
- this.btn_SelectAll.Location = new System.Drawing.Point(93, 7);
- this.btn_SelectAll.Name = "btn_SelectAll";
- this.btn_SelectAll.Size = new System.Drawing.Size(75, 23);
- this.btn_SelectAll.TabIndex = 1;
- this.btn_SelectAll.Text = "选择所有";
- this.btn_SelectAll.UseVisualStyleBackColor = true;
- this.btn_SelectAll.Click += new System.EventHandler(this.btn_SelectAll_Click);
- //
- // btn_NotAll
- //
- this.btn_NotAll.Location = new System.Drawing.Point(12, 7);
- this.btn_NotAll.Name = "btn_NotAll";
- this.btn_NotAll.Size = new System.Drawing.Size(75, 23);
- this.btn_NotAll.TabIndex = 0;
- this.btn_NotAll.Text = "全不选";
- this.btn_NotAll.UseVisualStyleBackColor = true;
- this.btn_NotAll.Click += new System.EventHandler(this.btn_NotAll_Click);
- //
- // btn_Determine
- //
- this.btn_Determine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.btn_Determine.Location = new System.Drawing.Point(522, 7);
- this.btn_Determine.Name = "btn_Determine";
- this.btn_Determine.Size = new System.Drawing.Size(75, 23);
- this.btn_Determine.TabIndex = 2;
- this.btn_Determine.Text = "确定";
- this.btn_Determine.UseVisualStyleBackColor = true;
- this.btn_Determine.Click += new System.EventHandler(this.btn_Determine_Click);
- //
- // UnsavedProcessingDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(706, 411);
- this.Controls.Add(this.panel2);
- this.Controls.Add(this.panel1);
- this.MinimumSize = new System.Drawing.Size(722, 450);
- this.Name = "UnsavedProcessingDialog";
- this.ShowIcon = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "保存文件";
- this.TopMost = true;
- this.Load += new System.EventHandler(this.UnsavedProcessingDialog_Load);
- this.SizeChanged += new System.EventHandler(this.UnsavedProcessingDialog_SizeChanged);
- this.Controls.SetChildIndex(this.panel1, 0);
- this.Controls.SetChildIndex(this.panel2, 0);
- ((System.ComponentModel.ISupportInitialize)(this.DataInformationView)).EndInit();
- this.panel1.ResumeLayout(false);
- this.panel2.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- private void InitializeLanguageText()
- {
- this.btn_Determine.Text = PdnResources.GetString("Menu.ensure.text");
- this.btn_Close.Text = PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText");
- this.btn_NotAll.Text = PdnResources.GetString("Menu.Binaryoperation.Objecthandling.unselectall.text");
- this.btn_SelectAll.Text = PdnResources.GetString("SelectAll.text");
- this.Text = PdnResources.GetString("SaveFile.text");
- }
- /// <summary>
- /// 初始化
- /// </summary>
- private void DisplayNotSaved()
- {
- this.DataInformationView.Columns[2].ReadOnly = true;
- this.DataInformationView.Columns[3].ReadOnly = true;
- foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
- {
- if (document.Document.Dirty)
- {
- string imgName = document.GetFriendlyName();
- string imgType = string.Empty;
- int index = 0;
- if (imgName.Contains("."))
- {
- index = imgName.LastIndexOf('.');
- imgType = imgName.Substring(index);
- imgName = imgName.Substring(0, index);
- }
- else
- imgType = ".jpg";
- //获取图片路径
- string fileName;
- //FileType fileType;
- //SaveConfigToken saveConfigToken;
- document.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
- string path = Path.GetDirectoryName(fileName);
- this.DataInformationView.Rows.Add(true, imgName, imgType, fileName != null ? path : Startup.instance.configModel.HardFilePath != null ? Startup.instance.configModel.HardFilePath : Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), PdnResources.GetString("Menu.browse.Text"));
- this.DataInformationView.Rows[this.DataInformationView.Rows.Count - 1].Tag = document;
- }
- }
- }
- /// <summary>
- /// 保存与关闭Document
- /// </summary>
- public void PerformAction()
- {
- if (appWorkspace == null)
- throw new ArgumentNullException("appWorkspace");
- appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- DocumentWorkspace dw;
- if (this.closeMe == null)
- {
- if (appWorkspace.toRemoveDocumentWorkspaceIndex >= 0 && appWorkspace.toRemoveDocumentWorkspaceIndex < appWorkspace.DocumentWorkspaces.Length)
- {
- dw = appWorkspace.DocumentWorkspaces[appWorkspace.toRemoveDocumentWorkspaceIndex];
- appWorkspace.toRemoveDocumentWorkspaceIndex = -1;
- }
- else
- 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;
- Image taskImage = DrawRulerHelper.ResizeImage(appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(), 115, 86, Base.Enum.ThumbnailMode.Cut);
- Form mainForm = appWorkspace.FindForm();
- if (mainForm != null)
- {
- PdnBaseForm asPDF = mainForm as PdnBaseForm;
- if (asPDF != null) 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;
- bool save = false;
- if (this.DataInformationView.Rows.Count > 0)
- {
- for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
- {
- if ((DocumentWorkspace)(this.DataInformationView.Rows[i].Tag) == dw)
- {
- DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataInformationView.Rows[i].Cells[0];
- save = Convert.ToBoolean(checkCell.Value);
- dw.fileText = DataInformationView.Rows[i].Cells[1].Value.ToString() + DataInformationView.Rows[i].Cells[2].Value.ToString();
- dw.UpdateDw2buttonName(dw.fileText);
- dw.picName = dw.fileText;
- dw.filePath = DataInformationView.Rows[i].Cells[3].Value.ToString() +"\\" + dw.fileText;
- this.DataInformationView.Rows.Remove(this.DataInformationView.Rows[i]);
- break;
- }
- }
- }
- if (save)
- {
- if (dw.DoSaveNew())
- {
- this.cancelled = false;
- if (!dw.IsDisposed)
- appWorkspace.RemoveDocumentWorkspace(dw);
- }
- else
- this.cancelled = true;
- }
- else /*if (!save)*/
- {
- this.cancelled = false;
- if (!dw.IsDisposed)
- appWorkspace.RemoveDocumentWorkspace(dw);
- }
- //else
- //{
- // this.cancelled = true;
- //}
- }
- }
- Utility.GCFullCollect();
- }
- #endregion
- }
- }
|