def write_async(self): '''Write data asynchronously and set C{modified} to C{False} @returns: an L{FunctionThread} object ''' func = FunctionThread(self.file, self.file.writelines, self.dump()) func.start() self.set_modified(False) return func
def do_save_version_async(self, msg=None): if not self.notebook_ext.vcs: return if self._autosave_thread and not self._autosave_thread.done: self._autosave_thread.join() self._autosave_thread = FunctionThread(self.do_save_version, (msg,)) self._autosave_thread.start() monitor_thread(self._autosave_thread)
def _store_async(self): # Get lines before forking a new thread, otherwise the parsetree # could change in a non-atomic way in the GUI in the mean time lines = self._dump() self.modified = False #~ print '!! STORE PAGE ASYNC in files' func = FunctionThread(self._store_lines, (lines, )) func.start() return func
def write_async(self): '''Write data asynchronously and set C{modified} to C{False} @returns: an L{FunctionThread} object ''' func = FunctionThread( self.file, self.file.writelines, self.dump()) func.start() self.set_modified(False) return func
def do_save_version_async(self, msg=None): if not self.notebook_ext.vcs: return False # stop timer if self._autosave_thread and not self._autosave_thread.done: return True # continue time self._autosave_thread = FunctionThread(self.do_save_version, (msg,)) self._autosave_thread.start() monitor_thread(self._autosave_thread) return True # continue timer
def on_path_deleted(self, path): """Callback to remove a file from Bazaar when deleted from the wiki Note: the VCS operation is asynchronous @param path: the L{UnixFile} object representing the path of the file or folder to delete @returns: nothing """ FunctionThread(self.vcs.remove, (path,), lock=self._lock).start()
def on_path_moved(self, fs, oldpath, newpath): """Callback to move the file in Bazaar when moved in the wiki Note: the VCS operation is asynchronous @param fs: the L{FSSingletonClass} instance representing the file system @param oldpath: the L{UnixFile} object representing the old path of the file or folder @param newpath: the L{UnixFile} object representing the new path of the file or folder @returns: nothing """ if newpath.ischild(self.root) and not self._ignored(newpath): if oldpath.ischild(self.root): # Parent of newpath needs to be versioned in order to make mv succeed FunctionThread(self.vcs.move, (oldpath, newpath), lock=self._lock).start() else: FunctionThread(self.vcs.add, (newpath,), lock=self._lock).start() elif oldpath.ischild(self.root) and not self._ignored(oldpath): self.on_path_deleted(self, fs, oldpath)
def on_path_created(self, fs, path): """Callback to add a new file or folder when added to the wiki Note: the VCS operation is asynchronous @param fs: the L{FSSingletonClass} instance representing the file system @param path: the L{UnixFile} object representing the newly created file or folder @returns: nothing """ if path.ischild(self.root) and not self._ignored(path): FunctionThread(self.vcs.add, (path,), lock=self._lock).start()
def on_path_deleted(self, fs, path): """Callback to remove a file from Bazaar when deleted from the wiki Note: the VCS operation is asynchronous @param fs: the L{FSSingletonClass} instance representing the file system @param path: the L{UnixFile} object representing the path of the file or folder to delete @returns: nothing """ if path.ischild(self.root) and not self._ignored(path): FunctionThread(self.vcs.remove, (path,), lock=self._lock).start()
class MainWindowExtension(WindowExtension): uimanager_xml = ''' <ui> <menubar name='menubar'> <menu action='file_menu'> <placeholder name='versioning_actions'> <menuitem action='save_version'/> <menuitem action='show_versions'/> </placeholder> </menu> </menubar> </ui> ''' def __init__(self, plugin, window, notebook_ext): WindowExtension.__init__(self, plugin, window) self.notebook_ext = notebook_ext self._autosave_thread = None if self.notebook_ext.vcs is None: gaction = self.actiongroup.get_action('show_versions') gaction.set_sensitive(False) else: if self.plugin.preferences['autosave']: self.do_save_version_async() def on_quit(o): if self._autosave_thread and not self._autosave_thread.done: self._autosave_thread.join() if self.plugin.preferences['autosave']: self.do_save_version() self.window.ui.connect('quit', on_quit) # XXX def do_save_version_async(self, msg=None): if not self.notebook_ext.vcs: return if self._autosave_thread and not self._autosave_thread.done: self._autosave_thread.join() self._autosave_thread = FunctionThread(self.do_save_version, (msg,)) self._autosave_thread.start() monitor_thread(self._autosave_thread) def do_save_version(self, msg=None): if not self.notebook_ext.vcs: return if not msg: msg = _('Automatically saved version from zim') # T: default version comment for auto-saved versions self.window.ui.assert_save_page_if_modified() # XXX try: self.notebook_ext.vcs.commit(msg) except NoChangesError: logger.debug('No autosave version needed - no changes') @action(_('S_ave Version...'), 'gtk-save-as', '<ctrl><shift>S', readonly=False) # T: menu item def save_version(self): self.window.ui.assert_save_page_if_modified() # XXX if not self.notebook_ext.vcs: vcs = VersionControlInitDialog().run() if vcs is None: return # Canceled self.notebook_ext.init_vcs(vcs) if self.notebook_ext.vcs: gaction = self.actiongroup.get_action('show_versions') gaction.set_sensitive(True) with self.notebook_ext.notebook.lock: SaveVersionDialog(self.window, self, self.notebook_ext.vcs).run() @action(_('_Versions...')) # T: menu item def show_versions(self): self.window.ui.assert_save_page_if_modified() # XXX dialog = VersionsDialog.unique(self, self.window, self.notebook_ext.vcs, self.notebook_ext.notebook, self.window.ui.page # XXX ) dialog.present()
class MainWindowExtension(WindowExtension): uimanager_xml = ''' <ui> <menubar name='menubar'> <menu action='file_menu'> <placeholder name='versioning_actions'> <menuitem action='save_version'/> <menuitem action='show_versions'/> </placeholder> </menu> </menubar> </ui> ''' def __init__(self, plugin, window, notebook_ext): WindowExtension.__init__(self, plugin, window) self.notebook_ext = notebook_ext self._autosave_thread = None self._autosave_timer = None if self.notebook_ext.vcs is None: gaction = self.actiongroup.get_action('show_versions') gaction.set_sensitive(False) else: self.on_preferences_changed(None, start=True) def on_quit(o): self._stop_timer() if self.plugin.preferences['autosave'] \ or self.plugin.preferences['autosave_at_interval']: self.do_save_version() self.window.ui.connect('quit', on_quit) # XXX self.connectto(self.plugin.preferences, 'changed', self.on_preferences_changed) def on_preferences_changed(self, o, start=False): self._stop_timer() if (start and self.plugin.preferences['autosave']) \ or self.plugin.preferences['autosave_at_interval']: self.do_save_version_async() if self.plugin.preferences['autosave_at_interval']: self._start_timer() def _start_timer(self): timeout = 60000 * self.plugin.preferences['autosave_interval'] self._autosave_timer = gobject.timeout_add( timeout, self.do_save_version_async) def _stop_timer(self): if self._autosave_timer: gobject.source_remove(self._autosave_timer) self._autosave_timer = None def teardown(self): self._stop_timer() def do_save_version_async(self, msg=None): if not self.notebook_ext.vcs: return False # stop timer if self._autosave_thread and not self._autosave_thread.done: return True # continue time self._autosave_thread = FunctionThread(self.do_save_version, (msg,)) self._autosave_thread.start() monitor_thread(self._autosave_thread) return True # continue timer def do_save_version(self, msg=None): if not self.notebook_ext.vcs: return if self._autosave_thread \ and not self._autosave_thread.done \ and not self._autosave_thread == threading.current_thread(): self._autosave_thread.join() if not msg: msg = _('Automatically saved version from zim') # T: default version comment for auto-saved versions with NotebookState(self.notebook_ext.notebook): try: self.notebook_ext.vcs.commit(msg) except NoChangesError: logger.debug('No autosave version needed - no changes') @action(_('S_ave Version...'), 'gtk-save-as', '<Primary><shift>S', readonly=False) # T: menu item def save_version(self): if not self.notebook_ext.vcs: vcs = VersionControlInitDialog(self.window).run() if vcs is None: return # Canceled self.notebook_ext.init_vcs(vcs) if self.notebook_ext.vcs: gaction = self.actiongroup.get_action('show_versions') gaction.set_sensitive(True) self.on_preferences_changed(None, start=False) with NotebookState(self.notebook_ext.notebook): SaveVersionDialog(self.window, self, self.notebook_ext.vcs).run() @action(_('_Versions...')) # T: menu item def show_versions(self): dialog = VersionsDialog.unique(self, self.window, self.notebook_ext.vcs, self.notebook_ext.notebook, self.window.ui.page # XXX ) dialog.present()