File scratch-2.4.1-gtk.patch of Package scratch

diff -ruN scratch-text-editor-2.4.1.orig/plugins/pastebin/pastebin_dialog.vala scratch-text-editor-2.4.1/plugins/pastebin/pastebin_dialog.vala
--- scratch-text-editor-2.4.1.orig/plugins/pastebin/pastebin_dialog.vala	2017-02-20 14:37:19.000000000 +0300
+++ scratch-text-editor-2.4.1/plugins/pastebin/pastebin_dialog.vala	2018-01-24 09:55:15.314903530 +0300
@@ -18,13 +18,11 @@
   END LICENSE
 ***/
 
-using Gtk;
-
 using Scratch.Services;
 
 namespace Scratch.Dialogs {
 
-    public class PasteBinDialog : Granite.Widgets.LightWindow {
+    public class PasteBinDialog : Gtk.Dialog {
 
 		public string[,] languages = {
 			//if default, code, desc, scratch-equivalent
@@ -227,63 +225,49 @@
 			{"n", "xpp", "XPP", ""},
 			{"n", "yaml", "YAML", ""},
 			{"n", "z80", "Z80 Assembler", ""},
-			{"n", "zxbasic", "ZXBasic", ""} };
-
-            private Scratch.Services.Document doc;
-
-			private Box content;
-			private Box padding;
+        {"n", "zxbasic", "ZXBasic", ""}
+    };
 
-			private Entry name_entry;
-			private ComboBoxText expiry_combo;
-			private CheckButton private_check;
-
-			private ComboBoxText format_combo;
-			private Window format_others_win;
-			private TreeView format_others_view;
-			private Gtk.ListStore format_store;
-
-			private Button send_button;
+		public Scratch.Services.Document doc { get; construct; }
+		
+        private Gtk.Button send_button;
+        private Gtk.Entry name_entry;
+        private Gtk.ComboBoxText expiry_combo;
+        private Gtk.CheckButton private_check;
+        private Gtk.ComboBoxText format_combo;
+        private Gtk.Window format_others_win;
+        private Gtk.TreeView format_others_view;
+        private Gtk.ListStore format_store;
+        private Gtk.Stack stack;
 
 
         public PasteBinDialog (Gtk.Window? parent, Scratch.Services.Document doc) {
-            this.doc = doc;
-
-            if (parent != null)
-                this.set_transient_for (parent);
-            this.title = _("Share via PasteBin");
-            this.type_hint = Gdk.WindowTypeHint.DIALOG;
-
-            create_dialog ();
-
-            send_button.clicked.connect (send_button_clicked);
-            this.destroy.connect (() => {
-                write_settings ();
-            });
+            Object (
+                border_width: 5,
+                deletable: false,
+                doc: doc,
+                transient_for: parent,
+                title: _("Share via PasteBin")
+            );
         }
 
-        private void create_dialog () {
+        construct {
+            name_entry = new Gtk.Entry ();
 
-            content = new Box (Gtk.Orientation.VERTICAL, 10);
-            padding = new Box (Gtk.Orientation.HORIZONTAL, 10);
+            var name_entry_l = new Gtk.Label (_("Name:"));
+            name_entry_l.halign = Gtk.Align.END;
 
-            name_entry = new Entry ();
-            name_entry.text = "Test";
-            var name_entry_l = new Label (_("Name:"));
-            var name_entry_box = new Box (Gtk.Orientation.HORIZONTAL, 58);
-            name_entry_box.pack_start (name_entry_l, false, true, 0);
-            name_entry_box.pack_start (name_entry, true, true, 0);
-
-
-			var format_label = new Label (_("Format: "));
-			format_combo = new ComboBoxText();
-			var format_button = new Button.with_label (_("Others..."));
-				format_button.clicked.connect (format_button_clicked);
+			var format_label = new Gtk.Label (_("Format:"));
+            format_label.halign = Gtk.Align.END;
+ 
+			format_combo = new Gtk.ComboBoxText ();
+
+			var format_button = new Gtk.Button.with_label (_("Others..."));
+			format_button.clicked.connect (format_button_clicked);
 
 			//populate combo box
 			var sel_lang = doc.get_language_id ();
 			for (var i=0; i < languages.length[0]; i++) {
-
 				//insert all languages that are in the scratch combo, and also those that are marked with "y"
 				if ( (languages[i, 3] != "") || (languages[i, 0] == "y")) format_combo.append (languages[i, 1], languages[i, 2]);
 				//if the inserted language is selected in scratch combo, select it as default
@@ -294,85 +278,106 @@
 			if (format_combo.get_active_id() == null) format_combo.set_active_id("text");
 
 
-			var format_box = new Box (Gtk.Orientation.HORIZONTAL, 28);
-			format_box.pack_start (format_label);
-			format_box.pack_start (format_combo);
-			format_box.pack_start (format_button);
-
-
-            expiry_combo = new ComboBoxText ();
+            var expiry_combo_l = new Gtk.Label (_("Expiry time:"));
+            expiry_combo_l.halign = Gtk.Align.END;
+            expiry_combo = new Gtk.ComboBoxText ();
             populate_expiry_combo ();
-            var expiry_combo_l = new Label (_("Expiry time:"));
-            var expiry_combo_box = new Box (Gtk.Orientation.HORIZONTAL, 28);
-            expiry_combo_box.pack_start (expiry_combo_l, false, true, 0);
-            expiry_combo_box.pack_start (expiry_combo, true, true, 0);
-
-            private_check = new CheckButton.with_label (_("Keep this paste private"));
-
-            send_button = new Button.with_label (_("Upload"));
-
-            var bottom_buttons = new ButtonBox (Gtk.Orientation.HORIZONTAL);
-            bottom_buttons.set_layout (ButtonBoxStyle.CENTER);
-            bottom_buttons.set_spacing (10);
-            bottom_buttons.pack_end (send_button);
-
-            content.pack_start (wrap_alignment (name_entry_box, 12, 0, 0, 0), true, true, 0);
-            content.pack_start (format_box, true, true, 0);
-            content.pack_start (expiry_combo_box, true, true, 0);
-            content.pack_start (private_check, true, true, 0);
-            content.pack_end (bottom_buttons, true, true, 12);
-
-            padding.pack_start (content, false, true, 12);
-
-            add (padding);
+ 
+            private_check = new Gtk.CheckButton.with_label (_("Keep this paste private"));
+            private_check.margin_top = 12;
+
+            var grid = new Gtk.Grid ();
+            grid.column_spacing = 6;
+            grid.row_spacing = 12;
+            grid.margin = 5;
+            grid.margin_top = 0;
+            grid.attach (name_entry_l, 0, 0, 1, 1);
+            grid.attach (name_entry, 1, 0, 1, 1);
+            grid.attach (format_label, 0, 1, 1, 1);
+            grid.attach (format_combo, 1, 1, 1, 1);
+            grid.attach (format_button, 2, 1, 1, 1);
+            grid.attach (expiry_combo_l, 0, 2, 1, 1);
+            grid.attach (expiry_combo, 1, 2, 1, 1);
+            grid.attach (private_check, 1, 3, 2, 1);
+
+            var spinner = new Gtk.Spinner ();
+            spinner.active = true;
+            spinner.height_request = 32;
+            spinner.valign = Gtk.Align.CENTER;
+
+            stack = new Gtk.Stack ();
+            stack.add (grid);
+            stack.add (spinner);
+
+            var content_area = get_content_area () as Gtk.Box;
+            content_area.add (stack);
+
+            send_button = new Gtk.Button.with_label (_("Upload"));
+
+            var cancel_button = new Gtk.Button.with_label (_("Close"));
+
+            var action_area = get_action_area () as Gtk.Box;
+            action_area.margin_top = 7;
+            action_area.add (cancel_button);
+            action_area.add (send_button);
 
             read_settings ();
 
             show_all ();
 
-            send_button.grab_focus ();
-
+            send_button.clicked.connect (() => {
+                stack.visible_child = spinner;
+                send_button_clicked ();
+            });
+            cancel_button.clicked.connect (() => {
+                destroy ();
+            });
+ 
+            this.destroy.connect (() => {
+                write_settings ();
+            });
         }
 
 
 		private void format_button_clicked() {
 
-			format_others_win = new Window();
+			format_others_win = new Gtk.Window();
 			format_others_win.set_modal(true);
 			format_others_win.set_title(_("Other formats"));
 			format_others_win.set_default_size (250, 300);
 
-				format_others_view = new TreeView();
-		        format_others_view.set_headers_visible(false);
-				format_store = new Gtk.ListStore (2, typeof (string), typeof (string));
-				format_others_view.set_model (format_store);
-				format_others_view.insert_column_with_attributes (-1, "Language", new CellRendererText (), "text", 0);
-
-				TreeIter iter;
-				for (var i=0; i < languages.length[0]; i++) {
-					format_store.append (out iter);
-					format_store.set (iter, 0, languages[i, 2], 1, languages[i, 1]);
-				}
-
-			var format_others_scroll = new ScrolledWindow(null, null);
-				format_others_scroll.add(format_others_view);
-
-			var format_others_ok = new Button.from_icon_name ("dialog-ok", IconSize.BUTTON);
-				format_others_ok.clicked.connect (format_others_ok_clicked);
-			var format_others_cancel = new Button.from_icon_name ("dialog-cancel", IconSize.BUTTON);
-				format_others_cancel.clicked.connect (format_others_cancel_clicked);
-			var format_others_buttons = new ButtonBox (Orientation.HORIZONTAL);
-				format_others_buttons.set_layout (ButtonBoxStyle.CENTER);
-				format_others_buttons.pack_start (format_others_cancel);
-				format_others_buttons.pack_start (format_others_ok);
-
-			var format_others_box = new Box (Gtk.Orientation.VERTICAL, 10);
-				format_others_box.pack_start (format_others_scroll);
-				format_others_box.pack_start (format_others_buttons);
+            format_others_view = new Gtk.TreeView();
+            format_others_view.set_headers_visible(false);
+            format_store = new Gtk.ListStore (2, typeof (string), typeof (string));
+            format_others_view.set_model (format_store);
+            format_others_view.insert_column_with_attributes (-1, "Language", new Gtk.CellRendererText (), "text", 0);
+
+            Gtk.TreeIter iter;
+            for (var i=0; i < languages.length[0]; i++) {
+	            format_store.append (out iter);
+	            format_store.set (iter, 0, languages[i, 2], 1, languages[i, 1]);
+            }
+
+            var format_others_scroll = new Gtk.ScrolledWindow(null, null);
+            format_others_scroll.add(format_others_view);
+
+            var format_others_ok = new Gtk.Button.from_icon_name ("dialog-ok", Gtk.IconSize.BUTTON);
+            format_others_ok.clicked.connect (format_others_ok_clicked);
+
+            var format_others_cancel = new Gtk.Button.from_icon_name ("dialog-cancel", Gtk.IconSize.BUTTON);
+            format_others_cancel.clicked.connect (format_others_cancel_clicked);
+
+            var format_others_buttons = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
+            format_others_buttons.set_layout (Gtk.ButtonBoxStyle.CENTER);
+            format_others_buttons.pack_start (format_others_cancel);
+            format_others_buttons.pack_start (format_others_ok);
+
+            var format_others_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
+            format_others_box.pack_start (format_others_scroll);
+            format_others_box.pack_start (format_others_buttons);
 
 			format_others_win.add (format_others_box);
 			format_others_win.show_all();
-
 		}
 
 		private void format_others_cancel_clicked() {
@@ -382,7 +387,7 @@
 		private void format_others_ok_clicked() {
 
 			var selection = format_others_view.get_selection ();
-			TreeIter iter;
+			Gtk.TreeIter iter;
 			if (selection.get_selected (null, out iter) == true) {
 
 				Value lang_name;
@@ -400,19 +405,6 @@
 		}
 
 
-        private static Alignment wrap_alignment (Widget widget, int top, int right,
-                                                 int bottom, int left) {
-
-            var alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
-            alignment.top_padding = top;
-            alignment.right_padding = right;
-            alignment.bottom_padding = bottom;
-            alignment.left_padding = left;
-
-            alignment.add(widget);
-            return alignment;
-
-        }
 
         private void read_settings () {
 
@@ -435,29 +427,19 @@
 
         private void send_button_clicked () {
 
-            content.hide ();
-
-            // Probably your connection is too fast to not see this
-            var spinner = new Spinner ();
-            padding.pack_start (spinner, true, true, 10);
-            spinner.show ();
-            spinner.start ();
+            send_button.sensitive = false;
 
             string link;
             var submit_result = submit_paste (out link);
 
-            // Show the new view
-            spinner.hide ();
-
-            var box = new Box (Gtk.Orientation.VERTICAL, 10);
+            var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
+            stack.add (box);
 
             if (submit_result == 0) {
-
                 //paste successfully
-                var link_button = new LinkButton (link);
+                var link_button = new Gtk.LinkButton (link);
                 box.pack_start (link_button, false, true, 25);
             } else {
-
                 //paste error
                 var error_desc = new StringBuilder();
 
@@ -477,15 +459,13 @@
                 }
 
                 error_desc.append("\n" + "The text was sent");
-                var err_label = new Label(error_desc.str);
+                var err_label = new Gtk.Label(error_desc.str);
 
                 box.pack_start (err_label, false, true, 0);
             }
 
-            padding.pack_start (box, false, true, 12);
-            padding.halign = Align.CENTER;
-            box.valign = Align.CENTER;
             box.show_all ();
+            stack.visible_child = box;
         }
 
 
diff -ruN scratch-text-editor-2.4.1.orig/plugins/source-tree/SourceTreePlugin.vala scratch-text-editor-2.4.1/plugins/source-tree/SourceTreePlugin.vala
--- scratch-text-editor-2.4.1.orig/plugins/source-tree/SourceTreePlugin.vala	2017-02-20 14:37:19.000000000 +0300
+++ scratch-text-editor-2.4.1/plugins/source-tree/SourceTreePlugin.vala	2018-01-24 10:05:57.454077453 +0300
@@ -28,7 +28,7 @@
     public File file { get; construct set; }
     bool loaded = false;
 
-    const string ATTRIBUTES = FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE + 
+    const string ATTRIBUTES = FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE +
         "," + FileAttribute.STANDARD_ICON;
     const string[] IGNORED = { "pyc", "class", "pyo", "o" };
 
@@ -37,16 +37,16 @@
         file = dir;
         name = dir.get_basename ();
         selectable = false;
-        
+
         //need to add one item to make the folder appear
         add (new Granite.Widgets.SourceList.Item (_("Loading...")));
-        
+
         toggled.connect (() => {
             if (!expanded || loaded)
                 return;
-            
+
             loaded = true;
-            
+
             load ();
             var children_tmp = new Gee.ArrayList<Granite.Widgets.SourceList.Item> ();
             children_tmp.add_all (children);
@@ -56,21 +56,21 @@
             }
         });
     }
-    
+
     public void load () {
         try {
             var enumerator = file.enumerate_children (ATTRIBUTES, FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
             FileInfo? file_info = null;
-            
+
             while ((file_info = enumerator.next_file ()) != null) {
                 var file_name = file_info.get_name ();
                 var file_type = file_info.get_file_type ();
-                
+
                 if (file_type == FileType.REGULAR && !file_name.has_suffix ("~") && !file_name.has_prefix (".")) {
                     // Ignore some kind of temporany files
 
                     bool ignore = false;
-                    for (int n = 0; n < IGNORED.length; n++) { 
+                    for (int n = 0; n < IGNORED.length; n++) {
                         string ignored_suffix = IGNORED[n];
                         debug (ignored_suffix);
                         var tmp = file_name.split (".");
@@ -97,13 +97,13 @@
     public Document (File file, Icon icon)
     {
         Object (file: file, icon: icon);
-        
+
         name = file.get_basename ();
-        
+
         action_activated.connect (() => {
             if (parent == null)
                 return;
-                
+
             scratch_interface.close_document (doc);
             parent.remove (this);
         });
@@ -119,7 +119,7 @@
         doc = _doc;
         try {
             activatable = Gtk.IconTheme.get_default ().lookup_by_gicon (new ThemedIcon ("window-close-symbolic"), 16, 0).load_symbolic ({1, 1, 1, 1});
-        } catch (Error e) { warning (e.message); }      
+        } catch (Error e) { warning (e.message); }
     }
 }
 
@@ -139,7 +139,7 @@
         action_activated.connect (() => {
             if (parent == null)
                 return;
-            
+
             parent.remove (this);
         });
     }
@@ -149,7 +149,7 @@
     public class SourceTreePlugin : Peas.ExtensionBase, Peas.Activatable {
         Scratch.Services.Interface plugins;
         public Object object { owned get; construct; }
-        
+
         Gtk.ToolButton? new_button = null;
         Gtk.ToolButton? bookmark_tool_button = null;
         Gtk.Notebook scratch_notebook;
@@ -163,13 +163,26 @@
 
         bool my_select = false;
 
+        bool _in_side_notebook;
+        bool in_side_notebook {
+            get {
+                return _in_side_notebook;
+            }
+
+            set {
+                _in_side_notebook = value;
+                this.bookmark_tool_button.visible = value;
+                this.bookmark_tool_button.no_show_all = value;
+            }
+        }
+
         public void activate () {
             plugins = (Scratch.Services.Interface) object;
             plugins.hook_notebook_sidebar.connect (on_hook_sidebar);
             plugins.hook_document.connect (on_hook_document);
             plugins.hook_toolbar.connect ((toolbar) => {
                 MainWindow window = plugins.manager.window;
-                if (this.bookmark_tool_button != null && this.new_button != null) 
+                if (this.bookmark_tool_button != null && this.new_button != null)
                     return;
                 this.new_button = window.main_actions.get_action ("NewTab").create_tool_item() as Gtk.ToolButton;
                 this.bookmark_tool_button = new Gtk.ToolButton (new Gtk.Image.from_icon_name ("bookmark-new", Gtk.IconSize.LARGE_TOOLBAR), _("Bookmark"));
@@ -179,25 +192,20 @@
                 toolbar.pack_start (new_button);
                 //toolbar.insert (bookmark_tool_button, toolbar.get_item_index (toolbar.find_button) + 1);
                 //toolbar.insert (new_button, 0);
+                in_side_notebook = false;
             });
             plugins.hook_split_view.connect ((view) => {
                 this.bookmark_tool_button.visible = ! view.is_empty ();
                 this.bookmark_tool_button.no_show_all = view.is_empty ();
                 view.welcome_shown.connect (() => {
-                    this.bookmark_tool_button.visible = false;
-                    this.bookmark_tool_button.no_show_all = true;
                     int current_page = this.side_notebook.get_current_page ();
                     if (this.side_notebook.get_nth_page (current_page) == this.view) {
                         this.side_notebook.remove_page (current_page);
+                        in_side_notebook = false;
                     }
                 });
-                view.welcome_hidden.connect (() => {
-                    this.bookmark_tool_button.visible = true;
-                    this.bookmark_tool_button.no_show_all = false;
-                    this.side_notebook.append_page (this.view, new Gtk.Label (_("Source Tree")));
-                });
             });
-            
+
             scratch_interface = ((Scratch.Services.Interface)object);
         }
 
@@ -217,23 +225,14 @@
         void on_hook_sidebar (Gtk.Notebook notebook) {
             if (view != null)
                 return;
+
             side_notebook = notebook;
             view = new Granite.Widgets.SourceList ();
-            view.set_sort_func ((a, b) => {
-                if (a is Folder && b is Folder)
-                    return a.name.collate (b.name);
-                if (a is Folder)
-                    return -1;
-                if (b is Folder)
-                    return 1;
-
-                return a.parent == view.root && a.name == "Bookmarks" ? 1 : a.name.collate (b.name);
-            });
 
             view.get_style_context ().add_class ("sidebar");
-            category_files = new Granite.Widgets.SourceList.ExpandableItem (_("Files"));
-            category_project = new Granite.Widgets.SourceList.ExpandableItem (_("Project"));
-            category_bookmarks = new Granite.Widgets.SourceList.ExpandableItem (_("Bookmarks"));
+            category_files = new SourceTreePluginExpandableItem (_("Files"));
+            category_project = new SourceTreePluginExpandableItem (_("Project"));
+            category_bookmarks = new SourceTreePluginExpandableItem (_("Bookmarks"));
             view.root.add (category_files);
             view.root.add (category_project);
             view.root.add (category_bookmarks);
@@ -254,13 +253,12 @@
                 var doc = new_current as Document;
                 ((Scratch.Services.Interface)object).open_file (doc.file);
             });
-
         }
 
         void on_hook_document (Scratch.Services.Document doc) {
             scratch_notebook = (doc.get_parent () as Gtk.Notebook);
             scratch_notebook.set_show_tabs (!HIDE_TOOLBAR);
-            
+
             foreach (var d in category_files.children) {
                 if ((d as Document).file == doc.file) {
                     view.selected = d;
@@ -274,6 +272,15 @@
             }
 
             add_doc (doc);
+
+            ensure_in_notebook ();
+        }
+
+        void ensure_in_notebook () {
+            if (!in_side_notebook) {
+                side_notebook.append_page (this.view, new Gtk.Label (_("Source Tree")));
+                in_side_notebook = true;
+            }
         }
 
         void wait_for_save (Scratch.Services.Document doc) {
@@ -287,11 +294,11 @@
             my_select = true;
             view.selected = item;
             my_select = false;
-            
+
             var new_root = detect_project (doc.file);
             if (root == null || root.get_path () != new_root.get_path ()) {
                 root = new_root;
-                category_project.clear ();              
+                category_project.clear ();
                 category_project.expand_all ();
                 category_project.add (new Folder (root));
             }
@@ -327,10 +334,41 @@
             } else if (dir.get_parent ().get_basename () == "src") {
                 dir = dir.get_parent ().get_parent ();
             }
-            
+
             return dir;
         }
     }
+
+    internal class SourceTreePluginExpandableItem : Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable {
+
+        public SourceTreePluginExpandableItem (string name) {
+            base (name);
+        }
+
+        public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) {
+            if (a.get_type () ==  b.get_type ()) {
+                return a.name.collate (b.name);
+            } else if (a is Folder ) {
+                return -1;
+            } else if (b is Folder ) {
+                return 1;
+            } else if (a is Document ) {
+                return -1;
+            } else if (b is Document ) {
+                return 1;
+            } else if (a is Bookmark ) {
+                return -1;
+            } else if (b is Bookmark ) {
+                return 1;
+            } else {
+                return 0;
+            }
+        }
+
+        public bool allow_dnd_sorting () {
+            return false;
+        }
+    }
 }
 
 [ModuleInit]
openSUSE Build Service is sponsored by