Skip to content

Commit

Permalink
Movements with tabs, and fixed remove last row/col
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Apr 26, 2016
1 parent d27664c commit de1f974
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Core/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 19 additions & 6 deletions Core/CsvDocumentPersistence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FileExtension = new ReadOnlyCollection<string>(new string[]{ "csv", "tsv" } );
public const string TempExtension = "tmp";
public const string Spaces = " \n\r";
public const string FileFilter = "*." + FileExtension;
public static ReadOnlyCollection<string> FileFilter = new ReadOnlyCollection<string>(
new string[]{ "*." + FileExtension[ 0 ], "*." + FileExtension[ 1 ] } );

public CsvDocumentPersistence() {
this.document = null;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -280,7 +293,7 @@ protected void LoadCsvData(IList<string> 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
Expand Down
23 changes: 16 additions & 7 deletions Core/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Gui/DlgImportLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 7 additions & 15 deletions Gui/MainWindowLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}
}

Expand Down
Loading

0 comments on commit de1f974

Please sign in to comment.