예제 #1
0
    def init_vcs(self, vcs):
        dir = self._get_notebook_dir()
        self.vcs = VCS.create(vcs, dir, dir)

        if self.vcs and not self.vcs.repo_exists():
            with NotebookState(self.notebook):
                self.vcs.init_repo()
예제 #2
0
	def init_vcs(self, vcs):
		dir = self._get_notebook_dir()
		self.vcs = VCS.create(vcs, dir, dir)

		if self.vcs:
			with NotebookState(self.notebook):
				self.vcs.init()
예제 #3
0
    def do_save_version(self, msg=None):
        if not self.notebook_ext.vcs:
            return

        if self._autosave_thread and self._autosave_thread.is_alive():
            self._autosave_thread.join()

        with NotebookState(self.notebook_ext.notebook):
            self._save_version(msg)
예제 #4
0
    def runTest(self):
        notebook = self.setUpNotebook(content={'test': 'test123\n'})
        pageview = setUpPageView(notebook)

        # Install wrapper with events
        orig = notebook._store_page_async_thread_main
        start_thread_event = threading.Event()
        thread_done_event = threading.Event()

        def wrapper(*a):
            start_thread_event.wait()
            orig(*a)
            thread_done_event.set()

        notebook._store_page_async_thread_main = wrapper

        # Test1 - normal scenario
        page = notebook.get_page(Path('Test'))
        pageview.set_page(page)
        pageview.readonly = False

        pageview.textview.get_buffer().set_text('foo')
        self.assertTrue(page.modified)
        pageview._save_page_handler.try_save_page()
        self.assertTrue(page.modified)
        start_thread_event.set()
        thread_done_event.wait()
        with NotebookState(notebook):
            self.assertFalse(page.modified)

        # Test2 - with race condition
        start_thread_event.clear()
        thread_done_event.clear()
        pageview.textview.get_buffer().set_text('bar')
        self.assertTrue(page.modified)
        pageview._save_page_handler.try_save_page()
        self.assertTrue(page.modified)
        pageview.textview.get_buffer().set_text(
            'dusss')  # edit while save ongoing
        start_thread_event.set()
        thread_done_event.wait()
        with NotebookState(notebook):
            self.assertTrue(
                page.modified)  # page must still show modified is True
예제 #5
0
    def do_save_version_async(self, msg=None):
        if not self.notebook_ext.vcs:
            return False  # stop timer

        if self._autosave_thread and self._autosave_thread.is_alive():
            return True  # continue time

        with NotebookState(self.notebook_ext.notebook):
            op, thread = self._commit_op(msg)
            self._autosave_thread = thread
            op.run_on_idle()

        return True  # continue timer
예제 #6
0
	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()
예제 #7
0
	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')