diff --git a/Core/AppInfo.cs b/Core/AppInfo.cs index f9e3f11..96dd78d 100644 --- a/Core/AppInfo.cs +++ b/Core/AppInfo.cs @@ -2,10 +2,10 @@ namespace Colorado.Core { public class AppInfo { public const string Name = "Colorado"; - public const string Version = "v1.0.3 20150911"; + public const string Version = "v1.0.4 20160626"; public const string Author = "baltasarq@gmail.com"; public const string Website = "http://baltasarq.info/dev/"; - public const string Comments = "A simple tool to view&edit CSV files"; + public const string Comments = "A simple tool to view&edit TSV/CSV files"; public const string License = @" Copyright (c) 2015 dev::baltasarq (baltasarq@gmail.com) diff --git a/Core/CsvDocumentPersistence.cs b/Core/CsvDocumentPersistence.cs index 215d7ed..971d26c 100644 --- a/Core/CsvDocumentPersistence.cs +++ b/Core/CsvDocumentPersistence.cs @@ -2,14 +2,16 @@ using System.IO; using System.Xml; using System.Text; +using System.Collections.ObjectModel; using System.Collections.Generic; namespace Colorado.Core { public class CsvDocumentPersistence { - public const string FileExtension = "csv"; + public static ReadOnlyCollection FileExtension = new ReadOnlyCollection(new string[]{ "csv", "tsv" } ); public const string TempExtension = "tmp"; public const string Spaces = " \n\r"; - public const string FileFilter = "*." + FileExtension; + public static ReadOnlyCollection FileFilter = new ReadOnlyCollection( + new string[]{ "*." + FileExtension[ 0 ], "*." + FileExtension[ 1 ] } ); public CsvDocumentPersistence() { this.document = null; @@ -34,8 +36,19 @@ public static void PrepareFileName(ref string fileName) fileName = fileName.Trim(); string fileNameLower = fileName.ToLower(); - if ( !fileNameLower.EndsWith( FileExtension.ToLower() ) ) { - fileName += "." + FileExtension; + // Look in all extensions + int i = 0; + while ( i < FileExtension.Count ) { + if ( fileNameLower.EndsWith( FileExtension[ i ].ToLower() ) ) { + break; + } + + ++i; + } + + // Okay, no valid extension: append one. + if ( i >= FileExtension.Count ) { + fileName += "." + FileExtension[ 0 ]; } return; @@ -152,7 +165,7 @@ public void Load(string fileName, char delimiter = '\0', bool firstRowForHeaders } } } else { - throw new ApplicationException( "No data in CSV document" ); + throw new ApplicationException( "No data in spreadsheet" ); } this.Document.Changed = false; @@ -280,7 +293,7 @@ protected void LoadCsvData(IList lines) int colsLength = cols.Length; if ( colsLength > Document.Data.NumColumns ) { - throw new ApplicationException( "Bad CSV format -- too variable number of columns" ); + throw new ApplicationException( "Bad format -- too variable number of columns" ); } // Set data diff --git a/Core/Data.cs b/Core/Data.cs index 0db9afd..d82a298 100644 --- a/Core/Data.cs +++ b/Core/Data.cs @@ -408,12 +408,17 @@ public void RemoveRows(int pos, int numRows) ChkValue( numRows, 0, NumRows, "number of rows to remove" ); Changed = true; - // Value to really delete - int removeCount = Math.Min( numRows, this.NumRows - pos - 1 ); - - // Do it and fix - this.data.RemoveRange( pos, removeCount ); - this.numRows -= removeCount; + // Value to really delete + int removeCount = Math.Min( numRows, this.NumRows - pos - 1 ); + + if ( pos < ( this.NumRows - 1 ) ) { + // Do it and fix + this.data.RemoveRange( pos, removeCount ); + this.numRows -= removeCount; + } else { + this.numRows -=1; + } + Owner.FormulaManager.FixFormulasRowsRemoved( pos, removeCount ); Owner.FormulaManager.AllowFormulaUpdating = true; } @@ -452,7 +457,11 @@ public void RemoveColumns(int pos, int numCols) Changed = true; // Real count to delete - int removeCount = Math.Min( numCols, this.NumColumns - pos - 1 ); + int removeCount = 1; + + if ( pos < ( this.NumColumns - 1 ) ) { + removeCount = Math.Min( numCols, this.NumColumns - pos - 1 ); + } // For each row... for (int i = 0; i < NumRows; ++i) { diff --git a/Gui/DlgImportLogic.cs b/Gui/DlgImportLogic.cs index 52f08e5..6793bb6 100644 --- a/Gui/DlgImportLogic.cs +++ b/Gui/DlgImportLogic.cs @@ -26,7 +26,7 @@ private void OnOpen() Core.AppInfo.Name, "Open", (Gtk.Window) this.Parent, ref lastFileName, - Core.CsvDocumentPersistence.FileFilter ) ) + Core.CsvDocumentPersistence.FileFilter[ 0 ] ) ) { this.edFileName.Text = lastFileName; } diff --git a/Gui/MainWindowLogic.cs b/Gui/MainWindowLogic.cs index b0e3d15..642ade9 100644 --- a/Gui/MainWindowLogic.cs +++ b/Gui/MainWindowLogic.cs @@ -249,7 +249,7 @@ private bool OnCloseDocument() bool toret = true; if ( this.document != null ) { - if ( Util.Ask( this, AppInfo.Name, "Close CSV document '" + document.FileName + "' ?" ) ) { + if ( Util.Ask( this, AppInfo.Name, "Close spreadsheet '" + document.FileName + "' ?" ) ) { this.CloseDocument(); } else { toret = false; @@ -262,7 +262,7 @@ private bool OnCloseDocument() private void CloseDocument() { if ( this.document.Changed ) { // Save the document, if needed - if ( Util.Ask( this, AppInfo.Name, "Save CSV document '" + document.FileName + "' ?" ) ) { + if ( Util.Ask( this, AppInfo.Name, "Save spreadsheet '" + document.FileName + "' ?" ) ) { this.OnSave(); } } @@ -275,10 +275,10 @@ private void OnOpen() { if ( this.OnCloseDocument() ) { if ( Util.DlgOpen( AppInfo.Name, - "Open CSV", + "Open spreadsheet", this, ref lastFileName, - CsvDocumentPersistence.FileFilter ) ) + CsvDocumentPersistence.FileFilter[ 0 ] ) ) { this.OpenDocument( lastFileName, '\0', true ); } @@ -514,10 +514,10 @@ private void OnSaveAs() try { if ( this.document != null ) { if ( Util.DlgOpen( - AppInfo.Name, "Save CSV as...", + AppInfo.Name, "Save spreadsheet as...", this, ref lastFileName, - CsvDocumentPersistence.FileFilter ) ) + CsvDocumentPersistence.FileFilter[ 0 ] ) ) { this.SetStatus( "Saving..." ); this.document.FileName = this.lastFileName; @@ -1201,14 +1201,8 @@ private void OnTableKeyPressed(Gtk.KeyPressEventArgs args) // Get the current position, needed in both cases. this.GetCurrentCell( out rowIndex, out colIndex ); -/* - Gtk.TreeIter itRow; - this.tvTable.Model.GetIter( out itRow, new Gtk.TreePath( new int[] { rowIndex } ) ); - var cell = (Gtk.CellRendererText) ( (Gtk.ListStore) this.tvTable.Model ).GetValue( itRow, colIndex ); - //if ( cell. -*/ - // Adapt the column + // Adapt the column colIndex += NumFixedColumns; if ( args.Event.Key != Gdk.Key.ISO_Enter ) { @@ -1237,8 +1231,6 @@ private void OnTableKeyPressed(Gtk.KeyPressEventArgs args) this.SetCurrentCell( rowIndex, colIndex ); args.RetVal = true; // Eat the TAB - } else { - this.SetCurrentCell( rowIndex, colIndex, true ); } } diff --git a/Gui/MainWindowView.cs b/Gui/MainWindowView.cs index 1b47eea..4b5e9e3 100644 --- a/Gui/MainWindowView.cs +++ b/Gui/MainWindowView.cs @@ -79,163 +79,163 @@ private void BuildIcons() { this.iconAbout = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.about.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "about", 32, this.iconAbout ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-about", 32, this.iconAbout ); this.iconAdd = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.add.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "add", 32, this.iconAdd ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-add", 32, this.iconAdd ); this.iconClear = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.clear.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "clear", 32, this.iconClear ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-clear", 32, this.iconClear ); this.iconClose = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.close.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "close", 32, this.iconClose ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-close", 32, this.iconClose ); this.iconCopy = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.copy.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "copy", 32, this.iconCopy ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-copy", 32, this.iconCopy ); this.iconExit = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.exit.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "exit", 32, this.iconExit ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-exit", 32, this.iconExit ); this.iconExport = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.export.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "export", 32, this.iconExport ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-export", 32, this.iconExport ); this.iconFind = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.find.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "find", 32, this.iconFind ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-find", 32, this.iconFind ); this.iconFormula = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.formula.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "formula", 32, this.iconFormula ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-formula", 32, this.iconFormula ); this.iconImport = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.import.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "import", 32, this.iconImport ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-import", 32, this.iconImport ); this.iconNew = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.new.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "new", 32, this.iconNew ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-new", 32, this.iconNew ); this.iconOpen = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.open.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "open", 32, this.iconOpen ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-open", 32, this.iconOpen ); this.iconPaste = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.paste.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "paste", 32, this.iconPaste ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-paste", 32, this.iconPaste ); this.iconProperties = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.properties.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "properties", 32, this.iconProperties ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-properties", 32, this.iconProperties ); this.iconRemove = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.remove.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "remove", 32, this.iconRemove ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-remove", 32, this.iconRemove ); this.iconRevert = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.revert.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "revert", 32, this.iconRevert ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-revert", 32, this.iconRevert ); this.iconSave = new Gdk.Pixbuf( System.Reflection.Assembly.GetEntryAssembly(), "Colorado.Res.save.png", 32, 32 ); - Gtk.IconTheme.AddBuiltinIcon( "save", 32, this.iconSave ); + Gtk.IconTheme.AddBuiltinIcon( "clrd-save", 32, this.iconSave ); } catch(System.Exception) { this.ToolbarMode = Gtk.ToolbarStyle.Text; } } private void BuildActions() { - this.newAction = new Gtk.Action( "new", "_New", "new spreadhseet", "new" ) { IconName = "new" }; + this.newAction = new Gtk.Action( "new", "_New", "new spreadhseet", "new" ) {IconName = "clrd-new" }; this.newAction.Activated += (sender, e) => this.OnNew(); - this.openAction = new Gtk.Action( "open", "_Open", "open spreadhseet", "open") { IconName = "open" }; + this.openAction = new Gtk.Action( "open", "_Open", "open spreadhseet", "open") { IconName = "clrd-open" }; this.openAction.Activated += (sender, e) => this.OnOpen(); - this.saveAction = new Gtk.Action( "save", "_Save", "save spreadhseet", "save" ) { IconName = "save" }; + this.saveAction = new Gtk.Action( "save", "_Save", "save spreadhseet", "save" ) { IconName = "clrd-save" }; this.saveAction.Activated += (sender, e) => this.OnSave(); - this.saveAsAction = new Gtk.Action( "save_as", "Save _as...", "save spreadhseet as...", "save" ) { IconName = "save" }; + this.saveAsAction = new Gtk.Action( "save_as", "Save _as...", "save spreadhseet as...", "save" ) { IconName = "clrd-save" }; this.saveAsAction.Activated += (sender, e) => this.OnSaveAs(); - this.propertiesAction = new Gtk.Action( "properties", "_Properties", "properties", "properties" ) { IconName = "properties" }; + this.propertiesAction = new Gtk.Action( "properties", "_Properties", "properties", "properties" ) { IconName = "clrd-properties" }; this.propertiesAction.Activated += (sender, e) => this.OnProperties(); - this.closeAction = new Gtk.Action( "close", "_Close", "close spreadhseet", "close" ) { IconName = "close" }; + this.closeAction = new Gtk.Action( "close", "_Close", "close spreadhseet", "close" ) { IconName = "clrd-close" }; this.closeAction.Activated += (sender, e) => this.CloseDocument(); - this.aboutAction = new Gtk.Action( "about", "_About", "about...", "about" ) { IconName = "about" }; + this.aboutAction = new Gtk.Action( "about", "_About", "about...", "about" ) { IconName = "clrd-about" }; this.aboutAction.Activated += (sender, e) => this.OnAbout(); - this.importAction = new Gtk.Action( "import", "_Import", "import data", "import" ) { IconName = "import" }; + this.importAction = new Gtk.Action( "import", "_Import", "import data", "import" ) { IconName = "clrd-import" }; this.importAction.Activated += (sender, e) => this.OnImport(); - this.exportAction = new Gtk.Action( "export", "_Export", "export to...", "export" ) { IconName = "export" }; + this.exportAction = new Gtk.Action( "export", "_Export", "export to...", "export" ) { IconName = "clrd-export" }; this.exportAction.Activated += (sender, e) => this.OnExport(); - this.revertAction = new Gtk.Action( "revert", "_Revert", "revert to file", "revert" ) { IconName = "revert" }; + this.revertAction = new Gtk.Action( "revert", "_Revert", "revert to file", "revert" ) { IconName = "clrd-revert" }; this.revertAction.Activated += (sender, e) => this.OnRevert(); - this.quitAction = new Gtk.Action( "quit", "_Quit", "quit", "exit" ) { IconName = "exit" }; + this.quitAction = new Gtk.Action( "quit", "_Quit", "quit", "exit" ) { IconName = "clrd-exit" }; this.quitAction.Activated += (sender, e) => this.OnQuit(); - this.findAction = new Gtk.Action( "find", "_Find", "find...", "find" ) { IconName = "find" }; + this.findAction = new Gtk.Action( "find", "_Find", "find...", "find" ) { IconName = "clrd-find" }; this.findAction.Activated += (sender, e) => this.OnFind(); - this.findAgainAction = new Gtk.Action( "find_again", "_Find again", "find again", "find" ) { IconName = "find" }; + this.findAgainAction = new Gtk.Action( "find_again", "_Find again", "find again", "find" ) { IconName = "clrd-find" }; this.findAgainAction.Activated += (sender, e) => this.OnFindAgain(); - this.insertFormulaAction = new Gtk.Action( "insert_formula", "_Insert formula", "insert formula", "formula" ) { IconName = "formula" }; + this.insertFormulaAction = new Gtk.Action( "insert_formula", "_Insert formula", "insert formula", "formula" ) { IconName = "clrd-formula" }; this.insertFormulaAction.Activated += (sender, e) => this.OnInsertFormula(); - this.addRowsAction = new Gtk.Action( "add_rows", "_Add rows", "add rows", "add" ) { IconName = "add" }; + this.addRowsAction = new Gtk.Action( "add_rows", "_Add rows", "add rows", "add" ) { IconName = "clrd-add" }; this.addRowsAction.Activated += (sender, e) => this.OnAddRows(); - this.removeRowsAction = new Gtk.Action( "remove_rows", "_Remove rows", "remove rows", "remove" ) { IconName = "remove" }; + this.removeRowsAction = new Gtk.Action( "remove_rows", "_Remove rows", "remove rows", "remove" ) { IconName = "clrd-remove" }; this.removeRowsAction.Activated += (sender, e) => this.OnRemoveRows(); - this.clearRowsAction = new Gtk.Action( "clear_rows", "_Clear rows", "clear rows", "clear" ) { IconName = "clear" }; + this.clearRowsAction = new Gtk.Action( "clear_rows", "_Clear rows", "clear rows", "clear" ) { IconName = "clrd-clear" }; this.clearRowsAction.Activated += (sender, e) => this.OnClearRows(); - this.copyRowAction = new Gtk.Action( "copy_row", "_Copy row", "copy row", "copy" ) { IconName = "copy" }; + this.copyRowAction = new Gtk.Action( "copy_row", "_Copy row", "copy row", "copy" ) { IconName = "clrd-copy" }; this.copyRowAction.Activated += (sender, e) => this.OnCopyRow(); - this.fillRowAction = new Gtk.Action( "fill_row", "_Fill row", "fill row", "paste" ) { IconName = "paste" }; + this.fillRowAction = new Gtk.Action( "fill_row", "_Fill row", "fill row", "paste" ) { IconName = "clrd-paste" }; this.fillRowAction.Activated += (sender, e) => this.OnFillRow(); - this.addColumnsAction = new Gtk.Action( "add_columns", "_Add columns", "add columns", "add" ) { IconName = "add" }; + this.addColumnsAction = new Gtk.Action( "add_columns", "_Add columns", "add columns", "add" ) { IconName = "clrd-add" }; this.addColumnsAction.Activated += (sender, e) => this.OnAddColumns(); - this.removeColumnsAction = new Gtk.Action( "remove_columns", "_Remove columns", "remove columns", "remove" ) { IconName = "remove" }; + this.removeColumnsAction = new Gtk.Action( "remove_columns", "_Remove columns", "remove columns", "remove" ) { IconName = "clrd-remove" }; this.removeColumnsAction.Activated += (sender, e) => this.OnRemoveColumns(); - this.clearColumnsAction = new Gtk.Action( "clear_Columns", "_Clear columns", "clear columns", "clear" ) { IconName = "clear" }; + this.clearColumnsAction = new Gtk.Action( "clear_Columns", "_Clear columns", "clear columns", "clear" ) { IconName = "clrd-clear" }; this.clearColumnsAction.Activated += (sender, e) => this.OnClearColumns(); - this.copyColumnAction = new Gtk.Action( "copy_column", "_Copy column", "copy column", "copy" ) { IconName = "copy" }; + this.copyColumnAction = new Gtk.Action( "copy_column", "_Copy column", "copy column", "copy" ) { IconName = "clrd-copy" }; this.copyColumnAction.Activated += (sender, e) => this.OnCopyColumn(); - this.fillColumnAction = new Gtk.Action( "fill_column", "_Fill column", "fill column", "paste" ) { IconName = "paste" }; + this.fillColumnAction = new Gtk.Action( "fill_column", "_Fill column", "fill column", "paste" ) { IconName = "clrd-paste" }; this.fillColumnAction.Activated += (sender, e) => this.OnFillColumn(); } @@ -272,7 +272,7 @@ private void BuildMenu() { miColumns.Submenu = mColumns; miHelp.Submenu = mHelp; - var opNew = this.newAction.CreateMenuItem(); + var opNew = this.newAction.CreateMenuItem(); opNew.AddAccelerator( "activate", accelGroup, new Gtk.AccelKey( Gdk.Key.n, Gdk.ModifierType.ControlMask, Gtk.AccelFlags.Visible) );