Пример #1
0
/**
 * @brief Slot called when a quest file of has been renamed.
 *
 * The corresponding tab is closed if any.
 *
 * @param old_path Old path of the file.
 * @param new_path New path after renaming.
 */
void EditorTabs::file_renamed(const QString& old_path, const QString& new_path) {

  Q_UNUSED(new_path);

  if (get_editor() == nullptr) {
    return;
  }

  Quest& quest = get_editor()->get_quest();
  ResourceType resource_type;
  QString language_id;

  QString path = old_path;
  if (quest.is_potential_resource_element(path, resource_type, language_id) &&
      resource_type == ResourceType::LANGUAGE) {

    int index = find_editor(quest.get_strings_path(language_id));
    if (index != -1) {
      remove_editor(index);
    }
    path = quest.get_dialogs_path(language_id);
  }

  int index = find_editor(path);
  if (index != -1) {
    remove_editor(index);
  }
}
Пример #2
0
/**
 * @brief Slot called when the current tab changes.
 * @param index Index of the new current tab.
 */
void EditorTabs::current_editor_changed(int /* index */) {

  Editor* editor = get_editor();
  if (editor == nullptr) {
    get_undo_group().setActiveStack(nullptr);
    emit can_cut_changed(false);
    emit can_copy_changed(false);
    emit can_paste_changed(false);
  }
  else {
    get_undo_group().setActiveStack(&editor->get_undo_stack());
    connect(editor, &Editor::can_cut_changed, [=](bool can_cut) {
      if (get_editor() == editor) {
        emit can_cut_changed(can_cut);
      }
    });
    connect(editor, &Editor::can_copy_changed, [=](bool can_copy) {
      if (get_editor() == editor) {
        emit can_copy_changed(can_copy);
      }
    });
    connect(editor, &Editor::can_paste_changed, [=](bool can_paste) {
      if (get_editor() == editor) {
        emit can_paste_changed(can_paste);
      }
    });
    emit can_cut_changed(editor->can_cut());
    emit can_copy_changed(editor->can_copy());
    emit can_paste_changed(editor->can_paste());
  }
}
Пример #3
0
/* EDTINIT -- Initialize the editor.
 */
void 
edtinit (void)
{
	register int	i;
	char 	editor[SZ_FNAME];	/* the name of the editor	 */

	/* See if the current editor is the one to use.  If not, get the
	 * editor.ed definitions.
	 */
	if (c_envgets ("editor", editor, SZ_FNAME) > 0)
	    if (strcmp (editor, command[EDITOR_ID].keystroke) != 0)
		get_editor (editor);

	/* Count the number of editor commands.
	 */
	numcommands = FIRST_CMD;
	for (i=FIRST_CMD;  command[i].cmd < NOMORE_COMMANDS;  i++)
	    numcommands++;

	/* Send the initial edit sequence (to enable keypad, if any).
	 */
	if (*(command[EDIT_INIT].escape) != '\0')
	    printf ("%s",command[EDIT_INIT].escape); 

	/* Enable transmission of the screen repaint sequence, to be returned
	 * by the terminal driver if the process is suspended and later
	 * resumed while in raw mode.
	 */
	for (i=FIRST_CMD;  command[i].cmd < NOMORE_COMMANDS;  i++)
	    if (command[i].cmd == REPAINT && strlen(command[i].escape)==1)
		c_fseti ((XINT)STDOUT, F_SETREDRAW, command[i].escape[0]);
}
Пример #4
0
/**
 * @brief Slot called when the user attempts to close a tab.
 * @param index Index of the tab to close.
 */
void EditorTabs::close_file_requested(int index) {

  Editor* editor = get_editor(index);
  if (editor != nullptr && editor->confirm_close()) {
    remove_editor(index);
  }
}
Пример #5
0
char *process_comment_option(const char *cmt)
{
	char *retval;

	assert(cmt);

	if (!strcmp(cmt, "-")) {
		/*
		 * Read comment from stdin.
		 */
		retval = read_from_fp(stdin);
		if (!retval) {
			myerror("Could not read data from stdin");
			return NULL;
		}
	} else if (!strcmp(cmt, "--")) {
		/*
		 * Open the user's favourite editor and edit the comment there 
		 * in a temporary file.
		 */
		char *e;

		e = get_editor();
		if (!e)
			return NULL;
		retval = read_from_editor(e);
		free(e);
		if (!retval)
			return NULL;
	} else {
		/*
		 * The comment was stored as a plain string in the -c/--comment 
		 * argument.
		 */
		retval = strdup(cmt);
		if (!retval) {
			myerror("%s: Cannot allocate memory for comment, "
			        "strdup() failed");
			return NULL;
		}
	}
	if (!valid_xml_chars(retval)) {
		fprintf(stderr, "%s: Comment contains illegal characters or "
		                "is not valid UTF-8\n", progname);
		free(retval);
		return NULL;
	}

	/* fixme: This is how it's done in the Perl version. I'm not sure if 
	 * it's an ok thing to do, even though it looks nice in the log files 
	 * and has worked great for years. Maybe this behaviour should be 
	 * changed when the C version passes all tests in suuid.t .
	 */
	trim_str_front(retval);
	trim_str_end(retval);

	return retval;
}
Пример #6
0
/**
 * @brief Returns the editor currently open if any
 * @return The current editor.
 * Returns nullptr if there is no tab.
 */
Editor* EditorTabs::get_editor() {

  int index = currentIndex();
  if (index == -1) {
    return nullptr;
  }

  return get_editor(index);
}
Пример #7
0
/**
 * @brief Slot called when the is-modified state of the current tab has changed.
 * @param clean @c true if the file is now clean, @c false if it is now
 * modified.
 */
void EditorTabs::modification_state_changed(bool clean) {

  if (count() == 0) {
    return;
  }

  QString title = get_editor()->get_title();
  if (!clean) {
    title += '*';
  }
  setTabText(currentIndex(), title);
}
Пример #8
0
/**
 * @brief Function called when the user wants to close all editors.
 *
 * The user can save files if necessary.
 *
 * @return @c false to cancel the closing operation.
 */
bool EditorTabs::confirm_close() {

  for (int i = 0; i < count(); ++i) {

    Editor* editor = get_editor(i);
    if (!editor->confirm_close()) {
      return false;
    }
  }

  return true;
}
Пример #9
0
char *
ot_editor_prompt (OstreeRepo *repo,
                  const char *input,
                  GCancellable *cancellable,
                  GError **error)
{
  glnx_unref_object GSubprocess *proc = NULL;
  g_autoptr(GFile) file = NULL;
  g_autoptr(GFileIOStream) io = NULL;
  GOutputStream *output;
  const char *editor;
  char *ret = NULL;
  g_autofree char *args = NULL;

  editor = get_editor ();
  if (editor == NULL)
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Terminal is dumb, but EDITOR unset");
      goto out;
    }

  file = g_file_new_tmp (NULL, &io, error);
  if (file == NULL)
    goto out;

  output = g_io_stream_get_output_stream (G_IO_STREAM (io));
  if (!g_output_stream_write_all (output, input, strlen (input), NULL, cancellable, error) ||
      !g_io_stream_close (G_IO_STREAM (io), cancellable, error))
    goto out;

  {
    g_autofree char *quoted_file = g_shell_quote (gs_file_get_path_cached (file));
    args = g_strconcat (editor, " ", quoted_file, NULL);
  }

  proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, 
                           "/bin/sh", "-c", args, NULL);

  if (!g_subprocess_wait_check (proc, cancellable, error))
    {
      g_prefix_error (error, "There was a problem with the editor '%s'", editor);
      goto out;
    }

  ret = glnx_file_get_contents_utf8_at (AT_FDCWD, gs_file_get_path_cached (file), NULL,
                                        cancellable, error);

out:
  if (file)
    (void )g_file_delete (file, NULL, NULL);
  return ret;
}
Пример #10
0
char* interact_edit(TALLOC_CTX* mem_ctx, const char* str) {
	char fname[] = "/tmp/net_idmap_check.XXXXXX";
	char buf[128];
	char* ret = NULL;
	FILE* file;
	mode_t mask;
	int fd;

	mask = umask(S_IRWXO | S_IRWXG);
	fd = mkstemp(fname);
	umask(mask);
	if (fd == -1) {
		DEBUG(0, ("failed to mkstemp %s: %s\n", fname,
			  strerror(errno)));
		return NULL;
	}

	file  = fdopen(fd, "w");
	if (!file) {
		DEBUG(0, ("failed to open %s for writing: %s\n", fname,
			  strerror(errno)));
		close(fd);
		unlink(fname);
		return NULL;
	}

	fprintf(file, "%s", str);
	fclose(file);

	snprintf(buf, sizeof(buf), "%s %s\n", get_editor(), fname);
	if (system(buf) != 0) {
		DEBUG(0, ("failed to start editor %s: %s\n", buf,
			  strerror(errno)));
		unlink(fname);
		return NULL;
	}

	file = fopen(fname, "r");
	if (!file) {
		DEBUG(0, ("failed to open %s for reading: %s\n", fname,
			  strerror(errno)));
		unlink(fname);
		return NULL;
	}
	while ( fgets(buf, sizeof(buf), file) ) {
		ret = talloc_strdup_append(ret, buf);
	}
	fclose(file);
	unlink(fname);

	return talloc_steal(mem_ctx, ret);
}
Пример #11
0
/**
 * @brief Closes the editor at the specified index without confirmation.
 * @param index An editor index.
 */
void EditorTabs::remove_editor(int index) {

  Editor* editor = get_editor(index);
  QString path = editor->get_file_path();

  undo_group->removeStack(&editor->get_undo_stack());

  // Tell the quest that this file is now closed.
  editor->get_quest().set_path_open(path, false);

  editors.remove(path);
  removeTab(index);

}
Пример #12
0
/**
 * @brief Slot called when the user attempts to save a file.
 * @param index Index of the tab to save.
 */
void EditorTabs::save_file_requested(int index) {

  Editor* editor = get_editor(index);
  if (editor == nullptr) {
    return;
  }

  try {
    editor->save();
    editor->get_undo_stack().setClean();
  }
  catch (const EditorException& ex) {
    ex.show_dialog();
  }
}
Пример #13
0
/* HOST_EDITOR -- Return a pointer to the command string to be sent to the
 * host system to run an editor, given the user name for the editor.
 */
char *
host_editor (char *editor)
{
	get_editor (editor);
	return (ed_editorcmd);
}
Пример #14
0
/**
 * @brief Reloads settings of all editors.
 */
void EditorTabs::reload_settings() {

  for (int i = 0; i < count(); ++i) {
    get_editor(i)->reload_settings();
  }
}