Fixing save/save as dialog
This commit is contained in:
parent
fa1e17f4e5
commit
7f3ea8c146
|
@ -70,7 +70,6 @@ class ControllerData:
|
||||||
self.src_buffer = GtkSource.Buffer(max_undo_levels = 0)
|
self.src_buffer = GtkSource.Buffer(max_undo_levels = 0)
|
||||||
self.src_preview = self.builder.get_object('src_preview')
|
self.src_preview = self.builder.get_object('src_preview')
|
||||||
|
|
||||||
|
|
||||||
self.scheme_manager = GtkSource.StyleSchemeManager()
|
self.scheme_manager = GtkSource.StyleSchemeManager()
|
||||||
self.language_manager = GtkSource.LanguageManager()
|
self.language_manager = GtkSource.LanguageManager()
|
||||||
self.all_styles_dict = collections.OrderedDict()
|
self.all_styles_dict = collections.OrderedDict()
|
||||||
|
|
|
@ -41,34 +41,35 @@ class DialogSignalsMixin():
|
||||||
self.load_scheme(path)
|
self.load_scheme(path)
|
||||||
|
|
||||||
def on_save_clicked(self, param):
|
def on_save_clicked(self, param):
|
||||||
if not self.origSchemeFile:
|
if not self.orig_scheme_file:
|
||||||
filename = run_save_as_dialog(self.window, self.entryId.get_text() + '.xml')
|
filename = self.run_save_as_dialog(self.window, self.id_entry.get_text() + '.xml')
|
||||||
|
|
||||||
if filename and not '.' in os.path.basename(filename):
|
if filename and not '.' in os.path.basename(filename):
|
||||||
filename = f"{filename}.xml"
|
filename = f"{filename}.xml"
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
self.write_scheme(filename, self.entryId.get_text())
|
self.write_scheme(filename, self.id_entry.get_text())
|
||||||
self.origSchemeFile = filename
|
self.orig_scheme_file = filename
|
||||||
else:
|
else:
|
||||||
self.write_scheme(self.origSchemeFile, self.entryId.get_text())
|
self.write_scheme(self.orig_scheme_file, self.id_entry.get_text())
|
||||||
|
|
||||||
def on_save_as_clicked(self, param):
|
def on_save_as_clicked(self, param):
|
||||||
filename = run_save_as_dialog(self.window, self.entryId.get_text() + '.xml')
|
filename = self.run_save_as_dialog(self.window, self.id_entry.get_text() + '.xml')
|
||||||
if filename and not '.' in os.path.basename(filename):
|
if filename and not '.' in os.path.basename(filename):
|
||||||
filename = f"{filename}.xml"
|
filename = f"{filename}.xml"
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
self.write_scheme(filename, self.entryId.get_text())
|
self.write_scheme(filename, self.id_entry.get_text())
|
||||||
self.origSchemeFile = filename
|
self.orig_scheme_file = filename
|
||||||
|
|
||||||
|
|
||||||
def message_dialog(
|
def message_dialog(
|
||||||
|
self,
|
||||||
dialog_type,
|
dialog_type,
|
||||||
short_msg,
|
short_msg,
|
||||||
long_msg = None,
|
long_msg = None,
|
||||||
parent = None,
|
parent = None,
|
||||||
buttons = Gtk.ButtonsType.OK,
|
buttons = Gtk.ButtonsType.OK,
|
||||||
additional_buttons = None
|
additional_buttons = None
|
||||||
):
|
):
|
||||||
dialog = Gtk.MessageDialog(parent = parent, flags = Gtk.DialogFlags.MODAL, type = dialog_type, buttons = buttons)
|
dialog = Gtk.MessageDialog(parent = parent, flags = Gtk.DialogFlags.MODAL, type = dialog_type, buttons = buttons)
|
||||||
|
@ -97,7 +98,7 @@ class DialogSignalsMixin():
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def run_save_as_dialog(parent, current_name):
|
def run_save_as_dialog(self, parent, current_name):
|
||||||
file_chooser = Gtk.FileChooserDialog('Save As', parent, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
file_chooser = Gtk.FileChooserDialog('Save As', parent, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
||||||
|
|
||||||
file_filter = Gtk.FileFilter()
|
file_filter = Gtk.FileFilter()
|
||||||
|
|
|
@ -52,14 +52,14 @@ class SourceviewSignalsMixin:
|
||||||
this_scheme = self.scheme_manager.get_scheme(scheme_id_or_file)
|
this_scheme = self.scheme_manager.get_scheme(scheme_id_or_file)
|
||||||
if not this_scheme: return False
|
if not this_scheme: return False
|
||||||
|
|
||||||
self.currentScheme = this_scheme
|
self.current_scheme = this_scheme
|
||||||
|
|
||||||
self.name_entry.set_text( this_scheme.get_name() )
|
self.name_entry.set_text( this_scheme.get_name() )
|
||||||
self.authr_entry.set_text( ', '.join( this_scheme.get_authors() ) )
|
self.authr_entry.set_text( ', '.join( this_scheme.get_authors() ) )
|
||||||
self.desc_entry.set_text( this_scheme.get_description() )
|
self.desc_entry.set_text( this_scheme.get_description() )
|
||||||
self.id_entry.set_text( this_scheme.get_id() )
|
self.id_entry.set_text( this_scheme.get_id() )
|
||||||
|
|
||||||
scheme_file = self.currentScheme.get_filename()
|
scheme_file = self.current_scheme.get_filename()
|
||||||
with open(scheme_file, 'r') as f:
|
with open(scheme_file, 'r') as f:
|
||||||
xml_tree = ET.parse(f)
|
xml_tree = ET.parse(f)
|
||||||
|
|
||||||
|
@ -67,12 +67,12 @@ class SourceviewSignalsMixin:
|
||||||
self.all_styles_dict.clear()
|
self.all_styles_dict.clear()
|
||||||
|
|
||||||
for style_elem in style_elems:
|
for style_elem in style_elems:
|
||||||
this_style = self.currentScheme.get_style(style_elem.attrib['name'])
|
this_style = self.current_scheme.get_style(style_elem.attrib['name'])
|
||||||
styleProps = StyleProperties()
|
styleProps = StyleProperties()
|
||||||
styleProps.from_gtk_source_style(this_style)
|
styleProps.from_gtk_source_style(this_style)
|
||||||
self.all_styles_dict[style_elem.attrib['name']] = styleProps;
|
self.all_styles_dict[style_elem.attrib['name']] = styleProps;
|
||||||
|
|
||||||
self.src_buffer.set_style_scheme(self.currentScheme);
|
self.src_buffer.set_style_scheme(self.current_scheme);
|
||||||
|
|
||||||
# set up temp file so the sample view can be updated
|
# set up temp file so the sample view can be updated
|
||||||
self.temp_scheme_id = f"{this_scheme.get_id()}_temp"
|
self.temp_scheme_id = f"{this_scheme.get_id()}_temp"
|
||||||
|
|
|
@ -96,7 +96,7 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue