Пример #1
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     textBox.Clear();
     textBox.Enabled = true;
     saveAsToolStripMenuItem.Enabled = true;
     currentFile = new TextFile();
     isChanged = false;
 }
Пример #2
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     openFileDlg.ShowDialog();
     currentFile = new TextFile(openFileDlg.FileName);
     textBox.Text = currentFile.Content;
     saveAsToolStripMenuItem.Enabled = true;
     isChanged = false;
 }
Пример #3
0
 private async void LoadTextFile(int id)
 {
     try
     {
         if (id == -1)
         {
             m_textFile = m_repository.NewFile();
         }
         else
         {
             m_textFile = await m_repository.FileById(id);
         }
         m_textFile.IsDirty = false;
         m_text.DataContext = m_textFile;
         Title = string.Format("TextEditor - {0}", string.IsNullOrEmpty(m_textFile.Name) ? "*" : m_textFile.Name);
         m_textFile.PropertyChanged += TextFileBecomeDirtyHandler;
     }
     catch (Exception exc)
     {
         MessageBox.Show(this, exc.Message + "\n" + exc.StackTrace, "Exception on loading text file", MessageBoxButton.OK,
                         MessageBoxImage.Error);
     }
 }
Пример #4
0
        private void loginButton_Click(object sender, EventArgs e) //logs the user in
        {
            try
            {
                string[] lines = System.IO.File.ReadAllLines("login.txt"); //reads the user details from login.txt

                foreach (string set in lines)
                {
                    string[] splitter = set.Split(',');
                    if (usernameTextBox.Text == splitter[0] && passwordTextBox.Text == splitter[1])
                    {
                        TextFile ss = new TextFile(splitter);
                        this.Hide();
                        ss.ShowDialog();
                        this.Show();
                    }
                }
            }
            catch (FileNotFoundException a)
            {
                Console.WriteLine(a.Message);
                Console.ReadKey();
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.DarkGreen;

            Console.WriteLine("enter the name of the file you want to create or open: ");
            string filename = Console.ReadLine();

            FileStream fs = new FileStream(filename + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);

            Console.WriteLine(
                "\nhere you go!" +
                "\nnew line commands: save, undo, exit\n\n");

            string input = "";

            using (StreamReader sr = new StreamReader(filename + ".txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                    input += line + "\n";
                }
            }

            fs = new FileStream(filename + ".txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw        = new StreamWriter(fs);
            Caretaker    caretaker = new Caretaker();
            TextFile     tf        = new TextFile(input);

            while (true)
            {
                input = Console.ReadLine();

                if (input == "save")
                {
                    caretaker.SaveState(tf);
                    continue;
                }

                else if (input == "undo")
                {
                    caretaker.RestoreState(tf);
                    fs = new FileStream(filename + ".txt", FileMode.Truncate, FileAccess.Write);
                    sw = new StreamWriter(fs);
                    sw.WriteLine(tf.Text);
                    continue;
                }

                else if (input == "exit")
                {
                    sw.Close();
                    break;
                }

                tf.Text += input + "\n";
                sw.WriteLine(input);
            }

            Console.Clear();
            Console.WriteLine("Enter a keyword to search: ");
            string        keyword  = Console.ReadLine();
            string        filepath = "/Volumes/Mac HDD/visualstudio/TextEditor/TextEditor/bin/Debug/netcoreapp3.1/";
            KeywordSearch ks       = new KeywordSearch(filepath, keyword);

            ks.SearchResult();
        }
Пример #6
0
 public Closing(TextFile file)
 {
     InitializeComponent();
     this.lbl_message.Text = String.Format("Voulez-vous enregistrer les modifications de {0}", file.FileName);
 }