Esempio n. 1
0
        private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (CurrentFilePath == null)
            {
                Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                datagrid_elements tempgrid         = new datagrid_elements();
                string            temp_s           = "";
                foreach (datagrid_elements element in datagrid.ItemsSource)
                {
                    temp_s += element.data + "\n";
                }
                dlg.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
                if (dlg.ShowDialog() == true)
                {
                    File.WriteAllText(dlg.FileName, temp_s);
                }
            }

            else
            {
                string temp_s = "";
                foreach (datagrid_elements element in datagrid.ItemsSource)
                {
                    temp_s += element.data + "\n";
                }
                File.WriteAllText(CurrentFilePath, temp_s);
            }
        }
Esempio n. 2
0
        private void commandline_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) // COMMANDLINE STUFF
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                var      command = command_box.Text;
                string[] temp    = command.Split(' ');

                if (temp[0].ToLower() == "save" && temp.Count() > 1 && temp[1].ToLower() == "as")
                {
                    Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                    datagrid_elements tempgrid         = new datagrid_elements();
                    string            temp_s           = "";
                    foreach (datagrid_elements element in datagrid.ItemsSource)
                    {
                        temp_s += element.data + "\n";
                    }
                    dlg.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
                    if (dlg.ShowDialog() == true)
                    {
                        File.WriteAllText(dlg.FileName, temp_s);
                    }
                }
                else if (temp[0].ToLower() == "save")
                {
                    if (CurrentFilePath == null)
                    {
                        Microsoft.Win32.SaveFileDialog dlg3 = new Microsoft.Win32.SaveFileDialog();
                        datagrid_elements tempgrid2         = new datagrid_elements();
                        string            temp_s2           = "";
                        foreach (datagrid_elements element in datagrid.ItemsSource)
                        {
                            temp_s2 += element.data + "\n";
                        }
                        dlg3.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
                        if (dlg3.ShowDialog() == true)
                        {
                            File.WriteAllText(dlg3.FileName, temp_s2);
                        }
                    }

                    else
                    {
                        string temp_s3 = "";
                        foreach (datagrid_elements element in datagrid.ItemsSource)
                        {
                            temp_s3 += element.data + "\n";
                        }
                        File.WriteAllText(CurrentFilePath, temp_s3);
                    }
                }

                else if (temp[0].ToLower() == "search" || temp[0].ToLower() == "find")
                {
                    int    founds = 0, totalfounds = 0, line_num, control = 0, position = 0;
                    string s_str;
                    if (temp.Length == 3)
                    {
                        string[] parts = temp[1].Split('/');
                        s_str = parts[1];

                        if (parts[2] == "*")
                        {
                            line_num = 0;
                        }
                        else
                        {
                            line_num = Int32.Parse(parts[2]) - 1;
                        }

                        int column_number = Int32.Parse(temp[2]);

                        for (int i = line_num; i < data_list.Count(); i++)
                        {
                            if (control == 0 && data_list[i].data.Substring(column_number).Contains(s_str))
                            {
                                founds = 1;
                                totalfounds++;
                                control++;
                                position = i;
                            }
                            else if (control != 0 && data_list[i].data.Contains(s_str))
                            {
                                founds = 1;
                                totalfounds++;
                                position = i;
                            }
                            control++;
                        }

                        if (founds == 1)
                        {
                            System.Windows.MessageBox.Show(s_str + " is found " + totalfounds + " times.");
                            currentline           = position;
                            datagrid.SelectedItem = datagrid.Items[currentline];
                            datagrid.ScrollIntoView(datagrid.Items[currentline]);
                        }
                        else
                        {
                            System.Windows.MessageBox.Show(s_str + " is not found ");
                        }
                    }
                }

                else if (temp[0].Contains("1") || temp[0].Contains("2") || temp[0].Contains("3") || temp[0].Contains("4") || temp[0].Contains("5") || temp[0].Contains("6") ||
                         temp[0].Contains("7") || temp[0].Contains("8") || temp[0].Contains("9"))
                {
                    int number = Int32.Parse(temp[0]);
                    if (number >= counter_size)
                    {
                        number = counter_size;
                    }

                    currentline           = number;
                    datagrid.SelectedItem = datagrid.Items[number - 1];
                    datagrid.ScrollIntoView(datagrid.Items[number - 1]);
                }

                else if (temp[0].ToLower() == "up")
                {
                    int number = Int32.Parse(temp[1]);

                    if (currentline - number <= 1)
                    {
                        currentline = 1;
                        for (int i = 0; i < counter_size; i++)
                        {
                            scrollViewer.LineUp();
                        }
                    }
                    else
                    {
                        currentline -= number;
                        for (int i = 0; i < number; i++)
                        {
                            scrollViewer.LineUp();
                        }
                    }
                }

                else if (temp[0].ToLower() == "down")
                {
                    int number = Int32.Parse(temp[1]);

                    if (number + currentline >= counter_size)
                    {
                        currentline = counter_size;
                        for (int i = 0; i < counter_size; i++)
                        {
                            scrollViewer.LineDown();
                        }
                    }
                    else
                    {
                        currentline += number;
                        for (int i = 0; i < number; i++)
                        {
                            scrollViewer.LineDown();
                        }
                    }
                }
                else if (temp[0].ToLower() == "left")
                {
                    int number = Int32.Parse(temp[1]);

                    for (int i = 0; i < number; i++)
                    {
                        scrollViewer.LineLeft();
                    }
                }
                else if (temp[0].ToLower() == "right")
                {
                    int number = Int32.Parse(temp[1]);
                    for (int i = 0; i < number; i++)
                    {
                        scrollViewer.LineRight();
                    }
                }
                else if (temp[0].ToLower() == "forward")
                {
                    if (MainWindowHeight == new_windowsize)
                    {
                        if (currentline - 9 < 1)
                        {
                            currentline = 1;
                        }
                        else
                        {
                            currentline -= 9;
                        }
                        for (int i = 0; i < 9; i++)
                        {
                            scrollViewer.LineUp();
                        }
                    }
                    else if (MainWindowHeight > new_windowsize)
                    {
                        double a  = (MainWindowHeight - new_windowsize) / 20;
                        int    a2 = Convert.ToInt32(a);
                        if (currentline - 9 + a2 < 1)
                        {
                            currentline = 1;
                        }
                        else
                        {
                            currentline += -9 + a2;
                        }
                        for (int i = 0; i < 9 - a2; i++)
                        {
                            scrollViewer.LineUp();
                        }
                    }
                    else
                    {
                        double a  = (new_windowsize - MainWindowHeight) / 20;
                        int    a2 = Convert.ToInt32(a);
                        if (currentline - 9 - a2 < 1)
                        {
                            currentline = 1;
                        }
                        else
                        {
                            currentline += -9 - a2;
                        }
                        for (int i = 0; i < 9 + a2; i++)
                        {
                            scrollViewer.LineUp();
                        }
                    }
                }



                else if (temp[0].ToLower() == "back")
                {
                    if (MainWindowHeight == new_windowsize)
                    {
                        if (currentline + 9 >= counter_size)
                        {
                            currentline = counter_size;
                        }
                        else
                        {
                            currentline += 9;
                        }
                        for (int i = 0; i < 9; i++)
                        {
                            scrollViewer.LineDown();
                        }
                    }

                    else if (MainWindowHeight > new_windowsize)
                    {
                        double a  = (MainWindowHeight - new_windowsize) / 20;
                        int    a2 = Convert.ToInt32(a);
                        if (currentline + 9 - a2 > counter_size)
                        {
                            currentline = counter_size;
                        }
                        else
                        {
                            currentline += 9 - a2;
                        }
                        for (int i = 0; i < 9 - a2; i++)
                        {
                            scrollViewer.LineDown();
                        }
                    }
                    else
                    {
                        double a  = (new_windowsize - MainWindowHeight) / 20;
                        int    a2 = Convert.ToInt32(a);
                        if (currentline + 9 + a2 > counter_size)
                        {
                            currentline = counter_size;
                        }
                        else
                        {
                            currentline += 9 + a2;
                        }
                        for (int i = 0; i < 9 + a2; i++)
                        {
                            scrollViewer.LineDown();
                        }
                    }
                }

                else if (temp[0].ToLower() == "setcl")
                {
                    int counter = 1;
                    if (Char.IsNumber(temp[1], 0) == true)
                    {
                        int number = Int32.Parse(temp[1]);
                        if (number <= counter_size)
                        {
                            currentline = number;
                            foreach (datagrid_elements element in datagrid.ItemsSource)
                            {
                                var row = (DataGridRow)datagrid.ItemContainerGenerator.ContainerFromItem(element) as DataGridRow;
                                row.Foreground = Brushes.Black;
                                if (counter == number)
                                {
                                    row.Foreground = Brushes.Red;
                                }
                                counter++;
                            }
                            label2.Content = "Current Line: " + currentline;
                        }
                        else
                        {
                            currentline = counter_size;
                            foreach (datagrid_elements element in datagrid.ItemsSource)
                            {
                                var row = (DataGridRow)datagrid.ItemContainerGenerator.ContainerFromItem(element) as DataGridRow;
                                row.Foreground = Brushes.Black;
                                if (counter == counter_size)
                                {
                                    row.Foreground = Brushes.Red;
                                }
                                counter++;
                            }
                            label2.Content = "Current Line: " + currentline;
                        }
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("Please Enter valid number");
                    }
                }


                else if (temp[0].ToLower() == "change" || temp[0].ToLower() == "replace")
                {
                    string s_str, r_str;
                    int    found = 0, totalFounds = 0, n_lines;
                    if (temp.Count() == 2 || temp.Count() == 3)
                    {
                        string[] parts = temp[1].Split('/');
                        s_str = parts[1];
                        r_str = parts[2];

                        if (parts[3] == "*")
                        {
                            n_lines = counter_size;
                        }
                        else
                        {
                            n_lines = Int32.Parse(parts[3]);
                        }

                        if (temp[2] != null && temp[2] == "*")
                        {
                            for (int i = 0; i < counter_size; i++)
                            {
                                if (data_list[i].data.Contains(s_str))
                                {
                                    found = 1;
                                    totalFounds++;
                                    string new_data = data_list[i].data.Replace(s_str, r_str);
                                    data_list[i].data = new_data;
                                }
                            }
                        }
                        else
                        {
                            for (int i = currentline - 1; i < n_lines; i++)
                            {
                                if (i < counter_size)
                                {
                                    if (data_list[i].data.Contains(s_str))
                                    {
                                        found = 1;
                                        totalFounds++;
                                        string new_data = data_list[i].data.Replace(s_str, r_str);
                                        data_list[i].data = new_data;
                                    }
                                }
                            }
                        }
                        if (found == 1)
                        {
                            System.Windows.MessageBox.Show(s_str + " is replaced with " + r_str + " " + totalFounds + " times.");
                            datagrid.ItemsSource  = data_list;
                            datagrid.SelectedItem = datagrid.Items[currentline];
                            datagrid.ScrollIntoView(datagrid.Items[currentline]);
                            datagrid.Items.Refresh();
                        }
                        else
                        {
                            System.Windows.MessageBox.Show(s_str + " is not found");
                        }
                    }
                }

                else if (temp[0].ToLower() == "help")
                {
                    Help window2 = new Help();
                    window2.Show();
                }
                else
                {
                    System.Windows.MessageBox.Show("Invalid entry!! Please try again and enter new one");
                }
            }
        }
Esempio n. 3
0
        private void Handle() // COMBOBOX HANDLER
        {
            int f = cmbx1.SelectedIndex;

            switch (f)
            {
            case 0:
                //Handle for the first combobox item
                label1.Content = "";
                label3.Content = "";
                label2.Content = "";
                counter_size   = 0;
                data_list.Clear();
                datagrid.ItemsSource = null;
                string reader = "";
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Filter = "All files (*.*)|*.*|Rich Text Format (*.rtf)|*.rtf";
                if (dlg.ShowDialog() == true)
                {
                    FileStream   fileStream = new FileStream(dlg.FileName, FileMode.Open);
                    StreamReader file       = new StreamReader(fileStream);
                    while ((reader = file.ReadLine()) != null)
                    {
                        counter_size++;
                        data_list.Add(new datagrid_elements {
                            line_number = counter_size, data = reader, suffix = "====="
                        });
                    }
                    CurrentFilePath        = dlg.FileName;
                    datagrid.ItemsSource   = data_list;
                    TextEditorWindow.Title = "Kedit ~ " + CurrentFilePath;
                    label1.Content         = "Path: " + CurrentFilePath;
                    label2.Content         = "Currentline: " + currentline;
                    label3.Content         = "Size: " + counter_size;
                    fileStream.Close();
                }

                break;

            case 1:
                //Handle for the second combobox
                if (CurrentFilePath == null)
                {
                    Microsoft.Win32.SaveFileDialog dlg3 = new Microsoft.Win32.SaveFileDialog();
                    datagrid_elements tempgrid2         = new datagrid_elements();
                    string            temp_s2           = "";
                    foreach (datagrid_elements element in datagrid.ItemsSource)
                    {
                        temp_s2 += element.data + "\n";
                    }
                    dlg3.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
                    if (dlg3.ShowDialog() == true)
                    {
                        File.WriteAllText(dlg3.FileName, temp_s2);
                    }
                }

                else
                {
                    string temp_s3 = "";
                    foreach (datagrid_elements element in datagrid.ItemsSource)
                    {
                        temp_s3 += element.data + "\n";
                    }
                    File.WriteAllText(CurrentFilePath, temp_s3);
                }

                break;

            case 2:
                //Handle for the third combobox

                Microsoft.Win32.SaveFileDialog dlg2 = new Microsoft.Win32.SaveFileDialog();
                datagrid_elements tempgrid          = new datagrid_elements();
                string            temp_s            = "";
                foreach (datagrid_elements element in datagrid.ItemsSource)
                {
                    temp_s += element.data + "\n";
                }
                dlg2.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
                if (dlg2.ShowDialog() == true)
                {
                    File.WriteAllText(dlg2.FileName, temp_s);
                }

                break;

            case 3:
                Help window2 = new Help();
                window2.Show();
                break;
            }
        }