Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preview for files in projects #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BafDyce
Copy link

@BafDyce BafDyce commented Mar 18, 2016

This patch aims to fix #13.
When opening a project, each file-editor receives a pointer to the editor
instance of the root file. After saving a non-root file of a project, Gummi will
compile the pdf as if the root file was changed.

Note: This doesn't provide a live-preview for non-root files, but at least it
shows the compiled pdf, without having to switch to the root-file editor.

I did test it a bit (on Linux only though), however since I didn't know the
codebase at all before doing the change, I don't know whether I missed
something.

This patch aims to fix alexandervdm#13.
When opening a project, each file-editor receives a pointer to the editor
instance of the root file. After saving a non-root file of a project, Gummi will
compile the pdf as if the root file was changed.

Note: This doesn't provide a live-preview for non-root files, but at least it
shows the compiled pdf, without having to switch to the root-file editor.

I did test it a bit (on Linux only though), however since I didn't know the
codebase at all before doing the change, I don't know whether I missed
something.
@BafDyce
Copy link
Author

BafDyce commented Apr 28, 2016

Note: Today I discovered that this does not work yet when you just created the project. However, after restarting Gummi and opening the project via "Project -> Open Project" the preview functionality works as intended.
As soon as I have time to investigate that further, I'll fix that.

@tchotchke87
Copy link

Would it be possible for you to produce a version of this patch that applies to the GTK3 port of Gummi (non-official)?

This is probably not where I should ask this, but I'm new to github. How do I apply this patch using Ubuntu to the version of gummi I can download from here?

@BafDyce
Copy link
Author

BafDyce commented Jan 28, 2017

I'm quite busy these days, however I'll try to find some time to look into this in the next few days. I don't know how much of the codebase changed, so it's either directly applicable or I need to rewrite some stuff.

I'll let you know once I know more.

@@ -174,7 +174,7 @@ void on_projfile_add_clicked (GtkWidget* widget, void* user) {
int amount = projectgui_list_projfiles (gummi->project->projfile);
gtk_label_set_text (gui->projectgui->proj_nroffiles,
g_strdup_printf("%d", amount));
gui_open_file (selected);
gui_open_file (selected, NULL, NULL);
Copy link

@neoh4x0r neoh4x0r Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root/created editor is not set -- when a new file is added.

This would cause the preview (for newly added files) to use the old behavior of compiling/previewing the current document (instead of the root).

The rooteditor is only set when the project files are loaded (but not when created/added).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would cause the preview to use the old behavior of attemping to compile the current editor/document.

Copy link

@neoh4x0r neoh4x0r Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following works when the project is newly created.

  1. get all editors (and find the one that is the root, generally the first one)
  2. open the added file, and set the created editor's project file
void on_projfile_add_clicked (GtkWidget* widget, void* user) {
	gboolean status = FALSE;
	gchar* selected = NULL;
	gint rootpos;
	GuEditor* rootEditor = NULL;
	selected = get_open_filename (TYPE_LATEX);
	
	if (selected) {
		if (project_add_document (gummi->project->projfile, selected)) {
			int amount = projectgui_list_projfiles (gummi->project->projfile);
			gtk_label_set_text (gui->projectgui->proj_nroffiles,
								g_strdup_printf("%d", amount));			
			
			GList* editor_list = gummi_get_all_editors();
			gint length = g_list_length (editor_list);
			
			for (int i=0; i<length;i++) {
				GuEditor* editor = g_list_nth_data (editor_list, i);
				if(strcmp(editor->filename, gummi->project->rootfile) == 0) {
					rootEditor = editor;
					fprintf(stderr,"Found rootEditor at pos:%d\n", i);
					GuEditor* createdEditor = NULL;
					gui_open_file (selected, rootEditor, &createdEditor);
					createdEditor->projfile = gummi->project->projfile;
					rootpos = i;
					status = TRUE;
					break;
				}
			}
		}
		else {
			statusbar_set_message ("Error adding document to the project..");
		}
	}
	if (status == TRUE) projectgui_set_rootfile (rootpos);
	g_free (selected);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gummi tries to compile currently open document, instead of "home" file of project
3 participants