Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Ask for a new file name & create | open it
Browse files Browse the repository at this point in the history
  • Loading branch information
zrzka committed Nov 3, 2017
1 parent 8734e48 commit 25406c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
* Console is not cluttered with local / latest release info (installer prints this)
* Update `check()` doesn't ask if update should (not) be installer (installer also asks)
* If there's new update available, installer is executed, you will still be asked (just once, not twice)
* Script `new_file.py` modified
* File opened
* Asks for a file name (empty & `Enter` -> Cancel)
* New file path is currently opened file dirname + entered file name
* If file doesn't exist, new file is created and opened
* If file exists, file is opened
* No file opened
* Same behavior as now
* New tab created and _New File..._ button tap emulated

## 1.4.0 (2017-11-01)

Expand Down
32 changes: 30 additions & 2 deletions blackmamba/script/new_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,42 @@
"""
Script name ``new_file.py``.
Shows Pythonista new file dialog.
If there's no opened file in the Pythonista, new tab is created and _New File..._
button tap is emulated.
Otherwise dialog appears where you can enter new file name. File will be created
in the current folder. If it already exists, file will be opened instead of creating
new one.
"""

import blackmamba.ide.tab as tab
import editor
import os
import console


def main():
tab.new_file()
path = editor.get_path()

if not path:
tab.new_file()
return

folder = os.path.dirname(path)
try:
file_name = console.input_alert('Enter filename').strip()

if not file_name:
raise KeyboardInterrupt

path = os.path.join(folder, file_name)
if os.path.exists(path):
editor.open_file(path, new_tab=True)
else:
editor.make_new_file(path, new_tab=True)

except KeyboardInterrupt:
pass


if __name__ == '__main__':
Expand Down

0 comments on commit 25406c4

Please sign in to comment.