Ejemplo n.º 1
0
        // Open file
        private void abrirArchivoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "All files (*.*)|*.*";
            openFileDialog.RestoreDirectory = true;

            // If no tabs then create once
            if (!(tabs.SelectedIndex >= 0))
            {
                this.addNewTab();
            }

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Change current tab name
                            tabs.SelectedTab.Text        = Path.GetFileNameWithoutExtension(openFileDialog.SafeFileName);
                            tabs.SelectedTab.ToolTipText = openFileDialog.FileName;
                            tabs.SelectedTab.ImageKey    = getIconFromExt(Path.GetExtension(openFileDialog.SafeFileName).Substring(1)) + ".png";

                            // Take file extension
                            codeLang.Text = Path.GetExtension(openFileDialog.SafeFileName).Substring(1).ToUpper();

                            // Load file to Scintilla
                            SuEditor editor = (SuEditor)editors[tabs.SelectedIndex];
                            editor.Text = File.ReadAllText(openFileDialog.FileName);

                            // Get hash code of file
                            hashFile.Text = myStream.GetHashCode().ToString();
                            myStream.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se pudo leer el fichero.", "Error fatal");
                }
            }
        }
Ejemplo n.º 2
0
        // Save file
        private void guardarArchivoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "All files (*.*)|*.*";
            saveFileDialog.RestoreDirectory = true;

            if (tabs.SelectedIndex >= 0)
            {
                try
                {
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        if ((myStream = saveFileDialog.OpenFile()) != null)
                        {
                            using (myStream)
                            {
                                // Change current tab name
                                tabs.SelectedTab.Text        = Path.GetFileNameWithoutExtension(saveFileDialog.FileName);
                                tabs.SelectedTab.ToolTipText = saveFileDialog.ToString();
                                tabs.SelectedTab.ImageKey    = getIconFromExt(Path.GetExtension(saveFileDialog.FileName).Substring(1)) + ".png";

                                // Take file extension
                                codeLang.Text = Path.GetExtension(saveFileDialog.FileName).Substring(1).ToUpper();

                                // Load file to editor
                                SuEditor editor = (SuEditor)editors[tabs.SelectedIndex];
                                //editor.SaveFile(myStream, RichTextBoxStreamType.PlainText);

                                // Get hash code of file
                                hashFile.Text = myStream.GetHashCode().ToString();
                                myStream.Close();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se pudo escribir el fichero.", "Error fatal");
                }
            }
        }
Ejemplo n.º 3
0
        private void addNewTab()
        {
            string  title     = "Nuevo " + (tabs.TabCount + 1).ToString();
            TabPage myTabPage = new TabPage(title);

            // Add event to the new TabPage
            //myTabPage.MouseClick += new MouseEventHandler(tabs_MouseClick);

            tabs.TabPages.Add(myTabPage);
            tabs.SelectedIndex = tabs.TabCount - 1;

            // Create internal component: SuEditor
            SuEditor editor = new SuEditor(new Scintilla());

            // Styling the editor
            editor.Dock = DockStyle.Fill;

            editors.Add(editor);
            tabs.SelectedTab.Controls.Add(editor);
            //Console.Write("selected=" + tabs.SelectedIndex + " total=" + tabs.TabCount);
        }