Esempio n. 1
0
        /// <summary>
        /// Returns true if the file was saved or false if canceled by the user (which can happen
        /// if this file falls back to "Save as")
        /// </summary>
        bool Save(NimEditor ed)
        {
            if (ed == null)
            {
                return(true);
            }

            if (!File.Exists(ed.FileName))
            {
                return(SaveAs(ed));
            }

            try
            {
                ed.SaveToFile(ed.FileName, Encoding.UTF8);
                ed.Modified = false;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                throw;
            }


            return(true);
        }
Esempio n. 2
0
        private bool OpenDocument(string filename)
        {
            //TODO: check if document is already open and switch to it!

            //ios this document already opened? if so, switch to it:
            NimEditor oldEditor = FindEditor(filename);

            if (oldEditor != null)
            {
                var tp = FindTabPage(oldEditor);
                if (tp != null)
                {
                    tabControl1.SelectedTab = tp;
                    return(true);
                }
            }

            if (File.Exists(filename))
            {
                NimEditor se = CreateDocument(filename);
                se.OpenFile(filename, Encoding.UTF8);
                se.Modified = false;

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        TabPage FindTabPage(NimEditor ed)
        {
            foreach (TabPage tp in tabControl1.TabPages)
            {
                if (tp.Controls[0] as NimEditor == ed)
                {
                    return(tp);
                }
            }

            return(null);
        }
Esempio n. 4
0
        private NimEditor CreateDocument(string filename = "", string displayName = "")
        {
            NimEditor se = new NimEditor(filename);

            se.ModifiedChanged += se_ModifiedChanged;



            TabPage tp = new TabPage(displayName);

            se.Dock = DockStyle.Fill;
            tp.Controls.Add(se);
            tabControl1.TabPages.Add(tp);
            tabControl1.SelectedTab = tp;

            UpdateTabText(tp);

            return(se);
        }
Esempio n. 5
0
        bool GetCurrentFile(out string filename, bool showSaveMsg)
        {
            filename = null;

            NimEditor ed = CurrentEditor;

            if (ed == null)
            {
                return(false);
            }
            if (!File.Exists(ed.FileName))
            {
                if (showSaveMsg)
                {
                    MessageBox.Show("The current file has to be saved first.");
                }
                return(false);
            }

            filename = ed.FileName;
            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Returns true if the file was saved or false if canceled by the user.
        /// </summary>
        bool SaveAs(NimEditor ed)
        {
            if (ed == null)
            {
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(ed.FileName))
            {
                string dir = Path.GetDirectoryName(ed.FileName);
                string fn  = Path.GetFileName(ed.FileName);

                if (Directory.Exists(dir))
                {
                    saveDialog.InitialDirectory = dir;
                }
                saveDialog.FileName = Path.GetFileName(ed.FileName);
            }

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ed.SaveToFile(saveDialog.FileName, Encoding.UTF8);
                    ed.FileName = saveDialog.FileName;
                    ed.Modified = true; //ste to true+false to force uodate of filename in tab even if modified was not changed
                    ed.Modified = false;
                    return(true);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                    throw;
                }
            }

            return(false);
        }
Esempio n. 7
0
        private void UpdateTabText(TabPage tp)
        {
            if (tp == null)
            {
                return;
            }

            NimEditor ed = tp.Controls[0] as NimEditor;

            if (ed == null)
            {
                return;
            }

            string displayName = ed.DisplayName;

            if (string.IsNullOrEmpty(displayName))
            {
                if (ed.NonameIndex <= 0) //unique noname count index
                {
                    ed.NonameIndex = nonameCount++;
                }
                if (string.IsNullOrEmpty(displayName))
                {
                    displayName = "NONAME" + (ed.NonameIndex).ToString(CultureInfo.InvariantCulture) + ".nim";
                }
            }

            if (ed.Modified)
            {
                tp.Text = displayName + "*";
            }
            else
            {
                tp.Text = displayName;
            }
        }