1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2006 Ali Afshar aafshar@gmail.com
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
import pida.core.service as service
28
defs = service.definitions
31
import pida.pidagtk.contentview as contentview
35
class new_file_options(gtk.VBox):
38
super(new_file_options, self).__init__(spacing=6)
39
hb = gtk.HBox(spacing=6)
40
self.pack_start(hb, expand=False)
41
copycheck = gtk.CheckButton(label='License')
42
copycheck.connect('toggled', self.cb_copy_toggled)
43
hb.pack_start(copycheck, expand=False)
44
self.__copy_combo = gtk.combo_box_new_text()
45
hb.pack_start(self.__copy_combo)
46
copycheck.set_active(False)
47
self.__copy_combo.set_sensitive(False)
48
hb = gtk.HBox(spacing=6)
49
self.pack_start(hb, expand=False)
50
copycheck = gtk.CheckButton(label='Comment Style')
51
copycheck.connect('toggled', self.cb_comment_toggled)
52
hb.pack_start(copycheck, expand=False)
53
self.__comment_combo = gtk.combo_box_new_text()
54
hb.pack_start(self.__comment_combo)
55
copycheck.set_active(True)
58
def cb_copy_toggled(self, tgl):
59
self.__copy_combo.set_sensitive(tgl.get_active())
61
def cb_comment_toggled(self, tgl):
62
self.__comment_combo.set_sensitive(tgl.get_active())
64
class new_file(service.service):
66
class locations(defs.optiongroup):
67
"""Options relating to the location of new files."""
68
class start_in_current_project_directory(defs.option):
69
"""Whether files will be made in the current project directory."""
72
class use_project_directories_as_shortcuts(defs.option):
73
"""Whether the project directories will be added as shortcuts to the file chooser."""
78
self.__projlinks = os.path.join(self.boss.pida_home, 'data',
80
if not os.path.exists(self.__projlinks):
81
os.mkdir(self.__projlinks)
83
def cmd_create_interactive(self, directory=None,
86
directory = os.getcwd()
87
if self.opts.locations__start_in_current_project_directory:
88
proj = self.boss.call_command('projectmanager',
89
'get_current_project')
91
directory = proj.source_directory
94
path = os.path.join(directory, name)
96
prompt = 'Directory Name'
97
self.boss.call_command('window', 'input',
98
callback_function=_callback,
101
view = self.create_view()
102
view.set_current_folder(directory)
106
def cmd_create(self, filename):
107
f = open(filename, 'w')
110
def create_view(self):
111
chooser = gtk.FileChooserDialog("Create New File",
112
self.boss.get_main_window(),
113
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
114
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
115
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
116
chooser.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
118
chooser.set_do_overwrite_confirmation(True)
119
except AttributeError:
121
chooser.connect('response', self.cb_response)
122
if self.opts.locations__use_project_directories_as_shortcuts:
123
for directory in self.__create_project_links():
124
chooser.add_shortcut_folder(directory)
125
options = new_file_options()
126
#chooser.vbox.pack_start(options, expand=False)
129
def cb_response(self, dlg, response):
130
if response == gtk.RESPONSE_ACCEPT:
131
filename = dlg.get_filename()
132
self.call('create', filename=dlg.get_filename())
133
self.boss.call_command('buffermanager', 'open_file',
137
def __create_project_links(self):
138
projs = self.boss.call_command('projectmanager', 'get_projects')
140
src = proj.source_directory
141
dst = os.path.join(self.__projlinks, proj.name)
142
if os.path.exists(dst):