[Bps-public-commit] r9902 - in RT-Client-Console: trunk/lib/RT/Client trunk/lib/RT/Client/Console/Session trunk/lib/RT/Client/Console/Session/Ticket

dams at bestpractical.com dams at bestpractical.com
Tue Dec 11 22:56:13 EST 2007


Author: dams
Date: Tue Dec 11 22:56:12 2007
New Revision: 9902

Modified:
   RT-Client-Console/   (props changed)
   RT-Client-Console/trunk/lib/RT/Client/Console.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm

Log:
 r27 at pundit:  dams | 2007-12-12 03:56:07 +0000
 . implement attachment scrollings
 . if an action returns -1, keyhandler will not redraw the entire screen (use with caution)
 . improved GUI (thanks maddingue)


Modified: RT-Client-Console/trunk/lib/RT/Client/Console.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console.pm	Tue Dec 11 22:56:12 2007
@@ -133,7 +133,7 @@
 use Curses::Forms::Dialog::Input;
 sub input_ok_cancel {
     my ($class, $title, $message, $length) = @_;
-    my ($rv, $value) = input($title, BTN_OK | BTN_CANCEL, $message, $length || 256,
+    my ($rv, $value) = input("[ $title ]", BTN_OK | BTN_CANCEL, $message, $length || 256,
                              qw(white blue yellow));
     # XXX bug, if one doesn't enter anything, or an empty string or 0 or '0'...
 	$class->cls();

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	Tue Dec 11 22:56:12 2007
@@ -48,9 +48,11 @@
 				} elsif (exists $heap->{key_to_action}->{$keystroke}) {
  					my $action = $heap->{key_to_action}->{$keystroke};
  					print STDERR "action : $action, event : $action->{event}\n";
- 					$kernel->call($action->{session}, $action->{event});
- 					$kernel->call('key_handler', 'compute_keys');
- 					$kernel->call('key_handler', 'draw_all');
+ 					my $ret = $kernel->call($action->{session}, $action->{event});
+					$kernel->call('key_handler', 'compute_keys');
+					if ($ret != -1) {
+						$kernel->call('key_handler', 'draw_all');
+					}
  				}
 			}
  		},

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	Tue Dec 11 22:56:12 2007
@@ -1,10 +1,14 @@
 package RT::Client::Console::Session::Ticket::Attachments;
 
+use strict;
+use warnings;
+
 use base qw(RT::Client::Console::Session);
 
 use Params::Validate qw(:all);
 use Error qw(:try);
 
+use Curses::Widgets;
 use POE;
 
 # class method
@@ -28,7 +32,9 @@
 		},
 		available_keys => sub {
 			return (['<KEY_NPAGE>', 'next attachment', 'next_attachment'],
-					['<KEY_PPAGE>', 'previous attachment', 'prev_attachment']
+					['<KEY_PPAGE>', 'previous attachment', 'prev_attachment'],
+					['<KEY_UP>', 'previous attachment', 'scroll_up'],
+					['<KEY_DOWN>', 'previous attachment', 'scroll_down'],
 				   );
 		},
 		next_attachment => sub {
@@ -36,12 +42,53 @@
 			$heap->{current}++;
 			$heap->{current} > $heap->{total} - 1
 			  and $heap->{current} = $heap->{total} - 1;
+			$heap->{positions}[$heap->{current}]->{current} = 0;
 		},
 		prev_attachment => sub {
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
 			$heap->{current}--;
 			$heap->{current} < 0
 			  and $heap->{current} = 0;
+			$heap->{positions}[$heap->{current}]->{current} = 0;
+		},
+		scroll_down => sub {
+ 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
+ 			my $idx = $heap->{current};
+			my $positions = $heap->{positions}[$idx];
+			defined $positions or return -1;
+			if ($positions->{current} >= @{$positions->{array}} - 1) {
+				if ($heap->{current} < $heap->{total} - 1 ) {
+					$heap->{current}++;
+					if (defined $heap->{positions}[$idx+1]) {
+						$heap->{positions}[$idx+1]->{current} = 0;
+					}
+					$kernel->call("ticket_attachments_$ticket_id", 'draw');
+				}
+				return -1;
+			}
+			$positions->{current}++;
+ 			$kernel->call("ticket_attachments_$ticket_id", 'draw');
+			return -1;
+		},
+		scroll_up => sub {
+ 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
+ 			my $idx = $heap->{current};
+			my $positions = $heap->{positions}[$idx];
+			defined $positions or return -1;
+			if ($positions->{current} <= 0) {
+				if ($heap->{current} > 0) {
+					$heap->{current}--;
+					if (defined $heap->{positions}[$idx-1]) {
+						$heap->{positions}[$idx-1]->{current} =
+						  @{$heap->{positions}[$idx-1]->{array}} - 1;
+					}
+					$kernel->call("ticket_attachments_$ticket_id", 'draw');
+				}
+				return -1;
+			}
+			$positions->{current}--;
+ 			$kernel->call("ticket_attachments_$ticket_id", 'draw');
+			return -1;
 		},
 		draw => sub {
 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
@@ -80,23 +127,19 @@
 					warn ref($e), ": ", $e->message || $e->description, "\n";
 				};
 				
-				$text = $class->as_text($attachment);
+				$text = $class->as_text($heap, $attachment, $idx, $heap->{width});
 			}
 			my $title = '[ Attachment ' . ($idx + 1) . " / $total - $user_details ]";
 			$title =~ s/\s+/ /g;
 
 			use Curses::Widgets::ListBox;
-#my $widget = Curses::Widgets::ListBox->new({
-#  Y           => 2,
-#  X           => 38,
-#  COLUMNS     => 20,
-#  LISTITEMS   => ['Ham', 'Eggs', 'Cheese', 'Hash Browns', 'Toast'],
-#  MULTISEL    => 1,
-#  VALUE       => [0, 2],
-#  SELECTEDCOL => 'green',
-#  CAPTION     => 'List Box',
-#  CAPTIONCOL  => 'yellow',
-#  });
+			my ($textstart, $cursorpos) = (0, 0);
+			my $positions = $heap->{positions}[$idx];
+			if (defined $positions) {
+				($textstart, $cursorpos) = @{$positions->{array}[$positions->{current}]};
+			}
+			print STDERR "+++ SCROLL : text start : $textstart\n";
+			print STDERR "+++ CURSOR : $cursorpos\n";
 
 			use Curses::Widgets::TextMemo;
  			my $widget = Curses::Widgets::TextMemo->new(
@@ -109,17 +152,23 @@
  					 FOREGROUND  => 'white',
  					 BACKGROUND  => 'black',
  					 VALUE       => $text,
- 					 BORDERCOL   => 'blue',
+ 					 BORDERCOL   => 'red',
  					 BORDER      => 1,
  					 CAPTION     => $title,
  					 CAPTIONCOL  => 'yellow',
  					 READONLY    => 1,
- 					}
+					 TEXTSTART   => $textstart,
+					 CURSORPOS   => $cursorpos,
+					}
  			);
 			$widget->draw($class->get_curses_handler());
 
 			# draw keys
-			my @keys = $kernel->call("ticket_attachments_$ticket_id" => 'available_keys');
+			my @keys = map {
+				my $n = $_->[0];
+				$n =~ s/<KEY_(.*)>/$1/;
+				[ lc($n), @{$_}[1,2] ];
+			} $kernel->call("ticket_attachments_$ticket_id" => 'available_keys');			
 			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} + 1 ,
 									 X => $heap->{'pos_x'} + 5,
 									 COLUMNS => $heap->{width} - 2,
@@ -132,6 +181,8 @@
 			  'pos_y' => 0,
 			  'width' => 0,
 			  'height' => 0,
+			  positions => [],
+			  text => [],
 			},
 	);
 }
@@ -152,18 +203,32 @@
 }
 
 sub as_text {
-    my ($class, $attachment) = @_;
+    my ($class, $heap, $attachment, $idx, $width) = @_;
+	defined $heap->{text}[$idx] and return $heap->{text}[$idx];
 	my $s = 'content :(' . $attachment->content_type() . ')' . "\n"
 	      . 'subject :{' . $attachment->subject() . '}' . "\n"
 	      . 'filename:{' . $attachment->file_name() . '}';
+	my $text;
     if ($attachment->content_type eq 'text/plain') {
-        return $s . "\n\n" . $attachment->content();
+        $text = $s . "\n\n" . $attachment->content();
     } elsif ($attachment->content_type eq 'multipart/mixed') {
-        return $s . "\n\n[" . $attachment->content() . "]\n";
-	}
-	else {
-        return $s;
+        $text = $s . "\n\n[" . $attachment->content() . "]\n";
+	} else {
+        $text = $s;
     }
+	$heap->{text}[$idx] = $text;
+	my @lines = textwrap($text, $width - 1);
+	my $i = 0;
+	my $l = 0;
+	$heap->{positions}[$idx] = 
+	  {
+	   current => 0,
+	   array => [
+				 [ 0, 0 ],
+				 map { [ ++$i, $l += length ]; } @lines,
+				],
+	  };
+	return $text;
 }
 
 sub _generate_job {

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	Tue Dec 11 22:56:12 2007
@@ -37,7 +37,7 @@
 								  keys => {
 										   s => { text => 'change subject',
 												  code => sub {
-													  if (my $new_subject = $class->input_ok_cancel(' Change subject ', $ticket->subject(), 500)) {
+													  if (my $new_subject = $class->input_ok_cancel('Change subject', $ticket->subject(), 500)) {
 														  $ticket->subject($new_subject);
 														  return 1; # stop modal mode
 													  }
@@ -45,7 +45,7 @@
 												},
 										   t => { text => 'change status',
 												  code => sub {
-													  if (my $new_status = $class->input_list(title => ' Change status ',
+													  if (my $new_status = $class->input_list(title => 'Change status',
 																							  items => [ qw(new open resolved stalled rejected deleted) ],
 																							  value => $ticket->status(),
 																							 )) {
@@ -57,7 +57,7 @@
 										   q => { text => 'change queue',
 												  code => sub {
 
-													  if (my $new_queue = $class->input_ok_cancel(' Change queue ', $ticket->queue(), 500)) {
+													  if (my $new_queue = $class->input_ok_cancel('Change queue', $ticket->queue(), 500)) {
 														  $ticket->queue($new_queue);
 														  return 1; # stop modal mode
 													  }
@@ -85,7 +85,7 @@
 												},
 										   p => { text => 'change priority',
 												  code => sub {
-													  if (my $new_priority = $class->input_ok_cancel(' Change priority ', $ticket->priority(), 20)) {
+													  if (my $new_priority = $class->input_ok_cancel('Change priority', $ticket->priority(), 20)) {
 														  $ticket->priority($new_priority);
 														  return 1; # stop modal mode
 													  }

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	Tue Dec 11 22:56:12 2007
@@ -34,7 +34,7 @@
 								  keys => {
 										   p => { text => 'change parents',
 												  code => sub {
-													  if (my $new_parents = $class->input_ok_cancel(' Change parents ', join(', ', map {$_->id() } @{$heap->{parents}}), 500)) {
+													  if (my $new_parents = $class->input_ok_cancel('Change parents', join(', ', map {$_->id() } @{$heap->{parents}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -42,7 +42,7 @@
 												},
 										   c => { text => 'change children',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change children ', join(', ', map {$_->id() } @{$heap->{children}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel('Change children', join(', ', map {$_->id() } @{$heap->{children}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -50,7 +50,7 @@
 												},
 										   d => { text => 'change depends',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change depends ', join(', ', map {$_->id() } @{$heap->{depends}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel('Change depends', join(', ', map {$_->id() } @{$heap->{depends}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -58,7 +58,7 @@
 												},
 										   D => { text => 'change depended',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change depended ', join(', ', map {$_->id() } @{$heap->{depended}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel('Change depended', join(', ', map {$_->id() } @{$heap->{depended}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -66,7 +66,7 @@
 												},
 										   r => { text => 'change refers',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change refers ', join(', ', map {$_->id() } @{$heap->{refers}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel('Change refers', join(', ', map {$_->id() } @{$heap->{refers}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -74,7 +74,7 @@
 												},
 										   R => { text => 'change referred',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change referred ', join(', ', map {$_->id() } @{$heap->{refered}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel('Change referred', join(', ', map {$_->id() } @{$heap->{refered}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  



More information about the Bps-public-commit mailing list