Example #1
0
std::string TPathUtil::GetReletivePath(const std::string& completePath, const std::string& base)
{
    if (base.empty()) {
        return completePath;
    }
    
    TStrings baseCoponents = TStringUtils::Split(base, "/");
    TStrings pathCoponents = TStringUtils::Split(completePath, "/");
    
    for (size_t i = 0; i < baseCoponents.size(); ++ i) {
        if (i < pathCoponents.size() && !baseCoponents.at(i).empty()) {
            if (baseCoponents.at(i) == pathCoponents.at(i)) {
                pathCoponents[i] = "";
            } else {
                pathCoponents.insert(pathCoponents.begin(), "..");
            }
        }
    }
    
    std::string reletivePath;
    for (size_t i = 0; i < pathCoponents.size(); ++ i) {
        if (pathCoponents.at(i).empty()) {
            continue;
        }
        
        if (!reletivePath.empty()) {
            reletivePath += "/";
        }
        reletivePath += pathCoponents.at(i);
    }
    return reletivePath;
}
Example #2
0
void RightPanel::onCallback(FlLayout::Widget const& w, Fl_Widget * pWidget, int userData)
{
#ifdef USE_LUABIND
	try
	{
		if(L)
		{
			bool res=luabind::call_function<bool>(L->L, "onCallback", w, userData);
			if (res) return;
		}
	}
	CATCH_LUABIND_ERROR("onCallBack", *this)
#else
		if(L)
		{
			lunaStack l(L);
			l.getglobal("onCallback");
			l.push<FlLayout::Widget>(&w);
			l<<userData;
			l.call(2,1);
			bool res;
			l>>res;
			if(res) return;
		}
#endif
	if(w.mId=="update")
	{
		mPDFwin->pageChanged();
		mPDFwin->redraw();
	}
	else if(w.mId=="Use automatic segmentation")
	{
		if(w.checkButton()->value())
		{
			findLayout("Automatic segmentation")->activate();
			redraw();
		}
		else
		{
			findLayout("Automatic segmentation")->deactivate();
			redraw();
		}
	}
	else if(w.mId=="Option")
	{
		TString fn=FlChooseFile("Choose option", "script","*.lua");
		if(fn.length())
		{
			TString ff, dir;
			ff=sz1::filename(fn, dir);
			find<Fl_Input>("Option_Input")->value(processOption(ff.left(-4)));
			redraw();
		}

	}
	else if(w.mId=="Load a PDF file")
	{
#ifndef NO_SHOW_WIN
		Fl_Native_File_Chooser *chooser = new Fl_Native_File_Chooser();
		chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);   // let user browse a single file
		chooser->title("Open a file");                        // optional title
		//chooser->preset_file("/var/tmp/somefile.txt");        // optional filename preset
		chooser->filter("PDF Files\t*.pdf");                 // optional filter
		TString fn;
		switch ( chooser->show() ) {
			case -1:    // ERROR
			fprintf(stderr, "*** ERROR show() failed:%s\n", chooser->errmsg());
			break;
			case 1:     // CANCEL
			fprintf(stderr, "*** CANCEL\n");
			break;
			default:    // USER PICKED A FILE
			fn=chooser->filename();
			break;
		}
		//TString fn=fl_file_chooser("Choose a PDF file", "*.pdf", NULL);
		if(fn.length())
		{
			mPDFwin->load(fn);

		}
#endif
	}
	else if(w.mId=="Batch process")
	{
#ifndef NO_SHOW_WIN
		Fl_Native_File_Chooser *chooser = new Fl_Native_File_Chooser();
		chooser->type(Fl_Native_File_Chooser::BROWSE_MULTI_FILE);   // let user browse a single file
		chooser->title("Open files");                        // optional title
		//chooser->preset_file("/var/tmp/somefile.txt");        // optional filename preset
		chooser->filter("PDF Files\t*.pdf");                 // optional filter
		TStrings fn;
		switch ( chooser->show() ) {
			case -1:    // ERROR
			fprintf(stderr, "*** ERROR show() failed:%s\n", chooser->errmsg());
			break;
			case 1:     // CANCEL
			fprintf(stderr, "*** CANCEL\n");
			break;
			default:    // USER PICKED A FILE
				{
					fn.resize(chooser->count());
					for (int n = 0; n < chooser->count(); n++ ) 
      				fn[n]=chooser->filename(n);
				}
			break;
		}
		//TString fn=fl_file_chooser("Choose a PDF file", "*.pdf", NULL);
		if(fn.size())
		{

			for(int i=0; i<fn.size(); i++)
			{
				mPDFwin->load(fn[i]);
				onCallback(findWidget("Process all pages"), w.widgetRaw(), 0);
			}
		}
#endif
	}
}