<commit_before>import os
import wx

from dirdialog import DirDialog
from save_changes_dialog import SaveChangesDialog
from text_input_dialog import TextInputDialog

class Dialogs(object):
    def __init__(self, prefix=""):
        self._prefix = prefix
        self._paths = {}

    def save_state(self):
        return {"paths" : self._paths}

    def load_state(self, state):
        self._paths = state.get("paths", {}).copy()

    def _make_caption(self, caption):
        return (self._prefix + " - " + caption) if caption else self._prefix

    def message_dialog(self, parent, message, caption, style):
        dlg = wx.MessageDialog(parent, message, self._make_caption(caption), style)
        try:
            return dlg.ShowModal()
        finally:
            dlg.Destroy()

    def error(self, parent, message, caption="Error"):
        self.message_dialog(parent, message, caption, wx.OK | wx.ICON_ERROR)

    def info(self, parent, message, caption=""):
        self.message_dialog(parent, message, caption, wx.OK | wx.ICON_INFORMATION)

    def _get_file_dialog(self, parent, message, path, wildcard, context, style):
        if context and not path:
            path = self._paths.get(context, "")
        dlg = wx.FileDialog(parent,
            wildcard=wildcard, message=self._make_caption(message),
            defaultDir=path, style=style)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                selected_path = dlg.GetPath()
                if context:
                    self._paths[context] = os.path.dirname(selected_path)
                return selected_path
        finally:
            dlg.Destroy()

    def get_file_to_open(self, parent, message="Open File", path="", wildcard="All Files|*", context=""):
        return self._get_file_dialog(parent, message, path, wildcard, context, 0)

    def get_file_to_save(self, parent, message="Save File", path="", wildcard="All Files|*", context=""):
        return self._get_file_dialog(
            parent, message, path, wildcard, context, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

    def get_directory(self, parent, message="Select Folder", path=""):
        dlg = DirDialog(parent, message=message, select_path=path)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                return dlg.GetPath()
        finally:
            dlg.Destroy()

    def ask_save_changes(self, parent, path=""):
        path = os.path.basename(path)
        if path:
            message = "File '%s' has been modified. Save changes?" % path
        else:
            message = "Save unsaved changes?"
        dlg = SaveChangesDialog(parent, message, self._make_caption("Unsaved Changes"))
        try:
            return dlg.ShowModal()
        finally:
            dlg.Destroy()

    def ask_overwrite(self, parent, path):
        return message_dialog(parent, 
            "A file named '%s' already exists. Overwrite?" % path,
            "Confirm Overwrite",
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) == wx.ID_YES

    def ask_delete(self, parent, path):
        return message_dialog(parent,
            "Are you sure you want to delete '%s'?" % path,
            "Confirm Delete",
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) == wx.ID_YES<commit_msg>Fixed<commit_after>import os
import wx

from dirdialog import DirDialog
from save_changes_dialog import SaveChangesDialog
from text_input_dialog import TextInputDialog

class Dialogs(object):
    def __init__(self, prefix=""):
        self._prefix = prefix
        self._paths = {}

    def save_state(self):
        return {"paths" : self._paths}

    def load_state(self, state):
        self._paths = state.get("paths", {}).copy()

    def _make_caption(self, caption):
        return (self._prefix + " - " + caption) if caption else self._prefix

    def message_dialog(self, parent, message, caption, style):
        dlg = wx.MessageDialog(parent, message, self._make_caption(caption), style)
        try:
            return dlg.ShowModal()
        finally:
            dlg.Destroy()

    def error(self, parent, message, caption="Error"):
        self.message_dialog(parent, message, caption, wx.OK | wx.ICON_ERROR)

    def info(self, parent, message, caption=""):
        self.message_dialog(parent, message, caption, wx.OK | wx.ICON_INFORMATION)

    def _get_file_dialog(self, parent, message, path, wildcard, context, style):
        if context and not path:
            path = self._paths.get(context, "")
        dlg = wx.FileDialog(parent,
            wildcard=wildcard, message=self._make_caption(message),
            defaultDir=path, style=style)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                selected_path = dlg.GetPath()
                if context:
                    self._paths[context] = os.path.dirname(selected_path)
                return selected_path
        finally:
            dlg.Destroy()

    def get_file_to_open(self, parent, message="Open File", path="", wildcard="All Files|*", context=""):
        return self._get_file_dialog(parent, message, path, wildcard, context, 0)

    def get_file_to_save(self, parent, message="Save File", path="", wildcard="All Files|*", context=""):
        return self._get_file_dialog(
            parent, message, path, wildcard, context, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

    def get_directory(self, parent, message="Select Folder", path=""):
        dlg = DirDialog(parent, message=message, select_path=path)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                return dlg.GetPath()
        finally:
            dlg.Destroy()

    def ask_save_changes(self, parent, path=""):
        path = os.path.basename(path)
        if path:
            message = "File '%s' has been modified. Save changes?" % path
        else:
            message = "Save unsaved changes?"
        dlg = SaveChangesDialog(parent, message, self._make_caption("Unsaved Changes"))
        try:
            return dlg.ShowModal()
        finally:
            dlg.Destroy()

    def ask_overwrite(self, parent, path):
        return self.message_dialog(parent, 
            "A file named '%s' already exists. Overwrite?" % path,
            "Confirm Overwrite",
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) == wx.ID_YES

    def ask_delete(self, parent, path):
        return self.message_dialog(parent,
            "Are you sure you want to delete '%s'?" % path,
            "Confirm Delete",
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) == wx.ID_YES
{'fraction_non_alphanumeric': 0.11498470948012232, 'fraction_numerical': 0.0003058103975535168, 'mean_word_length': 2.4737121614445035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1290463', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1884, 'n_words': 481}