OSDN Git Service

帯域制限超過時のメッセージを更新した
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.java
index f60750e..0a1a9a2 100644 (file)
@@ -1,6 +1,7 @@
 /*
-  * This file is part of NixNote 
+  * This file is part of NixNote/NeighborNote 
  * Copyright 2009 Randy Baumgarte
+ * Copyright 2013 Yuki Takahashi
  * 
  * This file may be licensed under the terms of of the
  * GNU General Public License Version 2 (the ``GPL'').
@@ -41,14 +42,15 @@ import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.Vector;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.thrift.TException;
 import org.h2.tools.ChangeFileEncryption;
 
+import com.evernote.edam.error.EDAMErrorCode;
 import com.evernote.edam.error.EDAMNotFoundException;
 import com.evernote.edam.error.EDAMSystemException;
 import com.evernote.edam.error.EDAMUserException;
@@ -65,6 +67,7 @@ import com.evernote.edam.type.Resource;
 import com.evernote.edam.type.SavedSearch;
 import com.evernote.edam.type.Tag;
 import com.evernote.edam.type.User;
+import com.evernote.thrift.TException;
 import com.trolltech.qt.QThread;
 import com.trolltech.qt.core.QByteArray;
 import com.trolltech.qt.core.QDateTime;
@@ -81,6 +84,7 @@ import com.trolltech.qt.core.QModelIndex;
 import com.trolltech.qt.core.QSize;
 import com.trolltech.qt.core.QTemporaryFile;
 import com.trolltech.qt.core.QTextCodec;
+import com.trolltech.qt.core.QTextStream;
 import com.trolltech.qt.core.QThreadPool;
 import com.trolltech.qt.core.QTimer;
 import com.trolltech.qt.core.QTranslator;
@@ -104,7 +108,6 @@ import com.trolltech.qt.gui.QComboBox;
 import com.trolltech.qt.gui.QCursor;
 import com.trolltech.qt.gui.QDesktopServices;
 import com.trolltech.qt.gui.QDialog;
-import com.trolltech.qt.gui.QDockWidget;
 import com.trolltech.qt.gui.QFileDialog;
 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
 import com.trolltech.qt.gui.QFileDialog.FileMode;
@@ -144,6 +147,7 @@ import com.trolltech.qt.network.QNetworkRequest;
 import com.trolltech.qt.webkit.QWebPage.WebAction;
 import com.trolltech.qt.webkit.QWebSettings;
 
+import cx.fbn.nevernote.clipboard.ClipBoardObserver;
 import cx.fbn.nevernote.config.InitializationException;
 import cx.fbn.nevernote.config.StartupConfig;
 import cx.fbn.nevernote.dialog.AccountDialog;
@@ -179,6 +183,7 @@ import cx.fbn.nevernote.gui.ExternalBrowse;
 import cx.fbn.nevernote.gui.MainMenuBar;
 import cx.fbn.nevernote.gui.NotebookTreeWidget;
 import cx.fbn.nevernote.gui.RensoNoteList;
+import cx.fbn.nevernote.gui.RensoNoteListDock;
 import cx.fbn.nevernote.gui.SavedSearchTreeWidget;
 import cx.fbn.nevernote.gui.SearchPanel;
 import cx.fbn.nevernote.gui.TabBrowse;
@@ -188,7 +193,6 @@ import cx.fbn.nevernote.gui.TagTreeWidget;
 import cx.fbn.nevernote.gui.Thumbnailer;
 import cx.fbn.nevernote.gui.TrashTreeWidget;
 import cx.fbn.nevernote.gui.controls.QuotaProgressBar;
-import cx.fbn.nevernote.neighbornote.ClipBoardObserver;
 import cx.fbn.nevernote.oauth.OAuthTokenizer;
 import cx.fbn.nevernote.oauth.OAuthWindow;
 import cx.fbn.nevernote.sql.DatabaseConnection;
@@ -248,9 +252,9 @@ public class NeverNote extends QMainWindow{
     NoteFilter                         filter;                                         // Note filter
     String                                     currentNoteGuid;                        // GUID of the current note 
     Note                                       currentNote;                            // The currently viewed note
-    boolean                                    noteDirty;                                      // Has the note been changed?
-    boolean                            inkNote;                   // if this is an ink note, it is read only
-    boolean                                    readOnly;                                       // Is this note read-only?
+    HashMap<Integer, Boolean>  noteDirty;                              // Has the note been changed?
+    HashMap<Integer, Boolean>  inkNote;                // if this is an ink note, it is read only
+    HashMap<Integer, Boolean>  readOnly;                               // Is this note read-only?
        
   
     ListManager                                listManager;                                    // DB runnable task
@@ -325,17 +329,18 @@ public class NeverNote extends QMainWindow{
     int                                        tagDeadCount=0;                         // number of consecutive dead times for the tag thread
     int                                        trashDeadCount=0;                       // number of consecutive dead times for the trash thread
     int                                saveThreadDeadCount=0;          // number of consecutive dead times for the save thread
+    int                                enRelatedNotesThreadDeadCount=0;        // number of consecutive dead times for the EvernoteRelatedNotes Thread
     boolean                            disableTagThreadCheck=false;
     boolean                            disableNotebookThreadCheck=false;
     boolean                            disableTrashThreadCheck=false;
     boolean                            disableSaveThreadCheck=false;
     boolean                            disableSyncThreadCheck=false;
     boolean                            disableIndexThreadCheck=false;
+    boolean                            disableENRelatedNotesThreadCheck=false;
     
     HashMap<String, String>            noteCache;                      // Cash of note content 
     HashMap<String, Boolean>   readOnlyCache;          // List of cashe notes that are read-only
     HashMap<String, Boolean>   inkNoteCache;           // List of cache notes that are ink notes 
-       // ICHANGED
        HashMap<Integer, ArrayList<String>> historyGuids;  // タブごとの以前見たノートのGUID
        HashMap<Integer, Integer> historyPosition; // Position within the viewed items
        HashMap<Integer, Boolean> fromHistory; // Is this from the history queue?
@@ -357,11 +362,9 @@ public class NeverNote extends QMainWindow{
     private QTimer             blockTimer;
     BrowserWindow              blockingWindow;
     
-       // ICHANGED
-       private final TabBrowserWidget tabBrowser; // ブラウザウィンドウをタブ化
-       private final HashMap<Integer, TabBrowse> tabWindows; // タブウィンドウ
-       private final RensoNoteList rensoNoteList; // 連想ノートリスト
-       private final QDockWidget rensoNoteListDock; // 連想ノートリストドックウィジェット
+       private final TabBrowserWidget tabBrowser;                              // ブラウザウィンドウをタブ化
+       private final HashMap<Integer, TabBrowse> tabWindows;   // タブウィンドウ
+       private final RensoNoteListDock rensoNoteListDock;              // 連想ノートリストドックウィジェット
        ClipBoardObserver cbObserver;
        String rensoNotePressedItemGuid;
        
@@ -376,7 +379,6 @@ public class NeverNote extends QMainWindow{
     // Application Constructor 
        @SuppressWarnings("static-access")
        public NeverNote(DatabaseConnection dbConn)  {
-               // ICHANGED
                cbObserver = new ClipBoardObserver();
                
                conn = dbConn;          
@@ -411,7 +413,7 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.EXTREME, "Starting GUI build");
 
                QTranslator nevernoteTranslator = new QTranslator();
-               nevernoteTranslator.load(Global.getFileManager().getTranslateFilePath("nevernote_" + QLocale.system().name() + ".qm"));
+               nevernoteTranslator.load(Global.getFileManager().getTranslateFilePath("neighbornote_" + QLocale.system().name() + ".qm"));
                QApplication.instance().installTranslator(nevernoteTranslator);
 
                Global.originalPalette = QApplication.palette();
@@ -421,7 +423,6 @@ public class NeverNote extends QMainWindow{
         setWindowTitle(tr("NeighborNote"));
 
         mainLeftRightSplitter = new QSplitter();
-               // ICHANGED
                mainLeftRightSplitter.setOrientation(Qt.Orientation.Horizontal);
                
         setCentralWidget(mainLeftRightSplitter);
@@ -440,7 +441,6 @@ public class NeverNote extends QMainWindow{
         listManager = new ListManager(conn, logger);
         
                logger.log(logger.EXTREME, "Building index runners & timers");
-               // ICHANGED Global.getBehaviorDatabaseUrl()を追加
                indexRunner = new IndexRunner("indexRunner.log",
                                Global.getDatabaseUrl(), Global.getIndexDatabaseUrl(),
                                Global.getResourceDatabaseUrl(),
@@ -450,9 +450,9 @@ public class NeverNote extends QMainWindow{
                indexThread = new QThread(indexRunner, "Index Thread");
         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
         indexRunner.indexImageRecognition = Global.indexImageRecognition();
-        indexRunner.indexNoteBody = Global.indexNoteBody();
-        indexRunner.indexNoteTitle = Global.indexNoteTitle();
-        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
+//        indexRunner.indexNoteBody = Global.indexNoteBody();
+//        indexRunner.indexNoteTitle = Global.indexNoteTitle();
+//        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
                indexThread.start();
                
         synchronizeAnimationTimer = new QTimer();
@@ -467,7 +467,6 @@ public class NeverNote extends QMainWindow{
                                
                logger.log(logger.EXTREME, "Setting sync thread & timers");
                syncThreadsReady=1;
-               // ICHANGED Global.getBehaviorDatabaseUrl()を追加
                syncRunner = new SyncRunner("syncRunner.log", Global.getDatabaseUrl(),
                                Global.getIndexDatabaseUrl(), Global.getResourceDatabaseUrl(),
                                Global.getBehaviorDatabaseUrl(), Global.getDatabaseUserid(),
@@ -479,6 +478,7 @@ public class NeverNote extends QMainWindow{
         syncRunner.status.message.connect(this, "setMessage(String)");
         syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)");
         syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()");
+        syncRunner.limitSignal.rateLimitReached.connect(this, "informRateLimit(Integer)");
         syncRunning = false;   
                if (syncTime > 0) {
                        automaticSync = true;
@@ -494,7 +494,6 @@ public class NeverNote extends QMainWindow{
                
                logger.log(logger.EXTREME, "Starting thumnail thread");
                pdfReadyQueue = new ArrayList<String>();
-               // ICHANGED Global.getBehaviorDatabaseUrl()を追加
                thumbnailRunner = new ThumbnailRunner("thumbnailRunner.log",
                                Global.getDatabaseUrl(), Global.getIndexDatabaseUrl(),
                                Global.getResourceDatabaseUrl(),
@@ -544,7 +543,6 @@ public class NeverNote extends QMainWindow{
         tagTree = new TagTreeWidget(conn);
         savedSearchTree = new SavedSearchTreeWidget();
         trashTree = new TrashTreeWidget();
-               // ICHANGED
                noteTableView = new TableView(logger, listManager, this);     
         
         searchField = new QComboBox();
@@ -584,27 +582,32 @@ public class NeverNote extends QMainWindow{
         noteCache = new HashMap<String,String>();
         readOnlyCache = new HashMap<String, Boolean>();
         inkNoteCache = new HashMap<String, Boolean>();
-        // ICHANGED
         browserWindow = new BrowserWindow(conn, cbObserver);
 
-               // ICHANGED 下から移動してきた。
+               // 下から移動してきた。
                historyGuids = new HashMap<Integer, ArrayList<String>>();
                historyPosition = new HashMap<Integer, Integer>();
                fromHistory = new HashMap<Integer, Boolean>();
                
-               // ICHANGED タブブラウザ作成
+               // タブブラウザ作成
                tabWindows = new HashMap<Integer, TabBrowse>();
                tabBrowser = new TabBrowserWidget(this);
                tabBrowser.setStyleSheet("QTabBar::tab{width:150px;}");
+               tabBrowser.setMovable(true);
+               tabBrowser.setTabsClosable(true);
                TabBrowse tab = new TabBrowse(conn, tabBrowser, cbObserver);
                browserWindow = tab.getBrowserWindow();
                int index = tabBrowser.addNewTab(tab, "");
                tabWindows.put(index, tab);
-               tabBrowser.setTabsClosable(true);
                tabBrowser.currentChanged.connect(this, "tabWindowChanged(int)");
-               tabBrowser.tabCloseRequested.connect(this, "tabWindowClosing(int)");
+               tabBrowser.tabCloseRequested.connect(this, "tabCloseRequested(int)");
+               
+               noteDirty = new HashMap<Integer, Boolean>();
+               noteDirty.put(index, false);
+               
+               inkNote = new HashMap<Integer, Boolean>();
+               readOnly = new HashMap<Integer, Boolean>();
 
-               // ICHANGED
                // 履歴記録のハッシュマップを初期化
                historyGuids.put(index, new ArrayList<String>());
                historyPosition.put(index, 0);
@@ -613,25 +616,16 @@ public class NeverNote extends QMainWindow{
         mainLeftRightSplitter.addWidget(leftSplitter1);
         mainLeftRightSplitter.addWidget(browserIndexSplitter);
         
-               // ICHANGED
                // 連想ノートリストをセットアップ
-               rensoNoteList = new RensoNoteList(conn, this);
-               rensoNoteList.itemPressed.connect(this,
-                               "rensoNoteItemPressed(QListWidgetItem)");
-               rensoNoteListDock = new QDockWidget(tr("Renso Note List"), this);
-               rensoNoteListDock.setWidget(rensoNoteList);
+        rensoNoteListDock = new RensoNoteListDock(conn, this, syncRunner, iconPath, tr("Renso Note List"));
                addDockWidget(DockWidgetArea.RightDockWidgetArea, rensoNoteListDock);
 
                if (Global.getListView() == Global.View_List_Wide) {
                        browserIndexSplitter.addWidget(noteTableView);
-                       // ICHANGED
                        browserIndexSplitter.addWidget(tabBrowser);
-                       // browserIndexSplitter.addWidget(browserWindow);
                } else {
                        mainLeftRightSplitter.addWidget(noteTableView);
-                       // ICHANGED
                        mainLeftRightSplitter.addWidget(tabBrowser);
-                       // mainLeftRightSplitter.addWidget(browserWindow);
                }
        
        // Setup the thumbnail viewer
@@ -695,12 +689,12 @@ public class NeverNote extends QMainWindow{
                savedSearchTree.setVisible(Global.isWindowVisible("savedSearchTree"));
                menuBar.hideSavedSearches.setChecked(Global.isWindowVisible("savedSearchTree"));
                
-               // ICHANGED noteTableViewに新しいタブで開くを追加
+               // noteTableViewに新しいタブで開くを追加
                noteTableView.setOpenNewTabAction(menuBar.noteOpenNewTab);
                        
                noteTableView.setAddAction(menuBar.noteAdd);
                
-               // ICHANGED noteTableViewに新しいタブでノート追加を追加
+               // noteTableViewに新しいタブでノート追加を追加
                noteTableView.setAddNoteNewTabAction(menuBar.noteAddNewTab);
                
                noteTableView.setDeleteAction(menuBar.noteDelete);
@@ -728,13 +722,19 @@ public class NeverNote extends QMainWindow{
                noteTableView.setVisible(Global.isWindowVisible("noteList"));
                menuBar.hideNoteList.setChecked(Global.isWindowVisible("noteList"));
                
-               if (!Global.isWindowVisible("editorButtonBar"))
+               if (!Global.isWindowVisible("editorButtonBar")) {
+                       menuBar.showEditorBar.setChecked(false);
                        toggleEditorButtonBar();
+               }
                
                if (!Global.isWindowVisible("leftPanel"))
                        menuBar.hideLeftSide.setChecked(true);
-               if (Global.isWindowVisible("noteInformation"))
+               
+               if (Global.isWindowVisible("noteInformation")) {
+                       menuBar.noteAttributes.setChecked(true);
                        toggleNoteInformation();
+               }
+               
                quotaBar.setVisible(Global.isWindowVisible("quota"));
                // IFIXED quotaBar.isVisible() → Global.isWindowVisible("quota")
                // なぜかquotaBar.isVisible()が常にfalseを返すようなので修正
@@ -780,14 +780,12 @@ public class NeverNote extends QMainWindow{
                if (currentNoteGuid.equals(""))
                        currentNote = new Note();
                
-               // ICHANGED
-               /* 上に移動したので要らない
-               historyGuids = new ArrayList<String>();
-               historyPosition = 0;
-               fromHistory = false;
-               */
+               /* 上に移動したのでここには不要
+                * historyGuids = new ArrayList<String>();
+                * historyPosition = 0;
+                * fromHistory = false;
+                */
                
-               noteDirty = false;
                if (!currentNoteGuid.trim().equals("")) {
                        currentNote = conn.getNoteTable().getNote(currentNoteGuid, true,true,false,false,true);
                }
@@ -838,12 +836,11 @@ public class NeverNote extends QMainWindow{
        threadMonitorTimer.timeout.connect(this, "threadMonitorCheck()");
        threadMonitorTimer.start(1000*10);  // Check for threads every 10 seconds;              
        
-               // ICHANGED たぶんこれはいらない
-               // IFIXED ?
+               // IFIXED 恐らく不要なのでコメントアウト
                /*
-               historyGuids.add(currentNoteGuid);
-               historyPosition = 1;
-               */
+                * historyGuids.add(currentNoteGuid);
+                * historyPosition = 1;
+                */
        
        menuBar.blockSignals(true);
        menuBar.narrowListView.blockSignals(true);
@@ -858,14 +855,13 @@ public class NeverNote extends QMainWindow{
        menuBar.narrowListView.blockSignals(false);
        menuBar.wideListView.blockSignals(false);
        
-               // IFIXED
-               // 上に同じコードがあるよね? とりあえずコメントアウト
+               // IFIXED 上に同じコードがあるのでコメントアウト
                /*
                 * if (Global.getListView() == Global.View_List_Wide) {
-                * browserIndexSplitter.addWidget(noteTableView); // ICHANGED //
+                * browserIndexSplitter.addWidget(noteTableView);
                 * browserIndexSplitter.addWidget(tabBrowser);
                 * browserIndexSplitter.addWidget(browserWindow); } else {
-                * mainLeftRightSplitter.addWidget(noteTableView); // ICHANGED //
+                * mainLeftRightSplitter.addWidget(noteTableView);
                 * mainLeftRightSplitter.addWidget(tabBrowser);
                 * mainLeftRightSplitter.addWidget(browserWindow); }
                 */
@@ -899,8 +895,11 @@ public class NeverNote extends QMainWindow{
        }
                
                if (Global.checkVersionUpgrade()) {
-                       // ICHANGED TODO とりあえず封印
-                       // checkForUpdates();
+                       checkForUpdates();
+               }
+               
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
                }
        }
        
@@ -1019,7 +1018,6 @@ public class NeverNote extends QMainWindow{
        File fr = Global.getFileManager().getDbDirFile(Global.resourceDatabaseName + ".h2.db");
                // IFIXED resourceDatabaseNameになっていたので修正
                File fi = Global.getFileManager().getDbDirFile(Global.indexDatabaseName + ".h2.db");
-               // ICHANGED
                File fb = Global.getFileManager().getDbDirFile(Global.behaviorDatabaseName + ".h2.db");
                                
                if (!f.exists())
@@ -1028,7 +1026,6 @@ public class NeverNote extends QMainWindow{
                        Global.setResourceDatabaseUrl("");              
                if (!fi.exists())
                        Global.setIndexDatabaseUrl(""); 
-               // ICHANGED
                if (!fb.exists())
                        Global.setBehaviorDatabaseUrl("");
        
@@ -1044,7 +1041,6 @@ public class NeverNote extends QMainWindow{
                         Global.getDatabaseUserPassword(), Global.cipherPassword);
             }
         }
-        // ICHANGED Global.getBehaviorDatabaserUrl()を追加
                DatabaseConnection dbConn = new DatabaseConnection(logger,Global.getDatabaseUrl(), 
                                Global.getIndexDatabaseUrl(), Global.getResourceDatabaseUrl(), Global.getBehaviorDatabaseUrl(),
                                Global.getDatabaseUserid(), Global.getDatabaseUserPassword(), Global.cipherPassword, 0);
@@ -1062,7 +1058,6 @@ public class NeverNote extends QMainWindow{
                st.execute("shutdown");
                st = conn.getIndexConnection().createStatement();
                st.execute("shutdown");
-               // ICHANGED
                st = conn.getBehaviorConnection().createStatement();
                st.execute("shutdown");
                
@@ -1073,13 +1068,11 @@ public class NeverNote extends QMainWindow{
                        ChangeFileEncryption.execute(dbPath, "NeverNote", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
                        ChangeFileEncryption.execute(dbPath, "Resources", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
                        ChangeFileEncryption.execute(dbPath, "Index", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
-                       // ICHANGED
                        ChangeFileEncryption.execute(dbPath, "Behavior", encryptCipher, null, Global.cipherPassword.toCharArray(), true);
                        
                        Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
                        Global.setResourceDatabaseUrl(Global.getResourceDatabaseUrl() + ";CIPHER="+encryptCipher);
                        Global.setIndexDatabaseUrl(Global.getIndexDatabaseUrl() + ";CIPHER="+encryptCipher);
-                       // ICHANGED
                                Global.setBehaviorDatabaseUrl(Global.getBehaviorDatabaseUrl() + ";CIPHER=" + encryptCipher);
 
                        QMessageBox.information(this, tr("Encryption Complete"), tr("Encryption is complete"));
@@ -1202,7 +1195,7 @@ public class NeverNote extends QMainWindow{
                        browser.close();
                }
                
-               // ICHANGED タブブラウザに対してクローズ処理を行う
+               // タブブラウザに対してクローズ処理を行う
                Collection<TabBrowse> win = tabWindows.values();
                Iterator<TabBrowse> it = win.iterator();
                tabBrowser.currentChanged.disconnect();
@@ -1229,6 +1222,9 @@ public class NeverNote extends QMainWindow{
                saveNote();
                listManager.stop();
                saveWindowState();
+               
+               // 連想ノートリストのEvernote関連ノート取得スレッドを終了
+               rensoNoteListDock.getRensoNoteList().stopThread();
 
                if (tempFiles != null)
                        tempFiles.clear();
@@ -1431,7 +1427,7 @@ public class NeverNote extends QMainWindow{
                saveNoteColumnPositions();
                saveNoteIndexWidth();
                showColumns();
-        ConfigDialog settings = new ConfigDialog(this);
+        ConfigDialog settings = new ConfigDialog(this, conn);
         String dateFormat = Global.getDateFormat();
         String timeFormat = Global.getTimeFormat();
         
@@ -1440,9 +1436,9 @@ public class NeverNote extends QMainWindow{
         
         settings.exec();
         indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
-        indexRunner.indexNoteBody = Global.indexNoteBody();
-        indexRunner.indexNoteTitle = Global.indexNoteTitle();
-        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
+//        indexRunner.indexNoteBody = Global.indexNoteBody();
+//        indexRunner.indexNoteTitle = Global.indexNoteTitle();
+//        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
         indexRunner.indexImageRecognition = Global.indexImageRecognition();
         if (Global.showTrayIcon() || Global.minimizeOnClose())
                trayIcon.show();
@@ -1450,7 +1446,6 @@ public class NeverNote extends QMainWindow{
                trayIcon.hide();
         showColumns();
         if (menuBar.showEditorBar.isChecked()){
-               // ICHANGED 
                for(int i = 0; i < tabBrowser.count(); i++){
                        BrowserWindow browser = ((TabBrowse) tabBrowser.widget(i)).getBrowserWindow();
                        showEditorButtons(browser);
@@ -1490,7 +1485,6 @@ public class NeverNote extends QMainWindow{
                mainLeftRightSplitter.setObjectName("mainLeftRightSplitter");
                browserIndexSplitter.setObjectName("browserIndexSplitter");
                leftSplitter1.setObjectName("leftSplitter1");
-               // ICHANGED
                rensoNoteListDock.setObjectName("rensoNoteListDock");
                
                // Restore the actual positions.
@@ -1499,7 +1493,6 @@ public class NeverNote extends QMainWindow{
         mainLeftRightSplitter.restoreState(Global.restoreState(mainLeftRightSplitter.objectName()));
         browserIndexSplitter.restoreState(Global.restoreState(browserIndexSplitter.objectName()));
         leftSplitter1.restoreState(Global.restoreState(leftSplitter1.objectName()));
-        // ICHANGED
        rensoNoteListDock.restoreGeometry(Global.restoreGeometry(rensoNoteListDock.objectName()));
        
        }
@@ -1510,7 +1503,6 @@ public class NeverNote extends QMainWindow{
                Global.saveState(browserIndexSplitter.objectName(), browserIndexSplitter.saveState());
                Global.saveState(leftSplitter1.objectName(), leftSplitter1.saveState());
                Global.saveState(objectName(), saveState());
-               // ICHANGED
                Global.saveGeometry(rensoNoteListDock.objectName(), rensoNoteListDock.saveGeometry());
        }    
        // Load the style sheet
@@ -1651,7 +1643,7 @@ public class NeverNote extends QMainWindow{
        menuBar.notebookIconAction.setEnabled(true);
        menuBar.notebookStackAction.setEnabled(true);
        
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -1924,7 +1916,6 @@ public class NeverNote extends QMainWindow{
                while(set.hasNext())
                        externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
                
-               // ICHANGED
                Iterator<Integer>it = tabWindows.keySet().iterator();
                while (it.hasNext()) {
                        tabWindows.get(it.next()).getBrowserWindow()
@@ -2076,7 +2067,7 @@ public class NeverNote extends QMainWindow{
        // A note's notebook has been updated
        @SuppressWarnings("unused")
        private void updateNoteNotebook(String guid, String notebookGuid) {
-               // ICHANGED 同じノートブックに入れられたノート間の履歴を登録
+               // 同じノートブックに入れられたノート間の履歴を登録
                conn.getHistoryTable().addSameNotebookHistory(guid, notebookGuid);
                
                // Update the list manager
@@ -2171,7 +2162,6 @@ public class NeverNote extends QMainWindow{
                while(set.hasNext())
                        externalWindows.get(set.next()).getBrowserWindow().setNotebookList(filteredBooks);
                
-               // ICHANGED
                // 全てのタブウィンドウを更新
                Iterator<Integer> it = tabWindows.keySet().iterator();
                while (it.hasNext()) {
@@ -2424,7 +2414,7 @@ public class NeverNote extends QMainWindow{
        
                menuBar.noteRestoreAction.setVisible(false);
                
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -2518,7 +2508,14 @@ public class NeverNote extends QMainWindow{
                        }
                }
                browserWindow.setTag(names.toString());
-               noteDirty = true;
+               
+               for (TabBrowse tab: tabWindows.values()) {
+                       if (tab.getBrowserWindow().getNote().getGuid().equals(guid)) {
+                               int index = tabBrowser.indexOf(tab);
+                               noteDirty.put(index, true);
+                               break;
+                       }
+               }
                
                // Now, we need to add any new tags to the tag tree
                for (int i=0; i<newTags.size(); i++) 
@@ -2783,7 +2780,7 @@ public class NeverNote extends QMainWindow{
        menuBar.savedSearchDeleteAction.setEnabled(true);
        menuBar.savedSearchIconAction.setEnabled(true);
        
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -2934,6 +2931,8 @@ public class NeverNote extends QMainWindow{
                status.setTagCount(listManager.getTagIndex().size());
                status.setResourceCount(conn.getNoteTable().noteResourceTable.getResourceCount());
                status.setWordCount(conn.getWordsTable().getWordCount());
+               status.setHistoryCount(conn.getHistoryTable().getHistoryCount());
+               status.setRensoClickCount(conn.getHistoryTable().getRensoClickCount());
                waitCursor(false);
                status.exec();
        }
@@ -2974,7 +2973,12 @@ public class NeverNote extends QMainWindow{
                if (!file.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly,
                 QIODevice.OpenModeFlag.Text)))
                        return;
-               textBox.setText(file.readAll().toString());
+               // 日本語文字化け対策
+               QTextCodec codec = QTextCodec.codecForName("UTF-8");
+               QTextStream textStream = new QTextStream(file);
+               textStream.setCodec(codec);
+               textBox.setText(textStream.readAll().toString());
+               
                file.close();
                dialog.setWindowTitle(tr("Release Notes"));
                dialog.setLayout(layout);
@@ -2993,11 +2997,10 @@ public class NeverNote extends QMainWindow{
        @SuppressWarnings("unused")
        private void about() {
                logger.log(logger.HIGH, "Entering NeverNote.about");
-               // ICHANGED based on...の記述を付加
                QMessageBox.about(this, 
                                                tr("About NeighborNote"),
                                                tr("<h4><center><b>NeighborNote</b></center></h4><hr><center>Version ")
-                                               +Global.version + "(based on NixNote 1.5)"
+                                               +Global.version + "(based on NixNote 1.6)"
                                                //+"1.2.120724"
                                                +tr("<hr>"
                                                                +"Open Source Evernote Client.<br><br>" 
@@ -3184,6 +3187,7 @@ public class NeverNote extends QMainWindow{
        logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
        toolBar = addToolBar(tr("Tool Bar"));   
        toolBar.setObjectName("toolBar");
+       toolBar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon);
        menuBar.setupToolBarVisible();
        if (!Global.isWindowVisible("toolBar"))
                toolBar.setVisible(false);
@@ -3193,78 +3197,87 @@ public class NeverNote extends QMainWindow{
 //     toolBar.addWidget(menuBar);
 //     menuBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
 //     toolBar.addSeparator();
-       prevButton = toolBar.addAction(tr("Previous"));
+       prevButton = toolBar.addAction(tr(""));
+       prevButton.setToolTip(tr("Previous"));
        QIcon prevIcon = new QIcon(iconPath+"back.png");
        prevButton.setIcon(prevIcon);
        prevButton.triggered.connect(this, "previousViewedAction()");   
-       togglePrevArrowButton(Global.isToolbarButtonVisible("prevArrow"));
+       togglePrevArrowButton(Global.isToolbarButtonVisible("prevArrow", true));
        
-       nextButton = toolBar.addAction(tr("Next"));
+       nextButton = toolBar.addAction(tr(""));
+       nextButton.setToolTip(tr("Next"));
        QIcon nextIcon = new QIcon(iconPath+"forward.png");
        nextButton.setIcon(nextIcon);
        nextButton.triggered.connect(this, "nextViewedAction()");       
-       toggleNextArrowButton(Global.isToolbarButtonVisible("nextArrow"));
+       toggleNextArrowButton(Global.isToolbarButtonVisible("nextArrow", true));
+       
+       toolBar.addSeparator();
        
        upButton = toolBar.addAction(tr("Up"));
        QIcon upIcon = new QIcon(iconPath+"up.png");
        upButton.setIcon(upIcon);
        upButton.triggered.connect(this, "upAction()");         
-       toggleUpArrowButton(Global.isToolbarButtonVisible("upArrow"));
+       toggleUpArrowButton(Global.isToolbarButtonVisible("upArrow", false));
 
        
        downButton = toolBar.addAction(tr("Down"));
        QIcon downIcon = new QIcon(iconPath+"down.png");
        downButton.setIcon(downIcon);
        downButton.triggered.connect(this, "downAction()");
-       toggleDownArrowButton(Global.isToolbarButtonVisible("downArrow"));
+       toggleDownArrowButton(Global.isToolbarButtonVisible("downArrow", false));
        
        synchronizeButton = toolBar.addAction(tr("Synchronize"));
        synchronizeButton.setIcon(new QIcon(iconPath+"synchronize.png"));
        synchronizeIconAngle = 0;
        synchronizeButton.triggered.connect(this, "evernoteSync()");
-       toggleSynchronizeButton(Global.isToolbarButtonVisible("synchronize"));
+       toggleSynchronizeButton(Global.isToolbarButtonVisible("synchronize", true));
        
        printButton = toolBar.addAction(tr("Print"));
        QIcon printIcon = new QIcon(iconPath+"print.png");
        printButton.setIcon(printIcon);
        printButton.triggered.connect(this, "printNote()");
-       togglePrintButton(Global.isToolbarButtonVisible("print"));
+       togglePrintButton(Global.isToolbarButtonVisible("print", false));
 
        tagButton = toolBar.addAction(tr("Tag")); 
        QIcon tagIcon = new QIcon(iconPath+"tag.png");
        tagButton.setIcon(tagIcon);
        tagButton.triggered.connect(browserWindow, "modifyTags()");
-       toggleTagButton(Global.isToolbarButtonVisible("tag"));
+       toggleTagButton(Global.isToolbarButtonVisible("tag", false));
 
        attributeButton = toolBar.addAction(tr("Attributes")); 
        QIcon attributeIcon = new QIcon(iconPath+"attribute.png");
        attributeButton.setIcon(attributeIcon);
        attributeButton.triggered.connect(this, "toggleNoteAttributes()");
-       toggleAttributeButton(Global.isToolbarButtonVisible("attribute"));
+       toggleAttributeButton(Global.isToolbarButtonVisible("attribute", true));
                
        emailButton = toolBar.addAction(tr("Email"));
        QIcon emailIcon = new QIcon(iconPath+"email.png");
        emailButton.setIcon(emailIcon);
        emailButton.triggered.connect(this, "emailNote()");
-       toggleEmailButton(Global.isToolbarButtonVisible("email"));
+       toggleEmailButton(Global.isToolbarButtonVisible("email", false));
 
        deleteButton = toolBar.addAction(tr("Delete"));         
        QIcon deleteIcon = new QIcon(iconPath+"delete.png");
        deleteButton.setIcon(deleteIcon);
        deleteButton.triggered.connect(this, "deleteNote()");
-       toggleDeleteButton(Global.isToolbarButtonVisible("delete"));
+       toggleDeleteButton(Global.isToolbarButtonVisible("delete", true));
 
        newButton = toolBar.addAction(tr("New"));
        QIcon newIcon = new QIcon(iconPath+"new.png");
-       newButton.triggered.connect(this, "addNote()");
+       if (Global.toolBarNewAction()) {
+               newButton.triggered.connect(this, "noteAddNewTab()");
+       } else {
+               newButton.triggered.connect(this, "addNote()");
+       }
+
        newButton.setIcon(newIcon);
-       toggleNewButton(Global.isToolbarButtonVisible("new"));
+       toggleNewButton(Global.isToolbarButtonVisible("new", true));
        
        allNotesButton = toolBar.addAction(tr("All Notes"));
        QIcon allIcon = new QIcon(iconPath+"books.png");
        allNotesButton.triggered.connect(this, "allNotes()");
        allNotesButton.setIcon(allIcon);
-       toggleAllNotesButton(Global.isToolbarButtonVisible("allNotes"));
+       toggleAllNotesButton(Global.isToolbarButtonVisible("allNotes", true));
        
        //toolBar.addSeparator();
        //toolBar.addWidget(new QLabel(tr("Quota:")));
@@ -3349,9 +3362,9 @@ public class NeverNote extends QMainWindow{
        contextMenu.addAction(allNotesAction);
        allNotesAction.triggered.connect(this, "toggleAllNotesButton(Boolean)");
        
-       QAction searchClearAction = addContextAction("searchClear", tr("Search Clear"));
-       contextMenu.addAction(searchClearAction);
-       searchClearAction.triggered.connect(this, "toggleSearchClearButton(Boolean)");
+//     QAction searchClearAction = addContextAction("searchClear", tr("Search Clear"));
+//     contextMenu.addAction(searchClearAction);
+//     searchClearAction.triggered.connect(this, "toggleSearchClearButton(Boolean)");
        
        return contextMenu;
        
@@ -3360,7 +3373,7 @@ public class NeverNote extends QMainWindow{
        QAction newAction = new QAction(this);
                newAction.setText(name);
                newAction.setCheckable(true);
-               newAction.setChecked(Global.isToolbarButtonVisible(config));
+               newAction.setChecked(Global.isToolbarButtonVisible(config, true));
                return newAction;
     }
     private void togglePrevArrowButton(Boolean toggle) {
@@ -3411,11 +3424,11 @@ public class NeverNote extends QMainWindow{
                allNotesButton.setVisible(toggle);
                Global.saveToolbarButtonsVisible("allNotes", toggle);
     }
-    @SuppressWarnings("unused")
-       private void toggleSearchClearButton(Boolean toggle) {
-               searchClearButton.setVisible(toggle);
-               Global.saveToolbarButtonsVisible("searchClear", toggle);
-    }
+//    @SuppressWarnings("unused")
+//     private void toggleSearchClearButton(Boolean toggle) {
+//             searchClearButton.setVisible(toggle);
+//             Global.saveToolbarButtonsVisible("searchClear", toggle);
+//    }
 
 
 
@@ -3542,7 +3555,7 @@ public class NeverNote extends QMainWindow{
                Global.showDeleted = false;
                menuBar.noteRestoreAction.setEnabled(false);
                menuBar.noteRestoreAction.setVisible(false);
-                       // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+                       // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                        rensoNoteListDock.setEnabled(true);
        }
        else {
@@ -3550,11 +3563,17 @@ public class NeverNote extends QMainWindow{
                currentNoteGuid = trashNoteGuid;
                menuBar.noteRestoreAction.setEnabled(true);
                menuBar.noteRestoreAction.setVisible(true);
-               // ICHANGED ゴミ箱を開く。連想ノートリストをOFFに。
+               // ゴミ箱を開く。連想ノートリストをOFFに。
                rensoNoteListDock.setEnabled(false);
                                        
                Global.showDeleted = true;
        }
+       
+       menuBar.noteAddNewTab.setEnabled(newButton.isEnabled());
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
+               }
+       
        listManager.loadNotesIndex();
        noteIndexUpdated(false);
 ////           browserWindow.setEnabled(newButton.isEnabled());
@@ -3574,6 +3593,10 @@ public class NeverNote extends QMainWindow{
                listManager.setSelectedSavedSearch("");
                newButton.setEnabled(!newButton.isEnabled());
                menuBar.noteAdd.setEnabled(newButton.isEnabled());
+               menuBar.noteAddNewTab.setEnabled(newButton.isEnabled());
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
+               }
                menuBar.noteAdd.setVisible(true);
                browserWindow.clear();
                
@@ -3589,7 +3612,7 @@ public class NeverNote extends QMainWindow{
                listManager.loadNotesIndex();
                noteIndexUpdated(false);
                
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -3612,6 +3635,11 @@ public class NeverNote extends QMainWindow{
                Global.showDeleted = false;
        newButton.setEnabled(true);
        menuBar.noteAdd.setEnabled(true);
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
+               } else {
+                       menuBar.noteAddNewTab.setEnabled(true);
+               }
        menuBar.noteAdd.setVisible(true);
                trashTree.blockSignals(true);
                trashTree.clearSelection();
@@ -3652,7 +3680,7 @@ public class NeverNote extends QMainWindow{
        OAuthTokenizer tokenizer = new OAuthTokenizer();
        AESEncrypter aes = new AESEncrypter();
        try {
-                       aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("oauth.txt")));
+                       aes.decrypt(new FileInputStream(Global.getFileManager().getHomeDirFile("oauthkey.txt")));
                } catch (FileNotFoundException e) {
                        // File not found, so we'll just get empty strings anyway. 
                }
@@ -3696,6 +3724,7 @@ public class NeverNote extends QMainWindow{
 
                Global.isConnected = syncRunner.isConnected;
                
+               boolean autoLoginMessageFlag = false;
                if (!Global.isConnected) {
                OAuthWindow window = new OAuthWindow(logger);
                if (window.error) {
@@ -3714,7 +3743,7 @@ public class NeverNote extends QMainWindow{
                }
                aes.setString(window.response);
                try {
-                               aes.encrypt(new FileOutputStream(Global.getFileManager().getHomeDirFile("oauth.txt")));
+                               aes.encrypt(new FileOutputStream(Global.getFileManager().getHomeDirFile("oauthkey.txt")));
                        } catch (FileNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
@@ -3722,6 +3751,7 @@ public class NeverNote extends QMainWindow{
                syncRunner.authToken = tokenizer.oauth_token;
                        syncRunner.enConnect();
                        Global.isConnected = syncRunner.isConnected;
+                       autoLoginMessageFlag = true;
                }
 //             Global.username = syncRunner.username;
                        
@@ -3729,9 +3759,16 @@ public class NeverNote extends QMainWindow{
                        return;
                setupOnlineMenu();
                setupConnectMenuOptions();
+               
+               // 初回ログイン時に自動ログインが無効だったら、有効化するか確認する
+               if (autoLoginMessageFlag && !Global.automaticLogin()) {
+                       if (QMessageBox.question(this, tr("Confirmation"), tr("Are you sure you want to enable the auto-login feature?"), 
+                                       QMessageBox.StandardButton.Yes, QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
+                               Global.setAutomaticLogin(true);
+                       }
+               }
+               
                logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
-
-
     }
     private void setupConnectMenuOptions() {
        logger.log(logger.HIGH, "entering NeverNote.setupConnectMenuOptions");
@@ -3762,7 +3799,7 @@ public class NeverNote extends QMainWindow{
        clearTrashFilter();
 //     clearSavedSearchFilter();
        
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -3877,7 +3914,6 @@ public class NeverNote extends QMainWindow{
 
                saveNote();
                
-               // ICHANGED
                // 右クリックだったときの処理
                if (QApplication.mouseButtons().isSet(MouseButton.RightButton)) {
                        // 選択されたノートのguidをselectedNoteGUIDsにセット
@@ -3903,7 +3939,6 @@ public class NeverNote extends QMainWindow{
 
                // If the ctrl key is pressed, then they are selecting multiple 
                // entries and we don't want to change the currently viewed note.
-               // ICHANGED
                // Shiftキーを押しながらの場合の処理も追加
                if ((QApplication.keyboardModifiers().isSet(KeyboardModifier.ControlModifier) ||
                                QApplication.keyboardModifiers().isSet(KeyboardModifier.ShiftModifier)) &&
@@ -3918,12 +3953,11 @@ public class NeverNote extends QMainWindow{
                        return;
                }
                
-               // ICHANGED たぶんこれは不要
-               // IFIXED ?
-               /*if (historyGuids.size() == 0) {
-                       historyGuids.add(currentNoteGuid);
-                       historyPosition = 1;
-               }*/
+               // IFIXED 恐らく不要なのでコメントアウト
+//             if (historyGuids.size() == 0) {
+//                     historyGuids.add(currentNoteGuid);
+//                     historyPosition = 1;
+//             }
 
        noteTableView.showColumn(Global.noteTableGuidPosition);
        
@@ -3936,6 +3970,9 @@ public class NeverNote extends QMainWindow{
                menuBar.noteOnlineHistoryAction.setEnabled(true);
                menuBar.noteMergeAction.setEnabled(true);
                selectedNoteGUIDs.clear();
+               if (currentNoteGuid != null && !currentNoteGuid.equals("") && !Global.showDeleted) {
+                       menuBar.noteAddNewTab.setEnabled(true);
+               }
                if (selections.size() != 1 || Global.showDeleted) {
                        menuBar.noteDuplicateAction.setEnabled(false);
                }
@@ -3966,13 +4003,11 @@ public class NeverNote extends QMainWindow{
        nextButton.setEnabled(true);
                prevButton.setEnabled(true);
                
-               // ICHANGED
                int currentIndex = tabBrowser.currentIndex();
                ArrayList<String> histGuids = historyGuids.get(currentIndex);
                int histPosition = historyPosition.get(currentIndex);
                boolean fromHist = fromHistory.get(currentIndex);
                
-               // ICHANGED
                if (!fromHist) {
                        int endPosition = histGuids.size() - 1;
 
@@ -3994,23 +4029,19 @@ public class NeverNote extends QMainWindow{
        scrollToGuid(currentNoteGuid);
        refreshEvernoteNote(true);
        
-               // ICHANGED
                if (currentNoteGuid != null && !currentNoteGuid.equals("")) {
                        if (!Global.showDeleted) { // ゴミ箱じゃなければ
                                addBrowseHistory();
                        }
                }
 
-               // ICHANGED
                // 連想ノートリストを更新
-               rensoNoteList.refreshRensoNoteList(currentNoteGuid);
+               rensoNoteListDock.getRensoNoteList().refreshRensoNoteList(currentNoteGuid);
                
                waitCursor(false);
                logger.log(logger.HIGH, "Leaving NeverNote.noteTableSelection");
     }
     
-
-       // ICHANGED
     // 複数ノートの同時閲覧履歴をデータベースに保存
        private void addBrowseHistory() {
                // このノートと他のタブウィンドウノートの関連性を内部データベースのHistoryテーブルに登録
@@ -4076,7 +4107,6 @@ public class NeverNote extends QMainWindow{
                String saveCurrentNoteGuid = new String();
                String tempNoteGuid = new String();
                
-               // ICHANGED
                int currentIndex = tabBrowser.currentIndex();
                ArrayList<String> histGuids = historyGuids.get(currentIndex);
                histGuids.clear();
@@ -4120,7 +4150,6 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNoteList");
        } 
     
-       // ICHANGED
        // Called when the previous arrow button is clicked
        @SuppressWarnings("unused")
        private void previousViewedAction() {
@@ -4158,7 +4187,7 @@ public class NeverNote extends QMainWindow{
        private void nextViewedAction() {
        if (!nextButton.isEnabled())
                return;
-               // ICHANGED
+       
                int currentIndex = tabBrowser.currentIndex();
                ArrayList<String> histGuids = historyGuids.get(currentIndex);
                int histPosition = historyPosition.get(currentIndex);
@@ -4553,7 +4582,6 @@ public class NeverNote extends QMainWindow{
        menuBar.narrowListView.blockSignals(false);
        
        mainLeftRightSplitter.addWidget(noteTableView);
-       // ICHANGED browserWindow → tabBrowser
        mainLeftRightSplitter.addWidget(tabBrowser);
        
        restoreWindowState(false);
@@ -4594,7 +4622,6 @@ public class NeverNote extends QMainWindow{
        menuBar.narrowListView.blockSignals(false);
        browserIndexSplitter.setVisible(true);
         browserIndexSplitter.addWidget(noteTableView);
-               // ICHANGED browserWindow → tabBrowser
                browserIndexSplitter.addWidget(tabBrowser);
                
         restoreWindowState(false);
@@ -4668,7 +4695,6 @@ public class NeverNote extends QMainWindow{
        Note note = conn.getNoteTable().getNote(guid, true, true, false, true, true);
        // We have a new external editor to create
        QIcon appIcon = new QIcon(iconPath+"nevernote.png");
-       // ICHANGED
        ExternalBrowse newBrowser = new ExternalBrowse(conn, cbObserver);
        
        newBrowser.setWindowIcon(appIcon);
@@ -4723,7 +4749,7 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-       // ICHANGED 連想ノートリストから新しいタブで開く
+       // 連想ノートリストから新しいタブで開く
        @SuppressWarnings("unused")
        private void openNewTabFromRNL(){
                if(rensoNotePressedItemGuid != null){
@@ -4736,8 +4762,7 @@ public class NeverNote extends QMainWindow{
                        conn.getHistoryTable().addHistory("rensoItemClick", prevCurrentNoteGuid, rensoNotePressedItemGuid);
                }
        }
-
-       // ICHANGED
+       
        private void openTabEditor(String guid) {
                
                Note note = conn.getNoteTable().getNote(guid, true, true, false, true, true);
@@ -4745,6 +4770,11 @@ public class NeverNote extends QMainWindow{
                TabBrowse newBrowser = new TabBrowse(conn, tabBrowser, cbObserver);
                showEditorButtons(newBrowser.getBrowserWindow());
                
+               String noteTitle = note.getTitle();
+               int index = tabBrowser.addNewTab(newBrowser, noteTitle);
+               tabWindows.put(index, newBrowser);
+               noteDirty.put(index, false);
+               
                // noteTableViewの選択を変更するとselectionChangedが発生してしまうので一度切断
                noteTableView.selectionModel().selectionChanged.disconnect(this, "noteTableSelection()");
                loadNoteBrowserInformation(newBrowser.getBrowserWindow(), guid, note);
@@ -4753,10 +4783,6 @@ public class NeverNote extends QMainWindow{
                
                setupBrowserWindowListeners(newBrowser.getBrowserWindow(), false);
                
-               String noteTitle = note.getTitle();
-               int index = tabBrowser.addNewTab(newBrowser, noteTitle);
-               tabWindows.put(index, newBrowser);
-               
                // ExtendedInformationを必要があれば表示する
                toggleNoteInformation();
                // Sourceを必要があれば表示する
@@ -4782,22 +4808,28 @@ public class NeverNote extends QMainWindow{
                        }
                }
        }
+       
+       // タブが閉じられた
+       @SuppressWarnings("unused")
+       private void tabCloseRequested(int index) {
+               tabWindowClosing((TabBrowse)tabBrowser.widget(index));
+       }
 
-       // ICHANGED タブが閉じられた
-       private void tabWindowClosing(int index) {
+       // タブが閉じられた
+       private void tabWindowClosing(TabBrowse tab) {
                // タブが1つしかなかったら閉じない
                if (tabBrowser.count() <= 1) {
                        return;
                }
 
-               TabBrowse t = (TabBrowse) tabBrowser.widget(index);
-               String guid = t.getBrowserWindow().getNote().getGuid();
-               String content = t.getBrowserWindow().getContent();
-               BrowserWindow browser = t.getBrowserWindow();
-               // ノートが変更されていたら保存
-               if (t.getNoteDirty()) {
-                       saveNoteTabBrowser(guid, content, true, browser);
-               }
+               int index = tabBrowser.indexOf(tab);
+//             String guid = tab.getBrowserWindow().getNote().getGuid();
+//             String content = tab.getBrowserWindow().getContent();
+               BrowserWindow browser = tab.getBrowserWindow();
+//             // ノートが変更されていたら保存
+//             if (tab.getNoteDirty()) {
+//                     saveNoteTabBrowser(guid, content, true, browser);
+//             }
 
                // シグナル切断
                browser.noteSignal.tagsChanged.disconnect();
@@ -4810,6 +4842,9 @@ public class NeverNote extends QMainWindow{
                // ノートを削除
                tabWindows.remove(index);
                tabBrowser.removeTab(index);
+               noteDirty.remove(index);
+               inkNote.remove(index);
+               readOnly.remove(index);
 
                // 履歴記録のハッシュマップを削除
                historyGuids.remove(index);
@@ -4819,9 +4854,21 @@ public class NeverNote extends QMainWindow{
                // タブのインデックスを更新(削除によって空いた部分を詰める)
                for(int i = index ; tabWindows.containsKey(i + 1) ; i++){
                        // tabWindows
-                       TabBrowse tab = tabWindows.get(i + 1);
-                       tabWindows.put(i, tab);
+                       TabBrowse nextTab = tabWindows.get(i + 1);
+                       tabWindows.put(i, nextTab);
                        tabWindows.remove(i + 1);
+                       // noteDirty
+                       boolean isNoteDirty = noteDirty.get(i + 1);
+                       noteDirty.put(i, isNoteDirty);
+                       noteDirty.remove(i + 1);
+                       // inkNote
+                       boolean isInkNote = inkNote.get(i + 1);
+                       inkNote.put(i, isInkNote);
+                       inkNote.remove(i + 1);
+                       // readOnly
+                       boolean isReadOnly = readOnly.get(i + 1);
+                       readOnly.put(i, isReadOnly);
+                       readOnly.remove(i + 1);
                        // historyGuids
                        ArrayList<String> histGuids = historyGuids.get(i + 1);
                        historyGuids.put(i, histGuids);
@@ -4836,6 +4883,11 @@ public class NeverNote extends QMainWindow{
                        fromHistory.remove(i + 1);
                }
                
+               // タブが残り1つになったら、閉じるボタンを消す
+               if (tabBrowser.count() == 1) {
+                       tabBrowser.hideTabCloseButton(0);
+               }
+               
                // タブの閉じるボタンを押すと、tabWindowClosingより先にtabWindowChangedが呼ばれてしまうので、手動で呼びなおす
                tabWindowChanged(tabBrowser.currentIndex());
        }
@@ -4844,17 +4896,26 @@ public class NeverNote extends QMainWindow{
        private void noteAddNewTab() {
                saveNote();
                
+               // ノートを何も開いていないときは現在のタブにノート追加
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       addNote();
+                       return;
+               }
+               
                // ノート追加前に開いていたノートとの関連性を記録するためにguidをとっておく
                TabBrowse prevTab = (TabBrowse)tabBrowser.currentWidget();
-               String prevTabGuid = prevTab.getBrowserWindow().getNote().getGuid();
+               String prevTabGuid = null;
+               if (prevTab.getBrowserWindow() != null && prevTab.getBrowserWindow().getNote() != null) {
+                       prevTabGuid = prevTab.getBrowserWindow().getNote().getGuid();
+               }
                
                openEmptyTabEditor();
                addNote();
                
                // 追加されたノートのguidを取得し、ノート追加操作履歴としてデータベースに登録
-               TabBrowse addedTab = (TabBrowse)tabBrowser.currentWidget();
-               String addedTabGuid = addedTab.getBrowserWindow().getNote().getGuid();
                if (prevTabGuid != null && !prevTabGuid.equals("")) {
+                       TabBrowse addedTab = (TabBrowse)tabBrowser.currentWidget();
+                       String addedTabGuid = addedTab.getBrowserWindow().getNote().getGuid();
                        if (addedTabGuid != null && !addedTabGuid.equals("")) {
                                if (!prevTabGuid.equals(addedTabGuid)) {
                                        conn.getHistoryTable().addHistory("addNewNote", prevTabGuid, addedTabGuid);
@@ -4863,7 +4924,6 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-       // ICHANGED
        private void openEmptyTabEditor() {
                // 新しいタブエディタを作成
                TabBrowse newBrowser = new TabBrowse(conn, tabBrowser, cbObserver);
@@ -4873,6 +4933,7 @@ public class NeverNote extends QMainWindow{
                
                int index = tabBrowser.addNewTab(newBrowser, "");
                tabWindows.put(index, newBrowser);
+               noteDirty.put(index, false);
                
                // ExtendedInformationを必要があれば表示する
                toggleNoteInformation();
@@ -4896,60 +4957,76 @@ public class NeverNote extends QMainWindow{
     //***************************************************************
     //***************************************************************    
        private void setNoteDirty() {
+               for (String guid: selectedNoteGUIDs) {
+                       setNoteDirty(guid);
+               }
+       }
+       
+       private void setNoteDirty(String targetGuid) {
                logger.log(logger.EXTREME, "Entering NeverNote.setNoteDirty()");
                
                // Find if the note is being edited externally.  If it is, update it.
-               if (externalWindows.containsKey(currentNoteGuid)) {
+               if (externalWindows.containsKey(targetGuid)) {
                        QTextCodec codec = QTextCodec.codecForName("UTF-8");
                QByteArray unicode =  codec.fromUnicode(browserWindow.getContent());
-                       ExternalBrowse window = externalWindows.get(currentNoteGuid);
+                       ExternalBrowse window = externalWindows.get(targetGuid);
                window.getBrowserWindow().setContent(unicode);
                }
                
-               // ICHANGED ↓↓↓ここから↓↓↓
                // 他のタブで同じノートを開いていないか探す。もしあったら、内容を更新する。
-               Collection<TabBrowse> tabBrowsers = tabWindows.values();
-               Iterator<TabBrowse> tabIterator = tabBrowsers.iterator();
                Collection<Integer> tabIndexes = tabWindows.keySet();
                Iterator<Integer>       indexIterator = tabIndexes.iterator();
                
-               while (tabIterator.hasNext()) {
-                       TabBrowse tab = tabIterator.next();
+               for (TabBrowse tab: tabWindows.values()) {
                        int index = indexIterator.next();
                        String guid = tab.getBrowserWindow().getNote().getGuid();
                        
                        QTextCodec codec = QTextCodec.codecForName("UTF-8");
                        QByteArray unicode = codec.fromUnicode(browserWindow.getContent());
                        
-                       if (guid.equals(currentNoteGuid)) {
+                       if (guid.equals(guid)) {
                                if (index != tabBrowser.currentIndex()) {
                                        TabBrowse window = tabWindows.get(index);
                                        window.getBrowserWindow().setContent(unicode);
                                }
                        }
                }
-               // ICHANGED ↑↑↑ここまで↑↑↑
                
+               // ターゲットノートがタブで開かれていて、かつDirty = trueかどうかを取得する
                // If the note is dirty, then it is unsynchronized by default.
-               if (noteDirty) 
+               int index = -1;
+               boolean isNoteDirty = false;
+               for (TabBrowse tab: tabWindows.values()) {
+                       if (tab.getBrowserWindow().getNote().getGuid().equals(targetGuid)) {
+                               index = tabBrowser.indexOf(tab);
+                               isNoteDirty = noteDirty.get(index);
+                               break;
+                       }
+               }
+               if (isNoteDirty) {
                        return;
+               }
                
                // Set the note as dirty and check if its status is synchronized in the display table
-               noteDirty = true;
-               if (listManager.getNoteMetadata().containsKey(currentNoteGuid) && 
-                               listManager.getNoteMetadata().get(currentNoteGuid).isDirty()) {
+               // まだダーティでなく、かつタブで開かれている場合にnoteDirty = trueにする
+               if (index >= 0) {
+                       noteDirty.put(index, true);
+               }
+
+               if (listManager.getNoteMetadata().containsKey(targetGuid) &&
+                               listManager.getNoteMetadata().get(targetGuid).isDirty()) {
                                return;
                }
                
                // If this wasn't already marked as unsynchronized, then we need to update the table
-               listManager.getNoteTableModel().updateNoteSyncStatus(currentNoteGuid, false);
-//     listManager.getUnsynchronizedNotes().add(currentNoteGuid);
+               listManager.getNoteTableModel().updateNoteSyncStatus(targetGuid, false);
+//     listManager.getUnsynchronizedNotes().add(targetGuid);
        for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
                QModelIndex modelIndex =  listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
                if (modelIndex != null) {
                        SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
                        String tableGuid =  (String)ix.values().toArray()[0];
-                       if (tableGuid.equals(currentNoteGuid)) {
+                       if (tableGuid.equals(targetGuid)) {
                                listManager.getNoteTableModel().proxyModel.setData(i, Global.noteTableSynchronizedPosition, "false");
                                return;
                        }
@@ -4965,7 +5042,8 @@ public class NeverNote extends QMainWindow{
        noteCache.remove(guid);
                noteCache.put(guid, unicode.toString());
        if (guid.equals(currentNoteGuid)) {
-               noteDirty = true;
+               int index = tabBrowser.currentIndex();
+               noteDirty.put(index, true);
                browserWindow.setContent(unicode);
        } 
        if (save) {
@@ -4975,25 +5053,35 @@ public class NeverNote extends QMainWindow{
        
     }
     
-       // ICHANGED
-       private void saveNoteTabBrowser(String guid, String content, Boolean save,
-                       BrowserWindow browser) {
-               QTextCodec codec = QTextCodec.codecForName("UTF-8");
-               QByteArray unicode = codec.fromUnicode(content);
-               noteCache.remove(guid);
-               noteCache.put(guid, unicode.toString());
-               if (save) {
-                       thumbnailRunner.addWork("GENERATE " + guid);
-                       saveNote(guid, browser);
-               }
-       }
+//     private void saveNoteTabBrowser(String guid, String content, Boolean save,
+//                     BrowserWindow browser) {
+//             QTextCodec codec = QTextCodec.codecForName("UTF-8");
+//             QByteArray unicode = codec.fromUnicode(content);
+//             noteCache.remove(guid);
+//             noteCache.put(guid, unicode.toString());
+//             if (save) {
+//                     thumbnailRunner.addWork("GENERATE " + guid);
+//                     saveNote(guid, browser);
+//             }
+//     }
        
     private void saveNote() {
-       if (noteDirty) {
-               saveNote(currentNoteGuid, browserWindow);
-               thumbnailRunner.addWork("GENERATE "+ currentNoteGuid);
-               noteDirty = false;
-       } 
+       // すべてのタブに対して、Dirtyを確認し、trueならセーブする
+       Collection<Integer> dirtyIndex = noteDirty.keySet();
+       Iterator<Integer> indexIterator = dirtyIndex.iterator();
+       for (boolean isNoteDirty: noteDirty.values()) {
+               int index = indexIterator.next();
+               if (isNoteDirty) {
+                       if (index < 0) {
+                               return;
+                       }
+                       BrowserWindow b = tabWindows.get(index).getBrowserWindow();
+                       String guid = b.getNote().getGuid();
+                       saveNote(guid, b);
+                       thumbnailRunner.addWork("GENERATE "+ guid);
+                       noteDirty.put(index, false);
+               }
+       }
     }
     private void saveNote(String guid, BrowserWindow window) {
                logger.log(logger.EXTREME, "Inside NeverNote.saveNote()");
@@ -5029,12 +5117,14 @@ public class NeverNote extends QMainWindow{
                        browserWindow.setEnabled(false);
                        return;
                }
-               inkNote = false;
-               readOnly = false;
-               if (Global.showDeleted || currentNoteGuid == null || currentNoteGuid.equals(""))
-                       readOnly = true;
+               inkNote.put(tabBrowser.currentIndex(), false);
+               readOnly.put(tabBrowser.currentIndex(), false);
+               
+               if (Global.showDeleted || currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       readOnly.put(tabBrowser.currentIndex(), true);
+               }
                Global.cryptCounter =0;
-               if (readOnly) {
+               if (readOnly.get(tabBrowser.currentIndex())) {
                        browserWindow.setReadOnly(true);
                }
                
@@ -5050,7 +5140,6 @@ public class NeverNote extends QMainWindow{
                        return;
                }
                
-               // ICHANGED
                tabBrowser.setTabTitle(tabBrowser.currentIndex(), currentNote.getTitle());
                
                loadNoteBrowserInformation(browserWindow, currentNoteGuid, currentNote);
@@ -5061,6 +5150,16 @@ public class NeverNote extends QMainWindow{
                formatter.setNote(note, Global.pdfPreview());
                formatter.setHighlight(listManager.getEnSearch());
                QByteArray js;
+               int tabIndex = -1;
+               
+               // 対象のタブインデックスを取得
+               for (TabBrowse tab: tabWindows.values()) {
+                       if (tab.getBrowserWindow() == browser) {
+                               tabIndex = tabBrowser.indexOf(tab);
+                               break;
+                       }
+               }
+               
                if (!noteCache.containsKey(guid)) {
                        js = new QByteArray();
                        // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly 
@@ -5085,7 +5184,7 @@ public class NeverNote extends QMainWindow{
                        noteCache.put(guid, js.toString());
 
                        if (formatter.resourceError)
-                               resourceErrorMessage();
+                               resourceErrorMessage(tabIndex);
                        if (formatter.formatError) {
                                waitCursor(false);
                             QMessageBox.information(this, tr("Error"),
@@ -5093,35 +5192,50 @@ public class NeverNote extends QMainWindow{
                                                " To protect your data this note is being marked as read-only."));      
                             waitCursor(true);
                        }
-                       readOnly = formatter.readOnly;
-                       inkNote = formatter.inkNote;
-                       if (readOnly)
+                       
+                       if (tabIndex >= 0) {
+                               readOnly.put(tabIndex, formatter.readOnly);
+                               inkNote.put(tabIndex, formatter.inkNote);
+                       } 
+                       
+                       if (tabIndex >= 0 && readOnly.get(tabIndex)) {
                                readOnlyCache.put(guid, true);
-                       if (inkNote)
+                       }
+                       if (tabIndex >= 0 && inkNote.get(tabIndex)) {
                                inkNoteCache.put(guid, true);
+                       }
+                       
                } else {
                        logger.log(logger.HIGH, "Note content is being pulled from the cache");
                        String cachedContent = formatter.modifyCachedTodoTags(noteCache.get(guid));
                        js = new QByteArray(cachedContent);
                        browser.setContent(js);
-                       if (readOnlyCache.containsKey(guid))
-                                       readOnly = true;
-                       if (inkNoteCache.containsKey(guid))
-                                       inkNote = true;
+                       if (readOnlyCache.containsKey(guid) && tabIndex >= 0) {
+                               readOnly.put(tabIndex, true);
+                       } else {
+                               readOnly.put(tabIndex, false);
+                       }
+                       if (inkNoteCache.containsKey(guid) && tabIndex >= 0) {
+                               inkNote.put(tabIndex, true);
+                       } else {
+                               inkNote.put(tabIndex, false);
+                       }
                }
                if (conn.getNoteTable().isThumbnailNeeded(guid)) {
                        thumbnailHTMLReady(guid, js, Global.calculateThumbnailZoom(js.toString()));
                }
-               if (readOnly || inkNote || 
-                               (note.getAttributes() != null && note.getAttributes().getContentClass() != null && note.getAttributes().getContentClass() != ""))
+               if (tabIndex >= 0 && (readOnly.get(tabIndex) || inkNote.get(tabIndex) || 
+                               (note.getAttributes() != null && note.getAttributes().getContentClass() != null && note.getAttributes().getContentClass() != "")))
                        browser.getBrowser().page().setContentEditable(false);  // We don't allow editing of ink notes
                else
                        browser.getBrowser().page().setContentEditable(true);
-               browser.setReadOnly(readOnly);
-               deleteButton.setEnabled(!readOnly);
-               tagButton.setEnabled(!readOnly);
-               menuBar.noteDelete.setEnabled(!readOnly);
-               menuBar.noteTags.setEnabled(!readOnly);
+               if (tabIndex >= 0) {
+                       browser.setReadOnly(readOnly.get(tabIndex));
+                       deleteButton.setEnabled(!readOnly.get(tabIndex));
+                       tagButton.setEnabled(!readOnly.get(tabIndex));
+                       menuBar.noteDelete.setEnabled(!readOnly.get(tabIndex));
+                       menuBar.noteTags.setEnabled(!readOnly.get(tabIndex));
+               }
                browser.setNote(note);
                
                if (note != null && note.getNotebookGuid() != null && 
@@ -5162,7 +5276,14 @@ public class NeverNote extends QMainWindow{
                browser.setAllTags(tagList);
                
                browser.setCurrentTags(note.getTagNames());
-               noteDirty = false;
+               for (TabBrowse tab: tabWindows.values()) {
+                       if (tab.getBrowserWindow().getNote().getGuid().equals(guid)) {
+                               int index = tabBrowser.indexOf(tab);
+                               noteDirty.put(index, false);
+                               break;
+                       }
+               }
+               
                scrollToGuid(guid);
                
                browser.loadingData(false);
@@ -5176,7 +5297,6 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.HIGH, "Leaving NeverNote.refreshEvernoteNote");
        }
        
-       // ICHANGED
        @SuppressWarnings("unused")
        private void toggleNoteAttributes() {
                menuBar.noteAttributes.setChecked(!menuBar.noteAttributes.isChecked());
@@ -5187,7 +5307,6 @@ public class NeverNote extends QMainWindow{
        private void toggleNoteInformation() {
                logger.log(logger.HIGH, "Entering NeverNote.toggleNoteInformation");
        
-       // ICHANGED
                boolean isChecked = menuBar.noteAttributes.isChecked();
                
        for(int i = 0; i < tabBrowser.count(); i++){
@@ -5285,6 +5404,7 @@ public class NeverNote extends QMainWindow{
                return;
        if (currentNoteGuid.equals(""))
                return;
+       
        String title = null;
        if (selectedNoteGUIDs.size() == 1)
                title = conn.getNoteTable().getNote(selectedNoteGUIDs.get(0),false,false,false,false,false).getTitle();
@@ -5307,11 +5427,17 @@ public class NeverNote extends QMainWindow{
                                        return;
                        }
                }
-               if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals("")) 
+               if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals("")) {
                        selectedNoteGUIDs.add(currentNoteGuid);
-               for (int i=0; i<selectedNoteGUIDs.size(); i++) {
-                       listManager.deleteNote(selectedNoteGUIDs.get(i));
                }
+               
+               List<String> deleteNoteGUIDs = new ArrayList<String>(selectedNoteGUIDs);        // タブを閉じるとselectedNoteGUIDsが変わってしまうのでその前にコピー
+               closeTabs(selectedNoteGUIDs);
+               for (String guid : deleteNoteGUIDs) {
+                       listManager.deleteNote(guid);
+               }
+               
+               closeExternalWindows(deleteNoteGUIDs);
        } else { 
                // If we are deleting from the trash.
                if (Global.verifyDelete()) {
@@ -5332,86 +5458,84 @@ public class NeverNote extends QMainWindow{
                }
                if (selectedNoteGUIDs.size() == 0 && !currentNoteGuid.equals("")) 
                        selectedNoteGUIDs.add(currentNoteGuid);
-               for (int i=selectedNoteGUIDs.size()-1; i>=0; i--) {
+               
+               List<String> deleteNoteGUIDs = new ArrayList<String>(selectedNoteGUIDs);        // タブを閉じるとselectedNoteGUIDsが変わってしまうのでその前にコピー
+               for (int i=deleteNoteGUIDs.size()-1; i>=0; i--) {
                        for (int j=listManager.getNoteTableModel().rowCount()-1; j>=0; j--) {
                        QModelIndex modelIndex =  listManager.getNoteTableModel().index(j, Global.noteTableGuidPosition);
                        if (modelIndex != null) {
                                SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
                                String tableGuid =  (String)ix.values().toArray()[0];
-                               if (tableGuid.equals(selectedNoteGUIDs.get(i))) {
+                               if (tableGuid.equals(deleteNoteGUIDs.get(i))) {
                                        listManager.getNoteTableModel().removeRow(j);
                                        j=-1;
                                }
                        }
                }
-                       listManager.expungeNote(selectedNoteGUIDs.get(i));
-                       
-                       // ICHANGED
-                       conn.getHistoryTable().expungeHistory(selectedNoteGUIDs.get(i));
-                       conn.getExcludedTable().expungeExcludedNote(selectedNoteGUIDs.get(i));
-                       conn.getStaredTable().expungeStaredNote(selectedNoteGUIDs.get(i));
+                       closeTab(deleteNoteGUIDs.get(i));
+                       listManager.expungeNote(deleteNoteGUIDs.get(i));
                        
+                       conn.getHistoryTable().expungeHistory(deleteNoteGUIDs.get(i));
+                       conn.getExcludedTable().expungeExcludedNote(deleteNoteGUIDs.get(i));
+                       conn.getStaredTable().expungeStaredNote(deleteNoteGUIDs.get(i));
                }
+               
+               closeExternalWindows(deleteNoteGUIDs);
        }
-       currentNoteGuid = "";
        
-       // ICHANGED ↓↓↓ここから↓↓↓
-               // 削除したノートを外部ウィンドウで開いていたら、閉じる
-               Collection<ExternalBrowse>      windows = externalWindows.values();
-               Iterator<ExternalBrowse>        windowIterator = windows.iterator();
-               Collection<String>                      guids = externalWindows.keySet();
-               Iterator<String>                        guidIterator = guids.iterator();
-               List<ExternalBrowse>            closeWindows = new ArrayList<ExternalBrowse>(); // イテレータ操作中に中身をいじっちゃダメなので
-               
-               while (windowIterator.hasNext()) {
-                       ExternalBrowse browser = windowIterator.next();
-                       String guid = guidIterator.next();
-                       
-                       for (int i = 0; i < selectedNoteGUIDs.size(); i++) {
-                               if (guid.equals(selectedNoteGUIDs.get(i))) {
-                                       closeWindows.add(browser);
-                               }
-                       }
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
                }
                
-               for (int i = closeWindows.size() - 1; i >= 0; i--) {
-                       closeWindows.get(i).close();
-               }
-               // ICHANGED ↑↑↑ここまで↑↑↑
-               
-       // ICHANGED ↓↓↓ここから↓↓↓
-       // 削除したノートをタブで開いていたら、閉じる
-               Collection<TabBrowse> tabBrowsers = tabWindows.values();
-               Iterator<TabBrowse> tabIterator = tabBrowsers.iterator();
-               Collection<Integer> tabIndexes = tabWindows.keySet();
-               Iterator<Integer>       indexIterator = tabIndexes.iterator();
-               List<Integer> closeIndexes = new ArrayList<Integer>();  //イテレータ操作中に中身をいじっちゃダメなので
-
-               while (tabIterator.hasNext()) {
-                       TabBrowse tab = tabIterator.next();
-                       int index = indexIterator.next();
-                       String guid = tab.getBrowserWindow().getNote().getGuid();
-                       
-                       for(int i = 0; i < selectedNoteGUIDs.size(); i++){
-                               if(guid.equals(selectedNoteGUIDs.get(i))){
-                                       closeIndexes.add(index);
-                               }
-                       }
-               }
-               
-               for(int i = closeIndexes.size() - 1; i >= 0; i--){
-                       tabWindowClosing(closeIndexes.get(i));
-               }
-               // ICHANGED ↑↑↑ここまで↑↑↑              
-       
        listManager.loadNotesIndex();
        noteIndexUpdated(false);
        refreshEvernoteNote(true);
        scrollToGuid(currentNoteGuid);
        logger.log(logger.HIGH, "Leaving NeverNote.deleteNote");
     }
+    
+    // 対象ノートをタブで開いていたら閉じる
+    private void closeTabs(List<String> noteGUIDs) {
+       for (String guid : noteGUIDs) {
+               closeTab(guid);
+       }
+    }
+    
+    // 対象ノートをタブで開いていたら閉じる
+    private void closeTab(String noteGUID) {
+       List<TabBrowse> closeTabs = new ArrayList<TabBrowse>();
+       
+       for (TabBrowse tab : tabWindows.values()) {
+               String guid = tab.getBrowserWindow().getNote().getGuid();
+               
+               if (guid.equals(noteGUID)) {
+                       closeTabs.add(tab);
+               }
+       }
+       
+       for (TabBrowse tab : closeTabs) {
+               tabWindowClosing(tab);
+       }
+    }
+    
+    // 対象ノートを外部ウィンドウで開いていたら閉じる
+    private void closeExternalWindows(List<String> noteGUIDs) {
+               List<ExternalBrowse> closeWindows = new ArrayList<ExternalBrowse>();
+               
+               for (Map.Entry<String, ExternalBrowse> e : externalWindows.entrySet()) {
+                       for (String guid : noteGUIDs) {
+                               if (guid.equals(e.getKey())) {
+                                       closeWindows.add(e.getValue());
+                               }
+                       }
+               }
+               
+               for (ExternalBrowse externalBrowse : closeWindows) {
+                       externalBrowse.close();
+               }
+    }
+    
     // Add a new note
-    // ICHANGED @SuppressWarnings("unused") を削除
        private void addNote() {
        logger.log(logger.HIGH, "Inside NeverNote.addNote");
 //     browserWindow.setEnabled(true);
@@ -5513,7 +5637,6 @@ public class NeverNote extends QMainWindow{
        listManager.addNote(newNote, metadata);
 //     noteTableView.insertRow(newNote, true, -1);
        
-       // ICHANGED
        String prevCurrentNoteGuid = new String(currentNoteGuid);
        
        currentNote = newNote;
@@ -5521,19 +5644,19 @@ public class NeverNote extends QMainWindow{
        // IFIXED こいつのせいで、ノート追加時にcurrentNoteGuidが更新されないので消す
        // noteTableView.clearSelection();
        
-       refreshEvernoteNote(true);
-       listManager.countNotebookResults(listManager.getNoteIndex());
-       browserWindow.titleLabel.setFocus();
-       browserWindow.titleLabel.selectAll();
-//     notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
-       
-       // ICHANGED 新規に作成したノートとそれまで開いていたノートの関連性を追加
+       // 新規に作成したノートとそれまで開いていたノートの関連性を追加
        if (prevCurrentNoteGuid != null && !prevCurrentNoteGuid.equals("")) {
                if (currentNoteGuid != null && !currentNoteGuid.equals("")) {
                        conn.getHistoryTable().addHistory("addNewNote", prevCurrentNoteGuid, currentNoteGuid);
                }
        }
        
+       refreshEvernoteNote(true);
+       listManager.countNotebookResults(listManager.getNoteIndex());
+       browserWindow.titleLabel.setFocus();
+       browserWindow.titleLabel.selectAll();
+//     notebookTree.updateCounts(listManager.getNotebookIndex(), listManager.getNotebookCounter());
+       
        // If the window is hidden, then we want to popup this in an external window & 
        if (!isVisible())
                listDoubleClick();
@@ -5613,10 +5736,11 @@ public class NeverNote extends QMainWindow{
                        externalWindows.put(newGuid, b);
                }
        
-               // ICHANGED
                for(int i = 0; i < tabBrowser.count(); i++){
                        TabBrowse b = (TabBrowse)tabBrowser.widget(i);
-                       b.getBrowserWindow().getNote().setGuid(newGuid);
+                       if (b.getBrowserWindow().getNote().getGuid().equals(oldGuid)) {
+                               b.getBrowserWindow().getNote().setGuid(newGuid);
+                       }
                }
 
        for (int i=0; i<listManager.getNoteIndex().size(); i++) {
@@ -5635,7 +5759,7 @@ public class NeverNote extends QMainWindow{
     }
        
     // Toggle the note editor button bar
-    // ICHANGED すべてのタブに
+    // すべてのタブに
     private void toggleEditorButtonBar() {
        boolean isChecked = menuBar.showEditorBar.isChecked();
        
@@ -5753,7 +5877,6 @@ public class NeverNote extends QMainWindow{
                }
                newNote.setResources(resList);
                
-               // ICHANGED
                // 操作履歴と除外ノートとスター付きノートも複製する
                if(Global.getDuplicateRensoNote()) {
                        conn.getHistoryTable().duplicateHistory(newGuid, oldNote.getGuid());
@@ -5791,7 +5914,7 @@ public class NeverNote extends QMainWindow{
                notebookTreeSelection();
                refreshEvernoteNote(true);
                
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                if (!rensoNoteListDock.isEnabled()) {
                        rensoNoteListDock.setEnabled(true);
                }
@@ -5820,7 +5943,7 @@ public class NeverNote extends QMainWindow{
                mergeNoteContents(masterGuid, sources);
                currentNoteGuid = masterGuid;
                
-               // ICHANGED 操作履歴と除外ノートとスター付きノートをマージ
+               // 操作履歴と除外ノートとスター付きノートをマージ
                if(Global.getMergeRensoNote()) {
                        for (int i = 0; i < sources.size(); i++) {
                                String childGuid = sources.get(i);
@@ -5834,13 +5957,12 @@ public class NeverNote extends QMainWindow{
                        }
                }
                
-       // ICHANGED ↓↓↓ここから↓↓↓
                // マージしたノート(child)を外部ウィンドウで開いていたら、閉じる
                Collection<ExternalBrowse>      windows = externalWindows.values();
                Iterator<ExternalBrowse>        windowIterator = windows.iterator();
                Collection<String>                      guids = externalWindows.keySet();
                Iterator<String>                        guidIterator = guids.iterator();
-               List<ExternalBrowse>            closeWindows = new ArrayList<ExternalBrowse>(); // イテレータ操作中に中身をいじっちゃダメなので
+               List<ExternalBrowse>            closeWindows = new ArrayList<ExternalBrowse>();
                
                while (windowIterator.hasNext()) {
                        ExternalBrowse browser = windowIterator.next();
@@ -5856,36 +5978,25 @@ public class NeverNote extends QMainWindow{
                for (int i = closeWindows.size() - 1; i >= 0; i--) {
                        closeWindows.get(i).close();
                }
-               // ICHANGED ↑↑↑ここまで↑↑↑
                
-       // ICHANGED ↓↓↓ここから↓↓↓
        // マージしたノート(child)をタブで開いていたら、閉じる
-               Collection<TabBrowse> tabBrowsers = tabWindows.values();
-               Iterator<TabBrowse> tabIterator = tabBrowsers.iterator();
-               Collection<Integer> tabIndexes = tabWindows.keySet();
-               Iterator<Integer>       indexIterator = tabIndexes.iterator();
-               List<Integer> closeIndexes = new ArrayList<Integer>();  //イテレータ操作中に中身をいじっちゃダメなので
-
-               while (tabIterator.hasNext()) {
-                       TabBrowse tab = tabIterator.next();
-                       int tabIndex = indexIterator.next();
+               List<TabBrowse> closeTabs = new ArrayList<TabBrowse>();
+               for (TabBrowse tab : tabWindows.values()) {
                        String guid = tab.getBrowserWindow().getNote().getGuid();
                        
-                       for(int i = 0; i < sources.size(); i++){
-                               if(guid.equals(sources.get(i))){
-                                       closeIndexes.add(tabIndex);
+                       for (String source : sources) {
+                               if (guid.equals(source)) {
+                                       closeTabs.add(tab);
                                }
                        }
                }
-               
-               for(int i = closeIndexes.size() - 1; i >= 0; i--){
-                       tabWindowClosing(closeIndexes.get(i));
+               for (TabBrowse tab : closeTabs) {
+                       tabWindowClosing(tab);
                }
-               // ICHANGED ↑↑↑ここまで↑↑↑              
                
                noteIndexUpdated(false);
                // IFIXED 
-               // ICHANGED マージ後の新しいノートコンテンツを表示するためキャッシュを削除
+               // マージ後の新しいノートコンテンツを表示するためキャッシュを削除
                noteCache.remove(masterGuid);
                
                refreshEvernoteNote(true);
@@ -6052,6 +6163,9 @@ public class NeverNote extends QMainWindow{
                        setMessage("EDAMUserException: " +e.getMessage());
                        return;
                } catch (EDAMSystemException e) {
+                       if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                               QMessageBox.warning(this, tr("Rate limit reached"), tr("Evernote usage has been temporarily exceeded. Please try again in ") +  + e.getRateLimitDuration() + tr(" seconds."));
+                       }
                        setMessage("EDAMSystemException: " +e.getMessage());
                        return;
                } catch (EDAMNotFoundException e) {
@@ -6065,7 +6179,6 @@ public class NeverNote extends QMainWindow{
                
                // If we've gotten this far, we have a good note.
                if (historyWindow == null) {
-                       // ICHANGED
                        historyWindow = new OnlineNoteHistory(logger, conn, cbObserver);
                        
                        historyWindow.historyCombo.activated.connect(this, "reloadHistoryWindow(String)");
@@ -6112,6 +6225,9 @@ public class NeverNote extends QMainWindow{
                                waitCursor(false);
                                return null;
                        } catch (EDAMSystemException e) {
+                               if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                                       QMessageBox.warning(this, tr("Rate limit reached"), tr("Evernote usage has been temporarily exceeded. Please try again in ") +  + e.getRateLimitDuration() + tr(" seconds."));
+                               }
                                setMessage("EDAMSystemException: " +e.getMessage());
                                waitCursor(false);
                                return null;
@@ -6176,6 +6292,9 @@ public class NeverNote extends QMainWindow{
                        setMessage("EDAMUserException: " +e.getMessage());
                        return;
                } catch (EDAMSystemException e) {
+                       if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                               QMessageBox.warning(this, tr("Rate limit reached"), tr("Evernote usage has been temporarily exceeded. Please try again in ") +  + e.getRateLimitDuration() + tr(" seconds."));
+                       }
                        setMessage("EDAMSystemException: " +e.getMessage());
                        return;
                } catch (TException e) {
@@ -6301,8 +6420,11 @@ public class NeverNote extends QMainWindow{
        //**********************************************************
        //**********************************************************
        // An error has happended fetching a resource.  let the user know
-       private void resourceErrorMessage() {
-               if (inkNote)
+       private void resourceErrorMessage(int tabIndex) {
+               if (tabIndex < 0) {
+                       return;
+               }
+               if (inkNote.get(tabIndex))
                        return;
                waitCursor(false);
                QMessageBox.information(this, tr("DOUGH!!!"), tr("Well, this is embarrassing."+
@@ -6315,7 +6437,7 @@ public class NeverNote extends QMainWindow{
                "Don't get angry.  I'm doing it to prevent you from messing up\n"+
                "this note on the Evernote servers.  Sorry."+
                "\n\nP.S. You might want to re-synchronize to see if it corrects this problem.\nWho knows, you might get lucky."));
-               inkNote = true;
+               inkNote.put(tabIndex, true);
                browserWindow.setReadOnly(true);
                waitCursor(true);
        }
@@ -6421,7 +6543,22 @@ public class NeverNote extends QMainWindow{
        public void refreshLists() {
                logger.log(logger.EXTREME, "Entering NeverNote.refreshLists");
                updateQuotaBar();
-               listManager.refreshLists(currentNote, noteDirty, browserWindow.getContent());
+               // すべてのタブのノートを調べて、Dirtyならばセーブする。その後refreshListsする。
+               Collection<Integer> tabIndex = noteDirty.keySet();
+               Iterator<Integer> indexIterator = tabIndex.iterator();
+               HashMap<Integer, Note> saveNotes = new HashMap<Integer, Note>();
+               HashMap<Integer, String> saveContents = new HashMap<Integer, String>();
+               for (boolean isNoteDirty: noteDirty.values()) {
+                       int index = indexIterator.next();
+                       if (isNoteDirty) {
+                               saveNotes.put(index, tabWindows.get(index).getBrowserWindow().getNote());
+                               saveContents.put(index, tabWindows.get(index).getBrowserWindow().getContent());
+                       }
+               }
+               
+               listManager.saveUpdatedNotes(saveNotes, saveContents);
+               listManager.refreshLists();
+
                tagIndexUpdated(true);
                notebookIndexUpdated();
                savedSearchIndexUpdated();
@@ -6572,7 +6709,15 @@ public class NeverNote extends QMainWindow{
                } else
                        indexThreadDeadCount=0;
 
-               
+               if (!rensoNoteListDock.getRensoNoteList().getEnRelatedNotesThread().isAlive()) {
+                       enRelatedNotesThreadDeadCount++;
+                       if (enRelatedNotesThreadDeadCount > MAX && !disableENRelatedNotesThreadCheck) {
+                               QMessageBox.information(this, tr("A thread has died."), tr("It appears as the Evernote Related Notes thread has died.  I recommend "+
+                                       "checking stopping NeighborNote, saving the logs for later viewing, and restarting.  Sorry."));
+                               disableENRelatedNotesThreadCheck = true;
+                       }
+               } else
+                       enRelatedNotesThreadDeadCount=0;
        }
 
        private void thumbnailTimer() {
@@ -7248,7 +7393,7 @@ public class NeverNote extends QMainWindow{
        //* View / Hide source HTML for a note
        //*************************************************
        public void viewSource() {
-               // ICHANGED すべてのタブに対して
+               // すべてのタブに対して
        for(int i = 0; i < tabBrowser.count(); i++){
                BrowserWindow browser = ((TabBrowse) tabBrowser.widget(i)).getBrowserWindow();
                browser.showSource(menuBar.viewSource.isChecked());
@@ -7284,7 +7429,6 @@ public class NeverNote extends QMainWindow{
                blockSignals(false);
        }
        
-       // ICHANGED
        // タブが変更された
        private void tabWindowChanged(int index) {
                if (index < 0 || index >= tabBrowser.count()) {
@@ -7380,10 +7524,9 @@ public class NeverNote extends QMainWindow{
                refreshEvernoteNote(true);
 
                // 連想ノートリストを更新
-               rensoNoteList.refreshRensoNoteList(currentNoteGuid);
+               rensoNoteListDock.getRensoNoteList().refreshRensoNoteList(currentNoteGuid);
        }
        
-       // ICHANGD
        // 生存ノートテーブル→ゴミ箱(またはその逆)に切り替える
        private void switchNoteTable(boolean toDeleted) {
        clearNotebookFilter();
@@ -7398,6 +7541,10 @@ public class NeverNote extends QMainWindow{
        // toggle the add buttons
        newButton.setEnabled(!newButton.isEnabled());
        menuBar.noteAdd.setEnabled(newButton.isEnabled());
+       menuBar.noteAddNewTab.setEnabled(newButton.isEnabled());
+               if (currentNoteGuid == null || currentNoteGuid.equals("")) {
+                       menuBar.noteAddNewTab.setEnabled(false);
+               }
        menuBar.noteAdd.setVisible(true);
        
        if (!toDeleted) {       // 生存ノートテーブルへ
@@ -7407,7 +7554,7 @@ public class NeverNote extends QMainWindow{
                Global.showDeleted = false;
                menuBar.noteRestoreAction.setEnabled(false);
                menuBar.noteRestoreAction.setVisible(false);
-               // ICHANGED ゴミ箱から元の画面に戻す。連想ノートリストをONに。
+               // ゴミ箱から元の画面に戻す。連想ノートリストをONに。
                rensoNoteListDock.setEnabled(true);
        } else {        // ゴミ箱へ
                trashTree.itemSelectionChanged.disconnect(this, "trashTreeSelection()");
@@ -7416,7 +7563,7 @@ public class NeverNote extends QMainWindow{
                Global.showDeleted = true;
                menuBar.noteRestoreAction.setEnabled(true);
                menuBar.noteRestoreAction.setVisible(true);
-               // ICHANGED ゴミ箱を開く。連想ノートリストをOFFに。
+               // ゴミ箱を開く。連想ノートリストをOFFに。
                rensoNoteListDock.setEnabled(false);
        }
        
@@ -7430,13 +7577,12 @@ public class NeverNote extends QMainWindow{
        browserWindow.setReadOnly(!newButton.isEnabled());
        }
 
-       // ICHANGED
        // ユーザが連想ノートリストのアイテムを選択した時の処理
        @SuppressWarnings("unused")
        private void rensoNoteItemPressed(QListWidgetItem current) {
                logger.log(logger.HIGH, "Nevernote.rensoNoteSelectionChangeに入った");
 
-               rensoNotePressedItemGuid = rensoNoteList.getNoteGuid(current);
+               rensoNotePressedItemGuid = rensoNoteListDock.getRensoNoteList().getNoteGuid(current);
                
                // 右クリックだったら終了
                if (QApplication.mouseButtons().isSet(MouseButton.RightButton)) {
@@ -7456,7 +7602,7 @@ public class NeverNote extends QMainWindow{
                                String tableGuid = (String) ix.values().toArray()[0];
                                if (tableGuid.equals(rensoNotePressedItemGuid)) {
                                        noteTableView.selectRow(i);
-                                       return;
+                                       break;
                                }
                        }
                }
@@ -7467,7 +7613,6 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.HIGH, "Nevernote.rensoNoteSelectionChangeを出た");
        }
        
-       // ICHANGED
        // 関連ノートリストからノートを除外する
        @SuppressWarnings("unused")
        private void excludeNote() {
@@ -7477,7 +7622,6 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-       // ICHANGED
        // 関連ノートリストからノートを除外する
        private void excludeNote(String guid) {
                if (Global.verifyExclude()) {
@@ -7503,10 +7647,9 @@ public class NeverNote extends QMainWindow{
                // 除外ノートテーブルに追加
                conn.getExcludedTable().addExclusion(guid, currentNoteGuid);
                
-               rensoNoteList.refreshRensoNoteList(currentNoteGuid);
+               rensoNoteListDock.getRensoNoteList().refreshRensoNoteList(currentNoteGuid);
        }
        
-       // ICHANGED
        // 関連ノートリストのノートにスターを付ける
        @SuppressWarnings("unused")
        private void starNote() {
@@ -7516,16 +7659,14 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-       // ICHANGED
        // 関連ノートリストのノートにスターを付ける
        private void starNote(String guid) {
                // スター付きノートテーブルに追加
                conn.getStaredTable().addStaredItem(currentNoteGuid, guid);
                
-               rensoNoteList.refreshRensoNoteList(currentNoteGuid);
+               rensoNoteListDock.getRensoNoteList().refreshRensoNoteList(currentNoteGuid);
        }
        
-       // ICHANGED
        // 関連ノートリストのノートからスターを外す
        @SuppressWarnings("unused")
        private void unstarNote() {
@@ -7535,18 +7676,66 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-       // ICHANGED
        // 関連ノートリストのノートからスターを外す
        private void unstarNote(String guid) {
                // スター付きノートテーブルから削除
                conn.getStaredTable().removeStaredItem(currentNoteGuid, guid);
                
-               rensoNoteList.refreshRensoNoteList(currentNoteGuid);
+               rensoNoteListDock.getRensoNoteList().refreshRensoNoteList(currentNoteGuid);
        }
        
-       // ICHANGED
        // currentNoteGuidを返す
        public String getCurrentNoteGuid() {
                return currentNoteGuid;
        }
+       
+       @SuppressWarnings("unused")
+       // タブ入れ替えによってタブインデックスが変わったので、インデックスで管理しているハッシュマップ達も入れ替える
+       private void tabIndexChanged(int from, int to) {
+               // tabWindows
+               TabBrowse tab = tabWindows.get(from);
+               tabWindows.put(from, tabWindows.get(to));
+               tabWindows.put(to, tab);
+               // noteDirty
+               boolean isNoteDirty = noteDirty.get(from);
+               noteDirty.put(from, noteDirty.get(to));
+               noteDirty.put(to, isNoteDirty);
+               // inkNote
+               boolean isInkNote = inkNote.get(from);
+               inkNote.put(from, inkNote.get(to));
+               inkNote.put(to, isInkNote);
+               // readOnly
+               boolean isReadOnly = readOnly.get(from);
+               readOnly.put(from, readOnly.get(to));
+               readOnly.put(to, isReadOnly);
+               // historyGuids
+               ArrayList<String> histGuids = historyGuids.get(from);
+               historyGuids.put(from, historyGuids.get(to));
+               historyGuids.put(to, histGuids);
+               // historyPosition
+               int histPosition = historyPosition.get(from);
+               historyPosition.put(from, historyPosition.get(to));
+               historyPosition.put(to, histPosition);
+               // fromHistory
+               boolean fromHist = fromHistory.get(from);
+               fromHistory.put(from,  fromHistory.get(to));
+               fromHistory.put(to, fromHist);
+       }
+       
+       // 連想ノートリストのgetter
+       public RensoNoteList getRensoNoteList() {
+               return rensoNoteListDock.getRensoNoteList();
+       }
+       
+       // 帯域制限の超過をユーザに通知
+       @SuppressWarnings("unused")
+       private void informRateLimit(Integer rateLimitDuration) {
+               QMessageBox.warning(this, tr("Rate limit reached"), tr("Evernote usage has been temporarily exceeded. Please try again in ") +  + rateLimitDuration + tr(" seconds."));
+       }
+       
+       // ツールバーの「新規」ボタンの接続スロットを設定
+       public void connectNewButtonSlot(String slot) {
+               newButton.triggered.disconnect();
+               newButton.triggered.connect(this, slot);
+       }
 }