summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-06 22:59:13 +0100
committerhut <hut@lavabit.com>2010-01-06 22:59:13 +0100
commita808a661b1368e74cbb67fb1de021e746a1d53d1 (patch)
treea150b99431c1896c782c76df3e3a2c54bb90c43c
parentab65b3533f439988fe80ff7a742c88a62e3e15e2 (diff)
downloadranger-a808a661b1368e74cbb67fb1de021e746a1d53d1.tar.gz
loader: fixed some issues with updating/redrawing
-rw-r--r--TODO2
-rw-r--r--ranger/actions.py14
-rw-r--r--ranger/fsobject/directory.py118
-rw-r--r--ranger/gui/widgets/browsercolumn.py12
4 files changed, 82 insertions, 64 deletions
diff --git a/TODO b/TODO
index db86fb74..7b124a93 100644
--- a/TODO
+++ b/TODO
@@ -31,7 +31,7 @@ Bugs
    (X) #17  10/01/01  why do bookmarks disappear sometimes?
    (X) #18  10/01/01  fix notify widget (by adding a LogView?)
    (X) #19  10/01/01  resizing after pressing g
-   ( ) #23  10/01/04  stop dir loading with ^C -> wont load anymore
+   (X) #23  10/01/04  stop dir loading with ^C -> wont load anymore
    ( ) #25  10/01/06  directories sometimes dont reload correctly
    ( ) #26  10/01/06  :delete on symlinks of directories fails
    ( ) #31  10/01/06  ^C breaks cd-after-exit
diff --git a/ranger/actions.py b/ranger/actions.py
index 8fc796a3..ed0fc2c1 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -305,14 +305,16 @@ class Actions(EnvironmentAware, SettingsAware):
 	
 	def force_load_preview(self):
 		cf = self.env.cf
-		if cf is not None:
-			cf.force_load = True
+		if hasattr(cf, 'unload') and hasattr(cf, 'load_content'):
+			cf.unload()
+			cf.load_content()
 
 	def reload_cwd(self):
 		try:
 			cwd = self.env.pwd
 		except:
 			pass
+		cwd.unload()
 		cwd.load_content()
 
 	def set_filter(self, fltr):
@@ -391,7 +393,7 @@ class Actions(EnvironmentAware, SettingsAware):
 		if not copied_files:
 			return
 
-		pwd = self.env.pwd
+		original_path = self.env.pwd.path
 		try:
 			one_file = copied_files[0]
 		except:
@@ -406,8 +408,9 @@ class Actions(EnvironmentAware, SettingsAware):
 				descr = "moving files from: " + one_file.dirname
 			def generate():
 				for f in copied_files:
-					for _ in shutil_g.move(f.path, pwd.path):
+					for _ in shutil_g.move(f.path, original_path):
 						yield
+				pwd = self.env.get_directory(original_path)
 				pwd.load_content()
 		else:
 			if len(copied_files) == 1:
@@ -421,8 +424,9 @@ class Actions(EnvironmentAware, SettingsAware):
 								join(self.env.pwd.path, f.basename)):
 							yield
 					else:
-						for _ in shutil_g.copy2(f.path, self.env.pwd.path):
+						for _ in shutil_g.copy2(f.path, original_path):
 							yield
+				pwd = self.env.get_directory(original_path)
 				pwd.load_content()
 
 		self.loader.add(LoadableObject(generate(), descr))
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 9b42e3c6..f1810915 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -1,7 +1,9 @@
+from collections import deque
+from time import time
+
 from ranger.fsobject import BAD_INFO, File, FileSystemObject
 from ranger.shared import SettingsAware
 from ranger.ext.accumulator import Accumulator
-from collections import deque
 import ranger.fsobject
 
 def sort_by_basename(path):
@@ -28,6 +30,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 	scroll_begin = 0
 	scroll_offset = 0
 
+	last_update_time = -1
+
 	old_show_hidden = None
 	old_directories_first = None
 	old_reverse = None
@@ -119,62 +123,66 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 		self.loading = True
 		self.load_if_outdated()
 
-		if self.exists and self.runnable:
-			yield
-			filenames = []
-			for fname in listdir(self.path):
-				if not self.settings.show_hidden and fname[0] == '.':
-					continue
-				if isinstance(self.filter, str) and self.filter \
-						and self.filter not in fname:
-					continue
-				filenames.append(join(self.path, fname))
-			yield
-
-			marked_paths = set(map( \
-					lambda obj: obj.path, self.marked_items))
-
-			files = []
-			for name in filenames:
-				if isdir(name):
-					try:
-						item = self.fm.env.get_directory(name)
-					except:
-						item = Directory(name)
-				else:
-					item = File(name)
-				item.load_if_outdated()
-				files.append(item)
+		try:
+			if self.exists and self.runnable:
+				yield
+				filenames = []
+				for fname in listdir(self.path):
+					if not self.settings.show_hidden and fname[0] == '.':
+						continue
+					if isinstance(self.filter, str) and self.filter \
+							and self.filter not in fname:
+						continue
+					filenames.append(join(self.path, fname))
 				yield
 
-			self.scroll_offset = 0
-			self.filenames = filenames
-			self.infostring = ' %d' % len(self.filenames) # update the infostring
-			self.files = files
-
-			self._clear_marked_items()
-			for item in self.files:
-				if item.path in marked_paths:
-					self.mark_item(item, True)
-				else:
-					self.mark_item(item, False)
-
-			self.old_directories_first = None
-			self.sort()
-
-			if len(self.files) > 0:
-				if self.pointed_obj is not None:
-					self.sync_index()
-				else:
-					self.move(absolute=0)
-		else:
-			self.filenames = None
-			self.files = None
-			self.infostring = BAD_INFO
-
-		self.cycle_list = None
-		self.content_loaded = True
-		self.loading = False
+				marked_paths = set(map( \
+						lambda obj: obj.path, self.marked_items))
+
+				files = []
+				for name in filenames:
+					if isdir(name):
+						try:
+							item = self.fm.env.get_directory(name)
+						except:
+							item = Directory(name)
+					else:
+						item = File(name)
+					item.load_if_outdated()
+					files.append(item)
+					yield
+
+				self.scroll_offset = 0
+				self.filenames = filenames
+				self.infostring = ' %d' % len(self.filenames) # update the infostring
+				self.files = files
+
+				self._clear_marked_items()
+				for item in self.files:
+					if item.path in marked_paths:
+						self.mark_item(item, True)
+					else:
+						self.mark_item(item, False)
+
+				self.old_directories_first = None
+				self.sort()
+
+				if len(self.files) > 0:
+					if self.pointed_obj is not None:
+						self.sync_index()
+					else:
+						self.move(absolute=0)
+			else:
+				self.filenames = None
+				self.files = None
+				self.infostring = BAD_INFO
+
+			self.cycle_list = None
+			self.content_loaded = True
+			self.last_update_time = time()
+
+		finally:
+			self.loading = False
 
 	def unload(self):
 		self.loading = False
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index f392aecc..b359d7de 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -1,4 +1,6 @@
 """The BrowserColumn widget displays the contents of a directory or file."""
+from time import time
+
 from . import Widget
 from .pager import Pager
 
@@ -9,6 +11,7 @@ class BrowserColumn(Pager, Widget):
 	target = None
 	postpone_drawing = False
 	tagged_marker = '*'
+	last_redraw_time = -1
 
 	old_dir = None
 	old_cf = None
@@ -72,6 +75,7 @@ class BrowserColumn(Pager, Widget):
 
 	def draw(self):
 		"""Call either _draw_file() or _draw_directory()"""
+		from ranger import log
 		from ranger.fsobject.file import File
 		from ranger.fsobject.directory import Directory
 
@@ -87,9 +91,10 @@ class BrowserColumn(Pager, Widget):
 		if type(self.target) == Directory:
 			if self.target.load_content_if_outdated():
 				self.need_redraw = True
-			else:
-				if self.target.sort_if_outdated():
-					self.need_redraw = True
+			elif self.target.sort_if_outdated():
+				self.need_redraw = True
+			elif self.last_redraw_time < self.target.last_update_time:
+				self.need_redraw = True
 
 		if self.need_redraw:
 			self.win.erase()
@@ -102,6 +107,7 @@ class BrowserColumn(Pager, Widget):
 				self._draw_directory()
 				Widget.draw(self)
 			self.need_redraw = False
+			self.last_redraw_time = time()
 
 	def _preview_this_file(self, target):
 		return target.document and self.settings.preview_files
d='n539' href='#n539'>539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674