diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index b175a6e1..ff2eeaa7 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -43,6 +43,34 @@ void printStr(const TCHAR *str2print) ::MessageBox(NULL, str2print, TEXT(""), MB_OK); }; +std::string getFileContent(const TCHAR *file2read) +{ + const size_t blockSize = 256; + char data[blockSize]; + FILE *fp = generic_fopen(file2read, TEXT("rb")); + + _fseeki64 (fp , 0 , SEEK_END); + unsigned __int64 fileSize =_ftelli64(fp); + rewind(fp); + + size_t lenFile = fread(data, 1, blockSize, fp); + fclose(fp); + if (lenFile <= 0) return ""; + if (fileSize >= blockSize) + data[blockSize-1] = '\0'; + else + data[fileSize] = '\0'; + return data; +} + +void writeFileContent(const TCHAR *file2write, const char *content2write) +{ + FILE *f = generic_fopen(file2write, TEXT("w+")); + fwrite(content2write, sizeof(content2write[0]), strlen(content2write), f); + fflush(f); + fclose(f); +} + void writeLog(const TCHAR *logFileName, const char *log2write) { FILE *f = generic_fopen(logFileName, TEXT("a+")); diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 1d7f5fc1..70001b9b 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -108,6 +108,9 @@ std::string wstring2string(const std::wstring & rwString, UINT codepage); bool isInList(const TCHAR *token, const TCHAR *list); generic_string BuildMenuFileName(int filenameLen, unsigned int pos, const generic_string &filename); +std::string getFileContent(const TCHAR *file2read); +void writeFileContent(const TCHAR *file2write, const char *content2write); + class WcharMbcsConvertor { public: static WcharMbcsConvertor * getInstance() {return _pSelf;}; diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index ee3ef463..cfbed8be 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1422,11 +1422,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa if (_pTrayIco) _pTrayIco->doTrayIcon(REMOVE); - bool isSnapshotMode = pNppParam->getNppGUI().isSnapshotMode(); + const NppGUI & nppgui = pNppParam->getNppGUI(); + + bool isSnapshotMode = nppgui.isSnapshotMode(); if (isSnapshotMode) MainFileManager->backupCurrentBuffer(); - const NppGUI & nppgui = pNppParam->getNppGUI(); Session currentSession; if (nppgui._rememberLastSession) { @@ -1462,22 +1463,38 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa scnN.nmhdr.idFrom = 0; _pluginsManager.notify(&scnN); - // - // saving config.xml - // saveFindHistory(); //writeFindHistory _lastRecentFileList.saveLRFL(); //writeRecentFileHistorySettings, writeHistory saveScintillaParams(); //writeScintillaParams saveGUIParams(); //writeGUIParams saveProjectPanelsParams(); //writeProjectPanelsSettings + // + // saving config.xml + // pNppParam->saveConfig_xml(); - - + + // + // saving userDefineLang.xml + // saveUserDefineLangs(); + + // + // saving shortcuts.xml + // saveShortcuts(); + + // + // saving session.xml + // if (nppgui._rememberLastSession && !nppgui._isCmdlineNosessionActivated) saveSession(currentSession); + // write settings on cloud if enabled + if (nppgui._cloudChoice == dropbox) + { + pNppParam->writeSettingsFilesOnCloud(dropbox); + } + //Sends WM_DESTROY, Notepad++ will end if(Message == WM_CLOSE) ::DestroyWindow(hwnd); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index cdca9e23..71056f25 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -798,6 +798,69 @@ bool NppParameters::reloadLang() return loadOkay; } +generic_string NppParameters::getCloudSettingsPath(const generic_string & cloudChoicePath) +{ + // check if dropbox is present + generic_string cloudSettingsPath = TEXT(""); + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_PROFILE, &pidl); + TCHAR tmp[MAX_PATH]; + SHGetPathFromIDList(pidl, tmp); + + cloudSettingsPath = tmp; + PathAppend(cloudSettingsPath, TEXT("Dropbox")); + if (PathFileExists(cloudSettingsPath.c_str())) + _nppGUI._availableClouds |= DROPBOX_AVAILABLE; + + if (!PathFileExists(cloudChoicePath.c_str())) + return TEXT(""); + + // Read cloud choice + std::string cloudChoice = getFileContent(cloudChoicePath.c_str()); + + + if (cloudChoice == "dropbox" && _nppGUI._availableClouds & DROPBOX_AVAILABLE) + { + PathAppend(cloudSettingsPath, TEXT("Notepad++")); + + // The folder %userprofile%\Dropbox\Notepad++ should exist. + // if it doesn't, it means this folder was removed by user, we create it anyway + if (!PathFileExists(cloudSettingsPath.c_str())) + { + ::CreateDirectory(cloudSettingsPath.c_str(), NULL); + } + _nppGUI._cloudChoice = dropbox; + } + else if (cloudChoice == "oneDrive") + { + _nppGUI._cloudChoice = oneDrive; + } + else if (cloudChoice == "googleDrive") + { + _nppGUI._cloudChoice = googleDrive; + } + return cloudSettingsPath; +} + +generic_string NppParameters::getSettingsFolder() +{ + generic_string settingsFolderPath; + if (_isLocal) + { + return _nppPath; + } + else + { + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); + TCHAR tmp[MAX_PATH]; + SHGetPathFromIDList(pidl, tmp); + generic_string settingsFolderPath = tmp; + PathAppend(settingsFolderPath, TEXT("Notepad++")); + return settingsFolderPath; + } +} + bool NppParameters::load() { L_END = L_EXTERNAL; @@ -811,25 +874,25 @@ bool NppParameters::load() // Test if localConf.xml exist _isLocal = (PathFileExists(localConfPath.c_str()) == TRUE); - // Under vista and windows 7, the usage of doLocalConf.xml is not allowed - // if Notepad++ is installed in "program files" directory, because of UAC - if (_isLocal) - { - // We check if OS is Vista or above - if (_winVersion >= WV_VISTA) - { - ITEMIDLIST *pidl; - SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl); - TCHAR progPath[MAX_PATH]; - SHGetPathFromIDList(pidl, progPath); - TCHAR nppDirLocation[MAX_PATH]; - lstrcpy(nppDirLocation, _nppPath.c_str()); - ::PathRemoveFileSpec(nppDirLocation); + // Under vista and windows 7, the usage of doLocalConf.xml is not allowed + // if Notepad++ is installed in "program files" directory, because of UAC + if (_isLocal) + { + // We check if OS is Vista or greater version + if (_winVersion >= WV_VISTA) + { + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl); + TCHAR progPath[MAX_PATH]; + SHGetPathFromIDList(pidl, progPath); + TCHAR nppDirLocation[MAX_PATH]; + lstrcpy(nppDirLocation, _nppPath.c_str()); + ::PathRemoveFileSpec(nppDirLocation); - if (lstrcmp(progPath, nppDirLocation) == 0) - _isLocal = false; - } - } + if (lstrcmp(progPath, nppDirLocation) == 0) + _isLocal = false; + } + } if (_isLocal) { @@ -852,6 +915,21 @@ bool NppParameters::load() } } + _sessionPath = _userPath; // Session stock the absolute file path, it should never be on cloud + + // Detection cloud settings + //bool isCloud = false; + generic_string cloudChoicePath = _userPath; + cloudChoicePath += TEXT("\\cloud\\choice"); + + generic_string cloudPath = getCloudSettingsPath(cloudChoicePath); + if (cloudPath != TEXT("")) + { + _userPath = cloudPath; + } + //} + + //-------------------------------------// // Transparent function for w2k and xp // //-------------------------------------// @@ -1115,7 +1193,7 @@ bool NppParameters::load() //----------------------------// // session.xml : for per user // //----------------------------// - _sessionPath = _userPath; + PathAppend(_sessionPath, TEXT("session.xml")); // Don't load session.xml if not required in order to speed up!! @@ -2277,6 +2355,109 @@ LangType NppParameters::getLangFromExt(const TCHAR *ext) return L_TEXT; } +void NppParameters::writeSettingsFilesOnCloud(CloudChoice choice) +{ + generic_string cloudSettingsPath; + + if (choice == dropbox) + { + cloudSettingsPath = TEXT(""); + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_PROFILE, &pidl); + TCHAR tmp[MAX_PATH]; + SHGetPathFromIDList(pidl, tmp); + + cloudSettingsPath = tmp; + PathAppend(cloudSettingsPath, TEXT("Dropbox")); + if (!::PathFileExists(cloudSettingsPath.c_str())) + return; + PathAppend(cloudSettingsPath, TEXT("Notepad++")); + if (!::PathFileExists(cloudSettingsPath.c_str())) + { + ::CreateDirectory(cloudSettingsPath.c_str(), NULL); + } + } + else + { + return; + } + + // config.xml + generic_string cloudConfigPath = cloudSettingsPath; + PathAppend(cloudConfigPath, TEXT("config.xml")); + if (!::PathFileExists(cloudConfigPath.c_str()) && _pXmlUserDoc) + { + _pXmlUserDoc->SaveFile(cloudConfigPath.c_str()); + } + + // stylers.xml + generic_string cloudStylersPath = cloudSettingsPath; + PathAppend(cloudStylersPath, TEXT("stylers.xml")); + if (!::PathFileExists(cloudStylersPath.c_str()) && _pXmlUserStylerDoc) + { + _pXmlUserStylerDoc->SaveFile(cloudStylersPath.c_str()); + } + + // langs.xml + generic_string cloudLangsPath = cloudSettingsPath; + PathAppend(cloudLangsPath, TEXT("langs.xml")); + if (!::PathFileExists(cloudLangsPath.c_str()) && _pXmlUserDoc) + { + _pXmlDoc->SaveFile(cloudLangsPath.c_str()); + } +/* + // session.xml: Session stock the absolute file path, it should never be on cloud + generic_string cloudSessionPath = cloudSettingsPath; + PathAppend(cloudSessionPath, TEXT("session.xml")); + if (!::PathFileExists(cloudSessionPath.c_str()) && _pXmlSessionDoc) + { + _pXmlSessionDoc->SaveFile(cloudSessionPath.c_str()); + } +*/ + // userDefineLang.xml + generic_string cloudUserLangsPath = cloudSettingsPath; + PathAppend(cloudUserLangsPath, TEXT("userDefineLang.xml")); + if (!::PathFileExists(cloudUserLangsPath.c_str()) && _pXmlUserLangDoc) + { + _pXmlUserLangDoc->SaveFile(cloudUserLangsPath.c_str()); + } + + // shortcuts.xml + generic_string cloudShortcutsPath = cloudSettingsPath; + PathAppend(cloudShortcutsPath, TEXT("shortcuts.xml")); + if (!::PathFileExists(cloudShortcutsPath.c_str()) && _pXmlShortcutDoc) + { + _pXmlShortcutDoc->SaveFile(cloudShortcutsPath.c_str()); + } + + // contextMenu.xml + generic_string cloudContextMenuPath = cloudSettingsPath; + PathAppend(cloudContextMenuPath, TEXT("contextMenu.xml")); + if (!::PathFileExists(cloudContextMenuPath.c_str()) && _pXmlContextMenuDocA) + { + _pXmlContextMenuDocA->SaveUnicodeFilePath(cloudContextMenuPath.c_str()); + } + + // nativeLang.xml + generic_string cloudNativeLangPath = cloudSettingsPath; + PathAppend(cloudNativeLangPath, TEXT("nativeLang.xml")); + if (!::PathFileExists(cloudNativeLangPath.c_str()) && _pXmlNativeLangDocA) + { + _pXmlNativeLangDocA->SaveUnicodeFilePath(cloudNativeLangPath.c_str()); + } + + /* + // functionList.xml + generic_string cloudFunctionListPath = cloudSettingsPath; + PathAppend(cloudFunctionListPath, TEXT("functionList.xml")); + if (!::PathFileExists(cloudFunctionListPath.c_str())) + { + + } + */ +} + + void NppParameters::writeUserDefinedLang() { if (!_pXmlUserLangDoc) diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 0b39d677..1f269e82 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -103,6 +103,7 @@ enum ChangeDetect {cdDisabled=0, cdEnabled=1, cdAutoUpdate=2, cdGo2end=3, cdAuto enum BackupFeature {bak_none = 0, bak_simple = 1, bak_verbose = 2}; enum OpenSaveDirSetting {dir_followCurrent = 0, dir_last = 1, dir_userDef = 2}; enum MultiInstSetting {monoInst = 0, multiInstOnSession = 1, multiInst = 2}; +enum CloudChoice {noCloud = 0, dropbox = 1, oneDrive = 2, googleDrive = 3}; const int LANG_INDEX_INSTR = 0; const int LANG_INDEX_INSTR2 = 1; @@ -124,6 +125,11 @@ const int COPYDATA_FILENAMESW = 2; #define DECSEP_COMMA 1 #define DECSEP_BOTH 2 + +#define DROPBOX_AVAILABLE 1 +#define ONEDRIVE_AVAILABLE 2 +#define GOOGLEDRIVE_AVAILABLE 4 + const TCHAR fontSizeStrs[][3] = {TEXT(""), TEXT("5"), TEXT("6"), TEXT("7"), TEXT("8"), TEXT("9"), TEXT("10"), TEXT("11"), TEXT("12"), TEXT("14"), TEXT("16"), TEXT("18"), TEXT("20"), TEXT("22"), TEXT("24"), TEXT("26"), TEXT("28")}; const TCHAR localConfFile[] = TEXT("doLocalConf.xml"); @@ -711,7 +717,7 @@ struct NppGUI _checkHistoryFiles(true) ,_enableSmartHilite(true), _disableSmartHiliteTmp(false), _enableTagsMatchHilite(true), _enableTagAttrsHilite(true), _enableHiliteNonHTMLZone(false),\ _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _isCmdlineNosessionActivated(false), _detectEncoding(true), _backup(bak_none), _useDir(false), _backupDir(TEXT("")),\ _doTaskList(true), _maitainIndent(true), _openSaveDir(dir_followCurrent), _styleMRU(true), _styleURL(0),\ - _autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")),\ + _autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")), _cloudChoice(noCloud), _availableClouds(0),\ _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _enableMultiSelection(false), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false),\ _smartHiliteCaseSensitive(false), _leftmostDelimiter('('), _rightmostDelimiter(')'), _delimiterSelectionOnEntireDocument(false), _multiInstSetting(monoInst),\ _fileSwitcherWithoutExtColumn(false), _isSnapshotMode(true), _snapshotBackupTiming(7000), _backSlashIsEscapeCharacterForSql(true) { @@ -819,6 +825,8 @@ struct NppGUI bool isSnapshotMode() const {return _isSnapshotMode && _rememberLastSession && !_isCmdlineNosessionActivated;}; bool _isSnapshotMode; size_t _snapshotBackupTiming; + CloudChoice _cloudChoice; // this option will never be read/written from/to config.xml + unsigned char _availableClouds; // this option will never be read/written from/to config.xml }; struct ScintillaViewParams @@ -1200,6 +1208,8 @@ public: bool reloadLang(); bool reloadStylers(TCHAR *stylePath = NULL); void destroyInstance(); + generic_string getCloudSettingsPath(const generic_string & cloudChoicePath); + generic_string getSettingsFolder(); bool _isTaskListRBUTTONUP_Active; int L_END; @@ -1538,6 +1548,8 @@ public: return _userPath; }; + void writeSettingsFilesOnCloud(CloudChoice choice); + DPIManager _dpiManager; private: diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp index 64937f20..afaa1c3d 100644 --- a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp @@ -825,6 +825,18 @@ bool TiXmlDocumentA::SaveFile( const char * filename ) const } return false; } +bool TiXmlDocumentA::SaveUnicodeFilePath( const TCHAR* filename ) const +{ + // The old c stuff lives on... + FILE* fp = generic_fopen( filename, TEXT("w") ); + if ( fp ) + { + Print( fp, 0 ); + fclose( fp ); + return true; + } + return false; +} TiXmlNodeA* TiXmlDocumentA::Clone() const diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h index 3bae74ec..0ebfc6a8 100644 --- a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h @@ -1004,7 +1004,9 @@ public: /// Save a file using the given filename. Returns true if successful. bool SaveFile( const char * filename ) const; - bool LoadUnicodeFilePath(const TCHAR* filename); + /// Load and Save a file using the given unicode filename. Returns true if successful. + bool LoadUnicodeFilePath( const TCHAR* filename ); + bool SaveUnicodeFilePath( const TCHAR* filename ) const; #ifdef TIXMLA_USE_STL bool LoadFile( const std::string& filename ) ///< STL std::string version. diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index b5638dfd..6c112fdb 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -36,6 +36,9 @@ FunctionParsersManager::~FunctionParsersManager() { delete _parsers[i]; } + + if (_pXmlFuncListDoc) + delete _pXmlFuncListDoc; } bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** ppEditView) @@ -149,6 +152,13 @@ bool FunctionParsersManager::getUnitPaserParameters(TiXmlNode *functionParser, g return true; } +void FunctionParsersManager::writeFunctionListXml(const TCHAR *destFoder) const +{ + generic_string dest = destFoder; + PathAppend(dest, TEXT("functionList.xml")); + if (_pXmlFuncListDoc) + _pXmlFuncListDoc->SaveFile(dest.c_str()); +} bool FunctionParsersManager::getFuncListFromXmlTree() { diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.h b/PowerEditor/src/WinControls/FunctionList/functionParser.h index 73254902..525a74d1 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.h +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.h @@ -135,6 +135,7 @@ public: ~FunctionParsersManager(); bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); bool parse(std::vector & foundInfos, const AssociationInfo & assoInfo); + void writeFunctionListXml(const TCHAR *destFoder) const; private: ScintillaEditView **_ppEditView; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index acec63c8..144bd5d5 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -370,3 +370,12 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,118,109,160,10 END +IDD_PREFERENCE_SETTINGSONCLOUD_BOX DIALOGEX 0, 0, 455, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Settings on cloud",IDC_SETTINGSONCLOUD_GB_STATIC,89,44,268,89,BS_CENTER + CONTROL "Dropbox",IDD_SETTINGSONCLOUD_DROPBOX_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,118,60,160,10 +END + diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index a354cc66..01fcd817 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -139,6 +139,10 @@ BOOL CALLBACK PreferenceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa _delimiterSettingsDlg.init(_hInst, _hSelf); _delimiterSettingsDlg.create(IDD_PREFERENCE_DELIMITERSETTINGS_BOX, false, false); + _settingsOnCloudDlg.init(_hInst, _hSelf); + _settingsOnCloudDlg.create(IDD_PREFERENCE_SETTINGSONCLOUD_BOX, false, false); + + _wVector.push_back(DlgInfo(&_barsDlg, TEXT("General"), TEXT("Global"))); _wVector.push_back(DlgInfo(&_marginsDlg, TEXT("Editing"), TEXT("Scintillas"))); _wVector.push_back(DlgInfo(&_defaultNewDocDlg, TEXT("New Document"), TEXT("NewDoc"))); @@ -152,6 +156,7 @@ BOOL CALLBACK PreferenceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa _wVector.push_back(DlgInfo(&_autoCompletionDlg, TEXT("Auto-Completion"), TEXT("AutoCompletion"))); _wVector.push_back(DlgInfo(&_multiInstDlg, TEXT("Multi-Instance"), TEXT("MultiInstance"))); _wVector.push_back(DlgInfo(&_delimiterSettingsDlg, TEXT("Delimiter"), TEXT("Delimiter"))); + _wVector.push_back(DlgInfo(&_settingsOnCloudDlg, TEXT("Cloud"), TEXT("Cloud"))); _wVector.push_back(DlgInfo(&_settingsDlg, TEXT("MISC."), TEXT("MISC"))); @@ -177,6 +182,7 @@ BOOL CALLBACK PreferenceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa _autoCompletionDlg.reSizeTo(rc); _multiInstDlg.reSizeTo(rc); _delimiterSettingsDlg.reSizeTo(rc); + _settingsOnCloudDlg.reSizeTo(rc); NppParameters *pNppParam = NppParameters::getInstance(); ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); @@ -2780,3 +2786,85 @@ BOOL CALLBACK DelimiterSettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPA return FALSE; } + +BOOL CALLBACK SettingsOnCloudDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) +{ + NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); + switch (Message) + { + case WM_INITDIALOG : + { + CloudChoice cloudChoice = nppGUI._cloudChoice; + ::SendDlgItemMessage(_hSelf, IDD_SETTINGSONCLOUD_DROPBOX_CHECK, BM_SETCHECK, cloudChoice == dropbox?BST_CHECKED:BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_SETTINGSONCLOUD_DROPBOX_CHECK), (nppGUI._availableClouds & DROPBOX_AVAILABLE) != 0); + } + break; + + case WM_COMMAND : + { + switch (wParam) + { + case IDD_SETTINGSONCLOUD_DROPBOX_CHECK : + { + nppGUI._cloudChoice = isCheckedOrNot(IDD_SETTINGSONCLOUD_DROPBOX_CHECK)?dropbox:noCloud; + if (nppGUI._cloudChoice == dropbox) + { + setCloudChoice("dropbox"); + /* + // files on cloud can never be erased or modified while setting cloud + if (!hasSettingsFilesInDropBox()) + { + // it's the first time to set Notepad++ settings on cloud + changeSettingsFilesPath(); + + } + else + { + // Notepad++ settings are already on cloud + askForRestarting(); + } + */ + } + else + { + removeCloudChoice(); + //changeSettingsFilesPath(); + } + } + break; + + default : + return FALSE; + } + } + break; + } + return FALSE; +} + +void SettingsOnCloudDlg::setCloudChoice(const char *choice) +{ + generic_string cloudChoicePath = (NppParameters::getInstance())->getSettingsFolder(); + cloudChoicePath += TEXT("\\cloud\\"); + + if (!PathFileExists(cloudChoicePath.c_str())) + { + ::CreateDirectory(cloudChoicePath.c_str(), NULL); + } + cloudChoicePath += TEXT("choice"); + writeFileContent(cloudChoicePath.c_str(), choice); + +} + +void SettingsOnCloudDlg::removeCloudChoice() +{ + generic_string cloudChoicePath = (NppParameters::getInstance())->getSettingsFolder(); + //NppParameters *nppParams = ; + + cloudChoicePath += TEXT("\\cloud\\choice"); + if (PathFileExists(cloudChoicePath.c_str())) + { + ::DeleteFile(cloudChoicePath.c_str()); + } +} + diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h index 6c8f43a1..7b71022c 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.h +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -213,6 +213,17 @@ private : RECT _closerRect, _closerLabelRect; }; +class SettingsOnCloudDlg : public StaticDialog +{ +public : + SettingsOnCloudDlg() {}; + +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + void setCloudChoice(const char *choice); + void removeCloudChoice(); +}; + class PreferenceDlg : public StaticDialog { friend class NativeLangSpeaker; @@ -261,6 +272,7 @@ private : AutoCompletionDlg _autoCompletionDlg; MultiInstDlg _multiInstDlg; DelimiterSettingsDlg _delimiterSettingsDlg; + SettingsOnCloudDlg _settingsOnCloudDlg; }; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index 173d8d04..7a8cd440 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -111,9 +111,8 @@ #define IDC_BORDERWIDTH_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 31) #define IDC_BORDERWIDTHVAL_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 32) #define IDC_BORDERWIDTH_SLIDER (IDD_PREFERENCE_MARGEIN_BOX + 33) - #define IDC_CHECK_DISABLEADVANCEDSCROLL (IDD_PREFERENCE_MARGEIN_BOX + 34) - + #define IDD_PREFERENCE_DELIMITERSETTINGS_BOX 6250 //(IDD_PREFERENCE_BOX + 250) #define IDC_DELIMITERSETTINGS_GB_STATIC (IDD_PREFERENCE_DELIMITERSETTINGS_BOX + 1) #define IDD_STATIC_OPENDELIMITER (IDD_PREFERENCE_DELIMITERSETTINGS_BOX + 2) @@ -124,6 +123,10 @@ #define IDD_STATIC_BLABLA (IDD_PREFERENCE_DELIMITERSETTINGS_BOX + 7) #define IDD_STATIC_BLABLA2NDLINE (IDD_PREFERENCE_DELIMITERSETTINGS_BOX + 8) +#define IDD_PREFERENCE_SETTINGSONCLOUD_BOX 6260 //(IDD_PREFERENCE_BOX + 250) + #define IDC_SETTINGSONCLOUD_GB_STATIC (IDD_PREFERENCE_SETTINGSONCLOUD_BOX + 1) + #define IDD_SETTINGSONCLOUD_DROPBOX_CHECK (IDD_PREFERENCE_SETTINGSONCLOUD_BOX + 2) + #define IDD_PREFERENCE_SETTING_BOX 6300 //(IDD_PREFERENCE_BOX + 300) #define IDC_TABSETTING_GB_STATIC (IDD_PREFERENCE_SETTING_BOX + 1) #define IDC_CHECK_REPLACEBYSPACE (IDD_PREFERENCE_SETTING_BOX + 2)