コード例 #1
0
        private bool Save(tabbutton item, fctb_box fctb)
        {
            if (item.fileLocation == null)
            {
                sfdMain.FileName = item.Text;
                if (sfdMain.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }
                item.fileLocation = sfdMain.FileName;
                string filename = Path.GetFileName(item.fileLocation);
                if (filename.Length > 3 && filename.Substring(filename.Length - 3, 3) == ".py")
                {
                    filename = filename.Substring(0, filename.Length - 3);
                }
                item.Text = filename;
            }

            try
            {
                // Replace 4 spaces with Tab while saving file
                // File.WriteAllText(item.fileLocation as string, fctb.Text.Replace("    ","\t"));
                File.WriteAllText(item.fileLocation as string, fctb.Text);
                fctb.IsChanged = false;
                item.openedTab = true;
            }
            catch (Exception ex)
            {
                item.fileLocation = null;
                item.Text         = "Untitled";
                if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    return(Save(item, fctb));
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        public void newTab(string filename, int tabIndex)
        {
            String button_text  = "untitled";
            String fileLocation = null;

            if (filename != null)
            {
                fileLocation = filename;
                filename     = Path.GetFileName(filename);
                if (filename.Length > 3 && filename.Substring(filename.Length - 3, 3) == ".py")
                {
                    filename = filename.Substring(0, filename.Length - 3);
                }
                button_text = filename;

                if (tabIndex != -1)
                {
                    tabbutton temp_button = buttonList[tabIndex];
                    temp_button.openedTab = true;
                    temp_button.Text      = button_text;
                    int ind = getFctbBox(temp_button.Target);
                    fctbList[ind].OpenFile(fileLocation);
                    fctbList[ind].BringToFront();
                    temp_button.fileLocation = fileLocation;
                    buttonList[tabIndex]     = temp_button;
                    resetColor(buttonList[tabIndex]);
                    return;
                }
            }
            incrementcount++;
            tabCount++;
            button_text = "untitled" + incrementcount;
            String button_name = "tab" + incrementcount;
            String fctb_name   = "fctb" + incrementcount;

            fctb_box  fctb_box = new fctb_box();
            tabbutton button   = new tabbutton();

            if (filename != null)
            {
                fctb_box.OpenFile(fileLocation);
                button_text      = filename;
                button.openedTab = true;
            }
            fctb_box.Name = fctb_name;
            fctbList.Add(fctb_box);
            panel_editor.Controls.Add(fctbList[fctbList.Count - 1]);
            fctbList[fctbList.Count - 1].BringToFront();
            if (!panel_editor.Controls.Contains(tabpanel))
            {
                panel_editor.Controls.Add(tabpanel);
            }


            button.Text         = button_text;
            button.Name         = button_name;
            button.Target       = fctb_name;
            button.fileLocation = fileLocation;


            button.Location = new Point((focusedtab + 1) * 320, 0);
            buttonList.Insert(focusedtab + 1, button);
            // update location
            int cnt = -1;

            foreach (tabbutton item in buttonList)
            {
                cnt++;
                if (cnt > focusedtab + 1)
                {
                    item.Location = new Point(item.Location.X + 320, 0);
                }
            }
            tabpanel.Controls.Add(buttonList[focusedtab + 1]);
            resetColor(buttonList[focusedtab + 1]);
            fctbList[focusedtab].Select();
        }