[latexila] project_id: some code clean-up
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] project_id: some code clean-up
- Date: Thu, 23 Jun 2011 00:02:04 +0000 (UTC)
commit 60ad5ddd48295e1ceec07e753712fd34604afe41
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Wed Jun 22 23:03:11 2011 +0200
project_id: some code clean-up
src/clean_build_files.vala | 8 +++-----
src/document.vala | 13 +++++++++----
src/document_tab.vala | 35 +++++++++++++++--------------------
src/documents_panel.vala | 2 +-
src/file_browser.vala | 5 +++--
src/main.vala | 2 +-
src/main_window.vala | 7 +++----
7 files changed, 35 insertions(+), 37 deletions(-)
---
diff --git a/src/clean_build_files.vala b/src/clean_build_files.vala
index 877dc51..66e2151 100644
--- a/src/clean_build_files.vala
+++ b/src/clean_build_files.vala
@@ -56,14 +56,12 @@ public class CleanBuildFiles : GLib.Object
Gee.ArrayList<File> files_to_delete;
File directory;
+ Project? project = _doc.get_project ();
+
// the document is part of a project
- if (_doc.project_id != -1)
+ if (project != null)
{
- Project? project = Projects.get_default ().get (_doc.project_id);
- return_val_if_fail (project != null, false);
-
directory = project.directory;
-
files_to_delete = get_build_files_in_directory (directory);
}
else
diff --git a/src/document.vala b/src/document.vala
index 45e8f4a..f2c0bc5 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -502,15 +502,20 @@ public class Document : Gtk.SourceBuffer
return ret;
}
+ public Project? get_project ()
+ {
+ if (project_id == -1)
+ return null;
+
+ return Projects.get_default ().get (project_id);
+ }
+
public File? get_main_file ()
{
if (location == null)
return null;
- if (project_id == -1)
- return location;
-
- Project? project = Projects.get_default ().get (project_id);
+ Project? project = get_project ();
if (project == null)
return location;
diff --git a/src/document_tab.vala b/src/document_tab.vala
index 4c08713..7a64234 100644
--- a/src/document_tab.vala
+++ b/src/document_tab.vala
@@ -218,32 +218,27 @@ public class DocumentTab : VBox
private void update_label_tooltip ()
{
if (document.location == null)
- _label.tooltip_markup = "";
- else
{
- _label.tooltip_markup = document.get_uri_for_display ();
-
- if (document.project_id != -1)
- {
- Project? project = Projects.get_default ().get (document.project_id);
- if (project == null)
- return;
-
- if (project.main_file.equal (document.location))
- _label.tooltip_markup += "\n<b>" + _("Main File") + "</b>";
- else
- _label.tooltip_markup += "\n<b>" + _("Main File:") + "</b> "
- + get_main_file_relative_path ();
- }
+ _label.tooltip_markup = "";
+ return;
}
+
+ _label.tooltip_markup = document.get_uri_for_display ();
+
+ Project? project = document.get_project ();
+ if (project == null)
+ return;
+
+ if (project.main_file.equal (document.location))
+ _label.tooltip_markup += "\n<b>" + _("Main File") + "</b>";
+ else
+ _label.tooltip_markup += "\n<b>" + _("Main File:") + "</b> "
+ + get_main_file_relative_path ();
}
private string? get_main_file_relative_path ()
{
- if (document.project_id == -1)
- return null;
-
- Project? project = Projects.get_default ().get (document.project_id);
+ Project? project = document.get_project ();
if (project == null)
return null;
diff --git a/src/documents_panel.vala b/src/documents_panel.vala
index 2152e44..e668d2e 100644
--- a/src/documents_panel.vala
+++ b/src/documents_panel.vala
@@ -1,7 +1,7 @@
/*
* This file is part of LaTeXila.
*
- * Copyright  2010 SÃbastien Wilmet
+ * Copyright  2010-2011 SÃbastien Wilmet
*
* LaTeXila is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/file_browser.vala b/src/file_browser.vala
index fe4586f..8bf3d42 100644
--- a/src/file_browser.vala
+++ b/src/file_browser.vala
@@ -296,9 +296,11 @@ public class FileBrowser : VBox
// displayed.
public void refresh_for_document (Document doc)
{
+ Project? project = doc.get_project ();
+
// If the document is not part of a project, refresh only if the document's
// directory is the same as the current directory.
- if (doc.project_id == -1)
+ if (project == null)
{
if (doc.location != null
&& current_directory.equal (doc.location.get_parent ()))
@@ -310,7 +312,6 @@ public class FileBrowser : VBox
}
// If a project is defined, refresh if the current dir is part of the project.
- Project? project = Projects.get_default ().get (doc.project_id);
File project_dir = project.directory;
if (current_directory.equal (project_dir)
diff --git a/src/main.vala b/src/main.vala
index f849a1c..cda4f6b 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -1,7 +1,7 @@
/*
* This file is part of LaTeXila.
*
- * Copyright  2010 SÃbastien Wilmet
+ * Copyright  2010-2011 SÃbastien Wilmet
*
* LaTeXila is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/src/main_window.vala b/src/main_window.vala
index a27f539..beef23b 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -1222,9 +1222,9 @@ public class MainWindow : Window
// save the document if it's a compilation (e.g. with rubber)
if (tool.compilation)
{
- int num = active_document.project_id;
+ int project_id = active_document.project_id;
- if (num == -1)
+ if (project_id == -1)
active_document.save ();
// save all the documents belonging to the project
@@ -1233,7 +1233,7 @@ public class MainWindow : Window
List<Document> docs = Application.get_default ().get_documents ();
foreach (Document doc in docs)
{
- if (doc.project_id == num)
+ if (doc.project_id == project_id)
doc.save ();
}
}
@@ -1424,7 +1424,6 @@ public class MainWindow : Window
public void update_config_project_sensitivity ()
{
- /* configure current project: sensitivity */
Gtk.Action action = action_group.get_action ("ProjectsConfigCurrent");
action.set_sensitive (active_tab != null && active_document.project_id != -1);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]