Example #1
0
void GotoMark(WindowInfo *window, Widget w, char label, int extendSel)
{
    int index, oldStart, newStart, oldEnd, newEnd, cursorPos;
    selection *sel, *oldSel;
    
    /* look up the mark in the mark table */
    label = toupper(label);
    for (index=0; index<window->nMarks; index++) {
    	if (window->markTable[index].label == label)
   	    break;
    }
    if (index == window->nMarks) {
    	XBell(TheDisplay, 0);
    	return;
    }
    
    /* reselect marked the selection, and move the cursor to the marked pos */
    sel = &window->markTable[index].sel;
    oldSel = &window->buffer->primary;
    cursorPos = window->markTable[index].cursorPos;
    if (extendSel) {
	oldStart = oldSel->selected ? oldSel->start : TextGetCursorPos(w);
	oldEnd = oldSel->selected ? oldSel->end : TextGetCursorPos(w);
	newStart = sel->selected ? sel->start : cursorPos;
	newEnd = sel->selected ? sel->end : cursorPos;
	BufSelect(window->buffer, oldStart < newStart ? oldStart : newStart,
		oldEnd > newEnd ? oldEnd : newEnd);
    } else {
	if (sel->selected) {
    	    if (sel->rectangular)
    		BufRectSelect(window->buffer, sel->start, sel->end,
			sel->rectStart, sel->rectEnd);
    	    else
    		BufSelect(window->buffer, sel->start, sel->end);
	} else
    	    BufUnselect(window->buffer);
    }
    
    /* Move the window into a pleasing position relative to the selection
       or cursor.   MakeSelectionVisible is not great with multi-line
       selections, and here we will sometimes give it one.  And to set the
       cursor position without first using the less pleasing capability
       of the widget itself for bringing the cursor in to view, you have to
       first turn it off, set the position, then turn it back on. */
    XtVaSetValues(w, textNautoShowInsertPos, False, NULL);
    TextSetCursorPos(w, cursorPos);
    MakeSelectionVisible(window, window->lastFocus);
    XtVaSetValues(w, textNautoShowInsertPos, True, NULL);
}
Example #2
0
static void insert_into_string(TextStructure *cstext, char *s)
{
    int pos;
    
    pos = TextGetCursorPos(cstext);
    TextInsert(cstext, pos, s);
}
Example #3
0
static void gotoCB(Widget widget, WindowInfo *window, Atom *sel,
    	Atom *type, char *value, int *length, int *format)
{
     /* two integers and some space in between */
    char lineText[(TYPE_INT_STR_SIZE(int) * 2) + 5];
    int rc, lineNum, column, position, curCol;
    
    /* skip if we can't get the selection data, or it's obviously not a number */
    if (*type == XT_CONVERT_FAIL || value == NULL) {
    	XBell(TheDisplay, 0);
	return;
    }
    if (((size_t) *length) > sizeof(lineText) - 1) {
    	XBell(TheDisplay, 0);
	XtFree(value);
	return;
    }
    /* should be of type text??? */
    if (*format != 8) {
    	fprintf(stderr, "NEdit: Can't handle non 8-bit text\n");
    	XBell(TheDisplay, 0);
	XtFree(value);
	return;
    }
    strncpy(lineText, value, sizeof(lineText));
    lineText[sizeof(lineText) - 1] = '\0';
    
    rc = StringToLineAndCol(lineText, &lineNum, &column);
    XtFree(value);
    if (rc == -1) {
    	XBell(TheDisplay, 0);
	return;
    }

    /* User specified column, but not line number */
    if ( lineNum == -1 ) {
        position = TextGetCursorPos(widget);
        if (TextPosToLineAndCol(widget, position, &lineNum, &curCol) == False) {
            XBell(TheDisplay, 0);
            return;
        }
    }
    /* User didn't specify a column */
    else if ( column == -1 ) {
        SelectNumberedLine(window, lineNum);
        return;
    }

    position = TextLineAndColToPos(widget, lineNum, column );
    if ( position == -1 ) {
        XBell(TheDisplay, 0);
        return;
    }
    TextSetCursorPos(widget, position);
}
Example #4
0
/*
** Execute the line of text where the the insertion cursor is positioned
** as a shell command.
*/
void ExecCursorLine(WindowInfo *window, int fromMacro)
{
    char *cmdText;
    int left, right, insertPos;
    char *subsCommand, fullName[MAXPATHLEN];
    int pos, line, column;
    char lineNumber[11];

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }

    /* get all of the text on the line with the insert position */
    pos = TextGetCursorPos(window->lastFocus);
    if (!GetSimpleSelection(window->buffer, &left, &right)) {
	left = right = pos;
	left = BufStartOfLine(window->buffer, left);
	right = BufEndOfLine(window->buffer, right);
	insertPos = right;
    } else
    	insertPos = BufEndOfLine(window->buffer, right);
    cmdText = BufGetRange(window->buffer, left, right);
    BufUnsubstituteNullChars(cmdText, window->buffer);
    
    /* insert a newline after the entire line */
    BufInsert(window->buffer, insertPos, "\n");

    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(cmdText, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* issue the command */
    issueCommand(window, subsCommand, NULL, 0, 0, window->lastFocus, insertPos+1,
	    insertPos+1, fromMacro);
    free(subsCommand);
    XtFree(cmdText);
}
Example #5
0
static int fonttool_aac_cb(void *data)
{
    fonttool_ui *ui = (fonttool_ui *) data;
    if (ui->cstext_parent != NULL) {
        char *s = TextGetString(ui->cstext);
        int pos = TextGetCursorPos(ui->cstext);
        TextSetString(ui->cstext_parent, s);
        TextSetCursorPos(ui->cstext_parent, pos);
        xfree(s);
    }
    
    return RETURN_SUCCESS;
}
Example #6
0
/*
** Execute shell command "command", depositing the result at the current
** insert position or in the current selection if the window has a
** selection.
*/
void ExecShellCommand(WindowInfo *window, const char *command, int fromMacro)
{
    int left, right, flags = 0;
    char *subsCommand, fullName[MAXPATHLEN];
    int pos, line, column;
    char lineNumber[11];

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }
    
    /* get the selection or the insert position */
    pos = TextGetCursorPos(window->lastFocus);
    if (GetSimpleSelection(window->buffer, &left, &right))
    	flags = ACCUMULATE | REPLACE_SELECTION;
    else
    	left = right = pos;
    
    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(command, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* issue the command */
    issueCommand(window, subsCommand, NULL, 0, flags, window->lastFocus, left,
	    right, fromMacro);
    free(subsCommand);
}
Example #7
0
void AddMark(WindowInfo *window, Widget widget, char label)
{
    int index;
    
    /* look for a matching mark to re-use, or advance
       nMarks to create a new one */
    label = toupper(label);
    for (index=0; index<window->nMarks; index++) {
    	if (window->markTable[index].label == label)
   	    break;
    }
    if (index >= MAX_MARKS) {
    	fprintf(stderr, "no more marks allowed\n"); /* shouldn't happen */
    	return;
    }
    if (index == window->nMarks)
    	window->nMarks++;
    
    /* store the cursor location and selection position in the table */
    window->markTable[index].label = label;
    memcpy(&window->markTable[index].sel, &window->buffer->primary,
    	    sizeof(selection));
    window->markTable[index].cursorPos = TextGetCursorPos(widget);
}
Example #8
0
/*
** Do a shell command, with the options allowed to users (input source,
** output destination, save first and load after) in the shell commands
** menu.
*/
void DoShellMenuCmd(WindowInfo *window, const char *command,
        int input, int output,
	int outputReplacesInput, int saveFirst, int loadAfter, int fromMacro) 
{
    int flags = 0;
    char *text;
    char *subsCommand, fullName[MAXPATHLEN];
    int left, right, textLen;
    int pos, line, column;
    char lineNumber[11];
    WindowInfo *inWindow = window;
    Widget outWidget;

    /* Can't do two shell commands at once in the same window */
    if (window->shellCmdData != NULL) {
    	XBell(TheDisplay, 0);
    	return;
    }

    /* Substitute the current file name for % and the current line number
       for # in the shell command */
    strcpy(fullName, window->path);
    strcat(fullName, window->filename);
    pos = TextGetCursorPos(window->lastFocus);
    TextPosToLineAndCol(window->lastFocus, pos, &line, &column);
    sprintf(lineNumber, "%d", line);
    
    subsCommand = shellCommandSubstitutes(command, fullName, lineNumber);
    if (subsCommand == NULL)
    {
        DialogF(DF_ERR, window->shell, 1, "Shell Command",
                "Shell command is too long due to\n"
                "filename substitutions with '%%' or\n"
                "line number substitutions with '#'", "OK");
        return;
    }

    /* Get the command input as a text string.  If there is input, errors
      shouldn't be mixed in with output, so set flags to ERROR_DIALOGS */
    if (input == FROM_SELECTION) {
	text = BufGetSelectionText(window->buffer);
	if (*text == '\0') {
    	    XtFree(text);
            free(subsCommand);
    	    XBell(TheDisplay, 0);
    	    return;
    	}
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else if (input == FROM_WINDOW) {
	text = BufGetAll(window->buffer);
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else if (input == FROM_EITHER) {
	text = BufGetSelectionText(window->buffer);
	if (*text == '\0') {
	    XtFree(text);
	    text = BufGetAll(window->buffer);
    	}
    	flags |= ACCUMULATE | ERROR_DIALOGS;
    } else /* FROM_NONE */
    	text = NULL;
    
    /* If the buffer was substituting another character for ascii-nuls,
       put the nuls back in before exporting the text */
    if (text != NULL) {
	textLen = strlen(text);
	BufUnsubstituteNullChars(text, window->buffer);
    } else
	textLen = 0;
    
    /* Assign the output destination.  If output is to a new window,
       create it, and run the command from it instead of the current
       one, to free the current one from waiting for lengthy execution */
    if (output == TO_DIALOG) {
    	outWidget = NULL;
	flags |= OUTPUT_TO_DIALOG;
    	left = right = 0;
    } else if (output == TO_NEW_WINDOW) {
    	EditNewFile(GetPrefOpenInTab()?inWindow:NULL, NULL, False, NULL, window->path);
    	outWidget = WindowList->textArea;
	inWindow = WindowList;
    	left = right = 0;
	CheckCloseDim();
    } else { /* TO_SAME_WINDOW */
    	outWidget = window->lastFocus;
    	if (outputReplacesInput && input != FROM_NONE) {
    	    if (input == FROM_WINDOW) {
    		left = 0;
    		right = window->buffer->length;
    	    } else if (input == FROM_SELECTION) {
    	    	GetSimpleSelection(window->buffer, &left, &right);
	        flags |= ACCUMULATE | REPLACE_SELECTION;
    	    } else if (input == FROM_EITHER) {
    	    	if (GetSimpleSelection(window->buffer, &left, &right))
	            flags |= ACCUMULATE | REPLACE_SELECTION;
	        else {
	            left = 0;
	            right = window->buffer->length;
	        }
	    }
    	} else {
	    if (GetSimpleSelection(window->buffer, &left, &right))
	        flags |= ACCUMULATE | REPLACE_SELECTION;
	    else
    		left = right = TextGetCursorPos(window->lastFocus);
    	}
    }
    
    /* If the command requires the file be saved first, save it */
    if (saveFirst) {
    	if (!SaveWindow(window)) {
    	    if (input != FROM_NONE)
    		XtFree(text);
            free(subsCommand);
    	    return;
	}
    }
    
    /* If the command requires the file to be reloaded after execution, set
       a flag for issueCommand to deal with it when execution is complete */
    if (loadAfter)
    	flags |= RELOAD_FILE_AFTER;
    	
    /* issue the command */
    issueCommand(inWindow, subsCommand, text, textLen, flags, outWidget, left,
	    right, fromMacro);
    free(subsCommand);
}
Example #9
0
void create_fonttool(TextStructure *cstext_parent)
{
    static fonttool_ui *ui = NULL;
    
    if (ui == NULL) {
        ui = xmalloc(sizeof(fonttool_ui));
        memset(ui, 0, sizeof(fonttool_ui));
	
        ui->fonttool_panel = CreateDialog(app_shell, "Font tool");

        ui->font_select = CreateFontChoice(ui->fonttool_panel, "Font:");
        FormAddVChild(ui->fonttool_panel, ui->font_select->menu);
        
        ui->font_table = CreateTable("fontTable", ui->fonttool_panel,
                                     FONT_TOOL_ROWS, FONT_TOOL_COLS,
                                     8, 16);
        TableFontInit(ui->font_table);
        TableSetDefaultColWidth(ui->font_table, 2);
        TableSetDefaultColAlignment(ui->font_table, ALIGN_BEGINNING);
        TableUpdateVisibleRowsCols(ui->font_table);

        AddTableDrawCellCB(ui->font_table, DrawCB, ui);
        AddTableEnterCellCB(ui->font_table, EnterCB, ui);
        AddOptionChoiceCB(ui->font_select, update_fonttool_cb, ui);

        FormAddVChild(ui->fonttool_panel, ui->font_table);

        ui->cstext = CreateCSText(ui->fonttool_panel, "CString:");

        AddTextValidateCB(ui->cstext, EditStringCB, ui);
        
        ui->aac_buts = CreateAACDialog(ui->fonttool_panel,
            ui->cstext->form, fonttool_aac_cb, ui);

        FormFixateVChild(ui->cstext->form);
        
        update_fonttool_cb(NULL, 0, ui);
    }

    if (cstext_parent == ui->cstext) {
        /* avoid recursion */
        return;
    }
    
    ui->cstext_parent = cstext_parent;
    
    if (ui->cstext_parent == NULL) {
        TextSetString(ui->cstext, "");
        WidgetSetSensitive(ui->aac_buts[0], FALSE);
        WidgetSetSensitive(ui->aac_buts[1], FALSE);
    } else {
        char *s = TextGetString(ui->cstext_parent);
        int pos = TextGetCursorPos(ui->cstext_parent);
        TextSetString(ui->cstext, s);
        TextSetCursorPos(ui->cstext, pos);
        xfree(s);
        WidgetSetSensitive(ui->aac_buts[0], TRUE);
        WidgetSetSensitive(ui->aac_buts[1], TRUE);
    }
    
    DialogRaise(ui->fonttool_panel);
}