[latexila] Document compilation: set tmp location if file not saved
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Document compilation: set tmp location if file not saved
- Date: Sat, 3 Mar 2012 23:36:06 +0000 (UTC)
commit 7b9e0c0106fa5cbfd967ed6c65385808778e92cd
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Sun Feb 5 16:44:51 2012 +0100
Document compilation: set tmp location if file not saved
glib.vapi is needed because g_dir_make_tmp() is missing in the VAPI:
https://bugzilla.gnome.org/show_bug.cgi?id=669416
When this bug is fixed, glib.vapi can be removed and the code adapted.
TODO | 20 +++-----------------
src/document.vala | 22 ++++++++++++++++++++++
src/main_window.vala | 43 ++++++++++++++++++++++++++++++++-----------
vapi/glib.vapi | 8 ++++++++
4 files changed, 65 insertions(+), 28 deletions(-)
---
diff --git a/TODO b/TODO
index 81eaf64..7a98dfa 100644
--- a/TODO
+++ b/TODO
@@ -6,29 +6,15 @@ See also the Roadmap:
The Roadmap is less detailed, but have a long-term view.
The TODO is more detailed, but focus more on the short-term.
-LaTeXila 2.4
-============
-
-- Possibility to compile an unsaved LaTeX file, to test easily some code without
- the need to save it in a temporary file that we have to delete just after the test,
- and that we don't delete anyway.
-
- The unsaved file would simply be saved somewhere in /tmp/.
-
-- Improve completion:
- - complete placeholders (\ref, \cite, ...)
- (take into account all *.tex, *.bib, ... files of the project)
-
-
-LaTeXila â 2.4
-==============
-
- Migrate to GTK+ 3 [in progress]
- It's not a high priority, since it's not a big issue for GNOME 3 users,
but it would be nice. The problem is that it involves a lot of work,
more than expected. See the branch gnome-3.
- Improve completion:
+ - complete placeholders (\ref, \cite, ...)
+ (take into account all *.tex, *.bib, ... files of the project)
+
- show details by default (now we have to click on the button to see
the details)
diff --git a/src/document.vala b/src/document.vala
index 96cf73b..114ff68 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -587,6 +587,28 @@ public class Document : Gtk.SourceBuffer
return _structure;
}
+ public bool set_tmp_location ()
+ {
+ /* Create a temporary directory (most probably in /tmp/) */
+ string template = "latexila-XXXXXX";
+ string tmp_dir;
+
+ try
+ {
+ tmp_dir = MyDirUtils.make_tmp (template);
+ }
+ catch (FileError e)
+ {
+ warning ("Impossible to create temporary directory: %s", e.message);
+ return false;
+ }
+
+ /* Set the location as 'tmp.tex' in the temporary directory */
+ this.location = File.new_for_path (Path.build_filename (tmp_dir, "tmp.tex"));
+
+ return true;
+ }
+
/***************
* SEARCH
diff --git a/src/main_window.vala b/src/main_window.vala
index 51f4936..7c5c51a 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -1226,7 +1226,6 @@ public class MainWindow : Window
private void build_tools_menu_activate (Gtk.Action action)
{
return_if_fail (active_tab != null);
- return_if_fail (active_document.location != null);
string[] _name = action.name.split ("_");
int tool_index = int.parse (_name[1]);
@@ -1234,11 +1233,20 @@ public class MainWindow : Window
BuildTool? tool = BuildTools.get_default ()[tool_index];
return_if_fail (tool != null);
+ if (! tool.compilation)
+ return_if_fail (active_document.location != null);
+
build_view.show ();
// save the document if it's a compilation (e.g. with rubber)
if (tool.compilation)
{
+ if (active_document.location == null)
+ {
+ bool tmp_location_set = active_document.set_tmp_location ();
+ return_if_fail (tmp_location_set);
+ }
+
int project_id = active_document.project_id;
if (project_id == -1)
@@ -1406,7 +1414,7 @@ public class MainWindow : Window
Gtk.Action clean_action = action_group.get_action ("BuildClean");
Gtk.Action view_log_action = action_group.get_action ("BuildViewLog");
- if (active_tab == null || active_document.get_main_file () == null)
+ if (active_tab == null)
{
build_tools_action_group.set_sensitive (false);
clean_action.set_sensitive (false);
@@ -1417,28 +1425,41 @@ public class MainWindow : Window
// we must set the _action group_ sensitive and then set the sensitivity for each
// action of the action group
build_tools_action_group.set_sensitive (true);
+
bool is_tex = active_document.is_main_file_a_tex_file ();
clean_action.set_sensitive (is_tex);
view_log_action.set_sensitive (is_tex);
- string path = active_document.get_main_file ().get_parse_name ();
- string ext = Utils.get_extension (path);
+ bool unsaved_doc = active_document.location == null;
+ string ext = "";
+ if (! unsaved_doc)
+ {
+ string path = active_document.get_main_file ().get_parse_name ();
+ ext = Utils.get_extension (path);
+ }
- int i = 0;
+ int tool_num = 0;
foreach (BuildTool tool in BuildTools.get_default ())
{
if (! tool.show)
{
- i++;
+ tool_num++;
continue;
}
- string[] extensions = tool.extensions.split (" ");
- bool sensitive = tool.extensions.length == 0 || ext in extensions;
+ Gtk.Action action =
+ build_tools_action_group.get_action (@"BuildTool_$tool_num");
- Gtk.Action action = build_tools_action_group.get_action (@"BuildTool_$i");
- action.set_sensitive (sensitive);
- i++;
+ if (unsaved_doc)
+ action.set_sensitive (tool.compilation);
+ else
+ {
+ string[] extensions = tool.extensions.split (" ");
+ bool sensitive = tool.extensions.length == 0 || ext in extensions;
+ action.set_sensitive (sensitive);
+ }
+
+ tool_num++;
}
}
diff --git a/vapi/glib.vapi b/vapi/glib.vapi
new file mode 100644
index 0000000..a548769
--- /dev/null
+++ b/vapi/glib.vapi
@@ -0,0 +1,8 @@
+namespace GLib
+{
+ namespace MyDirUtils
+ {
+ [CCode (cname = "g_dir_make_tmp", cheader_filename = "glib.h,glib/gstdio.h")]
+ public static string make_tmp (string tmpl) throws FileError;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]