| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
import logging |
| 11 |
|
| 12 |
from apptools.io.api import File |
| 13 |
from pyface.action.api import Action |
| 14 |
from pyface.api import FileDialog, OK |
| 15 |
from traits.api import Any |
| 16 |
|
| 17 |
from .editor.text_editor import TextEditor |
| 18 |
|
| 19 |
logger = logging.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
class NewFileAction(Action): |
| 23 |
"""Open a new file in the text editor.""" |
| 24 |
|
| 25 |
tooltip = "Create a new file for editing" |
| 26 |
description = "Create a new file for editing" |
| 27 |
|
| 28 |
# The WorkbenchWindow the action is attached to. |
| 29 |
window = Any() |
| 30 |
|
| 31 |
def perform(self, event=None): |
| 32 |
logger.info("NewFileAction.perform()") |
| 33 |
self.window.workbench.edit( |
| 34 |
File(""), kind=TextEditor, use_existing=False |
| 35 |
) |
| 36 |
|
| 37 |
|
| 38 |
class OpenFileAction(Action): |
| 39 |
"""Open an existing file in the text editor.""" |
| 40 |
|
| 41 |
tooltip = "Open a file for editing" |
| 42 |
description = "Open a file for editing" |
| 43 |
|
| 44 |
def perform(self, event=None): |
| 45 |
logger.info("OpenFileAction.perform()") |
| 46 |
dialog = FileDialog(parent=self.window.control, title="Open File") |
| 47 |
if dialog.open() == OK: |
| 48 |
self.window.workbench.edit(File(dialog.path), kind=TextEditor) |