make it so when you add nothing (eg. ' "material" "concrete/", "material" "debug/debugambientcube" '), it adds it: import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog
import os

class HammerMapEditor:
    def __init__(self, root):
        self.root = root
        self.root.title("Hammer Map Notepad")
        self.root.geometry("800x600")

        # Default color scheme (Light mode)
        self.is_dark_mode = False
        self.bg_color = "#FFFFFF"
        self.fg_color = "#000000"
        self.highlight_color = "#A5A5A5"
        self.comment_color = "#228B22"

        # Create the Text widget for the editor area
        self.text_area = tk.Text(self.root, wrap=tk.WORD, undo=True, font=("Courier", 12))
        self.text_area.pack(expand=True, fill=tk.BOTH)

        # Apply initial color scheme
        self.apply_color_scheme()

        # Create a Menu bar
        self.menu_bar = tk.Menu(self.root)
        self.root.config(menu=self.menu_bar)

        # File menu
        self.file_menu = tk.Menu(self.menu_bar, tearoff=0)
        self.menu_bar.add_cascade(label="File", menu=self.file_menu)
        self.file_menu.add_command(label="Open", command=self.open_file)
        self.file_menu.add_command(label="Save", command=self.save_file)
        self.file_menu.add_command(label="Exit", command=self.exit_app)

        # Edit menu
        self.edit_menu = tk.Menu(self.menu_bar, tearoff=0)
        self.menu_bar.add_cascade(label="Edit", menu=self.edit_menu)
        self.edit_menu.add_command(label="Undo", command=self.text_area.edit_undo)
        self.edit_menu.add_command(label="Redo", command=self.text_area.edit_redo)

        # Addons menu
        self.addons_menu = tk.Menu(self.menu_bar, tearoff=0)
        self.menu_bar.add_cascade(label="Addons", menu=self.addons_menu)
        self.addons_menu.add_command(label="Edit All", command=self.edit_all_materials)

        # View menu (for dark/light mode toggle)
        self.view_menu = tk.Menu(self.menu_bar, tearoff=0)
        self.menu_bar.add_cascade(label="View", menu=self.view_menu)
        self.view_menu.add_command(label="Toggle Dark/Light Mode", command=self.toggle_mode)

        # Add tutorial button
        self.tutorial_button = tk.Button(self.root, text="Show Tutorial", command=self.open_tutorial_map)
        self.tutorial_button.pack(side=tk.BOTTOM, padx=10, pady=10)

        self.current_file = None

    def apply_color_scheme(self):
        self.text_area.config(bg=self.bg_color, fg=self.fg_color)
        self.root.config(bg=self.bg_color)
        self.highlight_syntax()

    def toggle_mode(self):
        if self.is_dark_mode:
            self.bg_color = "#FFFFFF"
            self.fg_color = "#000000"
            self.highlight_color = "#A5A5A5"
            self.comment_color = "#228B22"
        else:
            self.bg_color = "#2E2E2E"
            self.fg_color = "#DCDCDC"
            self.highlight_color = "#A5A5A5"
            self.comment_color = "#98FB98"

        self.is_dark_mode = not self.is_dark_mode
        self.apply_color_scheme()

    def open_file(self):
        file_path = filedialog.askopenfilename(
            filetypes=[("Valve Map Files", "*.vmf"), ("All Files", "*.*")]
        )
        if file_path:
            self.load_file(file_path)

    def open_tutorial_map(self):
        tutorial_file_path = r"C:\Users\dan27\Downloads\VMFEditor\tutorial.vmf"

        if os.path.exists(tutorial_file_path):
            self.load_file(tutorial_file_path)
            self.show_tutorial()
        else:
            messagebox.showerror("Error", "Tutorial map file not found!")

    def load_file(self, file_path):
        try:
            with open(file_path, 'r', encoding='utf-8') as file:
                content = file.read()
                self.text_area.delete(1.0, tk.END)
                self.text_area.insert(tk.END, content)
                self.current_file = file_path
                self.highlight_syntax()
        except Exception as e:
            messagebox.showerror("Error", f"Failed to open file: {e}")

    def save_file(self):
        if self.current_file:
            self._save_existing_file(self.current_file)
        else:
            self.save_as_file()

    def save_as_file(self):
        file_path = filedialog.asksaveasfilename(
            defaultextension=".vmf",
            filetypes=[("Valve Map Files", "*.vmf"), ("All Files", "*.*")]
        )
        if file_path:
            self._save_existing_file(file_path)

    def _save_existing_file(self, file_path):
        try:
            with open(file_path, 'w', encoding='utf-8') as file:
                content = self.text_area.get(1.0, tk.END)
                file.write(content.strip())
                self.current_file = file_path
                messagebox.showinfo("Saved", f"File saved successfully: {file_path}")
        except Exception as e:
            messagebox.showerror("Error", f"Failed to save file: {e}")

    def exit_app(self):
        if messagebox.askokcancel("Quit", "Do you want to quit without saving?"):
            self.root.quit()

    def show_tutorial(self):
        tutorial_text = (
            "Welcome to Hammer Map Notepad Tutorial!\n\n"
            "This is a simple tutorial on how to edit Hammer Map files (.vmf).\n\n"
            "### Structure of a VMF file ###\n"
            "1. **versioninfo**: Contains information about the Hammer editor version used to create the map.\n"
            "2. **classes**: Defines the world properties including environment aspects like sky texture.\n"
            "3. **solid**: Represents the geometry of the map. Each solid can have multiple sides.\n"
            "4. **entity**: Defines entities like spawn points, props, triggers, etc. The 'classname' property determines its type.\n\n"
            "### Editing Tips ###\n"
            "- Comments denote text that won’t affect the map and can be added using `//`. \n"
            "- Use the Hammer editor to visualize changes as you modify the VMF file.\n"
            "- Always maintain proper syntax and indentation for easier readability.\n"
            "- Save frequently to prevent loss of your progress.\n\n"
            "### Enjoy Editing! ###"
        )
        messagebox.showinfo("Tutorial", tutorial_text)

    def highlight_syntax(self):
        content = self.text_area.get(1.0, tk.END)
        self.apply_syntax_color(r"//.*", self.comment_color)
        self.apply_syntax_color(r"\b(worldspawn|entity|solid|brush|vertex|material|texture)\b", self.highlight_color)

    def apply_syntax_color(self, pattern, color):
        self.text_area.tag_remove("highlight", 1.0, tk.END)
        start = 1.0
        while True:
            start = self.text_area.search(pattern, start, stopindex=tk.END, regexp=True)
            if not start:
                break
            end = f"{start}+{len(self.text_area.get(start, start + '+1c'))}c"
            self.text_area.tag_add("highlight", start, end)
            self.text_area.tag_configure("highlight", foreground=color)
            start = end

    def edit_all_materials(self):
        # Get the replacement input from the user
        user_input = simpledialog.askstring("Edit All", "Enter the replacement pair (old material, new material) separated by a comma:\n(Syntax: \"material\" \"old_material\", \"material\" \"new_material\")")
        if user_input:
            try:
                # Split the input into old and new materials
                old_material, new_material = [item.strip().strip('"') for item in user_input.split(',')]
                
                content = self.text_area.get(1.0, tk.END)
                # Replace only the lines containing the old material
                updated_content = self.replace_partial_matches(content, old_material, new_material)

                # Clear the text area and insert the updated content
                self.text_area.delete(1.0, tk.END)
                self.text_area.insert(tk.END, updated_content)
                self.highlight_syntax()

            except Exception as e:
                messagebox.showerror("Error", f"Failed to edit materials: {e}")

    def replace_partial_matches(self, content, old_material, new_material):
        # Replace occurrences of the old material with new material in the content
        return content.replace(old_material, new_material)

# Create the main window
root = tk.Tk()
app = HammerMapEditor(root)

# Start the Tkinter event loop
root.mainloop()