Commits

Herbert Breunung  committed 2282784

sanitize path handling a bit

  • Participants
  • Parent commits d85efc2

Comments (0)

Files changed (5)

File lib/Kephra.pm

 
 package Kephra;
 our $NAME     = __PACKAGE__;    # name of entire application
-our $VERSION  = '0.4.5.13';
+our $VERSION  = '0.4.5.14';
+our $MODE     = 'test';
+our $start_path;
+our $location_path;
 
 our @external_dependencies = (
 	qw/Benchmark Encode Encode::Guess Cwd/,
 sub start {
 	#start_worker_thread();
 	load_libs();
-	configdir();
+	$start_path = Cwd::cwd();
+	$location_path = File::Spec->catfile($start_path, __FILE__);
+	$location_path = ( File::Spec->splitpath($location_path) )[1];
 	Kephra::App->new()->MainLoop();
 }
 

File lib/Kephra/App/Part/FileBrowser.pm

+use v5.10;
 use strict;
 use warnings;
 
 package Kephra::App::Part::FileBrowser;
 our @ISA = 'Wx::TreeCtrl';
 my $panel;
-use Cwd;
 use File::Find;
 use File::Spec;
 
-use Kephra::API;
-use Kephra::File;
-
 Kephra::API::Command::register({
  'filebrowser-focus' =>{ sub=>'focus', label => ' ', keys => 'F2' },
 });
 		&Wx::wxTR_SINGLE | &Wx::wxTR_HIDE_ROOT,
 	);
 
-	my @lib = @{ get_modules_and_paths('lib') };
+	my $lib = get_modules_and_paths($Kephra::location_path);
 	my $root_ID = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new( ));
-	for (0 .. $#lib){
-		my $data = Wx::TreeItemData->new; 
-		$data->SetData( $lib[$_][1] );
-		my $ItemID = $self->AppendItem( $root_ID, $lib[$_][0] );
-		$self->SetItemData( $ItemID, $data );
+	if (ref $lib eq 'ARRAY'){
+		for (0 .. @$lib - 1){
+			my $data = Wx::TreeItemData->new; 
+			$data->SetData( $lib->[$_][1] );
+			my $ItemID = $self->AppendItem( $root_ID, $lib->[$_][0] );
+			$self->SetItemData( $ItemID, $data );
+		}
 	}
 
 	Wx::Event::EVT_TREE_ITEM_ACTIVATED( $self, -1, sub {
 		my ($fb, $event) = @_;
+		say $fb->GetItemData( $event->GetItem )->GetData;
 		Kephra::File::open( $fb->GetItemData( $event->GetItem )->GetData );
 		Wx::Window::SetFocus( $fb );
 	} );
 sub get_modules_and_paths {
 	my $dir = shift;
 	return 0 unless -d $dir;
+	my $cwd = Cwd::cwd();
+	chdir $dir;
 	my @libs;
-	my $cwd = Cwd::cwd();
 	find( sub {
 		return if not -f $_ or $_ !~ /\.pm$/;
 		my $file = my $module = $File::Find::name;
-		$module =~ s|lib/||;
+		$module = substr($module, 2);
 		$module =~ s|\.pm||;
 		$module =~ s|/|::|g;
-		push @libs, [ $module, File::Spec->catfile( $cwd, $file ) ];
-	}, $dir);
+		push @libs, [ $module, File::Spec->catfile($dir, $file) ];
+	}, '.');
+	chdir $cwd;
 	@libs = sort {$a->[0] cmp $b->[0]} @libs;
 	return \@libs;
 }

File lib/Kephra/Config.pm

 
 package Kephra::Config;
 
-sub init {
-}
+sub init {}
 
 1;

File lib/Kephra/Config/File/Location.pm

 use strict;
 use warnings;
 use Cwd;
+use FindBin;
 
 package Kephra::Config::File::Location;
-our $base_path;
+my $base_path = $Kephra::MODE eq 'test'
+	? Cwd::cwd()
+	: File::UserConfig->configdir( dist => $Kephra::NAME );
 
-use File::Spec;
-use File::HomeDir;
-use File::UserConfig;
+
+;
 
 
 sub init {
 	#$base_path
 	#say Cwd::cwd();
 	#say Kephra::configdir();
-	say File::UserConfig->configdir(dist     => 'Kephra', sharedir  => 'config');
+	#say $base_path;
+	#my $path = File::Spec->catfile(Cwd::cwd(), __FILE__);
+	#say rindex($path, 'Kephra'
+	#my $base_madule_name = (split '::', __PACKAGE__)[0];
+	#say $FindBin::Bin;
+	#say File::Spec->catfile(Cwd::cwd(), __FILE__) if -e $path;
 	#say File::UserConfig->configdir('Kephra');
+	
 	#say File::HomeDir->my_home;
 }
 

File lib/Kephra/Document.pm

 		}
 
 		$self->_set_old_file_path( $self->file_path );
-		$_->set_page_title( $self->title, $self->panel->{$_} )
-			for Kephra::API::all_docbars();
+		#$_->set_page_title( $self->title, $self->panel->{$_} )
+			#for Kephra::API::all_docbars();
+		# panel is no hash
+		say $self->panel for Kephra::API::all_docbars();
 	});
 has file_dir     => ( is => 'rwp', );
 has file_name    => ( is => 'rwp', );