Commits

Herbert Breunung committed f00cf47

consequent usage of the word page in the Docbar API

Comments (0)

Files changed (3)

lib/Kephra/App/Bar/Document.pm

 package Kephra::App::Bar::Document;
 our @ISA = 'Wx::AuiNotebook';
 
-my $put_on_panel = Kephra::App::Util::get('put_on_panel');
+my ($is_panel, $is_widget) = Kephra::App::Util::get(qw/is_panel is_widget/);
 
 sub new {
 	my( $class, $parent) = @_;
 		&Wx::wxAUI_NB_SCROLL_BUTTONS | &Wx::wxAUI_NB_CLOSE_ON_ACTIVE_TAB
 	);
 
-	$self->{'visual_panel_order'} = [];   # visual order of internal indexes : vis -> int
-	$self->{'internal_panel_order'} = []; # internal order of visual indexes : int -> vis
+	$self->{'visual_page_order'} = [];   # visual order of internal indexes : vis -> int
+	$self->{'internal_page_order'} = []; # internal order of visual indexes : int -> vis
 	$self->activate_events();
 
 	return $self;
 	my ($self) = @_;
 	Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG( $self, -1, sub {
 		my ($nb, $event ) = @_;
-		$self->{'DND_panel_nr'} = $event->GetSelection;
+		$self->{'DND_page_nr'} = $event->GetSelection;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_END_DRAG($self, -1, sub {
 		my ($nb, $event ) = @_;
-		return unless defined $self->{'DND_panel_nr'};
-		$nb->move_panel_index_visually($self->{'DND_panel_nr'}, $event->GetSelection);
-		$self->{'DND_panel_nr'} = undef;
+		return unless defined $self->{'DND_page_nr'};
+		$nb->move_page_index_visually($self->{'DND_page_nr'}, $event->GetSelection);
+		$self->{'DND_page_nr'} = undef;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
 		my ($nb, $event ) = @_;
 sub add_page {
 	my ($self, $label, $position, $set_active, $panel_candidate ) = @_;
 	return unless $panel_candidate 
-		and ($panel_candidate->isa('Wx::Panel') 
-		  or $panel_candidate->isa('Wx::Control')
-		  or $panel_candidate->isa('Kephra::Document')
+		and ($is_panel->($panel_candidate) or $is_widget->($panel_candidate) or
+		     $panel_candidate->isa('Kephra::Document')
 	);
 	my $new_panel  = $panel_candidate->isa('Kephra::Document')
 		? $panel_candidate->editor
 		: $panel_candidate;
 	my $active_pos = $self->GetSelection;
 
-	$label    = ''                            unless defined $label;
-	$position = 'right'                       if $position eq 'default' or $position == -1;
-	$position = $self->rightmost_panel_pos+1  if $position eq 'rightmost';
-	$position = $active_pos + 1               if $position eq 'right';
-	$position = $active_pos                   if $position eq 'left';
-	$position = $self->leftmost_panel_pos     if $position eq 'leftmost';
-	$set_active = 1                           unless defined $set_active;
+	$label    = ''                           unless defined $label;
+	$position = 'right'                      if $position eq 'default' or $position == -1;
+	$position = $self->rightmost_page_pos+1  if $position eq 'rightmost';
+	$position = $active_pos + 1              if $position eq 'right';
+	$position = $active_pos                  if $position eq 'left';
+	$position = $self->leftmost_page_pos     if $position eq 'leftmost';
+	$set_active = 1                          unless defined $set_active;
 
 	unless ($new_panel->isa('Wx::Panel')) { # put panel under a none-panel
 		$new_panel = Kephra::App::Panel->new( $self, $new_panel);
 	$panel_candidate->panel( $new_panel ) if $panel_candidate->isa('Kephra::Document');
 
 	$self->InsertPage( $position, $new_panel, $label, $set_active );
-	$self->set_title( $position, $label);
+	$self->set_page_title( $position, $label);
 	Wx::Window::SetFocus( $new_panel ) if $set_active;
 
 	# inserting new index to position translators
-	for   (@{$self->{'visual_panel_order'}}){ $_++ if $_ >= $position }
-	splice @{$self->{'visual_panel_order'}},  $position, 0, $position;
-	$self->refresh_internal_panel_order();
+	for   (@{$self->{'visual_page_order'}}){ $_++ if $_ >= $position }
+	splice @{$self->{'visual_page_order'}},  $position, 0, $position;
+	$self->refresh_internal_page_order();
 
 	return $position;
 }
 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'};
+	my $visual_position = $self->{'internal_page_order'}[$internal_position];
+	my $visual = $self->{'visual_page_order'};
 	splice @$visual, $visual_position, 1;
 	for (@$visual) {$_-- if $_ > $internal_position}
-	$self->{'visual_panel_order'} = $visual;
-	$self->refresh_internal_panel_order;
+	$self->{'visual_page_order'} = $visual;
+	$self->refresh_internal_page_order;
 }
 
-sub refresh_internal_panel_order {
+sub refresh_internal_page_order {
 	my ($self) = @_;
-	my $visual = $self->{'visual_panel_order'};
+	my $visual = $self->{'visual_page_order'};
 	return unless ref $visual eq ref [];
 	my $internal;
 	$internal->[ $visual->[$_] ] = $_ for 0 .. @$visual-1;
-	$self->{'internal_panel_order'} = $internal;
+	$self->{'internal_page_order'} = $internal;
 }
 
-sub move_panel_index_visually { # for dnd only
+sub move_page_index_visually { # for dnd only
 	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();
+	my $index = splice @{$self->{'visual_page_order'}}, $from, 1;
+	splice @{$self->{'visual_page_order'}}, $to, 0, $index;
+	$self->refresh_internal_page_order();
 }
 
-sub move_panel_visually { # for movements by keyboard
+sub move_page_visually { # for movements by keyboard
 	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 $pos = $self->{'visual_page_order'}[ $from ];
 	my $page = $self->GetPage( $pos );
 	my $label = $self->GetPageText( $pos );
-	my $visual = $self->{'visual_panel_order'};
+	my $visual = $self->{'visual_page_order'};
 
 	$self->silence_events();
 	$self->RemovePage( $pos );
 	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->{'visual_page_order'} = $visual;
+	$self->refresh_internal_page_order();
+	$self->SetSelection( $self->{'visual_page_order'}[$to] );
 	$self->activate_events();
 }
 
-sub move_panel_left  { 
+sub move_page_left  { 
 	my ($self) = @_;
-	$self->move_panel_visually ( 
-		$self->active_visual_pos, $self->next_pos_rot_left( $self->GetSelection )
+	$self->move_page_visually ( 
+		$self->active_visual_pos, $self->next_page_pos_rot_left( $self->GetSelection )
 	);
 }
-sub move_panel_right { 
+sub move_page_right { 
 	my ($self) = @_;
-	$self->move_panel_visually( 
-		$self->active_visual_pos, $self->next_pos_rot_right( $self->GetSelection )
+	$self->move_page_visually( 
+		$self->active_visual_pos, $self->next_page_pos_rot_right( $self->GetSelection )
 	);
 }
-sub move_panel_leftmost  { 
+sub move_page_leftmost  { 
 	my ($self) = @_;
-	$self->move_panel_visually( $self->active_visual_pos, $self->leftmost_panel_pos );
+	$self->move_page_visually( $self->active_visual_pos, $self->leftmost_page_pos );
 }
-sub move_panel_rightmost { 
+sub move_page_rightmost { 
 	my ($self) = @_;
-	$self->move_panel_visually( $self->active_visual_pos, $self->rightmost_panel_pos );
+	$self->move_page_visually( $self->active_visual_pos, $self->rightmost_page_pos );
 }
 
-sub select_panel_left  { 
+sub select_page_left  { 
 	my ($self) = @_;
-	$self->SetSelection( $self->next_pos_rot_left( $self->GetSelection ) );
+	$self->SetSelection( $self->next_page_pos_rot_left( $self->GetSelection ) );
 }
-sub select_panel_right { 
+sub select_page_right { 
 	my ($self) = @_;
-	$self->SetSelection( $self->next_pos_rot_right( $self->GetSelection ) );
+	$self->SetSelection( $self->next_page_pos_rot_right( $self->GetSelection ) );
 }
-sub select_panel_leftmost  { $_[0]->SetSelection( $_[0]->leftmost_panel_pos ) }
-sub select_panel_rightmost { $_[0]->SetSelection( $_[0]->rightmost_panel_pos ) }
+sub select_page_leftmost  { $_[0]->SetSelection( $_[0]->leftmost_page_pos ) }
+sub select_page_rightmost { $_[0]->SetSelection( $_[0]->rightmost_page_pos ) }
 
-sub leftmost_panel_pos { 0 }
-sub rightmost_panel_pos { $_[0]->GetPageCount-1 }
-sub active_visual_pos { $_[0]->{'internal_panel_order'}[ $_[0]->GetSelection ] }
-sub next_pos_rot_left {
+sub leftmost_page_pos { 0 }
+sub rightmost_page_pos { $_[0]->GetPageCount-1 }
+sub active_visual_pos { $_[0]->{'internal_page_order'}[ $_[0]->GetSelection ] }
+sub next_page_pos_rot_left {
 	my ($self) = @_; # take in position of internal order
-	my $pos = $self->{'internal_panel_order'}[ $_[1] ];
-	$self->{'visual_panel_order'}[$pos == 0 ? $self->rightmost_panel_pos : $pos-1]
+	my $pos = $self->{'internal_page_order'}[ $_[1] ];
+	$self->{'visual_page_order'}[$pos == 0 ? $self->rightmost_page_pos : $pos-1]
 }
-sub next_pos_rot_right {
+sub next_page_pos_rot_right {
 	my ($self) = @_; # take in position of internal order
-	my $pos = $self->{'internal_panel_order'}[ $_[1] ];
-	$self->{'visual_panel_order'}[$pos == $self->rightmost_panel_pos ? 0 : $pos+1]
+	my $pos = $self->{'internal_page_order'}[ $_[1] ];
+	$self->{'visual_page_order'}[$pos == $self->rightmost_page_pos ? 0 : $pos+1]
 }
 
-sub raise_panel {
-	my ($self, $panel) = @_;
-	$self->SetSelection( $self->GetPageIndex($panel) );
+sub raise_page {
+	my ($self, $page) = @_;
+	$self->SetSelection( $self->GetPageIndex($page) );
 }
 
-sub set_title {
+sub set_page_title {
 	my ($self, $position, $label) = @_;
 	return unless $position >= 0 and $position < $self->GetPageCount;
 	$label = '<untitled>' unless $label;

lib/Kephra/App/Panel/Editor.pm

 
 sub raise_file {
 	my $file = shift;
-	active_docbar()->raise_panel( 
+	active_docbar()->raise_page( 
 		Kephra::DocumentStash::doc_by_path($file)->{panel}
 	);
 }
-sub select_tab_leftmost {active_docbar()->select_panel_leftmost }
-sub select_tab_rightmost{active_docbar()->select_panel_rightmost }
-sub select_tab_left     {active_docbar()->select_panel_left }
-sub select_tab_right    {active_docbar()->select_panel_right }
-sub move_tab_leftmost   {active_docbar()->move_panel_leftmost }
-sub move_tab_rightmost  {active_docbar()->move_panel_rightmost }
-sub move_tab_left       {active_docbar()->move_panel_left }
-sub move_tab_right      {active_docbar()->move_panel_right }
+sub select_tab_leftmost {active_docbar()->select_page_leftmost }
+sub select_tab_rightmost{active_docbar()->select_page_rightmost }
+sub select_tab_left     {active_docbar()->select_page_left }
+sub select_tab_right    {active_docbar()->select_page_right }
+sub move_tab_leftmost   {active_docbar()->move_page_leftmost }
+sub move_tab_rightmost  {active_docbar()->move_page_rightmost }
+sub move_tab_left       {active_docbar()->move_page_left }
+sub move_tab_right      {active_docbar()->move_page_right }
 
 sub active_title {
 	my $nb = active_docbar();

lib/Kephra/App/Util.pm

 sub is_object { ( ref $_[0] and index(ref $_[0], '=') == -1) ? 1 : 0 }
 sub is_widget { ( is_object( $_[0] ) and $_[0]->isa('Wx::Control') ) ? 1 : 0 }
 sub is_panel  {
-	(  ($_[0] ref $_[0] and $_[0]->isa('Wx::Panel') ) ? 1 : 0 
+	($_[0] and ref $_[0] and 
+	 ($_[0]->isa('Wx::Panel') or $_[0]->isa('Kephra::App::Panel') )) ? 1 : 0
 }
 sub is_sizer  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Sizer') ) ? 1 : 0 }
 sub is_color  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk ) ? 1 : 0 }