1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/usr/bin/env python
# Rapache - Apache Configuration Tool
# Copyright (C) 2008 Stefano Forenza, Jason Taylor, Emanuele Gentili
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
import os
import RapacheGtk.GuiUtils
from RapacheCore.Module import *
from RapacheGtk import GuiUtils
import RapacheCore.Shell
class EditGenericWindow:
def __init__(self):
gladefile = os.path.join(Configuration.GLADEPATH, "edit_generic.glade")
wtree = gtk.glade.XML(gladefile)
self.window = wtree.get_widget("dialog_edit_generic")
self.scrolledwindow_generic = wtree.get_widget("scrolledwindow_generic")
self.label_path = wtree.get_widget("label_path")
self.combobox_backups = wtree.get_widget("combobox_backups")
signals = {
"on_button_save_clicked" : self.on_button_save_clicked,
"on_button_cancel_clicked" : self.on_button_cancel_clicked,
"on_button_restore_version_clicked" : self.on_button_restore_version_clicked
}
wtree.signal_autoconnect(signals)
# add on destroy to quit loop
self.window.connect("destroy", self.on_destroy)
self.text_view_source = GuiUtils.new_apache_sourceview()
self.scrolledwindow_generic.add( self.text_view_source )
self.text_view_source.show()
self.return_value = None
def on_button_restore_version_clicked(self, widget):
buf = self.text_view_source.get_buffer()
buf.set_text( Shell.command.read_file( self.file_path ) )
if self.text_view_source.get_buffer().get_modified():
md = gtk.MessageDialog(self.window, flags=0, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK_CANCEL, message_format="Are you sure, you will lose all your current changes")
result = md.run()
md.destroy()
if result != gtk.RESPONSE_OK:
return
selected = self.combobox_backups.get_active()
if selected == 0:
buf.set_text( Shell.command.read_file( self.file_path ) )
else:
value = self.combobox_backups.get_active_text()[7:]
buf.set_text( Shell.command.read_file_version( self.file_path, value ) )
buf.set_modified(False)
def on_button_cancel_clicked(self, widget):
self.window.destroy()
return
def on_button_save_clicked(self, widget):
buff = self.text_view_source.get_buffer()
text = buff.get_text(buff.get_start_iter(), buff.get_end_iter())
Shell.command.write_file(self.file_path, text)
self.window.destroy()
return
def run(self):
self.window.show()
gtk.main()
return self.return_value
def load (self, path):
self.file_path = path
self.window.set_title("Edit " + path)
self.label_path.set_text( path )
for file in Shell.command.get_backup_files( path ):
self.combobox_backups.append_text("Backup " + file[0][-21:-4])
self.combobox_backups.set_active(0)
buf = self.text_view_source.get_buffer()
buf.set_text( Shell.command.read_file( path ) )
buf.set_modified(False)
return
def on_destroy(self, widget, data=None):
gtk.main_quit()
|