示例#1
0
void handle_file_ide (gchar *filename, gint line)
{
  if (! filename || ! cur_tea_project)
     return;
 
  gchar *cmd = g_strconcat (cur_tea_project->dir_source, filename, NULL);
 
  gint i = get_n_page_by_filename (cmd);

  if (i != -1)
     {
      gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook1), i);
      if (get_page_text ())
          doc_select_line (cur_text_doc, line); 
      return;
     } 

  if (! g_file_test (cmd, G_FILE_TEST_EXISTS))
     return;
 
  else
      {
       if (! get_page_text() )
          cur_settings.selected_enc = ch_str (cur_settings.selected_enc, "UTF-8");
       else
           cur_settings.selected_enc = ch_str (cur_settings.selected_enc, cur_text_doc->encoding);

       cur_text_doc = open_file_std (cmd);
       doc_select_line (cur_text_doc, line);
      }
}
示例#2
0
/**
 * msg_queue_check:
 *
 * checks the queue for any messages
 * this is called by the master program, usually by gtk_timeout_add()
 * the messages it will listen to are the types:
 * - MSG_QUEUE_ASK_ALIVE - we should respond with a type MSG_QUEUE_SEND_ALIVE
 * - MSG_QUEUE_OPENFILE - open a filename
 * - MSG_QUEUE_OPENPROJECT - open a filename as project
 * - MSG_QUEUE_OPENNEWWIN - open a new window
 */
static gboolean msg_queue_check(gint started_by_gtk_timeout)
{
	struct msgbuf {
		long mtype;
		char mtext[MSQ_QUEUE_SIZE];
	} msgp;
	gint retval;
	if (main_v->bfwinlist == NULL || BFWIN(main_v->bfwinlist->data)->documentlist == NULL) {
		DEBUG_MSG("msg_queue_check, no documentlist yet, so we do not continue\n");
		return TRUE;
	}

	if (msg_queue.msgid == -1) {
		return FALSE;
	}
	retval = msgrcv(msg_queue.msgid, &msgp, MSQ_QUEUE_SIZE, -MSG_QUEUE_OPENFILE, IPC_NOWAIT);
	if (retval != -1) {
		DEBUG_MSG("msg_queue_check, found type %ld\n", msgp.mtype);
		if (msgp.mtype == MSG_QUEUE_ASK_ALIVE) {
			struct small_msgbuf {
				long mtype;
				char mtext[MSQ_QUEUE_SMALL_SIZE];
			} small_msgp;
			DEBUG_MSG("msg_queue_check, a keepalive is asked from %s, sending!\n", msgp.mtext);
			small_msgp.mtype = MSG_QUEUE_SEND_ALIVE;
			strncpy(small_msgp.mtext, msgp.mtext, MSQ_QUEUE_SMALL_SIZE - 1);
			msgsnd(msg_queue.msgid, (void *) &small_msgp, MSQ_QUEUE_SMALL_SIZE * sizeof(char),
				   IPC_NOWAIT);
		} else if (msgp.mtype == MSG_QUEUE_OPENFILE) {
			GList *lastlist = g_list_last(main_v->bfwinlist);
			DEBUG_MSG("msg_queue_check, a filename %s is received\n", msgp.mtext);
			Tdocument *tmpdoc = doc_new_with_file(BFWIN(lastlist->data),msgp.mtext, FALSE, TRUE);
			if (!tmpdoc) {
				msg_queue.file_error_list = g_list_append(msg_queue.file_error_list, g_strdup(msgp.mtext));
			} else if (msg_queue.linenumber >=0) {
				doc_activate( tmpdoc );
				doc_select_line( tmpdoc, msg_queue.linenumber, TRUE );
				gtk_widget_grab_focus( GTK_WIDGET( tmpdoc->view ) );
			}
			msg_queue_check(0); /* call myself again, there may have been multiple files */
			if (started_by_gtk_timeout) {
				if (msg_queue.file_error_list) {
					gchar *message, *tmp;
					tmp = stringlist_to_string(msg_queue.file_error_list, "\n");
					free_stringlist(msg_queue.file_error_list);
					msg_queue.file_error_list = NULL;
					message = g_strconcat(_("These files were not opened:\n"), tmp, NULL);
					g_free(tmp);
					warning_dialog(BFWIN(main_v->bfwinlist->data)->main_window,_("Unable to open file(s)\n"), message);
					g_free(message);
				}
/*				gtk_notebook_set_page(GTK_NOTEBOOK(main_v->notebook),g_list_length(main_v->documentlist) - 1);
				notebook_changed(-1);*/
			}
		} else if (msgp.mtype == MSG_QUEUE_OPENPROJECT) {
			GList *lastlist = g_list_last(main_v->bfwinlist);
			DEBUG_MSG("msg_queue_check, a project %s is received\n", msgp.mtext);
			project_open_from_file(BFWIN(lastlist->data), msgp.mtext, msg_queue.linenumber);
			msg_queue_check(0);	/* call myself again, there may have been multiple projects */
		} else if (msgp.mtype == MSG_QUEUE_OPENNEWWIN) {
			/* now check if this is indeed send by another process
			if the message queue was dead during the startup of this process,
			it might be started by this very process */
			int otherpid = atoi(msgp.mtext);
			DEBUG_MSG("msg_queue_check, a new window is requested by PID=%d\n",otherpid);
			if (otherpid != (int) getpid()) {
				DEBUG_MSG("msg_queue_check, the PID is not ours, opening new window\n");
				gui_new_window(NULL, NULL);
			}
		} else if (msgp.mtype == MSG_QUEUE_SETLINE) {
			msg_queue.linenumber = strtoul(msgp.mtext, NULL,10);
		}
#ifdef DEBUG
		 else {
		 	DEBUG_MSG("msg_queue_check, unknown message queue type %ld\n", msgp.mtype);
		 }
#endif
		
	} else {
#ifdef MSG_QUEUE_DEBUG
		DEBUG_MSG("msg_queue_check, found errno(%d)=%s\n", errno, g_strerror(errno));
#endif
	/*
	43 = Identifier removed
	*/
		if (errno == 22 || errno == 43) {
			DEBUG_MSG("msg_queue_check, re-opening message queue ?!?!?\n");
			/* the msg_queue was removed !?!?! */
			if (msg_queue_open()) {
				DEBUG_MSG("msg_queue_check, another process has opened the message_queue, stopping server\n");
				msg_queue.server = FALSE;
				return FALSE;
			}
		}
	}
	return TRUE;
}