Skip to content

Commit

Permalink
use long for history archive indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed May 16, 2011
1 parent 2a9f9fc commit 779c144
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/cpp/r/include/r/session/RConsoleHistory.hpp
Expand Up @@ -47,7 +47,7 @@ class ConsoleHistory : boost::noncopyable
// COPYING: boost::noncopyable

public:
void setCapacity(int capacity);
void setCapacity(long capacity);

void setRemoveDuplicates(bool removeDuplicates);

Expand All @@ -56,15 +56,15 @@ class ConsoleHistory : boost::noncopyable
const_iterator begin() const { return historyBuffer_.begin(); }
const_iterator end() const { return historyBuffer_.end(); }

int size() const
long size() const
{
return historyBuffer_.size();
}

void clear();

void subset(int beginIndex, // inclusive
int endIndex, // exclusive,
void subset(long beginIndex, // inclusive
long endIndex, // exclusive,
std::vector<std::string>* pEntries) const;

void asJson(core::json::Array* pHistoryArray) const;
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/r/session/RConsoleHistory.cpp
Expand Up @@ -37,7 +37,7 @@ ConsoleHistory::ConsoleHistory()
setCapacity(500);
}

void ConsoleHistory::setCapacity(int capacity)
void ConsoleHistory::setCapacity(long capacity)
{
historyBuffer_.set_capacity(capacity);
}
Expand Down Expand Up @@ -85,8 +85,8 @@ void ConsoleHistory::clear()
historyBuffer_.clear();
}

void ConsoleHistory::subset(int beginIndex, // inclusive
int endIndex, // exclusive,
void ConsoleHistory::subset(long beginIndex, // inclusive
long endIndex, // exclusive,
std::vector<std::string>* pEntries) const
{
// clear existing
Expand Down
55 changes: 29 additions & 26 deletions src/cpp/session/modules/SessionHistory.cpp
Expand Up @@ -48,11 +48,11 @@ namespace {
struct HistoryEntry
{
HistoryEntry() : index(0), timestamp(0) {}
HistoryEntry(int index, double timestamp, const std::string& command)
HistoryEntry(long index, double timestamp, const std::string& command)
: index(index), timestamp(timestamp), command(command)
{
}
int index;
long index;
double timestamp;
std::string command;
};
Expand All @@ -67,7 +67,7 @@ void historyEntriesAsJson(const std::vector<HistoryEntry>& entries,
json::Array indexArray, timestampArray, commandArray;
for (std::size_t i=0; i<entries.size(); i++)
{
indexArray.push_back(entries[i].index);
indexArray.push_back((double)entries[i].index);
timestampArray.push_back(entries[i].timestamp);
commandArray.push_back(entries[i].command);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class HistoryEntryReader
}
}
private:
int nextIndex_;
long nextIndex_;
};


Expand Down Expand Up @@ -252,12 +252,12 @@ History& historyArchive()
return instance;
}

Error setJsonResultFromHistory(int startIndex,
int endIndex,
Error setJsonResultFromHistory(long startIndex,
long endIndex,
json::JsonRpcResponse* pResponse)
{
// validate indexes
int historySize = historyArchive().size();
long historySize = historyArchive().size();
if ( (startIndex < 0) ||
(startIndex > historySize) ||
(endIndex < 0) ||
Expand Down Expand Up @@ -295,8 +295,8 @@ bool matches(const HistoryEntry& entry,
}


void historyRangeAsJson(int startIndex,
int endIndex,
void historyRangeAsJson(long startIndex,
long endIndex,
json::Object* pHistoryJson)
{
// get the subset of entries
Expand All @@ -318,10 +318,11 @@ Error getRecentHistory(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get params
int maxItems;
Error error = json::readParam(request.params, 0, &maxItems);
double maxItemsDbl;
Error error = json::readParam(request.params, 0, &maxItemsDbl);
if (error)
return error;
long maxItems = (long)maxItemsDbl;

// alias console history
using namespace r::session;
Expand All @@ -332,8 +333,8 @@ Error getRecentHistory(const json::JsonRpcRequest& request,
return Error(json::errc::ParamInvalid, ERROR_LOCATION);

// compute start and end indexes
int startIndex = std::max(0, consoleHistory.size() - maxItems);
int endIndex = consoleHistory.size();
long startIndex = std::max(0L, consoleHistory.size() - maxItems);
long endIndex = consoleHistory.size();

// get json and set it
json::Object historyJson;
Expand All @@ -346,15 +347,15 @@ Error getHistoryItems(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get start and end index
int startIndex; // inclusive
int endIndex; // exclusive
double startIndex; // inclusive
double endIndex; // exclusive
Error error = json::readParams(request.params, &startIndex, &endIndex);
if (error)
return error;

// get the range and return it
json::Object historyJson;
historyRangeAsJson(startIndex, endIndex, &historyJson);
historyRangeAsJson((long)startIndex, (long)endIndex, &historyJson);
pResponse->setResult(historyJson);
return Success();
}
Expand All @@ -381,30 +382,31 @@ Error getHistoryArchiveItems(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get start and end index
int startIndex; // inclusive
int endIndex; // exclusive
double startIndex; // inclusive
double endIndex; // exclusive
Error error = json::readParams(request.params, &startIndex, &endIndex);
if (error)
return error;

// truncate indexes if necessary
int historySize = historyArchive().size();
startIndex = std::min(startIndex, historySize);
endIndex = std::min(endIndex, historySize);
long historySize = historyArchive().size();
long startIndexLong = std::min((long)startIndex, historySize);
long endIndexLong = std::min((long)endIndex, historySize);

// return json for the appropriate range
return setJsonResultFromHistory(startIndex, endIndex, pResponse);
return setJsonResultFromHistory(startIndexLong, endIndexLong, pResponse);
}

Error searchHistoryArchive(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get the query
std::string query;
int maxEntries;
Error error = json::readParams(request.params, &query, &maxEntries);
double maxEntriesDbl;
Error error = json::readParams(request.params, &query, &maxEntriesDbl);
if (error)
return error;
long maxEntries = maxEntriesDbl;

// convert the query into a list of search terms
std::vector<std::string> searchTerms;
Expand Down Expand Up @@ -444,10 +446,11 @@ Error searchHistoryArchiveByPrefix(const json::JsonRpcRequest& request,
{
// get the query
std::string prefix;
int maxEntries;
Error error = json::readParams(request.params, &prefix, &maxEntries);
double maxEntriesDbl;
Error error = json::readParams(request.params, &prefix, &maxEntriesDbl);
if (error)
return error;
long maxEntries = (long)maxEntriesDbl;

// trim the prefix
boost::algorithm::trim(prefix);
Expand Down
Expand Up @@ -1020,7 +1020,7 @@ public void getHistoryItems(


public void removeHistoryItems(JsArrayNumber itemIndexes,
ServerRequestCallback<Bool> requestCallback)
ServerRequestCallback<Void> requestCallback)
{
sendRequest(RPC_SCOPE,
REMOVE_HISTORY_ITEMS,
Expand Down
Expand Up @@ -12,6 +12,7 @@
*/
package org.rstudio.studio.client.workbench.views.history;

import com.google.gwt.core.client.JsArrayNumber;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
Expand Down Expand Up @@ -358,7 +359,46 @@ void onHistorySendToSource()

@Handler
void onHistoryRemoveEntries()
{
{
// get selected indexes (bail if there is no selection)
final ArrayList<Long> selectedIndexes = view_.getSelectedCommandIndexes();
if (selectedIndexes.size() < 1)
{
globalDisplay_.showErrorMessage(
"Error",
"No history entries currently selected.");
return;
}

// bring view to front
view_.bringToFront();

globalDisplay_.showYesNoMessage(
GlobalDisplay.MSG_QUESTION,
"Confirm Remove Entries",
"Are you sure you want to remove the selected entries from " +
"the history?",

new ProgressOperation() {
public void execute(final ProgressIndicator indicator)
{
indicator.onProgress("Removing items...");

JsArrayNumber indexes = (JsArrayNumber)
JsArrayNumber.createArray();

for (int i = 0; i<selectedIndexes.size(); i++)
indexes.push(selectedIndexes.get(i));

server_.removeHistoryItems(
indexes,
new VoidServerRequestCallback(indicator));
}
},

true
);


}

Expand Down
Expand Up @@ -13,7 +13,6 @@
package org.rstudio.studio.client.workbench.views.history.model;

import org.rstudio.core.client.jsonrpc.RpcObjectList;
import org.rstudio.studio.client.server.Bool;
import org.rstudio.studio.client.server.Void;
import org.rstudio.studio.client.server.ServerRequestCallback;

Expand All @@ -40,7 +39,7 @@ void getHistoryItems(
* removeHistoryItems -- indexes of items to remove
*/
void removeHistoryItems(JsArrayNumber itemIndexes,
ServerRequestCallback<Bool> requestCallback);
ServerRequestCallback<Void> requestCallback);


/*
Expand Down
Expand Up @@ -542,7 +542,7 @@ public void onBlur(BlurEvent event)
return new Toolbar(new Widget[] {
commands_.historySendToConsole().createToolbarButton(),
commands_.historySendToSource().createToolbarButton(),
// commands_.historyRemoveEntries().createToolbarButton(),
// commands_.historyRemoveEntries().createToolbarButton(),
commands_.clearHistory().createToolbarButton()
}, new Widget[] {
searchWidget_
Expand Down

0 comments on commit 779c144

Please sign in to comment.