UnsavedProcessingDialog.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.SettingModel;
  3. using PaintDotNet.File.BatchSaveComponet;
  4. using System;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. namespace PaintDotNet.File.UnsavedProcessing
  9. {
  10. /// <summary>
  11. /// 关闭保存
  12. /// </summary>
  13. internal class UnsavedProcessingDialog : PdnBaseForm
  14. {
  15. #region 属性
  16. private DataGridView DataInformationView;
  17. private Panel panel1;
  18. private Panel panel2;
  19. private Button btn_Close;
  20. private Button btn_SelectAll;
  21. private Button btn_NotAll;
  22. private Button btn_Determine;
  23. private AppWorkspace appWorkspace;
  24. private DocumentWorkspace closeMe;
  25. private DataGridViewCheckBoxColumn Column1;
  26. private DataGridViewTextBoxColumn Column2;
  27. private DataGridViewTextBoxColumn Column3;
  28. private DataGridViewTextBoxColumn Column4;
  29. private DataGridViewButtonColumn Column5;
  30. private bool cancelled;
  31. public bool Cancelled
  32. {
  33. get
  34. {
  35. return this.cancelled;
  36. }
  37. }
  38. #endregion
  39. #region 构造函数
  40. public UnsavedProcessingDialog(AppWorkspace appWorkspace)
  41. {
  42. this.appWorkspace = appWorkspace;
  43. InitializeComponent();
  44. InitializeLanguageText();
  45. }
  46. #endregion
  47. #region 事件
  48. private void UnsavedProcessingDialog_SizeChanged(object sender, EventArgs e)
  49. {
  50. DataInformationView.Columns[0].Width = 40;//设置保存列宽度
  51. DataInformationView.Columns[1].Width = 200;//设置名称列宽度
  52. DataInformationView.Columns[2].Width = 70;//设置类型列宽度
  53. DataInformationView.Columns[3].Width = DataInformationView.Width - 353;//设置路径列宽度
  54. DataInformationView.Columns[4].Width = 40;//设置浏览列宽度
  55. }
  56. private void UnsavedProcessingDialog_Load(object sender, EventArgs e)
  57. {
  58. DisplayNotSaved();
  59. }
  60. /// <summary>
  61. /// 确定
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void btn_Determine_Click(object sender, EventArgs e)
  66. {
  67. if (this.DataInformationView.Rows.Count > 0)
  68. {
  69. for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
  70. {
  71. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataInformationView.Rows[i].Cells[0];
  72. bool isSave = Convert.ToBoolean(checkCell.Value);
  73. if (isSave)
  74. {
  75. string path = this.DataInformationView.Rows[i].Cells[3].Value.ToString();
  76. if (!Directory.Exists(path))//判断是否存在
  77. {
  78. MessageBox.Show(path + " 路径不存在!");
  79. return;
  80. }
  81. }
  82. }
  83. }
  84. int Length = this.appWorkspace.DocumentWorkspaces.Length;
  85. for (int i = 0; i < Length; i++) PerformAction();
  86. this.DialogResult = DialogResult.OK;
  87. this.Close();
  88. }
  89. /// <summary>
  90. /// 全不选
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. private void btn_NotAll_Click(object sender, EventArgs e)
  95. {
  96. if (this.DataInformationView.Rows.Count > 0)
  97. {
  98. for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
  99. {
  100. this.DataInformationView.Rows[i].Cells[0].Value = false;
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// 选择所有
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. private void btn_SelectAll_Click(object sender, EventArgs e)
  110. {
  111. if (this.DataInformationView.Rows.Count > 0)
  112. {
  113. for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
  114. {
  115. this.DataInformationView.Rows[i].Cells[0].Value = true;
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// 取消
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void btn_Close_Click(object sender, EventArgs e)
  125. {
  126. this.cancelled = true;
  127. this.Close();
  128. }
  129. /// <summary>
  130. /// 点击浏览选择路径
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void DataInformationView_CellClick(object sender, DataGridViewCellEventArgs e)
  135. {
  136. try
  137. {
  138. if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
  139. DataGridViewCell cell = this.DataInformationView.Rows[e.RowIndex].Cells[e.ColumnIndex];
  140. if (e.ColumnIndex == 4 /*cell.Value.ToString() == "浏览"*/ )
  141. {
  142. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  143. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  144. {
  145. string path = folderBrowserDialog1.SelectedPath;
  146. this.DataInformationView.Rows[e.RowIndex].Cells[3].Value = path;
  147. }
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. }
  153. }
  154. #endregion
  155. #region 方法
  156. /// <summary>
  157. /// 控件初始化
  158. /// </summary>
  159. private void InitializeComponent()
  160. {
  161. this.DataInformationView = new System.Windows.Forms.DataGridView();
  162. this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
  163. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  164. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  165. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  166. this.Column5 = new System.Windows.Forms.DataGridViewButtonColumn();
  167. this.panel1 = new System.Windows.Forms.Panel();
  168. this.panel2 = new System.Windows.Forms.Panel();
  169. this.btn_Close = new System.Windows.Forms.Button();
  170. this.btn_SelectAll = new System.Windows.Forms.Button();
  171. this.btn_NotAll = new System.Windows.Forms.Button();
  172. this.btn_Determine = new System.Windows.Forms.Button();
  173. ((System.ComponentModel.ISupportInitialize)(this.DataInformationView)).BeginInit();
  174. this.panel1.SuspendLayout();
  175. this.panel2.SuspendLayout();
  176. this.SuspendLayout();
  177. //
  178. // DataInformationView
  179. //
  180. this.DataInformationView.AllowUserToAddRows = false;
  181. this.DataInformationView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  182. | System.Windows.Forms.AnchorStyles.Left)
  183. | System.Windows.Forms.AnchorStyles.Right)));
  184. this.DataInformationView.BackgroundColor = System.Drawing.SystemColors.Control;
  185. this.DataInformationView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  186. this.DataInformationView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  187. this.Column1,
  188. this.Column2,
  189. this.Column3,
  190. this.Column4,
  191. this.Column5});
  192. this.DataInformationView.Location = new System.Drawing.Point(0, 0);
  193. this.DataInformationView.Name = "DataInformationView";
  194. this.DataInformationView.RowHeadersVisible = false;
  195. this.DataInformationView.RowTemplate.Height = 23;
  196. this.DataInformationView.Size = new System.Drawing.Size(694, 352);
  197. this.DataInformationView.TabIndex = 0;
  198. this.DataInformationView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataInformationView_CellClick);
  199. //
  200. // Column1
  201. //
  202. this.Column1.HeaderText = PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText");
  203. this.Column1.Name = "Column1";
  204. this.Column1.Width = 40;
  205. //
  206. // Column2
  207. //
  208. this.Column2.HeaderText = PdnResources.GetString("Menu.name.text");
  209. this.Column2.Name = "Column2";
  210. this.Column2.Width = 200;
  211. //
  212. // Column3
  213. //
  214. this.Column3.HeaderText = PdnResources.GetString("Menu.Type.text");
  215. this.Column3.Name = "Column3";
  216. this.Column3.Width = 70;
  217. //
  218. // Column4
  219. //
  220. this.Column4.HeaderText = PdnResources.GetString("Path.text");
  221. this.Column4.Name = "Column4";
  222. this.Column4.Width = 326;
  223. //
  224. // Column5
  225. //
  226. this.Column5.HeaderText = "";
  227. this.Column5.Name = "Column5";
  228. this.Column5.Width = 55;
  229. //
  230. // panel1
  231. //
  232. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  233. | System.Windows.Forms.AnchorStyles.Left)
  234. | System.Windows.Forms.AnchorStyles.Right)));
  235. this.panel1.Controls.Add(this.DataInformationView);
  236. this.panel1.Location = new System.Drawing.Point(6, 7);
  237. this.panel1.Name = "panel1";
  238. this.panel1.Size = new System.Drawing.Size(694, 352);
  239. this.panel1.TabIndex = 5;
  240. //
  241. // panel2
  242. //
  243. this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  244. | System.Windows.Forms.AnchorStyles.Right)));
  245. this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  246. this.panel2.Controls.Add(this.btn_Close);
  247. this.panel2.Controls.Add(this.btn_SelectAll);
  248. this.panel2.Controls.Add(this.btn_NotAll);
  249. this.panel2.Controls.Add(this.btn_Determine);
  250. this.panel2.Location = new System.Drawing.Point(6, 364);
  251. this.panel2.Name = "panel2";
  252. this.panel2.Size = new System.Drawing.Size(694, 40);
  253. this.panel2.TabIndex = 6;
  254. //
  255. // btn_Close
  256. //
  257. this.btn_Close.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  258. this.btn_Close.Location = new System.Drawing.Point(603, 7);
  259. this.btn_Close.Name = "btn_Close";
  260. this.btn_Close.Size = new System.Drawing.Size(75, 23);
  261. this.btn_Close.TabIndex = 3;
  262. this.btn_Close.Text = "取消";
  263. this.btn_Close.UseVisualStyleBackColor = true;
  264. this.btn_Close.Click += new System.EventHandler(this.btn_Close_Click);
  265. //
  266. // btn_SelectAll
  267. //
  268. this.btn_SelectAll.Location = new System.Drawing.Point(93, 7);
  269. this.btn_SelectAll.Name = "btn_SelectAll";
  270. this.btn_SelectAll.Size = new System.Drawing.Size(75, 23);
  271. this.btn_SelectAll.TabIndex = 1;
  272. this.btn_SelectAll.Text = "选择所有";
  273. this.btn_SelectAll.UseVisualStyleBackColor = true;
  274. this.btn_SelectAll.Click += new System.EventHandler(this.btn_SelectAll_Click);
  275. //
  276. // btn_NotAll
  277. //
  278. this.btn_NotAll.Location = new System.Drawing.Point(12, 7);
  279. this.btn_NotAll.Name = "btn_NotAll";
  280. this.btn_NotAll.Size = new System.Drawing.Size(75, 23);
  281. this.btn_NotAll.TabIndex = 0;
  282. this.btn_NotAll.Text = "全不选";
  283. this.btn_NotAll.UseVisualStyleBackColor = true;
  284. this.btn_NotAll.Click += new System.EventHandler(this.btn_NotAll_Click);
  285. //
  286. // btn_Determine
  287. //
  288. this.btn_Determine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  289. this.btn_Determine.Location = new System.Drawing.Point(522, 7);
  290. this.btn_Determine.Name = "btn_Determine";
  291. this.btn_Determine.Size = new System.Drawing.Size(75, 23);
  292. this.btn_Determine.TabIndex = 2;
  293. this.btn_Determine.Text = "确定";
  294. this.btn_Determine.UseVisualStyleBackColor = true;
  295. this.btn_Determine.Click += new System.EventHandler(this.btn_Determine_Click);
  296. //
  297. // UnsavedProcessingDialog
  298. //
  299. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  300. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  301. this.ClientSize = new System.Drawing.Size(706, 411);
  302. this.Controls.Add(this.panel2);
  303. this.Controls.Add(this.panel1);
  304. this.MinimumSize = new System.Drawing.Size(722, 450);
  305. this.Name = "UnsavedProcessingDialog";
  306. this.ShowIcon = false;
  307. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  308. this.Text = "保存文件";
  309. this.TopMost = true;
  310. this.Load += new System.EventHandler(this.UnsavedProcessingDialog_Load);
  311. this.SizeChanged += new System.EventHandler(this.UnsavedProcessingDialog_SizeChanged);
  312. this.Controls.SetChildIndex(this.panel1, 0);
  313. this.Controls.SetChildIndex(this.panel2, 0);
  314. ((System.ComponentModel.ISupportInitialize)(this.DataInformationView)).EndInit();
  315. this.panel1.ResumeLayout(false);
  316. this.panel2.ResumeLayout(false);
  317. this.ResumeLayout(false);
  318. }
  319. private void InitializeLanguageText()
  320. {
  321. this.btn_Determine.Text = PdnResources.GetString("Menu.ensure.text");
  322. this.btn_Close.Text = PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText");
  323. this.btn_NotAll.Text = PdnResources.GetString("Menu.Binaryoperation.Objecthandling.unselectall.text");
  324. this.btn_SelectAll.Text = PdnResources.GetString("SelectAll.text");
  325. this.Text = PdnResources.GetString("SaveFile.text");
  326. }
  327. /// <summary>
  328. /// 初始化
  329. /// </summary>
  330. private void DisplayNotSaved()
  331. {
  332. this.DataInformationView.Columns[2].ReadOnly = true;
  333. this.DataInformationView.Columns[3].ReadOnly = true;
  334. foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
  335. {
  336. if (document.Document.Dirty)
  337. {
  338. string imgName = document.GetFriendlyName();
  339. string imgType = string.Empty;
  340. int index = 0;
  341. if (imgName.Contains("."))
  342. {
  343. index = imgName.LastIndexOf('.');
  344. imgType = imgName.Substring(index);
  345. imgName = imgName.Substring(0, index);
  346. }
  347. else
  348. imgType = ".jpg";
  349. //获取图片路径
  350. string fileName;
  351. //FileType fileType;
  352. //SaveConfigToken saveConfigToken;
  353. document.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
  354. string path = Path.GetDirectoryName(fileName);
  355. 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"));
  356. this.DataInformationView.Rows[this.DataInformationView.Rows.Count - 1].Tag = document;
  357. }
  358. }
  359. }
  360. /// <summary>
  361. /// 保存与关闭Document
  362. /// </summary>
  363. public void PerformAction()
  364. {
  365. if (appWorkspace == null)
  366. throw new ArgumentNullException("appWorkspace");
  367. appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  368. DocumentWorkspace dw;
  369. if (this.closeMe == null)
  370. {
  371. if (appWorkspace.toRemoveDocumentWorkspaceIndex >= 0 && appWorkspace.toRemoveDocumentWorkspaceIndex < appWorkspace.DocumentWorkspaces.Length)
  372. {
  373. dw = appWorkspace.DocumentWorkspaces[appWorkspace.toRemoveDocumentWorkspaceIndex];
  374. appWorkspace.toRemoveDocumentWorkspaceIndex = -1;
  375. }
  376. else
  377. dw = appWorkspace.ActiveDocumentWorkspace;
  378. }
  379. else
  380. {
  381. dw = this.closeMe;
  382. }
  383. if (dw != null)
  384. {
  385. if (dw.Document == null)
  386. appWorkspace.RemoveDocumentWorkspace(dw);
  387. else if (!dw.Document.Dirty)
  388. appWorkspace.RemoveDocumentWorkspace(dw);
  389. else
  390. {
  391. appWorkspace.ActiveDocumentWorkspace = dw;
  392. Image taskImage = DrawRulerHelper.ResizeImage(appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(), 115, 86, Base.Enum.ThumbnailMode.Cut);
  393. Form mainForm = appWorkspace.FindForm();
  394. if (mainForm != null)
  395. {
  396. PdnBaseForm asPDF = mainForm as PdnBaseForm;
  397. if (asPDF != null) asPDF.RestoreWindow();
  398. }
  399. Icon warningIcon;
  400. ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png");
  401. if (warningIconImageRes != null)
  402. {
  403. Image warningIconImage = warningIconImageRes.Reference;
  404. warningIcon = Utility.ImageToIcon(warningIconImage, false);
  405. }
  406. else
  407. warningIcon = null;
  408. bool save = false;
  409. if (this.DataInformationView.Rows.Count > 0)
  410. {
  411. for (int i = 0; i < this.DataInformationView.Rows.Count; i++)
  412. {
  413. if ((DocumentWorkspace)(this.DataInformationView.Rows[i].Tag) == dw)
  414. {
  415. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataInformationView.Rows[i].Cells[0];
  416. save = Convert.ToBoolean(checkCell.Value);
  417. dw.fileText = DataInformationView.Rows[i].Cells[1].Value.ToString() + DataInformationView.Rows[i].Cells[2].Value.ToString();
  418. dw.UpdateDw2buttonName(dw.fileText);
  419. dw.picName = dw.fileText;
  420. dw.filePath = DataInformationView.Rows[i].Cells[3].Value.ToString() +"\\" + dw.fileText;
  421. this.DataInformationView.Rows.Remove(this.DataInformationView.Rows[i]);
  422. break;
  423. }
  424. }
  425. }
  426. if (save)
  427. {
  428. if (dw.DoSaveNew())
  429. {
  430. this.cancelled = false;
  431. if (!dw.IsDisposed)
  432. appWorkspace.RemoveDocumentWorkspace(dw);
  433. }
  434. else
  435. this.cancelled = true;
  436. }
  437. else /*if (!save)*/
  438. {
  439. this.cancelled = false;
  440. if (!dw.IsDisposed)
  441. appWorkspace.RemoveDocumentWorkspace(dw);
  442. }
  443. //else
  444. //{
  445. // this.cancelled = true;
  446. //}
  447. }
  448. }
  449. Utility.GCFullCollect();
  450. }
  451. #endregion
  452. }
  453. }