Commits

Herbert Breunung committed 2d42ab2

moving notbook tabs works now for mouse and keys

  • Participants
  • Parent commits 3a54b2a

Comments (0)

Files changed (3)

File lib/Kephra/App/Bar/Document.pm

 		&Wx::wxAUI_NB_SCROLL_BUTTONS | &Wx::wxAUI_NB_CLOSE_ON_ACTIVE_TAB
 	);
 
-	$self->{'visual_panel_order'} = [];
-	$self->{'internal_panel_order'} = [];
+	$self->{'visual_panel_order'} = [];   # visual order of internal indexes : vis -> int
+	$self->{'internal_panel_order'} = []; # internal order of visual indexes : int -> vis
+	$self->activate_events();
 
-	my $dragged_tab_nr;
+	return $self;
+}
+
+sub activate_events {
+	my ($self) = @_;
 	Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG( $self, -1, sub {
 		my ($nb, $event ) = @_;
-		$self->{'moving_panel_nr'} = $event->GetSelection;
+		$self->{'DND_panel_nr'} = $event->GetSelection;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_END_DRAG($self, -1, sub {
 		my ($nb, $event ) = @_;
-		return unless defined $self->{'moving_panel_nr'};
-		my $panel_nr = $self->{'moving_panel_nr'};
-		$nb->move_panel($panel_nr, $event->GetSelection);
-		$self->{'moving_panel_nr'} = undef;
+		return unless defined $self->{'DND_panel_nr'};
+		$nb->move_panel_index_visually($self->{'DND_panel_nr'}, $event->GetSelection);
+		$self->{'DND_panel_nr'} = undef;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
 		my ($nb, $event ) = @_;
 		Kephra::File::close_active();
 	});
 	# keep focus on editor even when klicking on tab bar
-	Wx::Event::EVT_LEFT_DOWN($self, sub { Kephra::API::active_editor()->focus; print "--"; });
-	return $self;
+	#Wx::Event::EVT_LEFT_DOWN($self, sub { Kephra::API::active_editor()->focus; print "--"; });
+	#$self->Connect( -1, -1, &Wx::wxEVT_SET_FOCUS, sub {  print "--"; } )
+}
+sub silence_events {
+	my ($self) = @_;
+	Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG( $self, -1, sub {});
+	Wx::Event::EVT_AUINOTEBOOK_END_DRAG($self, -1, sub {});
+	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {});
+	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub {});
 }
 
 sub add_page {
 	$self->set_title( $position, $label);
 	$ed->focus() if $set_active;
 
+	splice @{ $self->{'visual_panel_order'} }, $position, 0, $self->GetPageCount-1;
+	$self->refresh_internal_panel_order;
+
 	return $ed;
 }
 
+sub remove_page {
+	my ($self, $internal_position) = @_;
+	$self->DeletePage( $internal_position );
+	my $visual_position = $self->{'internal_panel_order'}[$internal_position];
+	my $visual = $self->{'visual_panel_order'};
+	splice @$visual, $visual_position, 1;
+	for (@$visual) {$_-- if $_ > $internal_position}
+	$self->{'visual_panel_order'} = $visual;
+	$self->refresh_internal_panel_order;
+}
+
+sub refresh_internal_panel_order {
+	my ($self) = @_;
+	my $visual = $self->{'visual_panel_order'};
+	return unless ref $visual eq ref [];
+	my $internal;
+	$internal->[ $visual->[$_] ] = $_ for 0 .. @$visual-1;
+	$self->{'internal_panel_order'} = $internal;
+}
+
+sub move_panel_index_visually { 
+	my ($self, $from, $to ) = @_;
+	return unless $from >= 0 and $from < $self->GetPageCount;
+	return unless $to >= 0 and $to < $self->GetPageCount;
+	my $index = splice @{$self->{'visual_panel_order'}}, $from, 1;
+	splice @{$self->{'visual_panel_order'}}, $to, 0, $index;
+	$self->refresh_internal_panel_order();
+}
+
+sub move_panel_visually { 
+	my ($self, $from, $to ) = @_;
+	my $max = $self->GetPageCount - 1;
+	return if $from < 0 or $from > $max;
+	return if $to < 0 or $to > $max;
+	return if $from == $to;
+
+	my $pos = $self->{'visual_panel_order'}[ $from ];
+	my $page = $self->GetPage( $pos );
+	my $label = $self->GetPageText( $pos );
+	my $visual = $self->{'visual_panel_order'};
+
+	$self->silence_events();
+	$self->RemovePage( $pos );
+	$self->InsertPage( $to, $page, $label);
+	my $removed = splice @$visual, $from, 1;
+	if ($from < $to) { for (@$visual) {$_-- if $_ > $removed and $_ <= $to} }
+	else             { for (@$visual) {$_++ if $_ < $removed and $_ >= $to} }
+	splice @$visual, $to, 0, $to;
+	$self->{'visual_panel_order'} = $visual;
+	$self->refresh_internal_panel_order();
+	$self->SetSelection( $self->{'visual_panel_order'}[$to] );
+	$self->activate_events();
+}
+
+sub move_panel_left  { 
+	my ($self) = @_;
+	my $max = $self->GetPageCount - 1;
+	my $pos = $self->{'internal_panel_order'}[ $self->GetSelection ];
+	$self->move_panel_visually( $pos, $pos == 0 ? $max : $pos-1 );
+}
+sub move_panel_right { 
+	my ($self) = @_;
+	my $max = $self->GetPageCount - 1;
+	my $pos = $self->{'internal_panel_order'}[ $self->GetSelection ];
+	$self->move_panel_visually( $pos, $pos == $max ? 0 : $pos+1 );
+}
+
+sub select_panel_left  { 
+	my ($self) = @_;
+	my $max = $self->GetPageCount - 1;
+	my $pos = $self->{'internal_panel_order'}[ $self->GetSelection ];
+	$pos = $self->{'visual_panel_order'}[ $pos == 0 ? $max : $pos-1 ];
+	$self->SetSelection( $pos );
+}
+sub select_panel_right { 
+	my ($self) = @_;
+	my $max = $self->GetPageCount - 1;
+	my $pos = $self->{'internal_panel_order'}[ $self->GetSelection ];
+	$pos = $self->{'visual_panel_order'}[  $pos == $max ? 0 : $pos+1 ];
+	$self->SetSelection( $pos );
+}
+
 sub raise_panel {
 	my ($self, $ed) = @_;
 	$self->SetSelection( $self->GetPageIndex($ed) );
 }
 
 sub set_title {
-	my ($self, $nr, $label) = @_;
-	return unless $nr >= 0 and $nr < $self->GetPageCount;
+	my ($self, $position, $label) = @_;
+	return unless $position >= 0 and $position < $self->GetPageCount;
 	$label = '<untitled>' unless $label;
-	$self->SetPageText( $nr, $label );
-}
-
-sub select_panel_left  { 
-	my ($self) = @_;
-	my ($pos, $max) = ($self->GetSelection, $self->GetPageCount - 1);
-	$self->SetSelection( $pos == 0 ? $max : $pos-1 );
-}
-sub select_panel_right { 
-	my ($self) = @_;
-	my ($pos, $max) = ($self->GetSelection, $self->GetPageCount - 1);
-	$self->SetSelection( $pos == $max ? 0 : $pos+1 );
-}
-sub move_panel_left  { 
-	my ($self) = @_;
-	my ($pos, $max) = ($self->GetSelection, $self->GetPageCount - 1);
-	my $next = $pos == 0 ? $max : $pos-1;
-	$self->move_panel( $pos, $next );
-}
-sub move_panel_right { 
-	my ($self) = @_;
-	my ($pos, $max) = ($self->GetSelection, $self->GetPageCount - 1);
-	my $next = $pos == $max ? 0 : $pos+1;
-	$self->move_panel( $pos, $next );
-}
-
-sub move_panel { 
-	my ($self, $from, $to ) = @_;
-}
-sub refresh_internal_panel_order {
-	my ($self) = @_;
-	my $visual = $self->{'visual_panel_order'};
-	return unless ref $visual eq ref [];
-	my $internal;
-	$internal->[] for 0 .. @$visual-1;
-	$self->{'internal_panel_order'} = $internal;
+	$self->SetPageText( $position, $label );
 }
 
 1;

File lib/Kephra/App/Panel/Editor.pm

 	return unless ref $doc and $doc->isa('Kephra::Document');
 	my $main_doc_bar = _active_docbar();
 	if ($main_doc_bar->GetPageCount > 1) {
-		$main_doc_bar->DeletePage( $main_doc_bar->GetPageIndex( $doc->editor ) );
+		$main_doc_bar->remove_page( $main_doc_bar->GetPageIndex( $doc->editor ) );
 	} else {
 		$doc->editor->ClearAll;
 		$doc->assign_file('');

File lib/Kephra/App/Window.pm

 
 sub new {
     my( $class, $title ) = @_;
-    my( $self ) = $_ref = $class->SUPER::new ( undef, -1, $title, [-1,-1],[800, 600] );
+    my( $self ) = $_ref = $class->SUPER::new ( undef, -1, $title, [-1,-1],[1000, 800] );
     $self->SetIcon( Wx::GetWxPerlIcon() );
 
     # container var for all panel, sizer and splitter