private void SetNotebookItem() { var lvi = _list.SelectedItems[0]; var type = (NotebookItemType)Enum.Parse(typeof(NotebookItemType), lvi.Group.Name); NotebookItem = new NotebookItem(type, lvi.Text); }
public void RenameItem(NotebookItem item, string newName) { string lcNewName = newName.ToLower(); bool isCaseChange = item.Name.ToLower() == lcNewName; switch (item.Type) { case NotebookItemType.Console: case NotebookItemType.Note: case NotebookItemType.Script: if (!isCaseChange) { // is the new name already in use? if (Notebook.UserData.Items.Any(x => x.Name.ToLower() == lcNewName)) { throw new Exception($"An item named \"{newName}\" already exists."); } } var itemRec = Notebook.UserData.Items.Single(x => x.Name == item.Name); itemRec.Name = newName; if (item.Type == NotebookItemType.Script) { var scriptParamRec = Notebook.UserData.ScriptParameters.SingleOrDefault(x => x.ScriptName == item.Name); if (scriptParamRec != null) { scriptParamRec.ScriptName = newName; } } break; case NotebookItemType.Table: Notebook.Invoke(() => { Notebook.Execute($"ALTER TABLE {item.Name.DoubleQuote()} RENAME TO \"{newName.Replace("\"", "\"\"")}\""); }); break; case NotebookItemType.View: Notebook.Invoke(() => { var createViewSql = (string)Notebook.QueryValue("SELECT sql FROM sqlite_master WHERE name = @old_name", new Dictionary <string, object> { ["@old_name"] = item.Name }); var tokens = Notebook.Tokenize(createViewSql); if (tokens.Count < 3 || tokens[0].Type != TokenType.Create || tokens[1].Type != TokenType.View) { throw new Exception($"Unable to parse the original CREATE VIEW statement for \"{item.Name}\"."); } var suffix = string.Join(" ", tokens.Select(x => x.Text).Skip(3)); // everything after "CREATE VIEW viewname" Notebook.Execute($"DROP VIEW {item.Name.DoubleQuote()}"); Notebook.Execute($"CREATE VIEW {newName.DoubleQuote()} {suffix}"); }); break; } NotebookItemRename?.Invoke(this, new NotebookItemRenameEventArgs(item, newName)); SetDirty(); }
private void Manager_NotebookItemRename(object sender, NotebookItemRenameEventArgs e) { UserControlDockContent ucdc; if (_openItems.TryGetValue(e.Item, out ucdc)) { ucdc.Text = e.NewName; ucdc.Content.ItemName = e.NewName; _openItems.Remove(e.Item); var newItem = new NotebookItem(e.Item.Type, e.NewName); _openItems.Add(newItem, ucdc); } var isTableOrView = e.Item.Type == NotebookItemType.Table || e.Item.Type == NotebookItemType.View; _manager.Rescan(notebookItemsOnly: !isTableOrView); }
private void DoDelete() { if (_list.SelectedItems.Count != 1) { return; } var lvi = _list.SelectedItems[0]; var name = lvi.Text; var type = (NotebookItemType)Enum.Parse(typeof(NotebookItemType), lvi.Group.Name); // can't delete tables or views if an operation is in progress bool isTableOrView = type == NotebookItemType.Table || type == NotebookItemType.View; if (isTableOrView && _operationInProgress) { MessageForm.ShowError(_mainForm, "Delete Item", "Cannot delete tables or views while an operation is in progress.", "Please wait until the current operation finishes, and then try again."); return; } var deleteBtn = "&Delete"; var d = new MessageForm { Title = "Delete Item", Message = $"Are you sure you want to delete \"{name}\"?", Buttons = new[] { deleteBtn, "Cancel" }, Icon = Resources.Warning32 }; if (d.ShowDialog(this) != deleteBtn) { return; } var item = new NotebookItem(type, name); _manager.CloseItem(item); new WaitForm("Delete", "Deleting the selected item...", () => { _manager.DeleteItem(item); }).ShowDialogAndDispose(this); _manager.Rescan(notebookItemsOnly: !isTableOrView); }
public void DeleteItem(NotebookItem item) { switch (item.Type) { case NotebookItemType.Console: case NotebookItemType.Script: case NotebookItemType.Note: Notebook.UserData.Items.RemoveWhere(x => x.Name == item.Name); break; case NotebookItemType.Table: Notebook.Invoke(() => Notebook.Execute($"DROP TABLE {item.Name.DoubleQuote()}")); break; case NotebookItemType.View: Notebook.Invoke(() => Notebook.Execute($"DROP VIEW {item.Name.DoubleQuote()}")); break; } SetDirty(); }
public NotebookItemRenameEventArgs(NotebookItem item, string newName) { Item = item; NewName = newName; }
public NotebookItemRequestEventArgs(NotebookItem item) { Item = item; }
public void CloseItem(NotebookItem item) { NotebookItemCloseRequest?.Invoke(this, new NotebookItemRequestEventArgs(item)); }
public void OpenItem(NotebookItem item) { NotebookItemOpenRequest?.Invoke(this, new NotebookItemRequestEventArgs(item)); }
private void OpenItem(NotebookItem item) { UserControlDockContent wnd; if (_openItems.TryGetValue(item, out wnd)) { wnd.Activate(); wnd.Focus(); return; } UserControlDockContent f = null; Func <string> getName = null; var dockAreas = DockAreas.Document | DockAreas.Float; if (item.Type == NotebookItemType.Console) { var doc = new ConsoleDocumentControl(item.Name, _manager, this); f = new UserControlDockContent(item.Name, doc, dockAreas) { Icon = Resources.ApplicationXpTerminalIco }; ApplySaveOnClose(f, doc); getName = () => doc.ItemName; } else if (item.Type == NotebookItemType.Note) { var doc = new NoteDocumentControl(item.Name, _manager); f = new UserControlDockContent(item.Name, doc, dockAreas) { Icon = Resources.NoteIco }; ApplySaveOnClose(f, doc); getName = () => doc.ItemName; } else if (item.Type == NotebookItemType.Script) { var doc = new QueryDocumentControl(item.Name, _manager, this, _operationInProgress); f = new UserControlDockContent(item.Name, doc, dockAreas) { Icon = Resources.ScriptIco }; ApplySaveOnClose(f, doc); getName = () => doc.ItemName; } else if (item.Type == NotebookItemType.Table || item.Type == NotebookItemType.View) { var doc = new TableDocumentControl(_manager, item.Name, this); f = new UserControlDockContent(item.Name, doc, dockAreas) { Icon = Resources.TableIco }; } if (getName != null) { f.FormClosed += (sender2, e2) => { // the item may have been renamed since we opened it, so make sure to use getName() for the current // name instead of closing over item.Name. _openItems.Remove(new NotebookItem(item.Type, getName())); }; _openItems[item] = f; } f.Show(_dockPanel); }