[latexila] Avoid grab_focus warning



commit d5c7185a729461796568a2c353ac84430eb834df
Author: Sébastien Wilmet <swilmet src gnome org>
Date:   Sun Jun 12 21:53:17 2011 +0200

    Avoid grab_focus warning

 src/document_tab.vala  |   16 +++++++------
 src/document_view.vala |    6 ++--
 src/main_window.vala   |   55 ++++++++++++++++++++++++-----------------------
 src/search.vala        |   40 +++++++++++++++++++---------------
 4 files changed, 62 insertions(+), 55 deletions(-)
---
diff --git a/src/document_tab.vala b/src/document_tab.vala
index a9cc518..9aa7bfb 100644
--- a/src/document_tab.vala
+++ b/src/document_tab.vala
@@ -131,7 +131,7 @@ public class DocumentTab : VBox
     private void initialize ()
     {
         // usefull when moving a tab to a new window
-        var reparent = document.tab != null;
+        bool reparent = document.tab != null;
 
         document.tab = this;
 
@@ -153,7 +153,7 @@ public class DocumentTab : VBox
         view.focus_in_event.connect (view_focused_in);
 
         // with a scrollbar
-        var sw = new ScrolledWindow (null, null);
+        ScrolledWindow sw = new ScrolledWindow (null, null);
         sw.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
 
         if (reparent)
@@ -168,7 +168,7 @@ public class DocumentTab : VBox
 
         update_label_text ();
 
-        var close_button = new Button ();
+        Button close_button = new Button ();
         close_button.relief = ReliefStyle.NONE;
         close_button.focus_on_click = false;
         close_button.name = "my-close-button";
@@ -185,7 +185,8 @@ public class DocumentTab : VBox
 
 
         /* auto save */
-        var settings = new GLib.Settings ("org.gnome.latexila.preferences.editor");
+        GLib.Settings settings =
+            new GLib.Settings ("org.gnome.latexila.preferences.editor");
         auto_save = settings.get_boolean ("auto-save");
         uint tmp;
         settings.get ("auto-save-interval", "u", out tmp);
@@ -203,7 +204,7 @@ public class DocumentTab : VBox
     public TabInfoBar add_message (string primary_msg, string secondary_msg,
         MessageType msg_type)
     {
-        var infobar = new TabInfoBar (primary_msg, secondary_msg, msg_type);
+        TabInfoBar infobar = new TabInfoBar (primary_msg, secondary_msg, msg_type);
         pack_start (infobar, false, false, 0);
         return infobar;
     }
@@ -333,7 +334,7 @@ public class DocumentTab : VBox
         {
             ask_if_externally_modified = true;
 
-            var primary_msg = _("The file %s changed on disk.")
+            string primary_msg = _("The file %s changed on disk.")
                 .printf (document.location.get_parse_name ());
 
             string secondary_msg;
@@ -342,7 +343,8 @@ public class DocumentTab : VBox
             else
                 secondary_msg = _("Do you want to reload the file?");
 
-            var infobar = add_message (primary_msg, secondary_msg, MessageType.WARNING);
+            TabInfoBar infobar = add_message (primary_msg, secondary_msg,
+                MessageType.WARNING);
             infobar.add_stock_button_with_text (_("Reload"), Stock.REFRESH,
                 ResponseType.OK);
             infobar.add_button (Stock.CANCEL, ResponseType.CANCEL);
diff --git a/src/document_view.vala b/src/document_view.vala
index 8d56e3e..a21c337 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -89,7 +89,7 @@ public class DocumentView : Gtk.SourceView
     public void cut_selection ()
     {
         return_if_fail (this.buffer != null);
-        var clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
+        Clipboard clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
         this.buffer.cut_clipboard (clipboard, ! ((Document) this.buffer).readonly);
         scroll_to_cursor (SCROLL_MARGIN);
         grab_focus ();
@@ -98,7 +98,7 @@ public class DocumentView : Gtk.SourceView
     public void copy_selection ()
     {
         return_if_fail (this.buffer != null);
-        var clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
+        Clipboard clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
         this.buffer.copy_clipboard (clipboard);
         grab_focus ();
     }
@@ -106,7 +106,7 @@ public class DocumentView : Gtk.SourceView
     public void my_paste_clipboard ()
     {
         return_if_fail (this.buffer != null);
-        var clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
+        Clipboard clipboard = get_clipboard (Gdk.SELECTION_CLIPBOARD);
         this.buffer.paste_clipboard (clipboard, null,
             ! ((Document) this.buffer).readonly);
         scroll_to_cursor (SCROLL_MARGIN);
diff --git a/src/main_window.vala b/src/main_window.vala
index a68b79d..72666ad 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -651,35 +651,36 @@ public class MainWindow : Window
         {
             foreach (Document doc in w.get_documents ())
             {
-                if (doc.location != null && location.equal (doc.location))
+                if (doc.location == null || ! location.equal (doc.location))
+                    continue;
+
+                /* the document is already opened in this window */
+                if (this == w)
                 {
-                    /* the document is already opened in this window */
-                    if (this == w)
-                    {
-                        if (jump_to)
-                            active_tab = doc.tab;
-                        return doc.tab;
-                    }
-
-                    /* the document is already opened in another window */
-                    DocumentTab tab = create_tab_from_location (location, jump_to);
-                    tab.document.readonly = true;
-                    string primary_msg = _("This file (%s) is already opened in another LaTeXila window.")
-                        .printf (location.get_parse_name ());
-                    string secondary_msg = _("LaTeXila opened this instance of the file in a non-editable way. Do you want to edit it anyway?");
-                    InfoBar infobar = tab.add_message (primary_msg, secondary_msg,
-                        MessageType.WARNING);
-                    infobar.add_button (_("Edit Anyway"), ResponseType.YES);
-                    infobar.add_button (_("Don't Edit"), ResponseType.NO);
-                    infobar.response.connect ((response_id) =>
-                    {
-                        if (response_id == ResponseType.YES)
-                            tab.document.readonly = false;
-                        infobar.destroy ();
-                        tab.view.grab_focus ();
-                    });
-                    return tab;
+                    if (jump_to)
+                        active_tab = doc.tab;
+                    return doc.tab;
                 }
+
+                /* the document is already opened in another window */
+                DocumentTab tab = create_tab_from_location (location, jump_to);
+                tab.document.readonly = true;
+                string primary_msg =
+                    _("This file (%s) is already opened in another LaTeXila window.")
+                    .printf (location.get_parse_name ());
+                string secondary_msg = _("LaTeXila opened this instance of the file in a non-editable way. Do you want to edit it anyway?");
+                InfoBar infobar = tab.add_message (primary_msg, secondary_msg,
+                    MessageType.WARNING);
+                infobar.add_button (_("Edit Anyway"), ResponseType.YES);
+                infobar.add_button (_("Don't Edit"), ResponseType.NO);
+                infobar.response.connect ((response_id) =>
+                {
+                    if (response_id == ResponseType.YES)
+                        tab.document.readonly = false;
+                    infobar.destroy ();
+                    tab.view.grab_focus ();
+                });
+                return tab;
             }
         }
 
diff --git a/src/search.vala b/src/search.vala
index 494e339..445cf17 100644
--- a/src/search.vala
+++ b/src/search.vala
@@ -29,14 +29,14 @@ public class GotoLine : HBox
         this.main_window = main_window;
         spacing = 3;
 
-        var close_button = new Button ();
+        Button close_button = new Button ();
         pack_start (close_button, false, false, 0);
         close_button.set_relief (ReliefStyle.NONE);
-        var img = new Image.from_stock (Stock.CLOSE, IconSize.MENU);
+        Image img = new Image.from_stock (Stock.CLOSE, IconSize.MENU);
         close_button.add (img);
         close_button.clicked.connect (() => hide ());
 
-        var label = new Label (_("Go to Line:"));
+        Label label = new Label (_("Go to Line:"));
         pack_start (label, false, false, 2);
 
         entry = new Entry ();
@@ -65,7 +65,7 @@ public class GotoLine : HBox
             return;
         }
 
-        var text = entry.get_text ();
+        string text = entry.get_text ();
 
         // check if all characters are digits
         for (int i = 0 ; i < text.length ; i++)
@@ -78,8 +78,8 @@ public class GotoLine : HBox
             }
         }
 
-        var line = int.parse (text);
-        var error = ! main_window.active_document.goto_line (--line);
+        int line = int.parse (text);
+        bool error = ! main_window.active_document.goto_line (--line);
         Utils.set_entry_error (entry, error);
         main_window.active_view.scroll_to_cursor ();
     }
@@ -128,11 +128,12 @@ public class SearchAndReplace : GLib.Object
     {
         this.main_window = main_window;
 
-        var path = Path.build_filename (Config.DATA_DIR, "ui", "search_and_replace.ui");
+        string path = Path.build_filename (Config.DATA_DIR, "ui",
+            "search_and_replace.ui");
 
         try
         {
-            var builder = new Builder ();
+            Builder builder = new Builder ();
             builder.add_from_file (path);
 
             /* get objects */
@@ -152,17 +153,18 @@ public class SearchAndReplace : GLib.Object
 
             entry_replace = (Entry) builder.get_object ("entry_replace");
             frame_replace = (Frame) builder.get_object ("frame_replace");
-            var button_clear_replace =
+            Button button_clear_replace =
                 (Button) builder.get_object ("button_clear_replace");
-            var button_replace = (Button) builder.get_object ("button_replace");
-            var button_replace_all = (Button) builder.get_object ("button_replace_all");
+            Button button_replace = (Button) builder.get_object ("button_replace");
+            Button button_replace_all =
+                (Button) builder.get_object ("button_replace_all");
 
             hbox_replace = (HBox) builder.get_object ("hbox_replace");
 
-            var button_previous = (Button) builder.get_object ("button_previous");
-            var button_next = (Button) builder.get_object ("button_next");
+            Button button_previous = (Button) builder.get_object ("button_previous");
+            Button button_next = (Button) builder.get_object ("button_next");
 
-            var button_close = (Button) builder.get_object ("button_close");
+            Button button_close = (Button) builder.get_object ("button_close");
 
             /* styles */
             Gdk.Color white;
@@ -171,7 +173,7 @@ public class SearchAndReplace : GLib.Object
             eventbox_label2.modify_bg (StateType.NORMAL, white);
 
             /* options menu */
-            var menu = new Menu ();
+            Menu menu = new Menu ();
             check_case_sensitive = new CheckMenuItem.with_label (_("Case sensitive"));
             check_entire_word = new CheckMenuItem.with_label (_("Entire words only"));
             menu.append (check_case_sensitive);
@@ -223,7 +225,7 @@ public class SearchAndReplace : GLib.Object
 
             entry_find.changed.connect (() =>
             {
-                var sensitive = entry_find.text_length > 0;
+                bool sensitive = entry_find.text_length > 0;
                 button_clear_find.sensitive = sensitive;
                 button_previous.sensitive = sensitive;
                 button_next.sensitive = sensitive;
@@ -284,7 +286,7 @@ public class SearchAndReplace : GLib.Object
         catch (Error e)
         {
             stderr.printf ("Error search and replace: %s\n", e.message);
-            var label = new Label (e.message);
+            Label label = new Label (e.message);
             label.set_line_wrap (true);
             widget = label;
         }
@@ -340,7 +342,9 @@ public class SearchAndReplace : GLib.Object
         if (working_document != null)
             clear_search ();
 
-        main_window.active_view.grab_focus ();
+        if (main_window.active_view != null)
+            main_window.active_view.grab_focus ();
+
         main_window.notify["active-document"].disconnect (active_document_changed);
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]