示例#1
0
/*
 * Reposition by a given number of lines
 */
static int
JumpBackwards(int *infile, int jump)
{
    int savejump;
    int blank;
    int n;
    int page = NumP(1);

    savejump = jump = page - jump;
    n = TopOfPage(*infile, &blank);

    /* jump the requested number of lines */
    if (jump > 0) {
	if (n == 0) {
	    while ((blank = LineAt[n].blank) != 0) {
		n++;
	    }
	}
	while (jump > 0) {
	    if (++n >= max_lines) {
		return (-1);
	    }
	    if (blank && LineAt[n].blank)
		continue;
	    blank = LineAt[n].blank;
	    jump--;
	}
    } else {
	while (jump < 0) {
	    if (--n < 0) {
		*infile = 0;	/* take what we can get */
		(void) JumpToLine(*infile);
		return (-1);
	    }
	    if (blank && LineAt[n].blank)
		continue;
	    blank = LineAt[n].blank;
	    jump++;
	}
    }
#if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG)
    if (jump != savejump
	&& (n + NumP(1) < max_lines)
	&& (jump - savejump) < NumP(1)
	&& (savejump - jump) < NumP(1)) {
	int y, x;
	getyx(stdscr, y, x);
	move(LINES - 2, 0);
	setscrreg(mark_W + 1, LINES - 2);
	scrl(savejump - jump);
	setscrreg(0, LINES - 1);
	move(y, x);
    }
#endif
    *infile = n;
    return JumpToLine(*infile);
}
///////////////
// Key pressed
void DialogStyling::OnKeyDown(wxKeyEvent &event) {
	int keycode = event.GetKeyCode();

	// Previous line
	if (keycode == WXK_PRIOR) {
		JumpToLine(linen-1);
	}

	// Next line
	if (keycode == WXK_NEXT) {
		JumpToLine(linen+1);
	}

	event.Skip();
}
示例#3
0
static int
FoundPattern(int *infile)
{
    int foo;
    int top_line = *infile;

    (void) StartPage(infile, TRUE, &foo);
    if (HadPattern || was_interrupted) {
	reset_catcher();
	if (JumpToLine(top_line) >= 0) {
	    *infile = top_line;
	    (void) StartPage(infile, FALSE, &foo);
	    return TRUE;
	}
    }
    IgnorePage(*infile);
    return FALSE;
}
/////////////////////////////
// Set style of current line
void DialogStyling::SetStyle (wxString curName, bool jump) {
	// Get line
	AssDialogue *line = grid->GetDialogue(linen);

	// Update line
	line->Style = curName;
	line->UpdateData();

	// Update grid/subs
	grid->Refresh(false);
	if (PreviewCheck->IsChecked()) {
		grid->ass->FlagAsModified(_("Change Style (Assistant)"));
		grid->CommitChanges();
	}
	else needCommit = true;

	// Next line
	if (jump) JumpToLine(linen+1);
}
///////////////
// Constructor
DialogStyling::DialogStyling (wxWindow *parent,SubtitlesGrid *_grid) :
wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxRESIZE_BORDER)
{
	// Variables
	grid = _grid;
	audio = grid->video->audio->box->audioDisplay;
	needCommit = false;
	linen = -1;

	// Top sizer
	wxSizer *TopSizer = new wxStaticBoxSizer(wxHORIZONTAL,this,_("Current line"));
	CurLine = new wxTextCtrl(this,-1,_("Current line"),wxDefaultPosition,wxSize(300,60),wxTE_MULTILINE | wxTE_READONLY);
	TopSizer->Add(CurLine,1,wxEXPAND,0);

	// Left sizer
	Styles = new wxListBox(this,STYLE_LIST,wxDefaultPosition,wxSize(150,180),grid->ass->GetStyles());
	wxSizer *LeftSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Styles available"));
	LeftSizer->Add(Styles,1,wxEXPAND,0);

	// Right sizer
	wxSizer *RightSizer = new wxBoxSizer(wxVERTICAL);
	wxSizer *RightTop = new wxStaticBoxSizer(wxHORIZONTAL,this,_("Set style"));
	wxSizer *RightBottom = new wxStaticBoxSizer(wxVERTICAL,this,_("Keys"));
	TypeBox = new StyleEditBox(this);
	RightTop->Add(TypeBox,1,wxEXPAND);

	// Shortcuts
	//wxStaticText *Keys = new wxStaticText(this,-1,_("Enter:\t\tAccept changes\nPage up:\tPrevious line\nPage down:\tNext line\nEnd:\t\tPlay sound\nClick on list:\tSet style\nCtrl+enter:\tAccept without going to next"));
	wxSizer *KeysInnerSizer = new wxGridSizer(2,0,5);
	KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Styling Assistant Accept")) + _T(": ")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Accept changes")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Styling Assistant Preview")) + _T(": ")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Preview changes")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Styling Assistant Prev")) + _T(": ")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Previous line")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Styling Assistant Next")) + _T(": ")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Next line")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Styling Assistant Play")) + _T(": ")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Play Audio")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Click on list:")));
	KeysInnerSizer->Add(new wxStaticText(this,-1,_("Select style")));

	// Rest of right sizer
	PreviewCheck = new wxCheckBox(this,-1,_("Enable preview (slow)"));
	PreviewCheck->SetValue(true);
	RightBottom->Add(KeysInnerSizer,0,wxEXPAND | wxBOTTOM,5);
	RightBottom->Add(PreviewCheck,0,0,0);
	RightBottom->AddStretchSpacer(1);
	RightSizer->Add(RightTop,0,wxEXPAND | wxBOTTOM,5);
	RightSizer->Add(RightBottom,1,wxEXPAND | wxBOTTOM,0);

	// Bottom sizer
	wxSizer *BottomSizer = new wxBoxSizer(wxHORIZONTAL);
	BottomSizer->Add(LeftSizer,1,wxEXPAND | wxRIGHT,5);
	BottomSizer->Add(RightSizer,1,wxEXPAND,0);

	// Button sizer
	wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
	ButtonSizer->Add(new wxButton(this,wxID_HELP),0,wxRIGHT,0);
	ButtonSizer->AddStretchSpacer(1);
	wxButton *PlayButton = new wxButton(this,BUTTON_PLAY,_("Play Audio"));
	PlayButton->Enable(audio->loaded);
	ButtonSizer->Add(PlayButton,0,wxRIGHT,5);
	ButtonSizer->Add(new wxButton(this,wxID_OK),0,wxRIGHT,0);

	// Main sizer
	wxSizer *MainSizer = new wxBoxSizer(wxVERTICAL);
	MainSizer->Add(TopSizer,0,wxEXPAND | wxALL,5);
	MainSizer->Add(BottomSizer,1,wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT,5);
	MainSizer->Add(ButtonSizer,0,wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT,5);
	MainSizer->SetSizeHints(this);
	SetSizer(MainSizer);

	// Position window
	if (lastx == -1 && lasty == -1) {
		CenterOnParent();
	} else {
		Move(lastx, lasty);
	}

	// h4x
	origColour = TypeBox->GetBackgroundColour();

	// Load styles
	LoadStyles();

	// Set selection
	wxArrayInt sel = grid->GetSelection();
	if (sel.Count() > 0) JumpToLine(sel[0]);
	else JumpToLine(0);
}
示例#6
0
void
dedtype(RING * gbl,
	char *name,
	int inlist,
	int binary,
	int stripped,
	int isdir)
{
    int had_eof;
    int c;
    int count,			/* ...and repeat-count */
      y,			/* current line-in-screen */
      shift = COLS / 4,		/* amount of left/right shift */
      done = FALSE, shown = FALSE, infile = -1;		/* # of lines processed */
    OFF_T skip = 0;

    tabstop = 8;
    Shift = 0;
    UsePattern = FALSE;
    OptBinary = binary;
    OptStripped = stripped;

    if (isdir && !OptBinary) {
	DIR *dp;
	DirentT *de;
	char bfr[MAXPATHLEN];
# define INO_FMT "%5lu"
	if ((InFile = tmpfile()) == 0) {
	    warn(gbl, "tmp-file");
	    return;
	}
	if ((dp = opendir(name)) != 0) {
	    while ((de = readdir(dp)) != NULL) {
		(void) ded2string(gbl, bfr,
				  (int) NAMLEN(de),
				  de->d_name,
				  FALSE);
		FPRINTF(InFile, INO_FMT, (unsigned long) de->d_ino);
		FPRINTF(InFile, " %s\n", bfr);
	    }
	    (void) closedir(dp);
	    rewind(InFile);
	} else {
	    warn(gbl, "opendir");
	    FCLOSE(InFile);
	    return;
	}
    } else
	InFile = fopen(name, "r");

    in_dedtype = TRUE;		/* disable clearing of workspace via A/a cmd */

    if (InFile) {
	int jump = 0;

	dlog_comment("type \"%s\" (%s %s)\n",
		     name,
		     OptBinary ? "binary" : "text",
		     isdir ? "directory" : "file");
	to_work(gbl, FALSE);

	dyn_init(&my_text, BUFSIZ);
	dyn_init(&my_over, BUFSIZ);

	max_lines = -1;
	MarkLine(&infile);

	while (!done) {

	    if (jump) {
#if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG)
		/*
		 * If we're doing single-line scrolling past
		 * the point we've read in the file, try to
		 * cache pointers so that the scrolling logic
		 * will go more smoothly.
		 */
		if (jump > 0
		    && jump < NumP(1)
		    && infile + NumP(1) >= max_lines) {
		    int line = infile;
		    (void) StartPage(&line, TRUE, &had_eof);
		}
#endif
		(void) JumpBackwards(&infile, jump);
		jump = 0;
	    }

	    markC(gbl, TRUE);
	    y = StartPage(&infile, (int) skip, &had_eof);
	    if (skip && !was_interrupted) {
		if (feof(InFile)) {
		    skip = 0;
		    jump = NumP(1);
		} else {
		    IgnorePage(infile);
		    skip--;
		}
		continue;
	    }
	    if (had_eof) {
		int blank;
		infile = TopOfPage(infile, &blank);
		(void) JumpToLine(infile);
		y = StartPage(&infile, 0, &had_eof);
	    }
	    shown |= FinishPage(gbl, inlist, infile, y);
	    jump = NumP(1);

	    reset_catcher();
	    switch (c = dlog_char(gbl, &count, 1)) {
	    case CTL('K'):
		deddump(gbl);
		break;
	    case 'w':
		retouch(gbl, 0);
		break;
	    case '\t':
		if (OptBinary) {
		    beep();
		} else {
		    tabstop = (count <= 1)
			? (tabstop == 8 ? 4 : 8)
			: count;
		}
		break;

	    case 'q':
		done = TRUE;
		break;

	    case KEY_HOME:
	    case '^':
		jump = infile;
		break;

	    case KEY_END:
	    case '$':
		infile = max_lines;
		skip = MaxP();
		break;

	    case KEY_PPAGE:
	    case '\b':
	    case 'b':
		if (AtTop(infile)) {
		    beep();
		} else {
		    jump += NumP(count);
		}
		break;
	    case KEY_NPAGE:
	    case '\n':
	    case ' ':
	    case 'f':
		jump = 0;
		skip = count - 1;
		break;

	    case '<':
	    case CTL('L'):
		LeftOrRight(-shift * count);
		break;
	    case '>':
	    case CTL('R'):
		LeftOrRight(shift * count);
		break;

	    case KEY_LEFT:
	    case 'h':
		LeftOrRight(-count);
		break;
	    case KEY_DOWN:
	    case 'j':
		jump = NumP(1) - count;
		if ((infile - jump) > max_lines) {
		    skip = (-jump + NumP(1) - 1) / NumP(1);
		    jump = 0;
		}
		break;
	    case KEY_UP:
	    case 'k':
		if (AtTop(infile)) {
		    beep();
		} else {
		    jump += count;
		}
		break;
	    case KEY_RIGHT:
	    case 'l':
		LeftOrRight(count);
		break;

		/* move work-area marker */
	    case 'A':
		count = -count;
		jump -= count;
		/*FALLTHRU */
	    case 'a':
		markset(gbl, (unsigned) (mark_W + count));
		break;

	    case '/':
	    case '?':
	    case 'n':
	    case 'N':
		FindPattern(gbl, &infile, c);
		break;
	    default:
		beep();
	    }
	}
	FCLOSE(InFile);
	if (shown)
	    (void) reshow(gbl, (unsigned) inlist);
	showMARK(gbl->Xbase);

	showC(gbl);
    } else
	warn(gbl, name);
    in_dedtype = FALSE;
}
示例#7
0
static void
FindPattern(RING * gbl,
	    int *infile,
	    int key)
{
    int foo;
    char *s;
    int next, save = *infile;
    static DYN *text;
    static HIST *History;
    static int order;		/* saves last legal search order */
    static int ok_expr;

    if (key == '/' || key == '?') {

	dyn_init(&text, BUFSIZ);
	if (!(s = dlog_string(gbl, "Target: ", LINES - 1, &text, (DYN **) 0,
			      &History, EOS, BUFSIZ))
	    || !*s) {
	    UsePattern = FALSE;
	    return;
	}
	if (key == '/')
	    order = 1;
	if (key == '?')
	    order = -1;
	next = order;

    } else if (order && (s = dyn_string(text))) {
	next = (key == 'n') ? order : -order;
    } else {
	waitmsg("No previous regular expression");
	return;
    }

    if (ok_expr)
	OLD_REGEX(ToFind);
    if ((ok_expr = NEW_REGEX(ToFind, s)) != 0) {

	UsePattern = TRUE;
	if (SamePattern(s)) {
	    if (ispunct(key))
		return;
	} else {
	    if (next < 0) ;
	    else if (JumpBackwards(infile, NumP(1)) < 0)
		return;
	}

	if (next < 0) {
	    while (JumpBackwards(infile, NumP(2)) >= 0) {
		if (FoundPattern(infile))
		    return;
	    }
	} else {
	    while (!feof(InFile)) {
		if (FoundPattern(infile))
		    return;
	    }
	}

	*infile = TopOfPage(save, &foo);
	if (JumpToLine(*infile) >= 0)
	    (void) StartPage(infile, FALSE, &foo);
	waitmsg("Expression not found");

    } else {
	order = 0;
	UsePattern = FALSE;
	BAD_REGEX(ToFind);
	showC(gbl);
    }
}