public static void LoadProject(string file) { TreeView treeView = Program.WinInstance.ProjectExplorer.TreeView; TreeStore treeStore = (TreeStore)Program.WinInstance.ProjectExplorer.TreeView.Model; ProjectManager.Project = new Project(file); treeStore.Clear(); CodeWidget.RemoveTab("Welcome to iCode !"); var e = new RowActivatedHandler((o, args) => { TreeIter treeIter; treeStore.GetIter(out treeIter, args.Path); int type = 0; foreach (var @class in _classNodes) { if (Equals(treeIter, @class)) { type = 1; break; } } if (type != 1) { foreach (var @class in _resourceNodes) { if (Equals(treeIter, @class)) { type = 2; break; } } } switch (type) { case 1: var code = CodeWidget.AddCodeTab(Path.Combine(Path.GetDirectoryName(file), (string)treeStore.GetValue(treeIter, 1))); CodeWidget.Codewidget.Tabs.Page = CodeWidget.Codewidget.Tabs.PageNum(Extensions.Tabs.First(x => x.Key == (string)treeStore.GetValue(treeIter, 1)).Value); break; case 2: Process.Start("gio", "open '" + Path.Combine(Path.GetDirectoryName(file), "Resources", (string)treeStore.GetValue(treeIter, 1)) + "'"); break; } }); foreach (var row in _handlers) { treeView.RowActivated -= row; } _handlers.Clear(); treeView.RowActivated += e; _handlers.Add(e); _projectNode = treeStore.AppendValues(new object[] { Utils.IconLoader.LoadIcon(Program.WinInstance.ProjectExplorer, "gtk-directory", IconSize.Menu), ProjectManager.Project.Name }); _resourcesNode = treeStore.AppendValues(_projectNode, new object[] { Utils.IconLoader.LoadIcon(Program.WinInstance.ProjectExplorer, "gtk-directory", IconSize.Menu), "Resources" }); foreach (Class @class in ProjectManager.Project.Classes) { var node = treeStore.AppendValues(_projectNode, Extensions.GetIconFromFile(Path.Combine(Project.Path, @class.Filename)), Path.GetFileName(@class.Filename) ); _classNodes.Add(node); } foreach (string path in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(file), "Resources"))) { var node = treeStore.AppendValues(_resourcesNode, Extensions.GetIconFromFile(Path.GetFullPath(path)), Path.GetFileName(path) ); _resourceNodes.Add(node); } var filea = ""; using (var f = File.Open(Path.Combine(Program.ConfigPath, "RecentProjects"), FileMode.OpenOrCreate)) { var wr = new StreamWriter(f); var re = new StreamReader(f); var content = re.ReadToEnd(); var lines = content.Split('\n').ToList(); if (lines.Count == 4) { lines.Remove(lines.First()); } var temp = new List <string>(); foreach (var line in from l in lines where l == Path.GetDirectoryName(file) select l) { temp.Add(line); } foreach (var temp2 in temp) { lines.Remove(temp2); } lines.Add(Path.GetDirectoryName(file)); filea = string.Join("\n", lines); wr.Dispose(); re.Dispose(); } foreach (var widget in _sensitiveWidgets) { widget.Sensitive = ProjectLoaded; } File.WriteAllText(Path.Combine(Program.ConfigPath, "RecentProjects"), filea); }
public MainWindow(Builder builder, IntPtr handle) : base(handle) { try { this._builder = builder; builder.Autoconnect(this); this.Title = Names.ApplicationName; _progressbar1.Text = Names.ApplicationName; CodeWidget.Initialize(); Box box = new Box(Orientation.Vertical, 0); _dock = new Dock(); this._master = (DockMaster)this._dock.Master; _master.SwitcherStyle = SwitcherStyle.Tabs; this._layout = new DockLayout(this._dock); _layout.Master = _master; this._bar = new DockBar(this._dock); Box box2 = new Box(Orientation.Horizontal, 5); box.PackStart(box2, true, true, 0u); box2.PackStart(this._bar, false, false, 0u); box2.PackEnd(this._dock, true, true, 0u); DockItem dockItem = new DockItem("code1", "Code", Stock.Edit, DockItemBehavior.CantClose); dockItem.Grip.Hide(); this._dock.AddItem(dockItem, DockPlacement.Center); this._dock.BorderWidth = 2u; CodeWidget.AddWelcomeTab(string.Format("Welcome to {0} !", Names.ApplicationName)); dockItem.Add(this.GetCodePane()); dockItem.ShowAll(); DockItem dockItem4 = new DockItem("outputConsole", "Output", Stock.Execute, 0); this._dock.AddItem(dockItem4, DockPlacement.Bottom); dockItem4.Add(_outputWidget); dockItem4.ShowAll(); DockItem dockItem2 = new DockItem("projectExplorer", "Project Explorer", Stock.Harddisk, 0); this._dock.AddItem(dockItem2, DockPlacement.Left); dockItem2.Add(this.CreateProjectExplorerPane()); dockItem2.ShowAll(); DockItem dockItem3 = new DockItem("properties", "Properties", Stock.Properties, 0); this._dock.AddItem(dockItem3, DockPlacement.Right); dockItem3.Add(this.CreatePropertiesPane()); dockItem3.ShowAll(); this.DeleteEvent += OnDeleteEvent; this.Add(box); this.Icon = Pixbuf.LoadFromResource("iCode.resources.images.icon.png"); this._buildProjectAction.Activated += (sender, e) => { Task.Factory.StartNew(() => { if (ProjectManager.BuildProject()) { StateLabel.Text = "Build succeeded."; } else { StateLabel.Text = "Build failed."; } }); }; this._aboutICodeAction.Activated += (sender, e) => { AboutWindow.Create().ShowAll(); }; ProjectManager.AddSensitiveWidget(_buildProjectAction); ProjectManager.AddSensitiveWidget(_button6); ProjectManager.AddSensitiveWidget(_button7); _label1.Text = Names.ApplicationName; this._button6.Clicked += (sender, e) => { ProjectManager.RunProject(); }; Gtk.CssProvider nopad = new CssProvider(); nopad.LoadFromData(@" widget { border-radius: 4px; background: @borders; } progress, trough { border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; min-height: 4px; } "); var layoutFile = System.IO.Path.Combine(Program.ConfigPath, "Layouts.xml"); if (!File.Exists(layoutFile)) { _layout.SaveLayout("default_layout"); _layout.SaveToFile(layoutFile); } _layout.LoadFromFile(layoutFile); XDocument xdoc = XDocument.Load(layoutFile); var layoutList = xdoc.Elements().First().Elements().ToList(); Dictionary <MenuItem, string> names = new Dictionary <MenuItem, string>(); Menu menu = new Menu(); var saveItem = new MenuItem(); saveItem.Label = "Save actual layout..."; saveItem.Activated += (o, a) => { InputWindow input = InputWindow.Create(); input.Title = "Select name for the layout"; input.Run(); if (string.IsNullOrWhiteSpace(input.Text)) { return; } Console.WriteLine($"Saving layout \"{input.Text}\""); _layout.SaveLayout(input.Text); var menuItem = new MenuItem(); menuItem.Label = input.Text; menuItem.Activated += (o, a) => { _layout.LoadLayout(input.Text); }; menu.Append(menuItem); }; menu.Append(saveItem); foreach (var a in layoutList) { var menuItem = new MenuItem(); var name = a.Attributes().First(x => x.Name == "name").Value; names.Add(menuItem, name); menuItem.Label = name; menuItem.Activated += (o, a) => { Console.WriteLine($"Loading layout {names[menuItem]}"); _layout.LoadLayout(names[menuItem]); }; menu.Append(menuItem); if (name == "__default_") { this.ShowAll(); _layout.LoadLayout(name); } } _layoutAction.Submenu = menu; if (Program.UpdateAvailable) { var updateMenu = new MenuItem(); var itemMenu = new Menu(); var item = new MenuItem(); updateMenu.Label = "Update iCode in background"; updateMenu.Activated += (sender, args) => { Gtk.Application.Invoke((o, a) => { itemMenu.Remove(updateMenu); item.Label = "Update in progress..."; }); Task.Factory.StartNew(() => { var outp = iCode.Utils.Extensions.LaunchProcess( System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Updater"), $"\"{Program.AppImagePath}\"", out int ret); if (ret == 0) { Gtk.Application.Invoke((o, a) => { item.Label = "Update completed."; }); } else { Gtk.Application.Invoke((o, a) => { item.Label = "Update failed."; }); } }); }; itemMenu.Append(updateMenu); item.Label = "Update available"; item.Submenu = itemMenu; _menuBar.Append(item); } _statusBox.ButtonPressEvent += (o, args) => { // Here it will redirect to the future error pane, but I need to fix signing first }; _statusBox.StyleContext.AddProvider(nopad, 1); _progressbar1.StyleContext.AddProvider(nopad, 1); _createProjectAction.Activated += CreateProject; _openProjectAction.Activated += LoadProjectActivated; // var b = layout.LoadFromFile(System.IO.Path.Combine(Program.ConfigPath, "layouts/saved.layout")); // Console.WriteLine("Fail or success ? It's " + b + " !"); } catch (Exception e) { ExceptionWindow.Create(e, this).ShowAll(); } }