ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.ScratchPad/ScratchPad.cs
(Generate patch)

Comparing trunk/RomCheater.ScratchPad/ScratchPad.cs (file contents):
Revision 762 by william, Thu Jun 20 20:25:55 2013 UTC vs.
Revision 769 by william, Thu Jun 20 21:34:48 2013 UTC

# Line 29 | Line 29 | namespace RomCheater.ScratchPad
29   {
30      public partial class ScratchPad : DockContent
31      {
32 <
32 >        List<ScratchPadDocument> docuemntList = new List<ScratchPadDocument>();
33          private UserControlPlugin plugin;
34          private bool PostInitDone = false;
35          public ScratchPad(UserControlPlugin plugin)
36          {
37              this.plugin = plugin;
38              InitPluginFramework();
39 <            InitializeComponent();            
40 <            this.PerformPreInit();
39 >            InitializeComponent();                        
40          }
41  
42  
# Line 76 | Line 75 | namespace RomCheater.ScratchPad
75          }
76  
77  
79        private void PerformPreInit()
80        {
81            txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Italic);
82            txtScratchPad.ForeColor = SystemColors.GrayText;
83            StringBuilder builder = new StringBuilder();
84            txtScratchPad.Clear();
85
86            builder.AppendFormat(System.Environment.NewLine);
87            builder.AppendFormat("\tThis is a scratchpad");
88            builder.AppendFormat(System.Environment.NewLine);
89            builder.AppendFormat("\tYou can type anything in here, and save it for later or load an existing file.");
90
91            txtScratchPad.AppendText(builder.ToString());
92        }
78  
79  
95        private void PerformSaveOperation()
96        {
97        }
98
99        private void mnuItemSave_Click(object sender, EventArgs e)
100        {
101            PerformPostInit();
102            DialogResult result = ScracthPadSaver.ShowDialog();
103            if (result != DialogResult.OK) { return; }
104            try
105            {
106                using (FileStream fs = new FileStream(ScracthPadSaver.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
107                {
108                    try
109                    {
110                        using (StreamWriter sw = new StreamWriter(fs))
111                        {
112                            string line = string.Empty;
113                            using (StringReader sr = new StringReader(txtScratchPad.Text))
114                            {
115                                while ((line = sr.ReadLine()) != null)
116                                {
117                                    sw.WriteLine(line);
118                                }
119                            }
120                            sw.Flush();
121                            sw.Close();
122                        }
123                    }
124                    catch (Exception ex)
125                    {
126                        logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
127                        logger.VerboseError.WriteLine(ex.ToString());
128                        MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
129                        return;
130                    }
131                }
132                MessageBox.Show(string.Format("Successfully saved file: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
133            }
134            catch (Exception ex)
135            {
136                logger.Error.WriteLine("Failed to save file: {0}", ScracthPadSaver.FileName);
137                logger.VerboseError.WriteLine(ex.ToString());
138                MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(ScracthPadSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
139            }
140        }
80  
142        private void mnuItemOpen_Click(object sender, EventArgs e)
143        {
144            PerformPostInit();
145            DialogResult result = ScracthPadLoader.ShowDialog();
146            if (result != DialogResult.OK) { return; }
147            txtScratchPad.Clear();
81  
149            try
150            {
151                using (FileStream fs = new FileStream(ScracthPadLoader.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
152                {
153                    try
154                    {
155                        using (StreamReader sr = new StreamReader(fs))
156                        {
157                            txtScratchPad.AppendText(sr.ReadToEnd());
158                        }
159                    }
160                    catch (Exception ex)
161                    {
162                        logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
163                        logger.VerboseError.WriteLine(ex.ToString());
164                        MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
165                        return;
166                    }
167                    //MessageBox.Show(string.Format("Successfully opened file: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
168                }
169            }
170            catch (Exception ex)
171            {
172                logger.Error.WriteLine("Failed to open file: {0}", ScracthPadLoader.FileName);
173                logger.VerboseError.WriteLine(ex.ToString());
174                MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(ScracthPadLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
175            }
82  
177            txtScratchPad.SelectionStart = 0;
178            txtScratchPad.ScrollToCaret();
83  
180        }
84  
85 <
183 <        private void PerformPostInit()
184 <        {
185 <            if (!PostInitDone)
186 <            {
187 <                txtScratchPad.Clear();
188 <                txtScratchPad.Font = new System.Drawing.Font(txtScratchPad.Font, FontStyle.Regular);
189 <                txtScratchPad.ForeColor = Color.Black;
190 <                PostInitDone = true;
191 <            }  
192 <        }
193 <        private void txtScratchPad_MouseDown(object sender, MouseEventArgs e)
194 <        {
195 <            PerformPostInit();
196 <        }
197 <
198 <        private void txtScratchPad_KeyDown(object sender, KeyEventArgs e)
199 <        {
200 <            PerformPostInit();
201 <        }
202 <
203 <        private void mnuItemUndo_Click(object sender, EventArgs e)
204 <        {
205 <            PerformPostInit();
206 <            txtScratchPad.Focus();
207 <            SendKeys.Send("^Z");
208 <        }
209 <
210 <        private void mnuItemRedo_Click(object sender, EventArgs e)
211 <        {
212 <            PerformPostInit();
213 <            txtScratchPad.Focus();
214 <            SendKeys.Send("^Y");
215 <        }
216 <
217 <        private void mnuItemClear_Click(object sender, EventArgs e)
218 <        {
219 <            txtScratchPad.Clear();
220 <        }
221 <
222 <        private void mnuItemCopy_Click(object sender, EventArgs e)
223 <        {
224 <            PerformPostInit();
225 <            string text = txtScratchPad.Text;
226 <            text = text.Replace("\n", System.Environment.NewLine);
227 <            Clipboard.SetText(text);
228 <        }
229 <
230 <        private void mnuItemPaste_Click(object sender, EventArgs e)
231 <        {
232 <            PerformPostInit();
233 <            string text = Clipboard.GetText();
234 <            txtScratchPad.Text = text;
235 <        }
85 >    
86  
87          private void ScratchPad_FormClosing(object sender, FormClosingEventArgs e)
88          {
89 <            if (txtScratchPad.Text != string.Empty && PostInitDone)
89 >            //if (txtScratchPad.Text != string.Empty && PostInitDone)
90 >            //{
91 >            //    DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
92 >            //    if (result == DialogResult.Cancel)
93 >            //    {
94 >            //        e.Cancel = true;
95 >            //        return;
96 >            //    }
97 >            //    if (result == DialogResult.Yes)
98 >            //    {
99 >            //        mnuItemSave.PerformClick();
100 >            //    }
101 >            //}
102 >            
103 >            for (int i = 0; i < docuemntList.Count; i++)
104              {
105 <                DialogResult result = MessageBox.Show("Would you like to save the ScratchPad data before Closing?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
106 <                if (result == DialogResult.Cancel)
243 <                {
244 <                    e.Cancel = true;
245 <                    return;
246 <                }
247 <                if (result == DialogResult.Yes)
248 <                {
249 <                    mnuItemSave.PerformClick();
250 <                }
105 >                var Document = docuemntList[i];
106 >                Document.OnDocumentQuit();                
107              }
108 +
109          }
110  
111          private void ScratchPad_Deactivate<T>(object sender, T e) where T: EventArgs
# Line 261 | Line 118 | namespace RomCheater.ScratchPad
118              catch { }
119          }
120  
121 <        private void txtScratchPad_LinkClicked(object sender, LinkClickedEventArgs e)
121 >        private void mnuItemNew_Click(object sender, EventArgs e)
122          {
123 <            //System.Diagnostics.Process.Start(e.LinkText);
124 <            if (this.plugin != null)
125 <            {
126 <                var p = this.plugin.WebBrowserInterface;
127 <                if (p != null)
128 <                {
129 <                    p.Navigate(e.LinkText);
130 <                }
131 <                else
132 <                {
133 <                    logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
134 <                    logger.Debug.WriteLine("Could not obtain a handle to the WebBrowser Provider's Interface.");
135 <                }
136 <            }
137 <            else
138 <            {
139 <                logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
140 <                logger.Debug.WriteLine("Loaded plugin is null");
141 <            }
142 <        }
123 >            // create new document
124 >            int tp_index = this.tb.TabPages.Count;
125 >            ScratchPadDocument t = new ScratchPadDocument(tp_index);
126 >            docuemntList.Add(t);
127 >            this.tb.TabPages.Add(t.DocumentTab);
128 >        }
129 >
130 >        //private void txtScratchPad_LinkClicked(object sender, LinkClickedEventArgs e)
131 >        //{
132 >        //    //System.Diagnostics.Process.Start(e.LinkText);
133 >        //    if (this.plugin != null)
134 >        //    {
135 >        //        var p = this.plugin.WebBrowserInterface;
136 >        //        if (p != null)
137 >        //        {
138 >        //            p.Navigate(e.LinkText);
139 >        //        }
140 >        //        else
141 >        //        {
142 >        //            logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
143 >        //            logger.Debug.WriteLine("Could not obtain a handle to the WebBrowser Provider's Interface.");
144 >        //        }
145 >        //    }
146 >        //    else
147 >        //    {
148 >        //        logger.Debug.WriteLine("Could not navigate to url: '{0}'", e.LinkText);
149 >        //        logger.Debug.WriteLine("Loaded plugin is null");
150 >        //    }
151 >        //}
152      }
153   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines