def reload_index(self, update_only=False): '''Check the notebook for changes and update the index. Shows an progressbar while updateing. @param update_only: if C{True} only updates are done, if C{False} also check is done for all files @returns: C{True} unless the user cancelled the update ''' from zim.notebook.index import IndexCheckAndUpdateOperation, IndexUpdateOperation from zim.notebook.operations import ongoing_operation op = ongoing_operation(self.notebook) if isinstance(op, IndexUpdateOperation): dialog = ProgressDialog(self.widget, op) dialog.run() if update_only or isinstance(op, IndexCheckAndUpdateOperation): return not dialog.cancelled else: # ongoing op was update only but we want check, so try again if not dialog.cancelled: return self.reload_index() # recurs else: return False else: op = IndexCheckAndUpdateOperation(self.notebook) dialog = ProgressDialog(self.widget, op) dialog.run() return not dialog.cancelled
def testReloadIndexWhileOngoing(self): from zim.notebook.operations import ongoing_operation from zim.notebook.index import IndexCheckAndUpdateOperation op = IndexCheckAndUpdateOperation(self.notebook) op_iter = iter(op) next(op_iter) self.assertEqual(ongoing_operation(self.notebook), op) self.uiactions.reload_index() self.assertIsNone(ongoing_operation(self.notebook))