diff --git a/src/nailab/ui/applicationwindow.py b/src/nailab/ui/applicationwindow.py index ae8b5b3..274b64d 100644 --- a/src/nailab/ui/applicationwindow.py +++ b/src/nailab/ui/applicationwindow.py @@ -19,6 +19,7 @@ class ApplicationWindow: handlers = { 'on_ApplicationWindow_delete_event' : Gtk.main_quit, 'on_OpenFile' : self.open_file, + 'on_menuSave' : self.save_file, 'on_StrategyExecute' : self.strategy_execute } @@ -36,6 +37,9 @@ class ApplicationWindow: dlg.destroy() + def save_file(self, arg): + self.tab_manager.save_current() + def strategy_execute(self, arg): sel = self.tv_datasources.get_selection() model, rows = sel.get_selected_rows() diff --git a/src/nailab/ui/sourceviewcontroller.py b/src/nailab/ui/sourceviewcontroller.py index 0364b71..2a660f7 100644 --- a/src/nailab/ui/sourceviewcontroller.py +++ b/src/nailab/ui/sourceviewcontroller.py @@ -6,3 +6,8 @@ class SourceViewController: def set_source_text(self, text): self.sourceview.get_buffer().set_text(text) + + def get_source_text(self): + buf = self.sourceview.get_buffer() + return buf.get_text(buf.get_start_iter(), buf.get_end_iter(), True) + diff --git a/src/nailab/ui/tabmanager.py b/src/nailab/ui/tabmanager.py index 88e013b..8f9fec7 100644 --- a/src/nailab/ui/tabmanager.py +++ b/src/nailab/ui/tabmanager.py @@ -9,6 +9,7 @@ class TabManager(GObject.Object): super().__init__() self.notebook = notebook self.widgets = {} + self.source_controllers = {} self.id_counter = 1 self.source_paths = {} @@ -39,6 +40,7 @@ class TabManager(GObject.Object): self.source_paths[tab_id] = source_file (sv, sv_controller) = self._init_sourceeditor() sv_controller.set_source_text(f.read()) + self.source_controllers[tab_id] = sv_controller self.widgets[tab_id] = sv sv.show_all() header = Gtk.HBox() @@ -64,6 +66,8 @@ class TabManager(GObject.Object): del self.widgets[tab_id] if tab_id in self.source_paths: del self.source_paths[tab_id] + if tab_id in self.source_controllers: + del self.source_controllers[tab_id] def get_current_source_path(self): index = self.notebook.get_current_page() @@ -74,6 +78,17 @@ class TabManager(GObject.Object): return None + def save_current(self): + index = self.notebook.get_current_page() + w = self.notebook.get_nth_page(index) + for k, v in self.widgets.items(): + if v == w: + text = self.source_controllers[k].get_source_text() + with open(self.source_paths[k], 'w') as f: + f.write(text) + + + def _init_sourceeditor(self): scroll = Gtk.ScrolledWindow() manager = GtkSource.LanguageManager() diff --git a/ui/nailab.glade b/ui/nailab.glade index 721ed27..c83d92e 100644 --- a/ui/nailab.glade +++ b/ui/nailab.glade @@ -105,7 +105,7 @@ - + gtk-open True False @@ -115,12 +115,13 @@ - + gtk-save True False True True +